Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Further work on the new API. All the functions to execute queries are there now. (CVS 1427) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
fc94575d77f9865e1553bb70c2e3eda2 |
User & Date: | danielk1977 2004-05-21 10:08:54.000 |
Context
2004-05-21
| ||
10:49 | Pretty-print blobs in vdbe-traces. (CVS 1428) (check-in: 5eb94c9765 user: danielk1977 tags: trunk) | |
10:08 | Further work on the new API. All the functions to execute queries are there now. (CVS 1427) (check-in: fc94575d77 user: danielk1977 tags: trunk) | |
03:01 | Eliminate the OP_SortMakeRec and OP_SortCallback opcodes. Sort using the standard record format. (CVS 1426) (check-in: 25643a0137 user: drh tags: trunk) | |
Changes
Changes to src/main.c.
︙ | ︙ | |||
10 11 12 13 14 15 16 | ** ************************************************************************* ** Main file for the SQLite library. The routines in this file ** implement the programmer interface to the library. Routines in ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ** ************************************************************************* ** Main file for the SQLite library. The routines in this file ** implement the programmer interface to the library. Routines in ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** ** $Id: main.c,v 1.180 2004/05/21 10:08:54 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> /* ** A pointer to this structure is used to communicate information |
︙ | ︙ | |||
1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 | rc = openDatabase(zFilename8, ppDb, options, TEXT_Utf16le); } sqliteFree(zFilename8); return rc; } #if 0 /* ** sqlite3_open ** */ | > > > > > > > > > > > > > > > > > > > > > > > > > > | 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 | rc = openDatabase(zFilename8, ppDb, options, TEXT_Utf16le); } sqliteFree(zFilename8); return rc; } /* ** The following routine destroys a virtual machine that is created by ** the sqlite3_compile() routine. The integer returned is an SQLITE_ ** success/failure code that describes the result of executing the virtual ** machine. ** ** This routine sets the error code and string returned by ** sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16(). */ int sqlite3_finalize_new(sqlite3_stmt *pStmt){ return sqlite3VdbeFinalize((Vdbe*)pStmt, 0); } /* ** Terminate the current execution of an SQL statement and reset it ** back to its starting state so that it can be reused. A success code from ** the prior execution is returned. ** ** This routine sets the error code and string returned by ** sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16(). */ int sqlite3_reset_new(sqlite3_stmt *pStmt){ int rc = sqlite3VdbeReset((Vdbe*)pStmt, 0); sqlite3VdbeMakeReady((Vdbe*)pStmt, -1, 0); return rc; } #if 0 /* ** sqlite3_open ** */ |
︙ | ︙ |
Changes to src/sqlite.h.in.
︙ | ︙ | |||
8 9 10 11 12 13 14 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This header file defines the interface that the SQLite library ** presents to client programs. ** | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This header file defines the interface that the SQLite library ** presents to client programs. ** ** @(#) $Id: sqlite.h.in,v 1.68 2004/05/21 10:08:54 danielk1977 Exp $ */ #ifndef _SQLITE_H_ #define _SQLITE_H_ #include <stdarg.h> /* Needed for the definition of va_list */ /* ** Make sure we can call this stuff from C++. |
︙ | ︙ | |||
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 | ** sqlite3_bind_int32 ** sqlite3_bind_int64 ** sqlite3_bind_double ** sqlite3_bind_null ** sqlite3_bind_text ** sqlite3_bind_text16 ** sqlite3_bind_blob ** ** Assuming no other intervening sqlite3_* API calls are made, the error ** code returned by this function is associated with the same error as ** the strings returned by sqlite3_errmsg() and sqlite3_errmsg16(). */ int sqlite3_errcode(sqlite3 *db); | > > > > > > | 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 | ** sqlite3_bind_int32 ** sqlite3_bind_int64 ** sqlite3_bind_double ** sqlite3_bind_null ** sqlite3_bind_text ** sqlite3_bind_text16 ** sqlite3_bind_blob ** sqlite3_open ** sqlite3_open16 ** sqlite3_prepare ** sqlite3_prepare16 ** sqlite3_step ** sqlite3_finalize ** ** Assuming no other intervening sqlite3_* API calls are made, the error ** code returned by this function is associated with the same error as ** the strings returned by sqlite3_errmsg() and sqlite3_errmsg16(). */ int sqlite3_errcode(sqlite3 *db); |
︙ | ︙ | |||
1028 1029 1030 1031 1032 1033 1034 | /* ** To execute an SQL query, it must first be compiled into a byte-code ** program using this routine. The first parameter "db" is an SQLite ** database handle. The second parameter "zSql" is the statement ** to be compiled, encoded as UTF-8 text. If the next parameter, "nBytes", ** is less than zero, then zSql is read up to the first nul terminator. ** If "nBytes" is not less than zero, then it is the length of the | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | | | | | > | > > | > > > > > > | | > > | | > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < < > > > > > > > > > > > > > | 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 | /* ** To execute an SQL query, it must first be compiled into a byte-code ** program using this routine. The first parameter "db" is an SQLite ** database handle. The second parameter "zSql" is the statement ** to be compiled, encoded as UTF-8 text. If the next parameter, "nBytes", ** is less than zero, then zSql is read up to the first nul terminator. ** If "nBytes" is not less than zero, then it is the length of the ** string zSql in bytes (not characters). ** ** *pzTail is made to point to the first byte past the end of the first ** SQL statement in zSql. This routine only compiles the first statement ** in zSql, so *pzTail is left pointing to what remains uncompiled. ** ** *ppStmt is left pointing to a compiled SQL statement that can be ** executed using sqlite3_step(). Or if there is an error, *ppStmt may be ** set to NULL. If the input text contained no SQL (if the input is and ** empty string or a comment) then *ppStmt is set to NULL. ** ** On success, SQLITE_OK is returned. Otherwise an error code is returned. ** */ int sqlite3_prepare( sqlite3 *db, /* Database handle */ const char *zSql, /* SQL statement, UTF-8 encoded */ int nBytes, /* Length of zSql in bytes. */ sqlite3_stmt **ppStmt, /* OUT: Statement handle */ const char **pzTail /* OUT: Pointer to unused portion of zSql */ ); /* ** To execute an SQL query, it must first be compiled into a byte-code ** program using this routine. The first parameter "db" is an SQLite ** database handle. The second parameter "zSql" is the statement ** to be compiled, encoded as UTF-16 text. If the next parameter, "nBytes", ** is less than zero, then zSql is read up to the first pair of successive ** 0x00 bytes. If "nBytes" is not less than zero, then it is the length of ** the string zSql in bytes (not characters). ** ** *pzTail is made to point to the first byte past the end of the first ** SQL statement in zSql. This routine only compiles the first statement ** in zSql, so *pzTail is left pointing to what remains uncompiled. ** ** *ppStmt is left pointing to a compiled SQL statement that can be ** executed using sqlite3_step(). Or if there is an error, *ppStmt may be ** set to NULL. If the input text contained no SQL (if the input is and ** empty string or a comment) then *ppStmt is set to NULL. ** ** On success, SQLITE_OK is returned. Otherwise an error code is returned. ** */ int sqlite3_prepare16( sqlite3 *db, /* Database handle */ const void *zSql, /* SQL statement, UTF-16 encoded */ int nBytes, /* Length of zSql in bytes. */ sqlite3_stmt **ppStmt, /* OUT: Statement handle */ const void **pzTail /* OUT: Pointer to unused portion of zSql */ ); /* ** Return the number of columns in the result set returned by the compiled ** SQL statement. This routine returns 0 if pStmt is an SQL statement ** that does not return data (for example an UPDATE). */ int sqlite3_column_count(sqlite3_stmt *pStmt); /* ** The first parameter is a compiled SQL statement. This function returns ** the column heading for the Nth column of that statement, where N is the ** second function parameter. The string returned is UTF-8 encoded. */ const char *sqlite3_column_name(sqlite3_stmt*,int); /* ** The first parameter is a compiled SQL statement. This function returns ** the column heading for the Nth column of that statement, where N is the ** second function parameter. The string returned is UTF-16 encoded. */ const void *sqlite3_column_name16(sqlite3_stmt*,int); /* ** The first parameter is a compiled SQL statement. If this statement ** is a SELECT statement, the Nth column of the returned result set ** of the SELECT is a table column then the declared type of the table ** column is returned. If the Nth column of the result set is not at table ** column, then a NULL pointer is returned. The returned string is always ** UTF-8 encoded. For example, in the database schema: ** ** CREATE TABLE t1(c1 VARINT); ** ** And the following statement compiled: ** ** SELECT c1 + 1, 0 FROM t1; ** ** Then this routine would return the string "VARIANT" for the second ** result column (i==1), and a NULL pointer for the first result column ** (i==0). */ const char *sqlite3_column_decltype(sqlite3_stmt *, int i); /* ** The first parameter is a compiled SQL statement. If this statement ** is a SELECT statement, the Nth column of the returned result set ** of the SELECT is a table column then the declared type of the table ** column is returned. If the Nth column of the result set is not at table ** column, then a NULL pointer is returned. The returned string is always ** UTF-16 encoded. For example, in the database schema: ** ** CREATE TABLE t1(c1 VARINT); ** ** And the following statement compiled: ** ** SELECT c1 + 1, 0 FROM t1; ** ** Then this routine would return the string "VARIANT" for the second ** result column (i==1), and a NULL pointer for the first result column ** (i==0). */ const void *sqlite3_column_decltype16(sqlite3_stmt*,int); /* ** After an SQL query has been compiled with a call to either ** sqlite3_prepare() or sqlite3_prepare16(), then this function must be ** called one or more times to execute the statement. ** ** The return value will be either SQLITE_BUSY, SQLITE_DONE, ** SQLITE_ROW, SQLITE_ERROR, or SQLITE_MISUSE. ** ** SQLITE_BUSY means that the database engine attempted to open ** a locked database and there is no busy callback registered. ** Call sqlite3_step() again to retry the open. ** ** SQLITE_DONE means that the statement has finished executing ** successfully. sqlite3_step() should not be called again on this virtual ** machine. ** ** If the SQL statement being executed returns any data, then ** SQLITE_ROW is returned each time a new row of data is ready ** for processing by the caller. The values may be accessed using ** the sqlite3_column_*() functions described below. sqlite3_step() ** is called again to retrieve the next row of data. ** ** SQLITE_ERROR means that a run-time error (such as a constraint ** violation) has occurred. sqlite3_step() should not be called again on ** the VM. More information may be found by calling sqlite3_errmsg(). ** ** SQLITE_MISUSE means that the this routine was called inappropriately. ** Perhaps it was called on a virtual machine that had already been ** finalized or on one that had previously returned SQLITE_ERROR or ** SQLITE_DONE. Or it could be the case the the same database connection ** is being used simulataneously by two or more threads. */ int sqlite3_step_new(sqlite3_stmt*); /* ** The sqlite3_finalize() function is called to delete a compiled ** SQL statement obtained by a previous call to sqlite3_prepare() ** or sqlite3_prepare16(). If the statement was executed successfully, or ** not executed at all, then SQLITE_OK is returned. If execution of the ** statement failed then an error code is returned. */ int sqlite3_finalize_new(sqlite3_stmt *pStmt); /* ** The sqlite3_reset() function is called to reset a compiled SQL ** statement obtained by a previous call to sqlite3_prepare() or ** sqlite3_prepare16() back to it's initial state, ready to be re-executed. ** Any SQL statement variables that had values bound to them using ** the sqlite3_bind_*() API retain their values. */ int sqlite3_reset_new(sqlite3_stmt *pStmt); int sqlite3_open_new( const char *filename, /* Database filename (UTF-8) */ sqlite3 **ppDb, /* OUT: SQLite db handle */ const char **args /* Null terminated array of option strings */ ); int sqlite3_open16( const void *filename, /* Database filename (UTF-16) */ sqlite3 **ppDb, /* OUT: SQLite db handle */ const char **args /* Null terminated array of option strings */ ); /* ** Return the number of values in the current row of the result set. ** ** After a call to sqlite3_step() that returns SQLITE_ROW, this routine ** will return the same value as the sqlite3_column_count() function. ** After sqlite3_step() has returned an SQLITE_DONE, SQLITE_BUSY or ** error code, or before sqlite3_step() has been called on a ** compiled SQL statement, this routine returns zero. */ int sqlite3_value_count(sqlite3_stmt *pStmt); #define SQLITE3_INTEGER 1 #define SQLITE3_FLOAT 2 #define SQLITE3_TEXT 3 #define SQLITE3_BLOB 4 #define SQLITE3_NULL 5 /* ** The first parameter is a compiled SQL statement for which the most ** recent call to sqlite3_step() has returned SQLITE_ROW. This routine ** retrieves the type of the Nth column of the current row, where ** N is the second function parameter. ** ** The value type is one of SQLITE3_INTEGER, SQLITE3_FLOAT, SQLITE3_TEXT, ** SQLITE3_BLOB and SQLITE3_NULL. */ int sqlite3_column_type(sqlite3_stmt *pStmt, int i); /* ** The first parameter is a compiled SQL statement for which the most ** recent call to sqlite3_step() has returned SQLITE_ROW. This routine ** retrieves the value of the Nth column of the current row, where ** N is the second function parameter. ** ** The value returned depends on the type of the SQL column value, as ** returned by sqlite3_column_type(): ** ** SQLITE3_NULL A Null pointer. ** SQLITE3_INTEGER String representation of the integer, UTF-8 encoded. ** SQLITE3_FLOAT String representation of the real, UTF-8 encoded. ** SQLITE3_TEXT The string UTF-8 encoded. ** SQLITE3_BLOB A pointer to the blob of data. */ const unsigned char *sqlite3_column_data(sqlite3_stmt*,int); /* ** The first parameter is a compiled SQL statement for which the most ** recent call to sqlite3_step() has returned SQLITE_ROW. This routine ** retrieves the value of the Nth column of the current row, where ** N is the second function parameter. ** ** The value returned depends on the type of the SQL column value, as ** returned by sqlite3_column_type(): ** ** SQLITE3_NULL A Null pointer. ** SQLITE3_INTEGER String representation of the integer, UTF-16 encoded. ** SQLITE3_FLOAT String representation of the real, UTF-16 encoded. ** SQLITE3_TEXT The string UTF-16 encoded. ** SQLITE3_BLOB A pointer to the blob of data. */ const void *sqlite3_column_data16(sqlite3_stmt*,int); /* ** The first parameter is a compiled SQL statement for which the most ** recent call to sqlite3_step() has returned SQLITE_ROW. This routine ** retrieves the length of the data in bytse returned by the ** sqlite3_column_data() routine for the same second parameter value. ** ** If sqlite3_column_data() returns a UTF-8 string, then the length ** returned by this function includes the nul terminator character at the ** end of the UTF-8 string. */ int sqlite3_column_bytes(sqlite3_stmt*,int); /* ** The first parameter is a compiled SQL statement for which the most ** recent call to sqlite3_step() has returned SQLITE_ROW. This routine ** retrieves the value of the Nth column of the current row, where ** N is the second function parameter as an integer. ** ** SQLITE3_NULL 0 ** SQLITE3_INTEGER The integer value. ** SQLITE3_FLOAT The integer component of the real (2^63 if too large) ** SQLITE3_TEXT Integer conversion of string, or 0 ** SQLITE3_BLOB 0 */ long long int sqlite3_column_int(sqlite3_stmt*,int); /* ** The first parameter is a compiled SQL statement for which the most ** recent call to sqlite3_step() has returned SQLITE_ROW. This routine ** retrieves the value of the Nth column of the current row, where ** N is the second function parameter as an integer. ** ** SQLITE3_NULL 0.0 ** SQLITE3_INTEGER The value of the integer. Some rounding may occur. ** SQLITE3_FLOAT The value of the float. ** SQLITE3_TEXT Real number conversion of string, or 0.0 ** SQLITE3_BLOB 0.0 */ double sqlite3_column_float(sqlite3_stmt*,int); #ifdef __cplusplus } /* End of the 'extern "C"' block */ #endif #endif |
Changes to src/sqliteInt.h.
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* ** 2001 September 15 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** Internal interface definitions for SQLite. ** | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /* ** 2001 September 15 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** Internal interface definitions for SQLite. ** ** @(#) $Id: sqliteInt.h,v 1.244 2004/05/21 10:08:54 danielk1977 Exp $ */ #include "config.h" #include "sqlite.h" #include "hash.h" #include "parse.h" #include <stdio.h> #include <stdlib.h> |
︙ | ︙ | |||
318 319 320 321 322 323 324 325 326 327 328 329 330 331 | /* ** Possible values for the Db.textEnc field. */ #define TEXT_Utf8 1 #define TEXT_Utf16le 2 #define TEXT_Utf16be 3 /* ** Each database is an instance of the following structure. ** ** The sqlite.file_format is initialized by the database file ** and helps determines how the data in the database file is ** represented. This field allows newer versions of the library | > | 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | /* ** Possible values for the Db.textEnc field. */ #define TEXT_Utf8 1 #define TEXT_Utf16le 2 #define TEXT_Utf16be 3 #define TEXT_Utf16 4 /* ** Each database is an instance of the following structure. ** ** The sqlite.file_format is initialized by the database file ** and helps determines how the data in the database file is ** represented. This field allows newer versions of the library |
︙ | ︙ | |||
1356 1357 1358 1359 1360 1361 1362 | void sqlite3TableAffinityStr(Vdbe *, Table *); char sqlite3CompareAffinity(Expr *pExpr, char aff2); char const *sqlite3AffinityString(char affinity); int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity); char sqlite3ExprAffinity(Expr *pExpr); int sqlite3atoi64(const char*, i64*); void sqlite3Error(sqlite *, int, const char*,...); | > | 1357 1358 1359 1360 1361 1362 1363 1364 | void sqlite3TableAffinityStr(Vdbe *, Table *); char sqlite3CompareAffinity(Expr *pExpr, char aff2); char const *sqlite3AffinityString(char affinity); int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity); char sqlite3ExprAffinity(Expr *pExpr); int sqlite3atoi64(const char*, i64*); void sqlite3Error(sqlite *, int, const char*,...); |
Changes to src/test1.c.
︙ | ︙ | |||
9 10 11 12 13 14 15 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** Code for testing the printf() interface to SQLite. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** Code for testing the printf() interface to SQLite. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** ** $Id: test1.c,v 1.45 2004/05/21 10:08:54 danielk1977 Exp $ */ #include "sqliteInt.h" #include "tcl.h" #include "os.h" #include <stdlib.h> #include <string.h> |
︙ | ︙ | |||
808 809 810 811 812 813 814 | default: zRc = "unknown"; break; } Tcl_AppendResult(interp, zRc, 0); return TCL_OK; } /* | | | | | | | | | | | | | > > | > > > > | > > > > > > > > > > > > > | > | > > > | > > > > < < < < < < < < < < < < < < < < < < < < < < < < < | 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 | default: zRc = "unknown"; break; } Tcl_AppendResult(interp, zRc, 0); return TCL_OK; } /* ** Usage: sqlite3_finalize STMT ** ** Finalize a statement handle. */ static int test_finalize( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ sqlite3_stmt *pStmt; int rc; if( objc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetStringFromObj(objv[0], 0), " <STMT>", 0); return TCL_ERROR; } if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; rc = sqlite3_finalize_new(pStmt); if( rc ){ return TCL_ERROR; } return TCL_OK; } /* ** Usage: sqlite3_reset STMT ** ** Finalize a statement handle. */ static int test_reset( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ sqlite3_stmt *pStmt; int rc; if( objc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetStringFromObj(objv[0], 0), " <STMT>", 0); return TCL_ERROR; } if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; rc = sqlite3_reset_new(pStmt); if( rc ){ return TCL_ERROR; } return TCL_OK; } /* ** Usage: sqlite3_reset VM ** ** Reset a virtual machine and prepare it to be run again. */ /* ** This is the "static_bind_value" that variables are bound to when ** the FLAG option of sqlite3_bind is "static" */ static char *sqlite_static_bind_value = 0; |
︙ | ︙ | |||
1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 | zFilename = Tcl_GetByteArrayFromObj(objv[1], 0); rc = sqlite3_open16(zFilename, &db, 0); if( makePointerStr(interp, zBuf, db) ) return TCL_ERROR; Tcl_AppendResult(interp, zBuf, 0); return TCL_OK; } /* ** This is a collating function named "REVERSE" which sorts text ** in reverse order. */ static int reverseCollatingFunc( void *NotUsed, | > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 | zFilename = Tcl_GetByteArrayFromObj(objv[1], 0); rc = sqlite3_open16(zFilename, &db, 0); if( makePointerStr(interp, zBuf, db) ) return TCL_ERROR; Tcl_AppendResult(interp, zBuf, 0); return TCL_OK; } /* ** Usage: sqlite3_step STMT ** ** Advance the statement to the next row. */ static int test_step_new( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ sqlite3_stmt *pStmt; int rc; if( objc!=3 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetString(objv[0]), " STMT", 0); return TCL_ERROR; } if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; rc = sqlite3_step_new(pStmt); if( rc!=SQLITE_OK ) return TCL_ERROR; return TCL_OK; } /* ** This is a collating function named "REVERSE" which sorts text ** in reverse order. */ static int reverseCollatingFunc( void *NotUsed, |
︙ | ︙ | |||
1470 1471 1472 1473 1474 1475 1476 | { "sqlite_abort", (Tcl_CmdProc*)sqlite_abort }, { "sqlite_datatypes", (Tcl_CmdProc*)sqlite_datatypes }, #ifdef MEMORY_DEBUG { "sqlite_malloc_fail", (Tcl_CmdProc*)sqlite_malloc_fail }, { "sqlite_malloc_stat", (Tcl_CmdProc*)sqlite_malloc_stat }, #endif { "sqlite_step", (Tcl_CmdProc*)test_step }, | | | > > > | 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 | { "sqlite_abort", (Tcl_CmdProc*)sqlite_abort }, { "sqlite_datatypes", (Tcl_CmdProc*)sqlite_datatypes }, #ifdef MEMORY_DEBUG { "sqlite_malloc_fail", (Tcl_CmdProc*)sqlite_malloc_fail }, { "sqlite_malloc_stat", (Tcl_CmdProc*)sqlite_malloc_stat }, #endif { "sqlite_step", (Tcl_CmdProc*)test_step }, // { "sqlite_finalize", (Tcl_CmdProc*)test_finalize }, { "sqlite_bind", (Tcl_CmdProc*)test_bind }, // { "sqlite_reset", (Tcl_CmdProc*)test_reset }, { "breakpoint", (Tcl_CmdProc*)test_breakpoint }, }; static struct { char *zName; Tcl_ObjCmdProc *xProc; } aObjCmd[] = { { "sqlite3_bind_int32", (Tcl_ObjCmdProc*)test_bind_int32 }, { "sqlite3_bind_int64", (Tcl_ObjCmdProc*)test_bind_int64 }, { "sqlite3_bind_double", (Tcl_ObjCmdProc*)test_bind_double }, { "sqlite3_bind_null", (Tcl_ObjCmdProc*)test_bind_null }, { "sqlite3_bind_text", (Tcl_ObjCmdProc*)test_bind_text }, { "sqlite3_bind_text16", (Tcl_ObjCmdProc*)test_bind_text16 }, { "sqlite3_bind_blob", (Tcl_ObjCmdProc*)test_bind_blob }, { "sqlite3_errcode", (Tcl_ObjCmdProc*)test_errcode }, { "sqlite3_errmsg", (Tcl_ObjCmdProc*)test_errmsg }, { "sqlite3_errmsg16", (Tcl_ObjCmdProc*)test_errmsg16 }, { "sqlite3_prepare", (Tcl_ObjCmdProc*)test_prepare }, { "sqlite3_prepare16", (Tcl_ObjCmdProc*)test_prepare16 }, { "sqlite3_open", (Tcl_ObjCmdProc*)test_open }, { "sqlite3_open16", (Tcl_ObjCmdProc*)test_open16 }, { "sqlite3_finalize", (Tcl_ObjCmdProc*)test_finalize }, { "sqlite3_reset", (Tcl_ObjCmdProc*)test_reset }, { "sqlite3_step", (Tcl_ObjCmdProc*)test_step_new }, { "add_reverse_collating_func", (Tcl_ObjCmdProc*)reverse_collfunc }, }; int i; for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){ Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0); } |
︙ | ︙ |
Changes to src/vdbe.c.
︙ | ︙ | |||
39 40 41 42 43 44 45 | ** ** Various scripts scan this source file in order to generate HTML ** documentation, headers files, or other derived files. The formatting ** of the code in this file is, therefore, important. See other comments ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** | | | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | ** ** Various scripts scan this source file in order to generate HTML ** documentation, headers files, or other derived files. The formatting ** of the code in this file is, therefore, important. See other comments ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** ** $Id: vdbe.c,v 1.313 2004/05/21 10:08:54 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> #include "vdbeInt.h" /* |
︙ | ︙ | |||
65 66 67 68 69 70 71 | ** of the db.flags field is set in order to simulate and interrupt. ** ** This facility is used for testing purposes only. It does not function ** in an ordinary build. */ int sqlite3_interrupt_count = 0; | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | ** of the db.flags field is set in order to simulate and interrupt. ** ** This facility is used for testing purposes only. It does not function ** in an ordinary build. */ int sqlite3_interrupt_count = 0; #define NulTermify(P) if(((P)->flags & MEM_Str)==0){hardStringify(P);} \ else if(((P)->flags & MEM_Term)==0){hardNulTermify(P);} static int hardNulTermify(Mem *pStack){ int flags = pStack->flags; assert( !(flags&MEM_Term) && (flags&MEM_Str) ); assert( flags&(MEM_Utf8|MEM_Utf16le|MEM_Utf16be) ); |
︙ | ︙ | |||
234 235 236 237 238 239 240 | return 0; } /* ** Convert the given stack entity into a string if it isn't one ** already. */ | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | return 0; } /* ** Convert the given stack entity into a string if it isn't one ** already. */ #define Stringify(P) if(!((P)->flags&(MEM_Str|MEM_Blob))){hardStringify(P);} static int hardStringify(Mem *pStack){ int fg = pStack->flags; if( fg & MEM_Real ){ sqlite3_snprintf(sizeof(pStack->zShort),pStack->zShort,"%.15g",pStack->r); }else if( fg & MEM_Int ){ sqlite3_snprintf(sizeof(pStack->zShort),pStack->zShort,"%lld",pStack->i); }else{ pStack->zShort[0] = 0; } pStack->z = pStack->zShort; pStack->n = strlen(pStack->zShort)+1; pStack->flags = MEM_Str | MEM_Short | MEM_Term | MEM_Utf8; return 0; } /* ** Release the memory associated with the given stack level. This ** leaves the Mem.flags field in an inconsistent state. */ #define Release(P) if((P)->flags&MEM_Dyn){ sqliteFree((P)->z); } /* ** Convert the given stack entity into a integer if it isn't one ** already. ** ** Any prior string or real representation is invalidated. ** NULLs are converted into 0. */ |
︙ | ︙ | |||
355 356 357 358 359 360 361 362 363 364 365 366 367 368 | }else if( pStack->flags & MEM_Int ){ pStack->r = pStack->i; }else{ pStack->r = 0.0; } pStack->flags |= MEM_Real; } /* ** The parameters are pointers to the head of two sorted lists ** of Sorter structures. Merge these two lists together and return ** a single sorted list. This routine forms the core of the merge-sort ** algorithm. ** | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 | }else if( pStack->flags & MEM_Int ){ pStack->r = pStack->i; }else{ pStack->r = 0.0; } pStack->flags |= MEM_Real; } /* ** If pMem is a string object, this routine sets the encoding of the string ** (to one of UTF-8 or UTF16) and whether or not the string is ** nul-terminated. If pMem is not a string object, then this routine is ** a no-op. ** ** If argument "utf16" is true, then this routine will attempt to convert ** the string to native byte order UTF-16 encoding. Otherwise, the ** conversion is to UTF-8 encoding. If the "term" argument is true, then a ** nul terminator is added to the string if it does not already have one. ** ** ** ** SQLITE_OK is returned if the conversion is successful (or not required). ** SQLITE_NOMEM may be returned if a malloc() fails during conversion ** between formats. */ static int SetEncoding(Mem *pMem, int flags){ int f; if( !(pMem->flags&MEM_Str) ){ return SQLITE_OK; } f = (pMem->flags)&(MEM_Utf8|MEM_Utf16le|MEM_Utf16be|MEM_Term); assert( flags==(flags&(MEM_Utf8|MEM_Utf16le|MEM_Utf16be|MEM_Term))); if( f==flags ){ return SQLITE_OK; } if( (SQLITE3_BIGENDIAN && (f&MEM_Utf16le)) || (SQLITE3_LITTLEENDIAN && (f&MEM_Utf16be)) ){ int i; for(i=0; i<pMem->n; i+=2){ char c = pMem->z[i]; pMem->z[i] = pMem->z[i+1]; pMem->z[i+1] = c; } } if( (flags&MEM_Utf8) && (f&(MEM_Utf16le|MEM_Utf16be)) ){ char *z = sqlite3utf16to8(pMem->z, pMem->n); if( !z ){ return SQLITE_NOMEM; } Release(pMem); pMem->z = z; pMem->n = strlen(z)+1; pMem->flags = (MEM_Utf8|MEM_Dyn|MEM_Str|MEM_Term); return SQLITE_OK; } if( (flags&MEM_Utf16le) && (f&MEM_Utf8) ){ char *z = sqlite3utf8to16le(pMem->z, pMem->n); if( !z ){ return SQLITE_NOMEM; } Release(pMem); pMem->z = z; pMem->n = sqlite3utf16ByteLen(z, -1) + 2; pMem->flags = (MEM_Utf16le|MEM_Dyn|MEM_Str|MEM_Term); return SQLITE_OK; } if( (flags&MEM_Utf16be) && (f&MEM_Utf8) ){ char *z = sqlite3utf8to16be(pMem->z, pMem->n); if( !z ){ return SQLITE_NOMEM; } Release(pMem); pMem->z = z; pMem->n = sqlite3utf16ByteLen(z, -1) + 2; pMem->flags = (MEM_Utf16be|MEM_Dyn|MEM_Str|MEM_Term); return SQLITE_OK; } if( (flags&MEM_Term) && !(f&&MEM_Term) ){ NulTermify(pMem); } return SQLITE_OK; } /* ** Convert the given stack entity into a string that has been obtained ** from sqliteMalloc(). This is different from Stringify() above in that ** Stringify() will use the NBFS bytes of static string space if the string ** will fit but this routine always mallocs for space. ** Return non-zero if we run out of memory. */ #define Dynamicify(P) (((P)->flags & MEM_Dyn)==0 ? hardDynamicify(P):0) static int hardDynamicify(Mem *pStack){ int fg = pStack->flags; char *z; if( (fg & MEM_Str)==0 ){ hardStringify(pStack); } assert( (fg & MEM_Dyn)==0 ); z = sqliteMallocRaw( pStack->n ); if( z==0 ) return 1; memcpy(z, pStack->z, pStack->n); pStack->z = z; pStack->flags |= MEM_Dyn; return 0; } /* ** Advance the virtual machine to the next output row. ** ** The return vale will be either SQLITE_BUSY, SQLITE_DONE, ** SQLITE_ROW, SQLITE_ERROR, or SQLITE_MISUSE. ** ** SQLITE_BUSY means that the virtual machine attempted to open ** a locked database and there is no busy callback registered. ** Call sqlite3_step() again to retry the open. *pN is set to 0 ** and *pazColName and *pazValue are both set to NULL. ** ** SQLITE_DONE means that the virtual machine has finished ** executing. sqlite3_step() should not be called again on this ** virtual machine. *pN and *pazColName are set appropriately ** but *pazValue is set to NULL. ** ** SQLITE_ROW means that the virtual machine has generated another ** row of the result set. *pN is set to the number of columns in ** the row. *pazColName is set to the names of the columns followed ** by the column datatypes. *pazValue is set to the values of each ** column in the row. The value of the i-th column is (*pazValue)[i]. ** The name of the i-th column is (*pazColName)[i] and the datatype ** of the i-th column is (*pazColName)[i+*pN]. ** ** SQLITE_ERROR means that a run-time error (such as a constraint ** violation) has occurred. The details of the error will be returned ** by the next call to sqlite3_finalize(). sqlite3_step() should not ** be called again on the VM. ** ** SQLITE_MISUSE means that the this routine was called inappropriately. ** Perhaps it was called on a virtual machine that had already been ** finalized or on one that had previously returned SQLITE_ERROR or ** SQLITE_DONE. Or it could be the case the the same database connection ** is being used simulataneously by two or more threads. */ int sqlite3_step( sqlite_vm *pVm, /* The virtual machine to execute */ int *pN, /* OUT: Number of columns in result */ const char ***pazValue, /* OUT: Column data */ const char ***pazColName /* OUT: Column names and datatypes */ ){ sqlite3_stmt *pStmt = (sqlite3_stmt*)pVm; int rc; rc = sqlite3_step_new(pStmt); if( pazValue ) *pazValue = 0; if( pazColName ) *pazColName = 0; if( pN ) *pN = 0; if( rc==SQLITE_DONE || rc==SQLITE_ROW ){ int i; int cols = sqlite3_column_count(pStmt) * (pazColName?1:0); int vals = sqlite3_value_count(pStmt) * (pazValue?1:0); /* Temporary memory leak */ if( cols ) *pazColName = sqliteMalloc(sizeof(char *)*cols * 2); if( pN ) *pN = cols; for(i=0; i<cols; i++){ (*pazColName)[i] = sqlite3_column_name(pStmt, i); } for(i=cols; i<(2*cols); i++){ (*pazColName)[i] = sqlite3_column_decltype(pStmt, i-cols); } if( rc==SQLITE_ROW ){ if( vals ) *pazValue = sqliteMalloc(sizeof(char *)*vals); for(i=0; i<vals; i++){ (*pazValue)[i] = sqlite3_column_data(pStmt, i); } } } return rc; } /* ** Execute the statement pStmt, either until a row of data is ready, the ** statement is completely executed or an error occurs. */ int sqlite3_step_new(sqlite3_stmt *pStmt){ Vdbe *p = (Vdbe*)pStmt; sqlite *db; int rc; if( p->magic!=VDBE_MAGIC_RUN ){ return SQLITE_MISUSE; } db = p->db; if( sqlite3SafetyOn(db) ){ p->rc = SQLITE_MISUSE; return SQLITE_MISUSE; } if( p->explain ){ rc = sqlite3VdbeList(p); }else{ rc = sqlite3VdbeExec(p); } if( sqlite3SafetyOff(db) ){ rc = SQLITE_MISUSE; } sqlite3Error(p->db, rc, p->zErrMsg); return rc; } /* ** Return the number of columns in the result set for the statement pStmt. */ int sqlite3_column_count(sqlite3_stmt *pStmt){ Vdbe *pVm = (Vdbe *)pStmt; return pVm->nResColumn; } /* ** Return the number of values available from the current row of the ** currently executing statement pStmt. */ int sqlite3_value_count(sqlite3_stmt *pStmt){ Vdbe *pVm = (Vdbe *)pStmt; if( !pVm->resOnStack ) return 0; return pVm->nResColumn; } /* ** Return the value of the 'i'th column of the current row of the currently ** executing statement pStmt. */ const unsigned char *sqlite3_column_data(sqlite3_stmt *pStmt, int i){ int vals; Vdbe *pVm = (Vdbe *)pStmt; Mem *pVal; vals = sqlite3_value_count(pStmt); if( i>=vals || i<0 ){ sqlite3Error(pVm->db, SQLITE_RANGE, 0); return 0; } pVal = &pVm->pTos[(1-vals)+i]; if( pVal->flags&MEM_Null ){ return 0; } if( !pVal->flags&MEM_Blob ){ Stringify(pVal); SetEncoding(pVal, MEM_Utf8|MEM_Term); } return pVal->z; } /* ** Return the number of bytes of data that will be returned by the ** equivalent sqlite3_column_data() call. */ int sqlite3_column_bytes(sqlite3_stmt *pStmt, int i){ Vdbe *pVm = (Vdbe *)pStmt; int vals; vals = sqlite3_value_count(pStmt); if( i>=vals || i<0 ){ sqlite3Error(pVm->db, SQLITE_RANGE, 0); return 0; } if( sqlite3_column_data(pStmt, i) ){ return pVm->pTos[(1-vals)+i].n; } return 0; } /* ** Return the value of the 'i'th column of the current row of the currently ** executing statement pStmt. */ long long int sqlite3_column_int(sqlite3_stmt *pStmt, int i){ int vals; Vdbe *pVm = (Vdbe *)pStmt; Mem *pVal; vals = sqlite3_value_count(pStmt); if( i>=vals || i<0 ){ sqlite3Error(pVm->db, SQLITE_RANGE, 0); return 0; } pVal = &pVm->pTos[(1-vals)+i]; Integerify(pVal); return pVal->i; } /* ** Return the value of the 'i'th column of the current row of the currently ** executing statement pStmt. */ double sqlite3_column_float(sqlite3_stmt *pStmt, int i){ int vals; Vdbe *pVm = (Vdbe *)pStmt; Mem *pVal; vals = sqlite3_value_count(pStmt); if( i>=vals || i<0 ){ sqlite3Error(pVm->db, SQLITE_RANGE, 0); return 0; } pVal = &pVm->pTos[(1-vals)+i]; Realify(pVal); return pVal->r; } /* ** Return the name of the Nth column of the result set returned by SQL ** statement pStmt. */ const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){ Vdbe *p = (Vdbe *)pStmt; if( N>=sqlite3_column_count(pStmt) || N<0 ){ sqlite3Error(p->db, SQLITE_RANGE, 0); return 0; } return p->azColName[N]; } /* ** Return the type of the 'i'th column of the current row of the currently ** executing statement pStmt. */ int sqlite3_column_type(sqlite3_stmt *pStmt, int i){ int vals; Vdbe *p = (Vdbe *)pStmt; int f; vals = sqlite3_value_count(pStmt); if( i>=vals || i<0 ){ sqlite3Error(p->db, SQLITE_RANGE, 0); return 0; } f = p->pTos[(1-vals)+i].flags; if( f&MEM_Null ){ return SQLITE3_NULL; } if( f&MEM_Int ){ return SQLITE3_INTEGER; } if( f&MEM_Real ){ return SQLITE3_FLOAT; } if( f&MEM_Str ){ return SQLITE3_TEXT; } if( f&MEM_Blob ){ return SQLITE3_BLOB; } assert(0); } /* ** This routine returns either the column name, or declaration type (see ** sqlite3_column_decltype16() ) of the 'i'th column of the result set of ** SQL statement pStmt. The returned string is UTF-16 encoded. ** ** The declaration type is returned if 'decltype' is true, otherwise ** the column name. */ static const void *columnName16(sqlite3_stmt *pStmt, int i, int decltype){ Vdbe *p = (Vdbe *)pStmt; if( i>=sqlite3_column_count(pStmt) || i<0 ){ sqlite3Error(p->db, SQLITE_RANGE, 0); return 0; } if( decltype ){ i += p->nResColumn; } if( !p->azColName16 ){ p->azColName16 = (void **)sqliteMalloc(sizeof(void *)*p->nResColumn*2); if( !p->azColName16 ){ sqlite3Error(p->db, SQLITE_NOMEM, 0); return 0; } } if( !p->azColName16[i] ){ if( SQLITE3_BIGENDIAN ){ p->azColName16[i] = sqlite3utf8to16be(p->azColName[i], -1); } if( !p->azColName16[i] ){ sqlite3Error(p->db, SQLITE_NOMEM, 0); return 0; } } return p->azColName16[i]; } /* ** Return the name of the 'i'th column of the result set of SQL statement ** pStmt, encoded as UTF-16. */ const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int i){ return columnName16(pStmt, i, 0); } /* ** Return the column declaration type (if applicable) of the 'i'th column ** of the result set of SQL statement pStmt, encoded as UTF-8. */ const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int i){ Vdbe *p = (Vdbe *)pStmt; if( i>=sqlite3_column_count(pStmt) || i<0 ){ sqlite3Error(p->db, SQLITE_RANGE, 0); return 0; } return p->azColName[i+p->nResColumn]; } /* ** Return the column declaration type (if applicable) of the 'i'th column ** of the result set of SQL statement pStmt, encoded as UTF-16. */ const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int i){ return columnName16(pStmt, i, 1); } /* ** Insert a new aggregate element and make it the element that ** has focus. ** ** Return 0 on success and 1 if memory is exhausted. */ static int AggInsert(Agg *p, char *zKey, int nKey){ AggElem *pElem, *pOld; int i; Mem *pMem; pElem = sqliteMalloc( sizeof(AggElem) + nKey + (p->nMem-1)*sizeof(pElem->aMem[0]) ); if( pElem==0 ) return 1; pElem->zKey = (char*)&pElem->aMem[p->nMem]; memcpy(pElem->zKey, zKey, nKey); pElem->nKey = nKey; pOld = sqlite3HashInsert(&p->hash, pElem->zKey, pElem->nKey, pElem); if( pOld!=0 ){ assert( pOld==pElem ); /* Malloc failed on insert */ sqliteFree(pOld); return 0; } for(i=0, pMem=pElem->aMem; i<p->nMem; i++, pMem++){ pMem->flags = MEM_Null; } p->pCurrent = pElem; return 0; } /* ** Get the AggElem currently in focus */ #define AggInFocus(P) ((P).pCurrent ? (P).pCurrent : _AggInFocus(&(P))) static AggElem *_AggInFocus(Agg *p){ HashElem *pElem = sqliteHashFirst(&p->hash); if( pElem==0 ){ AggInsert(p,"",1); pElem = sqliteHashFirst(&p->hash); } return pElem ? sqliteHashData(pElem) : 0; } /* ** An ephemeral string value (signified by the MEM_Ephem flag) contains ** a pointer to a dynamically allocated string where some other entity ** is responsible for deallocating that string. Because the stack entry ** does not control the string, it might be deleted without the stack ** entry knowing it. ** ** This routine converts an ephemeral string into a dynamically allocated ** string that the stack entry itself controls. In other words, it ** converts an MEM_Ephem string into an MEM_Dyn string. */ #define Deephemeralize(P) \ if( ((P)->flags&MEM_Ephem)!=0 && hardDeephem(P) ){ goto no_mem;} static int hardDeephem(Mem *pStack){ char *z; assert( (pStack->flags & MEM_Ephem)!=0 ); z = sqliteMallocRaw( pStack->n ); if( z==0 ) return 1; memcpy(z, pStack->z, pStack->n); pStack->z = z; pStack->flags &= ~MEM_Ephem; pStack->flags |= MEM_Dyn; return 0; } /* ** Pop the stack N times. */ static void popStack(Mem **ppTos, int N){ Mem *pTos = *ppTos; while( N>0 ){ N--; Release(pTos); pTos--; } *ppTos = pTos; } /* ** The parameters are pointers to the head of two sorted lists ** of Sorter structures. Merge these two lists together and return ** a single sorted list. This routine forms the core of the merge-sort ** algorithm. ** |
︙ | ︙ | |||
645 646 647 648 649 650 651 652 653 654 655 656 657 658 | assert( p->explain==0 ); if( sqlite3_malloc_failed ) goto no_mem; pTos = p->pTos; if( p->popStack ){ popStack(&pTos, p->popStack); p->popStack = 0; } CHECK_FOR_INTERRUPT; for(pc=p->pc; rc==SQLITE_OK; pc++){ assert( pc>=0 && pc<p->nOp ); assert( pTos<=&p->aStack[pc] ); #ifdef VDBE_PROFILE origPc = pc; start = hwtime(); | > | 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 | assert( p->explain==0 ); if( sqlite3_malloc_failed ) goto no_mem; pTos = p->pTos; if( p->popStack ){ popStack(&pTos, p->popStack); p->popStack = 0; } p->resOnStack = 0; CHECK_FOR_INTERRUPT; for(pc=p->pc; rc==SQLITE_OK; pc++){ assert( pc>=0 && pc<p->nOp ); assert( pTos<=&p->aStack[pc] ); #ifdef VDBE_PROFILE origPc = pc; start = hwtime(); |
︙ | ︙ | |||
820 821 822 823 824 825 826 | */ case OP_Integer: { pTos++; pTos->i = pOp->p1; pTos->flags = MEM_Int; if( pOp->p3 ){ pTos->z = pOp->p3; | | | 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 | */ case OP_Integer: { pTos++; pTos->i = pOp->p1; pTos->flags = MEM_Int; if( pOp->p3 ){ pTos->z = pOp->p3; pTos->flags |= MEM_Utf8 | MEM_Str | MEM_Static; pTos->n = strlen(pOp->p3)+1; if( pTos->i==0 ){ sqlite3GetInt64(pTos->z, &pTos->i); } } break; } |
︙ | ︙ | |||
842 843 844 845 846 847 848 | char *z = pOp->p3; pTos++; if( z==0 ){ pTos->flags = MEM_Null; }else{ pTos->z = z; pTos->n = strlen(z) + 1; | | | | 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 | char *z = pOp->p3; pTos++; if( z==0 ){ pTos->flags = MEM_Null; }else{ pTos->z = z; pTos->n = strlen(z) + 1; pTos->flags = MEM_Str | MEM_Static | MEM_Utf8 | MEM_Term; } break; } /* Opcode: Real * * P3 ** ** The string value P3 is converted to a real and pushed on to the stack. */ case OP_Real: { char *z = pOp->p3; assert( z ); assert( sqlite3IsNumber(z, 0) ); pTos++; pTos->r = sqlite3AtoF(z, 0); pTos->z = z; pTos->n = strlen(z)+1; pTos->flags = MEM_Real|MEM_Str|MEM_Static|MEM_Utf8; break; } /* Opcode: Variable P1 * * ** ** Push the value of variable P1 onto the stack. A variable is ** an unknown in the original SQL string as handed to sqlite3_compile(). |
︙ | ︙ | |||
955 956 957 958 959 960 961 | ** Also see the Pull instruction. */ case OP_Dup: { Mem *pFrom = &pTos[-pOp->p1]; assert( pFrom<=pTos && pFrom>=p->aStack ); pTos++; memcpy(pTos, pFrom, sizeof(*pFrom)-NBFS); | | | 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 | ** Also see the Pull instruction. */ case OP_Dup: { Mem *pFrom = &pTos[-pOp->p1]; assert( pFrom<=pTos && pFrom>=p->aStack ); pTos++; memcpy(pTos, pFrom, sizeof(*pFrom)-NBFS); if( pTos->flags & (MEM_Str|MEM_Blob) ){ if( pOp->p2 && (pTos->flags & (MEM_Dyn|MEM_Ephem)) ){ pTos->flags &= ~MEM_Dyn; pTos->flags |= MEM_Ephem; }else if( pTos->flags & MEM_Short ){ memcpy(pTos->zShort, pFrom->zShort, pTos->n); pTos->z = pTos->zShort; }else if( (pTos->flags & MEM_Static)==0 ){ |
︙ | ︙ | |||
995 996 997 998 999 1000 1001 | ts = *pFrom; Deephemeralize(pTos); for(i=0; i<pOp->p1; i++, pFrom++){ Deephemeralize(&pFrom[1]); *pFrom = pFrom[1]; assert( (pFrom->flags & MEM_Ephem)==0 ); if( pFrom->flags & MEM_Short ){ | | | | 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 | ts = *pFrom; Deephemeralize(pTos); for(i=0; i<pOp->p1; i++, pFrom++){ Deephemeralize(&pFrom[1]); *pFrom = pFrom[1]; assert( (pFrom->flags & MEM_Ephem)==0 ); if( pFrom->flags & MEM_Short ){ assert( pFrom->flags & (MEM_Str|MEM_Blob) ); assert( pFrom->z==pFrom[1].zShort ); pFrom->z = pFrom->zShort; } } *pTos = ts; if( pTos->flags & MEM_Short ){ assert( pTos->flags & (MEM_Str|MEM_Blob) ); assert( pTos->z==pTos[-pOp->p1].zShort ); pTos->z = pTos->zShort; } break; } /* Opcode: Push P1 * * |
︙ | ︙ | |||
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 | if( pCol->flags & MEM_Null ){ azArgv[i] = 0; }else{ Stringify(pCol); azArgv[i] = pCol->z; } } azArgv[i] = 0; p->nCallback++; p->azResColumn = azArgv; assert( p->nResColumn==pOp->p1 ); p->popStack = pOp->p1; p->pc = pc + 1; p->pTos = pTos; | > > | 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 | if( pCol->flags & MEM_Null ){ azArgv[i] = 0; }else{ Stringify(pCol); azArgv[i] = pCol->z; } } p->resOnStack = 1; azArgv[i] = 0; p->nCallback++; p->azResColumn = azArgv; assert( p->nResColumn==pOp->p1 ); p->popStack = pOp->p1; p->pc = pc + 1; p->pTos = pTos; |
︙ | ︙ | |||
1144 1145 1146 1147 1148 1149 1150 | } zNew[j] = 0; if( pOp->p2==0 ){ popStack(&pTos, nField); } pTos++; pTos->n = nByte; | | | 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 | } zNew[j] = 0; if( pOp->p2==0 ){ popStack(&pTos, nField); } pTos++; pTos->n = nByte; pTos->flags = MEM_Str|MEM_Dyn|MEM_Utf8; pTos->z = zNew; break; } /* Opcode: Add * * * ** ** Pop the top two elements from the stack, add them together, |
︙ | ︙ | |||
1829 1830 1831 1832 1833 1834 1835 | {MEM_Int, "INTEGER"}, {MEM_Real, "REAL"}, {MEM_Str, "TEXT"}, {MEM_Blob, "BLOB"} }; Release(pTos); | | | 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 | {MEM_Int, "INTEGER"}, {MEM_Real, "REAL"}, {MEM_Str, "TEXT"}, {MEM_Blob, "BLOB"} }; Release(pTos); pTos->flags = MEM_Str|MEM_Static|MEM_Utf8; for(i=0; i<5; i++){ if( classes[i].mask&flags ){ pTos->z = classes[i].zClass; break; } } |
︙ | ︙ | |||
1902 1903 1904 1905 1906 1907 1908 | if( i<0 ){ char *zRec; /* Pointer to record data from the stack. */ int off = 0; /* Offset in zRec to start of the columns data. */ int off2 = 0; /* Offset in zRec to the next serial type to read */ u64 colType; /* The serial type of the value being read. */ assert( &pTos[i-1]>=p->aStack ); | | | 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 | if( i<0 ){ char *zRec; /* Pointer to record data from the stack. */ int off = 0; /* Offset in zRec to start of the columns data. */ int off2 = 0; /* Offset in zRec to the next serial type to read */ u64 colType; /* The serial type of the value being read. */ assert( &pTos[i-1]>=p->aStack ); assert( pTos[i].flags & MEM_Blob ); assert( pTos[i-1].flags & MEM_Int ); if( pTos[i].n==0 ){ pTos->flags = MEM_Null; break; } |
︙ | ︙ | |||
2144 2145 2146 2147 2148 2149 2150 | } /* Pop nField entries from the stack and push the new entry on */ popStack(&pTos, nField); pTos++; pTos->n = nBytes; pTos->z = zNewRecord; | | | 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 | } /* Pop nField entries from the stack and push the new entry on */ popStack(&pTos, nField); pTos++; pTos->n = nBytes; pTos->z = zNewRecord; pTos->flags = MEM_Blob | MEM_Dyn; break; } /* Opcode: MakeKey P1 P2 P3 ** ** Convert the top P1 entries of the stack into a single entry suitable |
︙ | ︙ | |||
2272 2273 2274 2275 2276 2277 2278 | assert( offset==nByte ); /* Pop the consumed values off the stack and push on the new key. */ if( addRowid||(pOp->p2==0) ){ popStack(&pTos, nField+addRowid); } pTos++; | | | 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 | assert( offset==nByte ); /* Pop the consumed values off the stack and push on the new key. */ if( addRowid||(pOp->p2==0) ){ popStack(&pTos, nField+addRowid); } pTos++; pTos->flags = MEM_Blob|MEM_Dyn; /* TODO: should eventually be MEM_Blob */ pTos->z = zKey; pTos->n = nByte; /* If P2 is non-zero, and if the key contains a NULL value, and if this ** was an OP_MakeIdxKey instruction, not OP_MakeKey, jump to P2. */ if( pOp->p2 && containsNull && addRowid ){ |
︙ | ︙ | |||
3197 3198 3199 3200 3201 3202 3203 | pC->nextRowidValid = 0; } } if( pTos->flags & MEM_Null ){ pTos->z = 0; pTos->n = 0; }else{ | | | 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 | pC->nextRowidValid = 0; } } if( pTos->flags & MEM_Null ){ pTos->z = 0; pTos->n = 0; }else{ assert( pTos->flags & (MEM_Blob|MEM_Str) ); } if( pC->pseudoTable ){ /* PutStrKey does not work for pseudo-tables. ** The following assert makes sure we are not trying to use ** PutStrKey on a pseudo-table */ assert( pOp->opcode==OP_PutIntKey ); |
︙ | ︙ | |||
3337 3338 3339 3340 3341 3342 3343 | sqlite3BtreeKeySize(pCrsr, &n64); n = n64; }else{ sqlite3BtreeDataSize(pCrsr, &n); } pTos->n = n; if( n<=NBFS ){ | | | | | 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 | sqlite3BtreeKeySize(pCrsr, &n64); n = n64; }else{ sqlite3BtreeDataSize(pCrsr, &n); } pTos->n = n; if( n<=NBFS ){ pTos->flags = MEM_Blob | MEM_Short; pTos->z = pTos->zShort; }else{ char *z = sqliteMallocRaw( n ); if( z==0 ) goto no_mem; pTos->flags = MEM_Blob | MEM_Dyn; pTos->z = z; } if( pC->keyAsData || pOp->opcode==OP_RowKey ){ sqlite3BtreeKey(pCrsr, 0, n, pTos->z); }else{ sqlite3BtreeData(pCrsr, 0, n, pTos->z); } }else if( pC->pseudoTable ){ pTos->n = pC->nData; pTos->z = pC->pData; pTos->flags = MEM_Blob|MEM_Ephem; }else{ pTos->flags = MEM_Null; } break; } /* Opcode: Recno P1 * * |
︙ | ︙ | |||
3477 3478 3479 3480 3481 3482 3483 | if( amt<=0 ){ rc = SQLITE_CORRUPT; goto abort_due_to_error; } if( amt>NBFS ){ z = sqliteMallocRaw( amt ); if( z==0 ) goto no_mem; | | | | 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 | if( amt<=0 ){ rc = SQLITE_CORRUPT; goto abort_due_to_error; } if( amt>NBFS ){ z = sqliteMallocRaw( amt ); if( z==0 ) goto no_mem; pTos->flags = MEM_Blob | MEM_Dyn; }else{ z = pTos->zShort; pTos->flags = MEM_Blob | MEM_Short; } sqlite3BtreeKey(pCrsr, 0, amt, z); pTos->z = z; pTos->n = amt; } break; } |
︙ | ︙ | |||
3630 3631 3632 3633 3634 3635 3636 | */ case OP_IdxPut: { int i = pOp->p1; Cursor *pC; BtCursor *pCrsr; assert( pTos>=p->aStack ); assert( i>=0 && i<p->nCursor ); | | | 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 | */ case OP_IdxPut: { int i = pOp->p1; Cursor *pC; BtCursor *pCrsr; assert( pTos>=p->aStack ); assert( i>=0 && i<p->nCursor ); assert( pTos->flags & MEM_Blob ); if( (pCrsr = (pC = p->apCsr[i])->pCursor)!=0 ){ int nKey = pTos->n; const char *zKey = pTos->z; if( pOp->p2 ){ int res; int len; u64 n; |
︙ | ︙ | |||
3686 3687 3688 3689 3690 3691 3692 | ** This opcode removes that entry from the index. */ case OP_IdxDelete: { int i = pOp->p1; Cursor *pC; BtCursor *pCrsr; assert( pTos>=p->aStack ); | | | 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 | ** This opcode removes that entry from the index. */ case OP_IdxDelete: { int i = pOp->p1; Cursor *pC; BtCursor *pCrsr; assert( pTos>=p->aStack ); assert( pTos->flags & MEM_Blob ); assert( i>=0 && i<p->nCursor ); if( (pCrsr = (pC = p->apCsr[i])->pCursor)!=0 ){ int rx, res; rx = sqlite3BtreeMoveto(pCrsr, pTos->z, pTos->n, &res); if( rx==SQLITE_OK && res==0 ){ rc = sqlite3BtreeDelete(pCrsr); } |
︙ | ︙ | |||
3853 3854 3855 3856 3857 3858 3859 | */ case OP_IdxIsNull: { int i = pOp->p1; int k, n; const char *z; assert( pTos>=p->aStack ); | | | 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 | */ case OP_IdxIsNull: { int i = pOp->p1; int k, n; const char *z; assert( pTos>=p->aStack ); assert( pTos->flags & MEM_Blob ); z = pTos->z; n = pTos->n; for(k=0; k<n && i>0; i--){ u64 serial_type; k += sqlite3GetVarint(&z[k], &serial_type); if( serial_type==6 ){ /* Serial type 6 is a NULL */ pc = pOp->p2-1; |
︙ | ︙ | |||
3998 3999 4000 4001 4002 4003 4004 | sqlite3HashClear(&pSet->hash); pSet->prev = 0; z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p2].pBt, aRoot, nRoot); if( z==0 || z[0]==0 ){ if( z ) sqliteFree(z); pTos->z = "ok"; pTos->n = 3; | | | | 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 | sqlite3HashClear(&pSet->hash); pSet->prev = 0; z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p2].pBt, aRoot, nRoot); if( z==0 || z[0]==0 ){ if( z ) sqliteFree(z); pTos->z = "ok"; pTos->n = 3; pTos->flags = MEM_Utf8 | MEM_Str | MEM_Static; }else{ pTos->z = z; pTos->n = strlen(z) + 1; pTos->flags = MEM_Utf8 | MEM_Str | MEM_Dyn; } sqliteFree(aRoot); break; } /* Opcode: ListWrite * * * ** |
︙ | ︙ | |||
4242 4243 4244 4245 4246 4247 4248 | Sorter *pSorter = p->pSort; CHECK_FOR_INTERRUPT; if( pSorter!=0 ){ p->pSort = pSorter->pNext; pTos++; pTos->z = pSorter->pData; pTos->n = pSorter->nData; | | | 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 | Sorter *pSorter = p->pSort; CHECK_FOR_INTERRUPT; if( pSorter!=0 ){ p->pSort = pSorter->pNext; pTos++; pTos->z = pSorter->pData; pTos->n = pSorter->nData; pTos->flags = MEM_Blob|MEM_Dyn; sqliteFree(pSorter->zKey); sqliteFree(pSorter); }else{ pc = pOp->p2 - 1; } break; } |
︙ | ︙ | |||
4421 4422 4423 4424 4425 4426 4427 | }else{ z = 0; } pTos++; if( z ){ pTos->n = strlen(z) + 1; pTos->z = z; | | | 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 | }else{ z = 0; } pTos++; if( z ){ pTos->n = strlen(z) + 1; pTos->z = z; pTos->flags = MEM_Utf8 | MEM_Str | MEM_Ephem; }else{ pTos->flags = MEM_Null; } break; } /* Opcode: MemStore P1 P2 * |
︙ | ︙ | |||
4497 4498 4499 4500 4501 4502 4503 | ** value pushed onto the stack will change too. */ case OP_MemLoad: { int i = pOp->p1; assert( i>=0 && i<p->nMem ); pTos++; memcpy(pTos, &p->aMem[i], sizeof(pTos[0])-NBFS);; | | | 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 | ** value pushed onto the stack will change too. */ case OP_MemLoad: { int i = pOp->p1; assert( i>=0 && i<p->nMem ); pTos++; memcpy(pTos, &p->aMem[i], sizeof(pTos[0])-NBFS);; if( pTos->flags & (MEM_Str|MEM_Blob) ){ pTos->flags |= MEM_Ephem; pTos->flags &= ~(MEM_Dyn|MEM_Static|MEM_Short); } break; } /* Opcode: MemIncr P1 P2 * |
︙ | ︙ | |||
4678 4679 4680 4681 4682 4683 4684 | Mem *pMem; int i = pOp->p2; if( pFocus==0 ) goto no_mem; assert( i>=0 && i<p->agg.nMem ); pTos++; pMem = &pFocus->aMem[i]; *pTos = *pMem; | | | 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 | Mem *pMem; int i = pOp->p2; if( pFocus==0 ) goto no_mem; assert( i>=0 && i<p->agg.nMem ); pTos++; pMem = &pFocus->aMem[i]; *pTos = *pMem; if( pTos->flags & (MEM_Str|MEM_Blob) ){ pTos->flags &= ~(MEM_Dyn|MEM_Static|MEM_Short); pTos->flags |= MEM_Ephem; } break; } /* Opcode: AggNext * P2 * |
︙ | ︙ | |||
4843 4844 4845 4846 4847 4848 4849 | }else{ pc = pOp->p2 - 1; } } pTos++; pTos->z = sqliteHashKey(pSet->prev); pTos->n = sqliteHashKeysize(pSet->prev); | | | 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 | }else{ pc = pOp->p2 - 1; } } pTos++; pTos->z = sqliteHashKey(pSet->prev); pTos->n = sqliteHashKeysize(pSet->prev); pTos->flags = MEM_Utf8 | MEM_Str | MEM_Ephem; break; } /* Opcode: Vacuum * * * ** ** Vacuum the entire database. This opcode will cause other virtual ** machines to be created and run. It may not be called from within |
︙ | ︙ | |||
4929 4930 4931 4932 4933 4934 4935 | fprintf(p->trace, " NULL"); }else if( (pTos[i].flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){ fprintf(p->trace, " si:%lld", pTos[i].i); }else if( pTos[i].flags & MEM_Int ){ fprintf(p->trace, " i:%lld", pTos[i].i); }else if( pTos[i].flags & MEM_Real ){ fprintf(p->trace, " r:%g", pTos[i].r); | | | 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 | fprintf(p->trace, " NULL"); }else if( (pTos[i].flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){ fprintf(p->trace, " si:%lld", pTos[i].i); }else if( pTos[i].flags & MEM_Int ){ fprintf(p->trace, " i:%lld", pTos[i].i); }else if( pTos[i].flags & MEM_Real ){ fprintf(p->trace, " r:%g", pTos[i].r); }else if( pTos[i].flags & (MEM_Str|MEM_Blob) ){ int j, k; char zBuf[100]; zBuf[0] = ' '; if( pTos[i].flags & MEM_Dyn ){ zBuf[1] = 'z'; assert( (pTos[i].flags & (MEM_Static|MEM_Ephem))==0 ); }else if( pTos[i].flags & MEM_Static ){ |
︙ | ︙ |
Changes to src/vdbe.h.
︙ | ︙ | |||
11 12 13 14 15 16 17 | ************************************************************************* ** Header file for the Virtual DataBase Engine (VDBE) ** ** This header defines the interface to the virtual database engine ** or VDBE. The VDBE implements an abstract machine that runs a ** simple program to access and modify the underlying database. ** | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ************************************************************************* ** Header file for the Virtual DataBase Engine (VDBE) ** ** This header defines the interface to the virtual database engine ** or VDBE. The VDBE implements an abstract machine that runs a ** simple program to access and modify the underlying database. ** ** $Id: vdbe.h,v 1.81 2004/05/21 10:08:55 danielk1977 Exp $ */ #ifndef _SQLITE_VDBE_H_ #define _SQLITE_VDBE_H_ #include <stdio.h> /* ** A single VDBE is an opaque structure named "Vdbe". Only routines |
︙ | ︙ | |||
109 110 111 112 113 114 115 | void sqlite3VdbeChangeP3(Vdbe*, int addr, const char *zP1, int N); void sqlite3VdbeDequoteP3(Vdbe*, int addr); int sqlite3VdbeFindOp(Vdbe*, int, int, int); VdbeOp *sqlite3VdbeGetOp(Vdbe*, int); int sqlite3VdbeMakeLabel(Vdbe*); void sqlite3VdbeDelete(Vdbe*); void sqlite3VdbeMakeReady(Vdbe*,int,int); | < < | 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | void sqlite3VdbeChangeP3(Vdbe*, int addr, const char *zP1, int N); void sqlite3VdbeDequoteP3(Vdbe*, int addr); int sqlite3VdbeFindOp(Vdbe*, int, int, int); VdbeOp *sqlite3VdbeGetOp(Vdbe*, int); int sqlite3VdbeMakeLabel(Vdbe*); void sqlite3VdbeDelete(Vdbe*); void sqlite3VdbeMakeReady(Vdbe*,int,int); int sqlite3VdbeFinalize(Vdbe*,char**); void sqlite3VdbeResolveLabel(Vdbe*, int); int sqlite3VdbeCurrentAddr(Vdbe*); void sqlite3VdbeTrace(Vdbe*,FILE*); void sqlite3VdbeCompressSpace(Vdbe*,int); int sqlite3VdbeReset(Vdbe*,char **); int sqliteVdbeSetVariables(Vdbe*,int,const char**); |
︙ | ︙ |
Changes to src/vdbeInt.h.
︙ | ︙ | |||
265 266 267 268 269 270 271 272 273 274 275 276 277 278 | int nLabel; /* Number of labels used */ int nLabelAlloc; /* Number of slots allocated in aLabel[] */ int *aLabel; /* Space to hold the labels */ Mem *aStack; /* The operand stack, except string values */ Mem *pTos; /* Top entry in the operand stack */ char **zArgv; /* Text values used by the callback */ char **azColName; /* Becomes the 4th parameter to callbacks */ int nCursor; /* Number of slots in apCsr[] */ Cursor **apCsr; /* One element of this array for each open cursor */ Sorter *pSort; /* A linked list of objects to be sorted */ FILE *pFile; /* At most one open file handler */ int nField; /* Number of file fields */ char **azField; /* Data for each file field */ int nVar; /* Number of entries in apVar[] */ | > | 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | int nLabel; /* Number of labels used */ int nLabelAlloc; /* Number of slots allocated in aLabel[] */ int *aLabel; /* Space to hold the labels */ Mem *aStack; /* The operand stack, except string values */ Mem *pTos; /* Top entry in the operand stack */ char **zArgv; /* Text values used by the callback */ char **azColName; /* Becomes the 4th parameter to callbacks */ void **azColName16; /* UTF-16 encoded equivalent of azColName */ int nCursor; /* Number of slots in apCsr[] */ Cursor **apCsr; /* One element of this array for each open cursor */ Sorter *pSort; /* A linked list of objects to be sorted */ FILE *pFile; /* At most one open file handler */ int nField; /* Number of file fields */ char **azField; /* Data for each file field */ int nVar; /* Number of entries in apVar[] */ |
︙ | ︙ | |||
297 298 299 300 301 302 303 304 305 306 307 308 309 310 | int errorAction; /* Recovery action to do in case of an error */ int undoTransOnError; /* If error, either ROLLBACK or COMMIT */ int inTempTrans; /* True if temp database is transactioned */ int returnStack[100]; /* Return address stack for OP_Gosub & OP_Return */ int returnDepth; /* Next unused element in returnStack[] */ int nResColumn; /* Number of columns in one row of the result set */ char **azResColumn; /* Values for one row of result */ int popStack; /* Pop the stack this much on entry to VdbeExec() */ char *zErrMsg; /* Error message written here */ u8 explain; /* True if EXPLAIN present on SQL command */ }; /* ** The following are allowed values for Vdbe.magic | > | 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | int errorAction; /* Recovery action to do in case of an error */ int undoTransOnError; /* If error, either ROLLBACK or COMMIT */ int inTempTrans; /* True if temp database is transactioned */ int returnStack[100]; /* Return address stack for OP_Gosub & OP_Return */ int returnDepth; /* Next unused element in returnStack[] */ int nResColumn; /* Number of columns in one row of the result set */ char **azResColumn; /* Values for one row of result */ u8 resOnStack; /* True if there are result values on the stack */ int popStack; /* Pop the stack this much on entry to VdbeExec() */ char *zErrMsg; /* Error message written here */ u8 explain; /* True if EXPLAIN present on SQL command */ }; /* ** The following are allowed values for Vdbe.magic |
︙ | ︙ | |||
333 334 335 336 337 338 339 | int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *); int sqlite3VdbeIdxKeyCompare(Cursor*, int , const unsigned char*, int*); int sqlite3VdbeIdxRowid(BtCursor *, i64 *); int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*); int sqlite3VdbeKeyCompare(void*,int,const void*,int, const void*); int sqlite3VdbeRowCompare(void*,int,const void*,int, const void*); | > > | 335 336 337 338 339 340 341 342 343 | int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *); int sqlite3VdbeIdxKeyCompare(Cursor*, int , const unsigned char*, int*); int sqlite3VdbeIdxRowid(BtCursor *, i64 *); int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*); int sqlite3VdbeKeyCompare(void*,int,const void*,int, const void*); int sqlite3VdbeRowCompare(void*,int,const void*,int, const void*); int sqlite3VdbeExec(Vdbe*); int sqlite3VdbeList(Vdbe*); |
Changes to src/vdbeaux.c.
︙ | ︙ | |||
456 457 458 459 460 461 462 | p->s.z = 0; p->s.n = 0; }else{ if( n<0 ) n = strlen(zResult); if( n<NBFS-1 ){ memcpy(p->s.zShort, zResult, n); p->s.zShort[n] = 0; | | | | 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | p->s.z = 0; p->s.n = 0; }else{ if( n<0 ) n = strlen(zResult); if( n<NBFS-1 ){ memcpy(p->s.zShort, zResult, n); p->s.zShort[n] = 0; p->s.flags = MEM_Utf8 | MEM_Str | MEM_Short; p->s.z = p->s.zShort; }else{ p->s.z = sqliteMallocRaw( n+1 ); if( p->s.z ){ memcpy(p->s.z, zResult, n); p->s.z[n] = 0; } p->s.flags = MEM_Utf8 | MEM_Str | MEM_Dyn; } p->s.n = n+1; } return p->s.z; } void sqlite3_set_result_int(sqlite_func *p, int iResult){ assert( !p->isStep ); |
︙ | ︙ | |||
933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 | */ int sqlite3VdbeReset(Vdbe *p, char **pzErrMsg){ sqlite *db = p->db; int i; if( p->magic!=VDBE_MAGIC_RUN && p->magic!=VDBE_MAGIC_HALT ){ sqlite3SetString(pzErrMsg, sqlite3_error_string(SQLITE_MISUSE), (char*)0); return SQLITE_MISUSE; } if( p->zErrMsg ){ if( pzErrMsg && *pzErrMsg==0 ){ *pzErrMsg = p->zErrMsg; }else{ sqliteFree(p->zErrMsg); } p->zErrMsg = 0; }else if( p->rc ){ sqlite3SetString(pzErrMsg, sqlite3_error_string(p->rc), (char*)0); } Cleanup(p); if( p->rc!=SQLITE_OK ){ switch( p->errorAction ){ case OE_Abort: { if( !p->undoTransOnError ){ for(i=0; i<db->nDb; i++){ | > > > > > | 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 | */ int sqlite3VdbeReset(Vdbe *p, char **pzErrMsg){ sqlite *db = p->db; int i; if( p->magic!=VDBE_MAGIC_RUN && p->magic!=VDBE_MAGIC_HALT ){ sqlite3SetString(pzErrMsg, sqlite3_error_string(SQLITE_MISUSE), (char*)0); sqlite3Error(p->db, SQLITE_MISUSE, sqlite3_error_string(SQLITE_MISUSE),0); return SQLITE_MISUSE; } if( p->zErrMsg ){ sqlite3Error(p->db, p->rc, "%s", p->zErrMsg, 0); if( pzErrMsg && *pzErrMsg==0 ){ *pzErrMsg = p->zErrMsg; }else{ sqliteFree(p->zErrMsg); } p->zErrMsg = 0; }else if( p->rc ){ sqlite3SetString(pzErrMsg, sqlite3_error_string(p->rc), (char*)0); sqlite3Error(p->db, p->rc, "%s", sqlite3_error_string(p->rc) , 0); }else{ sqlite3Error(p->db, SQLITE_OK, 0); } Cleanup(p); if( p->rc!=SQLITE_OK ){ switch( p->errorAction ){ case OE_Abort: { if( !p->undoTransOnError ){ for(i=0; i<db->nDb; i++){ |
︙ | ︙ | |||
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 | */ int sqlite3VdbeFinalize(Vdbe *p, char **pzErrMsg){ int rc; sqlite *db; if( p->magic!=VDBE_MAGIC_RUN && p->magic!=VDBE_MAGIC_HALT ){ sqlite3SetString(pzErrMsg, sqlite3_error_string(SQLITE_MISUSE), (char*)0); return SQLITE_MISUSE; } db = p->db; rc = sqlite3VdbeReset(p, pzErrMsg); sqlite3VdbeDelete(p); if( db->want_to_close && db->pVdbe==0 ){ sqlite3_close(db); | > > > | 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 | */ int sqlite3VdbeFinalize(Vdbe *p, char **pzErrMsg){ int rc; sqlite *db; if( p->magic!=VDBE_MAGIC_RUN && p->magic!=VDBE_MAGIC_HALT ){ sqlite3SetString(pzErrMsg, sqlite3_error_string(SQLITE_MISUSE), (char*)0); if( p->magic==VDBE_MAGIC_INIT ){ sqlite3Error(p->db, SQLITE_MISUSE, sqlite3_error_string(SQLITE_MISUSE),0); } return SQLITE_MISUSE; } db = p->db; rc = sqlite3VdbeReset(p, pzErrMsg); sqlite3VdbeDelete(p); if( db->want_to_close && db->pVdbe==0 ){ sqlite3_close(db); |
︙ | ︙ | |||
1486 1487 1488 1489 1490 1491 1492 | return 8; } /* String or blob */ assert( serial_type>=12 ); len = sqlite3VdbeSerialTypeLen(serial_type); if( serial_type&0x01 ){ | | | 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 | return 8; } /* String or blob */ assert( serial_type>=12 ); len = sqlite3VdbeSerialTypeLen(serial_type); if( serial_type&0x01 ){ pMem->flags = MEM_Str|MEM_Utf8; pMem->n = len+1; }else{ pMem->flags = MEM_Blob; pMem->n = len; } if( (pMem->n)>NBFS ){ |
︙ | ︙ | |||
1865 1866 1867 1868 1869 1870 1871 | *res = sqlite3VdbeKeyCompare(pC->pKeyInfo, len, pCellKey, nKey, pKey); if( freeCellKey ){ sqliteFree(pCellKey); } return SQLITE_OK; } | > > > | 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 | *res = sqlite3VdbeKeyCompare(pC->pKeyInfo, len, pCellKey, nKey, pKey); if( freeCellKey ){ sqliteFree(pCellKey); } return SQLITE_OK; } |
Changes to test/attach2.test.
︙ | ︙ | |||
8 9 10 11 12 13 14 | # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this script is testing the ATTACH and DETACH commands # and related functionality. # | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this script is testing the ATTACH and DETACH commands # and related functionality. # # $Id: attach2.test,v 1.9 2004/05/21 10:08:55 danielk1977 Exp $ # set testdir [file dirname $argv0] source $testdir/tester.tcl # Ticket #354 |
︙ | ︙ | |||
122 123 124 125 126 127 128 | # Ticket #574: Make sure it works usingi the non-callback API # do_test attach2-3.1 { db close set DB [sqlite db test.db] set rc [catch {sqlite3_prepare $DB "ATTACH 'test2.db' AS t2" -1 TAIL} VM] if {$rc} {lappend rc $VM} | | | | 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | # Ticket #574: Make sure it works usingi the non-callback API # do_test attach2-3.1 { db close set DB [sqlite db test.db] set rc [catch {sqlite3_prepare $DB "ATTACH 'test2.db' AS t2" -1 TAIL} VM] if {$rc} {lappend rc $VM} sqlite3_finalize $VM set rc } {0} do_test attach2-3.2 { set rc [catch {sqlite3_prepare $DB "DETACH t2" -1 TAIL} VM] if {$rc} {lappend rc $VM} sqlite3_finalize $VM set rc } {0} db close for {set i 2} {$i<=15} {incr i} { catch {db$i close} } file delete -force test2.db finish_test |
Changes to test/bind.test.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # 2003 September 6 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this script testing the sqlite_bind API. # | | | | | | | | | | | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | # 2003 September 6 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this script testing the sqlite_bind API. # # $Id: bind.test,v 1.6 2004/05/21 10:08:55 danielk1977 Exp $ # set testdir [file dirname $argv0] source $testdir/tester.tcl do_test bind-1.1 { db close set DB [sqlite db test.db] execsql {CREATE TABLE t1(a,b,c)} set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(?,?,?)} -1 TAIL] set TAIL } {} do_test bind-1.2 { sqlite_step $VM N VALUES COLNAMES } {SQLITE_DONE} do_test bind-1.3 { execsql {SELECT rowid, * FROM t1} } {1 {} {} {}} do_test bind-1.4 { sqlite3_reset $VM sqlite_bind $VM 1 {test value 1} normal sqlite_step $VM N VALUES COLNAMES } SQLITE_DONE do_test bind-1.5 { execsql {SELECT rowid, * FROM t1} } {1 {} {} {} 2 {test value 1} {} {}} do_test bind-1.6 { sqlite3_reset $VM sqlite_bind $VM 3 {'test value 2'} normal sqlite_step $VM N VALUES COLNAMES } SQLITE_DONE do_test bind-1.7 { execsql {SELECT rowid, * FROM t1} } {1 {} {} {} 2 {test value 1} {} {} 3 {test value 1} {} {'test value 2'}} do_test bind-1.8 { sqlite3_reset $VM set sqlite_static_bind_value 123 sqlite_bind $VM 1 {} static sqlite_bind $VM 2 {abcdefg} normal sqlite_bind $VM 3 {} null execsql {DELETE FROM t1} sqlite_step $VM N VALUES COLNAMES execsql {SELECT rowid, * FROM t1} } {1 123 abcdefg {}} do_test bind-1.9 { sqlite3_reset $VM sqlite_bind $VM 1 {456} normal sqlite_step $VM N VALUES COLNAMES execsql {SELECT rowid, * FROM t1} } {1 123 abcdefg {} 2 456 abcdefg {}} do_test bind-1.99 { sqlite3_finalize $VM } {} do_test bind-2.1 { execsql { DELETE FROM t1; } set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(?,?,?)} -1 TAIL] set TAIL } {} # 32 bit Integers do_test bind-2.2 { sqlite3_bind_int32 $VM 1 123 sqlite3_bind_int32 $VM 2 456 sqlite3_bind_int32 $VM 3 789 sqlite_step $VM N VALUES COLNAMES sqlite3_reset $VM execsql {SELECT rowid, * FROM t1} } {1 123 456 789} do_test bind-2.3 { sqlite3_bind_int32 $VM 2 -2000000000 sqlite3_bind_int32 $VM 3 2000000000 sqlite_step $VM N VALUES COLNAMES sqlite3_reset $VM execsql {SELECT rowid, * FROM t1} } {1 123 456 789 2 123 -2000000000 2000000000} do_test bind-2.4 { execsql {SELECT classof(a), classof(b), classof(c) FROM t1} } {INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER} do_test bind-2.5 { execsql { DELETE FROM t1; } } {} # 64 bit Integers do_test bind-3.1 { sqlite3_bind_int64 $VM 1 32 sqlite3_bind_int64 $VM 2 -2000000000000 sqlite3_bind_int64 $VM 3 2000000000000 sqlite_step $VM N VALUES COLNAMES sqlite3_reset $VM execsql {SELECT rowid, * FROM t1} } {1 32 -2000000000000 2000000000000} do_test bind-3.2 { execsql {SELECT classof(a), classof(b), classof(c) FROM t1} } {INTEGER INTEGER INTEGER} do_test bind-3.3 { execsql { DELETE FROM t1; } } {} # Doubles do_test bind-4.1 { sqlite3_bind_double $VM 1 1234.1234 sqlite3_bind_double $VM 2 0.00001 sqlite3_bind_double $VM 3 123456789 sqlite_step $VM N VALUES COLNAMES sqlite3_reset $VM execsql {SELECT rowid, * FROM t1} } {1 1234.1234 1e-05 123456789} do_test bind-4.2 { execsql {SELECT classof(a), classof(b), classof(c) FROM t1} } {REAL REAL REAL} do_test bind-4.3 { execsql { DELETE FROM t1; } } {} # NULL do_test bind-5.1 { sqlite3_bind_null $VM 1 sqlite3_bind_null $VM 2 sqlite3_bind_null $VM 3 sqlite_step $VM N VALUES COLNAMES sqlite3_reset $VM execsql {SELECT rowid, * FROM t1} } {1 {} {} {}} do_test bind-5.2 { execsql {SELECT classof(a), classof(b), classof(c) FROM t1} } {NULL NULL NULL} do_test bind-5.3 { execsql { DELETE FROM t1; } } {} # UTF-8 text do_test bind-6.1 { sqlite3_bind_text $VM 1 hellothere 5 sqlite3_bind_text $VM 2 "." 2 sqlite3_bind_text $VM 3 world -1 sqlite_step $VM N VALUES COLNAMES sqlite3_reset $VM execsql {SELECT rowid, * FROM t1} } {1 hello . world} do_test bind-6.2 { execsql {SELECT classof(a), classof(b), classof(c) FROM t1} } {TEXT TEXT TEXT} do_test bind-6.3 { execsql { DELETE FROM t1; } } {} # UTF-16 text do_test bind-7.1 { sqlite3_bind_text16 $VM 1 [encoding convertto unicode hellothere] 10 sqlite3_bind_text16 $VM 2 [encoding convertto unicode ""] 0 sqlite3_bind_text16 $VM 3 [encoding convertto unicode world] 10 sqlite_step $VM N VALUES COLNAMES sqlite3_reset $VM execsql {SELECT rowid, * FROM t1} } {1 hello {} world} do_test bind-7.2 { execsql {SELECT classof(a), classof(b), classof(c) FROM t1} } {TEXT TEXT TEXT} do_test bind-7.3 { execsql { |
︙ | ︙ | |||
212 213 214 215 216 217 218 | } {bind index out of range} do_test bind-8.7 { encoding convertfrom unicode [sqlite3_errmsg16 $DB] } {bind index out of range} do_test bind-9.99 { | | | 212 213 214 215 216 217 218 219 220 221 222 223 224 | } {bind index out of range} do_test bind-8.7 { encoding convertfrom unicode [sqlite3_errmsg16 $DB] } {bind index out of range} do_test bind-9.99 { sqlite3_finalize $VM } {} finish_test |
Changes to test/capi2.test.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # 2003 January 29 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this script testing the callback-free C/C++ API. # | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # 2003 January 29 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this script testing the callback-free C/C++ API. # # $Id: capi2.test,v 1.12 2004/05/21 10:08:55 danielk1977 Exp $ # set testdir [file dirname $argv0] source $testdir/tester.tcl # Check basic functionality # |
︙ | ︙ | |||
53 54 55 56 57 58 59 | set COLNAMES z sqlite_step $VM N VALUES COLNAMES } {SQLITE_MISUSE} do_test capi2-1.9 { list $N $VALUES $COLNAMES } {0 {} {}} do_test capi2-1.10 { | | | 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | set COLNAMES z sqlite_step $VM N VALUES COLNAMES } {SQLITE_MISUSE} do_test capi2-1.9 { list $N $VALUES $COLNAMES } {0 {} {}} do_test capi2-1.10 { sqlite3_finalize $VM } {} # Check to make sure that the "tail" of a multi-statement SQL script # is returned by sqlite3_prepare. # do_test capi2-2.1 { set SQL { |
︙ | ︙ | |||
80 81 82 83 84 85 86 | lappend r $n $val $colname } {SQLITE_ROW 2 {t1 1} {name rowid text INTEGER}} do_test capi2-2.3 { set r [sqlite_step $VM n val colname] lappend r $n $val $colname } {SQLITE_DONE 2 {} {name rowid text INTEGER}} do_test capi2-2.4 { | | | | 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | lappend r $n $val $colname } {SQLITE_ROW 2 {t1 1} {name rowid text INTEGER}} do_test capi2-2.3 { set r [sqlite_step $VM n val colname] lappend r $n $val $colname } {SQLITE_DONE 2 {} {name rowid text INTEGER}} do_test capi2-2.4 { sqlite3_finalize $VM } {} do_test capi2-2.5 { set VM [sqlite3_prepare $DB $SQL -1 SQL] set SQL } { -- A comment at the end } do_test capi2-2.6 { set r [sqlite_step $VM n val colname] lappend r $n $val $colname } {SQLITE_DONE 2 {} {name rowid text INTEGER}} do_test capi2-2.7 { sqlite3_finalize $VM } {} do_test capi2-2.8 { set VM [sqlite3_prepare $DB $SQL -1 SQL] list $SQL $VM } {{} {}} # Check the error handling. |
︙ | ︙ | |||
145 146 147 148 149 150 151 | do_test capi2-3.7 { set N {} set VALUE {} set COLNAME {} list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_ROW 1 {{}} {5/0 NUMERIC}} do_test capi2-3.8 { | | | | | | | | 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | do_test capi2-3.7 { set N {} set VALUE {} set COLNAME {} list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_ROW 1 {{}} {5/0 NUMERIC}} do_test capi2-3.8 { sqlite3_finalize $VM } {} do_test capi2-3.9 { execsql {CREATE UNIQUE INDEX i1 ON t1(a)} set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(1,2,3)} -1 TAIL] set TAIL } {} do_test capi2-3.9b {db changes} {0} do_test capi2-3.10 { set N {} set VALUE {} set COLNAME {} list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_DONE 0 {} {}} do_test capi2-3.10b {db changes} {1} do_test capi2-3.11 { sqlite3_finalize $VM } {} do_test capi2-3.11b {db changes} {1} do_test capi2-3.12 { list [catch {sqlite3_finalize $VM} msg] [set msg] } {1 {(21) library routine called out of sequence}} do_test capi2-3.13 { set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(1,3,4)} -1 TAIL] list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_ERROR 0 {} {}} do_test capi2-3.13b {db changes} {0} do_test capi2-3.14 { list [catch {sqlite3_finalize $VM} msg] [set msg] } {1 {(19) column a is not unique}} do_test capi2-3.15 { set VM [sqlite3_prepare $DB {CREATE TABLE t2(a NOT NULL, b)} -1 TAIL] set TAIL } {} do_test capi2-3.16 { list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_DONE 0 {} {}} do_test capi2-3.17 { list [catch {sqlite3_finalize $VM} msg] [set msg] } {0 {}} do_test capi2-3.18 { set VM [sqlite3_prepare $DB {INSERT INTO t2 VALUES(NULL,2)} -1 TAIL] list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_ERROR 0 {} {}} do_test capi2-3.19 { list [catch {sqlite3_finalize $VM} msg] [set msg] } {1 {(19) t2.a may not be NULL}} # Two or more virtual machines exists at the same time. # do_test capi2-4.1 { set VM1 [sqlite3_prepare $DB {INSERT INTO t2 VALUES(1,2)} -1 TAIL] set TAIL |
︙ | ︙ | |||
214 215 216 217 218 219 220 | do_test capi2-4.4 { list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_DONE 0 {} {}} do_test capi2-4.5 { execsql {SELECT * FROM t2 ORDER BY a} } {2 3} do_test capi2-4.6 { | | | | | 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | do_test capi2-4.4 { list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_DONE 0 {} {}} do_test capi2-4.5 { execsql {SELECT * FROM t2 ORDER BY a} } {2 3} do_test capi2-4.6 { list [catch {sqlite3_finalize $VM2} msg] [set msg] } {0 {}} do_test capi2-4.7 { list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_DONE 0 {} {}} do_test capi2-4.8 { execsql {SELECT * FROM t2 ORDER BY a} } {2 3 3 4} do_test capi2-4.9 { list [catch {sqlite3_finalize $VM3} msg] [set msg] } {0 {}} do_test capi2-4.10 { list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_DONE 0 {} {}} do_test capi2-4.11 { execsql {SELECT * FROM t2 ORDER BY a} } {1 2 2 3 3 4} do_test capi2-4.12 { list [catch {sqlite3_finalize $VM1} msg] [set msg] } {0 {}} # Interleaved SELECTs # do_test capi2-5.1 { set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL] set VM2 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL] |
︙ | ︙ | |||
262 263 264 265 266 267 268 | do_test capi2-5.6 { list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_ROW 2 {1 2} {a b {} {}}} do_test capi2-5.7 { list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_DONE 2 {} {a b {} {}}} do_test capi2-5.8 { | | | | | 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | do_test capi2-5.6 { list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_ROW 2 {1 2} {a b {} {}}} do_test capi2-5.7 { list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_DONE 2 {} {a b {} {}}} do_test capi2-5.8 { list [catch {sqlite3_finalize $VM3} msg] [set msg] } {0 {}} do_test capi2-5.9 { list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_ROW 2 {1 2} {a b {} {}}} do_test capi2-5.10 { list [catch {sqlite3_finalize $VM1} msg] [set msg] } {0 {}} do_test capi2-5.11 { list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_ROW 2 {3 4} {a b {} {}}} do_test capi2-5.12 { list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_ROW 2 {1 2} {a b {} {}}} do_test capi2-5.11 { list [catch {sqlite3_finalize $VM2} msg] [set msg] } {0 {}} # Check for proper SQLITE_BUSY returns. # do_test capi2-6.1 { execsql { BEGIN; |
︙ | ︙ | |||
337 338 339 340 341 342 343 | # execsql {pragma vdbe_trace=on} do_test capi2-6.13 { catchsql {UPDATE t3 SET x=x+1} } {1 {database table is locked}} do_test capi2-6.14 { list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_ROW 1 6 {x counter}} | | | 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | # execsql {pragma vdbe_trace=on} do_test capi2-6.13 { catchsql {UPDATE t3 SET x=x+1} } {1 {database table is locked}} do_test capi2-6.14 { list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_ROW 1 6 {x counter}} # puts [list [catch {sqlite3_finalize $VM1} msg] [set msg]]; exit do_test capi2-6.15 { execsql {SELECT * FROM t1} } {1 2 3} do_test capi2-6.16 { list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_ROW 1 7 {x counter}} do_test capi2-6.17 { |
︙ | ︙ | |||
387 388 389 390 391 392 393 | SELECT * FROM t1; } } {1 {column a is not unique}} do_test capi2-6.28 { list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_ROW 1 13 {x counter}} do_test capi2-6.99 { | | | 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | SELECT * FROM t1; } } {1 {column a is not unique}} do_test capi2-6.28 { list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME] } {SQLITE_ROW 1 13 {x counter}} do_test capi2-6.99 { list [catch {sqlite3_finalize $VM1} msg] [set msg] } {0 {}} catchsql {ROLLBACK} do_test capi2-7.1 { stepsql $DB { SELECT * FROM t1 } |
︙ | ︙ | |||
454 455 456 457 458 459 460 | lindex $x 0 } {0} # Ticket #261 - make sure we can finalize before the end of a query. # do_test capi2-8.1 { set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL] | | | | 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | lindex $x 0 } {0} # Ticket #261 - make sure we can finalize before the end of a query. # do_test capi2-8.1 { set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL] sqlite3_finalize $VM1 } {} # Tickets #384 and #385 - make sure the TAIL argument to sqlite3_prepare # and all of the return pointers in sqlite_step can be null. # do_test capi2-9.1 { set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 DUMMY] sqlite_step $VM1 sqlite3_finalize $VM1 } {} db2 close finish_test |
Changes to test/capi3.test.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # 2003 January 29 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this script testing the callback-free C/C++ API. # | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # 2003 January 29 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this script testing the callback-free C/C++ API. # # $Id: capi3.test,v 1.3 2004/05/21 10:08:55 danielk1977 Exp $ # set testdir [file dirname $argv0] source $testdir/tester.tcl # Return the UTF-16 representation of the supplied UTF-8 string $str. # If $nt is true, append two 0x00 bytes as a nul terminator. |
︙ | ︙ | |||
50 51 52 53 54 55 56 | # db close set DB [sqlite db test.db] do_test capi3-1.1 { set STMT [sqlite3_prepare $DB {SELECT name FROM sqlite_master} -1 TAIL] | | | | | | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | # db close set DB [sqlite db test.db] do_test capi3-1.1 { set STMT [sqlite3_prepare $DB {SELECT name FROM sqlite_master} -1 TAIL] sqlite3_finalize $STMT set TAIL } {} do_test capi3-1.2 { sqlite3_errcode $DB } {SQLITE_OK} do_test capi3-1.3 { sqlite3_errmsg $DB } {not an error} do_test capi3-1.4 { set sql {SELECT name FROM sqlite_master;SELECT 10} set STMT [sqlite3_prepare $DB $sql -1 TAIL] sqlite3_finalize $STMT set TAIL } {SELECT 10} do_test capi3-1.5 { set sql {SELECT namex FROM sqlite_master} catch { set STMT [sqlite3_prepare $DB $sql -1 TAIL] } } {1} do_test capi3-1.6 { sqlite3_errcode $DB } {SQLITE_ERROR} do_test capi3-1.7 { sqlite3_errmsg $DB } {no such column: namex} do_test capi3-2.1 { set sql16 [utf16 {SELECT name FROM sqlite_master}] set STMT [sqlite3_prepare16 $DB $sql16 -1 ::TAIL] sqlite3_finalize $STMT utf8 $::TAIL } {} do_test capi3-2.2 { set sql [utf16 {SELECT name FROM sqlite_master;SELECT 10}] set STMT [sqlite3_prepare16 $DB $sql -1 TAIL] sqlite3_finalize $STMT utf8 $TAIL } {SELECT 10} do_test capi3-2.3 { set sql [utf16 {SELECT namex FROM sqlite_master}] catch { set STMT [sqlite3_prepare16 $DB $sql -1 TAIL] } |
︙ | ︙ | |||
150 151 152 153 154 155 156 157 158 159 160 | } {SQLITE_CANTOPEN} do_test capi3-4.4 { utf8 [sqlite3_errmsg16 $db2] } {unable to open database file} do_test capi3-4.4 { sqlite3_close $db2 } {} finish_test | > > | 150 151 152 153 154 155 156 157 158 159 160 161 162 | } {SQLITE_CANTOPEN} do_test capi3-4.4 { utf8 [sqlite3_errmsg16 $db2] } {unable to open database file} do_test capi3-4.4 { sqlite3_close $db2 } {} db close finish_test |
Changes to test/tester.tcl.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # 2001 September 15 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements some common TCL routines used for regression # testing the SQLite library # | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # 2001 September 15 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements some common TCL routines used for regression # testing the SQLite library # # $Id: tester.tcl,v 1.35 2004/05/21 10:08:55 danielk1977 Exp $ # Make sure tclsqlite was compiled correctly. Abort now with an # error message if not. # if {[sqlite -tcl-uses-utf]} { if {"\u1234"=="u1234"} { puts stderr "***** BUILD PROBLEM *****" |
︙ | ︙ | |||
201 202 203 204 205 206 207 | if {[catch {sqlite3_prepare $dbptr $sql -1 sqltail} vm]} { return [list 1 $vm] } set sql [string trim $sqltail] while {[sqlite_step $vm N VAL COL]=="SQLITE_ROW"} { foreach v $VAL {lappend r $v} } | | | 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | if {[catch {sqlite3_prepare $dbptr $sql -1 sqltail} vm]} { return [list 1 $vm] } set sql [string trim $sqltail] while {[sqlite_step $vm N VAL COL]=="SQLITE_ROW"} { foreach v $VAL {lappend r $v} } if {[catch {sqlite3_finalize $vm} errmsg]} { return [list 1 $errmsg] } } return $r } # Delete a file or directory |
︙ | ︙ |
Changes to test/vacuum.test.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # 2001 September 15 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing the VACUUM statement. # | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # 2001 September 15 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing the VACUUM statement. # # $Id: vacuum.test,v 1.17 2004/05/21 10:08:55 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl proc cksum {{db db}} { set txt [$db eval {SELECT name, type, sql FROM sqlite_master}]\n foreach tbl [$db eval {SELECT name FROM sqlite_master WHERE type='table'}] { |
︙ | ︙ | |||
135 136 137 138 139 140 141 | do_test vacuum-4.1 { db close set DB [sqlite db test.db] set VM [sqlite3_prepare $DB {VACUUM} -1 TAIL] sqlite_step $VM N VALUES COLNAMES } {SQLITE_DONE} do_test vacuum-4.2 { | | | 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | do_test vacuum-4.1 { db close set DB [sqlite db test.db] set VM [sqlite3_prepare $DB {VACUUM} -1 TAIL] sqlite_step $VM N VALUES COLNAMES } {SQLITE_DONE} do_test vacuum-4.2 { sqlite3_finalize $VM } {} # Ticket #515. VACUUM after deleting and recreating the table that # a view refers to. # do_test vacuum-5.1 { db close |
︙ | ︙ |