Additional test cases added on the sqlite3_create_function() interface. (CVS 5349)

FossilOrigin-Name: 4e941f3d43556d8a503bb96e8a74451de36d243e
This commit is contained in:
drh
2008-07-07 14:50:14 +00:00
parent a2820970c5
commit 24b58dd717
9 changed files with 172 additions and 37 deletions
+4 -4
View File
@@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.466 2008/06/27 13:27:04 danielk1977 Exp $
** $Id: main.c,v 1.467 2008/07/07 14:50:14 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -677,7 +677,7 @@ int sqlite3CreateFunc(
(xFunc && (xFinal || xStep)) ||
(!xFunc && (xFinal && !xStep)) ||
(!xFunc && (!xFinal && xStep)) ||
(nArg<-1 || nArg>127) ||
(nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) ||
(255<(nName = strlen(zFunctionName))) ){
sqlite3Error(db, SQLITE_ERROR, "bad parameters");
return SQLITE_ERROR;
@@ -1191,8 +1191,8 @@ static const int aHardLimit[] = {
#if SQLITE_MAX_VDBE_OP<40
# error SQLITE_MAX_VDBE_OP must be at least 40
#endif
#if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>255
# error SQLITE_MAX_FUNCTION_ARG must be between 0 and 255
#if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>127
# error SQLITE_MAX_FUNCTION_ARG must be between 0 and 127
#endif
#if SQLITE_MAX_ATTACH<0 || SQLITE_MAX_ATTACH>30
# error SQLITE_MAX_ATTACH must be between 0 and 30
+2 -2
View File
@@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test1.c,v 1.309 2008/07/07 13:31:59 drh Exp $
** $Id: test1.c,v 1.310 2008/07/07 14:50:14 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -102,7 +102,7 @@ static int get_sqlite_pointer(
/*
** Decode a pointer to an sqlite3 object.
*/
static int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){
int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){
struct SqliteDb *p;
Tcl_CmdInfo cmdInfo;
if( Tcl_GetCommandInfo(interp, zA, &cmdInfo) ){
+2 -5
View File
@@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test8.c,v 1.66 2008/06/20 14:59:51 danielk1977 Exp $
** $Id: test8.c,v 1.67 2008/07/07 14:50:14 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -1189,10 +1189,7 @@ static sqlite3_module echoModule = {
/*
** Decode a pointer to an sqlite3 object.
*/
static int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){
*ppDb = (sqlite3*)sqlite3TextToPtr(zA);
return TCL_OK;
}
extern int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb);
static void moduleDestroy(void *p){
sqlite3_free(p);
+97 -1
View File
@@ -12,7 +12,7 @@
** Code for testing all sorts of SQLite interfaces. This code
** implements new SQL functions used by the test scripts.
**
** $Id: test_func.c,v 1.5 2008/04/15 12:14:22 drh Exp $
** $Id: test_func.c,v 1.6 2008/07/07 14:50:14 drh Exp $
*/
#include "sqlite3.h"
#include "tcl.h"
@@ -275,6 +275,101 @@ static int autoinstall_test_funcs(
return TCL_OK;
}
/*
** A bogus step function and finalizer function.
*/
static void tStep(sqlite3_context *a, int b, sqlite3_value **c){}
static void tFinal(sqlite3_context *a){}
/*
** tclcmd: abuse_create_function
**
** Make various calls to sqlite3_create_function that do not have valid
** parameters. Verify that the error condition is detected and reported.
*/
static int abuse_create_function(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
extern int getDbPointer(Tcl_Interp*, const char*, sqlite3**);
sqlite3 *db;
int rc;
int mxArg;
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
rc = sqlite3_create_function(db, "tx", 1, SQLITE_UTF8, 0, tStep,tStep,tFinal);
if( rc!=SQLITE_ERROR ) goto abuse_err;
if( sqlite3_errcode(db)!=SQLITE_ERROR ) goto abuse_err;
if( strcmp(sqlite3_errmsg(db), "bad parameters")!=0 ) goto abuse_err;
rc = sqlite3_create_function(db, "tx", 1, SQLITE_UTF8, 0, tStep, tStep, 0);
if( rc!=SQLITE_ERROR ) goto abuse_err;
if( sqlite3_errcode(db)!=SQLITE_ERROR ) goto abuse_err;
if( strcmp(sqlite3_errmsg(db), "bad parameters")!=0 ) goto abuse_err;
rc = sqlite3_create_function(db, "tx", 1, SQLITE_UTF8, 0, tStep, 0, tFinal);
if( rc!=SQLITE_ERROR ) goto abuse_err;
if( sqlite3_errcode(db)!=SQLITE_ERROR ) goto abuse_err;
if( strcmp(sqlite3_errmsg(db), "bad parameters")!=0 ) goto abuse_err;
rc = sqlite3_create_function(db, "tx", 1, SQLITE_UTF8, 0, 0, 0, tFinal);
if( rc!=SQLITE_ERROR ) goto abuse_err;
if( sqlite3_errcode(db)!=SQLITE_ERROR ) goto abuse_err;
if( strcmp(sqlite3_errmsg(db), "bad parameters")!=0 ) goto abuse_err;
rc = sqlite3_create_function(db, "tx", 1, SQLITE_UTF8, 0, 0, tStep, 0);
if( rc!=SQLITE_ERROR ) goto abuse_err;
if( sqlite3_errcode(db)!=SQLITE_ERROR ) goto abuse_err;
if( strcmp(sqlite3_errmsg(db), "bad parameters")!=0 ) goto abuse_err;
rc = sqlite3_create_function(db, "tx", -2, SQLITE_UTF8, 0, tStep, 0, 0);
if( rc!=SQLITE_ERROR ) goto abuse_err;
if( sqlite3_errcode(db)!=SQLITE_ERROR ) goto abuse_err;
if( strcmp(sqlite3_errmsg(db), "bad parameters")!=0 ) goto abuse_err;
rc = sqlite3_create_function(db, "tx", 128, SQLITE_UTF8, 0, tStep, 0, 0);
if( rc!=SQLITE_ERROR ) goto abuse_err;
if( sqlite3_errcode(db)!=SQLITE_ERROR ) goto abuse_err;
if( strcmp(sqlite3_errmsg(db), "bad parameters")!=0 ) goto abuse_err;
rc = sqlite3_create_function(db, "funcxx"
"_123456789_123456789_123456789_123456789_123456789"
"_123456789_123456789_123456789_123456789_123456789"
"_123456789_123456789_123456789_123456789_123456789"
"_123456789_123456789_123456789_123456789_123456789"
"_123456789_123456789_123456789_123456789_123456789",
1, SQLITE_UTF8, 0, tStep, 0, 0);
if( rc!=SQLITE_ERROR ) goto abuse_err;
if( sqlite3_errcode(db)!=SQLITE_ERROR ) goto abuse_err;
if( strcmp(sqlite3_errmsg(db), "bad parameters")!=0 ) goto abuse_err;
/* This last function registration should actually work. Generate
** a no-op function (that always returns NULL) and which has the
** maximum-length function name and the maximum number of parameters.
*/
sqlite3_limit(db, SQLITE_LIMIT_FUNCTION_ARG, 10000);
mxArg = sqlite3_limit(db, SQLITE_LIMIT_FUNCTION_ARG, -1);
rc = sqlite3_create_function(db, "nullx"
"_123456789_123456789_123456789_123456789_123456789"
"_123456789_123456789_123456789_123456789_123456789"
"_123456789_123456789_123456789_123456789_123456789"
"_123456789_123456789_123456789_123456789_123456789"
"_123456789_123456789_123456789_123456789_123456789",
mxArg, SQLITE_UTF8, 0, tStep, 0, 0);
if( rc!=SQLITE_OK ) goto abuse_err;
return TCL_OK;
abuse_err:
Tcl_AppendResult(interp, "sqlite3_create_function abused test failed",
(char*)0);
return TCL_ERROR;
}
/*
@@ -286,6 +381,7 @@ int Sqlitetest_func_Init(Tcl_Interp *interp){
Tcl_ObjCmdProc *xProc;
} aObjCmd[] = {
{ "autoinstall_test_functions", autoinstall_test_funcs },
{ "abuse_create_function", abuse_create_function },
};
int i;
for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
+2 -5
View File
@@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test_schema.c,v 1.14 2008/05/01 17:16:53 drh Exp $
** $Id: test_schema.c,v 1.15 2008/07/07 14:50:14 drh Exp $
*/
/* The code in this file defines a sqlite3 virtual-table module that
@@ -299,10 +299,7 @@ static sqlite3_module schemaModule = {
/*
** Decode a pointer to an sqlite3 object.
*/
static int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){
*ppDb = (sqlite3*)sqlite3TextToPtr(zA);
return TCL_OK;
}
extern int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb);
/*
** Register the schema virtual table module.
+2 -6
View File
@@ -16,7 +16,7 @@
** The emphasis of this file is a virtual table that provides
** access to TCL variables.
**
** $Id: test_tclvar.c,v 1.15 2008/05/29 05:23:42 drh Exp $
** $Id: test_tclvar.c,v 1.16 2008/07/07 14:50:14 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -277,11 +277,7 @@ static sqlite3_module tclvarModule = {
/*
** Decode a pointer to an sqlite3 object.
*/
static int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){
*ppDb = (sqlite3*)sqlite3TextToPtr(zA);
return TCL_OK;
}
extern int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb);
/*
** Register the echo virtual table module.