diff options
-rw-r--r-- | .gitattributes | 1 | ||||
-rw-r--r-- | framework/Data/SqlMap/Statements/TCachingStatement.php | 16 | ||||
-rw-r--r-- | framework/Data/SqlMap/Statements/TMappedStatement.php | 8 | ||||
-rw-r--r-- | framework/Data/SqlMap/TSqlMapGateway.php | 8 | ||||
-rw-r--r-- | tests/simple_unit/SqlMap/TestQueryForMap.php | 43 |
5 files changed, 60 insertions, 16 deletions
diff --git a/.gitattributes b/.gitattributes index dac6711d..dfdf47c8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2716,6 +2716,7 @@ tests/simple_unit/SqlMap/SelectKeyTest.php -text tests/simple_unit/SqlMap/SqlMapCacheTest.php -text tests/simple_unit/SqlMap/StatementExtendsTest.php -text tests/simple_unit/SqlMap/StatementTest.php -text +tests/simple_unit/SqlMap/TestQueryForMap.php -text tests/simple_unit/SqlMap/common.php -text tests/simple_unit/SqlMap/domain/A.php -text tests/simple_unit/SqlMap/domain/Account.php -text diff --git a/framework/Data/SqlMap/Statements/TCachingStatement.php b/framework/Data/SqlMap/Statements/TCachingStatement.php index 051a8ec3..4d39993d 100644 --- a/framework/Data/SqlMap/Statements/TCachingStatement.php +++ b/framework/Data/SqlMap/Statements/TCachingStatement.php @@ -42,15 +42,15 @@ class TCachingStatement implements IMappedStatement return $this->_mappedStatement->getManager();
}
- public function executeQueryForMap($connection, $parameter,$keyProperty, $valueProperty=null, $delegate=null)
+ public function executeQueryForMap($connection, $parameter,$keyProperty, $valueProperty=null, $skip=-1, $max=-1,$delegate=null)
{
- $sql = $this->createCommand($connection, $parameter);
- $key = $this->getCacheKey(array(clone($sql), $keyProperty, $valueProperty));
+ $sql = $this->createCommand($connection, $parameter, $skip, $max);
+ $key = $this->getCacheKey(array(clone($sql), $keyProperty, $valueProperty,$skip, $max));
$map = $this->getStatement()->getCache()->get($key);
if(is_null($map))
{
$map = $this->_mappedStatement->runQueryForMap(
- $connection, $parameter, $sql, $keyProperty, $valueProperty, $delegate);
+ $connection, $parameter, $sql, $keyProperty, $valueProperty, $delegate);
$this->getStatement()->getCache()->set($key, $map);
}
return $map;
@@ -68,13 +68,13 @@ class TCachingStatement implements IMappedStatement public function executeQueryForList($connection, $parameter, $result=null, $skip=-1, $max=-1, $delegate=null)
{
- $sql = $this->createCommand($connection, $parameter);
+ $sql = $this->createCommand($connection, $parameter, $skip, $max);
$key = $this->getCacheKey(array(clone($sql), $parameter, $skip, $max));
$list = $this->getStatement()->getCache()->get($key);
if(is_null($list))
{
$list = $this->_mappedStatement->runQueryForList(
- $connection, $parameter, $sql, $result, $skip, $max, $delegate);
+ $connection, $parameter, $sql, $result, $delegate);
$this->getStatement()->getCache()->set($key, $list);
}
return $list;
@@ -99,10 +99,10 @@ class TCachingStatement implements IMappedStatement return $cacheKey->getHash();
}
- protected function createCommand($connection, $parameter)
+ protected function createCommand($connection, $parameter, $skip=null, $max=null)
{
return $this->_mappedStatement->getCommand()->create($this->getManager(),
- $connection, $this->getStatement(), $parameter);
+ $connection, $this->getStatement(), $parameter, $skip, $max);
}
}
diff --git a/framework/Data/SqlMap/Statements/TMappedStatement.php b/framework/Data/SqlMap/Statements/TMappedStatement.php index db02857f..3b935e7f 100644 --- a/framework/Data/SqlMap/Statements/TMappedStatement.php +++ b/framework/Data/SqlMap/Statements/TMappedStatement.php @@ -204,7 +204,7 @@ class TMappedStatement extends TComponent implements IMappedStatement public function executeQueryForList($connection, $parameter, $result=null, $skip=-1, $max=-1, $delegate=null)
{
$sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter,$skip,$max);
- return $this->runQueryForList($connection, $parameter, $sql, $result, $skip, $max, $delegate);
+ return $this->runQueryForList($connection, $parameter, $sql, $result, $delegate);
}
/**
@@ -223,7 +223,7 @@ class TMappedStatement extends TComponent implements IMappedStatement * @return array a list of result objects
* @see executeQueryForList()
*/
- public function runQueryForList($connection, $parameter, $sql, $result, $skip=-1, $max=-1, $delegate=null)
+ public function runQueryForList($connection, $parameter, $sql, $result, $delegate=null)
{
$registry=$this->getManager()->getTypeHandlers();
$list = $result instanceof ArrayAccess ? $result :
@@ -274,9 +274,9 @@ class TMappedStatement extends TComponent implements IMappedStatement * @param callback row delegate handler
* @return array An array of object containing the rows keyed by keyProperty.
*/
- public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty=null, $delegate=null)
+ public function executeQueryForMap($connection, $parameter, $keyProperty, $valueProperty=null, $skip=-1, $max=-1, $delegate=null)
{
- $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter);
+ $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter, $skip, $max);
return $this->runQueryForMap($connection, $parameter, $sql, $keyProperty, $valueProperty, $delegate);
}
diff --git a/framework/Data/SqlMap/TSqlMapGateway.php b/framework/Data/SqlMap/TSqlMapGateway.php index b2819740..51a13a82 100644 --- a/framework/Data/SqlMap/TSqlMapGateway.php +++ b/framework/Data/SqlMap/TSqlMapGateway.php @@ -163,10 +163,10 @@ class TSqlMapGateway extends TComponent * @param string The property of the result object to be used as the value.
* @return TMap Array object containing the rows keyed by keyProperty.
*/
- public function queryForMap($statementName, $parameter=null, $keyProperty=null, $valueProperty=null)
+ public function queryForMap($statementName, $parameter=null, $keyProperty=null, $valueProperty=null, $skip=-1, $max=-1)
{
$statement = $this->getSqlMapManager()->getMappedStatement($statementName);
- return $statement->executeQueryForMap($this->getDbConnection(), $parameter, $keyProperty, $valueProperty);
+ return $statement->executeQueryForMap($this->getDbConnection(), $parameter, $keyProperty, $valueProperty, $skip, $max);
}
/**
@@ -182,10 +182,10 @@ class TSqlMapGateway extends TComponent * @param string The property of the result object to be used as the value.
* @return TMap Array object containing the rows keyed by keyProperty.
*/
- public function queryForMapWithRowDelegate($statementName, $delegate, $parameter=null, $keyProperty=null, $valueProperty=null)
+ public function queryForMapWithRowDelegate($statementName, $delegate, $parameter=null, $keyProperty=null, $valueProperty=null, $skip=-1, $max=-1)
{
$statement = $this->getSqlMapManager()->getMappedStatement($statementName);
- return $statement->executeQueryForMap($this->getDbConnection(), $parameter, $keyProperty, $valueProperty, $delegate);
+ return $statement->executeQueryForMap($this->getDbConnection(), $parameter, $keyProperty, $valueProperty, $skip, $max, $delegate);
}
/**
diff --git a/tests/simple_unit/SqlMap/TestQueryForMap.php b/tests/simple_unit/SqlMap/TestQueryForMap.php new file mode 100644 index 00000000..25ef2f4d --- /dev/null +++ b/tests/simple_unit/SqlMap/TestQueryForMap.php @@ -0,0 +1,43 @@ +<?php
+require_once(dirname(__FILE__).'/BaseCase.php');
+
+class TestQueryForMap extends BaseCase
+{
+ function __construct()
+ {
+ parent::__construct();
+ $this->initSqlMap();
+ }
+
+ /**
+ * Test ExecuteQueryForMap : Hashtable.
+ */
+ function testExecuteQueryForMap()
+ {
+ $map = $this->sqlmap->QueryForMap("GetAllAccountsViaResultClass", null, "FirstName",null,0,2);
+ $this->assertIdentical(2, count($map));
+ $this->assertAccount1($map["Joe"]);
+
+ $this->assertIdentical(1, $map["Joe"]->getID());
+ $this->assertIdentical(2, $map["Averel"]->getID());
+ }
+
+ /**
+ * Test ExecuteQueryForMap with value property :
+ * "FirstName" as key, "EmailAddress" as value
+ */
+ function testExecuteQueryForMapWithValueProperty()
+ {
+ $map = $this->sqlmap->QueryForMap("GetAllAccountsViaResultClass", null,
+ "FirstName", "EmailAddress",1,3);
+
+ $this->assertIdentical(3, count($map));
+
+ $this->assertIdentical("Averel.Dalton@somewhere.com", $map["Averel"]);
+ $this->assertNull($map["William"]);
+ $this->assertIdentical("Jack.Dalton@somewhere.com", $map["Jack"]);
+ }
+
+}
+
+?>
\ No newline at end of file |