1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

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
This commit is contained in:
drh
2008-09-09 12:31:33 +00:00
parent 4d60af9b0b
commit e3602be8fd
6 changed files with 87 additions and 28 deletions

View File

@@ -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;