summaryrefslogtreecommitdiff
path: root/framework/Data/DataGateway
diff options
context:
space:
mode:
authorwei <>2007-04-22 00:28:36 +0000
committerwei <>2007-04-22 00:28:36 +0000
commit38c18b2d740f61e342f00bc33791f0f3c014e126 (patch)
tree21c12cbd25c7f1ad12d1c7b8dc3ed071a96a2034 /framework/Data/DataGateway
parent15fc4fa7120a1795c6112f88145fdfa9bc460455 (diff)
Update to Active Record to use Mysql 4.
Add TActiveRecordRelation
Diffstat (limited to 'framework/Data/DataGateway')
-rw-r--r--framework/Data/DataGateway/TDataGatewayCommand.php26
1 files changed, 21 insertions, 5 deletions
diff --git a/framework/Data/DataGateway/TDataGatewayCommand.php b/framework/Data/DataGateway/TDataGatewayCommand.php
index dbabd2b7..43a57aa7 100644
--- a/framework/Data/DataGateway/TDataGatewayCommand.php
+++ b/framework/Data/DataGateway/TDataGatewayCommand.php
@@ -177,6 +177,18 @@ class TDataGatewayCommand extends TComponent
return $this->onExecuteCommand($command,$command->query());
}
+ public function findAllByIndex($criteria,$fields,$values)
+ {
+ $index = $this->getIndexKeyCondition($fields,$values);
+ if(strlen($where = $criteria->getCondition())>0)
+ $criteria->setCondition("({$index}) AND ({$where})");
+ else
+ $criteria->setCondition($index);
+ $command = $this->getFindCommand($criteria);
+ $this->onCreateCommand($command, $criteria);
+ return $this->onExecuteCommand($command,$command->query());
+ }
+
/**
* @param array multiple primary key values or composite value arrays
* @return integer number of rows affected.
@@ -190,6 +202,14 @@ class TDataGatewayCommand extends TComponent
return $this->onExecuteCommand($command,$command->execute());
}
+ protected function getIndexKeyCondition($fields,$values)
+ {
+ $columns = array();
+ foreach($fields as $field)
+ $columns[] = $this->getTableInfo()->getColumn($field)->getColumnName();
+ return '('.implode(', ',$columns).') IN '.$this->quoteTuple($values);
+ }
+
/**
* Construct a "pk IN ('key1', 'key2', ...)" criteria.
* @param array values for IN predicate
@@ -216,11 +236,7 @@ class TDataGatewayCommand extends TComponent
throw new TDbException('dbtablegateway_pk_value_count_mismatch',
$this->getTableInfo()->getTableFullName());
}
-
- $columns = array();
- foreach($primary as $key)
- $columns[] = $this->getTableInfo()->getColumn($key)->getColumnName();
- return '('.implode(', ',$columns).') IN '.$this->quoteTuple($values);
+ return $this->getIndexKeyCondition($primary, $values);
}
/**