From e48cd54a418436ab7f14ad15178a7b6355e7b47e Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 22 Jul 2008 13:12:53 +0000 Subject: [PATCH] - DibiTable::$types enables auto-convert columns to specified type - DibiTable::insert() returns NULL, when $primary is FALSE --- dibi/libs/DibiResult.php | 6 +++--- dibi/libs/DibiTable.php | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/dibi/libs/DibiResult.php b/dibi/libs/DibiResult.php index 3d241fc8..35c9c764 100644 --- a/dibi/libs/DibiResult.php +++ b/dibi/libs/DibiResult.php @@ -261,7 +261,7 @@ class DibiResult extends /*Nette::*/Object implements IDataSource if ($this->xlat !== NULL) { foreach ($this->xlat as $col => $type) { if (isset($row[$col])) { - $row[$col] = $this->convert($row[$col], $type[0], $type[1]); + $row[$col] = $this->convert($row[$col], $type['type'], $type['format']); } } } @@ -299,7 +299,7 @@ class DibiResult extends /*Nette::*/Object implements IDataSource $key = key($row); if (isset($this->xlat[$key])) { $type = $this->xlat[$key]; - return $this->convert($value, $type[0], $type[1]); + return $this->convert($value, $type['type'], $type['format']); } return $value; @@ -494,7 +494,7 @@ class DibiResult extends /*Nette::*/Object implements IDataSource */ final public function setType($col, $type, $format = NULL) { - $this->xlat[$col] = array($type, $format); + $this->xlat[$col] = array('type' => $type, 'format' => $format); } diff --git a/dibi/libs/DibiTable.php b/dibi/libs/DibiTable.php index fc116527..93fe5f83 100644 --- a/dibi/libs/DibiTable.php +++ b/dibi/libs/DibiTable.php @@ -49,6 +49,8 @@ abstract class DibiTable extends /*Nette::*/Object /** @var array */ protected $blankRow = array(); + /** @var array of pairs [type, format] */ + protected $types = array(); /** @@ -137,7 +139,10 @@ abstract class DibiTable extends /*Nette::*/Object $this->connection->query( 'INSERT INTO %n', $this->name, '%v', $this->prepare($data) ); - return $this->connection->insertId(); + + if ($this->primary) { + return $this->connection->insertId(); + } } @@ -284,6 +289,7 @@ abstract class DibiTable extends /*Nette::*/Object */ protected function complete($res) { + $res->setTypes($this->types); return $res; }