diff options
author | wei <> | 2007-04-14 05:02:29 +0000 |
---|---|---|
committer | wei <> | 2007-04-14 05:02:29 +0000 |
commit | 0f0d3c62e608287cdf77f1a3239371b521ecb40b (patch) | |
tree | bd91a9499a946e1667a0e17a9c5a97a9d695c7ce /framework/Data/Common/TDbCommandBuilder.php | |
parent | b05442bbe751b87998d8500ad8e6b28d652a35db (diff) |
Refactor ActiveRecordGateway to use TDataGatewayCommand
Diffstat (limited to 'framework/Data/Common/TDbCommandBuilder.php')
-rw-r--r-- | framework/Data/Common/TDbCommandBuilder.php | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/framework/Data/Common/TDbCommandBuilder.php b/framework/Data/Common/TDbCommandBuilder.php index 2a8f93ee..2c3578f0 100644 --- a/framework/Data/Common/TDbCommandBuilder.php +++ b/framework/Data/Common/TDbCommandBuilder.php @@ -67,6 +67,20 @@ class TDbCommandBuilder extends TComponent }
/**
+ * Iterate through all the columns and returns the last insert id of the
+ * first column that has a sequence or serial.
+ * @return mixed last insert id, null if none is found.
+ */
+ public function getLastInsertID()
+ {
+ foreach($this->getTableInfo()->getColumns() as $column)
+ {
+ if($column->hasSequence())
+ return $this->getDbConnection()->getLastInsertID($column->getSequenceName());
+ }
+ }
+
+ /**
* Alters the sql to apply $limit and $offset. Default implementation is applicable
* for PostgreSQL, MySQL and SQLite.
* @param string SQL query string.
@@ -122,6 +136,8 @@ class TDbCommandBuilder extends TComponent */
public function createFindCommand($where='1=1', $parameters=array(), $ordering=array(), $limit=-1, $offset=-1)
{
+ if($where===null)
+ $where='1=1';
$table = $this->getTableInfo()->getTableFullName();
$sql = "SELECT * FROM {$table} WHERE {$where}";
if(count($ordering) > 0)
@@ -141,6 +157,8 @@ class TDbCommandBuilder extends TComponent */
public function createCountCommand($where='1=1', $parameters=array(),$ordering=array(), $limit=-1, $offset=-1)
{
+ if($where===null)
+ $where='1=1';
$table = $this->getTableInfo()->getTableFullName();
$sql = "SELECT COUNT(*) FROM {$table} WHERE {$where}";
if(count($ordering) > 0)
|