summaryrefslogtreecommitdiff
path: root/framework/DataAccess/SQLMap/Statements
diff options
context:
space:
mode:
Diffstat (limited to 'framework/DataAccess/SQLMap/Statements')
-rw-r--r--framework/DataAccess/SQLMap/Statements/TMappedStatement.php1
-rw-r--r--framework/DataAccess/SQLMap/Statements/TPreparedCommand.php2
-rw-r--r--framework/DataAccess/SQLMap/Statements/TPreparedStatementFactory.php15
-rw-r--r--framework/DataAccess/SQLMap/Statements/TSimpleDynamicSql.php32
-rw-r--r--framework/DataAccess/SQLMap/Statements/TStaticSql.php2
5 files changed, 34 insertions, 18 deletions
diff --git a/framework/DataAccess/SQLMap/Statements/TMappedStatement.php b/framework/DataAccess/SQLMap/Statements/TMappedStatement.php
index c621f285..9bc1143f 100644
--- a/framework/DataAccess/SQLMap/Statements/TMappedStatement.php
+++ b/framework/DataAccess/SQLMap/Statements/TMappedStatement.php
@@ -220,7 +220,6 @@ class TMappedStatement extends TComponent implements IMappedStatement
$list = $result instanceof ArrayAccess ? $result :
$this->_statement->createInstanceOfListClass();
$recordSet = $this->executeSQLQueryLimit($connection, $sql, $max, $skip);
-
if(!is_null($delegate))
{
while($row = $recordSet->fetchRow())
diff --git a/framework/DataAccess/SQLMap/Statements/TPreparedCommand.php b/framework/DataAccess/SQLMap/Statements/TPreparedCommand.php
index 1c0e5ad7..3557fc1f 100644
--- a/framework/DataAccess/SQLMap/Statements/TPreparedCommand.php
+++ b/framework/DataAccess/SQLMap/Statements/TPreparedCommand.php
@@ -5,7 +5,7 @@ class TPreparedCommand
public function create($connection, $statement, $parameterObject)
{
- $prepared = $statement->getSQL()->getPreparedStatement();
+ $prepared = $statement->getSQL()->getPreparedStatement($parameterObject);
$parameters = $this->applyParameterMap($connection,
$prepared, $statement, $parameterObject);
return array('sql'=>$prepared->getPreparedSql(),
diff --git a/framework/DataAccess/SQLMap/Statements/TPreparedStatementFactory.php b/framework/DataAccess/SQLMap/Statements/TPreparedStatementFactory.php
index 41059934..52461983 100644
--- a/framework/DataAccess/SQLMap/Statements/TPreparedStatementFactory.php
+++ b/framework/DataAccess/SQLMap/Statements/TPreparedStatementFactory.php
@@ -11,36 +11,21 @@ class TPreparedStatementFactory
{
$this->_statement = $statement;
$this->_commandText = $sqlString;
- // $this->_statement = new TPreparedStatement();
-// $this->_statement->setSqlString($sqlString);
}
public function prepare()
{
- //$this->createParametersFromTextCommand();
- //return $this->_statement;
$this->_preparedStatement = new TPreparedStatement();
$this->_preparedStatement->setPreparedSql($this->_commandText);
if(!is_null($this->_statement->parameterMap()))
- {
$this->createParametersForTextCommand();
- //$this->evaluateParameterMap();
- }
- //var_dump($this->_preparedStatement);
return $this->_preparedStatement;
}
protected function createParametersForTextCommand()
{
- /*$matches = array();
- $string = $this->_statement->getSqlString();
- preg_match_all('/#([a-zA-Z0-9._]+)#/', $string, $matches);
- $this->_statement->getParameterNames()->copyFrom($matches[0]);*/
- //var_dump($this->_statement);
foreach($this->_statement->ParameterMap()->getProperties() as $prop)
- {
$this->_preparedStatement->getParameterNames()->add($prop->getProperty());
- }
}
}
diff --git a/framework/DataAccess/SQLMap/Statements/TSimpleDynamicSql.php b/framework/DataAccess/SQLMap/Statements/TSimpleDynamicSql.php
new file mode 100644
index 00000000..1230b4f7
--- /dev/null
+++ b/framework/DataAccess/SQLMap/Statements/TSimpleDynamicSql.php
@@ -0,0 +1,32 @@
+<?php
+
+class TSimpleDynamicSql extends TStaticSql
+{
+ private $_mappings=array();
+
+ public function __construct($mappings)
+ {
+ $this->_mappings = $mappings;
+ }
+
+ public function getPreparedStatement($parameter=null)
+ {
+ $statement = parent::getPreparedStatement($parameter);
+ if($parameter !== null)
+ $this->mapDynamicParameter($statement, $parameter);
+ return $statement;
+ }
+
+ protected function mapDynamicParameter($statement, $parameter)
+ {
+ $sql = $statement->getPreparedSql();
+ foreach($this->_mappings as $property)
+ {
+ $value = TPropertyAccess::get($parameter, $property);
+ $sql = preg_replace('/'.TSimpleDynamicParser::DYNAMIC_TOKEN.'/', $value, $sql, 1);
+ }
+ $statement->setPreparedSql($sql);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/framework/DataAccess/SQLMap/Statements/TStaticSql.php b/framework/DataAccess/SQLMap/Statements/TStaticSql.php
index bf6e4a18..b99b86ed 100644
--- a/framework/DataAccess/SQLMap/Statements/TStaticSql.php
+++ b/framework/DataAccess/SQLMap/Statements/TStaticSql.php
@@ -10,7 +10,7 @@ class TStaticSql extends TComponent
$this->_preparedStatement = $factory->prepare();
}
- public function getPreparedStatement()
+ public function getPreparedStatement($parameter=null)
{
return $this->_preparedStatement;
}