]> git.rmz.io Git - dotfiles.git/commitdiff
bin: add some old sqlite2mysql script
authorSamir Benmendil <me@rmz.io>
Sun, 22 May 2016 20:47:56 +0000 (21:47 +0100)
committerSamir Benmendil <me@rmz.io>
Sun, 22 May 2016 20:47:56 +0000 (21:47 +0100)
bin/old/sqlite2mysql.pl [new file with mode: 0755]

diff --git a/bin/old/sqlite2mysql.pl b/bin/old/sqlite2mysql.pl
new file mode 100755 (executable)
index 0000000..a28dfa9
--- /dev/null
@@ -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;
+    }
+}