OLD | NEW |
1 /* | 1 /* |
2 ** 2007 August 15 | 2 ** 2007 August 15 |
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 ** |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 227 |
228 if( rc==SQLITE_OK ){ | 228 if( rc==SQLITE_OK ){ |
229 memfault.isInstalled = 1; | 229 memfault.isInstalled = 1; |
230 } | 230 } |
231 return rc; | 231 return rc; |
232 } | 232 } |
233 | 233 |
234 #ifdef SQLITE_TEST | 234 #ifdef SQLITE_TEST |
235 | 235 |
236 /* | 236 /* |
237 ** This function is implemented in test1.c. Returns a pointer to a static | 237 ** This function is implemented in main.c. Returns a pointer to a static |
238 ** buffer containing the symbolic SQLite error code that corresponds to | 238 ** buffer containing the symbolic SQLite error code that corresponds to |
239 ** the least-significant 8-bits of the integer passed as an argument. | 239 ** the least-significant 8-bits of the integer passed as an argument. |
240 ** For example: | 240 ** For example: |
241 ** | 241 ** |
242 ** sqlite3TestErrorName(1) -> "SQLITE_ERROR" | 242 ** sqlite3ErrName(1) -> "SQLITE_ERROR" |
243 */ | 243 */ |
244 const char *sqlite3TestErrorName(int); | 244 extern const char *sqlite3ErrName(int); |
245 | 245 |
246 /* | 246 /* |
247 ** Transform pointers to text and back again | 247 ** Transform pointers to text and back again |
248 */ | 248 */ |
249 static void pointerToText(void *p, char *z){ | 249 static void pointerToText(void *p, char *z){ |
250 static const char zHex[] = "0123456789abcdef"; | 250 static const char zHex[] = "0123456789abcdef"; |
251 int i, k; | 251 int i, k; |
252 unsigned int u; | 252 unsigned int u; |
253 sqlite3_uint64 n; | 253 sqlite3_uint64 n; |
254 if( p==0 ){ | 254 if( p==0 ){ |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 int nPending; | 689 int nPending; |
690 if( objc!=1 ){ | 690 if( objc!=1 ){ |
691 Tcl_WrongNumArgs(interp, 1, objv, ""); | 691 Tcl_WrongNumArgs(interp, 1, objv, ""); |
692 return TCL_ERROR; | 692 return TCL_ERROR; |
693 } | 693 } |
694 nPending = faultsimPending(); | 694 nPending = faultsimPending(); |
695 Tcl_SetObjResult(interp, Tcl_NewIntObj(nPending)); | 695 Tcl_SetObjResult(interp, Tcl_NewIntObj(nPending)); |
696 return TCL_OK; | 696 return TCL_OK; |
697 } | 697 } |
698 | 698 |
| 699 /* |
| 700 ** The following global variable keeps track of the number of tests |
| 701 ** that have run. This variable is only useful when running in the |
| 702 ** debugger. |
| 703 */ |
| 704 static int sqlite3_memdebug_title_count = 0; |
699 | 705 |
700 /* | 706 /* |
701 ** Usage: sqlite3_memdebug_settitle TITLE | 707 ** Usage: sqlite3_memdebug_settitle TITLE |
702 ** | 708 ** |
703 ** Set a title string stored with each allocation. The TITLE is | 709 ** Set a title string stored with each allocation. The TITLE is |
704 ** typically the name of the test that was running when the | 710 ** typically the name of the test that was running when the |
705 ** allocation occurred. The TITLE is stored with the allocation | 711 ** allocation occurred. The TITLE is stored with the allocation |
706 ** and can be used to figure out which tests are leaking memory. | 712 ** and can be used to figure out which tests are leaking memory. |
707 ** | 713 ** |
708 ** Each title overwrite the previous. | 714 ** Each title overwrite the previous. |
709 */ | 715 */ |
710 static int test_memdebug_settitle( | 716 static int test_memdebug_settitle( |
711 void * clientData, | 717 void * clientData, |
712 Tcl_Interp *interp, | 718 Tcl_Interp *interp, |
713 int objc, | 719 int objc, |
714 Tcl_Obj *CONST objv[] | 720 Tcl_Obj *CONST objv[] |
715 ){ | 721 ){ |
716 const char *zTitle; | 722 sqlite3_memdebug_title_count++; |
717 if( objc!=2 ){ | 723 if( objc!=2 ){ |
718 Tcl_WrongNumArgs(interp, 1, objv, "TITLE"); | 724 Tcl_WrongNumArgs(interp, 1, objv, "TITLE"); |
719 return TCL_ERROR; | 725 return TCL_ERROR; |
720 } | 726 } |
721 zTitle = Tcl_GetString(objv[1]); | |
722 #ifdef SQLITE_MEMDEBUG | 727 #ifdef SQLITE_MEMDEBUG |
723 { | 728 { |
| 729 const char *zTitle; |
724 extern int sqlite3MemdebugSettitle(const char*); | 730 extern int sqlite3MemdebugSettitle(const char*); |
| 731 zTitle = Tcl_GetString(objv[1]); |
725 sqlite3MemdebugSettitle(zTitle); | 732 sqlite3MemdebugSettitle(zTitle); |
726 } | 733 } |
727 #endif | 734 #endif |
728 return TCL_OK; | 735 return TCL_OK; |
729 } | 736 } |
730 | 737 |
731 #define MALLOC_LOG_FRAMES 10 | 738 #define MALLOC_LOG_FRAMES 10 |
732 #define MALLOC_LOG_KEYINTS ( \ | 739 #define MALLOC_LOG_KEYINTS ( \ |
733 10 * ((sizeof(int)>=sizeof(void*)) ? 1 : sizeof(void*)/sizeof(int)) \ | 740 10 * ((sizeof(int)>=sizeof(void*)) ? 1 : sizeof(void*)/sizeof(int)) \ |
734 ) | 741 ) |
735 static Tcl_HashTable aMallocLog; | 742 static Tcl_HashTable aMallocLog; |
736 static int mallocLogEnabled = 0; | 743 static int mallocLogEnabled = 0; |
737 | 744 |
738 typedef struct MallocLog MallocLog; | 745 typedef struct MallocLog MallocLog; |
739 struct MallocLog { | 746 struct MallocLog { |
740 int nCall; | 747 int nCall; |
741 int nByte; | 748 int nByte; |
742 }; | 749 }; |
743 | 750 |
744 #ifdef SQLITE_MEMDEBUG | 751 #ifdef SQLITE_MEMDEBUG |
745 static void test_memdebug_callback(int nByte, int nFrame, void **aFrame){ | 752 static void test_memdebug_callback(int nByte, int nFrame, void **aFrame){ |
746 if( mallocLogEnabled ){ | 753 if( mallocLogEnabled ){ |
747 MallocLog *pLog; | 754 MallocLog *pLog; |
748 Tcl_HashEntry *pEntry; | 755 Tcl_HashEntry *pEntry; |
749 int isNew; | 756 int isNew; |
750 | 757 |
751 int aKey[MALLOC_LOG_KEYINTS]; | 758 int aKey[MALLOC_LOG_KEYINTS]; |
752 int nKey = sizeof(int)*MALLOC_LOG_KEYINTS; | 759 unsigned int nKey = sizeof(int)*MALLOC_LOG_KEYINTS; |
753 | 760 |
754 memset(aKey, 0, nKey); | 761 memset(aKey, 0, nKey); |
755 if( (sizeof(void*)*nFrame)<nKey ){ | 762 if( (sizeof(void*)*nFrame)<nKey ){ |
756 nKey = nFrame*sizeof(void*); | 763 nKey = nFrame*sizeof(void*); |
757 } | 764 } |
758 memcpy(aKey, aFrame, nKey); | 765 memcpy(aKey, aFrame, nKey); |
759 | 766 |
760 pEntry = Tcl_CreateHashEntry(&aMallocLog, (const char *)aKey, &isNew); | 767 pEntry = Tcl_CreateHashEntry(&aMallocLog, (const char *)aKey, &isNew); |
761 if( isNew ){ | 768 if( isNew ){ |
762 pLog = (MallocLog *)Tcl_Alloc(sizeof(MallocLog)); | 769 pLog = (MallocLog *)Tcl_Alloc(sizeof(MallocLog)); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 } | 880 } |
874 | 881 |
875 return TCL_OK; | 882 return TCL_OK; |
876 } | 883 } |
877 | 884 |
878 /* | 885 /* |
879 ** Usage: sqlite3_config_scratch SIZE N | 886 ** Usage: sqlite3_config_scratch SIZE N |
880 ** | 887 ** |
881 ** Set the scratch memory buffer using SQLITE_CONFIG_SCRATCH. | 888 ** Set the scratch memory buffer using SQLITE_CONFIG_SCRATCH. |
882 ** The buffer is static and is of limited size. N might be | 889 ** The buffer is static and is of limited size. N might be |
883 ** adjusted downward as needed to accomodate the requested size. | 890 ** adjusted downward as needed to accommodate the requested size. |
884 ** The revised value of N is returned. | 891 ** The revised value of N is returned. |
885 ** | 892 ** |
886 ** A negative SIZE causes the buffer pointer to be NULL. | 893 ** A negative SIZE causes the buffer pointer to be NULL. |
887 */ | 894 */ |
888 static int test_config_scratch( | 895 static int test_config_scratch( |
889 void * clientData, | 896 void * clientData, |
890 Tcl_Interp *interp, | 897 Tcl_Interp *interp, |
891 int objc, | 898 int objc, |
892 Tcl_Obj *CONST objv[] | 899 Tcl_Obj *CONST objv[] |
893 ){ | 900 ){ |
(...skipping 19 matching lines...) Expand all Loading... |
913 Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(N)); | 920 Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(N)); |
914 Tcl_SetObjResult(interp, pResult); | 921 Tcl_SetObjResult(interp, pResult); |
915 return TCL_OK; | 922 return TCL_OK; |
916 } | 923 } |
917 | 924 |
918 /* | 925 /* |
919 ** Usage: sqlite3_config_pagecache SIZE N | 926 ** Usage: sqlite3_config_pagecache SIZE N |
920 ** | 927 ** |
921 ** Set the page-cache memory buffer using SQLITE_CONFIG_PAGECACHE. | 928 ** Set the page-cache memory buffer using SQLITE_CONFIG_PAGECACHE. |
922 ** The buffer is static and is of limited size. N might be | 929 ** The buffer is static and is of limited size. N might be |
923 ** adjusted downward as needed to accomodate the requested size. | 930 ** adjusted downward as needed to accommodate the requested size. |
924 ** The revised value of N is returned. | 931 ** The revised value of N is returned. |
925 ** | 932 ** |
926 ** A negative SIZE causes the buffer pointer to be NULL. | 933 ** A negative SIZE causes the buffer pointer to be NULL. |
927 */ | 934 */ |
928 static int test_config_pagecache( | 935 static int test_config_pagecache( |
929 void * clientData, | 936 void * clientData, |
930 Tcl_Interp *interp, | 937 Tcl_Interp *interp, |
931 int objc, | 938 int objc, |
932 Tcl_Obj *CONST objv[] | 939 Tcl_Obj *CONST objv[] |
933 ){ | 940 ){ |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 /* | 1033 /* |
1027 ** Usage: sqlite3_config_lookaside SIZE COUNT | 1034 ** Usage: sqlite3_config_lookaside SIZE COUNT |
1028 ** | 1035 ** |
1029 */ | 1036 */ |
1030 static int test_config_lookaside( | 1037 static int test_config_lookaside( |
1031 void * clientData, | 1038 void * clientData, |
1032 Tcl_Interp *interp, | 1039 Tcl_Interp *interp, |
1033 int objc, | 1040 int objc, |
1034 Tcl_Obj *CONST objv[] | 1041 Tcl_Obj *CONST objv[] |
1035 ){ | 1042 ){ |
1036 int rc; | |
1037 int sz, cnt; | 1043 int sz, cnt; |
1038 Tcl_Obj *pRet; | 1044 Tcl_Obj *pRet; |
1039 if( objc!=3 ){ | 1045 if( objc!=3 ){ |
1040 Tcl_WrongNumArgs(interp, 1, objv, "SIZE COUNT"); | 1046 Tcl_WrongNumArgs(interp, 1, objv, "SIZE COUNT"); |
1041 return TCL_ERROR; | 1047 return TCL_ERROR; |
1042 } | 1048 } |
1043 if( Tcl_GetIntFromObj(interp, objv[1], &sz) ) return TCL_ERROR; | 1049 if( Tcl_GetIntFromObj(interp, objv[1], &sz) ) return TCL_ERROR; |
1044 if( Tcl_GetIntFromObj(interp, objv[2], &cnt) ) return TCL_ERROR; | 1050 if( Tcl_GetIntFromObj(interp, objv[2], &cnt) ) return TCL_ERROR; |
1045 pRet = Tcl_NewObj(); | 1051 pRet = Tcl_NewObj(); |
1046 Tcl_ListObjAppendElement( | 1052 Tcl_ListObjAppendElement( |
1047 interp, pRet, Tcl_NewIntObj(sqlite3GlobalConfig.szLookaside) | 1053 interp, pRet, Tcl_NewIntObj(sqlite3GlobalConfig.szLookaside) |
1048 ); | 1054 ); |
1049 Tcl_ListObjAppendElement( | 1055 Tcl_ListObjAppendElement( |
1050 interp, pRet, Tcl_NewIntObj(sqlite3GlobalConfig.nLookaside) | 1056 interp, pRet, Tcl_NewIntObj(sqlite3GlobalConfig.nLookaside) |
1051 ); | 1057 ); |
1052 rc = sqlite3_config(SQLITE_CONFIG_LOOKASIDE, sz, cnt); | 1058 sqlite3_config(SQLITE_CONFIG_LOOKASIDE, sz, cnt); |
1053 Tcl_SetObjResult(interp, pRet); | 1059 Tcl_SetObjResult(interp, pRet); |
1054 return TCL_OK; | 1060 return TCL_OK; |
1055 } | 1061 } |
1056 | 1062 |
1057 | 1063 |
1058 /* | 1064 /* |
1059 ** Usage: sqlite3_db_config_lookaside CONNECTION BUFID SIZE COUNT | 1065 ** Usage: sqlite3_db_config_lookaside CONNECTION BUFID SIZE COUNT |
1060 ** | 1066 ** |
1061 ** There are two static buffers with BUFID 1 and 2. Each static buffer | 1067 ** There are two static buffers with BUFID 1 and 2. Each static buffer |
1062 ** is 10KB in size. A BUFID of 0 indicates that the buffer should be NULL | 1068 ** is 10KB in size. A BUFID of 0 indicates that the buffer should be NULL |
1063 ** which will cause sqlite3_db_config() to allocate space on its own. | 1069 ** which will cause sqlite3_db_config() to allocate space on its own. |
1064 */ | 1070 */ |
1065 static int test_db_config_lookaside( | 1071 static int test_db_config_lookaside( |
1066 void * clientData, | 1072 void * clientData, |
1067 Tcl_Interp *interp, | 1073 Tcl_Interp *interp, |
1068 int objc, | 1074 int objc, |
1069 Tcl_Obj *CONST objv[] | 1075 Tcl_Obj *CONST objv[] |
1070 ){ | 1076 ){ |
1071 int rc; | 1077 int rc; |
1072 int sz, cnt; | 1078 int sz, cnt; |
1073 sqlite3 *db; | 1079 sqlite3 *db; |
1074 int bufid; | 1080 int bufid; |
1075 static char azBuf[2][10000]; | 1081 static char azBuf[2][10000]; |
1076 int getDbPointer(Tcl_Interp*, const char*, sqlite3**); | 1082 extern int getDbPointer(Tcl_Interp*, const char*, sqlite3**); |
1077 if( objc!=5 ){ | 1083 if( objc!=5 ){ |
1078 Tcl_WrongNumArgs(interp, 1, objv, "BUFID SIZE COUNT"); | 1084 Tcl_WrongNumArgs(interp, 1, objv, "BUFID SIZE COUNT"); |
1079 return TCL_ERROR; | 1085 return TCL_ERROR; |
1080 } | 1086 } |
1081 if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; | 1087 if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
1082 if( Tcl_GetIntFromObj(interp, objv[2], &bufid) ) return TCL_ERROR; | 1088 if( Tcl_GetIntFromObj(interp, objv[2], &bufid) ) return TCL_ERROR; |
1083 if( Tcl_GetIntFromObj(interp, objv[3], &sz) ) return TCL_ERROR; | 1089 if( Tcl_GetIntFromObj(interp, objv[3], &sz) ) return TCL_ERROR; |
1084 if( Tcl_GetIntFromObj(interp, objv[4], &cnt) ) return TCL_ERROR; | 1090 if( Tcl_GetIntFromObj(interp, objv[4], &cnt) ) return TCL_ERROR; |
1085 if( bufid==0 ){ | 1091 if( bufid==0 ){ |
1086 rc = sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE, 0, sz, cnt); | 1092 rc = sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE, 0, sz, cnt); |
1087 }else if( bufid>=1 && bufid<=2 && sz*cnt<=sizeof(azBuf[0]) ){ | 1093 }else if( bufid>=1 && bufid<=2 && sz*cnt<=sizeof(azBuf[0]) ){ |
1088 rc = sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE, azBuf[bufid], sz,cnt); | 1094 rc = sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE, azBuf[bufid], sz,cnt); |
1089 }else{ | 1095 }else{ |
1090 Tcl_AppendResult(interp, "illegal arguments - see documentation", (char*)0); | 1096 Tcl_AppendResult(interp, "illegal arguments - see documentation", (char*)0); |
1091 return TCL_ERROR; | 1097 return TCL_ERROR; |
1092 } | 1098 } |
1093 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); | 1099 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); |
1094 return TCL_OK; | 1100 return TCL_OK; |
1095 } | 1101 } |
1096 | 1102 |
1097 /* | 1103 /* |
1098 ** Usage: | 1104 ** Usage: sqlite3_config_heap NBYTE NMINALLOC |
1099 ** | |
1100 ** sqlite3_config_heap NBYTE NMINALLOC | |
1101 */ | 1105 */ |
1102 static int test_config_heap( | 1106 static int test_config_heap( |
1103 void * clientData, | 1107 void * clientData, |
1104 Tcl_Interp *interp, | 1108 Tcl_Interp *interp, |
1105 int objc, | 1109 int objc, |
1106 Tcl_Obj *CONST objv[] | 1110 Tcl_Obj *CONST objv[] |
1107 ){ | 1111 ){ |
1108 static char *zBuf; /* Use this memory */ | 1112 static char *zBuf; /* Use this memory */ |
1109 static int szBuf; /* Bytes allocated for zBuf */ | |
1110 int nByte; /* Size of buffer to pass to sqlite3_config() */ | 1113 int nByte; /* Size of buffer to pass to sqlite3_config() */ |
1111 int nMinAlloc; /* Size of minimum allocation */ | 1114 int nMinAlloc; /* Size of minimum allocation */ |
1112 int rc; /* Return code of sqlite3_config() */ | 1115 int rc; /* Return code of sqlite3_config() */ |
1113 | 1116 |
1114 Tcl_Obj * CONST *aArg = &objv[1]; | 1117 Tcl_Obj * CONST *aArg = &objv[1]; |
1115 int nArg = objc-1; | 1118 int nArg = objc-1; |
1116 | 1119 |
1117 if( nArg!=2 ){ | 1120 if( nArg!=2 ){ |
1118 Tcl_WrongNumArgs(interp, 1, objv, "NBYTE NMINALLOC"); | 1121 Tcl_WrongNumArgs(interp, 1, objv, "NBYTE NMINALLOC"); |
1119 return TCL_ERROR; | 1122 return TCL_ERROR; |
1120 } | 1123 } |
1121 if( Tcl_GetIntFromObj(interp, aArg[0], &nByte) ) return TCL_ERROR; | 1124 if( Tcl_GetIntFromObj(interp, aArg[0], &nByte) ) return TCL_ERROR; |
1122 if( Tcl_GetIntFromObj(interp, aArg[1], &nMinAlloc) ) return TCL_ERROR; | 1125 if( Tcl_GetIntFromObj(interp, aArg[1], &nMinAlloc) ) return TCL_ERROR; |
1123 | 1126 |
1124 if( nByte==0 ){ | 1127 if( nByte==0 ){ |
1125 free( zBuf ); | 1128 free( zBuf ); |
1126 zBuf = 0; | 1129 zBuf = 0; |
1127 szBuf = 0; | |
1128 rc = sqlite3_config(SQLITE_CONFIG_HEAP, (void*)0, 0, 0); | 1130 rc = sqlite3_config(SQLITE_CONFIG_HEAP, (void*)0, 0, 0); |
1129 }else{ | 1131 }else{ |
1130 zBuf = realloc(zBuf, nByte); | 1132 zBuf = realloc(zBuf, nByte); |
1131 szBuf = nByte; | |
1132 rc = sqlite3_config(SQLITE_CONFIG_HEAP, zBuf, nByte, nMinAlloc); | 1133 rc = sqlite3_config(SQLITE_CONFIG_HEAP, zBuf, nByte, nMinAlloc); |
1133 } | 1134 } |
1134 | 1135 |
1135 Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE); | 1136 Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE); |
1136 return TCL_OK; | 1137 return TCL_OK; |
1137 } | 1138 } |
1138 | 1139 |
1139 /* | 1140 /* |
1140 ** tclcmd: sqlite3_config_error [DB] | 1141 ** Usage: sqlite3_config_heap_size NBYTE |
| 1142 */ |
| 1143 static int test_config_heap_size( |
| 1144 void * clientData, |
| 1145 Tcl_Interp *interp, |
| 1146 int objc, |
| 1147 Tcl_Obj *CONST objv[] |
| 1148 ){ |
| 1149 int nByte; /* Size to pass to sqlite3_config() */ |
| 1150 int rc; /* Return code of sqlite3_config() */ |
| 1151 |
| 1152 Tcl_Obj * CONST *aArg = &objv[1]; |
| 1153 int nArg = objc-1; |
| 1154 |
| 1155 if( nArg!=1 ){ |
| 1156 Tcl_WrongNumArgs(interp, 1, objv, "NBYTE"); |
| 1157 return TCL_ERROR; |
| 1158 } |
| 1159 if( Tcl_GetIntFromObj(interp, aArg[0], &nByte) ) return TCL_ERROR; |
| 1160 |
| 1161 rc = sqlite3_config(SQLITE_CONFIG_WIN32_HEAPSIZE, nByte); |
| 1162 |
| 1163 Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE); |
| 1164 return TCL_OK; |
| 1165 } |
| 1166 |
| 1167 /* |
| 1168 ** Usage: sqlite3_config_error [DB] |
1141 ** | 1169 ** |
1142 ** Invoke sqlite3_config() or sqlite3_db_config() with invalid | 1170 ** Invoke sqlite3_config() or sqlite3_db_config() with invalid |
1143 ** opcodes and verify that they return errors. | 1171 ** opcodes and verify that they return errors. |
1144 */ | 1172 */ |
1145 static int test_config_error( | 1173 static int test_config_error( |
1146 void * clientData, | 1174 void * clientData, |
1147 Tcl_Interp *interp, | 1175 Tcl_Interp *interp, |
1148 int objc, | 1176 int objc, |
1149 Tcl_Obj *CONST objv[] | 1177 Tcl_Obj *CONST objv[] |
1150 ){ | 1178 ){ |
1151 sqlite3 *db; | 1179 sqlite3 *db; |
1152 int getDbPointer(Tcl_Interp*, const char*, sqlite3**); | 1180 extern int getDbPointer(Tcl_Interp*, const char*, sqlite3**); |
1153 | 1181 |
1154 if( objc!=2 && objc!=1 ){ | 1182 if( objc!=2 && objc!=1 ){ |
1155 Tcl_WrongNumArgs(interp, 1, objv, "[DB]"); | 1183 Tcl_WrongNumArgs(interp, 1, objv, "[DB]"); |
1156 return TCL_ERROR; | 1184 return TCL_ERROR; |
1157 } | 1185 } |
1158 if( objc==2 ){ | 1186 if( objc==2 ){ |
1159 if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; | 1187 if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
1160 if( sqlite3_db_config(db, 99999)!=SQLITE_ERROR ){ | 1188 if( sqlite3_db_config(db, 99999)!=SQLITE_ERROR ){ |
1161 Tcl_AppendResult(interp, | 1189 Tcl_AppendResult(interp, |
1162 "sqlite3_db_config(db, 99999) does not return SQLITE_ERROR", | 1190 "sqlite3_db_config(db, 99999) does not return SQLITE_ERROR", |
1163 (char*)0); | 1191 (char*)0); |
1164 return TCL_ERROR; | 1192 return TCL_ERROR; |
1165 } | 1193 } |
1166 }else{ | 1194 }else{ |
1167 if( sqlite3_config(99999)!=SQLITE_ERROR ){ | 1195 if( sqlite3_config(99999)!=SQLITE_ERROR ){ |
1168 Tcl_AppendResult(interp, | 1196 Tcl_AppendResult(interp, |
1169 "sqlite3_config(99999) does not return SQLITE_ERROR", | 1197 "sqlite3_config(99999) does not return SQLITE_ERROR", |
1170 (char*)0); | 1198 (char*)0); |
1171 return TCL_ERROR; | 1199 return TCL_ERROR; |
1172 } | 1200 } |
1173 } | 1201 } |
1174 return TCL_OK; | 1202 return TCL_OK; |
1175 } | 1203 } |
1176 | 1204 |
1177 /* | 1205 /* |
1178 ** Usage: | 1206 ** Usage: sqlite3_config_uri BOOLEAN |
1179 ** | 1207 ** |
1180 ** sqlite3_dump_memsys3 FILENAME | 1208 ** Enables or disables interpretation of URI parameters by default using |
1181 ** sqlite3_dump_memsys5 FILENAME | 1209 ** SQLITE_CONFIG_URI. |
| 1210 */ |
| 1211 static int test_config_uri( |
| 1212 void * clientData, |
| 1213 Tcl_Interp *interp, |
| 1214 int objc, |
| 1215 Tcl_Obj *CONST objv[] |
| 1216 ){ |
| 1217 int rc; |
| 1218 int bOpenUri; |
| 1219 |
| 1220 if( objc!=2 ){ |
| 1221 Tcl_WrongNumArgs(interp, 1, objv, "BOOL"); |
| 1222 return TCL_ERROR; |
| 1223 } |
| 1224 if( Tcl_GetBooleanFromObj(interp, objv[1], &bOpenUri) ){ |
| 1225 return TCL_ERROR; |
| 1226 } |
| 1227 |
| 1228 rc = sqlite3_config(SQLITE_CONFIG_URI, bOpenUri); |
| 1229 Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE); |
| 1230 |
| 1231 return TCL_OK; |
| 1232 } |
| 1233 |
| 1234 /* |
| 1235 ** Usage: sqlite3_config_cis BOOLEAN |
| 1236 ** |
| 1237 ** Enables or disables the use of the covering-index scan optimization. |
| 1238 ** SQLITE_CONFIG_COVERING_INDEX_SCAN. |
| 1239 */ |
| 1240 static int test_config_cis( |
| 1241 void * clientData, |
| 1242 Tcl_Interp *interp, |
| 1243 int objc, |
| 1244 Tcl_Obj *CONST objv[] |
| 1245 ){ |
| 1246 int rc; |
| 1247 int bUseCis; |
| 1248 |
| 1249 if( objc!=2 ){ |
| 1250 Tcl_WrongNumArgs(interp, 1, objv, "BOOL"); |
| 1251 return TCL_ERROR; |
| 1252 } |
| 1253 if( Tcl_GetBooleanFromObj(interp, objv[1], &bUseCis) ){ |
| 1254 return TCL_ERROR; |
| 1255 } |
| 1256 |
| 1257 rc = sqlite3_config(SQLITE_CONFIG_COVERING_INDEX_SCAN, bUseCis); |
| 1258 Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE); |
| 1259 |
| 1260 return TCL_OK; |
| 1261 } |
| 1262 |
| 1263 |
| 1264 /* |
| 1265 ** Usage: sqlite3_dump_memsys3 FILENAME |
| 1266 ** sqlite3_dump_memsys5 FILENAME |
1182 ** | 1267 ** |
1183 ** Write a summary of unfreed memsys3 allocations to FILENAME. | 1268 ** Write a summary of unfreed memsys3 allocations to FILENAME. |
1184 */ | 1269 */ |
1185 static int test_dump_memsys3( | 1270 static int test_dump_memsys3( |
1186 void * clientData, | 1271 void * clientData, |
1187 Tcl_Interp *interp, | 1272 Tcl_Interp *interp, |
1188 int objc, | 1273 int objc, |
1189 Tcl_Obj *CONST objv[] | 1274 Tcl_Obj *CONST objv[] |
1190 ){ | 1275 ){ |
1191 if( objc!=2 ){ | 1276 if( objc!=2 ){ |
1192 Tcl_WrongNumArgs(interp, 1, objv, "FILENAME"); | 1277 Tcl_WrongNumArgs(interp, 1, objv, "FILENAME"); |
1193 return TCL_ERROR; | 1278 return TCL_ERROR; |
1194 } | 1279 } |
1195 | 1280 |
1196 switch( (int)clientData ){ | 1281 switch( SQLITE_PTR_TO_INT(clientData) ){ |
1197 case 3: { | 1282 case 3: { |
1198 #ifdef SQLITE_ENABLE_MEMSYS3 | 1283 #ifdef SQLITE_ENABLE_MEMSYS3 |
1199 extern void sqlite3Memsys3Dump(const char*); | 1284 extern void sqlite3Memsys3Dump(const char*); |
1200 sqlite3Memsys3Dump(Tcl_GetString(objv[1])); | 1285 sqlite3Memsys3Dump(Tcl_GetString(objv[1])); |
1201 break; | 1286 break; |
1202 #endif | 1287 #endif |
1203 } | 1288 } |
1204 case 5: { | 1289 case 5: { |
1205 #ifdef SQLITE_ENABLE_MEMSYS5 | 1290 #ifdef SQLITE_ENABLE_MEMSYS5 |
1206 extern void sqlite3Memsys5Dump(const char*); | 1291 extern void sqlite3Memsys5Dump(const char*); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 static int test_db_status( | 1363 static int test_db_status( |
1279 void * clientData, | 1364 void * clientData, |
1280 Tcl_Interp *interp, | 1365 Tcl_Interp *interp, |
1281 int objc, | 1366 int objc, |
1282 Tcl_Obj *CONST objv[] | 1367 Tcl_Obj *CONST objv[] |
1283 ){ | 1368 ){ |
1284 int rc, iValue, mxValue; | 1369 int rc, iValue, mxValue; |
1285 int i, op, resetFlag; | 1370 int i, op, resetFlag; |
1286 const char *zOpName; | 1371 const char *zOpName; |
1287 sqlite3 *db; | 1372 sqlite3 *db; |
1288 int getDbPointer(Tcl_Interp*, const char*, sqlite3**); | 1373 extern int getDbPointer(Tcl_Interp*, const char*, sqlite3**); |
1289 static const struct { | 1374 static const struct { |
1290 const char *zName; | 1375 const char *zName; |
1291 int op; | 1376 int op; |
1292 } aOp[] = { | 1377 } aOp[] = { |
1293 { "LOOKASIDE_USED", SQLITE_DBSTATUS_LOOKASIDE_USED }, | 1378 { "LOOKASIDE_USED", SQLITE_DBSTATUS_LOOKASIDE_USED }, |
1294 { "CACHE_USED", SQLITE_DBSTATUS_CACHE_USED }, | 1379 { "CACHE_USED", SQLITE_DBSTATUS_CACHE_USED }, |
1295 { "SCHEMA_USED", SQLITE_DBSTATUS_SCHEMA_USED }, | 1380 { "SCHEMA_USED", SQLITE_DBSTATUS_SCHEMA_USED }, |
1296 { "STMT_USED", SQLITE_DBSTATUS_STMT_USED }, | 1381 { "STMT_USED", SQLITE_DBSTATUS_STMT_USED }, |
1297 { "LOOKASIDE_HIT", SQLITE_DBSTATUS_LOOKASIDE_HIT }, | 1382 { "LOOKASIDE_HIT", SQLITE_DBSTATUS_LOOKASIDE_HIT }, |
1298 { "LOOKASIDE_MISS_SIZE", SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE }, | 1383 { "LOOKASIDE_MISS_SIZE", SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE }, |
1299 { "LOOKASIDE_MISS_FULL", SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL } | 1384 { "LOOKASIDE_MISS_FULL", SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL }, |
| 1385 { "CACHE_HIT", SQLITE_DBSTATUS_CACHE_HIT }, |
| 1386 { "CACHE_MISS", SQLITE_DBSTATUS_CACHE_MISS }, |
| 1387 { "CACHE_WRITE", SQLITE_DBSTATUS_CACHE_WRITE }, |
| 1388 { "DEFERRED_FKS", SQLITE_DBSTATUS_DEFERRED_FKS } |
1300 }; | 1389 }; |
1301 Tcl_Obj *pResult; | 1390 Tcl_Obj *pResult; |
1302 if( objc!=4 ){ | 1391 if( objc!=4 ){ |
1303 Tcl_WrongNumArgs(interp, 1, objv, "PARAMETER RESETFLAG"); | 1392 Tcl_WrongNumArgs(interp, 1, objv, "DB PARAMETER RESETFLAG"); |
1304 return TCL_ERROR; | 1393 return TCL_ERROR; |
1305 } | 1394 } |
1306 if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; | 1395 if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
1307 zOpName = Tcl_GetString(objv[2]); | 1396 zOpName = Tcl_GetString(objv[2]); |
1308 if( memcmp(zOpName, "SQLITE_", 7)==0 ) zOpName += 7; | 1397 if( memcmp(zOpName, "SQLITE_", 7)==0 ) zOpName += 7; |
1309 if( memcmp(zOpName, "DBSTATUS_", 9)==0 ) zOpName += 9; | 1398 if( memcmp(zOpName, "DBSTATUS_", 9)==0 ) zOpName += 9; |
1310 for(i=0; i<ArraySize(aOp); i++){ | 1399 for(i=0; i<ArraySize(aOp); i++){ |
1311 if( strcmp(aOp[i].zName, zOpName)==0 ){ | 1400 if( strcmp(aOp[i].zName, zOpName)==0 ){ |
1312 op = aOp[i].op; | 1401 op = aOp[i].op; |
1313 break; | 1402 break; |
(...skipping 27 matching lines...) Expand all Loading... |
1341 int isInstall; | 1430 int isInstall; |
1342 | 1431 |
1343 if( objc!=2 ){ | 1432 if( objc!=2 ){ |
1344 Tcl_WrongNumArgs(interp, 1, objv, "BOOLEAN"); | 1433 Tcl_WrongNumArgs(interp, 1, objv, "BOOLEAN"); |
1345 return TCL_ERROR; | 1434 return TCL_ERROR; |
1346 } | 1435 } |
1347 if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[1], &isInstall) ){ | 1436 if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[1], &isInstall) ){ |
1348 return TCL_ERROR; | 1437 return TCL_ERROR; |
1349 } | 1438 } |
1350 rc = faultsimInstall(isInstall); | 1439 rc = faultsimInstall(isInstall); |
1351 Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE); | 1440 Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE); |
1352 return TCL_OK; | 1441 return TCL_OK; |
1353 } | 1442 } |
1354 | 1443 |
1355 /* | 1444 /* |
1356 ** sqlite3_install_memsys3 | 1445 ** sqlite3_install_memsys3 |
1357 */ | 1446 */ |
1358 static int test_install_memsys3( | 1447 static int test_install_memsys3( |
1359 void * clientData, | 1448 void * clientData, |
1360 Tcl_Interp *interp, | 1449 Tcl_Interp *interp, |
1361 int objc, | 1450 int objc, |
1362 Tcl_Obj *CONST objv[] | 1451 Tcl_Obj *CONST objv[] |
1363 ){ | 1452 ){ |
1364 int rc = SQLITE_MISUSE; | 1453 int rc = SQLITE_MISUSE; |
1365 #ifdef SQLITE_ENABLE_MEMSYS3 | 1454 #ifdef SQLITE_ENABLE_MEMSYS3 |
1366 const sqlite3_mem_methods *sqlite3MemGetMemsys3(void); | 1455 const sqlite3_mem_methods *sqlite3MemGetMemsys3(void); |
1367 rc = sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetMemsys3()); | 1456 rc = sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetMemsys3()); |
1368 #endif | 1457 #endif |
1369 Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE); | 1458 Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE); |
1370 return TCL_OK; | 1459 return TCL_OK; |
1371 } | 1460 } |
1372 | 1461 |
1373 static int test_vfs_oom_test( | 1462 static int test_vfs_oom_test( |
1374 void * clientData, | 1463 void * clientData, |
1375 Tcl_Interp *interp, | 1464 Tcl_Interp *interp, |
1376 int objc, | 1465 int objc, |
1377 Tcl_Obj *CONST objv[] | 1466 Tcl_Obj *CONST objv[] |
1378 ){ | 1467 ){ |
1379 extern int sqlite3_memdebug_vfs_oom_test; | 1468 extern int sqlite3_memdebug_vfs_oom_test; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1412 { "sqlite3_memdebug_settitle", test_memdebug_settitle ,0 }, | 1501 { "sqlite3_memdebug_settitle", test_memdebug_settitle ,0 }, |
1413 { "sqlite3_memdebug_malloc_count", test_memdebug_malloc_count ,0 }, | 1502 { "sqlite3_memdebug_malloc_count", test_memdebug_malloc_count ,0 }, |
1414 { "sqlite3_memdebug_log", test_memdebug_log ,0 }, | 1503 { "sqlite3_memdebug_log", test_memdebug_log ,0 }, |
1415 { "sqlite3_config_scratch", test_config_scratch ,0 }, | 1504 { "sqlite3_config_scratch", test_config_scratch ,0 }, |
1416 { "sqlite3_config_pagecache", test_config_pagecache ,0 }, | 1505 { "sqlite3_config_pagecache", test_config_pagecache ,0 }, |
1417 { "sqlite3_config_alt_pcache", test_alt_pcache ,0 }, | 1506 { "sqlite3_config_alt_pcache", test_alt_pcache ,0 }, |
1418 { "sqlite3_status", test_status ,0 }, | 1507 { "sqlite3_status", test_status ,0 }, |
1419 { "sqlite3_db_status", test_db_status ,0 }, | 1508 { "sqlite3_db_status", test_db_status ,0 }, |
1420 { "install_malloc_faultsim", test_install_malloc_faultsim ,0 }, | 1509 { "install_malloc_faultsim", test_install_malloc_faultsim ,0 }, |
1421 { "sqlite3_config_heap", test_config_heap ,0 }, | 1510 { "sqlite3_config_heap", test_config_heap ,0 }, |
| 1511 { "sqlite3_config_heap_size", test_config_heap_size ,0 }, |
1422 { "sqlite3_config_memstatus", test_config_memstatus ,0 }, | 1512 { "sqlite3_config_memstatus", test_config_memstatus ,0 }, |
1423 { "sqlite3_config_lookaside", test_config_lookaside ,0 }, | 1513 { "sqlite3_config_lookaside", test_config_lookaside ,0 }, |
1424 { "sqlite3_config_error", test_config_error ,0 }, | 1514 { "sqlite3_config_error", test_config_error ,0 }, |
| 1515 { "sqlite3_config_uri", test_config_uri ,0 }, |
| 1516 { "sqlite3_config_cis", test_config_cis ,0 }, |
1425 { "sqlite3_db_config_lookaside",test_db_config_lookaside ,0 }, | 1517 { "sqlite3_db_config_lookaside",test_db_config_lookaside ,0 }, |
1426 { "sqlite3_dump_memsys3", test_dump_memsys3 ,3 }, | 1518 { "sqlite3_dump_memsys3", test_dump_memsys3 ,3 }, |
1427 { "sqlite3_dump_memsys5", test_dump_memsys3 ,5 }, | 1519 { "sqlite3_dump_memsys5", test_dump_memsys3 ,5 }, |
1428 { "sqlite3_install_memsys3", test_install_memsys3 ,0 }, | 1520 { "sqlite3_install_memsys3", test_install_memsys3 ,0 }, |
1429 { "sqlite3_memdebug_vfs_oom_test", test_vfs_oom_test ,0 }, | 1521 { "sqlite3_memdebug_vfs_oom_test", test_vfs_oom_test ,0 }, |
1430 }; | 1522 }; |
1431 int i; | 1523 int i; |
1432 for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){ | 1524 for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){ |
1433 ClientData c = (ClientData)aObjCmd[i].clientData; | 1525 ClientData c = (ClientData)SQLITE_INT_TO_PTR(aObjCmd[i].clientData); |
1434 Tcl_CreateObjCommand(interp, aObjCmd[i].zName, aObjCmd[i].xProc, c, 0); | 1526 Tcl_CreateObjCommand(interp, aObjCmd[i].zName, aObjCmd[i].xProc, c, 0); |
1435 } | 1527 } |
1436 return TCL_OK; | 1528 return TCL_OK; |
1437 } | 1529 } |
1438 #endif | 1530 #endif |
OLD | NEW |