r62762 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62761‎ | r62762 | r62763 >
Date:09:40, 21 February 2010
Author:maxsem
Status:ok
Tags:
Comment:
Also rewrite ALTER TABLE, handle int(...) properly
Modified paths:
  • /trunk/phase3/includes/db/DatabaseSqlite.php (modified) (history)
  • /trunk/phase3/maintenance/tests/DatabaseSqliteTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/DatabaseSqliteTest.php
@@ -36,9 +36,9 @@
3737 $this->assertEquals( 'foo', $this->replaceVars( 'foo' ), "Don't break anything accidentally" );
3838
3939 $this->assertEquals( "CREATE TABLE /**/foo (foo_key INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "
40 - . "foo_name TEXT NOT NULL DEFAULT '');",
 40+ . "foo_name TEXT NOT NULL DEFAULT '', foo_int INTEGER, foo_int2 INTEGER );",
4141 $this->replaceVars( "CREATE TABLE /**/foo (foo_key int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
42 - foo_name varchar(255) binary NOT NULL DEFAULT '') ENGINE=MyISAM;" )
 42+ foo_name varchar(255) binary NOT NULL DEFAULT '', foo_int tinyint( 8 ), foo_int2 int(16) ) ENGINE=MyISAM;" )
4343 );
4444
4545 $this->assertEquals( "CREATE TABLE foo ( foo_binary1 BLOB, foo_binary2 BLOB );",
@@ -49,5 +49,9 @@
5050 $this->replaceVars( "CREATE TABLE text ( text_foo tinytext );" ),
5151 'Table name changed'
5252 );
 53+
 54+ $this->assertEquals( "ALTER TABLE foo ADD COLUMN foo_bar INTEGER DEFAULT 42",
 55+ $this->replaceVars( "ALTER TABLE foo\nADD COLUMN foo_bar int(10) unsigned DEFAULT 42")
 56+ );
5357 }
5458 }
\ No newline at end of file
Index: trunk/phase3/includes/db/DatabaseSqlite.php
@@ -518,7 +518,7 @@
519519
520520 protected function replaceVars( $s ) {
521521 $s = parent::replaceVars( $s );
522 - if ( preg_match( '/^\s*CREATE TABLE/i', $s ) ) {
 522+ if ( preg_match( '/^\s*(CREATE|ALTER) TABLE/i', $s ) ) {
523523 // CREATE TABLE hacks to allow schema file sharing with MySQL
524524
525525 // binary/varbinary column type -> blob
@@ -526,7 +526,7 @@
527527 // no such thing as unsigned
528528 $s = preg_replace( '/\b(un)?signed\b/i', '', $s );
529529 // INT -> INTEGER
530 - $s = preg_replace( '/\b(tiny|small|medium|big|)int\b/i', 'INTEGER', $s );
 530+ $s = preg_replace( '/\b(tiny|small|medium|big|)int(\([\s\d]*\)|\b)/i', 'INTEGER', $s );
531531 // varchar -> TEXT
532532 $s = preg_replace( '/\bvarchar\(\d+\)/i', 'TEXT', $s );
533533 // TEXT normalization

Status & tagging log