Project

General

Profile

Actions

Bug #20346

closed

DBAL: Float database field gets converted to integer on insert

Added by Christian Ducrot over 15 years ago. Updated almost 15 years ago.

Status:
Closed
Priority:
Should have
Category:
Database API (Doctrine DBAL)
Target version:
-
Start date:
2009-04-23
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

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

10965.diff (2.44 KB) 10965.diff Administrator Admin, 2009-11-09 19:28

Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Bug #20427: DBAL - bigint (int8) values get converted to int4 by int-castClosed2009-05-15

Actions
Related to TYPO3 Core - Bug #17574: Double values are truncated to their prefixesClosedXavier Perseguers2007-08-31

Actions
Actions

Also available in: Atom PDF