I found that retrieving from the database gives the correct precision, so the rounding problem only occurs on saving. I've tested doctrine versions 1.0.13 (through symfony), 1.1.4, and 1.2 alpha2 - all have this problem.
//require_once('lib/vendor/Doctrine-1.2.0/lib/Doctrine.php');
require_once('lib/vendor/Doctrine-1.1.4/Doctrine.php');
spl_autoload_register(array('Doctrine', 'autoload'));
class TestRecord extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('test');
$this->hasColumn('id', 'integer', null, array(
'type' => 'integer',
'notnull' => false,
'primary' => true,
'autoincrement' => true,
));
$this->hasColumn('test_field', 'decimal', 18, array(
'scale' => 12,
));
}
}
$pdo = new PDO('sqlite:testdb.db');
//$pdo = new PDO('mysql:host=localhost;dbname=testdb', 'root', 'pass');
$conn = Doctrine_Manager::connection($pdo);
// test retreival of value (first row has 12.891841075016 inserted manually)
$q = Doctrine_Query::create()->from('TestRecord')
->where('id = ?', 1);
$record = $q->fetchOne();
echo 'retrieved value = ', $record['test_field'], "\n";
// outputs 12.891841075016 (OK)
// test save of high precision decimal
$test = new TestRecord();
$test['test_field'] = 12.891841075016;
$test->save();
// database shows 12.891841000000 (rounded incorrectly)
I found that retrieving from the database gives the correct precision, so the rounding problem only occurs on saving. I've tested doctrine versions 1.0.13 (through symfony), 1.1.4, and 1.2 alpha2 - all have this problem.
//require_once('lib/vendor/Doctrine-1.2.0/lib/Doctrine.php');
require_once('lib/vendor/Doctrine-1.1.4/Doctrine.php');
spl_autoload_register(array('Doctrine', 'autoload'));
class TestRecord extends Doctrine_Record
{ $this->setTableName('test'); $this->hasColumn('id', 'integer', null, array( 'type' => 'integer', 'notnull' => false, 'primary' => true, 'autoincrement' => true, )); $this->hasColumn('test_field', 'decimal', 18, array( 'scale' => 12, )); }{
public function setTableDefinition()
}
$pdo = new PDO('sqlite:testdb.db');
//$pdo = new PDO('mysql:host=localhost;dbname=testdb', 'root', 'pass');
$conn = Doctrine_Manager::connection($pdo);
// test retreival of value (first row has 12.891841075016 inserted manually)
$q = Doctrine_Query::create()->from('TestRecord')
->where('id = ?', 1);
$record = $q->fetchOne();
echo 'retrieved value = ', $record['test_field'], "\n";
// outputs 12.891841075016 (OK)
// test save of high precision decimal
$test = new TestRecord();
$test['test_field'] = 12.891841075016;
$test->save();
// database shows 12.891841000000 (rounded incorrectly)