Fix numeric values not being quoted for MySQL set columns.

Set columns should always have their values quoted. Not quoting values
makes MySQL do bad things.

Refs #5649
This commit is contained in:
mark_story 2015-01-14 22:18:13 -05:00
parent d39c744c28
commit d4a6d3f6c0
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);
}
}