Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Use the new form of the sqlite3_open() API everywhere. (CVS 1437) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
b449217318ade3196757bef8aaf73026 |
User & Date: | danielk1977 2004-05-22 09:21:21.000 |
Context
2004-05-22
| ||
10:33 | Add a couple of tests for UTF-16 databases. (CVS 1438) (check-in: d7551df8c3 user: danielk1977 tags: trunk) | |
09:21 | Use the new form of the sqlite3_open() API everywhere. (CVS 1437) (check-in: b449217318 user: danielk1977 tags: trunk) | |
08:16 | Tests for the functions in utf.c. (CVS 1436) (check-in: 802d65affc user: danielk1977 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.184 2004/05/22 09:21:21 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> /* ** A pointer to this structure is used to communicate information |
︙ | ︙ | |||
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 | sqlite3 **ppDb, /* OUT: Returned database handle */ const char **options, /* Null terminated list of db options, or null */ u8 def_enc /* One of TEXT_Utf8, TEXT_Utf16le or TEXT_Utf16be */ ){ sqlite3 *db; int rc, i; char *zErrMsg = 0; /* Allocate the sqlite data structure */ db = sqliteMalloc( sizeof(sqlite) ); if( db==0 ) goto opendb_out; db->onError = OE_Default; db->priorNewRowid = 0; db->magic = SQLITE_MAGIC_BUSY; | > > > > > > > > > > > > > | 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 | sqlite3 **ppDb, /* OUT: Returned database handle */ const char **options, /* Null terminated list of db options, or null */ u8 def_enc /* One of TEXT_Utf8, TEXT_Utf16le or TEXT_Utf16be */ ){ sqlite3 *db; int rc, i; char *zErrMsg = 0; #ifdef SQLITE_TEST for(i=0; options && options[i]; i++){ char const *zOpt = options[i]; if( 0==sqlite3StrICmp(zOpt, "-utf8") ){ def_enc = TEXT_Utf8; }else if( 0==sqlite3StrICmp(zOpt, "-utf16le") ){ def_enc = TEXT_Utf16le; }else if( 0==sqlite3StrICmp(zOpt, "-utf16be") ){ def_enc = TEXT_Utf16be; } } #endif /* Allocate the sqlite data structure */ db = sqliteMalloc( sizeof(sqlite) ); if( db==0 ) goto opendb_out; db->onError = OE_Default; db->priorNewRowid = 0; db->magic = SQLITE_MAGIC_BUSY; |
︙ | ︙ | |||
1253 1254 1255 1256 1257 1258 1259 | *ppDb = db; return sqlite3_errcode(db); } /* ** Open a new database handle. */ | | < < < < < < < < < < < < < < > > | 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 | *ppDb = db; return sqlite3_errcode(db); } /* ** Open a new database handle. */ int sqlite3_open( const char *zFilename, sqlite3 **ppDb, const char **options ){ return openDatabase(zFilename, ppDb, options, TEXT_Utf8); } /* ** Open a new database handle. */ int sqlite3_open16( const void *zFilename, sqlite3 **ppDb, const char **options ){ char *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */ int rc; assert( ppDb ); zFilename8 = sqlite3utf16to8(zFilename, -1, SQLITE3_BIGENDIAN); if( !zFilename8 ){ *ppDb = 0; return SQLITE_NOMEM; } /* FIX ME: Also need to translate the option strings */ if( SQLITE3_BIGENDIAN ){ rc = openDatabase(zFilename8, ppDb, options, TEXT_Utf16be); }else{ rc = openDatabase(zFilename8, ppDb, options, TEXT_Utf16le); } |
︙ | ︙ | |||
1331 1332 1333 1334 1335 1336 1337 | */ int sqlite3_reset_new(sqlite3_stmt *pStmt){ int rc = sqlite3VdbeReset((Vdbe*)pStmt, 0); sqlite3VdbeMakeReady((Vdbe*)pStmt, -1, 0); return rc; } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 1332 1333 1334 1335 1336 1337 1338 | */ int sqlite3_reset_new(sqlite3_stmt *pStmt){ int rc = sqlite3VdbeReset((Vdbe*)pStmt, 0); sqlite3VdbeMakeReady((Vdbe*)pStmt, -1, 0); return rc; } |
Changes to src/shell.c.
︙ | ︙ | |||
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 file contains code to implement the "sqlite" command line ** utility for accessing SQLite databases. ** | | | 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 file contains code to implement the "sqlite" command line ** utility for accessing SQLite databases. ** ** $Id: shell.c,v 1.97 2004/05/22 09:21:21 danielk1977 Exp $ */ #include <stdlib.h> #include <string.h> #include <stdio.h> #include "sqlite.h" #include <ctype.h> |
︙ | ︙ | |||
506 507 508 509 510 511 512 | /* ** Make sure the database is open. If it is not, then open it. If ** the database fails to open, print an error message and exit. */ static void open_db(struct callback_data *p){ if( p->db==0 ){ | < > | > < | | < < < | 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 | /* ** Make sure the database is open. If it is not, then open it. If ** the database fails to open, print an error message and exit. */ static void open_db(struct callback_data *p){ if( p->db==0 ){ #ifdef SQLITE_HAS_CODEC int n = p->zKey ? strlen(p->zKey) : 0; db = p->db = sqlite3_open_encrypted(p->zDbFilename, p->zKey, n, 0, &zErrMsg); assert(0); /* Encrypted databases are broken in SQLite 3 */ #else sqlite3_open(p->zDbFilename, &p->db, 0); db = p->db; #endif if( SQLITE_OK!=sqlite3_errcode(db) ){ fprintf(stderr,"Unable to open database \"%s\": %s\n", p->zDbFilename, sqlite3_errmsg(db)); exit(1); } } } /* ** If an input line begins with "." then invoke this routine to |
︙ | ︙ |
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.69 2004/05/22 09:21:21 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++. |
︙ | ︙ | |||
54 55 56 57 58 59 60 | /* ** Each open sqlite database is represented by an instance of the ** following opaque structure. */ typedef struct sqlite sqlite; | < < < < < < < < < < < < < < < < < < < | 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | /* ** Each open sqlite database is represented by an instance of the ** following opaque structure. */ typedef struct sqlite sqlite; /* ** A function to close the database. ** ** Call this function with a pointer to a structure that was previously ** returned from sqlite3_open() and the corresponding database will by closed. */ void sqlite3_close(sqlite *); |
︙ | ︙ | |||
1199 1200 1201 1202 1203 1204 1205 | ** 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); | > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > | 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 | ** 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); /* ** Open the sqlite database file "filename", where "filename" is UTF-8 ** encoded. An sqlite3* handle is returned in *ppDb, even if an error ** occurs. If the database is opened (or created) successfully, then ** SQLITE_OK is returned. Otherwise an error code is returned and the ** sqlite3_errmsg() function may be used to obtain an English language ** explanation of the error. ** ** If the database file does not exist, then a new database is created ** using UTF-8 text encoding. ** ** Whether or not an error occurs when it is opened, resources associated ** with the sqlite3* handle should be released by passing it to ** sqlite3_close() when it is no longer required. */ int sqlite3_open( const char *filename, /* Database filename (UTF-8) */ sqlite3 **ppDb, /* OUT: SQLite db handle */ const char **args /* Null terminated array of option strings */ ); /* ** Open the sqlite database file "filename", where "filename" is native ** byte order UTF-16 encoded. An sqlite3* handle is returned in *ppDb, even ** if an error occurs. If the database is opened (or created) successfully, ** then SQLITE_OK is returned. Otherwise an error code is returned and the ** sqlite3_errmsg() function may be used to obtain an English language ** explanation of the error. ** ** If the database file does not exist, then a new database is created ** using UTF-16 text encoding in the machines native byte order. ** ** Whether or not an error occurs when it is opened, resources associated ** with the sqlite3* handle should be released by passing it to ** sqlite3_close() when it is no longer required. */ 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 */ ); /* |
︙ | ︙ |
Changes to src/tclsqlite.c.
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. ** ************************************************************************* ** A TCL Interface to 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. ** ************************************************************************* ** A TCL Interface to SQLite ** ** $Id: tclsqlite.c,v 1.66 2004/05/22 09:21:21 danielk1977 Exp $ */ #ifndef NO_TCL /* Omit this whole file if TCL is unavailable */ #include "sqliteInt.h" #include "tcl.h" #include <stdlib.h> #include <string.h> |
︙ | ︙ | |||
1016 1017 1018 1019 1020 1021 1022 | ** sqlite -tcl-uses-utf ** ** Return "1" if compiled with a Tcl uses UTF-8. Return "0" if ** not. Used by tests to make sure the library was compiled ** correctly. */ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ | < > | 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 | ** sqlite -tcl-uses-utf ** ** Return "1" if compiled with a Tcl uses UTF-8. Return "0" if ** not. Used by tests to make sure the library was compiled ** correctly. */ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ SqliteDb *p; void *pKey = 0; int nKey = 0; const char *zArg; char *zErrMsg; const char *zFile; const char *zOpts[2] = {0, 0}; char zBuf[80]; if( objc==2 ){ zArg = Tcl_GetStringFromObj(objv[1], 0); if( strcmp(zArg,"-encoding")==0 ){ Tcl_AppendResult(interp,sqlite3_encoding,0); return TCL_OK; } |
︙ | ︙ | |||
1068 1069 1070 1071 1072 1073 1074 | "HANDLE FILENAME ?-key CODEC-KEY?" #else "HANDLE FILENAME ?MODE?" #endif ); return TCL_ERROR; } | < < < < < > > > | > > > > > | 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 | "HANDLE FILENAME ?-key CODEC-KEY?" #else "HANDLE FILENAME ?MODE?" #endif ); return TCL_ERROR; } zErrMsg = 0; p = (SqliteDb*)Tcl_Alloc( sizeof(*p) ); if( p==0 ){ Tcl_SetResult(interp, "malloc failed", TCL_STATIC); return TCL_ERROR; } memset(p, 0, sizeof(*p)); zFile = Tcl_GetStringFromObj(objv[2], 0); #ifdef SQLITE_HAS_CODEC p->db = sqlite3_open_encrypted(zFile, pKey, nKey, 0, &zErrMsg); #else if( objc>3 ){ zOpts[0] = Tcl_GetString(objv[3]); } sqlite3_open(zFile, &p->db, zOpts); if( SQLITE_OK!=sqlite3_errcode(p->db) ){ zErrMsg = strdup(sqlite3_errmsg(p->db)); sqlite3_close(p->db); p->db = 0; } #endif if( p->db==0 ){ Tcl_SetResult(interp, zErrMsg, TCL_VOLATILE); Tcl_Free((char*)p); free(zErrMsg); return TCL_ERROR; } |
︙ | ︙ |
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.46 2004/05/22 09:21:21 danielk1977 Exp $ */ #include "sqliteInt.h" #include "tcl.h" #include "os.h" #include <stdlib.h> #include <string.h> |
︙ | ︙ | |||
1363 1364 1365 1366 1367 1368 1369 | if( objc!=3 && objc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetString(objv[0]), " filename options-list", 0); return TCL_ERROR; } zFilename = Tcl_GetString(objv[1]); | | | 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 | if( objc!=3 && objc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetString(objv[0]), " filename options-list", 0); return TCL_ERROR; } zFilename = Tcl_GetString(objv[1]); rc = sqlite3_open(zFilename, &db, 0); if( makePointerStr(interp, zBuf, db) ) return TCL_ERROR; Tcl_AppendResult(interp, zBuf, 0); return TCL_OK; } /* |
︙ | ︙ |
Changes to src/test4.c.
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* ** 2003 December 18 ** ** 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. ** ************************************************************************* ** Code for testing the the SQLite library in a multithreaded environment. ** | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /* ** 2003 December 18 ** ** 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. ** ************************************************************************* ** Code for testing the the SQLite library in a multithreaded environment. ** ** $Id: test4.c,v 1.6 2004/05/22 09:21:21 danielk1977 Exp $ */ #include "sqliteInt.h" #include "tcl.h" #if defined(OS_UNIX) && OS_UNIX==1 && defined(THREADSAFE) && THREADSAFE==1 #include <stdlib.h> #include <string.h> #include <pthread.h> |
︙ | ︙ | |||
61 62 63 64 65 66 67 | ** The main loop for a thread. Threads use busy waiting. */ static void *thread_main(void *pArg){ Thread *p = (Thread*)pArg; if( p->db ){ sqlite3_close(p->db); } | | > > > > > | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | ** The main loop for a thread. Threads use busy waiting. */ static void *thread_main(void *pArg){ Thread *p = (Thread*)pArg; if( p->db ){ sqlite3_close(p->db); } sqlite3_open(p->zFilename, &p->db, 0); if( SQLITE_OK!=sqlite3_errcode(p->db) ){ p->zErr = strdup(sqlite3_errmsg(p->db)); sqlite3_close(p->db); p->db = 0; } p->vm = 0; p->completed = 1; while( p->opnum<=p->completed ) sched_yield(); while( p->xOp ){ if( p->zErr && p->zErr!=p->zStaticErr ){ sqlite3_freemem(p->zErr); p->zErr = 0; |
︙ | ︙ |
Changes to src/vacuum.c.
︙ | ︙ | |||
10 11 12 13 14 15 16 | ** ************************************************************************* ** This file contains code used to implement the VACUUM command. ** ** Most of the code in this file may be omitted by defining the ** SQLITE_OMIT_VACUUM macro. ** | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ** ************************************************************************* ** This file contains code used to implement the VACUUM command. ** ** Most of the code in this file may be omitted by defining the ** SQLITE_OMIT_VACUUM macro. ** ** $Id: vacuum.c,v 1.16 2004/05/22 09:21:21 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" /* ** A structure for holding a dynamic string - a string that can grow ** without bound. |
︙ | ︙ | |||
262 263 264 265 266 267 268 | if( i>=10 ){ sqlite3SetString(pzErrMsg, "unable to create a temporary database file " "in the same directory as the original database", (char*)0); goto end_of_vacuum; } | | < | | 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | if( i>=10 ){ sqlite3SetString(pzErrMsg, "unable to create a temporary database file " "in the same directory as the original database", (char*)0); goto end_of_vacuum; } if( SQLITE_OK!=sqlite3_open(zTemp, &dbNew, 0) ){ sqlite3SetString(pzErrMsg, "unable to open a temporary database at ", zTemp, " - ", sqlite3_errmsg(dbNew), (char*)0); goto end_of_vacuum; } if( (rc = execsql(pzErrMsg, db, "BEGIN"))!=0 ) goto end_of_vacuum; if( (rc = execsql(pzErrMsg, dbNew, "PRAGMA synchronous=off; BEGIN"))!=0 ){ goto end_of_vacuum; } |
︙ | ︙ | |||
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | } sqlite3_exec(db, "ROLLBACK", 0, 0, 0); if( dbNew ) sqlite3_close(dbNew); sqlite3OsDelete(zTemp); sqliteFree(zTemp); sqliteFree(sVac.s1.z); sqliteFree(sVac.s2.z); if( zErrMsg ) sqlite3_freemem(zErrMsg); if( rc==SQLITE_ABORT ) sVac.rc = SQLITE_ERROR; return sVac.rc; #endif } | > | 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | } sqlite3_exec(db, "ROLLBACK", 0, 0, 0); if( dbNew ) sqlite3_close(dbNew); sqlite3OsDelete(zTemp); sqliteFree(zTemp); sqliteFree(sVac.s1.z); sqliteFree(sVac.s2.z); if( dbNew ) sqlite3_close(dbNew); if( zErrMsg ) sqlite3_freemem(zErrMsg); if( rc==SQLITE_ABORT ) sVac.rc = SQLITE_ERROR; return sVac.rc; #endif } |