Fixed bugs #5044/#11142: Column's default value is not properly quoted in CREATE...
authorXavier Perseguers <typo3@perseguers.ch>
Fri, 20 Nov 2009 12:40:56 +0000 (12:40 +0000)
committerXavier Perseguers <typo3@perseguers.ch>
Fri, 20 Nov 2009 12:40:56 +0000 (12:40 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/dbal/trunk@26752 735d13b6-9817-0410-8766-e36946ffe9aa

typo3/sysext/dbal/ChangeLog
typo3/sysext/dbal/class.ux_t3lib_sqlparser.php
typo3/sysext/dbal/tests/db_oracle_testcase.php

index 8e704e2..8a6aa2e 100644 (file)
@@ -1,5 +1,6 @@
 2009-11-20  Xavier Perseguers  <typo3@perseguers.ch>
 
+       * Fixed bugs #5044/#11142: Column's default value is not properly quoted in CREATE TABLE
        * Added unit-test for bug #12670: Columns with NOT NULL are created as NULLable
 
 2009-11-17  Xavier Perseguers  <typo3@perseguers.ch>
index 9657210..8438e37 100644 (file)
@@ -613,6 +613,7 @@ class ux_t3lib_sqlparser extends t3lib_sqlparser {
                                }
 
                                        // Add additional features:
+                               $noQuote = TRUE;
                                if (is_array($fieldCfg['featureIndex'])) {
 
                                                // MySQL assigns DEFAULT value automatically if NOT NULL, fake this here
@@ -651,11 +652,16 @@ class ux_t3lib_sqlparser extends t3lib_sqlparser {
                                                                $cfg .= ' "\'\'"';
                                                        } else {
                                                                $cfg .= ' ' . $featureDef['value'][1] . $this->compileAddslashes($featureDef['value'][0]) . $featureDef['value'][1];
+                                                               if (!is_numeric($featureDef['value'][0])) {
+                                                                       $noQuote = FALSE;
+                                                               }
                                                        }
                                                }
                                        }
                                }
-                               $cfg .= ' NOQUOTE';
+                               if ($noQuote) {
+                                       $cfg .= ' NOQUOTE';
+                               }
                                break;
                }
 
index f1ed86e..b6760ea 100644 (file)
@@ -332,5 +332,44 @@ class db_oracle_testcase extends BaseTestCase {
                ');
                $this->assertEquals($expected, $this->cleanSql($sqlCommands[0]));
        }
+
+       /**
+        * @test
+        * @see http://bugs.typo3.org/view.php?id=11142
+        * @see http://bugs.typo3.org/view.php?id=12670
+        */
+       public function defaultValueIsProperlyQuotedInCreateTable() {
+               $parseString = '
+                       CREATE TABLE tx_test (
+                               uid int(11) NOT NULL auto_increment,
+                               lastname varchar(60) DEFAULT \'unknown\' NOT NULL,
+                               firstname varchar(60) DEFAULT \'\' NOT NULL,
+                               language varchar(2) NOT NULL,
+                               tstamp int(11) DEFAULT \'0\' NOT NULL,
+                               
+                               PRIMARY KEY (uid),
+                               KEY name (name)
+                       );
+               ';
+
+               $components = $GLOBALS['TYPO3_DB']->SQLparser->_callRef('parseCREATETABLE', $parseString);
+               $this->assertTrue(is_array($components), 'Not an array: ' . $components);
+       
+               $sqlCommands = $GLOBALS['TYPO3_DB']->SQLparser->_call('compileCREATETABLE', $components);
+               $this->assertTrue(is_array($sqlCommands), 'Not an array: ' . $sqlCommands);
+               $this->assertEquals(2, count($sqlCommands));
+
+               $expected = $this->cleanSql('
+                       CREATE TABLE "tx_test" (
+                               "uid" NUMBER(20) NOT NULL,
+                               "lastname" VARCHAR(60) DEFAULT \'unknown\',
+                               "firstname" VARCHAR(60) DEFAULT \'\',
+                               "language" VARCHAR(2) NOT NULL,
+                               "tstamp" NUMBER(20) DEFAULT 0,
+                               PRIMARY KEY ("uid")
+                       )
+               ');
+               $this->assertEquals($expected, $this->cleanSql($sqlCommands[0]));
+       }
 }
 ?>
\ No newline at end of file