From: Samir Benmendil Date: Sun, 22 May 2016 20:47:56 +0000 (+0100) Subject: bin: add some old sqlite2mysql script X-Git-Url: https://git.rmz.io/dotfiles.git/commitdiff_plain/8614cffd5191962c2dc34a23f8b39ebac6fdd954 bin: add some old sqlite2mysql script --- diff --git a/bin/old/sqlite2mysql.pl b/bin/old/sqlite2mysql.pl new file mode 100755 index 0000000..a28dfa9 --- /dev/null +++ b/bin/old/sqlite2mysql.pl @@ -0,0 +1,26 @@ +#! /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; + } +}