From 0f0d3c62e608287cdf77f1a3239371b521ecb40b Mon Sep 17 00:00:00 2001 From: wei <> Date: Sat, 14 Apr 2007 05:02:29 +0000 Subject: Refactor ActiveRecordGateway to use TDataGatewayCommand --- framework/Data/DataGateway/TDataGatewayCommand.php | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'framework/Data/DataGateway') diff --git a/framework/Data/DataGateway/TDataGatewayCommand.php b/framework/Data/DataGateway/TDataGatewayCommand.php index a5f729d8..8a340ee7 100644 --- a/framework/Data/DataGateway/TDataGatewayCommand.php +++ b/framework/Data/DataGateway/TDataGatewayCommand.php @@ -15,7 +15,7 @@ class TDataGatewayCommand extends TComponent /** * @return TDbTableInfo */ - protected function getTableInfo() + public function getTableInfo() { return $this->_builder->getTableInfo(); } @@ -23,7 +23,7 @@ class TDataGatewayCommand extends TComponent /** * @return TDbConnection */ - protected function getDbConnection() + public function getDbConnection() { return $this->_builder->getDbConnection(); } @@ -31,7 +31,7 @@ class TDataGatewayCommand extends TComponent /** * @return TDbCommandBuilder */ - protected function getBuilder() + public function getBuilder() { return $this->_builder; } @@ -65,6 +65,17 @@ class TDataGatewayCommand extends TComponent return $command->execute(); } + /** + * @param array update for update + * @param array primary key-value name pairs. + * @return integer number of records affected. + */ + public function updateByPk($data, $keys) + { + list($where, $parameters) = $this->getPrimaryKeyCondition((array)$keys); + return $this->update($data, new TSqlCriteria($where, $parameters)); + } + /** * Find one record matching the critera. * @param TSqlCriteria find conditions and parameters. @@ -281,11 +292,7 @@ class TDataGatewayCommand extends TComponent */ public function getLastInsertID() { - foreach($this->getTableInfo()->getColumns() as $column) - { - if($column->hasSequence()) - return $this->getDbConnection()->getLastInsertID($column->getSequenceName()); - } + return $this->getBuilder()->getLastInsertID(); } /** -- cgit v1.2.3