Edgewall Software

Changes between Version 15 and Version 16 of SqLiteToMySql


Ignore:
Timestamp:
Feb 13, 2012, 2:44:54 PM (12 years ago)
Author:
kmenc15@…
Comment:

Add perl scripts for migrate

Legend:

Unmodified
Added
Removed
Modified
  • SqLiteToMySql

    v15 v16  
    122122
    123123I've also modified the Python {{{cleansql}}} script, which will now take in both the mysql table structure SQL and the SQLite SQL. It will remove the {{{PRAGMA}}} statement and convert {{{CAST(p.value AS int)}}} to {{{CAST(p.value AS signed)}}}. It will also try to fix the backslash escaped quotes(!). Not the best script but it worked for me :)
     124
     125----
     126
     127None of the scripts here deal with quoting of ' characters caused by sqlite/mysql differences. Here is my perl script for sqlite to mysql migrate, which handles quoting very accurately:
     128{{{
     129print << 'EOF';
     130BEGIN;
     131TRUNCATE `attachment` ;
     132TRUNCATE `auth_cookie` ;
     133-- ############ more truncates here...
     134EOF
     135
     136$inq=0;
     137$del=0;
     138sub qut { local $_=shift; ($inq ? (/'/ ? "\\'\\" : ($inq=0,"'")) : "'".(/'/ ? '' : ($inq=1,''))).$_ }
     139
     140while (<>) {
     141        $del=!/;/, next if ($del);
     142        s/^(COMMIT|BEGIN TRANSACTION);//mg;
     143        $del=1, next if (/^CREATE (TABLE|INDEX)/);
     144        s/INSERT INTO "([^"]+)"/INSERT INTO `$1`/g;
     145        s/\\/\\\\/g;
     146        s/'(.|$)/qut($1)/ge;
     147        s/(INSERT INTO `milestone` .*),0,NULL/$1,NULL/g;
     148        print;
     149}
     150print "COMMIT;"
     151}}}