From 5426f6e6a768777efcf60d15b1b34834b50a9b6c Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Sun, 21 Feb 2010 09:40:27 +0000 Subject: [PATCH] Also rewrite ALTER TABLE, handle int(...) properly --- includes/db/DatabaseSqlite.php | 4 ++-- maintenance/tests/DatabaseSqliteTest.php | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index 831479fdec..1ce725c09e 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -518,7 +518,7 @@ class DatabaseSqlite extends DatabaseBase { 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 @@ class DatabaseSqlite extends DatabaseBase { // 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 diff --git a/maintenance/tests/DatabaseSqliteTest.php b/maintenance/tests/DatabaseSqliteTest.php index 9eb07dd23a..011ef79852 100644 --- a/maintenance/tests/DatabaseSqliteTest.php +++ b/maintenance/tests/DatabaseSqliteTest.php @@ -36,9 +36,9 @@ class DatabaseSqliteTest extends PHPUnit_Framework_TestCase { $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 @@ class DatabaseSqliteTest extends PHPUnit_Framework_TestCase { $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 -- 2.20.1