Created
June 8, 2013 23:44
-
-
Save carlesandres/5737012 to your computer and use it in GitHub Desktop.
Perl sqlite to mysql conversion
This file contains hidden or 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 | |
while ($line = <>){ | |
if (($line !~ /BEGIN TRANSACTION/) && ($line !~ /COMMIT/) && ($line !~ /sqlite_sequence/) && ($line !~ /CREATE UNIQUE INDEX/)){ | |
if ($line =~ /CREATE TABLE \"([a-z_]*)\"(.*)/){ | |
$name = $1; | |
$sub = $2; | |
$sub =~ s/\"//g; | |
$line = "DROP TABLE IF EXISTS $name;\nCREATE TABLE IF NOT EXISTS $name$sub\n"; | |
} | |
elsif ($line =~ /INSERT INTO \"([a-z_]*)\"(.*)/){ | |
$line = "INSERT INTO $1$2\n"; | |
$line =~ s/\"/\\\"/g; | |
$line =~ s/\"/\'/g; | |
}else{ | |
$line =~ s/\'\'/\\\'/g; | |
} | |
$line =~ s/([^\\'])\'t\'(.)/$1THIS_IS_TRUE$2/g; | |
$line =~ s/THIS_IS_TRUE/1/g; | |
$line =~ s/([^\\'])\'f\'(.)/$1THIS_IS_FALSE$2/g; | |
$line =~ s/THIS_IS_FALSE/0/g; | |
$line =~ s/AUTOINCREMENT/AUTO_INCREMENT/g; | |
print $line; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment