OLD | NEW |
1 /* | 1 /* |
2 ** 2001 September 15 | 2 ** 2001 September 15 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1245 */ | 1245 */ |
1246 if( pWC->op==TK_AND | 1246 if( pWC->op==TK_AND |
1247 && isLikeOrGlob(pParse, pExpr, &pStr1, &isComplete, &noCase) | 1247 && isLikeOrGlob(pParse, pExpr, &pStr1, &isComplete, &noCase) |
1248 ){ | 1248 ){ |
1249 Expr *pLeft; /* LHS of LIKE/GLOB operator */ | 1249 Expr *pLeft; /* LHS of LIKE/GLOB operator */ |
1250 Expr *pStr2; /* Copy of pStr1 - RHS of LIKE/GLOB operator */ | 1250 Expr *pStr2; /* Copy of pStr1 - RHS of LIKE/GLOB operator */ |
1251 Expr *pNewExpr1; | 1251 Expr *pNewExpr1; |
1252 Expr *pNewExpr2; | 1252 Expr *pNewExpr2; |
1253 int idxNew1; | 1253 int idxNew1; |
1254 int idxNew2; | 1254 int idxNew2; |
1255 Token sCollSeqName; /* Name of collating sequence */ | 1255 const char *zCollSeqName; /* Name of collating sequence */ |
1256 | 1256 |
1257 pLeft = pExpr->x.pList->a[1].pExpr; | 1257 pLeft = pExpr->x.pList->a[1].pExpr; |
1258 pStr2 = sqlite3ExprDup(db, pStr1, 0); | 1258 pStr2 = sqlite3ExprDup(db, pStr1, 0); |
1259 if( !db->mallocFailed ){ | 1259 if( !db->mallocFailed ){ |
1260 u8 c, *pC; /* Last character before the first wildcard */ | 1260 u8 c, *pC; /* Last character before the first wildcard */ |
1261 pC = (u8*)&pStr2->u.zToken[sqlite3Strlen30(pStr2->u.zToken)-1]; | 1261 pC = (u8*)&pStr2->u.zToken[sqlite3Strlen30(pStr2->u.zToken)-1]; |
1262 c = *pC; | 1262 c = *pC; |
1263 if( noCase ){ | 1263 if( noCase ){ |
1264 /* The point is to increment the last character before the first | 1264 /* The point is to increment the last character before the first |
1265 ** wildcard. But if we increment '@', that will push it into the | 1265 ** wildcard. But if we increment '@', that will push it into the |
1266 ** alphabetic range where case conversions will mess up the | 1266 ** alphabetic range where case conversions will mess up the |
1267 ** inequality. To avoid this, make sure to also run the full | 1267 ** inequality. To avoid this, make sure to also run the full |
1268 ** LIKE on all candidate expressions by clearing the isComplete flag | 1268 ** LIKE on all candidate expressions by clearing the isComplete flag |
1269 */ | 1269 */ |
1270 if( c=='A'-1 ) isComplete = 0; | 1270 if( c=='A'-1 ) isComplete = 0; |
1271 c = sqlite3UpperToLower[c]; | 1271 c = sqlite3UpperToLower[c]; |
1272 } | 1272 } |
1273 *pC = c + 1; | 1273 *pC = c + 1; |
1274 } | 1274 } |
1275 sCollSeqName.z = noCase ? "NOCASE" : "BINARY"; | 1275 zCollSeqName = noCase ? "NOCASE" : "BINARY"; |
1276 sCollSeqName.n = 6; | |
1277 pNewExpr1 = sqlite3ExprDup(db, pLeft, 0); | 1276 pNewExpr1 = sqlite3ExprDup(db, pLeft, 0); |
1278 pNewExpr1 = sqlite3PExpr(pParse, TK_GE, | 1277 pNewExpr1 = sqlite3PExpr(pParse, TK_GE, |
1279 sqlite3ExprAddCollateToken(pParse,pNewExpr1,&sCollSeqName), | 1278 sqlite3ExprAddCollateString(pParse,pNewExpr1,zCollSeqName), |
1280 pStr1, 0); | 1279 pStr1, 0); |
1281 transferJoinMarkings(pNewExpr1, pExpr); | 1280 transferJoinMarkings(pNewExpr1, pExpr); |
1282 idxNew1 = whereClauseInsert(pWC, pNewExpr1, TERM_VIRTUAL|TERM_DYNAMIC); | 1281 idxNew1 = whereClauseInsert(pWC, pNewExpr1, TERM_VIRTUAL|TERM_DYNAMIC); |
1283 testcase( idxNew1==0 ); | 1282 testcase( idxNew1==0 ); |
1284 exprAnalyze(pSrc, pWC, idxNew1); | 1283 exprAnalyze(pSrc, pWC, idxNew1); |
1285 pNewExpr2 = sqlite3ExprDup(db, pLeft, 0); | 1284 pNewExpr2 = sqlite3ExprDup(db, pLeft, 0); |
1286 pNewExpr2 = sqlite3PExpr(pParse, TK_LT, | 1285 pNewExpr2 = sqlite3PExpr(pParse, TK_LT, |
1287 sqlite3ExprAddCollateToken(pParse,pNewExpr2,&sCollSeqName), | 1286 sqlite3ExprAddCollateString(pParse,pNewExpr2,zCollSeqName), |
1288 pStr2, 0); | 1287 pStr2, 0); |
1289 transferJoinMarkings(pNewExpr2, pExpr); | 1288 transferJoinMarkings(pNewExpr2, pExpr); |
1290 idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC); | 1289 idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC); |
1291 testcase( idxNew2==0 ); | 1290 testcase( idxNew2==0 ); |
1292 exprAnalyze(pSrc, pWC, idxNew2); | 1291 exprAnalyze(pSrc, pWC, idxNew2); |
1293 pTerm = &pWC->a[idxTerm]; | 1292 pTerm = &pWC->a[idxTerm]; |
1294 if( isComplete ){ | 1293 if( isComplete ){ |
1295 pWC->a[idxNew1].iParent = idxTerm; | 1294 pWC->a[idxNew1].iParent = idxTerm; |
1296 pWC->a[idxNew2].iParent = idxTerm; | 1295 pWC->a[idxNew2].iParent = idxTerm; |
1297 pTerm->nChild = 2; | 1296 pTerm->nChild = 2; |
(...skipping 5302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6600 } | 6599 } |
6601 } | 6600 } |
6602 } | 6601 } |
6603 | 6602 |
6604 /* Final cleanup | 6603 /* Final cleanup |
6605 */ | 6604 */ |
6606 pParse->nQueryLoop = pWInfo->savedNQueryLoop; | 6605 pParse->nQueryLoop = pWInfo->savedNQueryLoop; |
6607 whereInfoFree(db, pWInfo); | 6606 whereInfoFree(db, pWInfo); |
6608 return; | 6607 return; |
6609 } | 6608 } |
OLD | NEW |