Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quote identifiers for numeric fields on insert queries. #9395

Merged
merged 3 commits into from Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Cache/Cache.php
Expand Up @@ -457,7 +457,7 @@ public static function clear($check = false, $config = 'default')

return $engine->clear($check);
}

/**
* Delete all keys from the cache from all configurations.
*
Expand All @@ -467,11 +467,11 @@ public static function clear($check = false, $config = 'default')
public static function clearAll($check = false)
{
$status = [];

foreach (self::configured() as $config) {
$status[$config] = self::clear($check, $config);
}

return $status;
}

Expand Down
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
2 changes: 1 addition & 1 deletion src/Http/ResponseTransformer.php
Expand Up @@ -53,7 +53,7 @@ public static function toCake(PsrResponse $response)
}
$headers = static::collapseHeaders($response);
$cake->header($headers);

if (!empty($headers['Content-Type'])) {
$cake->type($headers['Content-Type']);
}
Expand Down
7 changes: 2 additions & 5 deletions src/Network/Request.php
Expand Up @@ -584,9 +584,9 @@ public function __call($name, $params)
{
if (strpos($name, 'is') === 0) {
$type = strtolower(substr($name, 2));

array_unshift($params, $type);

return call_user_func_array([$this, 'is'], $params);
}
throw new BadMethodCallException(sprintf('Method %s does not exist', $name));
Expand Down Expand Up @@ -639,19 +639,16 @@ public function is($type)

return count(array_filter($result)) > 0;
}

$args = func_get_args();
array_shift($args);

$type = strtolower($type);
if (!isset(static::$_detectors[$type])) {
return false;
}

if ($args) {
return $this->_is($type, $args);
}

if (!isset($this->_detectorCache[$type])) {
$this->_detectorCache[$type] = $this->_is($type, $args);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Network/Session/DatabaseSession.php
Expand Up @@ -112,7 +112,7 @@ public function read($id)
if ($session === false) {
return '';
}

return $session;
}

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
2 changes: 1 addition & 1 deletion tests/TestCase/Http/MiddlewareQueueTest.php
Expand Up @@ -258,7 +258,7 @@ public function testInsertBefore()
$three = function () {
};
$four = new DumbMiddleware();

$queue = new MiddlewareQueue();
$queue->add($one)->add($two)->insertBefore(SampleMiddleware::class, $three)->insertBefore(SampleMiddleware::class, $four);

Expand Down