Merge pull request #5668 from cakephp/issue-5649

Fix numeric values not being quoted for MySQL set columns.
This commit is contained in:
Mark Story 2015-01-15 21:29:57 -05:00
commit 2a9f2d4b58
3 changed files with 36 additions and 2 deletions

View file

@ -795,6 +795,17 @@ class Mysql extends DboSource {
return 'text';
}
/**
* {@inheritDoc}
*/
public function value($data, $column = null) {
$value = parent::value($data, $column);
if (is_numeric($value) && substr($column, 0, 3) === 'set') {
return $this->_connection->quote($value);
}
return $value;
}
/**
* Gets the schema name
*

View file

@ -354,8 +354,10 @@ class DboSource extends DataSource {
return str_replace(',', '.', strval($data));
}
if ((is_int($data) || $data === '0') || (
is_numeric($data) && strpos($data, ',') === false &&
$data[0] != '0' && strpos($data, 'e') === false)
is_numeric($data) &&
strpos($data, ',') === false &&
$data[0] != '0' &&
strpos($data, 'e') === false)
) {
return $data;
}

View file

@ -553,6 +553,10 @@ class MysqlTest extends CakeTestCase {
$result = $this->Dbo->column('decimal(14,7) unsigned');
$expected = 'decimal';
$this->assertEquals($expected, $result);
$result = $this->Dbo->column("set('a','b','c')");
$expected = "set('a','b','c')";
$this->assertEquals($expected, $result);
}
/**
@ -4071,4 +4075,21 @@ SQL;
$this->Dbo->useNestedTransactions = $nested;
}
/**
* Test that value() quotes set values even when numeric.
*
* @return void
*/
public function testSetValue() {
$column = "set('a','b','c')";
$result = $this->Dbo->value('1', $column);
$this->assertEquals("'1'", $result);
$result = $this->Dbo->value(1, $column);
$this->assertEquals("'1'", $result);
$result = $this->Dbo->value('a', $column);
$this->assertEquals("'a'", $result);
}
}