From 8b4a94adc1dea3254a7eed1e33c210509c496e2d Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Nov 2015 21:23:59 +0000 Subject: [PATCH] Add the sqlite3_strlike() interface, which might be useful for implementing LIKE operators on virtual tables. FossilOrigin-Name: e70ec71d6883f2f8fc75301ff985bccb5aa06127 --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/analyze.c | 2 +- src/func.c | 7 +++++++ src/sqlite.h.in | 27 +++++++++++++++++++++++++++ src/sqlite3ext.h | 4 ++++ 6 files changed, 50 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 95094a3c1e..f37520206d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\sin\swhereexpr.c\scausing\sa\scrash\swhile\sprocessing\sa\suser-function\staht\saccepts\szero\sarguments. -D 2015-11-24T18:16:15.798 +C Add\sthe\ssqlite3_strlike()\sinterface,\swhich\smight\sbe\suseful\sfor\simplementing\nLIKE\soperators\son\svirtual\stables. +D 2015-11-24T21:23:59.705 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -276,7 +276,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c 9d649e46c780166e416fb11dbd23f8d49aab8267 -F src/analyze.c 4c308880cf53c558070cb8513bdff4ffb1a38a77 +F src/analyze.c 977bd50c751bb939ef52917892e12bedbfcea7ce F src/attach.c e944d0052b577703b9b83aac1638452ff42a8395 F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c 2869a76c03eb393ee795416e2387005553df72bc @@ -295,7 +295,7 @@ F src/delete.c 00af9f08a15ddc5cba5962d3d3e5bf2d67b2e7da F src/expr.c cb1a419508e5b27769a91e00e36e94724e7b1d51 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 31900763094a3736a5fc887469202eb579fef2d0 -F src/func.c ecdd69ec6a1e406f04cc73324be2ebbf6354197f +F src/func.c 5790a898a0c53e6787020ec268425d415e7e03c9 F src/global.c 508e4087f7b41d688e4762dcf4d4fe28cfbc87f9 F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 @@ -341,9 +341,9 @@ F src/resolve.c f4c897ca76ca6d5e0b3f0499c627392ffe657c8e F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c e10586c750d87211caa8f4b239e2bfa6a2049e5b F src/shell.c f0f59ea60ad297f671b7ae0fb957a736ad17c92c -F src/sqlite.h.in a71226fe80bded2af3b99c5aed7363ef486962e1 +F src/sqlite.h.in cbe8643b6a1c7313bf6447a2aa7abdb31c73dd77 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad -F src/sqlite3ext.h 4b66e3e3435da4b4c8c83696d0349f0c503b3924 +F src/sqlite3ext.h 41ef50b0418a7c5ad1337bb80db5a7928dee764f F src/sqliteInt.h 64256d193a16a147d9f6317cc4e095fdd3e0a2e9 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba @@ -1405,7 +1405,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 2fba7a96566b5448f527a4ec6a26e860c4889813 -R f36b8e4e640480a045269560fe77bd48 -U dan -Z 2212cd97f0c21ee66344a63115e7e327 +P 069e51b19c773aa3017a8d307c8daa0766c224ba +R d30ed8c32e99c9a94479405580943fff +U drh +Z d8529710de4140b85add41abcb0a95e1 diff --git a/manifest.uuid b/manifest.uuid index 2adfe4df8a..79fcb989cf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -069e51b19c773aa3017a8d307c8daa0766c224ba \ No newline at end of file +e70ec71d6883f2f8fc75301ff985bccb5aa06127 \ No newline at end of file diff --git a/src/analyze.c b/src/analyze.c index ad752d2c0e..06918eb744 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -990,7 +990,7 @@ static void analyzeOneTable( /* Do not gather statistics on views or virtual tables */ return; } - if( sqlite3_strnicmp(pTab->zName, "sqlite_", 7)==0 ){ + if( sqlite3_strlike("sqlite_%", pTab->zName, 0)==0 ){ /* Do not gather statistics on system tables */ return; } diff --git a/src/func.c b/src/func.c index 8ea1169327..b134c1a7c2 100644 --- a/src/func.c +++ b/src/func.c @@ -763,6 +763,13 @@ int sqlite3_strglob(const char *zGlobPattern, const char *zString){ return patternCompare((u8*)zGlobPattern, (u8*)zString, &globInfo, 0)==0; } +/* +** The sqlite3_strlike() interface. +*/ +int sqlite3_strlike(const char *zPattern, const char *zStr, unsigned int esc){ + return patternCompare((u8*)zPattern, (u8*)zStr, &likeInfoNorm, esc)==0; +} + /* ** Count the number of times that the LIKE operator (or GLOB which is ** just a variation of LIKE) gets called. This is used for testing diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 42652061fb..b93ff5873e 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -7377,9 +7377,36 @@ int sqlite3_strnicmp(const char *, const char *, int); ** ** Note that this routine returns zero on a match and non-zero if the strings ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()]. +** +** See also: sqlite3_strlike(). */ int sqlite3_strglob(const char *zGlob, const char *zStr); +/* +** CAPI3REF: String LIKE Matching +* +** ^The [sqlite3_strlike(P,X,E)] interface returns zero if string X matches +** the LIKE pattern P with escape character E, and it returns non-zero if +** string X does not match the like pattern. +** ^The definition of LIKE pattern matching used in +** [sqlite3_strlike(P,X,E)] is the same as for the "X LIKE P ESCAPE E" +** operator in the SQL dialect used by SQLite. ^For "X LIKE P" without +** the ESCAPE clause, set the E parameter of [sqlite3_strlike(P,X,E)] to 0. +** ^As with the LIKE operator, the [sqlite3_str(P,X,E)] function is case +** insensitive - equivalent upper and lower case ASCII characters match +** one another. +** +** ^The [sqlite3_strlike(P,X,E)] function matches Unicode characters, though +** only ASCII characters are case folded. (This is because when SQLite was +** first written, the case folding rules for Unicode where still in flux.) +** +** Note that this routine returns zero on a match and non-zero if the strings +** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()]. +** +** See also: sqlite3_strglob(). +*/ +int sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc); + /* ** CAPI3REF: Error Logging Interface ** diff --git a/src/sqlite3ext.h b/src/sqlite3ext.h index 017ea308b1..3029a82fa1 100644 --- a/src/sqlite3ext.h +++ b/src/sqlite3ext.h @@ -275,6 +275,8 @@ struct sqlite3_api_routines { /* Version 3.9.0 and later */ unsigned int (*value_subtype)(sqlite3_value*); void (*result_subtype)(sqlite3_context*,unsigned int); + /* Version 3.10.0 and later */ + int (*strlike)(const char*,const char*,unsigned int); }; /* @@ -514,6 +516,8 @@ struct sqlite3_api_routines { /* Version 3.9.0 and later */ #define sqlite3_value_subtype sqlite3_api->value_subtype #define sqlite3_result_subtype sqlite3_api->result_subtype +/* Version 3.10.0 and later */ +#define sqlite3_strlike sqlite3_api->strlike #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) -- 2.39.5