| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* TPreparedCommand class file.
|
|
|
4 |
*
|
|
|
5 |
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
|
|
|
6 |
* @link http://www.pradosoft.com/
|
|
|
7 |
* @copyright Copyright © 2005-2008 PradoSoft
|
|
|
8 |
* @license http://www.pradosoft.com/license/
|
|
|
9 |
* @version $Id: TPreparedCommand.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
10 |
* @package System.Data.SqlMap.Statements
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
Prado::using('System.Data.Common.TDbMetaData');
|
|
|
14 |
Prado::using('System.Data.Common.TDbCommandBuilder');
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* TPreparedCommand class.
|
|
|
18 |
*
|
|
|
19 |
* @author Wei Zhuo <weizho[at]gmail[dot]com>
|
|
|
20 |
* @version $Id: TPreparedCommand.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
21 |
* @package System.Data.SqlMap.Statements
|
|
|
22 |
* @since 3.1
|
|
|
23 |
*/
|
|
|
24 |
class TPreparedCommand
|
|
|
25 |
{
|
|
|
26 |
public function create(TSqlMapManager $manager, $connection, $statement, $parameterObject,$skip=null,$max=null)
|
|
|
27 |
{
|
|
|
28 |
$prepared = $statement->getSQLText()->getPreparedStatement($parameterObject);
|
|
|
29 |
$connection->setActive(true);
|
|
|
30 |
$sql = $prepared->getPreparedSql();
|
|
|
31 |
if($max!==null || $skip!==null)
|
|
|
32 |
{
|
|
|
33 |
$builder = TDbMetaData::getInstance($connection)->createCommandBuilder();
|
|
|
34 |
$sql = $builder->applyLimitOffset($sql,$max,$skip);
|
|
|
35 |
}
|
|
|
36 |
$command = $connection->createCommand($sql);
|
|
|
37 |
$this->applyParameterMap($manager, $command, $prepared, $statement, $parameterObject);
|
|
|
38 |
return $command;
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
protected function applyParameterMap($manager,$command,$prepared, $statement, $parameterObject)
|
|
|
42 |
{
|
|
|
43 |
$properties = $prepared->getParameterNames();
|
|
|
44 |
$parameters = $prepared->getParameterValues();
|
|
|
45 |
$registry=$manager->getTypeHandlers();
|
|
|
46 |
for($i = 0, $k=$properties->getCount(); $i<$k; $i++)
|
|
|
47 |
{
|
|
|
48 |
$property = $statement->parameterMap()->getProperty($i);
|
|
|
49 |
$value = $statement->parameterMap()->getPropertyValue($registry,$property, $parameterObject);
|
|
|
50 |
$dbType = $property->getDbType();
|
|
|
51 |
if($dbType=='') //relies on PHP lax comparison
|
|
|
52 |
$command->bindValue($i+1,$value, TDbCommandBuilder::getPdoType($value));
|
|
|
53 |
else if(strpos($dbType, 'PDO::')===0)
|
|
|
54 |
$command->bindValue($i+1,$value, constant($property->getDbType())); //assumes PDO types, e.g. PDO::PARAM_INT
|
|
|
55 |
else
|
|
|
56 |
$command->bindValue($i+1,$value);
|
|
|
57 |
}
|
|
|
58 |
}
|
|
|
59 |
}
|
|
|
60 |
|