/ Check-in [b4492173]
Login

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 | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b449217318ade3196757bef8aaf7302634f0f9b6
User & Date: danielk1977 2004-05-22 09:21:21
Context
2004-05-22
10:33
Add a couple of tests for UTF-16 databases. (CVS 1438) check-in: d7551df8 user: danielk1977 tags: trunk
09:21
Use the new form of the sqlite3_open() API everywhere. (CVS 1437) check-in: b4492173 user: danielk1977 tags: trunk
08:16
Tests for the functions in utf.c. (CVS 1436) check-in: 802d65af user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/main.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Main file for the SQLite library.  The routines in this file
    13     13   ** implement the programmer interface to the library.  Routines in
    14     14   ** other files are for internal use by SQLite and should not be
    15     15   ** accessed by users of the library.
    16     16   **
    17         -** $Id: main.c,v 1.183 2004/05/22 08:09:40 danielk1977 Exp $
           17  +** $Id: main.c,v 1.184 2004/05/22 09:21:21 danielk1977 Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include "os.h"
    21     21   #include <ctype.h>
    22     22   
    23     23   /*
    24     24   ** A pointer to this structure is used to communicate information
................................................................................
  1194   1194     sqlite3 **ppDb,        /* OUT: Returned database handle */
  1195   1195     const char **options,  /* Null terminated list of db options, or null */
  1196   1196     u8 def_enc             /* One of TEXT_Utf8, TEXT_Utf16le or TEXT_Utf16be */
  1197   1197   ){
  1198   1198     sqlite3 *db;
  1199   1199     int rc, i;
  1200   1200     char *zErrMsg = 0;
         1201  +
         1202  +#ifdef SQLITE_TEST
         1203  +  for(i=0; options && options[i]; i++){
         1204  +    char const *zOpt = options[i];
         1205  +    if( 0==sqlite3StrICmp(zOpt, "-utf8") ){
         1206  +      def_enc = TEXT_Utf8;
         1207  +    }else if( 0==sqlite3StrICmp(zOpt, "-utf16le") ){
         1208  +      def_enc = TEXT_Utf16le;
         1209  +    }else if( 0==sqlite3StrICmp(zOpt, "-utf16be") ){
         1210  +      def_enc = TEXT_Utf16be;
         1211  +    }
         1212  +  }
         1213  +#endif
  1201   1214   
  1202   1215     /* Allocate the sqlite data structure */
  1203   1216     db = sqliteMalloc( sizeof(sqlite) );
  1204   1217     if( db==0 ) goto opendb_out;
  1205   1218     db->onError = OE_Default;
  1206   1219     db->priorNewRowid = 0;
  1207   1220     db->magic = SQLITE_MAGIC_BUSY;
................................................................................
  1253   1266     *ppDb = db;
  1254   1267     return sqlite3_errcode(db);
  1255   1268   }
  1256   1269   
  1257   1270   /*
  1258   1271   ** Open a new database handle.
  1259   1272   */
  1260         -int sqlite3_open_new(
         1273  +int sqlite3_open(
  1261   1274     const char *zFilename, 
  1262   1275     sqlite3 **ppDb, 
  1263   1276     const char **options
  1264   1277   ){
  1265   1278     return openDatabase(zFilename, ppDb, options, TEXT_Utf8);
  1266         -  /* return openDatabase(zFilename, ppDb, options, TEXT_Utf16le); */
  1267         -}
  1268         -
  1269         -sqlite *sqlite3_open(const char *zFilename, int mode, char **pzErrMsg){
  1270         -  sqlite3 *db;
  1271         -  int rc;
  1272         - 
  1273         -  rc = sqlite3_open_new(zFilename, &db, 0);
  1274         -  if( rc!=SQLITE_OK && pzErrMsg ){
  1275         -    char *err = sqlite3_errmsg(db);
  1276         -    *pzErrMsg = malloc(strlen(err)+1);
  1277         -    strcpy(*pzErrMsg, err);
  1278         -  }
  1279         -  return db;
  1280   1279   }
  1281   1280   
  1282   1281   /*
  1283   1282   ** Open a new database handle.
  1284   1283   */
  1285   1284   int sqlite3_open16(
  1286   1285     const void *zFilename, 
................................................................................
  1293   1292     assert( ppDb );
  1294   1293   
  1295   1294     zFilename8 = sqlite3utf16to8(zFilename, -1, SQLITE3_BIGENDIAN);
  1296   1295     if( !zFilename8 ){
  1297   1296       *ppDb = 0;
  1298   1297       return SQLITE_NOMEM;
  1299   1298     }
         1299  +
         1300  +  /* FIX ME: Also need to translate the option strings */
  1300   1301   
  1301   1302     if( SQLITE3_BIGENDIAN ){
  1302   1303       rc = openDatabase(zFilename8, ppDb, options, TEXT_Utf16be);
  1303   1304     }else{
  1304   1305       rc = openDatabase(zFilename8, ppDb, options, TEXT_Utf16le);
  1305   1306     }
  1306   1307   
................................................................................
  1331   1332   */
  1332   1333   int sqlite3_reset_new(sqlite3_stmt *pStmt){
  1333   1334     int rc = sqlite3VdbeReset((Vdbe*)pStmt, 0);
  1334   1335     sqlite3VdbeMakeReady((Vdbe*)pStmt, -1, 0);
  1335   1336     return rc;
  1336   1337   }
  1337   1338   
  1338         -#if 0
  1339         -
  1340         -/*
  1341         -** sqlite3_open
  1342         -**
  1343         -*/
  1344         -int sqlite3_open(const char *filename, sqlite3 **pDb, const char **options){
  1345         -  *pDb = sqlite3_open(filename, 0, &errmsg);
  1346         -  return (*pDb?SQLITE_OK:SQLITE_ERROR);
  1347         -}
  1348         -int sqlite3_open16(const void *filename, sqlite3 **pDb, const char **options){
  1349         -  int rc;
  1350         -  char * filename8;
  1351         -
  1352         -  filename8 = sqlite3utf16to8(filename, -1, SQLITE3_BIGENDIAN);
  1353         -  if( !filename8 ){
  1354         -    return SQLITE_NOMEM;
  1355         -  }
  1356         -
  1357         -  rc = sqlite3_open(filename8, pDb, options);
  1358         -  sqliteFree(filename8);
  1359         -
  1360         -  return rc;
  1361         -}
  1362         -
  1363         -/*
  1364         -** sqlite3_close
  1365         -**
  1366         -*/
  1367         -int sqlite3_close(sqlite3 *db){
  1368         -  return sqlite3_close(db);
  1369         -}
  1370         -
  1371         -/*
  1372         -** sqlite3_errmsg
  1373         -**
  1374         -** TODO: !
  1375         -*/
  1376         -const char *sqlite3_errmsg(sqlite3 *db){
  1377         -  assert(!"TODO");
  1378         -}
  1379         -const void *sqlite3_errmsg16(sqlite3 *db){
  1380         -  assert(!"TODO");
  1381         -}
  1382         -
  1383         -/*
  1384         -** sqlite3_errcode
  1385         -**
  1386         -** TODO: !
  1387         -*/
  1388         -int sqlite3_errcode(sqlite3 *db){
  1389         -  assert(!"TODO");
  1390         -}
  1391         -
  1392         -struct sqlite_stmt {
  1393         -};
  1394         -
  1395         -/*
  1396         -** sqlite3_finalize
  1397         -*/
  1398         -int sqlite3_finalize(sqlite3_stmt *stmt){
  1399         -  return sqlite3_finalize(stmt, 0);
  1400         -}
  1401         -
  1402         -/*
  1403         -** sqlite3_reset
  1404         -*/
  1405         -int sqlite3_reset(sqlite3_stmt*){
  1406         -  return sqlite3_reset(stmt, 0);
  1407         -}
  1408         -
  1409         -/*
  1410         -** sqlite3_step
  1411         -*/
  1412         -int sqlite3_step(sqlite3_stmt *pStmt){
  1413         -  return sqlite3_step(pStmt);
  1414         -}
  1415         -
  1416         -int sqlite3_column_count(sqlite3_stmt*){
  1417         -}
  1418         -
  1419         -int sqlite3_column_type(sqlite3_stmt*,int){
  1420         -}
  1421         -
  1422         -const char *sqlite3_column_decltype(sqlite3_stmt*,int){
  1423         -}
  1424         -
  1425         -const void *sqlite3_column_decltype16(sqlite3_stmt*,int){
  1426         -}
  1427         -
  1428         -const char *sqlite3_column_name(sqlite3_stmt*,int){
  1429         -}
  1430         -
  1431         -const void *sqlite3_column_name16(sqlite3_stmt*,int){
  1432         -}
  1433         -
  1434         -const unsigned char *sqlite3_column_data(sqlite3_stmt*,int){
  1435         -}
  1436         -
  1437         -const void *sqlite3_column_data16(sqlite3_stmt*,int){
  1438         -}
  1439         -
  1440         -int sqlite3_column_bytes(sqlite3_stmt*,int){
  1441         -}
  1442         -
  1443         -long long int sqlite3_column_int(sqlite3_stmt*,int){
  1444         -}
  1445         -
  1446         -double sqlite3_column_float(sqlite3_stmt*,int){
  1447         -}
  1448         -
  1449         -#endif

Changes to src/shell.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code to implement the "sqlite" command line
    13     13   ** utility for accessing SQLite databases.
    14     14   **
    15         -** $Id: shell.c,v 1.96 2004/05/14 11:00:53 danielk1977 Exp $
           15  +** $Id: shell.c,v 1.97 2004/05/22 09:21:21 danielk1977 Exp $
    16     16   */
    17     17   #include <stdlib.h>
    18     18   #include <string.h>
    19     19   #include <stdio.h>
    20     20   #include "sqlite.h"
    21     21   #include <ctype.h>
    22     22   
................................................................................
   506    506   
   507    507   /*
   508    508   ** Make sure the database is open.  If it is not, then open it.  If
   509    509   ** the database fails to open, print an error message and exit.
   510    510   */
   511    511   static void open_db(struct callback_data *p){
   512    512     if( p->db==0 ){
   513         -    char *zErrMsg = 0;
   514    513   #ifdef SQLITE_HAS_CODEC
   515    514       int n = p->zKey ? strlen(p->zKey) : 0;
   516    515       db = p->db = sqlite3_open_encrypted(p->zDbFilename, p->zKey, n, 0, &zErrMsg);
          516  +    assert(0); /* Encrypted databases are broken in SQLite 3 */
   517    517   #else
   518         -    db = p->db = sqlite3_open(p->zDbFilename, 0, &zErrMsg);
          518  +    sqlite3_open(p->zDbFilename, &p->db, 0);
          519  +    db = p->db;
   519    520   #endif
   520         -    if( p->db==0 ){
   521         -      if( zErrMsg ){
   522         -        fprintf(stderr,"Unable to open database \"%s\": %s\n", 
   523         -           p->zDbFilename, zErrMsg);
   524         -      }else{
   525         -        fprintf(stderr,"Unable to open database %s\n", p->zDbFilename);
   526         -      }
          521  +    if( SQLITE_OK!=sqlite3_errcode(db) ){
          522  +      fprintf(stderr,"Unable to open database \"%s\": %s\n", 
          523  +          p->zDbFilename, sqlite3_errmsg(db));
   527    524         exit(1);
   528    525       }
   529    526     }
   530    527   }
   531    528   
   532    529   /*
   533    530   ** If an input line begins with "." then invoke this routine to

Changes to src/sqlite.h.in.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This header file defines the interface that the SQLite library
    13     13   ** presents to client programs.
    14     14   **
    15         -** @(#) $Id: sqlite.h.in,v 1.68 2004/05/21 10:08:54 danielk1977 Exp $
           15  +** @(#) $Id: sqlite.h.in,v 1.69 2004/05/22 09:21:21 danielk1977 Exp $
    16     16   */
    17     17   #ifndef _SQLITE_H_
    18     18   #define _SQLITE_H_
    19     19   #include <stdarg.h>     /* Needed for the definition of va_list */
    20     20   
    21     21   /*
    22     22   ** Make sure we can call this stuff from C++.
................................................................................
    54     54   
    55     55   /*
    56     56   ** Each open sqlite database is represented by an instance of the
    57     57   ** following opaque structure.
    58     58   */
    59     59   typedef struct sqlite sqlite;
    60     60   
    61         -/*
    62         -** A function to open a new sqlite database.  
    63         -**
    64         -** If the database does not exist and mode indicates write
    65         -** permission, then a new database is created.  If the database
    66         -** does not exist and mode does not indicate write permission,
    67         -** then the open fails, an error message generated (if errmsg!=0)
    68         -** and the function returns 0.
    69         -** 
    70         -** If mode does not indicates user write permission, then the 
    71         -** database is opened read-only.
    72         -**
    73         -** The Truth:  As currently implemented, all databases are opened
    74         -** for writing all the time.  Maybe someday we will provide the
    75         -** ability to open a database readonly.  The mode parameters is
    76         -** provided in anticipation of that enhancement.
    77         -*/
    78         -sqlite *sqlite3_open(const char *filename, int mode, char **errmsg);
    79         -
    80     61   /*
    81     62   ** A function to close the database.
    82     63   **
    83     64   ** Call this function with a pointer to a structure that was previously
    84     65   ** returned from sqlite3_open() and the corresponding database will by closed.
    85     66   */
    86     67   void sqlite3_close(sqlite *);
................................................................................
  1199   1180   ** statement obtained by a previous call to sqlite3_prepare() or
  1200   1181   ** sqlite3_prepare16() back to it's initial state, ready to be re-executed.
  1201   1182   ** Any SQL statement variables that had values bound to them using
  1202   1183   ** the sqlite3_bind_*() API retain their values.
  1203   1184   */
  1204   1185   int sqlite3_reset_new(sqlite3_stmt *pStmt);
  1205   1186   
  1206         -int sqlite3_open_new(
         1187  +/*
         1188  +** Open the sqlite database file "filename", where "filename" is UTF-8
         1189  +** encoded. An sqlite3* handle is returned in *ppDb, even if an error 
         1190  +** occurs. If the database is opened (or created) successfully, then 
         1191  +** SQLITE_OK is returned. Otherwise an error code is returned and the
         1192  +** sqlite3_errmsg() function may be used to obtain an English language
         1193  +** explanation of the error.
         1194  +**
         1195  +** If the database file does not exist, then a new database is created
         1196  +** using UTF-8 text encoding.
         1197  +**
         1198  +** Whether or not an error occurs when it is opened, resources associated
         1199  +** with the sqlite3* handle should be released by passing it to
         1200  +** sqlite3_close() when it is no longer required.
         1201  +*/
         1202  +int sqlite3_open(
  1207   1203     const char *filename,   /* Database filename (UTF-8) */
  1208   1204     sqlite3 **ppDb,         /* OUT: SQLite db handle */
  1209   1205     const char **args       /* Null terminated array of option strings */
  1210   1206   );
  1211   1207   
         1208  +/*
         1209  +** Open the sqlite database file "filename", where "filename" is native
         1210  +** byte order UTF-16 encoded. An sqlite3* handle is returned in *ppDb, even
         1211  +** if an error occurs. If the database is opened (or created) successfully,
         1212  +** then SQLITE_OK is returned. Otherwise an error code is returned and the
         1213  +** sqlite3_errmsg() function may be used to obtain an English language
         1214  +** explanation of the error.
         1215  +**
         1216  +** If the database file does not exist, then a new database is created
         1217  +** using UTF-16 text encoding in the machines native byte order.
         1218  +**
         1219  +** Whether or not an error occurs when it is opened, resources associated
         1220  +** with the sqlite3* handle should be released by passing it to
         1221  +** sqlite3_close() when it is no longer required.
         1222  +*/
  1212   1223   int sqlite3_open16(
  1213   1224     const void *filename,   /* Database filename (UTF-16) */
  1214   1225     sqlite3 **ppDb,         /* OUT: SQLite db handle */
  1215   1226     const char **args       /* Null terminated array of option strings */
  1216   1227   );
  1217   1228   
  1218   1229   /*

Changes to src/tclsqlite.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** A TCL Interface to SQLite
    13     13   **
    14         -** $Id: tclsqlite.c,v 1.65 2004/05/11 06:17:22 danielk1977 Exp $
           14  +** $Id: tclsqlite.c,v 1.66 2004/05/22 09:21:21 danielk1977 Exp $
    15     15   */
    16     16   #ifndef NO_TCL     /* Omit this whole file if TCL is unavailable */
    17     17   
    18     18   #include "sqliteInt.h"
    19     19   #include "tcl.h"
    20     20   #include <stdlib.h>
    21     21   #include <string.h>
................................................................................
  1016   1016   **  sqlite -tcl-uses-utf
  1017   1017   **
  1018   1018   **       Return "1" if compiled with a Tcl uses UTF-8.  Return "0" if
  1019   1019   **       not.  Used by tests to make sure the library was compiled 
  1020   1020   **       correctly.
  1021   1021   */
  1022   1022   static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
  1023         -  int mode;
  1024   1023     SqliteDb *p;
  1025   1024     void *pKey = 0;
  1026   1025     int nKey = 0;
  1027   1026     const char *zArg;
  1028   1027     char *zErrMsg;
  1029   1028     const char *zFile;
         1029  +  const char *zOpts[2] = {0, 0};
  1030   1030     char zBuf[80];
  1031   1031     if( objc==2 ){
  1032   1032       zArg = Tcl_GetStringFromObj(objv[1], 0);
  1033   1033       if( strcmp(zArg,"-encoding")==0 ){
  1034   1034         Tcl_AppendResult(interp,sqlite3_encoding,0);
  1035   1035         return TCL_OK;
  1036   1036       }
................................................................................
  1068   1068         "HANDLE FILENAME ?-key CODEC-KEY?"
  1069   1069   #else
  1070   1070         "HANDLE FILENAME ?MODE?"
  1071   1071   #endif
  1072   1072       );
  1073   1073       return TCL_ERROR;
  1074   1074     }
  1075         -  if( objc==3 ){
  1076         -    mode = 0666;
  1077         -  }else if( Tcl_GetIntFromObj(interp, objv[3], &mode)!=TCL_OK ){
  1078         -    return TCL_ERROR;
  1079         -  }
  1080   1075     zErrMsg = 0;
  1081   1076     p = (SqliteDb*)Tcl_Alloc( sizeof(*p) );
  1082   1077     if( p==0 ){
  1083   1078       Tcl_SetResult(interp, "malloc failed", TCL_STATIC);
  1084   1079       return TCL_ERROR;
  1085   1080     }
  1086   1081     memset(p, 0, sizeof(*p));
  1087   1082     zFile = Tcl_GetStringFromObj(objv[2], 0);
  1088   1083   #ifdef SQLITE_HAS_CODEC
  1089   1084     p->db = sqlite3_open_encrypted(zFile, pKey, nKey, 0, &zErrMsg);
  1090   1085   #else
  1091         -  p->db = sqlite3_open(zFile, mode, &zErrMsg);
         1086  +  if( objc>3 ){
         1087  +    zOpts[0] = Tcl_GetString(objv[3]);
         1088  +  }
         1089  +  sqlite3_open(zFile, &p->db, zOpts);
         1090  +  if( SQLITE_OK!=sqlite3_errcode(p->db) ){
         1091  +    zErrMsg = strdup(sqlite3_errmsg(p->db));
         1092  +    sqlite3_close(p->db);
         1093  +    p->db = 0;
         1094  +  }
  1092   1095   #endif
  1093   1096     if( p->db==0 ){
  1094   1097       Tcl_SetResult(interp, zErrMsg, TCL_VOLATILE);
  1095   1098       Tcl_Free((char*)p);
  1096   1099       free(zErrMsg);
  1097   1100       return TCL_ERROR;
  1098   1101     }

Changes to src/test1.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Code for testing the printf() interface to SQLite.  This code
    13     13   ** is not included in the SQLite library.  It is used for automated
    14     14   ** testing of the SQLite library.
    15     15   **
    16         -** $Id: test1.c,v 1.45 2004/05/21 10:08:54 danielk1977 Exp $
           16  +** $Id: test1.c,v 1.46 2004/05/22 09:21:21 danielk1977 Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "tcl.h"
    20     20   #include "os.h"
    21     21   #include <stdlib.h>
    22     22   #include <string.h>
    23     23   
................................................................................
  1363   1363     if( objc!=3 && objc!=2 ){
  1364   1364       Tcl_AppendResult(interp, "wrong # args: should be \"", 
  1365   1365          Tcl_GetString(objv[0]), " filename options-list", 0);
  1366   1366       return TCL_ERROR;
  1367   1367     }
  1368   1368   
  1369   1369     zFilename = Tcl_GetString(objv[1]);
  1370         -  rc = sqlite3_open_new(zFilename, &db, 0);
         1370  +  rc = sqlite3_open(zFilename, &db, 0);
  1371   1371     
  1372   1372     if( makePointerStr(interp, zBuf, db) ) return TCL_ERROR;
  1373   1373     Tcl_AppendResult(interp, zBuf, 0);
  1374   1374     return TCL_OK;
  1375   1375   }
  1376   1376   
  1377   1377   /*

Changes to src/test4.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Code for testing the the SQLite library in a multithreaded environment.
    13     13   **
    14         -** $Id: test4.c,v 1.5 2004/05/10 10:34:53 danielk1977 Exp $
           14  +** $Id: test4.c,v 1.6 2004/05/22 09:21:21 danielk1977 Exp $
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   #include "tcl.h"
    18     18   #if defined(OS_UNIX) && OS_UNIX==1 && defined(THREADSAFE) && THREADSAFE==1
    19     19   #include <stdlib.h>
    20     20   #include <string.h>
    21     21   #include <pthread.h>
................................................................................
    61     61   ** The main loop for a thread.  Threads use busy waiting. 
    62     62   */
    63     63   static void *thread_main(void *pArg){
    64     64     Thread *p = (Thread*)pArg;
    65     65     if( p->db ){
    66     66       sqlite3_close(p->db);
    67     67     }
    68         -  p->db = sqlite3_open(p->zFilename, 0, &p->zErr);
           68  +  sqlite3_open(p->zFilename, &p->db, 0);
           69  +  if( SQLITE_OK!=sqlite3_errcode(p->db) ){
           70  +    p->zErr = strdup(sqlite3_errmsg(p->db));
           71  +    sqlite3_close(p->db);
           72  +    p->db = 0;
           73  +  }
    69     74     p->vm = 0;
    70     75     p->completed = 1;
    71     76     while( p->opnum<=p->completed ) sched_yield();
    72     77     while( p->xOp ){
    73     78       if( p->zErr && p->zErr!=p->zStaticErr ){
    74     79         sqlite3_freemem(p->zErr);
    75     80         p->zErr = 0;

Changes to src/vacuum.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the VACUUM command.
    13     13   **
    14     14   ** Most of the code in this file may be omitted by defining the
    15     15   ** SQLITE_OMIT_VACUUM macro.
    16     16   **
    17         -** $Id: vacuum.c,v 1.15 2004/05/10 10:35:00 danielk1977 Exp $
           17  +** $Id: vacuum.c,v 1.16 2004/05/22 09:21:21 danielk1977 Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include "os.h"
    21     21   
    22     22   /*
    23     23   ** A structure for holding a dynamic string - a string that can grow
    24     24   ** without bound. 
................................................................................
   262    262     if( i>=10 ){
   263    263       sqlite3SetString(pzErrMsg, "unable to create a temporary database file "
   264    264          "in the same directory as the original database", (char*)0);
   265    265       goto end_of_vacuum;
   266    266     }
   267    267   
   268    268     
   269         -  dbNew = sqlite3_open(zTemp, 0, &zErrMsg);
   270         -  if( dbNew==0 ){
          269  +  if( SQLITE_OK!=sqlite3_open(zTemp, &dbNew, 0) ){
   271    270       sqlite3SetString(pzErrMsg, "unable to open a temporary database at ",
   272         -       zTemp, " - ", zErrMsg, (char*)0);
          271  +       zTemp, " - ", sqlite3_errmsg(dbNew), (char*)0);
   273    272       goto end_of_vacuum;
   274    273     }
   275    274     if( (rc = execsql(pzErrMsg, db, "BEGIN"))!=0 ) goto end_of_vacuum;
   276    275     if( (rc = execsql(pzErrMsg, dbNew, "PRAGMA synchronous=off; BEGIN"))!=0 ){
   277    276       goto end_of_vacuum;
   278    277     }
   279    278     
................................................................................
   309    308     }
   310    309     sqlite3_exec(db, "ROLLBACK", 0, 0, 0);
   311    310     if( dbNew ) sqlite3_close(dbNew);
   312    311     sqlite3OsDelete(zTemp);
   313    312     sqliteFree(zTemp);
   314    313     sqliteFree(sVac.s1.z);
   315    314     sqliteFree(sVac.s2.z);
          315  +  if( dbNew ) sqlite3_close(dbNew);
   316    316     if( zErrMsg ) sqlite3_freemem(zErrMsg);
   317    317     if( rc==SQLITE_ABORT ) sVac.rc = SQLITE_ERROR;
   318    318     return sVac.rc;
   319    319   #endif
   320    320   }
   321    321   
   322    322   
   323    323