diff options
author | drh <drh@noemail.net> | 2008-09-09 12:31:33 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2008-09-09 12:31:33 +0000 |
commit | e3602be8fd576880855289c201022ddc06e0135e (patch) | |
tree | 6e207d46f097c9735c678ab5be4bb489b164ad98 /src/tclsqlite.c | |
parent | 4d60af9b0bae64a65f38ac66aef199102964bfc8 (diff) | |
download | sqlite-e3602be8fd576880855289c201022ddc06e0135e.tar.gz sqlite-e3602be8fd576880855289c201022ddc06e0135e.zip |
Calling sqlite3_create_function with nArg==(-1) does not override prior
calls on the same function name with nArg>=0. Ticket #3345. Add the
new -argcount option to the "function" method in the TCL interface. (CVS 5684)
FossilOrigin-Name: 5aa5b8044a14f59559c1839dc0799b0d2f990809
Diffstat (limited to 'src/tclsqlite.c')
-rw-r--r-- | src/tclsqlite.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 083b31c29..152a44464 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -12,7 +12,7 @@ ** A TCL Interface to SQLite. Append this file to sqlite3.c and ** compile the whole thing to build a TCL-enabled version of SQLite. ** -** $Id: tclsqlite.c,v 1.223 2008/09/03 01:08:01 drh Exp $ +** $Id: tclsqlite.c,v 1.224 2008/09/09 12:31:34 drh Exp $ */ #include "tcl.h" #include <errno.h> @@ -1872,7 +1872,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ } /* - ** $db function NAME SCRIPT + ** $db function NAME [-argcount N] SCRIPT ** ** Create a new SQL function called NAME. Whenever that function is ** called, invoke SCRIPT to evaluate the function. @@ -1881,12 +1881,26 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ SqlFunc *pFunc; Tcl_Obj *pScript; char *zName; - if( objc!=4 ){ - Tcl_WrongNumArgs(interp, 2, objv, "NAME SCRIPT"); + int nArg = -1; + if( objc==6 ){ + const char *z = Tcl_GetString(objv[3]); + int n = strlen(z); + if( n>2 && strncmp(z, "-argcount",n)==0 ){ + if( Tcl_GetIntFromObj(interp, objv[4], &nArg) ) return TCL_ERROR; + if( nArg<0 ){ + Tcl_AppendResult(interp, "number of arguments must be non-negative", + (char*)0); + return TCL_ERROR; + } + } + pScript = objv[5]; + }else if( objc!=4 ){ + Tcl_WrongNumArgs(interp, 2, objv, "NAME [-argcount N] SCRIPT"); return TCL_ERROR; + }else{ + pScript = objv[3]; } zName = Tcl_GetStringFromObj(objv[2], 0); - pScript = objv[3]; pFunc = findSqlFunc(pDb, zName); if( pFunc==0 ) return TCL_ERROR; if( pFunc->pScript ){ @@ -1895,7 +1909,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ pFunc->pScript = pScript; Tcl_IncrRefCount(pScript); pFunc->useEvalObjv = safeToUseEvalObjv(interp, pScript); - rc = sqlite3_create_function(pDb->db, zName, -1, SQLITE_UTF8, + rc = sqlite3_create_function(pDb->db, zName, nArg, SQLITE_UTF8, pFunc, tclSqlFunc, 0, 0); if( rc!=SQLITE_OK ){ rc = TCL_ERROR; |