Make "test_regexp.c" into a loadable extension and move it over to
ext/misc/regexp.c. Add the "load_static_extension" command for testing purposes. FossilOrigin-Name: 860fc393bff27045e0593c3c51bf5577accd0b79
This commit is contained in:
parent
da8caa0b2d
commit
248f2be91a
@ -49,7 +49,17 @@
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "sqlite3.h"
|
||||
#include "sqlite3ext.h"
|
||||
SQLITE_EXTENSION_INIT1
|
||||
|
||||
/*
|
||||
** The following #defines change the names of some functions implemented in
|
||||
** this file to prevent name collisions with C-library functions of the
|
||||
** same name.
|
||||
*/
|
||||
#define re_match sqlite3re_match
|
||||
#define re_compile sqlite3re_compile
|
||||
#define re_free sqlite3re_free
|
||||
|
||||
/* The end-of-input character */
|
||||
#define RE_EOF 0 /* End of input */
|
||||
@ -175,7 +185,7 @@ static int re_space_char(int c){
|
||||
/* Run a compiled regular expression on the zero-terminated input
|
||||
** string zIn[]. Return true on a match and false if there is no match.
|
||||
*/
|
||||
int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
|
||||
static int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
|
||||
ReStateSet aStateSet[2], *pThis, *pNext;
|
||||
ReStateNumber aSpace[100];
|
||||
ReStateNumber *pToFree;
|
||||
@ -718,53 +728,20 @@ static void re_sql_func(
|
||||
}
|
||||
|
||||
/*
|
||||
** Invoke this routine in order to install the REGEXP function in an
|
||||
** Invoke this routine to register the regexp() function with the
|
||||
** SQLite database connection.
|
||||
**
|
||||
** Use:
|
||||
**
|
||||
** sqlite3_auto_extension(sqlite3_add_regexp_func);
|
||||
**
|
||||
** to cause this extension to be automatically loaded into each new
|
||||
** database connection.
|
||||
*/
|
||||
int sqlite3_add_regexp_func(sqlite3 *db){
|
||||
return sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8, 0,
|
||||
re_sql_func, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
/***************************** Test Code ***********************************/
|
||||
#ifdef SQLITE_TEST
|
||||
#include <tcl.h>
|
||||
extern int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb);
|
||||
|
||||
/* Implementation of the TCL command:
|
||||
**
|
||||
** sqlite3_add_regexp_func $DB
|
||||
*/
|
||||
static int tclSqlite3AddRegexpFunc(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
#ifdef _WIN32
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
int sqlite3_regexp_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
sqlite3 *db;
|
||||
if( objc!=2 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "DB");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
||||
sqlite3_add_regexp_func(db);
|
||||
return TCL_OK;
|
||||
int rc = SQLITE_OK;
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
rc = sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8, 0,
|
||||
re_sql_func, 0, 0);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Register the sqlite3_add_regexp_func TCL command with the TCL interpreter.
|
||||
*/
|
||||
int Sqlitetestregexp_Init(Tcl_Interp *interp){
|
||||
Tcl_CreateObjCommand(interp, "sqlite3_add_regexp_func",
|
||||
tclSqlite3AddRegexpFunc, 0, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
/**************************** End Of Test Code *******************************/
|
2
main.mk
2
main.mk
@ -256,7 +256,7 @@ TESTSRC = \
|
||||
$(TOP)/src/test_osinst.c \
|
||||
$(TOP)/src/test_pcache.c \
|
||||
$(TOP)/src/test_quota.c \
|
||||
$(TOP)/src/test_regexp.c \
|
||||
$(TOP)/ext/misc/regexp.c \
|
||||
$(TOP)/src/test_rtree.c \
|
||||
$(TOP)/src/test_schema.c \
|
||||
$(TOP)/src/test_server.c \
|
||||
|
23
manifest
23
manifest
@ -1,5 +1,5 @@
|
||||
C Fix\sharmless\scompiler\swarnings.
|
||||
D 2013-04-22T23:38:50.007
|
||||
C Make\s"test_regexp.c"\sinto\sa\sloadable\sextension\sand\smove\sit\sover\sto\next/misc/regexp.c.\s\sAdd\sthe\s"load_static_extension"\scommand\sfor\stesting\npurposes.
|
||||
D 2013-04-23T20:10:13.518
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in 87591ea5bf7d6ed521ad42d5bc69c124debe11a5
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
@ -83,6 +83,7 @@ F ext/fts3/unicode/mkunicode.tcl 7a9bc018e2962abb79563c5a39fe581fcbf2f675
|
||||
F ext/icu/README.txt d9fbbad0c2f647c3fdf715fc9fd64af53aedfc43
|
||||
F ext/icu/icu.c eb9ae1d79046bd7871aa97ee6da51eb770134b5a
|
||||
F ext/icu/sqliteicu.h 728867a802baa5a96de7495e9689a8e01715ef37
|
||||
F ext/misc/regexp.c c0fdb8af86981ff9890d776cfb97fe66297cc3b2 w src/test_regexp.c
|
||||
F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
|
||||
F ext/rtree/rtree.c 757abea591d4ff67c0ff4e8f9776aeda86b18c14
|
||||
F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e
|
||||
@ -104,7 +105,7 @@ F ext/rtree/tkt3363.test 142ab96eded44a3615ec79fba98c7bde7d0f96de
|
||||
F ext/rtree/viewrtree.tcl eea6224b3553599ae665b239bd827e182b466024
|
||||
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
|
||||
F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8
|
||||
F main.mk e97fbfe4c69060560574e1b59c43f4f88a38a0ec
|
||||
F main.mk 8f410dfbb97943889298a2da779be0f8f3dcb750
|
||||
F mkdll.sh 7d09b23c05d56532e9d44a50868eb4b12ff4f74a
|
||||
F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f
|
||||
F mkextw.sh 4123480947681d9b434a5e7b1ee08135abe409ac
|
||||
@ -190,8 +191,8 @@ F src/sqliteInt.h 2a83cfec9963372b636b0cabd4b200c1f1074a99
|
||||
F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
|
||||
F src/status.c bedc37ec1a6bb9399944024d63f4c769971955a9
|
||||
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
|
||||
F src/tclsqlite.c 9a716c737590d2f129d71c8fc7065e5aba0e7222
|
||||
F src/test1.c 6784fdacb35c33ba564ef749b62c4718fe515484
|
||||
F src/tclsqlite.c fd60f5950535fd880ce32f357fa9da62db65c490
|
||||
F src/test1.c 317741fa810b8acbdf849891202175ea762d68e9
|
||||
F src/test2.c 29e7154112f7448d64204e8d31179cf497ecf425
|
||||
F src/test3.c 96aed72a8e1d542fed127e3e8350ae357712fa82
|
||||
F src/test4.c cea2c55110241e4674e66d476d29c914627999f5
|
||||
@ -225,7 +226,6 @@ F src/test_osinst.c 90a845c8183013d80eccb1f29e8805608516edba
|
||||
F src/test_pcache.c a5cd24730cb43c5b18629043314548c9169abb00
|
||||
F src/test_quota.c 1ec82e02fd3643899e9a5de9684515e84641c91f
|
||||
F src/test_quota.h 8761e463b25e75ebc078bd67d70e39b9c817a0cb
|
||||
F src/test_regexp.c 06ae8138d41a793330f62351283dd6f6f21104f4
|
||||
F src/test_rtree.c aba603c949766c4193f1068b91c787f57274e0d9
|
||||
F src/test_schema.c 8c06ef9ddb240c7a0fcd31bc221a6a2aade58bf0
|
||||
F src/test_server.c 2f99eb2837dfa06a4aacf24af24c6affdf66a84f
|
||||
@ -684,7 +684,7 @@ F test/quote.test 215897dbe8de1a6f701265836d6601cc6ed103e6
|
||||
F test/randexpr1.tcl 40dec52119ed3a2b8b2a773bce24b63a3a746459
|
||||
F test/randexpr1.test eda062a97e60f9c38ae8d806b03b0ddf23d796df
|
||||
F test/rdonly.test c267d050a1d9a6a321de502b737daf28821a518d
|
||||
F test/regexp1.test 5cbb6e7122ca51260d71079cf9245b63b8f64e1a
|
||||
F test/regexp1.test 497ea812f264d12b6198d6e50a76be4a1973a9d8
|
||||
F test/reindex.test 44edd3966b474468b823d481eafef0c305022254
|
||||
F test/releasetest.mk 2eced2f9ae701fd0a29e714a241760503ccba25a
|
||||
F test/releasetest.tcl 06d289d8255794073a58d2850742f627924545ce
|
||||
@ -1054,7 +1054,10 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
|
||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
|
||||
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
|
||||
P 49cfa14fceeef2d55b449eb927c283ce6f650c07
|
||||
R 83c630a254d9cc209b10e1a83d85002b
|
||||
P 1a1cf5aa86734c832d845e07780262a178188d56
|
||||
R d55f2fee19b165fc6c487ed43598c861
|
||||
T *branch * std-ext
|
||||
T *sym-std-ext *
|
||||
T -sym-trunk *
|
||||
U drh
|
||||
Z a7a8588b07b6fce1e57eced049fe41f1
|
||||
Z 87544ad6dda5ce727b201c9348b14476
|
||||
|
@ -1 +1 @@
|
||||
1a1cf5aa86734c832d845e07780262a178188d56
|
||||
860fc393bff27045e0593c3c51bf5577accd0b79
|
@ -3685,7 +3685,6 @@ static void init_all(Tcl_Interp *interp){
|
||||
extern int SqlitetestSyscall_Init(Tcl_Interp*);
|
||||
extern int Sqlitetestfuzzer_Init(Tcl_Interp*);
|
||||
extern int Sqlitetestwholenumber_Init(Tcl_Interp*);
|
||||
extern int Sqlitetestregexp_Init(Tcl_Interp*);
|
||||
|
||||
#if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4)
|
||||
extern int Sqlitetestfts3_Init(Tcl_Interp *interp);
|
||||
@ -3730,7 +3729,6 @@ static void init_all(Tcl_Interp *interp){
|
||||
SqlitetestSyscall_Init(interp);
|
||||
Sqlitetestfuzzer_Init(interp);
|
||||
Sqlitetestwholenumber_Init(interp);
|
||||
Sqlitetestregexp_Init(interp);
|
||||
|
||||
#if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4)
|
||||
Sqlitetestfts3_Init(interp);
|
||||
|
48
src/test1.c
48
src/test1.c
@ -6045,6 +6045,53 @@ static int optimization_control(
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
typedef struct sqlite3_api_routines sqlite3_api_routines;
|
||||
/*
|
||||
** load_static_extension DB NAME
|
||||
**
|
||||
** Load an extension that is statically linked.
|
||||
*/
|
||||
static int tclLoadStaticExtensionCmd(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
extern int sqlite3_regexp_init(sqlite3*,char**,const sqlite3_api_routines*);
|
||||
static const struct {
|
||||
const char *zExtName;
|
||||
int (*pInit)(sqlite3*,char**,const sqlite3_api_routines*);
|
||||
} aExtension[] = {
|
||||
{ "regexp", sqlite3_regexp_init },
|
||||
};
|
||||
sqlite3 *db;
|
||||
const char *zName;
|
||||
int i, rc;
|
||||
char *zErrMsg = 0;
|
||||
if( objc!=3 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "DB NAME");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
||||
zName = Tcl_GetString(objv[2]);
|
||||
for(i=0; i<ArraySize(aExtension); i++){
|
||||
if( strcmp(zName, aExtension[i].zExtName)==0 ) break;
|
||||
}
|
||||
if( i>=ArraySize(aExtension) ){
|
||||
Tcl_AppendResult(interp, "no such extension: ", zName, (char*)0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
rc = aExtension[i].pInit(db, &zErrMsg, 0);
|
||||
if( rc!=SQLITE_OK || zErrMsg ){
|
||||
Tcl_AppendResult(interp, "initialization of ", zName, " failed: ", zErrMsg,
|
||||
(char*)0);
|
||||
sqlite3_free(zErrMsg);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Register commands with the TCL interpreter.
|
||||
*/
|
||||
@ -6266,6 +6313,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
|
||||
#if SQLITE_OS_UNIX
|
||||
{ "getrusage", test_getrusage },
|
||||
#endif
|
||||
{ "load_static_extension", tclLoadStaticExtensionCmd },
|
||||
};
|
||||
static int bitmask_size = sizeof(Bitmask)*8;
|
||||
int i;
|
||||
|
@ -16,7 +16,7 @@ set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
do_test regexp1-1.1 {
|
||||
sqlite3_add_regexp_func db
|
||||
load_static_extension db regexp
|
||||
db eval {
|
||||
CREATE TABLE t1(x INTEGER PRIMARY KEY, y TEXT);
|
||||
INSERT INTO t1 VALUES(1, 'For since by man came death,');
|
||||
|
Loading…
x
Reference in New Issue
Block a user