aboutsummaryrefslogtreecommitdiff
path: root/src/tclsqlite.c
diff options
context:
space:
mode:
authormistachkin <mistachkin@noemail.net>2012-09-10 07:29:29 +0000
committermistachkin <mistachkin@noemail.net>2012-09-10 07:29:29 +0000
commit540ebf82718987d243e169b19c20ccc2588407a8 (patch)
tree52e706c5d4dbd3b0b905e877bc12fd678bcfa850 /src/tclsqlite.c
parent60a7523bd3b2f1b95a35641e1dd1435d977125d9 (diff)
downloadsqlite-540ebf82718987d243e169b19c20ccc2588407a8.tar.gz
sqlite-540ebf82718987d243e169b19c20ccc2588407a8.zip
Refine error messages in the sqlite3 Tcl command when a NULL database connection is returned from sqlite3_open_v2.
FossilOrigin-Name: f260d7d567a1239c483c437d0b18a95bd0c96724
Diffstat (limited to 'src/tclsqlite.c')
-rw-r--r--src/tclsqlite.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/tclsqlite.c b/src/tclsqlite.c
index 51f8c517d..bb930f0c7 100644
--- a/src/tclsqlite.c
+++ b/src/tclsqlite.c
@@ -42,6 +42,12 @@
#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 ){