http://www.mediawiki.org/wiki/Special:Code/MediaWiki/62762

Revision: 62762
Author:   maxsem
Date:     2010-02-21 09:40:27 +0000 (Sun, 21 Feb 2010)

Log Message:
-----------
Also rewrite ALTER TABLE, handle int(...) properly

Modified Paths:
--------------
    trunk/phase3/includes/db/DatabaseSqlite.php
    trunk/phase3/maintenance/tests/DatabaseSqliteTest.php

Modified: trunk/phase3/includes/db/DatabaseSqlite.php
===================================================================
--- trunk/phase3/includes/db/DatabaseSqlite.php 2010-02-21 08:30:23 UTC (rev 
62761)
+++ trunk/phase3/includes/db/DatabaseSqlite.php 2010-02-21 09:40:27 UTC (rev 
62762)
@@ -518,7 +518,7 @@
 
        protected function replaceVars( $s ) {
                $s = parent::replaceVars( $s );
-               if ( preg_match( '/^\s*CREATE TABLE/i', $s ) ) {
+               if ( preg_match( '/^\s*(CREATE|ALTER) TABLE/i', $s ) ) {
                        // CREATE TABLE hacks to allow schema file sharing with 
MySQL
 
                        // binary/varbinary column type -> blob
@@ -526,7 +526,7 @@
                        // no such thing as unsigned
                        $s = preg_replace( '/\b(un)?signed\b/i', '', $s );
                        // INT -> INTEGER
-                       $s = preg_replace( 
'/\b(tiny|small|medium|big|)int\b/i', 'INTEGER', $s );
+                       $s = preg_replace( 
'/\b(tiny|small|medium|big|)int(\([\s\d]*\)|\b)/i', 'INTEGER', $s );
                        // varchar -> TEXT
                        $s = preg_replace( '/\bvarchar\(\d+\)/i', 'TEXT', $s );
                        // TEXT normalization

Modified: trunk/phase3/maintenance/tests/DatabaseSqliteTest.php
===================================================================
--- trunk/phase3/maintenance/tests/DatabaseSqliteTest.php       2010-02-21 
08:30:23 UTC (rev 62761)
+++ trunk/phase3/maintenance/tests/DatabaseSqliteTest.php       2010-02-21 
09:40:27 UTC (rev 62762)
@@ -36,9 +36,9 @@
                $this->assertEquals( 'foo', $this->replaceVars( 'foo' ), "Don't 
break anything accidentally" );
 
                $this->assertEquals( "CREATE TABLE /**/foo (foo_key INTEGER NOT 
NULL PRIMARY KEY AUTOINCREMENT, "
-                       . "foo_name TEXT NOT NULL DEFAULT '');",
+                       . "foo_name TEXT NOT NULL DEFAULT '', foo_int INTEGER, 
foo_int2 INTEGER );",
                        $this->replaceVars( "CREATE TABLE /**/foo (foo_key int 
unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
-                       foo_name varchar(255) binary NOT NULL DEFAULT '') 
ENGINE=MyISAM;" )
+                       foo_name varchar(255) binary NOT NULL DEFAULT '', 
foo_int tinyint( 8 ), foo_int2 int(16) ) ENGINE=MyISAM;" )
                        );
 
                $this->assertEquals( "CREATE TABLE foo ( foo_binary1 BLOB, 
foo_binary2 BLOB );",
@@ -49,5 +49,9 @@
                        $this->replaceVars( "CREATE TABLE text ( text_foo 
tinytext );" ),
                        'Table name changed'
                        );
+               
+               $this->assertEquals( "ALTER TABLE foo ADD COLUMN foo_bar 
INTEGER DEFAULT 42",
+                       $this->replaceVars( "ALTER TABLE foo\nADD COLUMN 
foo_bar int(10) unsigned DEFAULT 42")
+                       );
        }
 }
\ No newline at end of file



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to