OLD | NEW |
1 /* | 1 /* |
2 ** 2002 February 23 | 2 ** 2002 February 23 |
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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 int typeHaystack, typeNeedle; | 193 int typeHaystack, typeNeedle; |
194 int N = 1; | 194 int N = 1; |
195 int isText; | 195 int isText; |
196 | 196 |
197 UNUSED_PARAMETER(argc); | 197 UNUSED_PARAMETER(argc); |
198 typeHaystack = sqlite3_value_type(argv[0]); | 198 typeHaystack = sqlite3_value_type(argv[0]); |
199 typeNeedle = sqlite3_value_type(argv[1]); | 199 typeNeedle = sqlite3_value_type(argv[1]); |
200 if( typeHaystack==SQLITE_NULL || typeNeedle==SQLITE_NULL ) return; | 200 if( typeHaystack==SQLITE_NULL || typeNeedle==SQLITE_NULL ) return; |
201 nHaystack = sqlite3_value_bytes(argv[0]); | 201 nHaystack = sqlite3_value_bytes(argv[0]); |
202 nNeedle = sqlite3_value_bytes(argv[1]); | 202 nNeedle = sqlite3_value_bytes(argv[1]); |
203 if( typeHaystack==SQLITE_BLOB && typeNeedle==SQLITE_BLOB ){ | 203 if( nNeedle>0 ){ |
204 zHaystack = sqlite3_value_blob(argv[0]); | 204 if( typeHaystack==SQLITE_BLOB && typeNeedle==SQLITE_BLOB ){ |
205 zNeedle = sqlite3_value_blob(argv[1]); | 205 zHaystack = sqlite3_value_blob(argv[0]); |
206 isText = 0; | 206 zNeedle = sqlite3_value_blob(argv[1]); |
207 }else{ | 207 assert( zNeedle!=0 ); |
208 zHaystack = sqlite3_value_text(argv[0]); | 208 assert( zHaystack!=0 || nHaystack==0 ); |
209 zNeedle = sqlite3_value_text(argv[1]); | 209 isText = 0; |
210 isText = 1; | 210 }else{ |
| 211 zHaystack = sqlite3_value_text(argv[0]); |
| 212 zNeedle = sqlite3_value_text(argv[1]); |
| 213 isText = 1; |
| 214 if( zHaystack==0 || zNeedle==0 ) return; |
| 215 } |
| 216 while( nNeedle<=nHaystack && memcmp(zHaystack, zNeedle, nNeedle)!=0 ){ |
| 217 N++; |
| 218 do{ |
| 219 nHaystack--; |
| 220 zHaystack++; |
| 221 }while( isText && (zHaystack[0]&0xc0)==0x80 ); |
| 222 } |
| 223 if( nNeedle>nHaystack ) N = 0; |
211 } | 224 } |
212 while( nNeedle<=nHaystack && memcmp(zHaystack, zNeedle, nNeedle)!=0 ){ | |
213 N++; | |
214 do{ | |
215 nHaystack--; | |
216 zHaystack++; | |
217 }while( isText && (zHaystack[0]&0xc0)==0x80 ); | |
218 } | |
219 if( nNeedle>nHaystack ) N = 0; | |
220 sqlite3_result_int(context, N); | 225 sqlite3_result_int(context, N); |
221 } | 226 } |
222 | 227 |
223 /* | 228 /* |
224 ** Implementation of the printf() function. | 229 ** Implementation of the printf() function. |
225 */ | 230 */ |
226 static void printfFunc( | 231 static void printfFunc( |
227 sqlite3_context *context, | 232 sqlite3_context *context, |
228 int argc, | 233 int argc, |
229 sqlite3_value **argv | 234 sqlite3_value **argv |
230 ){ | 235 ){ |
231 PrintfArguments x; | 236 PrintfArguments x; |
232 StrAccum str; | 237 StrAccum str; |
233 const char *zFormat; | 238 const char *zFormat; |
234 int n; | 239 int n; |
235 sqlite3 *db = sqlite3_context_db_handle(context); | 240 sqlite3 *db = sqlite3_context_db_handle(context); |
236 | 241 |
237 if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){ | 242 if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){ |
238 x.nArg = argc-1; | 243 x.nArg = argc-1; |
239 x.nUsed = 0; | 244 x.nUsed = 0; |
240 x.apArg = argv+1; | 245 x.apArg = argv+1; |
241 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]); | 246 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]); |
242 sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x); | 247 str.printfFlags = SQLITE_PRINTF_SQLFUNC; |
| 248 sqlite3XPrintf(&str, zFormat, &x); |
243 n = str.nChar; | 249 n = str.nChar; |
244 sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n, | 250 sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n, |
245 SQLITE_DYNAMIC); | 251 SQLITE_DYNAMIC); |
246 } | 252 } |
247 } | 253 } |
248 | 254 |
249 /* | 255 /* |
250 ** Implementation of the substr() function. | 256 ** Implementation of the substr() function. |
251 ** | 257 ** |
252 ** substr(x,p1,p2) returns p2 characters of x[] beginning with p1. | 258 ** substr(x,p1,p2) returns p2 characters of x[] beginning with p1. |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 UNUSED_PARAMETER2(NotUsed, NotUsed2); | 566 UNUSED_PARAMETER2(NotUsed, NotUsed2); |
561 /* IMP: R-52756-41993 This function is a wrapper around the | 567 /* IMP: R-52756-41993 This function is a wrapper around the |
562 ** sqlite3_total_changes() C/C++ interface. */ | 568 ** sqlite3_total_changes() C/C++ interface. */ |
563 sqlite3_result_int(context, sqlite3_total_changes(db)); | 569 sqlite3_result_int(context, sqlite3_total_changes(db)); |
564 } | 570 } |
565 | 571 |
566 /* | 572 /* |
567 ** A structure defining how to do GLOB-style comparisons. | 573 ** A structure defining how to do GLOB-style comparisons. |
568 */ | 574 */ |
569 struct compareInfo { | 575 struct compareInfo { |
570 u8 matchAll; | 576 u8 matchAll; /* "*" or "%" */ |
571 u8 matchOne; | 577 u8 matchOne; /* "?" or "_" */ |
572 u8 matchSet; | 578 u8 matchSet; /* "[" or 0 */ |
573 u8 noCase; | 579 u8 noCase; /* true to ignore case differences */ |
574 }; | 580 }; |
575 | 581 |
576 /* | 582 /* |
577 ** For LIKE and GLOB matching on EBCDIC machines, assume that every | 583 ** For LIKE and GLOB matching on EBCDIC machines, assume that every |
578 ** character is exactly one byte in size. Also, provde the Utf8Read() | 584 ** character is exactly one byte in size. Also, provde the Utf8Read() |
579 ** macro for fast reading of the next character in the common case where | 585 ** macro for fast reading of the next character in the common case where |
580 ** the next character is ASCII. | 586 ** the next character is ASCII. |
581 */ | 587 */ |
582 #if defined(SQLITE_EBCDIC) | 588 #if defined(SQLITE_EBCDIC) |
583 # define sqlite3Utf8Read(A) (*((*A)++)) | 589 # define sqlite3Utf8Read(A) (*((*A)++)) |
584 # define Utf8Read(A) (*(A++)) | 590 # define Utf8Read(A) (*(A++)) |
585 #else | 591 #else |
586 # define Utf8Read(A) (A[0]<0x80?*(A++):sqlite3Utf8Read(&A)) | 592 # define Utf8Read(A) (A[0]<0x80?*(A++):sqlite3Utf8Read(&A)) |
587 #endif | 593 #endif |
588 | 594 |
589 static const struct compareInfo globInfo = { '*', '?', '[', 0 }; | 595 static const struct compareInfo globInfo = { '*', '?', '[', 0 }; |
590 /* The correct SQL-92 behavior is for the LIKE operator to ignore | 596 /* The correct SQL-92 behavior is for the LIKE operator to ignore |
591 ** case. Thus 'a' LIKE 'A' would be true. */ | 597 ** case. Thus 'a' LIKE 'A' would be true. */ |
592 static const struct compareInfo likeInfoNorm = { '%', '_', 0, 1 }; | 598 static const struct compareInfo likeInfoNorm = { '%', '_', 0, 1 }; |
593 /* If SQLITE_CASE_SENSITIVE_LIKE is defined, then the LIKE operator | 599 /* If SQLITE_CASE_SENSITIVE_LIKE is defined, then the LIKE operator |
594 ** is case sensitive causing 'a' LIKE 'A' to be false */ | 600 ** is case sensitive causing 'a' LIKE 'A' to be false */ |
595 static const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 }; | 601 static const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 }; |
596 | 602 |
597 /* | 603 /* |
598 ** Compare two UTF-8 strings for equality where the first string can | 604 ** Possible error returns from patternMatch() |
599 ** potentially be a "glob" or "like" expression. Return true (1) if they | 605 */ |
600 ** are the same and false (0) if they are different. | 606 #define SQLITE_MATCH 0 |
| 607 #define SQLITE_NOMATCH 1 |
| 608 #define SQLITE_NOWILDCARDMATCH 2 |
| 609 |
| 610 /* |
| 611 ** Compare two UTF-8 strings for equality where the first string is |
| 612 ** a GLOB or LIKE expression. Return values: |
| 613 ** |
| 614 ** SQLITE_MATCH: Match |
| 615 ** SQLITE_NOMATCH: No match |
| 616 ** SQLITE_NOWILDCARDMATCH: No match in spite of having * or % wildcards. |
601 ** | 617 ** |
602 ** Globbing rules: | 618 ** Globbing rules: |
603 ** | 619 ** |
604 ** '*' Matches any sequence of zero or more characters. | 620 ** '*' Matches any sequence of zero or more characters. |
605 ** | 621 ** |
606 ** '?' Matches exactly one character. | 622 ** '?' Matches exactly one character. |
607 ** | 623 ** |
608 ** [...] Matches one character from the enclosed list of | 624 ** [...] Matches one character from the enclosed list of |
609 ** characters. | 625 ** characters. |
610 ** | 626 ** |
(...skipping 15 matching lines...) Expand all Loading... |
626 ** character, including '%', '_', and esc, match exactly c. | 642 ** character, including '%', '_', and esc, match exactly c. |
627 ** | 643 ** |
628 ** The comments within this routine usually assume glob matching. | 644 ** The comments within this routine usually assume glob matching. |
629 ** | 645 ** |
630 ** This routine is usually quick, but can be N**2 in the worst case. | 646 ** This routine is usually quick, but can be N**2 in the worst case. |
631 */ | 647 */ |
632 static int patternCompare( | 648 static int patternCompare( |
633 const u8 *zPattern, /* The glob pattern */ | 649 const u8 *zPattern, /* The glob pattern */ |
634 const u8 *zString, /* The string to compare against the glob */ | 650 const u8 *zString, /* The string to compare against the glob */ |
635 const struct compareInfo *pInfo, /* Information about how to do the compare */ | 651 const struct compareInfo *pInfo, /* Information about how to do the compare */ |
636 u32 esc /* The escape character */ | 652 u32 matchOther /* The escape char (LIKE) or '[' (GLOB) */ |
637 ){ | 653 ){ |
638 u32 c, c2; /* Next pattern and input string chars */ | 654 u32 c, c2; /* Next pattern and input string chars */ |
639 u32 matchOne = pInfo->matchOne; /* "?" or "_" */ | 655 u32 matchOne = pInfo->matchOne; /* "?" or "_" */ |
640 u32 matchAll = pInfo->matchAll; /* "*" or "%" */ | 656 u32 matchAll = pInfo->matchAll; /* "*" or "%" */ |
641 u32 matchOther; /* "[" or the escape character */ | |
642 u8 noCase = pInfo->noCase; /* True if uppercase==lowercase */ | 657 u8 noCase = pInfo->noCase; /* True if uppercase==lowercase */ |
643 const u8 *zEscaped = 0; /* One past the last escaped input char */ | 658 const u8 *zEscaped = 0; /* One past the last escaped input char */ |
644 | 659 |
645 /* The GLOB operator does not have an ESCAPE clause. And LIKE does not | |
646 ** have the matchSet operator. So we either have to look for one or | |
647 ** the other, never both. Hence the single variable matchOther is used | |
648 ** to store the one we have to look for. | |
649 */ | |
650 matchOther = esc ? esc : pInfo->matchSet; | |
651 | |
652 while( (c = Utf8Read(zPattern))!=0 ){ | 660 while( (c = Utf8Read(zPattern))!=0 ){ |
653 if( c==matchAll ){ /* Match "*" */ | 661 if( c==matchAll ){ /* Match "*" */ |
654 /* Skip over multiple "*" characters in the pattern. If there | 662 /* Skip over multiple "*" characters in the pattern. If there |
655 ** are also "?" characters, skip those as well, but consume a | 663 ** are also "?" characters, skip those as well, but consume a |
656 ** single character of the input string for each "?" skipped */ | 664 ** single character of the input string for each "?" skipped */ |
657 while( (c=Utf8Read(zPattern)) == matchAll || c == matchOne ){ | 665 while( (c=Utf8Read(zPattern)) == matchAll || c == matchOne ){ |
658 if( c==matchOne && sqlite3Utf8Read(&zString)==0 ){ | 666 if( c==matchOne && sqlite3Utf8Read(&zString)==0 ){ |
659 return 0; | 667 return SQLITE_NOWILDCARDMATCH; |
660 } | 668 } |
661 } | 669 } |
662 if( c==0 ){ | 670 if( c==0 ){ |
663 return 1; /* "*" at the end of the pattern matches */ | 671 return SQLITE_MATCH; /* "*" at the end of the pattern matches */ |
664 }else if( c==matchOther ){ | 672 }else if( c==matchOther ){ |
665 if( esc ){ | 673 if( pInfo->matchSet==0 ){ |
666 c = sqlite3Utf8Read(&zPattern); | 674 c = sqlite3Utf8Read(&zPattern); |
667 if( c==0 ) return 0; | 675 if( c==0 ) return SQLITE_NOWILDCARDMATCH; |
668 }else{ | 676 }else{ |
669 /* "[...]" immediately follows the "*". We have to do a slow | 677 /* "[...]" immediately follows the "*". We have to do a slow |
670 ** recursive search in this case, but it is an unusual case. */ | 678 ** recursive search in this case, but it is an unusual case. */ |
671 assert( matchOther<0x80 ); /* '[' is a single-byte character */ | 679 assert( matchOther<0x80 ); /* '[' is a single-byte character */ |
672 while( *zString | 680 while( *zString ){ |
673 && patternCompare(&zPattern[-1],zString,pInfo,esc)==0 ){ | 681 int bMatch = patternCompare(&zPattern[-1],zString,pInfo,matchOther); |
| 682 if( bMatch!=SQLITE_NOMATCH ) return bMatch; |
674 SQLITE_SKIP_UTF8(zString); | 683 SQLITE_SKIP_UTF8(zString); |
675 } | 684 } |
676 return *zString!=0; | 685 return SQLITE_NOWILDCARDMATCH; |
677 } | 686 } |
678 } | 687 } |
679 | 688 |
680 /* At this point variable c contains the first character of the | 689 /* At this point variable c contains the first character of the |
681 ** pattern string past the "*". Search in the input string for the | 690 ** pattern string past the "*". Search in the input string for the |
682 ** first matching character and recursively contine the match from | 691 ** first matching character and recursively continue the match from |
683 ** that point. | 692 ** that point. |
684 ** | 693 ** |
685 ** For a case-insensitive search, set variable cx to be the same as | 694 ** For a case-insensitive search, set variable cx to be the same as |
686 ** c but in the other case and search the input string for either | 695 ** c but in the other case and search the input string for either |
687 ** c or cx. | 696 ** c or cx. |
688 */ | 697 */ |
689 if( c<=0x80 ){ | 698 if( c<=0x80 ){ |
690 u32 cx; | 699 u32 cx; |
| 700 int bMatch; |
691 if( noCase ){ | 701 if( noCase ){ |
692 cx = sqlite3Toupper(c); | 702 cx = sqlite3Toupper(c); |
693 c = sqlite3Tolower(c); | 703 c = sqlite3Tolower(c); |
694 }else{ | 704 }else{ |
695 cx = c; | 705 cx = c; |
696 } | 706 } |
697 while( (c2 = *(zString++))!=0 ){ | 707 while( (c2 = *(zString++))!=0 ){ |
698 if( c2!=c && c2!=cx ) continue; | 708 if( c2!=c && c2!=cx ) continue; |
699 if( patternCompare(zPattern,zString,pInfo,esc) ) return 1; | 709 bMatch = patternCompare(zPattern,zString,pInfo,matchOther); |
| 710 if( bMatch!=SQLITE_NOMATCH ) return bMatch; |
700 } | 711 } |
701 }else{ | 712 }else{ |
| 713 int bMatch; |
702 while( (c2 = Utf8Read(zString))!=0 ){ | 714 while( (c2 = Utf8Read(zString))!=0 ){ |
703 if( c2!=c ) continue; | 715 if( c2!=c ) continue; |
704 if( patternCompare(zPattern,zString,pInfo,esc) ) return 1; | 716 bMatch = patternCompare(zPattern,zString,pInfo,matchOther); |
| 717 if( bMatch!=SQLITE_NOMATCH ) return bMatch; |
705 } | 718 } |
706 } | 719 } |
707 return 0; | 720 return SQLITE_NOWILDCARDMATCH; |
708 } | 721 } |
709 if( c==matchOther ){ | 722 if( c==matchOther ){ |
710 if( esc ){ | 723 if( pInfo->matchSet==0 ){ |
711 c = sqlite3Utf8Read(&zPattern); | 724 c = sqlite3Utf8Read(&zPattern); |
712 if( c==0 ) return 0; | 725 if( c==0 ) return SQLITE_NOMATCH; |
713 zEscaped = zPattern; | 726 zEscaped = zPattern; |
714 }else{ | 727 }else{ |
715 u32 prior_c = 0; | 728 u32 prior_c = 0; |
716 int seen = 0; | 729 int seen = 0; |
717 int invert = 0; | 730 int invert = 0; |
718 c = sqlite3Utf8Read(&zString); | 731 c = sqlite3Utf8Read(&zString); |
719 if( c==0 ) return 0; | 732 if( c==0 ) return SQLITE_NOMATCH; |
720 c2 = sqlite3Utf8Read(&zPattern); | 733 c2 = sqlite3Utf8Read(&zPattern); |
721 if( c2=='^' ){ | 734 if( c2=='^' ){ |
722 invert = 1; | 735 invert = 1; |
723 c2 = sqlite3Utf8Read(&zPattern); | 736 c2 = sqlite3Utf8Read(&zPattern); |
724 } | 737 } |
725 if( c2==']' ){ | 738 if( c2==']' ){ |
726 if( c==']' ) seen = 1; | 739 if( c==']' ) seen = 1; |
727 c2 = sqlite3Utf8Read(&zPattern); | 740 c2 = sqlite3Utf8Read(&zPattern); |
728 } | 741 } |
729 while( c2 && c2!=']' ){ | 742 while( c2 && c2!=']' ){ |
730 if( c2=='-' && zPattern[0]!=']' && zPattern[0]!=0 && prior_c>0 ){ | 743 if( c2=='-' && zPattern[0]!=']' && zPattern[0]!=0 && prior_c>0 ){ |
731 c2 = sqlite3Utf8Read(&zPattern); | 744 c2 = sqlite3Utf8Read(&zPattern); |
732 if( c>=prior_c && c<=c2 ) seen = 1; | 745 if( c>=prior_c && c<=c2 ) seen = 1; |
733 prior_c = 0; | 746 prior_c = 0; |
734 }else{ | 747 }else{ |
735 if( c==c2 ){ | 748 if( c==c2 ){ |
736 seen = 1; | 749 seen = 1; |
737 } | 750 } |
738 prior_c = c2; | 751 prior_c = c2; |
739 } | 752 } |
740 c2 = sqlite3Utf8Read(&zPattern); | 753 c2 = sqlite3Utf8Read(&zPattern); |
741 } | 754 } |
742 if( c2==0 || (seen ^ invert)==0 ){ | 755 if( c2==0 || (seen ^ invert)==0 ){ |
743 return 0; | 756 return SQLITE_NOMATCH; |
744 } | 757 } |
745 continue; | 758 continue; |
746 } | 759 } |
747 } | 760 } |
748 c2 = Utf8Read(zString); | 761 c2 = Utf8Read(zString); |
749 if( c==c2 ) continue; | 762 if( c==c2 ) continue; |
750 if( noCase && c<0x80 && c2<0x80 && sqlite3Tolower(c)==sqlite3Tolower(c2) ){ | 763 if( noCase && sqlite3Tolower(c)==sqlite3Tolower(c2) && c<0x80 && c2<0x80 ){ |
751 continue; | 764 continue; |
752 } | 765 } |
753 if( c==matchOne && zPattern!=zEscaped && c2!=0 ) continue; | 766 if( c==matchOne && zPattern!=zEscaped && c2!=0 ) continue; |
754 return 0; | 767 return SQLITE_NOMATCH; |
755 } | 768 } |
756 return *zString==0; | 769 return *zString==0 ? SQLITE_MATCH : SQLITE_NOMATCH; |
757 } | 770 } |
758 | 771 |
759 /* | 772 /* |
760 ** The sqlite3_strglob() interface. | 773 ** The sqlite3_strglob() interface. Return 0 on a match (like strcmp()) and |
| 774 ** non-zero if there is no match. |
761 */ | 775 */ |
762 int sqlite3_strglob(const char *zGlobPattern, const char *zString){ | 776 int sqlite3_strglob(const char *zGlobPattern, const char *zString){ |
763 return patternCompare((u8*)zGlobPattern, (u8*)zString, &globInfo, 0)==0; | 777 return patternCompare((u8*)zGlobPattern, (u8*)zString, &globInfo, '['); |
764 } | 778 } |
765 | 779 |
766 /* | 780 /* |
767 ** The sqlite3_strlike() interface. | 781 ** The sqlite3_strlike() interface. Return 0 on a match and non-zero for |
| 782 ** a miss - like strcmp(). |
768 */ | 783 */ |
769 int sqlite3_strlike(const char *zPattern, const char *zStr, unsigned int esc){ | 784 int sqlite3_strlike(const char *zPattern, const char *zStr, unsigned int esc){ |
770 return patternCompare((u8*)zPattern, (u8*)zStr, &likeInfoNorm, esc)==0; | 785 return patternCompare((u8*)zPattern, (u8*)zStr, &likeInfoNorm, esc); |
771 } | 786 } |
772 | 787 |
773 /* | 788 /* |
774 ** Count the number of times that the LIKE operator (or GLOB which is | 789 ** Count the number of times that the LIKE operator (or GLOB which is |
775 ** just a variation of LIKE) gets called. This is used for testing | 790 ** just a variation of LIKE) gets called. This is used for testing |
776 ** only. | 791 ** only. |
777 */ | 792 */ |
778 #ifdef SQLITE_TEST | 793 #ifdef SQLITE_TEST |
779 int sqlite3_like_count = 0; | 794 int sqlite3_like_count = 0; |
780 #endif | 795 #endif |
(...skipping 10 matching lines...) Expand all Loading... |
791 ** | 806 ** |
792 ** This same function (with a different compareInfo structure) computes | 807 ** This same function (with a different compareInfo structure) computes |
793 ** the GLOB operator. | 808 ** the GLOB operator. |
794 */ | 809 */ |
795 static void likeFunc( | 810 static void likeFunc( |
796 sqlite3_context *context, | 811 sqlite3_context *context, |
797 int argc, | 812 int argc, |
798 sqlite3_value **argv | 813 sqlite3_value **argv |
799 ){ | 814 ){ |
800 const unsigned char *zA, *zB; | 815 const unsigned char *zA, *zB; |
801 u32 escape = 0; | 816 u32 escape; |
802 int nPat; | 817 int nPat; |
803 sqlite3 *db = sqlite3_context_db_handle(context); | 818 sqlite3 *db = sqlite3_context_db_handle(context); |
| 819 struct compareInfo *pInfo = sqlite3_user_data(context); |
804 | 820 |
805 #ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS | 821 #ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS |
806 if( sqlite3_value_type(argv[0])==SQLITE_BLOB | 822 if( sqlite3_value_type(argv[0])==SQLITE_BLOB |
807 || sqlite3_value_type(argv[1])==SQLITE_BLOB | 823 || sqlite3_value_type(argv[1])==SQLITE_BLOB |
808 ){ | 824 ){ |
809 #ifdef SQLITE_TEST | 825 #ifdef SQLITE_TEST |
810 sqlite3_like_count++; | 826 sqlite3_like_count++; |
811 #endif | 827 #endif |
812 sqlite3_result_int(context, 0); | 828 sqlite3_result_int(context, 0); |
813 return; | 829 return; |
(...skipping 19 matching lines...) Expand all Loading... |
833 ** Otherwise, return an error. | 849 ** Otherwise, return an error. |
834 */ | 850 */ |
835 const unsigned char *zEsc = sqlite3_value_text(argv[2]); | 851 const unsigned char *zEsc = sqlite3_value_text(argv[2]); |
836 if( zEsc==0 ) return; | 852 if( zEsc==0 ) return; |
837 if( sqlite3Utf8CharLen((char*)zEsc, -1)!=1 ){ | 853 if( sqlite3Utf8CharLen((char*)zEsc, -1)!=1 ){ |
838 sqlite3_result_error(context, | 854 sqlite3_result_error(context, |
839 "ESCAPE expression must be a single character", -1); | 855 "ESCAPE expression must be a single character", -1); |
840 return; | 856 return; |
841 } | 857 } |
842 escape = sqlite3Utf8Read(&zEsc); | 858 escape = sqlite3Utf8Read(&zEsc); |
| 859 }else{ |
| 860 escape = pInfo->matchSet; |
843 } | 861 } |
844 if( zA && zB ){ | 862 if( zA && zB ){ |
845 struct compareInfo *pInfo = sqlite3_user_data(context); | |
846 #ifdef SQLITE_TEST | 863 #ifdef SQLITE_TEST |
847 sqlite3_like_count++; | 864 sqlite3_like_count++; |
848 #endif | 865 #endif |
849 | 866 sqlite3_result_int(context, patternCompare(zB, zA, pInfo, escape)==SQLITE_MA
TCH); |
850 sqlite3_result_int(context, patternCompare(zB, zA, pInfo, escape)); | |
851 } | 867 } |
852 } | 868 } |
853 | 869 |
854 /* | 870 /* |
855 ** Implementation of the NULLIF(x,y) function. The result is the first | 871 ** Implementation of the NULLIF(x,y) function. The result is the first |
856 ** argument if the arguments are different. The result is NULL if the | 872 ** argument if the arguments are different. The result is NULL if the |
857 ** arguments are equal to each other. | 873 ** arguments are equal to each other. |
858 */ | 874 */ |
859 static void nullifFunc( | 875 static void nullifFunc( |
860 sqlite3_context *context, | 876 sqlite3_context *context, |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1315 } | 1331 } |
1316 } | 1332 } |
1317 if( zCharSet ){ | 1333 if( zCharSet ){ |
1318 sqlite3_free(azChar); | 1334 sqlite3_free(azChar); |
1319 } | 1335 } |
1320 } | 1336 } |
1321 sqlite3_result_text(context, (char*)zIn, nIn, SQLITE_TRANSIENT); | 1337 sqlite3_result_text(context, (char*)zIn, nIn, SQLITE_TRANSIENT); |
1322 } | 1338 } |
1323 | 1339 |
1324 | 1340 |
| 1341 #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION |
| 1342 /* |
| 1343 ** The "unknown" function is automatically substituted in place of |
| 1344 ** any unrecognized function name when doing an EXPLAIN or EXPLAIN QUERY PLAN |
| 1345 ** when the SQLITE_ENABLE_UNKNOWN_FUNCTION compile-time option is used. |
| 1346 ** When the "sqlite3" command-line shell is built using this functionality, |
| 1347 ** that allows an EXPLAIN or EXPLAIN QUERY PLAN for complex queries |
| 1348 ** involving application-defined functions to be examined in a generic |
| 1349 ** sqlite3 shell. |
| 1350 */ |
| 1351 static void unknownFunc( |
| 1352 sqlite3_context *context, |
| 1353 int argc, |
| 1354 sqlite3_value **argv |
| 1355 ){ |
| 1356 /* no-op */ |
| 1357 } |
| 1358 #endif /*SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION*/ |
| 1359 |
| 1360 |
1325 /* IMP: R-25361-16150 This function is omitted from SQLite by default. It | 1361 /* IMP: R-25361-16150 This function is omitted from SQLite by default. It |
1326 ** is only available if the SQLITE_SOUNDEX compile-time option is used | 1362 ** is only available if the SQLITE_SOUNDEX compile-time option is used |
1327 ** when SQLite is built. | 1363 ** when SQLite is built. |
1328 */ | 1364 */ |
1329 #ifdef SQLITE_SOUNDEX | 1365 #ifdef SQLITE_SOUNDEX |
1330 /* | 1366 /* |
1331 ** Compute the soundex encoding of a word. | 1367 ** Compute the soundex encoding of a word. |
1332 ** | 1368 ** |
1333 ** IMP: R-59782-00072 The soundex(X) function returns a string that is the | 1369 ** IMP: R-59782-00072 The soundex(X) function returns a string that is the |
1334 ** soundex encoding of the string X. | 1370 ** soundex encoding of the string X. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1385 #ifndef SQLITE_OMIT_LOAD_EXTENSION | 1421 #ifndef SQLITE_OMIT_LOAD_EXTENSION |
1386 /* | 1422 /* |
1387 ** A function that loads a shared-library extension then returns NULL. | 1423 ** A function that loads a shared-library extension then returns NULL. |
1388 */ | 1424 */ |
1389 static void loadExt(sqlite3_context *context, int argc, sqlite3_value **argv){ | 1425 static void loadExt(sqlite3_context *context, int argc, sqlite3_value **argv){ |
1390 const char *zFile = (const char *)sqlite3_value_text(argv[0]); | 1426 const char *zFile = (const char *)sqlite3_value_text(argv[0]); |
1391 const char *zProc; | 1427 const char *zProc; |
1392 sqlite3 *db = sqlite3_context_db_handle(context); | 1428 sqlite3 *db = sqlite3_context_db_handle(context); |
1393 char *zErrMsg = 0; | 1429 char *zErrMsg = 0; |
1394 | 1430 |
| 1431 /* Disallow the load_extension() SQL function unless the SQLITE_LoadExtFunc |
| 1432 ** flag is set. See the sqlite3_enable_load_extension() API. |
| 1433 */ |
| 1434 if( (db->flags & SQLITE_LoadExtFunc)==0 ){ |
| 1435 sqlite3_result_error(context, "not authorized", -1); |
| 1436 return; |
| 1437 } |
| 1438 |
1395 if( argc==2 ){ | 1439 if( argc==2 ){ |
1396 zProc = (const char *)sqlite3_value_text(argv[1]); | 1440 zProc = (const char *)sqlite3_value_text(argv[1]); |
1397 }else{ | 1441 }else{ |
1398 zProc = 0; | 1442 zProc = 0; |
1399 } | 1443 } |
1400 if( zFile && sqlite3_load_extension(db, zFile, zProc, &zErrMsg) ){ | 1444 if( zFile && sqlite3_load_extension(db, zFile, zProc, &zErrMsg) ){ |
1401 sqlite3_result_error(context, zErrMsg, -1); | 1445 sqlite3_result_error(context, zErrMsg, -1); |
1402 sqlite3_free(zErrMsg); | 1446 sqlite3_free(zErrMsg); |
1403 } | 1447 } |
1404 } | 1448 } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1583 int firstTerm = pAccum->mxAlloc==0; | 1627 int firstTerm = pAccum->mxAlloc==0; |
1584 pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH]; | 1628 pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH]; |
1585 if( !firstTerm ){ | 1629 if( !firstTerm ){ |
1586 if( argc==2 ){ | 1630 if( argc==2 ){ |
1587 zSep = (char*)sqlite3_value_text(argv[1]); | 1631 zSep = (char*)sqlite3_value_text(argv[1]); |
1588 nSep = sqlite3_value_bytes(argv[1]); | 1632 nSep = sqlite3_value_bytes(argv[1]); |
1589 }else{ | 1633 }else{ |
1590 zSep = ","; | 1634 zSep = ","; |
1591 nSep = 1; | 1635 nSep = 1; |
1592 } | 1636 } |
1593 if( nSep ) sqlite3StrAccumAppend(pAccum, zSep, nSep); | 1637 if( zSep ) sqlite3StrAccumAppend(pAccum, zSep, nSep); |
1594 } | 1638 } |
1595 zVal = (char*)sqlite3_value_text(argv[0]); | 1639 zVal = (char*)sqlite3_value_text(argv[0]); |
1596 nVal = sqlite3_value_bytes(argv[0]); | 1640 nVal = sqlite3_value_bytes(argv[0]); |
1597 if( zVal ) sqlite3StrAccumAppend(pAccum, zVal, nVal); | 1641 if( zVal ) sqlite3StrAccumAppend(pAccum, zVal, nVal); |
1598 } | 1642 } |
1599 } | 1643 } |
1600 static void groupConcatFinalize(sqlite3_context *context){ | 1644 static void groupConcatFinalize(sqlite3_context *context){ |
1601 StrAccum *pAccum; | 1645 StrAccum *pAccum; |
1602 pAccum = sqlite3_aggregate_context(context, 0); | 1646 pAccum = sqlite3_aggregate_context(context, 0); |
1603 if( pAccum ){ | 1647 if( pAccum ){ |
1604 if( pAccum->accError==STRACCUM_TOOBIG ){ | 1648 if( pAccum->accError==STRACCUM_TOOBIG ){ |
1605 sqlite3_result_error_toobig(context); | 1649 sqlite3_result_error_toobig(context); |
1606 }else if( pAccum->accError==STRACCUM_NOMEM ){ | 1650 }else if( pAccum->accError==STRACCUM_NOMEM ){ |
1607 sqlite3_result_error_nomem(context); | 1651 sqlite3_result_error_nomem(context); |
1608 }else{ | 1652 }else{ |
1609 sqlite3_result_text(context, sqlite3StrAccumFinish(pAccum), -1, | 1653 sqlite3_result_text(context, sqlite3StrAccumFinish(pAccum), -1, |
1610 sqlite3_free); | 1654 sqlite3_free); |
1611 } | 1655 } |
1612 } | 1656 } |
1613 } | 1657 } |
1614 | 1658 |
1615 /* | 1659 /* |
1616 ** This routine does per-connection function registration. Most | 1660 ** This routine does per-connection function registration. Most |
1617 ** of the built-in functions above are part of the global function set. | 1661 ** of the built-in functions above are part of the global function set. |
1618 ** This routine only deals with those that are not global. | 1662 ** This routine only deals with those that are not global. |
1619 */ | 1663 */ |
1620 void sqlite3RegisterBuiltinFunctions(sqlite3 *db){ | 1664 void sqlite3RegisterPerConnectionBuiltinFunctions(sqlite3 *db){ |
1621 int rc = sqlite3_overload_function(db, "MATCH", 2); | 1665 int rc = sqlite3_overload_function(db, "MATCH", 2); |
1622 assert( rc==SQLITE_NOMEM || rc==SQLITE_OK ); | 1666 assert( rc==SQLITE_NOMEM || rc==SQLITE_OK ); |
1623 if( rc==SQLITE_NOMEM ){ | 1667 if( rc==SQLITE_NOMEM ){ |
1624 db->mallocFailed = 1; | 1668 sqlite3OomFault(db); |
1625 } | 1669 } |
1626 } | 1670 } |
1627 | 1671 |
1628 /* | 1672 /* |
1629 ** Set the LIKEOPT flag on the 2-argument function with the given name. | 1673 ** Set the LIKEOPT flag on the 2-argument function with the given name. |
1630 */ | 1674 */ |
1631 static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){ | 1675 static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){ |
1632 FuncDef *pDef; | 1676 FuncDef *pDef; |
1633 pDef = sqlite3FindFunction(db, zName, sqlite3Strlen30(zName), | 1677 pDef = sqlite3FindFunction(db, zName, 2, SQLITE_UTF8, 0); |
1634 2, SQLITE_UTF8, 0); | |
1635 if( ALWAYS(pDef) ){ | 1678 if( ALWAYS(pDef) ){ |
1636 pDef->funcFlags |= flagVal; | 1679 pDef->funcFlags |= flagVal; |
1637 } | 1680 } |
1638 } | 1681 } |
1639 | 1682 |
1640 /* | 1683 /* |
1641 ** Register the built-in LIKE and GLOB functions. The caseSensitive | 1684 ** Register the built-in LIKE and GLOB functions. The caseSensitive |
1642 ** parameter determines whether or not the LIKE operator is case | 1685 ** parameter determines whether or not the LIKE operator is case |
1643 ** sensitive. GLOB is always case sensitive. | 1686 ** sensitive. GLOB is always case sensitive. |
1644 */ | 1687 */ |
(...skipping 27 matching lines...) Expand all Loading... |
1672 */ | 1715 */ |
1673 int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){ | 1716 int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){ |
1674 FuncDef *pDef; | 1717 FuncDef *pDef; |
1675 if( pExpr->op!=TK_FUNCTION | 1718 if( pExpr->op!=TK_FUNCTION |
1676 || !pExpr->x.pList | 1719 || !pExpr->x.pList |
1677 || pExpr->x.pList->nExpr!=2 | 1720 || pExpr->x.pList->nExpr!=2 |
1678 ){ | 1721 ){ |
1679 return 0; | 1722 return 0; |
1680 } | 1723 } |
1681 assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); | 1724 assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
1682 pDef = sqlite3FindFunction(db, pExpr->u.zToken, | 1725 pDef = sqlite3FindFunction(db, pExpr->u.zToken, 2, SQLITE_UTF8, 0); |
1683 sqlite3Strlen30(pExpr->u.zToken), | |
1684 2, SQLITE_UTF8, 0); | |
1685 if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){ | 1726 if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){ |
1686 return 0; | 1727 return 0; |
1687 } | 1728 } |
1688 | 1729 |
1689 /* The memcpy() statement assumes that the wildcard characters are | 1730 /* The memcpy() statement assumes that the wildcard characters are |
1690 ** the first three statements in the compareInfo structure. The | 1731 ** the first three statements in the compareInfo structure. The |
1691 ** asserts() that follow verify that assumption | 1732 ** asserts() that follow verify that assumption |
1692 */ | 1733 */ |
1693 memcpy(aWc, pDef->pUserData, 3); | 1734 memcpy(aWc, pDef->pUserData, 3); |
1694 assert( (char*)&likeInfoAlt == (char*)&likeInfoAlt.matchAll ); | 1735 assert( (char*)&likeInfoAlt == (char*)&likeInfoAlt.matchAll ); |
1695 assert( &((char*)&likeInfoAlt)[1] == (char*)&likeInfoAlt.matchOne ); | 1736 assert( &((char*)&likeInfoAlt)[1] == (char*)&likeInfoAlt.matchOne ); |
1696 assert( &((char*)&likeInfoAlt)[2] == (char*)&likeInfoAlt.matchSet ); | 1737 assert( &((char*)&likeInfoAlt)[2] == (char*)&likeInfoAlt.matchSet ); |
1697 *pIsNocase = (pDef->funcFlags & SQLITE_FUNC_CASE)==0; | 1738 *pIsNocase = (pDef->funcFlags & SQLITE_FUNC_CASE)==0; |
1698 return 1; | 1739 return 1; |
1699 } | 1740 } |
1700 | 1741 |
1701 /* | 1742 /* |
1702 ** All of the FuncDef structures in the aBuiltinFunc[] array above | 1743 ** All of the FuncDef structures in the aBuiltinFunc[] array above |
1703 ** to the global function hash table. This occurs at start-time (as | 1744 ** to the global function hash table. This occurs at start-time (as |
1704 ** a consequence of calling sqlite3_initialize()). | 1745 ** a consequence of calling sqlite3_initialize()). |
1705 ** | 1746 ** |
1706 ** After this routine runs | 1747 ** After this routine runs |
1707 */ | 1748 */ |
1708 void sqlite3RegisterGlobalFunctions(void){ | 1749 void sqlite3RegisterBuiltinFunctions(void){ |
1709 /* | 1750 /* |
1710 ** The following array holds FuncDef structures for all of the functions | 1751 ** The following array holds FuncDef structures for all of the functions |
1711 ** defined in this file. | 1752 ** defined in this file. |
1712 ** | 1753 ** |
1713 ** The array cannot be constant since changes are made to the | 1754 ** The array cannot be constant since changes are made to the |
1714 ** FuncDef.pHash elements at start-time. The elements of this array | 1755 ** FuncDef.pHash elements at start-time. The elements of this array |
1715 ** are read-only after initialization is complete. | 1756 ** are read-only after initialization is complete. |
| 1757 ** |
| 1758 ** For peak efficiency, put the most frequently used function last. |
1716 */ | 1759 */ |
1717 static SQLITE_WSD FuncDef aBuiltinFunc[] = { | 1760 static FuncDef aBuiltinFunc[] = { |
| 1761 #ifdef SQLITE_SOUNDEX |
| 1762 FUNCTION(soundex, 1, 0, 0, soundexFunc ), |
| 1763 #endif |
| 1764 #ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 1765 VFUNCTION(load_extension, 1, 0, 0, loadExt ), |
| 1766 VFUNCTION(load_extension, 2, 0, 0, loadExt ), |
| 1767 #endif |
| 1768 #if SQLITE_USER_AUTHENTICATION |
| 1769 FUNCTION(sqlite_crypt, 2, 0, 0, sqlite3CryptFunc ), |
| 1770 #endif |
| 1771 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
| 1772 DFUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ), |
| 1773 DFUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ), |
| 1774 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 1775 FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), |
| 1776 FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), |
| 1777 FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), |
| 1778 #ifdef SQLITE_DEBUG |
| 1779 FUNCTION2(affinity, 1, 0, 0, noopFunc, SQLITE_FUNC_AFFINITY), |
| 1780 #endif |
1718 FUNCTION(ltrim, 1, 1, 0, trimFunc ), | 1781 FUNCTION(ltrim, 1, 1, 0, trimFunc ), |
1719 FUNCTION(ltrim, 2, 1, 0, trimFunc ), | 1782 FUNCTION(ltrim, 2, 1, 0, trimFunc ), |
1720 FUNCTION(rtrim, 1, 2, 0, trimFunc ), | 1783 FUNCTION(rtrim, 1, 2, 0, trimFunc ), |
1721 FUNCTION(rtrim, 2, 2, 0, trimFunc ), | 1784 FUNCTION(rtrim, 2, 2, 0, trimFunc ), |
1722 FUNCTION(trim, 1, 3, 0, trimFunc ), | 1785 FUNCTION(trim, 1, 3, 0, trimFunc ), |
1723 FUNCTION(trim, 2, 3, 0, trimFunc ), | 1786 FUNCTION(trim, 2, 3, 0, trimFunc ), |
1724 FUNCTION(min, -1, 0, 1, minmaxFunc ), | 1787 FUNCTION(min, -1, 0, 1, minmaxFunc ), |
1725 FUNCTION(min, 0, 0, 1, 0 ), | 1788 FUNCTION(min, 0, 0, 1, 0 ), |
1726 AGGREGATE2(min, 1, 0, 1, minmaxStep, minMaxFinalize, | 1789 AGGREGATE2(min, 1, 0, 1, minmaxStep, minMaxFinalize, |
1727 SQLITE_FUNC_MINMAX ), | 1790 SQLITE_FUNC_MINMAX ), |
1728 FUNCTION(max, -1, 1, 1, minmaxFunc ), | 1791 FUNCTION(max, -1, 1, 1, minmaxFunc ), |
1729 FUNCTION(max, 0, 1, 1, 0 ), | 1792 FUNCTION(max, 0, 1, 1, 0 ), |
1730 AGGREGATE2(max, 1, 1, 1, minmaxStep, minMaxFinalize, | 1793 AGGREGATE2(max, 1, 1, 1, minmaxStep, minMaxFinalize, |
1731 SQLITE_FUNC_MINMAX ), | 1794 SQLITE_FUNC_MINMAX ), |
1732 FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF), | 1795 FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF), |
1733 FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH), | 1796 FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH), |
1734 FUNCTION(instr, 2, 0, 0, instrFunc ), | 1797 FUNCTION(instr, 2, 0, 0, instrFunc ), |
1735 FUNCTION(substr, 2, 0, 0, substrFunc ), | |
1736 FUNCTION(substr, 3, 0, 0, substrFunc ), | |
1737 FUNCTION(printf, -1, 0, 0, printfFunc ), | 1798 FUNCTION(printf, -1, 0, 0, printfFunc ), |
1738 FUNCTION(unicode, 1, 0, 0, unicodeFunc ), | 1799 FUNCTION(unicode, 1, 0, 0, unicodeFunc ), |
1739 FUNCTION(char, -1, 0, 0, charFunc ), | 1800 FUNCTION(char, -1, 0, 0, charFunc ), |
1740 FUNCTION(abs, 1, 0, 0, absFunc ), | 1801 FUNCTION(abs, 1, 0, 0, absFunc ), |
1741 #ifndef SQLITE_OMIT_FLOATING_POINT | 1802 #ifndef SQLITE_OMIT_FLOATING_POINT |
1742 FUNCTION(round, 1, 0, 0, roundFunc ), | 1803 FUNCTION(round, 1, 0, 0, roundFunc ), |
1743 FUNCTION(round, 2, 0, 0, roundFunc ), | 1804 FUNCTION(round, 2, 0, 0, roundFunc ), |
1744 #endif | 1805 #endif |
1745 FUNCTION(upper, 1, 0, 0, upperFunc ), | 1806 FUNCTION(upper, 1, 0, 0, upperFunc ), |
1746 FUNCTION(lower, 1, 0, 0, lowerFunc ), | 1807 FUNCTION(lower, 1, 0, 0, lowerFunc ), |
1747 FUNCTION(coalesce, 1, 0, 0, 0 ), | |
1748 FUNCTION(coalesce, 0, 0, 0, 0 ), | |
1749 FUNCTION2(coalesce, -1, 0, 0, noopFunc, SQLITE_FUNC_COALESCE), | |
1750 FUNCTION(hex, 1, 0, 0, hexFunc ), | 1808 FUNCTION(hex, 1, 0, 0, hexFunc ), |
1751 FUNCTION2(ifnull, 2, 0, 0, noopFunc, SQLITE_FUNC_COALESCE), | 1809 FUNCTION2(ifnull, 2, 0, 0, noopFunc, SQLITE_FUNC_COALESCE), |
1752 FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), | |
1753 FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), | |
1754 FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), | |
1755 VFUNCTION(random, 0, 0, 0, randomFunc ), | 1810 VFUNCTION(random, 0, 0, 0, randomFunc ), |
1756 VFUNCTION(randomblob, 1, 0, 0, randomBlob ), | 1811 VFUNCTION(randomblob, 1, 0, 0, randomBlob ), |
1757 FUNCTION(nullif, 2, 0, 1, nullifFunc ), | 1812 FUNCTION(nullif, 2, 0, 1, nullifFunc ), |
1758 DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ), | 1813 DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ), |
1759 DFUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ), | 1814 DFUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ), |
1760 FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ), | 1815 FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ), |
1761 #if SQLITE_USER_AUTHENTICATION | |
1762 FUNCTION(sqlite_crypt, 2, 0, 0, sqlite3CryptFunc ), | |
1763 #endif | |
1764 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS | |
1765 DFUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ), | |
1766 DFUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ), | |
1767 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ | |
1768 FUNCTION(quote, 1, 0, 0, quoteFunc ), | 1816 FUNCTION(quote, 1, 0, 0, quoteFunc ), |
1769 VFUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid), | 1817 VFUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid), |
1770 VFUNCTION(changes, 0, 0, 0, changes ), | 1818 VFUNCTION(changes, 0, 0, 0, changes ), |
1771 VFUNCTION(total_changes, 0, 0, 0, total_changes ), | 1819 VFUNCTION(total_changes, 0, 0, 0, total_changes ), |
1772 FUNCTION(replace, 3, 0, 0, replaceFunc ), | 1820 FUNCTION(replace, 3, 0, 0, replaceFunc ), |
1773 FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ), | 1821 FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ), |
1774 #ifdef SQLITE_SOUNDEX | 1822 FUNCTION(substr, 2, 0, 0, substrFunc ), |
1775 FUNCTION(soundex, 1, 0, 0, soundexFunc ), | 1823 FUNCTION(substr, 3, 0, 0, substrFunc ), |
1776 #endif | |
1777 #ifndef SQLITE_OMIT_LOAD_EXTENSION | |
1778 VFUNCTION(load_extension, 1, 0, 0, loadExt ), | |
1779 VFUNCTION(load_extension, 2, 0, 0, loadExt ), | |
1780 #endif | |
1781 AGGREGATE(sum, 1, 0, 0, sumStep, sumFinalize ), | 1824 AGGREGATE(sum, 1, 0, 0, sumStep, sumFinalize ), |
1782 AGGREGATE(total, 1, 0, 0, sumStep, totalFinalize ), | 1825 AGGREGATE(total, 1, 0, 0, sumStep, totalFinalize ), |
1783 AGGREGATE(avg, 1, 0, 0, sumStep, avgFinalize ), | 1826 AGGREGATE(avg, 1, 0, 0, sumStep, avgFinalize ), |
1784 AGGREGATE2(count, 0, 0, 0, countStep, countFinalize, | 1827 AGGREGATE2(count, 0, 0, 0, countStep, countFinalize, |
1785 SQLITE_FUNC_COUNT ), | 1828 SQLITE_FUNC_COUNT ), |
1786 AGGREGATE(count, 1, 0, 0, countStep, countFinalize ), | 1829 AGGREGATE(count, 1, 0, 0, countStep, countFinalize ), |
1787 AGGREGATE(group_concat, 1, 0, 0, groupConcatStep, groupConcatFinalize), | 1830 AGGREGATE(group_concat, 1, 0, 0, groupConcatStep, groupConcatFinalize), |
1788 AGGREGATE(group_concat, 2, 0, 0, groupConcatStep, groupConcatFinalize), | 1831 AGGREGATE(group_concat, 2, 0, 0, groupConcatStep, groupConcatFinalize), |
1789 | 1832 |
1790 LIKEFUNC(glob, 2, &globInfo, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE), | 1833 LIKEFUNC(glob, 2, &globInfo, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE), |
1791 #ifdef SQLITE_CASE_SENSITIVE_LIKE | 1834 #ifdef SQLITE_CASE_SENSITIVE_LIKE |
1792 LIKEFUNC(like, 2, &likeInfoAlt, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE), | 1835 LIKEFUNC(like, 2, &likeInfoAlt, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE), |
1793 LIKEFUNC(like, 3, &likeInfoAlt, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE), | 1836 LIKEFUNC(like, 3, &likeInfoAlt, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE), |
1794 #else | 1837 #else |
1795 LIKEFUNC(like, 2, &likeInfoNorm, SQLITE_FUNC_LIKE), | 1838 LIKEFUNC(like, 2, &likeInfoNorm, SQLITE_FUNC_LIKE), |
1796 LIKEFUNC(like, 3, &likeInfoNorm, SQLITE_FUNC_LIKE), | 1839 LIKEFUNC(like, 3, &likeInfoNorm, SQLITE_FUNC_LIKE), |
1797 #endif | 1840 #endif |
| 1841 #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION |
| 1842 FUNCTION(unknown, -1, 0, 0, unknownFunc ), |
| 1843 #endif |
| 1844 FUNCTION(coalesce, 1, 0, 0, 0 ), |
| 1845 FUNCTION(coalesce, 0, 0, 0, 0 ), |
| 1846 FUNCTION2(coalesce, -1, 0, 0, noopFunc, SQLITE_FUNC_COALESCE), |
1798 }; | 1847 }; |
1799 | |
1800 int i; | |
1801 FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions); | |
1802 FuncDef *aFunc = (FuncDef*)&GLOBAL(FuncDef, aBuiltinFunc); | |
1803 | |
1804 for(i=0; i<ArraySize(aBuiltinFunc); i++){ | |
1805 sqlite3FuncDefInsert(pHash, &aFunc[i]); | |
1806 } | |
1807 sqlite3RegisterDateTimeFunctions(); | |
1808 #ifndef SQLITE_OMIT_ALTERTABLE | 1848 #ifndef SQLITE_OMIT_ALTERTABLE |
1809 sqlite3AlterFunctions(); | 1849 sqlite3AlterFunctions(); |
1810 #endif | 1850 #endif |
1811 #if defined(SQLITE_ENABLE_STAT3) || defined(SQLITE_ENABLE_STAT4) | 1851 #if defined(SQLITE_ENABLE_STAT3) || defined(SQLITE_ENABLE_STAT4) |
1812 sqlite3AnalyzeFunctions(); | 1852 sqlite3AnalyzeFunctions(); |
1813 #endif | 1853 #endif |
| 1854 sqlite3RegisterDateTimeFunctions(); |
| 1855 sqlite3InsertBuiltinFuncs(aBuiltinFunc, ArraySize(aBuiltinFunc)); |
| 1856 |
| 1857 #if 0 /* Enable to print out how the built-in functions are hashed */ |
| 1858 { |
| 1859 int i; |
| 1860 FuncDef *p; |
| 1861 for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){ |
| 1862 printf("FUNC-HASH %02d:", i); |
| 1863 for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash){ |
| 1864 int n = sqlite3Strlen30(p->zName); |
| 1865 int h = p->zName[0] + n; |
| 1866 printf(" %s(%d)", p->zName, h); |
| 1867 } |
| 1868 printf("\n"); |
| 1869 } |
| 1870 } |
| 1871 #endif |
1814 } | 1872 } |
OLD | NEW |