/ Check-in [4c6a90a1]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Add the sqlite3_extended_errcode() interface. Change to return SQLITE_BUSY instead of SQLITE_ERROR when a COMMIT is attempted and one or more queries are still pending. (CVS 5850)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4c6a90a16627b1664bf7f15ab40b440b3bd60b48
User & Date: drh 2008-10-30 15:03:16
Context
2008-10-30
17:21
Fix a crash that can follow a malloc failure in sqlite3ValueFromExpr(). Ticket #3468. (CVS 5851) check-in: 0996783b user: danielk1977 tags: trunk
15:03
Add the sqlite3_extended_errcode() interface. Change to return SQLITE_BUSY instead of SQLITE_ERROR when a COMMIT is attempted and one or more queries are still pending. (CVS 5850) check-in: 4c6a90a1 user: drh tags: trunk
2008-10-29
07:01
If a hot-journal file is detected but the application does not have the required read/write permissions, return SQLITE_CANTOPEN. Prior to this change, SQLITE_BUSY was returned. Ticket #3457. (CVS 5849) check-in: dc5308c7 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.508 2008/10/12 00:27:53 shane Exp $
           17  +** $Id: main.c,v 1.509 2008/10/30 15:03:16 drh 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
................................................................................
  1261   1261     if( db && !sqlite3SafetyCheckSickOrOk(db) ){
  1262   1262       return SQLITE_MISUSE;
  1263   1263     }
  1264   1264     if( !db || db->mallocFailed ){
  1265   1265       return SQLITE_NOMEM;
  1266   1266     }
  1267   1267     return db->errCode & db->errMask;
         1268  +}
         1269  +int sqlite3_extended_errcode(sqlite3 *db){
         1270  +  if( db && !sqlite3SafetyCheckSickOrOk(db) ){
         1271  +    return SQLITE_MISUSE;
         1272  +  }
         1273  +  if( !db || db->mallocFailed ){
         1274  +    return SQLITE_NOMEM;
         1275  +  }
         1276  +  return db->errCode;
  1268   1277   }
  1269   1278   
  1270   1279   /*
  1271   1280   ** Create a new collating function for database "db".  The name is zName
  1272   1281   ** and the encoding is enc.
  1273   1282   */
  1274   1283   static int createCollation(

Changes to src/sqlite.h.in.

    26     26   ** on how SQLite interfaces are suppose to operate.
    27     27   **
    28     28   ** The name of this file under configuration management is "sqlite.h.in".
    29     29   ** The makefile makes some minor changes to this file (such as inserting
    30     30   ** the version number) and changes its name to "sqlite3.h" as
    31     31   ** part of the build process.
    32     32   **
    33         -** @(#) $Id: sqlite.h.in,v 1.405 2008/10/17 15:10:37 drh Exp $
           33  +** @(#) $Id: sqlite.h.in,v 1.406 2008/10/30 15:03:16 drh Exp $
    34     34   */
    35     35   #ifndef _SQLITE3_H_
    36     36   #define _SQLITE3_H_
    37     37   #include <stdarg.h>     /* Needed for the definition of va_list */
    38     38   
    39     39   /*
    40     40   ** Make sure we can call this stuff from C++.
................................................................................
   374    374   **          in *E an appropriate error message written into memory obtained
   375    375   **          from [sqlite3_malloc()].
   376    376   **
   377    377   ** {H12134} The [sqlite3_exec(D,S,C,A,E)] routine shall set the value of
   378    378   **          *E to NULL if E is not NULL and there are no errors.
   379    379   **
   380    380   ** {H12137} The [sqlite3_exec(D,S,C,A,E)] function shall set the [error code]
   381         -**          and message accessible via [sqlite3_errcode()],
          381  +**          and message accessible via [sqlite3_errcode()], 
          382  +**          [sqlite3_extended_errcode()],
   382    383   **          [sqlite3_errmsg()], and [sqlite3_errmsg16()].
   383    384   **
   384    385   ** {H12138} If the S parameter to [sqlite3_exec(D,S,C,A,E)] is NULL or an
   385    386   **          empty string or contains nothing other than whitespace, comments,
   386    387   **          and/or semicolons, then results of [sqlite3_errcode()],
          388  +**          [sqlite3_extended_errcode()],
   387    389   **          [sqlite3_errmsg()], and [sqlite3_errmsg16()]
   388    390   **          shall reset to indicate no errors.
   389    391   **
   390    392   ** ASSUMPTIONS:
   391    393   **
   392    394   ** {A12141} The first parameter to [sqlite3_exec()] must be an valid and open
   393    395   **          [database connection].
................................................................................
  2654   2656   /*
  2655   2657   ** CAPI3REF: Error Codes And Messages {H12800} <S60200>
  2656   2658   **
  2657   2659   ** The sqlite3_errcode() interface returns the numeric [result code] or
  2658   2660   ** [extended result code] for the most recent failed sqlite3_* API call
  2659   2661   ** associated with a [database connection]. If a prior API call failed
  2660   2662   ** but the most recent API call succeeded, the return value from
  2661         -** sqlite3_errcode() is undefined.
         2663  +** sqlite3_errcode() is undefined.  The sqlite3_extended_errcode()
         2664  +** interface is the same except that it always returns the 
         2665  +** [extended result code] even when extended result codes are
         2666  +** disabled.
  2662   2667   **
  2663   2668   ** The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
  2664   2669   ** text that describes the error, as either UTF-8 or UTF-16 respectively.
  2665   2670   ** Memory to hold the error message string is managed internally.
  2666   2671   ** The application does not need to worry about freeing the result.
  2667   2672   ** However, the error string might be overwritten or deallocated by
  2668   2673   ** subsequent calls to other SQLite interface functions.
................................................................................
  2673   2678   **
  2674   2679   ** INVARIANTS:
  2675   2680   **
  2676   2681   ** {H12801} The [sqlite3_errcode(D)] interface returns the numeric
  2677   2682   **          [result code] or [extended result code] for the most recently
  2678   2683   **          failed interface call associated with the [database connection] D.
  2679   2684   **
         2685  +** {H12802} The [sqlite3_extended_errcode(D)] interface returns the numeric
         2686  +**          [extended result code] for the most recently
         2687  +**          failed interface call associated with the [database connection] D.
         2688  +**
  2680   2689   ** {H12803} The [sqlite3_errmsg(D)] and [sqlite3_errmsg16(D)]
  2681   2690   **          interfaces return English-language text that describes
  2682   2691   **          the error in the mostly recently failed interface call,
  2683   2692   **          encoded as either UTF-8 or UTF-16 respectively.
  2684   2693   **
  2685   2694   ** {H12807} The strings returned by [sqlite3_errmsg()] and [sqlite3_errmsg16()]
  2686   2695   **          are valid until the next SQLite interface call.
  2687   2696   **
  2688   2697   ** {H12808} Calls to API routines that do not return an error code
  2689   2698   **          (example: [sqlite3_data_count()]) do not
  2690   2699   **          change the error code or message returned by
  2691         -**          [sqlite3_errcode()], [sqlite3_errmsg()], or [sqlite3_errmsg16()].
         2700  +**          [sqlite3_errcode()], [sqlite3_extended_errcode()],
         2701  +**          [sqlite3_errmsg()], or [sqlite3_errmsg16()].
  2692   2702   **
  2693   2703   ** {H12809} Interfaces that are not associated with a specific
  2694   2704   **          [database connection] (examples:
  2695   2705   **          [sqlite3_mprintf()] or [sqlite3_enable_shared_cache()]
  2696   2706   **          do not change the values returned by
  2697         -**          [sqlite3_errcode()], [sqlite3_errmsg()], or [sqlite3_errmsg16()].
         2707  +**          [sqlite3_errcode()], [sqlite3_extended_errcode()],
         2708  +**          [sqlite3_errmsg()], or [sqlite3_errmsg16()].
  2698   2709   */
  2699   2710   int sqlite3_errcode(sqlite3 *db);
         2711  +int sqlite3_extended_errcode(sqlite3 *db);
  2700   2712   const char *sqlite3_errmsg(sqlite3*);
  2701   2713   const void *sqlite3_errmsg16(sqlite3*);
  2702   2714   
  2703   2715   /*
  2704   2716   ** CAPI3REF: SQL Statement Object {H13000} <H13010>
  2705   2717   ** KEYWORDS: {prepared statement} {prepared statements}
  2706   2718   **
................................................................................
  5761   5773   **          parameter is non-zero.
  5762   5774   **
  5763   5775   ** {H17819} The [sqlite3_blob_open()] interface shall return [SQLITE_OK] on
  5764   5776   **          success and an appropriate [error code] on failure.
  5765   5777   **
  5766   5778   ** {H17821} If an error occurs during evaluation of [sqlite3_blob_open(D,...)]
  5767   5779   **          then subsequent calls to [sqlite3_errcode(D)],
         5780  +**          [sqlite3_extended_errcode()], 
  5768   5781   **          [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return
  5769   5782   **          information appropriate for that error.
  5770   5783   **
  5771   5784   ** {H17824} If any column in the row that a [sqlite3_blob] has open is
  5772   5785   **          changed by a separate [UPDATE] or [DELETE] statement or by
  5773   5786   **          an [ON CONFLICT] side effect, then the [sqlite3_blob] shall
  5774   5787   **          be marked as invalid.
................................................................................
  5874   5887   **
  5875   5888   ** {H17865} If the requested read could not be completed,
  5876   5889   **          the [sqlite3_blob_read(P,Z,N,X)] interface shall return an
  5877   5890   **          appropriate [error code] or [extended error code].
  5878   5891   **
  5879   5892   ** {H17868} If an error occurs during evaluation of [sqlite3_blob_read(P,...)]
  5880   5893   **          then subsequent calls to [sqlite3_errcode(D)],
         5894  +**          [sqlite3_extended_errcode()],
  5881   5895   **          [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return
  5882   5896   **          information appropriate for that error, where D is the
  5883   5897   **          [database connection] that was used to open the [BLOB handle] P.
  5884   5898   */
  5885   5899   int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
  5886   5900   
  5887   5901   /*
................................................................................
  5943   5957   **
  5944   5958   ** {H17885} If the requested write could not be completed,
  5945   5959   **          the [sqlite3_blob_write(P,Z,N,X)] interface shall return an
  5946   5960   **          appropriate [error code] or [extended error code].
  5947   5961   **
  5948   5962   ** {H17888} If an error occurs during evaluation of [sqlite3_blob_write(D,...)]
  5949   5963   **          then subsequent calls to [sqlite3_errcode(D)],
         5964  +**          [sqlite3_extended_errcode()],
  5950   5965   **          [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return
  5951   5966   **          information appropriate for that error.
  5952   5967   */
  5953   5968   int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
  5954   5969   
  5955   5970   /*
  5956   5971   ** CAPI3REF: Virtual File System Objects {H11200} <S20100>

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 all sorts of SQLite interfaces.  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.328 2008/10/12 00:27:54 shane Exp $
           16  +** $Id: test1.c,v 1.329 2008/10/30 15:03:16 drh Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "tcl.h"
    20     20   #include <stdlib.h>
    21     21   #include <string.h>
    22     22   
    23     23   /*
................................................................................
   113    113     }
   114    114     return TCL_OK;
   115    115   }
   116    116   
   117    117   
   118    118   const char *sqlite3TestErrorName(int rc){
   119    119     const char *zName = 0;
   120         -  switch( rc & 0xff ){
   121         -    case SQLITE_OK:         zName = "SQLITE_OK";          break;
   122         -    case SQLITE_ERROR:      zName = "SQLITE_ERROR";       break;
   123         -    case SQLITE_PERM:       zName = "SQLITE_PERM";        break;
   124         -    case SQLITE_ABORT:      zName = "SQLITE_ABORT";       break;
   125         -    case SQLITE_BUSY:       zName = "SQLITE_BUSY";        break;
   126         -    case SQLITE_LOCKED:     zName = "SQLITE_LOCKED";      break;
   127         -    case SQLITE_NOMEM:      zName = "SQLITE_NOMEM";       break;
   128         -    case SQLITE_READONLY:   zName = "SQLITE_READONLY";    break;
   129         -    case SQLITE_INTERRUPT:  zName = "SQLITE_INTERRUPT";   break;
   130         -    case SQLITE_IOERR:      zName = "SQLITE_IOERR";       break;
   131         -    case SQLITE_CORRUPT:    zName = "SQLITE_CORRUPT";     break;
   132         -    case SQLITE_FULL:       zName = "SQLITE_FULL";        break;
   133         -    case SQLITE_CANTOPEN:   zName = "SQLITE_CANTOPEN";    break;
   134         -    case SQLITE_PROTOCOL:   zName = "SQLITE_PROTOCOL";    break;
   135         -    case SQLITE_EMPTY:      zName = "SQLITE_EMPTY";       break;
   136         -    case SQLITE_SCHEMA:     zName = "SQLITE_SCHEMA";      break;
   137         -    case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT";  break;
   138         -    case SQLITE_MISMATCH:   zName = "SQLITE_MISMATCH";    break;
   139         -    case SQLITE_MISUSE:     zName = "SQLITE_MISUSE";      break;
   140         -    case SQLITE_NOLFS:      zName = "SQLITE_NOLFS";       break;
   141         -    case SQLITE_AUTH:       zName = "SQLITE_AUTH";        break;
   142         -    case SQLITE_FORMAT:     zName = "SQLITE_FORMAT";      break;
   143         -    case SQLITE_RANGE:      zName = "SQLITE_RANGE";       break;
   144         -    case SQLITE_ROW:        zName = "SQLITE_ROW";         break;
   145         -    case SQLITE_DONE:       zName = "SQLITE_DONE";        break;
   146         -    case SQLITE_NOTADB:     zName = "SQLITE_NOTADB";      break;
   147         -    case SQLITE_TOOBIG:     zName = "SQLITE_TOOBIG";      break;
   148         -    default:                zName = "SQLITE_Unknown";     break;
          120  +  switch( rc ){
          121  +    case SQLITE_OK:                  zName = "SQLITE_OK";                break;
          122  +    case SQLITE_ERROR:               zName = "SQLITE_ERROR";             break;
          123  +    case SQLITE_INTERNAL:            zName = "SQLITE_INTERNAL";          break;
          124  +    case SQLITE_PERM:                zName = "SQLITE_PERM";              break;
          125  +    case SQLITE_ABORT:               zName = "SQLITE_ABORT";             break;
          126  +    case SQLITE_BUSY:                zName = "SQLITE_BUSY";              break;
          127  +    case SQLITE_LOCKED:              zName = "SQLITE_LOCKED";            break;
          128  +    case SQLITE_NOMEM:               zName = "SQLITE_NOMEM";             break;
          129  +    case SQLITE_READONLY:            zName = "SQLITE_READONLY";          break;
          130  +    case SQLITE_INTERRUPT:           zName = "SQLITE_INTERRUPT";         break;
          131  +    case SQLITE_IOERR:               zName = "SQLITE_IOERR";             break;
          132  +    case SQLITE_CORRUPT:             zName = "SQLITE_CORRUPT";           break;
          133  +    case SQLITE_NOTFOUND:            zName = "SQLITE_NOTFOUND";          break;
          134  +    case SQLITE_FULL:                zName = "SQLITE_FULL";              break;
          135  +    case SQLITE_CANTOPEN:            zName = "SQLITE_CANTOPEN";          break;
          136  +    case SQLITE_PROTOCOL:            zName = "SQLITE_PROTOCOL";          break;
          137  +    case SQLITE_EMPTY:               zName = "SQLITE_EMPTY";             break;
          138  +    case SQLITE_SCHEMA:              zName = "SQLITE_SCHEMA";            break;
          139  +    case SQLITE_TOOBIG:              zName = "SQLITE_TOOBIG";            break;
          140  +    case SQLITE_CONSTRAINT:          zName = "SQLITE_CONSTRAINT";        break;
          141  +    case SQLITE_MISMATCH:            zName = "SQLITE_MISMATCH";          break;
          142  +    case SQLITE_MISUSE:              zName = "SQLITE_MISUSE";            break;
          143  +    case SQLITE_NOLFS:               zName = "SQLITE_NOLFS";             break;
          144  +    case SQLITE_AUTH:                zName = "SQLITE_AUTH";              break;
          145  +    case SQLITE_FORMAT:              zName = "SQLITE_FORMAT";            break;
          146  +    case SQLITE_RANGE:               zName = "SQLITE_RANGE";             break;
          147  +    case SQLITE_NOTADB:              zName = "SQLITE_NOTADB";            break;
          148  +    case SQLITE_ROW:                 zName = "SQLITE_ROW";               break;
          149  +    case SQLITE_DONE:                zName = "SQLITE_DONE";              break;
          150  +    case SQLITE_IOERR_READ:          zName = "SQLITE_IOERR_READ";        break;
          151  +    case SQLITE_IOERR_SHORT_READ:    zName = "SQLITE_IOERR_SHORT_READ";  break;
          152  +    case SQLITE_IOERR_WRITE:         zName = "SQLITE_IOERR_WRITE";       break;
          153  +    case SQLITE_IOERR_FSYNC:         zName = "SQLITE_IOERR_FSYNC";       break;
          154  +    case SQLITE_IOERR_DIR_FSYNC:     zName = "SQLITE_IOERR_DIR_FSYNC";   break;
          155  +    case SQLITE_IOERR_TRUNCATE:      zName = "SQLITE_IOERR_TRUNCATE";    break;
          156  +    case SQLITE_IOERR_FSTAT:         zName = "SQLITE_IOERR_FSTAT";       break;
          157  +    case SQLITE_IOERR_UNLOCK:        zName = "SQLITE_IOERR_UNLOCK";      break;
          158  +    case SQLITE_IOERR_RDLOCK:        zName = "SQLITE_IOERR_RDLOCK";      break;
          159  +    case SQLITE_IOERR_DELETE:        zName = "SQLITE_IOERR_DELETE";      break;
          160  +    case SQLITE_IOERR_BLOCKED:       zName = "SQLITE_IOERR_BLOCKED";     break;
          161  +    case SQLITE_IOERR_NOMEM:         zName = "SQLITE_IOERR_NOMEM";       break;
          162  +    case SQLITE_IOERR_ACCESS:        zName = "SQLITE_IOERR_ACCESS";      break;
          163  +    case SQLITE_IOERR_CHECKRESERVEDLOCK:
          164  +                               zName = "SQLITE_IOERR_CHECKRESERVEDLOCK"; break;
          165  +    case SQLITE_IOERR_LOCK:          zName = "SQLITE_IOERR_LOCK";        break;
          166  +    default:                         zName = "SQLITE_Unknown";           break;
   149    167     }
   150    168     return zName;
   151    169   }
   152    170   #define t1ErrorName sqlite3TestErrorName
   153    171   
   154    172   /*
   155    173   ** Convert an sqlite3_stmt* into an sqlite3*.  This depends on the
................................................................................
  3059   3077     }
  3060   3078     if( Tcl_GetIntFromObj(interp, objv[1], &ms) ){
  3061   3079       return TCL_ERROR;
  3062   3080     }
  3063   3081     Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_sleep(ms)));
  3064   3082     return TCL_OK;
  3065   3083   }
         3084  +
         3085  +/*
         3086  +** Usage: sqlite3_extended_errcode DB
         3087  +**
         3088  +** Return the string representation of the most recent sqlite3_* API
         3089  +** error code. e.g. "SQLITE_ERROR".
         3090  +*/
         3091  +static int test_ex_errcode(
         3092  +  void * clientData,
         3093  +  Tcl_Interp *interp,
         3094  +  int objc,
         3095  +  Tcl_Obj *CONST objv[]
         3096  +){
         3097  +  sqlite3 *db;
         3098  +  int rc;
         3099  +
         3100  +  if( objc!=2 ){
         3101  +    Tcl_AppendResult(interp, "wrong # args: should be \"", 
         3102  +       Tcl_GetString(objv[0]), " DB", 0);
         3103  +    return TCL_ERROR;
         3104  +  }
         3105  +  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
         3106  +  rc = sqlite3_extended_errcode(db);
         3107  +  Tcl_AppendResult(interp, (char *)t1ErrorName(rc), 0);
         3108  +  return TCL_OK;
         3109  +}
         3110  +
  3066   3111   
  3067   3112   /*
  3068   3113   ** Usage: sqlite3_errcode DB
  3069   3114   **
  3070   3115   ** Return the string representation of the most recent sqlite3_* API
  3071   3116   ** error code. e.g. "SQLITE_ERROR".
  3072   3117   */
................................................................................
  3074   3119     void * clientData,
  3075   3120     Tcl_Interp *interp,
  3076   3121     int objc,
  3077   3122     Tcl_Obj *CONST objv[]
  3078   3123   ){
  3079   3124     sqlite3 *db;
  3080   3125     int rc;
  3081         -  char zBuf[30];
  3082   3126   
  3083   3127     if( objc!=2 ){
  3084   3128       Tcl_AppendResult(interp, "wrong # args: should be \"", 
  3085   3129          Tcl_GetString(objv[0]), " DB", 0);
  3086   3130       return TCL_ERROR;
  3087   3131     }
  3088   3132     if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
  3089   3133     rc = sqlite3_errcode(db);
  3090         -  if( (rc&0xff)==rc ){
  3091         -    zBuf[0] = 0;
  3092         -  }else{
  3093         -    sprintf(zBuf,"+%d", rc>>8);
  3094         -  }
  3095         -  Tcl_AppendResult(interp, (char *)t1ErrorName(rc), zBuf, 0);
         3134  +  Tcl_AppendResult(interp, (char *)t1ErrorName(rc), 0);
  3096   3135     return TCL_OK;
  3097   3136   }
  3098   3137   
  3099   3138   /*
  3100   3139   ** Usage:   test_errmsg DB
  3101   3140   **
  3102   3141   ** Returns the UTF-8 representation of the error message string for the
................................................................................
  4663   4702        { "sqlite3_bind_blob",             test_bind_blob     ,0 },
  4664   4703        { "sqlite3_bind_parameter_count",  test_bind_parameter_count, 0},
  4665   4704        { "sqlite3_bind_parameter_name",   test_bind_parameter_name,  0},
  4666   4705        { "sqlite3_bind_parameter_index",  test_bind_parameter_index, 0},
  4667   4706        { "sqlite3_clear_bindings",        test_clear_bindings, 0},
  4668   4707        { "sqlite3_sleep",                 test_sleep,          0},
  4669   4708        { "sqlite3_errcode",               test_errcode       ,0 },
         4709  +     { "sqlite3_extended_errcode",      test_ex_errcode    ,0 },
  4670   4710        { "sqlite3_errmsg",                test_errmsg        ,0 },
  4671   4711        { "sqlite3_errmsg16",              test_errmsg16      ,0 },
  4672   4712        { "sqlite3_open",                  test_open          ,0 },
  4673   4713        { "sqlite3_open16",                test_open16        ,0 },
  4674   4714        { "sqlite3_complete16",            test_complete16    ,0 },
  4675   4715   
  4676   4716        { "sqlite3_prepare",               test_prepare       ,0 },

Changes to src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.783 2008/10/27 13:59:34 danielk1977 Exp $
           46  +** $Id: vdbe.c,v 1.784 2008/10/30 15:03:16 drh Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include <ctype.h>
    50     50   #include "vdbeInt.h"
    51     51   
    52     52   /*
    53     53   ** The following global variable is incremented every time a cursor
................................................................................
  2407   2407       /* If this instruction implements a COMMIT or ROLLBACK, other VMs are
  2408   2408       ** still running, and a transaction is active, return an error indicating
  2409   2409       ** that the other VMs must complete first. 
  2410   2410       */
  2411   2411       sqlite3SetString(&p->zErrMsg, db, "cannot %s transaction - "
  2412   2412           "SQL statements in progress",
  2413   2413           rollback ? "rollback" : "commit");
  2414         -    rc = SQLITE_ERROR;
         2414  +    rc = SQLITE_BUSY;
  2415   2415     }else if( i!=db->autoCommit ){
  2416   2416       if( pOp->p2 ){
  2417   2417         assert( i==1 );
  2418   2418         sqlite3RollbackAll(db);
  2419   2419         db->autoCommit = 1;
  2420   2420       }else{
  2421   2421         db->autoCommit = i;

Changes to test/capi3.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script testing the callback-free C/C++ API.
    13     13   #
    14         -# $Id: capi3.test,v 1.67 2008/07/12 15:55:55 danielk1977 Exp $
           14  +# $Id: capi3.test,v 1.68 2008/10/30 15:03:16 drh Exp $
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Return the UTF-16 representation of the supplied UTF-8 string $str.
    21     21   # If $nt is true, append two 0x00 bytes as a nul terminator.
................................................................................
    57     57     sqlite3_get_autocommit $DB
    58     58   } 1
    59     59   do_test capi3-1.1 {
    60     60     set STMT [sqlite3_prepare $DB {SELECT name FROM sqlite_master} -1 TAIL]
    61     61     sqlite3_finalize $STMT
    62     62     set TAIL
    63     63   } {}
    64         -do_test capi3-1.2 {
           64  +do_test capi3-1.2.1 {
    65     65     sqlite3_errcode $DB
    66     66   } {SQLITE_OK}
           67  +do_test capi3-1.2.2 {
           68  +  sqlite3_extended_errcode $DB
           69  +} {SQLITE_OK}
    67     70   do_test capi3-1.3 {
    68     71     sqlite3_errmsg $DB
    69     72   } {not an error}
    70     73   do_test capi3-1.4 {
    71     74     set sql {SELECT name FROM sqlite_master;SELECT 10}
    72     75     set STMT [sqlite3_prepare $DB $sql -1 TAIL]
    73     76     sqlite3_finalize $STMT
................................................................................
    88     91   
    89     92   do_test capi3-1.7 {
    90     93     set sql {SELECT namex FROM sqlite_master}
    91     94     catch {
    92     95       set STMT [sqlite3_prepare $DB $sql -1 TAIL]
    93     96     }
    94     97   } {1}
    95         -do_test capi3-1.8 {
           98  +do_test capi3-1.8.1 {
    96     99     sqlite3_errcode $DB
    97    100   } {SQLITE_ERROR}
          101  +do_test capi3-1.8.2 {
          102  +  sqlite3_extended_errcode $DB
          103  +} {SQLITE_ERROR}
    98    104   do_test capi3-1.9 {
    99    105     sqlite3_errmsg $DB
   100    106   } {no such column: namex}
   101    107   
   102    108   ifcapable {utf16} {
   103    109     do_test capi3-2.1 {
   104    110       set sql16 [utf16 {SELECT name FROM sqlite_master}]
................................................................................
   114    120     } {SELECT 10}
   115    121     do_test capi3-2.3 {
   116    122       set sql [utf16 {SELECT namex FROM sqlite_master}]
   117    123       catch {
   118    124         set STMT [sqlite3_prepare16 $DB $sql -1 TAIL]
   119    125       }
   120    126     } {1}
   121         -  do_test capi3-2.4 {
          127  +  do_test capi3-2.4.1 {
   122    128       sqlite3_errcode $DB
   123    129     } {SQLITE_ERROR}
          130  +  do_test capi3-2.4.2 {
          131  +    sqlite3_extended_errcode $DB
          132  +  } {SQLITE_ERROR}
   124    133     do_test capi3-2.5 {
   125    134       sqlite3_errmsg $DB
   126    135     } {no such column: namex}
   127    136   
   128    137     ifcapable schema_pragmas {
   129    138       do_test capi3-2.6 {
   130    139         execsql {CREATE TABLE tablename(x)}
................................................................................
   153    162   do_test capi3-3.2 {
   154    163     sqlite3_close $db2
   155    164   } {SQLITE_OK}
   156    165   do_test capi3-3.3 {
   157    166     catch {
   158    167       set db2 [sqlite3_open /bogus/path/test.db {}]
   159    168     }
   160         -  sqlite3_errcode $db2
          169  +  sqlite3_extended_errcode $db2
   161    170   } {SQLITE_CANTOPEN}
   162    171   do_test capi3-3.4 {
   163    172     sqlite3_errmsg $db2
   164    173   } {unable to open database file}
   165    174   do_test capi3-3.5 {
   166    175     sqlite3_close $db2
   167    176   } {SQLITE_OK}
................................................................................
   820    829   do_test capi3-11.1.1 {
   821    830     sqlite3_get_autocommit $DB
   822    831   } 0
   823    832   do_test capi3-11.2 {
   824    833     set STMT [sqlite3_prepare $DB "SELECT func(b, a) FROM t1" -1 TAIL]
   825    834     sqlite3_step $STMT
   826    835   } {SQLITE_ROW}
   827         -do_test capi3-11.3 {
          836  +do_test capi3-11.3.1 {
   828    837     catchsql {
   829    838       COMMIT;
   830    839     }
   831    840   } {1 {cannot commit transaction - SQL statements in progress}}
   832         -do_test capi3-11.3.1 {
          841  +do_test capi3-11.3.2 {
          842  +  sqlite3_extended_errcode $DB
          843  +} {SQLITE_BUSY}
          844  +do_test capi3-11.3.3 {
   833    845     sqlite3_get_autocommit $DB
   834    846   } 0
   835    847   do_test capi3-11.4 {
   836    848     sqlite3_step $STMT
   837    849   } {SQLITE_ERROR}
   838    850   do_test capi3-11.5 {
   839    851     sqlite3_finalize $STMT

Changes to test/capi3c.test.

     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  
    12     12   #
    13     13   # This is a copy of the capi3.test file that has been adapted to
    14     14   # test the new sqlite3_prepare_v2 interface.
    15     15   #
    16         -# $Id: capi3c.test,v 1.20 2008/10/12 00:27:54 shane Exp $
           16  +# $Id: capi3c.test,v 1.21 2008/10/30 15:03:16 drh Exp $
    17     17   #
    18     18   
    19     19   set testdir [file dirname $argv0]
    20     20   source $testdir/tester.tcl
    21     21   
    22     22   # Return the UTF-16 representation of the supplied UTF-8 string $str.
    23     23   # If $nt is true, append two 0x00 bytes as a nul terminator.
................................................................................
    59     59     sqlite3_get_autocommit $DB
    60     60   } 1
    61     61   do_test capi3c-1.1 {
    62     62     set STMT [sqlite3_prepare_v2 $DB {SELECT name FROM sqlite_master} -1 TAIL]
    63     63     sqlite3_finalize $STMT
    64     64     set TAIL
    65     65   } {}
    66         -do_test capi3c-1.2 {
           66  +do_test capi3c-1.2.1 {
    67     67     sqlite3_errcode $DB
    68     68   } {SQLITE_OK}
           69  +do_test capi3c-1.2.2 {
           70  +  sqlite3_extended_errcode $DB
           71  +} {SQLITE_OK}
    69     72   do_test capi3c-1.3 {
    70     73     sqlite3_errmsg $DB
    71     74   } {not an error}
    72     75   do_test capi3c-1.4 {
    73     76     set sql {SELECT name FROM sqlite_master;SELECT 10}
    74     77     set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL]
    75     78     sqlite3_finalize $STMT
................................................................................
    77     80   } {SELECT 10}
    78     81   do_test capi3c-1.5 {
    79     82     set sql {SELECT namex FROM sqlite_master}
    80     83     catch {
    81     84       set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL]
    82     85     }
    83     86   } {1}
    84         -do_test capi3c-1.6 {
           87  +do_test capi3c-1.6.1 {
    85     88     sqlite3_errcode $DB
    86     89   } {SQLITE_ERROR}
           90  +do_test capi3c-1.6.2 {
           91  +  sqlite3_extended_errcode $DB
           92  +} {SQLITE_ERROR}
    87     93   do_test capi3c-1.7 {
    88     94     sqlite3_errmsg $DB
    89     95   } {no such column: namex}
    90     96   
    91     97   
    92     98   ifcapable {utf16} {
    93     99     do_test capi3c-2.1 {
................................................................................
   104    110     } {SELECT 10}
   105    111     do_test capi3c-2.3 {
   106    112       set sql [utf16 {SELECT namex FROM sqlite_master}]
   107    113       catch {
   108    114         set STMT [sqlite3_prepare16_v2  $DB $sql -1 TAIL]
   109    115       }
   110    116     } {1}
   111         -  do_test capi3c-2.4 {
          117  +  do_test capi3c-2.4.1 {
   112    118       sqlite3_errcode $DB
   113    119     } {SQLITE_ERROR}
          120  +  do_test capi3c-2.4.2 {
          121  +    sqlite3_extended_errcode $DB
          122  +  } {SQLITE_ERROR}
   114    123     do_test capi3c-2.5 {
   115    124       sqlite3_errmsg $DB
   116    125     } {no such column: namex}
   117    126   
   118    127     ifcapable schema_pragmas {
   119    128       do_test capi3c-2.6 {
   120    129         execsql {CREATE TABLE tablename(x)}
................................................................................
  1227   1236   ifcapable progress {
  1228   1237     do_test capi3c-21.1 {
  1229   1238       set STMT [sqlite3_prepare_v2 $DB {SELECT * FROM t3} -1 TAIL]
  1230   1239       db progress 5 "expr 1"
  1231   1240       sqlite3_step $STMT
  1232   1241     } {SQLITE_INTERRUPT}
  1233   1242     do_test capi3c-21.2 {
  1234         -    sqlite3_errcode $DB
         1243  +    sqlite3_extended_errcode $DB
  1235   1244     } {SQLITE_INTERRUPT}
  1236   1245     do_test capi3c-21.3 {
  1237   1246       sqlite3_finalize $STMT
  1238   1247     } {SQLITE_INTERRUPT}
  1239   1248     do_test capi3c-21.4 {
  1240   1249       set STMT [sqlite3_prepare $DB {SELECT * FROM t3} -1 TAIL]
  1241   1250       db progress 5 "expr 1"
................................................................................
  1246   1255     } {SQLITE_ERROR}
  1247   1256     do_test capi3c-21.6 {
  1248   1257       sqlite3_finalize $STMT
  1249   1258     } {SQLITE_INTERRUPT}
  1250   1259     do_test capi3c-21.7 {
  1251   1260       sqlite3_errcode $DB
  1252   1261     } {SQLITE_INTERRUPT}
         1262  +  do_test capi3c-21.8 {
         1263  +    sqlite3_extended_errcode $DB
         1264  +  } {SQLITE_INTERRUPT}
  1253   1265   }
  1254   1266   
  1255   1267   # Make sure sqlite3_result_error_code() returns the correct error code.
  1256   1268   # See ticket #2940
  1257   1269   #
  1258   1270   do_test capi3c-22.1 {
  1259   1271     db progress 0 {}

Changes to test/misc7.test.

     6      6   #    May you do good and not evil.
     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13         -# $Id: misc7.test,v 1.24 2008/08/22 13:57:39 pweilbacher Exp $
           13  +# $Id: misc7.test,v 1.25 2008/10/30 15:03:16 drh Exp $
    14     14   
    15     15   set testdir [file dirname $argv0]
    16     16   source $testdir/tester.tcl
    17     17   
    18     18   do_test misc7-1-misuse {
    19     19     c_misuse_test
    20     20   } {}
................................................................................
   393    393         sqlite3 db test.db
   394    394       
   395    395         catch {file attributes test.db-journal -permissions r--------}
   396    396         catch {file attributes test.db-journal -readonly 1}
   397    397         catchsql {
   398    398           SELECT count(*) FROM t3;
   399    399         }
   400         -    } {1 {database is locked}}
          400  +    } {1 {unable to open database file}}
   401    401       do_test misc7-17.2 {
   402    402         # Note that the -readonly flag must be cleared before the -permissions
   403    403         # are set. Otherwise, when using tcl 8.5 on mac, the fact that the 
   404    404         # -readonly flag is set causes the attempt to set the permissions
   405    405         # to fail.
   406    406         catch {file attributes test.db-journal -readonly 0}
   407    407         catch {file attributes test.db-journal -permissions rw-------}