From: <lu...@us...> - 2007-01-31 05:31:48
|
Update of /cvsroot/tikiwiki/tiki/db/convertscripts In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv16022/db/convertscripts Modified Files: Tag: BRANCH-1-9 mysql3tosqlite.php Log Message: [FIX] more SQLite fixes Index: mysql3tosqlite.php =================================================================== RCS file: /cvsroot/tikiwiki/tiki/db/convertscripts/mysql3tosqlite.php,v retrieving revision 1.5.6.5 retrieving revision 1.5.6.6 diff -u -d -r1.5.6.5 -r1.5.6.6 --- mysql3tosqlite.php 31 Jan 2007 01:48:20 -0000 1.5.6.5 +++ mysql3tosqlite.php 31 Jan 2007 05:31:47 -0000 1.5.6.6 @@ -1,4 +1,5 @@ <?php +/* $Header$ */ $tikiversion='1.9'; if(!isset($_GET['version'])) { @@ -50,13 +51,14 @@ $poststmt="\n\n"; //replace comments + $stmt=preg_replace("/# --------------------------------------------------------/","-- ******************************************************",$stmt); $stmt=preg_replace("/#/","--",$stmt); // drop TYPE=MyISAM and AUTO_INCREMENT=1 - $stmt=preg_replace("/TYPE=MyISAM/","",$stmt); - $stmt=preg_replace("/AUTO_INCREMENT=1/","",$stmt); + $stmt=preg_replace("/ TYPE=MyISAM/","",$stmt); + $stmt=preg_replace("/ AUTO_INCREMENT=1/","",$stmt); //auto_increment things - $stmt=preg_replace("/int\(.\) (unsigned )*NOT NULL auto_increment/","serial",$stmt); - $stmt=preg_replace("/int\(..\) (unsigned )*NOT NULL auto_increment/","bigserial",$stmt); + $stmt=preg_replace("/int(eger)*\(.\) (unsigned )*NOT NULL auto_increment/","serial",$stmt); + $stmt=preg_replace("/int(eger)*\(..\) (unsigned )*NOT NULL auto_increment/","bigserial",$stmt); // integer types $stmt=preg_replace("/tinyint\([1-4]\)/","smallint",$stmt); $stmt=preg_replace("/int\([1-4]\)/","smallint",$stmt); @@ -69,27 +71,30 @@ // quote column names $stmt=preg_replace("/\n[ \t]+([a-zA-Z0-9_]+)/","\n \"$1\"",$stmt); // quote and record table names - $stmt=preg_replace("/(DROP TABLE |CREATE TABLE )([a-zA-Z0-9_]+)( \()*/e","record_tablename('$1','$2','$3')",$stmt); + $stmt=preg_replace("/(DROP TABLE IF EXISTS )([^\;]+)(\;)*/e","record_tablename('$1','$2','$3')",$stmt); + $stmt=preg_replace("/(CREATE TABLE )([a-zA-Z0-9_]+)( \()*/e","record_tablename('$1','$2','$3')",$stmt); // unquote the PRIMARY and other Keys $stmt=preg_replace("/\n[ \t]+\"(PRIMARY|KEY|FULLTEXT|UNIQUE)\"/","\n $1",$stmt); // convert enums - $stmt=preg_replace("/\n[ \t]+(\"[a-zA-Z0-9_]+\") enum\(([^\)]+)\)/e","convert_enums('$1','$2')",$stmt); + $stmt=preg_replace("/\n[ \t]+(\"[a-zA-Z0-9_]+\") enum *\(([^\)]+)\)/e","convert_enums('$1','$2')",$stmt); // quote column names in primary keys $stmt=preg_replace("/\n[ \t]+(PRIMARY KEY) \((.+)\),*/e","quote_prim_cols('$1','$2')",$stmt); // create indexes from KEY ... - $stmt=preg_replace("/\n[ \t]+KEY ([a-zA-Z0-9_]+) \((.+)\),*/e","create_index('$1','$2')",$stmt); - $stmt=preg_replace("/\n[ \t]+FULLTEXT KEY ([a-zA-Z0-9_]+) \((.+)\),*/e","create_index('$1','$2')",$stmt); - $stmt=preg_replace("/\n[ \t]+(UNIQUE) KEY ([a-zA-Z0-9_]+) \((.+)\),*/e","create_index('$2','$3','$1')",$stmt); + $stmt=preg_replace("/\n[ \t]+KEY *([a-zA-Z0-9_]+) \((.+)\),*/e","create_index('$1','$2')",$stmt); + $stmt=preg_replace("/\n[ \t]+FULLTEXT KEY *([a-zA-Z0-9_]+) \((.+)\),*/e","create_index('$1','$2')",$stmt); + $stmt=preg_replace("/\n[ \t]+(UNIQUE) KEY *([a-zA-Z0-9_]+) \((.+)\),*/e","create_index('$2','$3','$1')",$stmt); // handle inserts - $stmt=preg_replace("/INSERT INTO ([a-zA-Z0-9_]*).*\(([^\)]+)\) VALUES (.*)/e","do_inserts('$1','$2','$3')",$stmt); - $stmt=preg_replace("/INSERT IGNORE INTO ([a-zA-Z0-9_]*).*\(([^\)]+)\) VALUES (.*)/e","do_inserts('$1','$2','$3')",$stmt); + $stmt=preg_replace("/INSERT INTO *([a-zA-Z0-9_]*).*\(([^\)]+)\) VALUES *(.*)/e","do_inserts('$1','$2','$3')",$stmt); + $stmt=preg_replace("/INSERT IGNORE INTO *([a-zA-Z0-9_]*).*\(([^\)]+)\) VALUES *(.*)/e","do_inserts('$1','$2','$3')",$stmt); // why does i modifier not work??? - $stmt=preg_replace("/insert into ([a-zA-Z0-9_]*).*\(([^\)]+)\) values(.*)/e","do_inserts('$1','$2','$3')",$stmt); + $stmt=preg_replace("/insert into ([a-zA-Z0-9_]*).*\(([^\)]+)\) values *(.*)/e","do_inserts('$1','$2','$3')",$stmt); // the update $stmt=preg_replace("/update ([a-zA-Z0-9_]+) set (.*)/e","do_updates('$1','$2')",$stmt); $stmt=preg_replace("/UPDATE ([a-zA-Z0-9_]+) set (.*)/e","do_updates('$1','$2')",$stmt); // clean cases where UNIQUE was alone at the end $stmt=preg_replace("/,(\s*)\)/","$1)",$stmt); + // replace mysql reserved words backticks + $stmt=preg_replace("/`/","",$stmt); return $stmt.";".$poststmt; } @@ -97,7 +102,7 @@ { global $table_name; $table_name=$tabnam; - return($stmt."\"".$tabnam."\"".$tail); + return($stmt."'".$tabnam."'".$tail); } function create_index($name,$content,$type="") |