diff options
author | wei <> | 2006-04-14 06:22:09 +0000 |
---|---|---|
committer | wei <> | 2006-04-14 06:22:09 +0000 |
commit | 3d3f8d3832921f99daf8ce1953304763c2e76c62 (patch) | |
tree | e1b0a9bc3a13fccd253770fb452ac96cc6315121 /framework/DataAccess/SQLMap/Configuration/TInlineParameterMapParser.php | |
parent | 373d8acc503b94ea09823f49e2ab5e395eccc584 (diff) |
Importing SQLMap + sample + docs.
Diffstat (limited to 'framework/DataAccess/SQLMap/Configuration/TInlineParameterMapParser.php')
-rw-r--r-- | framework/DataAccess/SQLMap/Configuration/TInlineParameterMapParser.php | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/framework/DataAccess/SQLMap/Configuration/TInlineParameterMapParser.php b/framework/DataAccess/SQLMap/Configuration/TInlineParameterMapParser.php new file mode 100644 index 00000000..8b1ecf04 --- /dev/null +++ b/framework/DataAccess/SQLMap/Configuration/TInlineParameterMapParser.php @@ -0,0 +1,50 @@ +<?php
+
+class TInlineParameterMapParser
+{
+ private $PARAMETER_TOKEN_REGEXP = '/#(#?[^#]+#?)#/';
+
+ public function parseInlineParameterMap($sqlMap, $statement, $sqlText, $scope)
+ {
+ $parameterClass = !is_null($statement)
+ ? $statement->getParameterClass() : null;
+ $matches = array();
+ $mappings = array();
+ preg_match_all($this->PARAMETER_TOKEN_REGEXP, $sqlText, $matches);
+
+ for($i = 0, $k=count($matches[1]); $i<$k; $i++)
+ {
+ $mappings[] = $this->parseMapping($matches[1][$i],
+ $parameterClass, $sqlMap, $scope);
+ $sqlText = str_replace($matches[0][$i], '?', $sqlText);
+ }
+ return array('sql'=>$sqlText, 'parameters'=>$mappings);
+ }
+
+ /**
+ * Parse inline parameter with syntax as
+ * #propertyName,type=string,dbype=Varchar,nullValue=N/A,handler=string#
+ */
+ protected function parseMapping($token, $parameterClass, $sqlMap, $scope)
+ {
+ $mapping = new TParameterProperty;
+ $properties = explode(',', $token);
+ $mapping->setProperty(trim(array_shift($properties)));
+ //var_dump($properties);
+ foreach($properties as $property)
+ {
+ $prop = explode('=',$property);
+ $name = trim($prop[0]); $value=trim($prop[1]);
+ if($mapping->canSetProperty($name))
+ $mapping->{'set'.$name}($value);
+ else
+ throw new TSqlMapUndefinedException(
+ 'sqlmap_undefined_property_inline_map',
+ $name, $scope['statement'], $scope['file']);
+ }
+ $mapping->initialize($sqlMap);
+ return $mapping;
+ }
+}
+
+?>
\ No newline at end of file |