1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-10-21 11:13:54 +03:00

Fix for ticket #1: Implement the GLOB and LIKE operators as functions that

can be overridden.  This way, a developer can change the LIKE operator to
be case sensitive, for example. (CVS 537)

FossilOrigin-Name: 51572bf71774d7631c7083be90b806e621bc9bee
This commit is contained in:
drh
2002-04-20 14:24:41 +00:00
parent 67505e78c6
commit 0ac6589202
9 changed files with 94 additions and 143 deletions

View File

@@ -16,7 +16,7 @@
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: func.c,v 1.15 2002/04/06 14:10:47 drh Exp $
** $Id: func.c,v 1.16 2002/04/20 14:24:42 drh Exp $
*/
#include <ctype.h>
#include <math.h>
@@ -200,11 +200,39 @@ static void randomFunc(sqlite_func *context, int argc, const char **argv){
** Implementation of the last_insert_rowid() SQL function. The return
** value is the same as the sqlite_last_insert_rowid() API function.
*/
static void last_insert_rowid(sqlite_func *context, int arg, char **argv){
static void last_insert_rowid(sqlite_func *context, int arg, const char **argv){
sqlite *db = sqlite_user_data(context);
sqlite_set_result_int(context, sqlite_last_insert_rowid(db));
}
/*
** Implementation of the like() SQL function. This function implements
** the build-in LIKE operator. The first argument to the function is the
** string and the second argument is the pattern. So, the SQL statements:
**
** A LIKE B
**
** is implemented as like(A,B).
*/
static void likeFunc(sqlite_func *context, int arg, const char **argv){
sqlite_set_result_int(context,
sqliteLikeCompare(argv[0] ? argv[0] : "",argv[1] ? argv[1] : ""));
}
/*
** Implementation of the glob() SQL function. This function implements
** the build-in GLOB operator. The first argument to the function is the
** string and the second argument is the pattern. So, the SQL statements:
**
** A GLOB B
**
** is implemented as glob(A,B).
*/
static void globFunc(sqlite_func *context, int arg, const char **argv){
sqlite_set_result_int(context,
sqliteGlobCompare(argv[0] ? argv[0] : "",argv[1] ? argv[1] : ""));
}
/*
** An instance of the following structure holds the context of a
** sum() or avg() aggregate computation.
@@ -394,6 +422,8 @@ void sqliteRegisterBuildinFunctions(sqlite *db){
{ "coalesce", 0, 0 },
{ "coalesce", 1, 0 },
{ "random", -1, randomFunc },
{ "like", 2, likeFunc },
{ "glob", 2, globFunc },
};
static struct {
char *zName;