summaryrefslogtreecommitdiff
path: root/framework/DataAccess/SQLMap/Statements/TSimpleDynamicSql.php
diff options
context:
space:
mode:
Diffstat (limited to 'framework/DataAccess/SQLMap/Statements/TSimpleDynamicSql.php')
-rw-r--r--framework/DataAccess/SQLMap/Statements/TSimpleDynamicSql.php32
1 files changed, 32 insertions, 0 deletions
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