Created
May 5, 2014 21:07
-
-
Save 166MMX/cc2cd985e366cf3e78e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
while ( <> ) | |
{ | |
next if m' | |
^PRAGMA | | |
sqlite_sequence | | |
CREATE UNIQUE INDEX | |
'x; | |
if ( /^CREATE TABLE/i ) | |
{ | |
s/^CREATE TABLE \b([0-9A-Za-z_]*)\b/CREATE TABLE IF NOT EXISTS `$1`/i; | |
s/^CREATE TABLE \"([0-9A-Za-z_]*)\"/CREATE TABLE IF NOT EXISTS `$1`/i; | |
s/^CREATE TABLE \'([0-9A-Za-z_]*)\'/CREATE TABLE IF NOT EXISTS `$1`/i; | |
s/\bSTRING\b/TEXT/gi; | |
s/\bAUTOINCREMENT\b/AUTO_INCREMENT/gi; | |
#s/(?<=[(,])\s*([0-9a-z_]*)\s+([0-9a-z_]*)/`$1` $2/gi; | |
} | |
elsif ( /^BEGIN TRANSACTION/i ) | |
{ | |
s/^BEGIN TRANSACTION/START TRANSACTION/i; | |
} | |
elsif ( /^INSERT INTO/i ) | |
{ | |
s/^INSERT INTO [\'\"]([0-9a-z_]*)[\'\"]/INSERT INTO `$1`/i; | |
while ( !/;$/ ) | |
{ | |
my $line = $_; | |
my $next = <>; | |
$_ = "$line$next"; | |
} | |
s/\"/\\\'/g; # " => \' | |
} | |
elsif ( /^CREATE TRIGGER/i ) | |
{ | |
s/AFTER UPDATE OF [0-9a-z_]* ON/AFTER UPDATE ON/i; | |
} | |
elsif ( /^CREATE INDEX/i ) | |
{ | |
s/^CREATE INDEX \b([0-9a-z_]*)\b ON \b([0-9A-Za-z_]*)\b/CREATE INDEX `$1` ON `$2`/i; | |
#s/(?<=[(,])\s*([0-9a-z_]*)\b/`$1`/gi; | |
} | |
else | |
{ | |
s/\'\'/\\\'/g; # '' => \' | |
} | |
print; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment