]> git.rmz.io Git - dotfiles.git/blob - bin/old/sqlite2mysql.pl
vim: disable some horrible cpp snippets
[dotfiles.git] / bin / old / sqlite2mysql.pl
1 #! /usr/bin/perl
2
3 while ($line = <>){
4 if (($line !~ /BEGIN TRANSACTION/) && ($line !~ /COMMIT/) && ($line !~ /sqlite_sequence/) && ($line !~ /CREATE UNIQUE INDEX/)){
5
6 if ($line =~ /CREATE TABLE \"([a-z_]*)\"(.*)/){
7 $name = $1;
8 $sub = $2;
9 $sub =~ s/\"//g;
10 $line = "DROP TABLE IF EXISTS $name;\nCREATE TABLE IF NOT EXISTS $name$sub\n";
11 }
12 elsif ($line =~ /INSERT INTO \"([a-z_]*)\"(.*)/){
13 $line = "INSERT INTO $1$2\n";
14 $line =~ s/\"/\\\"/g;
15 $line =~ s/\"/\'/g;
16 }else{
17 $line =~ s/\'\'/\\\'/g;
18 }
19 $line =~ s/([^\\'])\'t\'(.)/$1THIS_IS_TRUE$2/g;
20 $line =~ s/THIS_IS_TRUE/1/g;
21 $line =~ s/([^\\'])\'f\'(.)/$1THIS_IS_FALSE$2/g;
22 $line =~ s/THIS_IS_FALSE/0/g;
23 $line =~ s/AUTOINCREMENT/AUTO_INCREMENT/g;
24 print $line;
25 }
26 }