mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
d39c744c28
commit
d4a6d3f6c0
3 changed files with 36 additions and 2 deletions
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue