Permalink
Browse files

FLTGetIsBetweenComparisonCommonExpresssion(): use appropriate backquo…

…te escaping for Date fields (#5104)
  • Loading branch information...
rouault committed Jun 23, 2015
1 parent a2d862d commit b1b97aa1675822dfcfb45969953dc91b67c785e6
Showing with 23 additions and 10 deletions.
  1. +23 −10 mapogcfiltercommon.c
View
@@ -127,6 +127,7 @@ char *FLTGetIsBetweenComparisonCommonExpresssion(FilterEncodingNode *psFilterNod
char **aszBounds = NULL;
int nBounds = 0;
int bString=0;
int bDateTime = 0;
char *pszExpression=NULL, *pszTmpEscaped;
if (!psFilterNode || !(strcasecmp(psFilterNode->pszValue, "PropertyIsBetween") == 0))
@@ -150,13 +151,17 @@ char *FLTGetIsBetweenComparisonCommonExpresssion(FilterEncodingNode *psFilterNod
/* -------------------------------------------------------------------- */
bString = 0;
if (aszBounds[0]) {
const char* pszType;
snprintf(szBuffer, bufferSize, "%s_type", psFilterNode->psLeftNode->pszValue);
if (msOWSLookupMetadata(&(lp->metadata), "OFG", szBuffer) != NULL && (strcasecmp(msOWSLookupMetadata(&(lp->metadata), "OFG", szBuffer), "Character") == 0))
pszType = msOWSLookupMetadata(&(lp->metadata), "OFG", szBuffer);
if (pszType != NULL && (strcasecmp(pszType, "Character") == 0))
bString = 1;
else if (pszType != NULL && (strcasecmp(pszType, "Date") == 0))
bDateTime = 1;
else if (FLTIsNumeric(aszBounds[0]) == MS_FALSE)
bString = 1;
}
if (!bString) {
if (!bString && !bDateTime) {
if (aszBounds[1]) {
if (FLTIsNumeric(aszBounds[1]) == MS_FALSE)
bString = 1;
@@ -185,17 +190,21 @@ char *FLTGetIsBetweenComparisonCommonExpresssion(FilterEncodingNode *psFilterNod
pszExpression = msStringConcatenate(pszExpression, szBuffer);
if (bString) {
sprintf(szBuffer,"%s", "\"");
pszExpression = msStringConcatenate(pszExpression, szBuffer);
pszExpression = msStringConcatenate(pszExpression, "\"");
}
else if (bDateTime) {
pszExpression = msStringConcatenate(pszExpression, "`");
}
pszTmpEscaped = msStringEscape(aszBounds[0]);
snprintf(szBuffer, bufferSize, "%s", pszTmpEscaped);
if(pszTmpEscaped != aszBounds[0] ) msFree(pszTmpEscaped);
pszExpression = msStringConcatenate(pszExpression, szBuffer);
if (bString) {
sprintf(szBuffer, "%s", "\"");
pszExpression = msStringConcatenate(pszExpression, szBuffer);
pszExpression = msStringConcatenate(pszExpression, "\"");
}
else if (bDateTime) {
pszExpression = msStringConcatenate(pszExpression, "`");
}
sprintf(szBuffer, "%s", " AND ");
@@ -219,17 +228,21 @@ char *FLTGetIsBetweenComparisonCommonExpresssion(FilterEncodingNode *psFilterNod
sprintf(szBuffer, "%s", " <= ");
pszExpression = msStringConcatenate(pszExpression, szBuffer);
if (bString) {
sprintf(szBuffer,"%s", "\"");
pszExpression = msStringConcatenate(pszExpression, szBuffer);
pszExpression = msStringConcatenate(pszExpression, "\"");
}
else if (bDateTime) {
pszExpression = msStringConcatenate(pszExpression, "`");
}
pszTmpEscaped = msStringEscape(aszBounds[1]);
snprintf(szBuffer, bufferSize, "%s", pszTmpEscaped);
if (pszTmpEscaped != aszBounds[1]) msFree(pszTmpEscaped);
pszExpression = msStringConcatenate(pszExpression, szBuffer);
if (bString) {
sprintf(szBuffer,"\"");
pszExpression = msStringConcatenate(pszExpression, szBuffer);
pszExpression = msStringConcatenate(pszExpression, "\"");
}
else if (bDateTime) {
pszExpression = msStringConcatenate(pszExpression, "`");
}
sprintf(szBuffer, "%s", ")");
pszExpression = msStringConcatenate(pszExpression, szBuffer);

0 comments on commit b1b97aa

Please sign in to comment.