Fixed bug #10965: Float database field gets converted to integer on insert (thanks...
authorXavier Perseguers <typo3@perseguers.ch>
Mon, 9 Nov 2009 18:49:39 +0000 (18:49 +0000)
committerXavier Perseguers <typo3@perseguers.ch>
Mon, 9 Nov 2009 18:49:39 +0000 (18:49 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/dbal/trunk@26345 735d13b6-9817-0410-8766-e36946ffe9aa

typo3/sysext/dbal/ChangeLog
typo3/sysext/dbal/class.ux_t3lib_db.php
typo3/sysext/dbal/tests/db_general_testcase.php

index 080b05f..a5c2e76 100644 (file)
@@ -1,5 +1,6 @@
 2009-11-09  Xavier Perseguers  <typo3@perseguers.ch>
 
+       * Fixed bug #10965: Float database field gets converted to integer on insert (thanks to Christian Ducrot)
        * Fixed bug #12515: DAM-related: CONCAT operator cannot be used after LIKE
        * Fixed bug #10411: Applied missing chunks of patch
 
index 7888984..3d2674e 100644 (file)
@@ -766,7 +766,11 @@ class ux_t3lib_DB extends t3lib_DB {
                                                // Add slashes old-school:
                                                // cast numerical values
                                        $mt = $this->sql_field_metatype($table, $k);
-                                       $v = (($mt{0} == 'I') || ($mt{0} == 'F')) ? (int)$v : $v;
+                                       if ($mt{0} == 'I') {
+                                               $v = (int)$v;
+                                       } else if ($mt{0} == 'F') {
+                                               $v = (double)$v;
+                                       }
 
                                        $nArr[$this->quoteFieldNames($k)] = (!in_array($k,$no_quote_fields)) ? $this->fullQuoteStr($v, $table) : $v;
                                }
@@ -837,7 +841,11 @@ class ux_t3lib_DB extends t3lib_DB {
                                                        // Add slashes old-school:
                                                        // cast numeric values
                                                $mt = $this->sql_field_metatype($table, $k);
-                                               $v = (($mt{0} == 'I') || ($mt{0} == 'F')) ? (int)$v : $v;
+                                               if ($mt{0} == 'I') {
+                                                       $v = (int)$v;
+                                               } else if ($mt{0} == 'F') {
+                                                       $v = (double)$v;
+                                               }
                                                $nArr[] = $this->quoteFieldNames($k) . '=' . ((!in_array($k, $no_quote_fields)) ? $this->fullQuoteStr($v, $table) : $v);
                                        }
                                }
index 8e1b14a..8dcde8c 100644 (file)
@@ -100,5 +100,39 @@ class db_general_testcase extends BaseTestCase {
                $expected .= ' AND sys_refindex.ref_string LIKE CONCAT(tx_dam_file_tracking.file_path,tx_dam_file_tracking.file_name)';
                $this->assertEquals($expected, $query);
        }
+
+       /** 
+        * @test
+        * @see http://bugs.typo3.org/view.php?id=10965
+        */
+       public function floatNumberCanBeStoredInDatabase() {
+                       // Prepare a fake extension configuration
+               $ext_tables = t3lib_div::tempnam('ext_tables');
+               t3lib_div::writeFile($ext_tables, '
+                       CREATE TABLE tx_test_dbal (
+                               foo double default \'0\',
+                               foobar integer default \'0\'
+                       );
+               ');
+
+               $GLOBALS['TYPO3_LOADED_EXT']['test_dbal'] = array(
+                       'ext_tables.sql' => $ext_tables
+               );
+
+                       // Append our test table to the list of existing tables
+               $this->fixture->clearCachedFieldInfo();
+               $this->fixture->_call('initInternalVariables');
+
+               $data = array(
+                       'foo'    => 99.12,
+                       'foobar' => -120,
+               );
+               $query = $this->cleanSql($this->fixture->INSERTquery('tx_test_dbal', $data));
+               $expected = 'INSERT INTO tx_test_dbal ( foo, foobar ) VALUES ( \'99.12\', \'-120\' )';
+               $this->assertEquals($expected, $query);
+
+                       // Remove temporary file
+               unlink($ext_tables);
+       }
 }
 ?>
\ No newline at end of file