Skip to content

Commit

Permalink
Quote identifiers for numeric fields on insert queries.
Browse files Browse the repository at this point in the history
Quote numeric column names as we would quote string column names.

Refs #9391
  • Loading branch information
markstory committed Sep 2, 2016
1 parent 05a37af commit 394fcfc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Database/IdentifierQuoter.php
Expand Up @@ -180,7 +180,7 @@ protected function _quoteInsert($query)
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);
}
}
Expand Down
23 changes: 23 additions & 0 deletions tests/TestCase/Database/QueryTest.php
Expand Up @@ -2930,6 +2930,29 @@ public function testInsertSimple()
$this->assertTable('articles', 1, $expected, ['id >=' => 4]);
}

/**
* 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.
Expand Down

0 comments on commit 394fcfc

Please sign in to comment.