| OLD | NEW |
| 1 /* | 1 /* |
| 2 ** 2008 March 19 | 2 ** 2008 March 19 |
| 3 ** | 3 ** |
| 4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
| 5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
| 6 ** | 6 ** |
| 7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
| 8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
| 9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
| 10 ** | 10 ** |
| 11 ************************************************************************* | 11 ************************************************************************* |
| 12 ** Code for testing all sorts of SQLite interfaces. This code | 12 ** Code for testing all sorts of SQLite interfaces. This code |
| 13 ** implements new SQL functions used by the test scripts. | 13 ** implements new SQL functions used by the test scripts. |
| 14 */ | 14 */ |
| 15 #include "sqlite3.h" | 15 #include "sqlite3.h" |
| 16 #include "tcl.h" | 16 #if defined(INCLUDE_SQLITE_TCL_H) |
| 17 # include "sqlite_tcl.h" |
| 18 #else |
| 19 # include "tcl.h" |
| 20 #endif |
| 17 #include <stdlib.h> | 21 #include <stdlib.h> |
| 18 #include <string.h> | 22 #include <string.h> |
| 19 #include <assert.h> | 23 #include <assert.h> |
| 20 | 24 |
| 21 #include "sqliteInt.h" | 25 #include "sqliteInt.h" |
| 22 #include "vdbeInt.h" | 26 #include "vdbeInt.h" |
| 23 | 27 |
| 24 | |
| 25 /* | 28 /* |
| 26 ** Allocate nByte bytes of space using sqlite3_malloc(). If the | 29 ** Allocate nByte bytes of space using sqlite3_malloc(). If the |
| 27 ** allocation fails, call sqlite3_result_error_nomem() to notify | 30 ** allocation fails, call sqlite3_result_error_nomem() to notify |
| 28 ** the database handle that malloc() has failed. | 31 ** the database handle that malloc() has failed. |
| 29 */ | 32 */ |
| 30 static void *testContextMalloc(sqlite3_context *context, int nByte){ | 33 static void *testContextMalloc(sqlite3_context *context, int nByte){ |
| 31 char *z = sqlite3_malloc(nByte); | 34 char *z = sqlite3_malloc(nByte); |
| 32 if( !z && nByte>0 ){ | 35 if( !z && nByte>0 ){ |
| 33 sqlite3_result_error_nomem(context); | 36 sqlite3_result_error_nomem(context); |
| 34 } | 37 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 sqlite3_value **argv | 148 sqlite3_value **argv |
| 146 ){ | 149 ){ |
| 147 sqlite3_result_int(pCtx, test_destructor_count_var); | 150 sqlite3_result_int(pCtx, test_destructor_count_var); |
| 148 } | 151 } |
| 149 | 152 |
| 150 /* | 153 /* |
| 151 ** The following aggregate function, test_agg_errmsg16(), takes zero | 154 ** The following aggregate function, test_agg_errmsg16(), takes zero |
| 152 ** arguments. It returns the text value returned by the sqlite3_errmsg16() | 155 ** arguments. It returns the text value returned by the sqlite3_errmsg16() |
| 153 ** API function. | 156 ** API function. |
| 154 */ | 157 */ |
| 155 #ifndef SQLITE_OMIT_BUILTIN_TEST | 158 #ifndef SQLITE_UNTESTABLE |
| 156 void sqlite3BeginBenignMalloc(void); | 159 void sqlite3BeginBenignMalloc(void); |
| 157 void sqlite3EndBenignMalloc(void); | 160 void sqlite3EndBenignMalloc(void); |
| 158 #else | 161 #else |
| 159 #define sqlite3BeginBenignMalloc() | 162 #define sqlite3BeginBenignMalloc() |
| 160 #define sqlite3EndBenignMalloc() | 163 #define sqlite3EndBenignMalloc() |
| 161 #endif | 164 #endif |
| 162 static void test_agg_errmsg16_step(sqlite3_context *a, int b,sqlite3_value **c){ | 165 static void test_agg_errmsg16_step(sqlite3_context *a, int b,sqlite3_value **c){ |
| 163 } | 166 } |
| 164 static void test_agg_errmsg16_final(sqlite3_context *ctx){ | 167 static void test_agg_errmsg16_final(sqlite3_context *ctx){ |
| 165 #ifndef SQLITE_OMIT_UTF16 | 168 #ifndef SQLITE_OMIT_UTF16 |
| 166 const void *z; | 169 const void *z; |
| 167 sqlite3 * db = sqlite3_context_db_handle(ctx); | 170 sqlite3 * db = sqlite3_context_db_handle(ctx); |
| 168 sqlite3_aggregate_context(ctx, 2048); | 171 sqlite3_aggregate_context(ctx, 2048); |
| 169 sqlite3BeginBenignMalloc(); | |
| 170 z = sqlite3_errmsg16(db); | 172 z = sqlite3_errmsg16(db); |
| 171 sqlite3EndBenignMalloc(); | |
| 172 sqlite3_result_text16(ctx, z, -1, SQLITE_TRANSIENT); | 173 sqlite3_result_text16(ctx, z, -1, SQLITE_TRANSIENT); |
| 173 #endif | 174 #endif |
| 174 } | 175 } |
| 175 | 176 |
| 176 /* | 177 /* |
| 177 ** Routines for testing the sqlite3_get_auxdata() and sqlite3_set_auxdata() | 178 ** Routines for testing the sqlite3_get_auxdata() and sqlite3_set_auxdata() |
| 178 ** interface. | 179 ** interface. |
| 179 ** | 180 ** |
| 180 ** The test_auxdata() SQL function attempts to register each of its arguments | 181 ** The test_auxdata() SQL function attempts to register each of its arguments |
| 181 ** as auxiliary data. If there are no prior registrations of aux data for | 182 ** as auxiliary data. If there are no prior registrations of aux data for |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 */ | 636 */ |
| 636 static void test_setsubtype( | 637 static void test_setsubtype( |
| 637 sqlite3_context *context, | 638 sqlite3_context *context, |
| 638 int argc, | 639 int argc, |
| 639 sqlite3_value **argv | 640 sqlite3_value **argv |
| 640 ){ | 641 ){ |
| 641 sqlite3_result_value(context, argv[0]); | 642 sqlite3_result_value(context, argv[0]); |
| 642 sqlite3_result_subtype(context, (unsigned int)sqlite3_value_int(argv[1])); | 643 sqlite3_result_subtype(context, (unsigned int)sqlite3_value_int(argv[1])); |
| 643 } | 644 } |
| 644 | 645 |
| 645 static int registerTestFunctions(sqlite3 *db){ | 646 static int registerTestFunctions( |
| 647 sqlite3 *db, |
| 648 char **pzErrMsg, |
| 649 const sqlite3_api_routines *pThunk |
| 650 ){ |
| 646 static const struct { | 651 static const struct { |
| 647 char *zName; | 652 char *zName; |
| 648 signed char nArg; | 653 signed char nArg; |
| 649 unsigned int eTextRep; /* 1: UTF-16. 0: UTF-8 */ | 654 unsigned int eTextRep; /* 1: UTF-16. 0: UTF-8 */ |
| 650 void (*xFunc)(sqlite3_context*,int,sqlite3_value **); | 655 void (*xFunc)(sqlite3_context*,int,sqlite3_value **); |
| 651 } aFuncs[] = { | 656 } aFuncs[] = { |
| 652 { "randstr", 2, SQLITE_UTF8, randStr }, | 657 { "randstr", 2, SQLITE_UTF8, randStr }, |
| 653 { "test_destructor", 1, SQLITE_UTF8, test_destructor}, | 658 { "test_destructor", 1, SQLITE_UTF8, test_destructor}, |
| 654 #ifndef SQLITE_OMIT_UTF16 | 659 #ifndef SQLITE_OMIT_UTF16 |
| 655 { "test_destructor16", 1, SQLITE_UTF8, test_destructor16}, | 660 { "test_destructor16", 1, SQLITE_UTF8, test_destructor16}, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 684 return SQLITE_OK; | 689 return SQLITE_OK; |
| 685 } | 690 } |
| 686 | 691 |
| 687 /* | 692 /* |
| 688 ** TCLCMD: autoinstall_test_functions | 693 ** TCLCMD: autoinstall_test_functions |
| 689 ** | 694 ** |
| 690 ** Invoke this TCL command to use sqlite3_auto_extension() to cause | 695 ** Invoke this TCL command to use sqlite3_auto_extension() to cause |
| 691 ** the standard set of test functions to be loaded into each new | 696 ** the standard set of test functions to be loaded into each new |
| 692 ** database connection. | 697 ** database connection. |
| 693 */ | 698 */ |
| 694 static int autoinstall_test_funcs( | 699 static int SQLITE_TCLAPI autoinstall_test_funcs( |
| 695 void * clientData, | 700 void * clientData, |
| 696 Tcl_Interp *interp, | 701 Tcl_Interp *interp, |
| 697 int objc, | 702 int objc, |
| 698 Tcl_Obj *CONST objv[] | 703 Tcl_Obj *CONST objv[] |
| 699 ){ | 704 ){ |
| 700 extern int Md5_Register(sqlite3*); | 705 extern int Md5_Register(sqlite3 *, char **, const sqlite3_api_routines *); |
| 701 int rc = sqlite3_auto_extension((void*)registerTestFunctions); | 706 int rc = sqlite3_auto_extension((void(*)(void))registerTestFunctions); |
| 702 if( rc==SQLITE_OK ){ | 707 if( rc==SQLITE_OK ){ |
| 703 rc = sqlite3_auto_extension((void*)Md5_Register); | 708 rc = sqlite3_auto_extension((void(*)(void))Md5_Register); |
| 704 } | 709 } |
| 705 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); | 710 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); |
| 706 return TCL_OK; | 711 return TCL_OK; |
| 707 } | 712 } |
| 708 | 713 |
| 709 /* | 714 /* |
| 710 ** A bogus step function and finalizer function. | 715 ** A bogus step function and finalizer function. |
| 711 */ | 716 */ |
| 712 static void tStep(sqlite3_context *a, int b, sqlite3_value **c){} | 717 static void tStep(sqlite3_context *a, int b, sqlite3_value **c){} |
| 713 static void tFinal(sqlite3_context *a){} | 718 static void tFinal(sqlite3_context *a){} |
| 714 | 719 |
| 715 | 720 |
| 716 /* | 721 /* |
| 717 ** tclcmd: abuse_create_function | 722 ** tclcmd: abuse_create_function |
| 718 ** | 723 ** |
| 719 ** Make various calls to sqlite3_create_function that do not have valid | 724 ** Make various calls to sqlite3_create_function that do not have valid |
| 720 ** parameters. Verify that the error condition is detected and reported. | 725 ** parameters. Verify that the error condition is detected and reported. |
| 721 */ | 726 */ |
| 722 static int abuse_create_function( | 727 static int SQLITE_TCLAPI abuse_create_function( |
| 723 void * clientData, | 728 void * clientData, |
| 724 Tcl_Interp *interp, | 729 Tcl_Interp *interp, |
| 725 int objc, | 730 int objc, |
| 726 Tcl_Obj *CONST objv[] | 731 Tcl_Obj *CONST objv[] |
| 727 ){ | 732 ){ |
| 728 extern int getDbPointer(Tcl_Interp*, const char*, sqlite3**); | 733 extern int getDbPointer(Tcl_Interp*, const char*, sqlite3**); |
| 729 sqlite3 *db; | 734 sqlite3 *db; |
| 730 int rc; | 735 int rc; |
| 731 int mxArg; | 736 int mxArg; |
| 732 | 737 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 if( rc!=SQLITE_OK ) goto abuse_err; | 783 if( rc!=SQLITE_OK ) goto abuse_err; |
| 779 | 784 |
| 780 return TCL_OK; | 785 return TCL_OK; |
| 781 | 786 |
| 782 abuse_err: | 787 abuse_err: |
| 783 Tcl_AppendResult(interp, "sqlite3_create_function abused test failed", | 788 Tcl_AppendResult(interp, "sqlite3_create_function abused test failed", |
| 784 (char*)0); | 789 (char*)0); |
| 785 return TCL_ERROR; | 790 return TCL_ERROR; |
| 786 } | 791 } |
| 787 | 792 |
| 793 |
| 788 /* | 794 /* |
| 789 ** Register commands with the TCL interpreter. | 795 ** Register commands with the TCL interpreter. |
| 790 */ | 796 */ |
| 791 int Sqlitetest_func_Init(Tcl_Interp *interp){ | 797 int Sqlitetest_func_Init(Tcl_Interp *interp){ |
| 792 static struct { | 798 static struct { |
| 793 char *zName; | 799 char *zName; |
| 794 Tcl_ObjCmdProc *xProc; | 800 Tcl_ObjCmdProc *xProc; |
| 795 } aObjCmd[] = { | 801 } aObjCmd[] = { |
| 796 { "autoinstall_test_functions", autoinstall_test_funcs }, | 802 { "autoinstall_test_functions", autoinstall_test_funcs }, |
| 797 { "abuse_create_function", abuse_create_function }, | 803 { "abuse_create_function", abuse_create_function }, |
| 798 }; | 804 }; |
| 799 int i; | 805 int i; |
| 800 extern int Md5_Register(sqlite3*); | 806 extern int Md5_Register(sqlite3 *, char **, const sqlite3_api_routines *); |
| 801 | 807 |
| 802 for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){ | 808 for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){ |
| 803 Tcl_CreateObjCommand(interp, aObjCmd[i].zName, aObjCmd[i].xProc, 0, 0); | 809 Tcl_CreateObjCommand(interp, aObjCmd[i].zName, aObjCmd[i].xProc, 0, 0); |
| 804 } | 810 } |
| 805 sqlite3_initialize(); | 811 sqlite3_initialize(); |
| 806 sqlite3_auto_extension((void*)registerTestFunctions); | 812 sqlite3_auto_extension((void(*)(void))registerTestFunctions); |
| 807 sqlite3_auto_extension((void*)Md5_Register); | 813 sqlite3_auto_extension((void(*)(void))Md5_Register); |
| 808 return TCL_OK; | 814 return TCL_OK; |
| 809 } | 815 } |
| OLD | NEW |