Browse Source

Quote identifiers for numeric fields on insert queries.

Quote numeric column names as we would quote string column names.

Refs #9391
Mark Story 9 years ago
parent
commit
394fcfc236
2 changed files with 24 additions and 1 deletions
  1. 1 1
      src/Database/IdentifierQuoter.php
  2. 23 0
      tests/TestCase/Database/QueryTest.php

+ 1 - 1
src/Database/IdentifierQuoter.php

@@ -180,7 +180,7 @@ class IdentifierQuoter
         list($table, $columns) = $query->clause('insert');
         $table = $this->_driver->quoteIdentifier($table);
         foreach ($columns as &$column) {
-            if (is_string($column)) {
+            if (is_scalar($column)) {
                 $column = $this->_driver->quoteIdentifier($column);
             }
         }

+ 23 - 0
tests/TestCase/Database/QueryTest.php

@@ -2931,6 +2931,29 @@ class QueryTest extends TestCase
     }
 
     /**
+     * Test insert queries quote integer column names
+     *
+     * @return void
+     */
+    public function testInsertQuoteColumns()
+    {
+        $this->loadFixtures('Articles');
+        $query = new Query($this->connection);
+        $query->insert([123])
+            ->into('articles')
+            ->values([
+                123 => 'mark',
+            ]);
+        $result = $query->sql();
+        $this->assertQuotedQuery(
+            'INSERT INTO <articles> \(<123>\) (OUTPUT INSERTED\.\* )?' .
+            'VALUES \(:c0\)',
+            $result,
+            !$this->autoQuote
+        );
+    }
+
+    /**
      * Test an insert when not all the listed fields are provided.
      * Columns should be matched up where possible.
      *