diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/md5.c | 33 | ||||
-rw-r--r-- | src/tclsqlite.c | 8 | ||||
-rw-r--r-- | src/test1.c | 20 |
3 files changed, 59 insertions, 2 deletions
@@ -30,6 +30,7 @@ */ #include <tcl.h> #include <string.h> +#include "sqlite.h" /* * If compiled on a machine that doesn't have a 32-bit integer, @@ -350,3 +351,35 @@ int Md5_Init(Tcl_Interp *interp){ Tcl_CreateCommand(interp, "md5file", md5file_cmd, 0, 0); return TCL_OK; } + +/* +** During testing, the special md5sum() aggregate function is available. +** inside SQLite. The following routines implement that function. +*/ +static void md5step(sqlite_func *context, int argc, const char **argv){ + MD5Context *p; + int i; + if( argc<1 ) return; + p = sqlite_aggregate_context(context, sizeof(*p)); + if( p==0 ) return; + if( sqlite_aggregate_count(context)==1 ){ + MD5Init(p); + } + for(i=0; i<argc; i++){ + if( argv[i] ){ + MD5Update(p, (unsigned char*)argv[i], strlen(argv[i])); + } + } +} +static void md5finalize(sqlite_func *context){ + MD5Context *p; + unsigned char digest[16]; + char zBuf[33]; + p = sqlite_aggregate_context(context, sizeof(*p)); + MD5Final(digest,p); + DigestToBase16(digest, zBuf); + sqlite_set_result_string(context, zBuf, strlen(zBuf)); +} +void Md5_Register(sqlite *db){ + sqlite_create_aggregate(db, "md5sum", -1, md5step, md5finalize, 0); +} diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 541914161..edf947655 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -11,7 +11,7 @@ ************************************************************************* ** A TCL Interface to SQLite ** -** $Id: tclsqlite.c,v 1.29 2002/01/16 21:00:27 drh Exp $ +** $Id: tclsqlite.c,v 1.30 2002/03/11 02:06:13 drh Exp $ */ #ifndef NO_TCL /* Omit this whole file if TCL is unavailable */ @@ -531,6 +531,12 @@ static int DbMain(void *cd, Tcl_Interp *interp, int argc, char **argv){ return TCL_ERROR; } Tcl_CreateObjCommand(interp, argv[1], DbObjCmd, (char*)p, DbDeleteCmd); +#ifdef SQLITE_TEST + { + extern void Md5_Register(sqlite*); + Md5_Register(p->db); + } +#endif return TCL_OK; } diff --git a/src/test1.c b/src/test1.c index 0ca93fe06..217d1f9d9 100644 --- a/src/test1.c +++ b/src/test1.c @@ -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.6 2002/01/16 21:00:27 drh Exp $ +** $Id: test1.c,v 1.7 2002/03/11 02:06:13 drh Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -325,6 +325,23 @@ static int sqlite_malloc_stat( #endif /* +** Usage: sqlite_abort +** +** Shutdown the process immediately. This is not a clean shutdown. +** This command is used to test the recoverability of a database in +** the event of a program crash. +*/ +static int sqlite_abort( + void *NotUsed, + Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ + int argc, /* Number of arguments */ + char **argv /* Text of each argument */ +){ + assert( interp==0 ); /* This will always fail */ + return TCL_OK; +} + +/* ** Register commands with the TCL interpreter. */ int Sqlitetest1_Init(Tcl_Interp *interp){ @@ -344,5 +361,6 @@ int Sqlitetest1_Init(Tcl_Interp *interp){ Tcl_CreateCommand(interp, "sqlite_malloc_fail", sqlite_malloc_fail, 0, 0); Tcl_CreateCommand(interp, "sqlite_malloc_stat", sqlite_malloc_stat, 0, 0); #endif + Tcl_CreateCommand(interp, "sqlite_abort", sqlite_abort, 0, 0); return TCL_OK; } |