diff options
| author | wei <> | 2006-07-16 06:19:36 +0000 | 
|---|---|---|
| committer | wei <> | 2006-07-16 06:19:36 +0000 | 
| commit | c7d41e5bea4a5f96979a08da9cc9f79355edfe70 (patch) | |
| tree | 8f21cba052c1eae7c7204ac272dd8c5e9d6fe110 /framework/DataAccess/SQLMap/Statements | |
| parent | af68030fcf0c266300feb2c100149ecadef7d364 (diff) | |
Update Time Tracker demo.
Diffstat (limited to 'framework/DataAccess/SQLMap/Statements')
4 files changed, 54 insertions, 26 deletions
| diff --git a/framework/DataAccess/SQLMap/Statements/TInsertMappedStatement.php b/framework/DataAccess/SQLMap/Statements/TInsertMappedStatement.php index 7a444c89..51731a5c 100644 --- a/framework/DataAccess/SQLMap/Statements/TInsertMappedStatement.php +++ b/framework/DataAccess/SQLMap/Statements/TInsertMappedStatement.php @@ -6,26 +6,26 @@ class TInsertMappedStatement extends TMappedStatement  								$keyProperty, $valueProperty=null)
  	{
  		throw new TSqlMapExecutionException(
 -				'sqlmap_cannot_execute_query_for_map', get_class($this));
 +				'sqlmap_cannot_execute_query_for_map', get_class($this), $this->getID());
  	}
  	public function executeUpdate($connection, $parameter)
  	{
  		throw new TSqlMapExecutionException(
 -				'sqlmap_cannot_execute_update', get_class($this));
 +				'sqlmap_cannot_execute_update', get_class($this), $this->getID());
  	}
  	public function executeQueryForList($connection, $parameter, $result,
  										$skip=-1, $max=-1)
  	{
  		throw new TSqlMapExecutionException(
 -				'sqlmap_cannot_execute_query_for_list', get_class($this));
 +				'sqlmap_cannot_execute_query_for_list', get_class($this), $this->getID());
  	}
  	public function executeQueryForObject($connection, $parameter, $result)
  	{
  		throw new TSqlMapExecutionException(
 -				'sqlmap_cannot_execute_query_for_object', get_class($this));
 +				'sqlmap_cannot_execute_query_for_object', get_class($this), $this->getID());
  	}
  }
 diff --git a/framework/DataAccess/SQLMap/Statements/TMappedStatement.php b/framework/DataAccess/SQLMap/Statements/TMappedStatement.php index 483a315a..c621f285 100644 --- a/framework/DataAccess/SQLMap/Statements/TMappedStatement.php +++ b/framework/DataAccess/SQLMap/Statements/TMappedStatement.php @@ -375,18 +375,23 @@ class TMappedStatement extends TComponent implements IMappedStatement  	 * @return object the object.
  	 * @see executeQueryForObject()
  	 */
 -	public function runQueryForObject($connection, $sql, $result)
 +	public function runQueryForObject($connection, $sql, &$result)
  	{
  		$recordSet = $this->executeSQLQuery($connection, $sql);
 -		$object = $this->applyResultMap($recordSet->fetchRow(), $result);
 -		//get group by result
 +		$object = null;
 +		
 +		while($row = $recordSet->fetchRow())
 +			$object = $this->applyResultMap($row, $result);	
 +
  		foreach($this->getGroupbyResults() as $group)
  			$object = $group->updateProperties();
 +
  		$this->clearGroupByResults();
  		$this->executePostSelect($connection);
  		$this->onExecuteQuery($sql);
 +		
  		return $object;
  	}
 @@ -403,7 +408,7 @@ class TMappedStatement extends TComponent implements IMappedStatement  		$sql = $this->_command->create($connection, $this->_statement, $parameter);
 -		$this->executeSQLQuery($connection, $sql);
 +		$result = $this->executeSQLQuery($connection, $sql);
  		if(is_null($generatedKey))
  			$generatedKey = $this->getPostGeneratedSelectKey($connection, $parameter);
 @@ -525,7 +530,7 @@ class TMappedStatement extends TComponent implements IMappedStatement  	 * @param object the result object, will create if necessary.
  	 * @return object the result filled with data, null if not filled.
  	 */
 -	protected function applyResultMap($row, $resultObject=null)
 +	protected function applyResultMap($row, &$resultObject=null)
  	{
  		if($row === false) return null;
 @@ -550,7 +555,7 @@ class TMappedStatement extends TComponent implements IMappedStatement  	protected function fillResultClass($resultClass, $row, $resultObject)
  	{
  		if(is_null($resultObject))
 -			$resultObject = $this->_statement->createInstanceOfResultClass();
 +			$resultObject = $this->_statement->createInstanceOfResultClass($row);
  		if($resultObject instanceOf ArrayAccess)
  			return $this->fillResultArrayList($row, $resultObject);
 @@ -608,14 +613,13 @@ class TMappedStatement extends TComponent implements IMappedStatement  	 * @param object result object to fill, will create new instances if required.
  	 * @return object result object filled with data.
  	 */
 -	protected function fillResultMap($resultMapName, $row, $resultObject)
 +	protected function fillResultMap($resultMapName, $row, &$resultObject)
  	{
  		$resultMap = $this->_sqlMap->getResultMap($resultMapName);
  		$resultMap = $resultMap->resolveSubMap($row);
  		if(is_null($resultObject))
  			$resultObject = $resultMap->createInstanceOfResult();
 -
  		if(is_object($resultObject))
  		{
  			if(strlen($resultMap->getGroupBy()) > 0)
 @@ -641,21 +645,41 @@ class TMappedStatement extends TComponent implements IMappedStatement  	 * @see getGroupByResults()
  	 * @see runQueryForList()
  	 */
 -	protected function addResultMapGroupBy($resultMap, $row, $resultObject)
 +	protected function addResultMapGroupBy($resultMap, $row, &$resultObject)
  	{
  		$group = $this->getResultMapGroupKey($resultMap, $row, $resultObject);
 +		
  		foreach($resultMap->getColumns() as $property)
  		{
 -			$this->setObjectProperty($resultMap, $property, $row, $resultObject);
 +			$scalar = $this->setObjectProperty($resultMap, $property, $row, $resultObject);
  			if(strlen($property->getResultMapping()) > 0)
  			{
  				$key = $property->getProperty();
 -				$value = TPropertyAccess::get($resultObject, $key);
 -				$this->_groupBy[$group]->addValue($key, $value);
 +				$value = $this->extractGroupByValue($property, $resultObject);
 +				if(!empty($value))
 +					$this->_groupBy[$group]->addValue($key, $value);
  			}
  		}
 +		
  		return null;
  	}
 +	
 +	/**
 +	 * Extract value from the object for later adding to a GroupBy collection.
 +	 * @param TResultProperty result property
 +	 * @param mixed result object
 +	 * @return mixed collection element
 +	 */
 +	protected function extractGroupByValue($property, $resultObject)
 +	{
 +		$key = $property->getProperty();	
 +		$value = TPropertyAccess::get($resultObject, $key);
 +		$type = strtolower($property->getType());
 +		if(($type == 'array' || $type == 'map') && is_array($value) && count($value) == 1)
 +			return $value[0];
 +		else
 +			return $value;
 +	}
  	/**
  	 * Gets the result 'group by' groupping key for each row.
 @@ -747,7 +771,7 @@ class TMappedStatement extends TComponent implements IMappedStatement  	 * @param array a result set row retrieved from the database
  	 * @param object the result object
  	 */
 -	protected function setObjectProperty($resultMap, $property, $row, $resultObject)
 +	protected function setObjectProperty($resultMap, $property, $row, &$resultObject)
  	{
  		$select = $property->getSelect();
  		$key = $property->getProperty();
 @@ -756,8 +780,12 @@ class TMappedStatement extends TComponent implements IMappedStatement  		if(strlen($select) == 0 && is_null($nested))
  		{
  			$value = $property->getDatabaseValue($row);
 -			TPropertyAccess::set($resultObject, $key, $value);
 +			
  			$this->_IsRowDataFound = $this->_IsRowDataFound || ($value != null);
 +			if(is_array($resultObject) || is_object($resultObject))
 +				TPropertyAccess::set($resultObject, $key, $value);
 +			else
 +				$resultObject = $value;
  		}
  		else if(!is_null($nested))
  		{
 @@ -844,12 +872,12 @@ class TMappedStatement extends TComponent implements IMappedStatement  	 * @param object the result object
  	 * @return boolean true if the data was found, false otherwise.
  	 */
 -	protected function fillPropertyWithResultMap($resultMap, $row, $resultObject)
 +	protected function fillPropertyWithResultMap($resultMap, $row, &$resultObject)
  	{
  		$dataFound = false;
  		foreach($resultMap->getColumns() as $property)
  		{
 -			$this->_IsRowDataFound = false;
 +			$this->_IsRowDataFound = false;		
  			$this->setObjectProperty($resultMap, $property, $row, $resultObject);
  			$dataFound = $dataFound || $this->_IsRowDataFound;
  		}
 diff --git a/framework/DataAccess/SQLMap/Statements/TSelectMappedStatement.php b/framework/DataAccess/SQLMap/Statements/TSelectMappedStatement.php index 1171e28f..b6f179c0 100644 --- a/framework/DataAccess/SQLMap/Statements/TSelectMappedStatement.php +++ b/framework/DataAccess/SQLMap/Statements/TSelectMappedStatement.php @@ -5,13 +5,13 @@ class TSelectMappedStatement extends TMappedStatement  	public function executeInsert($connection, $parameter)
  	{
  		throw new TSqlMapExecutionException(
 -				'sqlmap_cannot_execute_insert', get_class($this));
 +				'sqlmap_cannot_execute_insert', get_class($this), $this->getID());
  	}
  	public function executeUpdate($connection, $parameter)
  	{
  		throw new TSqlMapExecutionException(
 -				'sqlmap_cannot_execute_update', get_class($this));
 +				'sqlmap_cannot_execute_update', get_class($this), $this->getID());
  	}
  }
 diff --git a/framework/DataAccess/SQLMap/Statements/TUpdateMappedStatement.php b/framework/DataAccess/SQLMap/Statements/TUpdateMappedStatement.php index cf16ee52..353f4b26 100644 --- a/framework/DataAccess/SQLMap/Statements/TUpdateMappedStatement.php +++ b/framework/DataAccess/SQLMap/Statements/TUpdateMappedStatement.php @@ -5,27 +5,27 @@ class TUpdateMappedStatement extends TMappedStatement  	public function executeInsert($connection, $parameter)
  	{
  		throw new TSqlMapExecutionException(
 -				'sqlmap_cannot_execute_insert', get_class($this));
 +				'sqlmap_cannot_execute_insert', get_class($this), $this->getID());
  	}
  	public function executeQueryForMap($connection, $parameter, $keyProperty, 
  											$valueProperty=null)
  	{
  		throw new TSqlMapExecutionException(
 -				'sqlmap_cannot_execute_query_for_map', get_class($this));
 +				'sqlmap_cannot_execute_query_for_map', get_class($this), $this->getID());
  	}
  	public function executeQueryForList($connection, $parameter, $result,
  										$skip=-1, $max=-1)
  	{
  		throw new TSqlMapExecutionException(
 -				'sqlmap_cannot_execute_query_for_list', get_class($this));
 +				'sqlmap_cannot_execute_query_for_list', get_class($this), $this->getID());
  	}
  	public function executeQueryForObject($connection, $parameter, $result)
  	{
  		throw new TSqlMapExecutionException(
 -				'sqlmap_cannot_execute_query_for_object', get_class($this));
 +				'sqlmap_cannot_execute_query_for_object', get_class($this), $this->getID());
  	}
  }
 | 
