Support conversion of floating-point MySQL types in DatabaseSqlite::sourceStream()
authorMax Semenik <maxsem@users.mediawiki.org>
Thu, 7 Oct 2010 16:13:54 +0000 (16:13 +0000)
committerMax Semenik <maxsem@users.mediawiki.org>
Thu, 7 Oct 2010 16:13:54 +0000 (16:13 +0000)
includes/db/DatabaseSqlite.php
maintenance/tests/phpunit/includes/db/DatabaseSqliteTest.php

index b691d83..faadb0b 100644 (file)
@@ -606,7 +606,9 @@ 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(\s*\([\s\d]*\)|\b)/i', 'INTEGER', $s );
+                       $s = preg_replace( '/\b(tiny|small|medium|big|)int(\s*\(\s*\d+\s*\)|\b)/i', 'INTEGER', $s );
+                       // floating point types -> REAL
+                       $s = preg_replace( '/\b(float|double(\s+precision)?)(\s*\(\s*\d+\s*(,\s*\d+\s*)?\)|\b)/i', 'REAL', $s );
                        // varchar -> TEXT
                        $s = preg_replace( '/\b(var)?char\s*\(.*?\)/i', 'TEXT', $s );
                        // TEXT normalization
index e1a21f6..252a3ac 100644 (file)
@@ -44,6 +44,10 @@ class DatabaseSqliteTest extends PHPUnit_Framework_TestCase {
                        foo_bar char(13), foo_name varchar(255) binary NOT NULL DEFAULT '', foo_int tinyint ( 8 ), foo_int2 int(16) ) ENGINE=MyISAM;" )
                        );
 
+               $this->assertEquals( "CREATE TABLE foo ( foo1 REAL, foo2 REAL, foo3 REAL );",
+                       $this->replaceVars( "CREATE TABLE foo ( foo1 FLOAT, foo2 DOUBLE( 1,10), foo3 DOUBLE PRECISION );" )
+                       );
+
                $this->assertEquals( "CREATE TABLE foo ( foo_binary1 BLOB, foo_binary2 BLOB );",
                        $this->replaceVars( "CREATE TABLE foo ( foo_binary1 binary(16), foo_binary2 varbinary(32) );" )
                        );