Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add the ESCAPE clause to the LIKE operator. Not fully tested yet. (CVS 2107) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
49268c2b7a84c4c618214dac8bef0f54 |
User & Date: | danielk1977 2004-11-17 16:41:29.000 |
Context
2004-11-18
| ||
02:04 | Clarify the documentation of the sqlite3_create_function API. Ticket #1004. (CVS 2108) (check-in: ae45ad863b user: drh tags: trunk) | |
2004-11-17
| ||
16:41 | Add the ESCAPE clause to the LIKE operator. Not fully tested yet. (CVS 2107) (check-in: 49268c2b7a user: danielk1977 tags: trunk) | |
10:22 | Extra tests and resulting bugfixes for btree cursors. (CVS 2106) (check-in: e1530854c9 user: danielk1977 tags: trunk) | |
Changes
Changes to src/func.c.
︙ | |||
12 13 14 15 16 17 18 | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | - + | ** This file contains the C functions that implement various SQL ** functions of SQLite. ** ** There is only one exported symbol in this file - the function ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** |
︙ | |||
343 344 345 346 347 348 349 | 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | - + - + + + - + + + + + + + - + - + - + + | ** ** This routine is usually quick, but can be N**2 in the worst case. ** ** Hints: to match '*' or '?', put them in "[]". Like this: ** ** abc[*]xyz Matches "abc*xyz" only */ |
︙ | |||
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | + + + + | prior_c = c2; } sqliteNextChar(zPattern); } if( c2==0 || (seen ^ invert)==0 ) return 0; sqliteNextChar(zString); zPattern++; }else if( !prevEscape && sqlite3ReadUtf8(zPattern)==esc){ prevEscape = 1; sqliteNextChar(zPattern); }else{ if( noCase ){ if( sqlite3UpperToLower[c] != sqlite3UpperToLower[*zString] ) return 0; }else{ if( c != *zString ) return 0; } zPattern++; zString++; prevEscape = 0; } } return *zString==0; } /* |
︙ | |||
453 454 455 456 457 458 459 460 | 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 | + + + + + + + + + + + + + - + - + - + | static void likeFunc( sqlite3_context *context, int argc, sqlite3_value **argv ){ const unsigned char *zA = sqlite3_value_text(argv[0]); const unsigned char *zB = sqlite3_value_text(argv[1]); int escape = 0; if( argc==3 ){ /* The escape character string must consist of a single UTF-8 character. ** Otherwise, return an error. */ const unsigned char *zEsc = sqlite3_value_text(argv[2]); if( sqlite3utf8CharLen(zEsc, -1)!=1 ){ sqlite3_result_error(context, "ESCAPE expression must be a single character", -1); return; } escape = sqlite3ReadUtf8(zEsc); } if( zA && zB ){ |
︙ | |||
988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 | 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 | + | { "lower", 1, 0, SQLITE_UTF8, 0, lowerFunc }, { "coalesce", -1, 0, SQLITE_UTF8, 0, ifnullFunc }, { "coalesce", 0, 0, SQLITE_UTF8, 0, 0 }, { "coalesce", 1, 0, SQLITE_UTF8, 0, 0 }, { "ifnull", 2, 0, SQLITE_UTF8, 1, ifnullFunc }, { "random", -1, 0, SQLITE_UTF8, 0, randomFunc }, { "like", 2, 0, SQLITE_UTF8, 0, likeFunc }, { "like", 3, 0, SQLITE_UTF8, 0, likeFunc }, { "glob", 2, 0, SQLITE_UTF8, 0, globFunc }, { "nullif", 2, 0, SQLITE_UTF8, 1, nullifFunc }, { "sqlite_version", 0, 0, SQLITE_UTF8, 0, versionFunc}, { "quote", 1, 0, SQLITE_UTF8, 0, quoteFunc }, { "last_insert_rowid", 0, 1, SQLITE_UTF8, 0, last_insert_rowid }, { "changes", 0, 1, SQLITE_UTF8, 0, changes }, { "total_changes", 0, 1, SQLITE_UTF8, 0, total_changes }, |
︙ |
Changes to src/parse.y.
︙ | |||
10 11 12 13 14 15 16 | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | - + | ** ************************************************************************* ** This file contains SQLite's grammar for SQL. Process this file ** using the lemon parser generator to generate C code that runs ** the parser. Lemon will also generate a header file containing ** numeric codes for all of the tokens. ** |
︙ | |||
165 166 167 168 169 170 171 172 173 174 175 176 177 178 | 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | + | // constraint. // %left OR. %left AND. %right NOT. %left IS LIKE GLOB BETWEEN IN ISNULL NOTNULL NE EQ. %left GT LE LT GE. %right ESCAPE. %left BITAND BITOR LSHIFT RSHIFT. %left PLUS MINUS. %left STAR SLASH REM. %left CONCAT. %right UMINUS UPLUS BITNOT. // And "ids" is an identifer-or-string. |
︙ | |||
633 634 635 636 637 638 639 | 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 | + + + - + + + + + | expr(A) ::= expr(X) REM(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);} expr(A) ::= expr(X) CONCAT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);} %type likeop {struct LikeOp} likeop(A) ::= LIKE. {A.opcode = TK_LIKE; A.not = 0;} likeop(A) ::= GLOB. {A.opcode = TK_GLOB; A.not = 0;} likeop(A) ::= NOT LIKE. {A.opcode = TK_LIKE; A.not = 1;} likeop(A) ::= NOT GLOB. {A.opcode = TK_GLOB; A.not = 1;} %type escape {Expr*} escape(X) ::= ESCAPE expr(A). [ESCAPE] {X = A;} escape(X) ::= . [ESCAPE] {X = 0;} |
︙ |
Changes to test/expr.test.
1 2 3 4 5 6 7 8 9 10 11 12 13 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | - + | # 2001 September 15 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing expressions. # |
︙ | |||
263 264 265 266 267 268 269 270 271 272 273 274 275 276 | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | } test_expr expr-5.54 {t1='abc', t2=NULL} {t1 LIKE t2} {{}} test_expr expr-5.55 {t1='abc', t2=NULL} {t1 NOT LIKE t2} {{}} test_expr expr-5.56 {t1='abc', t2=NULL} {t2 LIKE t1} {{}} test_expr expr-5.57 {t1='abc', t2=NULL} {t2 NOT LIKE t1} {{}} # LIKE expressions that use ESCAPE characters. test_expr expr-5.58 {t1='abc', t2='A_C'} {t1 LIKE t2 ESCAPE '7'} 1 test_expr expr-5.59 {t1='a_c', t2='A7_C'} {t1 LIKE t2 ESCAPE '7'} 1 test_expr expr-5.60 {t1='abc', t2='A7_C'} {t1 LIKE t2 ESCAPE '7'} 0 test_expr expr-5.61 {t1='a7Xc', t2='A7_C'} {t1 LIKE t2 ESCAPE '7'} 0 test_expr expr-5.62 {t1='abcde', t2='A%E'} {t1 LIKE t2 ESCAPE '7'} 1 test_expr expr-5.63 {t1='abcde', t2='A7%E'} {t1 LIKE t2 ESCAPE '7'} 0 test_expr expr-5.64 {t1='a7cde', t2='A7%E'} {t1 LIKE t2 ESCAPE '7'} 0 test_expr expr-5.65 {t1='a7cde', t2='A77%E'} {t1 LIKE t2 ESCAPE '7'} 1 test_expr expr-5.66 {t1='abc7', t2='A%77'} {t1 LIKE t2 ESCAPE '7'} 1 test_expr expr-5.67 {t1='abc_', t2='A%7_'} {t1 LIKE t2 ESCAPE '7'} 1 test_expr expr-5.68 {t1='abc7', t2='A%7_'} {t1 LIKE t2 ESCAPE '7'} 0 # These are the same test as the block above, but using a multi-byte # character as the escape character. if {"\u1234"!="u1234"} { test_expr expr-5.69 "t1='abc', t2='A_C'" \ "t1 LIKE t2 ESCAPE '\u1234'" 1 test_expr expr-5.70 "t1='a_c', t2='A\u1234_C'" \ "t1 LIKE t2 ESCAPE '\u1234'" 1 test_expr expr-5.71 "t1='abc', t2='A\u1234_C'" \ "t1 LIKE t2 ESCAPE '\u1234'" 0 test_expr expr-5.72 "t1='a\u1234Xc', t2='A\u1234_C'" \ "t1 LIKE t2 ESCAPE '\u1234'" 0 test_expr expr-5.73 "t1='abcde', t2='A%E'" \ "t1 LIKE t2 ESCAPE '\u1234'" 1 test_expr expr-5.74 "t1='abcde', t2='A\u1234%E'" \ "t1 LIKE t2 ESCAPE '\u1234'" 0 test_expr expr-5.75 "t1='a\u1234cde', t2='A\u1234%E'" \ "t1 LIKE t2 ESCAPE '\u1234'" 0 test_expr expr-5.76 "t1='a\u1234cde', t2='A\u1234\u1234%E'" \ "t1 LIKE t2 ESCAPE '\u1234'" 1 test_expr expr-5.77 "t1='abc\u1234', t2='A%\u1234\u1234'" \ "t1 LIKE t2 ESCAPE '\u1234'" 1 test_expr expr-5.78 "t1='abc_', t2='A%\u1234_'" \ "t1 LIKE t2 ESCAPE '\u1234'" 1 test_expr expr-5.79 "t1='abc\u1234', t2='A%\u1234_'" \ "t1 LIKE t2 ESCAPE '\u1234'" 0 } test_expr expr-6.1 {t1='abc', t2='xyz'} {t1 GLOB t2} 0 test_expr expr-6.2 {t1='abc', t2='ABC'} {t1 GLOB t2} 0 test_expr expr-6.3 {t1='abc', t2='A?C'} {t1 GLOB t2} 0 test_expr expr-6.4 {t1='abc', t2='a?c'} {t1 GLOB t2} 1 test_expr expr-6.5 {t1='abc', t2='abc?'} {t1 GLOB t2} 0 test_expr expr-6.6 {t1='abc', t2='A*C'} {t1 GLOB t2} 0 |
︙ |
Added test/lock4.test.