1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Refine error messages in the sqlite3 Tcl command when a NULL database connection is returned from sqlite3_open_v2.

FossilOrigin-Name: f260d7d567a1239c483c437d0b18a95bd0c96724
This commit is contained in:
mistachkin
2012-09-10 07:29:29 +00:00
parent 60a7523bd3
commit 540ebf8271
3 changed files with 23 additions and 12 deletions

View File

@@ -41,6 +41,12 @@
#endif
#include <ctype.h>
/*
** This function is used to translate a return code into an error
** message.
*/
const char *sqlite3ErrStr(int rc);
/*
* Windows needs to know which symbols to export. Unix does not.
* BUILD_sqlite should be undefined for Unix.
@@ -2929,6 +2935,7 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
void *pKey = 0;
int nKey = 0;
#endif
int rc;
/* In normal use, each TCL interpreter runs in a single thread. So
** by default, we can turn of mutexing on SQLite database connections.
@@ -3033,12 +3040,16 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
memset(p, 0, sizeof(*p));
zFile = Tcl_GetStringFromObj(objv[2], 0);
zFile = Tcl_TranslateFileName(interp, zFile, &translatedFilename);
sqlite3_open_v2(zFile, &p->db, flags, zVfs);
rc = sqlite3_open_v2(zFile, &p->db, flags, zVfs);
Tcl_DStringFree(&translatedFilename);
if( SQLITE_OK!=sqlite3_errcode(p->db) ){
zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(p->db));
sqlite3_close(p->db);
p->db = 0;
if( p->db ){
if( SQLITE_OK!=sqlite3_errcode(p->db) ){
zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(p->db));
sqlite3_close(p->db);
p->db = 0;
}
}else{
zErrMsg = sqlite3_mprintf("%s", sqlite3ErrStr(rc));
}
#ifdef SQLITE_HAS_CODEC
if( p->db ){