/ Check-in [ce9c74ea]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:If any error occurs during sqlite3_open(), move the database handle into "sick" state. When in the sick state the user can use sqlite3_errcode() and sqlite3_errmsg(), but not much else. (CVS 5628)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ce9c74eaab459ddde213c828e821940f5d6cb354
User & Date: danielk1977 2008-08-27 19:01:58
Context
2008-08-28
02:26
Miscellaneous cleanup in the new pcache code. (CVS 5629) check-in: da177725 user: drh tags: trunk
2008-08-27
19:01
If any error occurs during sqlite3_open(), move the database handle into "sick" state. When in the sick state the user can use sqlite3_errcode() and sqlite3_errmsg(), but not much else. (CVS 5628) check-in: ce9c74ea user: danielk1977 tags: trunk
18:56
Add the trans2.test script designed to stress statement rollback and no-write optimizations on large transactions with a small cache. (CVS 5627) check-in: 39c34e22 user: drh 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.493 2008/08/21 20:21:35 drh Exp $
           17  +** $Id: main.c,v 1.494 2008/08/27 19:01:58 danielk1977 Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include <ctype.h>
    21     21   
    22     22   #ifdef SQLITE_ENABLE_FTS3
    23     23   # include "fts3.h"
    24     24   #endif
................................................................................
  1477   1477   #ifndef SQLITE_OMIT_VIRTUALTABLE
  1478   1478     sqlite3HashInit(&db->aModule, SQLITE_HASH_STRING, 0);
  1479   1479   #endif
  1480   1480   
  1481   1481     db->pVfs = sqlite3_vfs_find(zVfs);
  1482   1482     if( !db->pVfs ){
  1483   1483       rc = SQLITE_ERROR;
  1484         -    db->magic = SQLITE_MAGIC_SICK;
  1485   1484       sqlite3Error(db, rc, "no such vfs: %s", zVfs);
  1486   1485       goto opendb_out;
  1487   1486     }
  1488   1487   
  1489   1488     /* Add the default collation sequence BINARY. BINARY works for both UTF-8
  1490   1489     ** and UTF-16, so add a version for each to avoid any unnecessary
  1491   1490     ** conversions. The only error that can occur here is a malloc() failure.
  1492   1491     */
  1493   1492     createCollation(db, "BINARY", SQLITE_UTF8, 0, binCollFunc, 0);
  1494   1493     createCollation(db, "BINARY", SQLITE_UTF16BE, 0, binCollFunc, 0);
  1495   1494     createCollation(db, "BINARY", SQLITE_UTF16LE, 0, binCollFunc, 0);
  1496   1495     createCollation(db, "RTRIM", SQLITE_UTF8, (void*)1, binCollFunc, 0);
  1497   1496     if( db->mallocFailed ){
  1498         -    db->magic = SQLITE_MAGIC_SICK;
  1499   1497       goto opendb_out;
  1500   1498     }
  1501   1499     db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 6, 0);
  1502   1500     assert( db->pDfltColl!=0 );
  1503   1501   
  1504   1502     /* Also add a UTF-8 case-insensitive collation sequence. */
  1505   1503     createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
................................................................................
  1514   1512     /* Open the backend database driver */
  1515   1513     db->openFlags = flags;
  1516   1514     rc = sqlite3BtreeFactory(db, zFilename, 0, SQLITE_DEFAULT_CACHE_SIZE, 
  1517   1515                              flags | SQLITE_OPEN_MAIN_DB,
  1518   1516                              &db->aDb[0].pBt);
  1519   1517     if( rc!=SQLITE_OK ){
  1520   1518       sqlite3Error(db, rc, 0);
  1521         -    db->magic = SQLITE_MAGIC_SICK;
  1522   1519       goto opendb_out;
  1523   1520     }
  1524   1521     db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
  1525   1522     db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
  1526   1523   
  1527   1524   
  1528   1525     /* The default safety_level for the main database is 'full'; for the temp
................................................................................
  1604   1601     setupLookaside(db, 0, sqlite3Config.szLookaside, sqlite3Config.nLookaside);
  1605   1602   
  1606   1603   opendb_out:
  1607   1604     if( db ){
  1608   1605       assert( db->mutex!=0 || isThreadsafe==0 || sqlite3Config.bFullMutex==0 );
  1609   1606       sqlite3_mutex_leave(db->mutex);
  1610   1607     }
  1611         -  if( SQLITE_NOMEM==(rc = sqlite3_errcode(db)) ){
         1608  +  rc = sqlite3_errcode(db);
         1609  +  if( rc==SQLITE_NOMEM ){
  1612   1610       sqlite3_close(db);
  1613   1611       db = 0;
         1612  +  }else if( rc!=SQLITE_OK ){
         1613  +    db->magic = SQLITE_MAGIC_SICK;
  1614   1614     }
  1615   1615     *ppDb = db;
  1616   1616     return sqlite3ApiExit(0, rc);
  1617   1617   }
  1618   1618   
  1619   1619   /*
  1620   1620   ** Open a new database handle.

Changes to test/malloc.test.

    12     12   # This file attempts to check the behavior of the SQLite library in 
    13     13   # an out-of-memory situation. When compiled with -DSQLITE_DEBUG=1, 
    14     14   # the SQLite library accepts a special command (sqlite3_memdebug_fail N C)
    15     15   # which causes the N-th malloc to fail.  This special feature is used
    16     16   # to see what happens in the library if a malloc were to really fail
    17     17   # due to an out-of-memory situation.
    18     18   #
    19         -# $Id: malloc.test,v 1.63 2008/07/07 14:56:57 danielk1977 Exp $
           19  +# $Id: malloc.test,v 1.64 2008/08/27 19:01:58 danielk1977 Exp $
    20     20   
    21     21   set testdir [file dirname $argv0]
    22     22   source $testdir/tester.tcl
    23     23   
    24     24   
    25     25   # Only run these tests if memory debugging is turned on.
    26     26   #
................................................................................
   404    404       }
   405    405       sqlite3_extended_result_codes $DB2 1
   406    406     
   407    407       # Prepare statement
   408    408       set rc [catch {sqlite3_prepare $DB2 {SELECT * FROM sqlite_master} -1 X} msg]
   409    409       if {[sqlite3_errcode $DB2] eq "SQLITE_IOERR+12"} {
   410    410         error "out of memory"
          411  +    }
          412  +    if {[regexp ".*automatic extension loading.*" [sqlite3_errmsg $DB2]]} {
          413  +      error "out of memory"
   411    414       }
   412    415       if {$rc} {
   413    416         error [string range $msg 4 end]
   414    417       }
   415    418       set STMT $msg
   416    419     
   417    420       # Finalize statement