SHARE
TWEET

Easy SQLite to MySQL / MariaDB perl script

NotoriousPyro Oct 29th, 2016 1,197 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/perl
  2.  
  3. while ($line = <>){
  4.     if (($line !~  /BEGIN TRANSACTION/) && ($line !~ /COMMIT/) && ($line !~ /sqlite_sequence/) && ($line !~ /CREATE UNIQUE INDEX/) && ($line !~ /PRAGMA foreign_keys=OFF/)){
  5.  
  6.         if ($line =~ /CREATE TABLE \"(\w*)\"(.*)/){
  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 \"(\w*)\"(.*)/){
  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.         $line =~ s/(.*)varchar([^\(0-9\)].*)/$1varchar\(255\)$2/g;
  25.         print $line;
  26.     }
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top