/ Check-in [e70ec71d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the sqlite3_strlike() interface, which might be useful for implementing LIKE operators on virtual tables.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | vtab-like-operator
Files: files | file ages | folders
SHA1: e70ec71d6883f2f8fc75301ff985bccb5aa06127
User & Date: drh 2015-11-24 21:23:59
Context
2015-11-25
01:57
Enhancement the virtual table interface to support LIKE, GLOB, and REGEXP operators. Also add the sqlite3_strlike() interface, which might be useful as part of the implementation of LIKE on some virtual tables. check-in: a6bfd469 user: drh tags: trunk
2015-11-24
21:23
Add the sqlite3_strlike() interface, which might be useful for implementing LIKE operators on virtual tables. Closed-Leaf check-in: e70ec71d user: drh tags: vtab-like-operator
18:16
Fix a problem in whereexpr.c causing a crash while processing a user-function taht accepts zero arguments. check-in: 069e51b1 user: dan tags: vtab-like-operator
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/analyze.c.

   986    986     if( v==0 || NEVER(pTab==0) ){
   987    987       return;
   988    988     }
   989    989     if( pTab->tnum==0 ){
   990    990       /* Do not gather statistics on views or virtual tables */
   991    991       return;
   992    992     }
   993         -  if( sqlite3_strnicmp(pTab->zName, "sqlite_", 7)==0 ){
          993  +  if( sqlite3_strlike("sqlite_%", pTab->zName, 0)==0 ){
   994    994       /* Do not gather statistics on system tables */
   995    995       return;
   996    996     }
   997    997     assert( sqlite3BtreeHoldsAllMutexes(db) );
   998    998     iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
   999    999     assert( iDb>=0 );
  1000   1000     assert( sqlite3SchemaMutexHeld(db, iDb, 0) );

Changes to src/func.c.

   758    758   
   759    759   /*
   760    760   ** The sqlite3_strglob() interface.
   761    761   */
   762    762   int sqlite3_strglob(const char *zGlobPattern, const char *zString){
   763    763     return patternCompare((u8*)zGlobPattern, (u8*)zString, &globInfo, 0)==0;
   764    764   }
          765  +
          766  +/*
          767  +** The sqlite3_strlike() interface.
          768  +*/
          769  +int sqlite3_strlike(const char *zPattern, const char *zStr, unsigned int esc){
          770  +  return patternCompare((u8*)zPattern, (u8*)zStr, &likeInfoNorm, esc)==0;
          771  +}
   765    772   
   766    773   /*
   767    774   ** Count the number of times that the LIKE operator (or GLOB which is
   768    775   ** just a variation of LIKE) gets called.  This is used for testing
   769    776   ** only.
   770    777   */
   771    778   #ifdef SQLITE_TEST

Changes to src/sqlite.h.in.

  7373   7373   ** the glob pattern P.  ^The definition of glob pattern matching used in
  7374   7374   ** [sqlite3_strglob(P,X)] is the same as for the "X GLOB P" operator in the
  7375   7375   ** SQL dialect used by SQLite.  ^The sqlite3_strglob(P,X) function is case
  7376   7376   ** sensitive.
  7377   7377   **
  7378   7378   ** Note that this routine returns zero on a match and non-zero if the strings
  7379   7379   ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].
         7380  +**
         7381  +** See also: sqlite3_strlike().
  7380   7382   */
  7381   7383   int sqlite3_strglob(const char *zGlob, const char *zStr);
  7382   7384   
         7385  +/*
         7386  +** CAPI3REF: String LIKE Matching
         7387  +*
         7388  +** ^The [sqlite3_strlike(P,X,E)] interface returns zero if string X matches
         7389  +** the LIKE pattern P with escape character E, and it returns non-zero if
         7390  +** string X does not match the like pattern.
         7391  +** ^The definition of LIKE pattern matching used in
         7392  +** [sqlite3_strlike(P,X,E)] is the same as for the "X LIKE P ESCAPE E"
         7393  +** operator in the SQL dialect used by SQLite.  ^For "X LIKE P" without
         7394  +** the ESCAPE clause, set the E parameter of [sqlite3_strlike(P,X,E)] to 0.
         7395  +** ^As with the LIKE operator, the [sqlite3_str(P,X,E)] function is case
         7396  +** insensitive - equivalent upper and lower case ASCII characters match
         7397  +** one another.
         7398  +**
         7399  +** ^The [sqlite3_strlike(P,X,E)] function matches Unicode characters, though
         7400  +** only ASCII characters are case folded.  (This is because when SQLite was
         7401  +** first written, the case folding rules for Unicode where still in flux.)
         7402  +**
         7403  +** Note that this routine returns zero on a match and non-zero if the strings
         7404  +** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].
         7405  +**
         7406  +** See also: sqlite3_strglob().
         7407  +*/
         7408  +int sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc);
         7409  +
  7383   7410   /*
  7384   7411   ** CAPI3REF: Error Logging Interface
  7385   7412   **
  7386   7413   ** ^The [sqlite3_log()] interface writes a message into the [error log]
  7387   7414   ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
  7388   7415   ** ^If logging is enabled, the zFormat string and subsequent arguments are
  7389   7416   ** used with [sqlite3_snprintf()] to generate the final output string.

Changes to src/sqlite3ext.h.

   271    271     sqlite3_value *(*value_dup)(const sqlite3_value*);
   272    272     void (*value_free)(sqlite3_value*);
   273    273     int (*result_zeroblob64)(sqlite3_context*,sqlite3_uint64);
   274    274     int (*bind_zeroblob64)(sqlite3_stmt*, int, sqlite3_uint64);
   275    275     /* Version 3.9.0 and later */
   276    276     unsigned int (*value_subtype)(sqlite3_value*);
   277    277     void (*result_subtype)(sqlite3_context*,unsigned int);
          278  +  /* Version 3.10.0 and later */
          279  +  int (*strlike)(const char*,const char*,unsigned int);
   278    280   };
   279    281   
   280    282   /*
   281    283   ** The following macros redefine the API routines so that they are
   282    284   ** redirected through the global sqlite3_api structure.
   283    285   **
   284    286   ** This header file is also used by the loadext.c source file
................................................................................
   510    512   #define sqlite3_value_dup              sqlite3_api->value_dup
   511    513   #define sqlite3_value_free             sqlite3_api->value_free
   512    514   #define sqlite3_result_zeroblob64      sqlite3_api->result_zeroblob64
   513    515   #define sqlite3_bind_zeroblob64        sqlite3_api->bind_zeroblob64
   514    516   /* Version 3.9.0 and later */
   515    517   #define sqlite3_value_subtype          sqlite3_api->value_subtype
   516    518   #define sqlite3_result_subtype         sqlite3_api->result_subtype
          519  +/* Version 3.10.0 and later */
          520  +#define sqlite3_strlike                sqlite3_api->strlike
   517    521   #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
   518    522   
   519    523   #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
   520    524     /* This case when the file really is being compiled as a loadable 
   521    525     ** extension */
   522    526   # define SQLITE_EXTENSION_INIT1     const sqlite3_api_routines *sqlite3_api=0;
   523    527   # define SQLITE_EXTENSION_INIT2(v)  sqlite3_api=v;