Bug #20346
closedDBAL: Float database field gets converted to integer on insert
0%
Description
Example Database (must be included via dummy extension to get a value from sql_field_metatype):
CREATE TABLE tx_example (
foo double default '0'
);
Example PHP-Code:
$insertArray['foo'] = 99.12;
// save data
$result = $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_example', $insertArray);
// get data
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tx_example', '1=1');
$row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
$foo = $row['foo'];
// test data
if($foo != $insertArray['foo']) {
die("error: $foo != {$insertArray['foo']}");
}
So after inserting the database value is '99' and not '99.12'.
Possible solution in typo3/sysext/dbal/class.ux_t3lib_db.php:
Before:
} else {
// Add slashes old-school:
// cast numerical values
$mt = $this->sql_field_metatype($table,$k);
$v = (($mt{0}=='I')||($mt{0}=='F')) ? (int)$v : $v;
$nArr[$this->quoteFieldNames($k)] = (!in_array($k,$no_quote_fields)) ? $this->fullQuoteStr($v, $table) : $v;
}
After:
Before:
} else {
// Add slashes old-school:
// cast numerical values
$mt = $this->sql_field_metatype($table,$k);
$v = (($mt{0}=='I')) ? (int)$v : $v;
$nArr[$this->quoteFieldNames($k)] = (!in_array($k,$no_quote_fields)) ? $this->fullQuoteStr($v, $table) : $v;
}
PHP: 5.2.6
MySQL: 5.0.67
Typo3: 4.2.6
DBAL: 0.9.20
(issue imported from #M10965)
Files