瀏覽代碼

ogc:Filter add ogc:PropertyIsLike

Piotr Labudda 10 年之前
父節點
當前提交
037175e736
共有 2 個文件被更改,包括 56 次插入0 次删除
  1. 55 0
      SE/se-lib/Data_Source.php
  2. 1 0
      SE/se-lib/SqlQueryWhereBuilder.php

+ 55 - 0
SE/se-lib/Data_Source.php

@@ -274,6 +274,50 @@ OGC_FILTER_XML_FILE;
 					$fieldName = V::get('fieldName', '', $tag['attributes']);
 					$comparisonSign = V::get('comparisonSign', '', $tag['attributes']);
 					$value = V::get('value', '', $tag['attributes']);
+					DBG::_('DBG_DS_OGC', '>3', "sql_filter_comparisonFieldToValue comparisonSign", $comparisonSign, __CLASS__, __FUNCTION__, __LINE__);
+					if ('like' == $comparisonSign) {
+						$wildCard = V::get('wildCard', '', $tag['attributes']);
+						$singleChar = V::get('singleChar', '', $tag['attributes']);
+						$escapeChar = V::get('escapeChar', '', $tag['attributes']);
+						// wildCard="*" singleChar="#" escapeChar="!" => sql: % _ \
+						// '*ORMA!*' => '%ORMA\*'
+						// TODO: first replace every escapeChar
+						$valLength = strlen($value);
+						$valCharsAllowReplace = array(); for ($i = 0; $i < $valLength; $i++) $valCharsAllowReplace[] = true;
+						{// escapeChar
+							$lastOffset = 0;
+							while (false !== ($pos = strpos($value, $escapeChar, $lastOffset))) {
+								DBG::_('DBG_DS_OGC', '>3', "sql_filter_comparisonFieldToValue like value({$value}) escapeChar({$escapeChar}) pos({$pos}) lastOffset({$lastOffset})", null, __CLASS__, __FUNCTION__, __LINE__);
+								$value[$pos] = '\\';
+								$valCharsAllowReplace[$pos] = false;
+								if ($pos + 1 < $valLength) $valCharsAllowReplace[$pos + 1] = false;
+								$lastOffset = $pos + 1;
+							}
+						}
+						{// singleChar
+							$lastOffset = 0;
+							while (false !== ($pos = strpos($value, $singleChar, $lastOffset))) {
+								DBG::_('DBG_DS_OGC', '>3', "sql_filter_comparisonFieldToValue like value({$value}) singleChar({$singleChar}) pos({$pos}) lastOffset({$lastOffset})", null, __CLASS__, __FUNCTION__, __LINE__);
+								if ($valCharsAllowReplace[$pos]) {
+									$value[$pos] = '_';
+									$valCharsAllowReplace[$pos] = false;
+								}
+								$lastOffset = $pos + 1;
+							}
+						}
+						{// wildCard
+							$lastOffset = 0;
+							while (false !== ($pos = strpos($value, $wildCard, $lastOffset))) {
+								DBG::_('DBG_DS_OGC', '>3', "sql_filter_comparisonFieldToValue like value({$value}) wildCard({$wildCard}) pos({$pos}) lastOffset({$lastOffset})", null, __CLASS__, __FUNCTION__, __LINE__);
+								if ($valCharsAllowReplace[$pos]) {
+									$value[$pos] = '%';
+									$valCharsAllowReplace[$pos] = false;
+								}
+								$lastOffset = $pos + 1;
+							}
+						}
+					}
+					DBG::_('DBG_DS_OGC', '>3', "sql_filter_comparisonFieldToValue value({$value})", null, __CLASS__, __FUNCTION__, __LINE__);
 					$queryWhereBuilder->addComparisonFieldToValue($fieldName, $comparisonSign, $value);
 				}
 					break;
@@ -348,6 +392,17 @@ OGC_FILTER_XML_FILE;
 		</xsl:element>
 	</xsl:template>
 
+	<xsl:template match="ogc:PropertyIsLike">
+		<xsl:element name="sql_filter_comparisonFieldToValue">
+			<xsl:attribute name="fieldName"><xsl:value-of select="ogc:PropertyName" /></xsl:attribute>
+			<xsl:attribute name="comparisonSign"><xsl:value-of select="'like'" /></xsl:attribute>
+			<xsl:attribute name="value"><xsl:value-of select="ogc:Literal" /></xsl:attribute>
+			<xsl:attribute name="wildCard"><xsl:value-of select="@wildCard" /></xsl:attribute>
+			<xsl:attribute name="singleChar"><xsl:value-of select="@singleChar" /></xsl:attribute>
+			<xsl:attribute name="escapeChar"><xsl:value-of select="@escapeChar" /></xsl:attribute>
+		</xsl:element>
+	</xsl:template>
+
 </xsl:stylesheet>
 
 XSL_CONVERT_OGC_FILTER_TO_XML_TASK_LIST;

+ 1 - 0
SE/se-lib/SqlQueryWhereBuilder.php

@@ -23,6 +23,7 @@ class SqlQueryWhereBuilder {
 		$sqlCompSign = "";
 		switch ($comparisonSign) {
 			case '=': $sqlCompSign = '='; break;
+			case 'like': $sqlCompSign = 'like'; break;
 			default: throw new Exception("Unsupported comparison sign");
 		}
 		$this->_log[] = array('comparisonFieldToValue', $fieldName, $sqlCompSign, $value);