/ Check-in [307b5500]
Login

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

Overview
Comment:Add new sqlite3_open() and sqlite3_open16() APIs. (CVS 1423)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 307b55006c401f10ec5fa5b12cc7d5ba860f9a46
User & Date: danielk1977 2004-05-21 01:47:27
Context
2004-05-21
02:11
Fix typo in bind.test that was causing a seg-fault. (CVS 1424) check-in: d1af1a4a user: danielk1977 tags: trunk
01:47
Add new sqlite3_open() and sqlite3_open16() APIs. (CVS 1423) check-in: 307b5500 user: danielk1977 tags: trunk
01:29
Sorting bug fixes. Now only 17 tests fail. (CVS 1422) check-in: 0736b7e8 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.178 2004/05/20 22:16:29 drh Exp $
           17  +** $Id: main.c,v 1.179 2004/05/21 01:47:27 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
................................................................................
  1051   1051     if( !zFilename ){
  1052   1052       btree_flags |= BTREE_MEMORY;
  1053   1053     }
  1054   1054   
  1055   1055     return sqlite3BtreeOpen(zFilename, ppBtree, nCache, btree_flags);
  1056   1056   }
  1057   1057   
         1058  +/*
         1059  +** Return UTF-8 encoded English language explanation of the most recent
         1060  +** error.
         1061  +*/
  1058   1062   const char *sqlite3_errmsg(sqlite3 *db){
         1063  +  if( !db ){
         1064  +    /* If db is NULL, then assume that a malloc() failed during an
         1065  +    ** sqlite3_open() call.
         1066  +    */
         1067  +    return sqlite3_error_string(SQLITE_NOMEM);
         1068  +  }
  1059   1069     if( db->zErrMsg ){
  1060   1070       return db->zErrMsg;
  1061   1071     }
  1062   1072     return sqlite3_error_string(db->errCode);
  1063   1073   }
  1064   1074   
         1075  +/*
         1076  +** Return UTF-16 encoded English language explanation of the most recent
         1077  +** error.
         1078  +*/
  1065   1079   const void *sqlite3_errmsg16(sqlite3 *db){
         1080  +  if( !db ){
         1081  +    /* If db is NULL, then assume that a malloc() failed during an
         1082  +    ** sqlite3_open() call. We have a static version of the string 
         1083  +    ** "out of memory" encoded using UTF-16 just for this purpose.
         1084  +    **
         1085  +    ** Because all the characters in the string are in the unicode
         1086  +    ** range 0x00-0xFF, if we pad the big-endian string with a 
         1087  +    ** zero byte, we can obtain the little-endian string with
         1088  +    ** &big_endian[1].
         1089  +    */
         1090  +    static char outOfMemBe[] = {
         1091  +      0, 'o', 0, 'u', 0, 't', 0, ' ', 
         1092  +      0, 'o', 0, 'f', 0, ' ', 
         1093  +      0, 'm', 0, 'e', 0, 'm', 0, 'o', 0, 'r', 0, 'y', 0, 0, 0
         1094  +    };
         1095  +    static char *outOfMemLe = &outOfMemBe[1];
         1096  +
         1097  +    if( SQLITE3_BIGENDIAN ){
         1098  +      return (void *)outOfMemBe;
         1099  +    }else{
         1100  +      return (void *)outOfMemLe;
         1101  +    }
         1102  +  }
  1066   1103     if( !db->zErrMsg16 ){
  1067   1104       char const *zErr8 = sqlite3_errmsg(db);
  1068   1105       if( SQLITE3_BIGENDIAN ){
  1069   1106         db->zErrMsg16 = sqlite3utf8to16be(zErr8, -1);
  1070   1107       }else{
  1071   1108         db->zErrMsg16 = sqlite3utf8to16le(zErr8, -1);
  1072   1109       }
................................................................................
  1207   1244       */
  1208   1245       int chars_parsed = sqlite3utf8CharLen(zSql8, zTail8-zSql8);
  1209   1246       *pzTail = (u8 *)zSql + sqlite3utf16ByteLen(zSql, chars_parsed);
  1210   1247     }
  1211   1248    
  1212   1249     return rc;
  1213   1250   }
         1251  +
         1252  +/*
         1253  +** This routine does the work of opening a database on behalf of
         1254  +** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"  
         1255  +** is UTF-8 encoded. The fourth argument, "def_enc" is one of the TEXT_*
         1256  +** macros from sqliteInt.h. If we end up creating a new database file
         1257  +** (not opening an existing one), the text encoding of the database
         1258  +** will be set to this value.
         1259  +*/
         1260  +static int openDatabase(
         1261  +  const char *zFilename, /* Database filename UTF-8 encoded */
         1262  +  sqlite3 **ppDb,        /* OUT: Returned database handle */
         1263  +  const char **options,  /* Null terminated list of db options, or null */
         1264  +  u8 def_enc             /* One of TEXT_Utf8, TEXT_Utf16le or TEXT_Utf16be */
         1265  +){
         1266  +  sqlite3 *db;
         1267  +  int rc, i;
         1268  +  char *zErrMsg = 0;
         1269  +
         1270  +  /* Allocate the sqlite data structure */
         1271  +  db = sqliteMalloc( sizeof(sqlite) );
         1272  +  if( db==0 ) goto opendb_out;
         1273  +  db->onError = OE_Default;
         1274  +  db->priorNewRowid = 0;
         1275  +  db->magic = SQLITE_MAGIC_BUSY;
         1276  +  db->nDb = 2;
         1277  +  db->aDb = db->aDbStatic;
         1278  +  /* db->flags |= SQLITE_ShortColNames; */
         1279  +  sqlite3HashInit(&db->aFunc, SQLITE_HASH_STRING, 1);
         1280  +  sqlite3HashInit(&db->aCollSeq, SQLITE_HASH_STRING, 0);
         1281  +  for(i=0; i<db->nDb; i++){
         1282  +    sqlite3HashInit(&db->aDb[i].tblHash, SQLITE_HASH_STRING, 0);
         1283  +    sqlite3HashInit(&db->aDb[i].idxHash, SQLITE_HASH_STRING, 0);
         1284  +    sqlite3HashInit(&db->aDb[i].trigHash, SQLITE_HASH_STRING, 0);
         1285  +    sqlite3HashInit(&db->aDb[i].aFKey, SQLITE_HASH_STRING, 1);
         1286  +  }
         1287  +  db->pDfltColl =
         1288  +     sqlite3ChangeCollatingFunction(db, "BINARY", 6, 0, binaryCollatingFunc);
         1289  +  
         1290  +  /* Open the backend database driver */
         1291  +  if( zFilename[0]==':' && strcmp(zFilename,":memory:")==0 ){
         1292  +    db->temp_store = 2;
         1293  +  }
         1294  +  rc = sqlite3BtreeFactory(db, zFilename, 0, MAX_PAGES, &db->aDb[0].pBt);
         1295  +  if( rc!=SQLITE_OK ){
         1296  +    /* FIX ME: sqlite3BtreeFactory() should call sqlite3Error(). */
         1297  +    sqlite3Error(db, rc, 0);
         1298  +    db->magic = SQLITE_MAGIC_CLOSED;
         1299  +    goto opendb_out;
         1300  +  }
         1301  +  db->aDb[0].zName = "main";
         1302  +  db->aDb[1].zName = "temp";
         1303  +
         1304  +  /* Attempt to read the schema */
         1305  +  sqlite3RegisterBuiltinFunctions(db);
         1306  +  rc = sqlite3Init(db, &zErrMsg);
         1307  +  if( sqlite3_malloc_failed ){
         1308  +    sqlite3_close(db);
         1309  +    db = 0;
         1310  +    goto opendb_out;
         1311  +  }else if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
         1312  +    sqlite3Error(db, rc, "%s", zErrMsg, 0);
         1313  +    db->magic = SQLITE_MAGIC_CLOSED;
         1314  +  }else{
         1315  +    db->magic = SQLITE_MAGIC_OPEN;
         1316  +  }
         1317  +  if( zErrMsg ) sqliteFree(zErrMsg);
         1318  +
         1319  +opendb_out:
         1320  +  *ppDb = db;
         1321  +  return sqlite3_errcode(db);
         1322  +}
         1323  +
         1324  +/*
         1325  +** Open a new database handle.
         1326  +*/
         1327  +int sqlite3_open_new(
         1328  +  const char *zFilename, 
         1329  +  sqlite3 **ppDb, 
         1330  +  const char **options
         1331  +){
         1332  +  return openDatabase(zFilename, ppDb, options, TEXT_Utf8);
         1333  +}
         1334  +
         1335  +/*
         1336  +** Open a new database handle.
         1337  +*/
         1338  +int sqlite3_open16(
         1339  +  const void *zFilename, 
         1340  +  sqlite3 **ppDb, 
         1341  +  const char **options
         1342  +){
         1343  +  char *zFilename8;   /* zFilename encoded in UTF-8 instead of UTF-16 */
         1344  +  int rc;
         1345  +
         1346  +  assert( ppDb );
         1347  +
         1348  +  zFilename8 = sqlite3utf16to8(zFilename, -1);
         1349  +  if( !zFilename8 ){
         1350  +    *ppDb = 0;
         1351  +    return SQLITE_NOMEM;
         1352  +  }
         1353  +
         1354  +  if( SQLITE3_BIGENDIAN ){
         1355  +    rc = openDatabase(zFilename8, ppDb, options, TEXT_Utf16be);
         1356  +  }else{
         1357  +    rc = openDatabase(zFilename8, ppDb, options, TEXT_Utf16le);
         1358  +  }
         1359  +
         1360  +  sqliteFree(zFilename8);
         1361  +  return rc;
         1362  +}
  1214   1363   
  1215   1364   
  1216   1365   #if 0
  1217   1366   
  1218   1367   /*
  1219   1368   ** sqlite3_open
  1220   1369   **

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.66 2004/05/20 11:00:52 danielk1977 Exp $
           15  +** @(#) $Id: sqlite.h.in,v 1.67 2004/05/21 01:47:27 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++.
................................................................................
   592    592   */
   593    593   /* #define SQLITE_OK  0   // Allow access (This is actually defined above) */
   594    594   #define SQLITE_DENY   1   /* Abort the SQL statement with an error */
   595    595   #define SQLITE_IGNORE 2   /* Don't allow access, but don't generate an error */
   596    596   
   597    597   /*
   598    598   ** Register a function that is called at every invocation of sqlite3_exec()
   599         -** or sqlite3_compile().  This function can be used (for example) to generate
          599  +** or sqlite3_prepare().  This function can be used (for example) to generate
   600    600   ** a log file of all SQL executed against a database.
   601    601   */
   602    602   void *sqlite3_trace(sqlite*, void(*xTrace)(void*,const char*), void*);
   603    603   
   604    604   /*** The Callback-Free API
   605    605   ** 
   606    606   ** The following routines implement a new way to access SQLite that does not
................................................................................
   723    723   ** If sqlite3_reset() returns SQLITE_SCHEMA, then *ppVm is set to NULL.
   724    724   **
   725    725   ******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
   726    726   */
   727    727   int sqlite3_reset(sqlite_vm*, char **pzErrMsg);
   728    728   
   729    729   /*
   730         -** If the SQL that was handed to sqlite3_compile contains variables that
          730  +** If the SQL that was handed to sqlite3_prepare contains variables that
   731    731   ** are represeted in the SQL text by a question mark ('?').  This routine
   732    732   ** is used to assign values to those variables.
   733    733   **
   734         -** The first parameter is a virtual machine obtained from sqlite3_compile().
          734  +** The first parameter is a virtual machine obtained from sqlite3_prepare().
   735    735   ** The 2nd "idx" parameter determines which variable in the SQL statement
   736    736   ** to bind the value to.  The left most '?' is 1.  The 3rd parameter is
   737    737   ** the value to assign to that variable.  The 4th parameter is the number
   738    738   ** of bytes in the value, including the terminating \000 for strings.
   739    739   ** Finally, the 5th "copy" parameter is TRUE if SQLite should make its
   740    740   ** own private copy of this value, or false if the space that the 3rd
   741    741   ** parameter points to will be unchanging and can be used directly by
................................................................................
   744    744   ** Unbound variables are treated as having a value of NULL.  To explicitly
   745    745   ** set a variable to NULL, call this routine with the 3rd parameter as a
   746    746   ** NULL pointer.
   747    747   **
   748    748   ** If the 4th "len" parameter is -1, then strlen() is used to find the
   749    749   ** length.
   750    750   **
   751         -** This routine can only be called immediately after sqlite3_compile()
          751  +** This routine can only be called immediately after sqlite3_prepare()
   752    752   ** or sqlite3_reset() and before any calls to sqlite3_step().
   753    753   **
   754    754   ******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
   755    755   */
   756    756   int sqlite3_bind(sqlite_vm*, int idx, const char *value, int len, int copy);
   757    757   
   758    758   /*
................................................................................
   864    864   
   865    865   /* FIX ME */
   866    866   typedef sqlite_vm sqlite3_stmt;
   867    867   typedef sqlite sqlite3;
   868    868   
   869    869   /*
   870    870   ** This routine is used to bind a 32-bit integer value to a variable
   871         -** in an SQL statement compiled by sqlite3_compile(). See comments for
   872         -** sqlite3_compile() for more details on SQL statement variables.
          871  +** in an SQL statement compiled by sqlite3_prepare(). See comments for
          872  +** sqlite3_prepare() for more details on SQL statement variables.
   873    873   **
   874    874   ** The first argument is a pointer to an SQL statement previously
   875         -** obtained from a call to sqlite3_compile(). The second parameter "i"
          875  +** obtained from a call to sqlite3_prepare(). The second parameter "i"
   876    876   ** determines the parameter to bind the value "iValue" to.
   877    877   */
   878    878   int sqlite3_bind_int32(sqlite3_stmt*, int i, int iValue);
   879    879   
   880    880   /*
   881    881   ** This routine is used to bind a 64-bit integer value to a variable
   882         -** in an SQL statement compiled by sqlite3_compile(). See comments for
   883         -** sqlite3_compile() for more details on SQL statement variables.
          882  +** in an SQL statement compiled by sqlite3_prepare(). See comments for
          883  +** sqlite3_prepare() for more details on SQL statement variables.
   884    884   **
   885    885   ** The first argument is a pointer to an SQL statement previously
   886         -** obtained from a call to sqlite3_compile(). The second parameter "i"
          886  +** obtained from a call to sqlite3_prepare(). The second parameter "i"
   887    887   ** determines the parameter to bind the value "iValue" to.
   888    888   */
   889    889   int sqlite3_bind_int64(sqlite3_stmt*, int i, long long int iValue);
   890    890   
   891    891   /*
   892    892   ** This routine is used to bind a real (floating point) value to a variable
   893         -** in an SQL statement compiled by sqlite3_compile(). See comments for
   894         -** sqlite3_compile() for more details on SQL statement variables.
          893  +** in an SQL statement compiled by sqlite3_prepare(). See comments for
          894  +** sqlite3_prepare() for more details on SQL statement variables.
   895    895   **
   896    896   ** The first argument is a pointer to an SQL statement previously obtained
   897         -** from a call to sqlite3_compile(). The second parameter "i" determines
          897  +** from a call to sqlite3_prepare(). The second parameter "i" determines
   898    898   ** the parameter to bind the value "iValue" to. Internally, SQLite will
   899    899   ** manipulate the value as a 64-bit IEEE float.
   900    900   */
   901    901   int sqlite3_bind_double(sqlite3_stmt*, int i, double iValue);
   902    902   
   903    903   /*
   904    904   ** This routine is used to bind a NULL value to a variable in an SQL
   905         -** statement compiled by sqlite3_compile(). See comments for
   906         -** sqlite3_compile() for more details on SQL statement variables.
          905  +** statement compiled by sqlite3_prepare(). See comments for
          906  +** sqlite3_prepare() for more details on SQL statement variables.
   907    907   **
   908    908   ** The first argument is a pointer to an SQL statement previously obtained
   909         -** from a call to sqlite3_compile(). The second parameter "i" determines
          909  +** from a call to sqlite3_prepare(). The second parameter "i" determines
   910    910   ** the parameter to bind the NULL value to.
   911    911   */
   912    912   int sqlite3_bind_null(sqlite3_stmt*, int i);
   913    913   
   914    914   /*
   915    915   ** This routine is used to bind a UTF-8 string value to a variable in an
   916         -** SQL statement compiled by sqlite3_compile(). See comments for
   917         -** sqlite3_compile() for more details on SQL statement variables.
          916  +** SQL statement compiled by sqlite3_prepare(). See comments for
          917  +** sqlite3_prepare() for more details on SQL statement variables.
   918    918   **
   919    919   ** The first argument is a pointer to an SQL statement previously obtained
   920         -** from a call to sqlite3_compile(). The second parameter "i" determines
          920  +** from a call to sqlite3_prepare(). The second parameter "i" determines
   921    921   ** the parameter to bind the value to. Parameter three "z" is a pointer
   922    922   ** to the UTF-8 string. 
   923    923   **
   924    924   ** The fourth "n" parameter is the number of bytes (not characters) in the
   925    925   ** string pointed to by "z". "n" may or may not include any nul terminator
   926    926   ** character. If "n" is less than zero, then SQLite assumes that "z" is
   927    927   ** a nul terminated string.
................................................................................
   932    932   ** string data remains stable until after the SQL statement has been
   933    933   ** finalised or another value bound to variable "i".
   934    934   */
   935    935   int sqlite3_bind_text(sqlite3_stmt*, int i, const char* z, int n, int eCopy);
   936    936   
   937    937   /*
   938    938   ** This routine is used to bind a UTF-16 string value to a variable in an
   939         -** SQL statement compiled by sqlite3_compile(). See comments for
   940         -** sqlite3_compile() for more details on SQL statement variables.
          939  +** SQL statement compiled by sqlite3_prepare(). See comments for
          940  +** sqlite3_prepare() for more details on SQL statement variables.
   941    941   **
   942    942   ** The first argument is a pointer to an SQL statement previously obtained
   943         -** from a call to sqlite3_compile(). The second parameter "i" determines
          943  +** from a call to sqlite3_prepare(). The second parameter "i" determines
   944    944   ** the parameter to bind the value to. Parameter three "z" is a pointer to
   945    945   ** the UTF-16 string. If the string does not begin with a byte-order-mark,
   946    946   ** it is assumed to be encoded in the native byte order of the machine.
   947    947   **
   948    948   ** The fourth "n" parameter is the number of bytes (not characters) in the
   949    949   ** string pointed to by "z". "n" may or may not include any nul terminator
   950    950   ** character. If "n" is less than zero, then SQLite assumes that "z" is
................................................................................
   956    956   ** string data remains stable until after the SQL statement has been
   957    957   ** finalised or another value bound to variable "i".
   958    958   */
   959    959   int sqlite3_bind_text16(sqlite3_stmt*, int i, const void *z, int, int eCopy);
   960    960   
   961    961   /*
   962    962   ** This routine is used to bind a blob value to a variable in an
   963         -** SQL statement compiled by sqlite3_compile(). See comments for
   964         -** sqlite3_compile() for more details on SQL statement variables.
          963  +** SQL statement compiled by sqlite3_prepare(). See comments for
          964  +** sqlite3_prepare() for more details on SQL statement variables.
   965    965   **
   966    966   ** The first argument is a pointer to an SQL statement previously obtained
   967         -** from a call to sqlite3_compile(). The second parameter "i" determines
          967  +** from a call to sqlite3_prepare(). The second parameter "i" determines
   968    968   ** the parameter to bind the value to. Parameter three "z" is a pointer to
   969    969   ** the blob of data.
   970    970   **
   971    971   ** The fourth "n" parameter is the number of bytes in the blob pointed to
   972    972   ** by "z". "n" may not be less than zero.
   973    973   **
   974    974   ** If paramater "eCopy" is true, then SQLite makes a copy of the blob
................................................................................
  1021   1021   ** The returned string is always terminated by a pair of 0x00 bytes.
  1022   1022   **
  1023   1023   ** The string "not an error" is returned when the most recent API call was
  1024   1024   ** successful.
  1025   1025   */
  1026   1026   const void *sqlite3_errmsg16(sqlite3*);
  1027   1027   
         1028  +/*
         1029  +** To execute an SQL query, it must first be compiled into a byte-code
         1030  +** program using this routine. The first parameter "db" is an SQLite
         1031  +** database handle. The second parameter "zSql" is the statement
         1032  +** to be compiled, encoded as UTF-8 text. If the next parameter, "nBytes",
         1033  +** is less than zero, then zSql is read up to the first nul terminator.
         1034  +** If "nBytes" is not less than zero, then it is the length of the
         1035  +** string zSql, in bytes (not characters).
         1036  +**
         1037  +** *pzTail is made to point to the first character past the end of the first
         1038  +** SQL statement in zSql.  This routine only compiles the first statement
         1039  +** in zSql, so *pzTail is left pointing to what remains uncompiled.
         1040  +**
         1041  +** *ppStmt is left pointing to a compiled SQL statement that can be
         1042  +** executed using sqlite3_step().  Or if there is an error, *ppStmt may be
         1043  +** set to NULL.  If the input text contained no SQL (if the input is and
         1044  +** empty string or a comment) then *ppStmt is set to NULL.
         1045  +**
         1046  +** On success, SQLITE_OK is returned.  Otherwise an error code is returned.
         1047  +** 
         1048  +*/
  1028   1049   int sqlite3_prepare(
  1029   1050     sqlite3 *db,            /* Database handle */
  1030   1051     const char *zSql,       /* SQL statement, UTF-8 encoded */
  1031   1052     int nBytes,             /* Length of zSql in bytes. */
  1032   1053     sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  1033   1054     const char **pzTail     /* OUT: Pointer to unused portion of zSql */
  1034   1055   );
................................................................................
  1036   1057   int sqlite3_prepare16(
  1037   1058     sqlite3 *db,            /* Database handle */
  1038   1059     const void *zSql,       /* SQL statement, UTF-16 encoded */
  1039   1060     int nBytes,             /* Length of zSql in bytes. */
  1040   1061     sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  1041   1062     const void **pzTail     /* OUT: Pointer to unused portion of zSql */
  1042   1063   );
         1064  +
         1065  +int sqlite3_open_new(
         1066  +  const char *filename,   /* Database filename (UTF-8) */
         1067  +  sqlite3 **ppDb,         /* OUT: SQLite db handle */
         1068  +  const char **args       /* Null terminated array of option strings */
         1069  +);
         1070  +
         1071  +int sqlite3_open16(
         1072  +  const void *filename,   /* Database filename (UTF-16) */
         1073  +  sqlite3 **ppDb,         /* OUT: SQLite db handle */
         1074  +  const char **args       /* Null terminated array of option strings */
         1075  +);
         1076  +
  1043   1077   
  1044   1078   #if 0
  1045   1079   
  1046         -int sqlite3_open(const char*, sqlite3**, const char**);
  1047         -int sqlite3_open16(const void*, sqlite3**, const char**);
  1048   1080   int sqlite3_close(sqlite3*);
  1049   1081   
  1050   1082   int sqlite3_finalize(sqlite3_stmt*);
  1051   1083   int sqlite3_reset(sqlite3_stmt*);
  1052   1084   
  1053   1085   int sqlite3_step(sqlite3_stmt*);
  1054   1086   

Changes to src/sqliteInt.h.

     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   ** Internal interface definitions for SQLite.
    13     13   **
    14         -** @(#) $Id: sqliteInt.h,v 1.242 2004/05/21 01:29:06 drh Exp $
           14  +** @(#) $Id: sqliteInt.h,v 1.243 2004/05/21 01:47:27 danielk1977 Exp $
    15     15   */
    16     16   #include "config.h"
    17     17   #include "sqlite.h"
    18     18   #include "hash.h"
    19     19   #include "parse.h"
    20     20   #include <stdio.h>
    21     21   #include <stdlib.h>
................................................................................
   278    278     Hash idxHash;        /* All (named) indices indexed by name */
   279    279     Hash trigHash;       /* All triggers indexed by name */
   280    280     Hash aFKey;          /* Foreign keys indexed by to-table */
   281    281     u8 inTrans;          /* 0: not writable.  1: Transaction.  2: Checkpoint */
   282    282     u16 flags;           /* Flags associated with this database */
   283    283     void *pAux;          /* Auxiliary data.  Usually NULL */
   284    284     void (*xFreeAux)(void*);  /* Routine to free pAux */
          285  +  u8 textEnc;          /* Text encoding for this database. */
   285    286   };
   286    287   
   287    288   /*
   288    289   ** These macros can be used to test, set, or clear bits in the 
   289    290   ** Db.flags field.
   290    291   */
   291    292   #define DbHasProperty(D,I,P)     (((D)->aDb[I].flags&(P))==(P))
................................................................................
   311    312   ** changes and so the view will need to be reset.
   312    313   */
   313    314   #define DB_Locked          0x0001  /* OP_Transaction opcode has been emitted */
   314    315   #define DB_Cookie          0x0002  /* OP_VerifyCookie opcode has been emiited */
   315    316   #define DB_SchemaLoaded    0x0004  /* The schema has been loaded */
   316    317   #define DB_UnresetViews    0x0008  /* Some views have defined column names */
   317    318   
          319  +/*
          320  +** Possible values for the Db.textEnc field.
          321  +*/
          322  +#define TEXT_Utf8             1
          323  +#define TEXT_Utf16le          2
          324  +#define TEXT_Utf16be          3
   318    325   
   319    326   /*
   320    327   ** Each database is an instance of the following structure.
   321    328   **
   322    329   ** The sqlite.file_format is initialized by the database file
   323    330   ** and helps determines how the data in the database file is
   324    331   ** represented.  This field allows newer versions of the library

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.43 2004/05/20 22:16:30 drh Exp $
           16  +** $Id: test1.c,v 1.44 2004/05/21 01:47:27 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   
................................................................................
   128    128            "SQLite and what computer you are running on.", 0);
   129    129         return TCL_ERROR;
   130    130       }
   131    131     }
   132    132     return TCL_OK;
   133    133   }
   134    134   
   135         -/*
   136         -** Usage:   sqlite3_open filename
   137         -**
   138         -** Returns:  The name of an open database.
   139         -*/
   140         -static int sqlite_test_open(
   141         -  void *NotUsed,
   142         -  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   143         -  int argc,              /* Number of arguments */
   144         -  char **argv            /* Text of each argument */
   145         -){
   146         -  sqlite *db;
   147         -  char *zErr = 0;
   148         -  char zBuf[100];
   149         -  if( argc!=2 ){
   150         -    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   151         -       " FILENAME\"", 0);
   152         -    return TCL_ERROR;
   153         -  }
   154         -  db = sqlite3_open(argv[1], 0666, &zErr);
   155         -  if( db==0 ){
   156         -    Tcl_AppendResult(interp, zErr, 0);
   157         -    free(zErr);
   158         -    return TCL_ERROR;
   159         -  }
   160         -  if( makePointerStr(interp, zBuf, db) ) return TCL_ERROR;
   161         -  Tcl_AppendResult(interp, zBuf, 0);
   162         -  return TCL_OK;
   163         -}
   164         -
   165    135   /*
   166    136   ** The callback routine for sqlite3_exec_printf().
   167    137   */
   168    138   static int exec_printf_cb(void *pArg, int argc, char **argv, char **name){
   169    139     Tcl_DString *str = (Tcl_DString*)pArg;
   170    140     int i;
   171    141   
................................................................................
   777    747     if( rc!=0 && rc!=SQLITE_ABORT ){
   778    748       Tcl_AppendResult(interp, sqlite3_error_string(rc), 0);
   779    749       return TCL_ERROR;
   780    750     }
   781    751     return TCL_OK;
   782    752   }
   783    753   
   784         -/*
   785         -** Usage:  sqlite3_compile  DB  SQL  ?TAILVAR?
   786         -**
   787         -** Attempt to compile an SQL statement.  Return a pointer to the virtual
   788         -** machine used to execute that statement.  Unprocessed SQL is written
   789         -** into TAILVAR.
   790         -*/
   791         -static int test_compile(
   792         -  void *NotUsed,
   793         -  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   794         -  int argc,              /* Number of arguments */
   795         -  char **argv            /* Text of each argument */
   796         -){
   797         -  sqlite *db;
   798         -  sqlite_vm *vm;
   799         -  int rc;
   800         -  char *zErr = 0;
   801         -  const char *zTail;
   802         -  char zBuf[50];
   803         -  if( argc!=3 && argc!=4 ){
   804         -    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 
   805         -       " DB SQL TAILVAR", 0);
   806         -    return TCL_ERROR;
   807         -  }
   808         -  if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
   809         -  rc = sqlite3_compile(db, argv[2], argc==4 ? &zTail : 0, &vm, &zErr);
   810         -  if( argc==4 ) Tcl_SetVar(interp, argv[3], zTail, 0);
   811         -  if( rc ){
   812         -    assert( vm==0 );
   813         -    sprintf(zBuf, "(%d) ", rc);
   814         -    Tcl_AppendResult(interp, zBuf, zErr, 0);
   815         -    sqlite3_freemem(zErr);
   816         -    return TCL_ERROR;
   817         -  }
   818         -  if( vm ){
   819         -    if( makePointerStr(interp, zBuf, vm) ) return TCL_ERROR;
   820         -    Tcl_AppendResult(interp, zBuf, 0);
   821         -  }
   822         -  return TCL_OK;
   823         -}
   824         -
   825    754   /*
   826    755   ** Usage:  sqlite3_step  VM  ?NVAR?  ?VALUEVAR?  ?COLNAMEVAR?
   827    756   **
   828    757   ** Step a virtual machine.  Return a the result code as a string.
   829    758   ** Column results are written into three variables.
   830    759   */
   831    760   static int test_step(
................................................................................
  1326   1255   ){
  1327   1256     sqlite3 *db;
  1328   1257     const char *zSql;
  1329   1258     int bytes;
  1330   1259     const char *zTail = 0;
  1331   1260     sqlite3_stmt *pStmt = 0;
  1332   1261     char zBuf[50];
         1262  +  int rc;
  1333   1263   
  1334   1264     if( objc!=5 ){
  1335   1265       Tcl_AppendResult(interp, "wrong # args: should be \"", 
  1336   1266          Tcl_GetString(objv[0]), " DB sql bytes tailvar", 0);
  1337   1267       return TCL_ERROR;
  1338   1268     }
  1339   1269     if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
  1340   1270     zSql = Tcl_GetString(objv[2]);
  1341   1271     if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR;
  1342   1272   
  1343         -  if( SQLITE_OK!=sqlite3_prepare(db, zSql, bytes, &pStmt, &zTail) ){
  1344         -    return TCL_ERROR;
  1345         -  }
  1346         -
         1273  +  rc = sqlite3_prepare(db, zSql, bytes, &pStmt, &zTail);
  1347   1274     if( zTail ){
  1348   1275       if( bytes>=0 ){
  1349   1276         bytes = bytes - (zTail-zSql);
  1350   1277       }
  1351   1278       Tcl_ObjSetVar2(interp, objv[4], 0, Tcl_NewStringObj(zTail, bytes), 0);
  1352   1279     }
         1280  +  if( rc!=SQLITE_OK ){
         1281  +    assert( pStmt==0 );
         1282  +    sprintf(zBuf, "(%d) ", rc);
         1283  +    Tcl_AppendResult(interp, zBuf, sqlite3_errmsg(db), 0);
         1284  +    return TCL_ERROR;
         1285  +  }
  1353   1286   
  1354         -  if( makePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR;
  1355         -  Tcl_AppendResult(interp, zBuf, 0);
         1287  +  if( pStmt ){
         1288  +    if( makePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR;
         1289  +    Tcl_AppendResult(interp, zBuf, 0);
         1290  +  }
  1356   1291     return TCL_OK;
  1357   1292   }
  1358   1293   
  1359   1294   /*
  1360   1295   ** Usage: sqlite3_prepare DB sql bytes tailvar
  1361   1296   **
  1362   1297   ** Compile up to <bytes> bytes of the supplied SQL string <sql> using
................................................................................
  1396   1331       objlen = objlen - ((u8 *)zTail-(u8 *)zSql);
  1397   1332     }else{
  1398   1333       objlen = 0;
  1399   1334     }
  1400   1335     pTail = Tcl_NewByteArrayObj((u8 *)zTail, objlen);
  1401   1336     Tcl_IncrRefCount(pTail);
  1402   1337     Tcl_ObjSetVar2(interp, objv[4], 0, pTail, 0);
  1403         -  // Tcl_DecrRefCount(pTail);
         1338  +  Tcl_DecrRefCount(pTail);
         1339  +
         1340  +  if( pStmt ){
         1341  +    if( makePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR;
         1342  +  }
         1343  +  Tcl_AppendResult(interp, zBuf, 0);
         1344  +  return TCL_OK;
         1345  +}
         1346  +
         1347  +/*
         1348  +** Usage: sqlite3_open filename ?options-list?
         1349  +*/
         1350  +static int test_open(
         1351  +  void * clientData,
         1352  +  Tcl_Interp *interp,
         1353  +  int objc,
         1354  +  Tcl_Obj *CONST objv[]
         1355  +){
         1356  +  const char *zFilename;
         1357  +  sqlite3 *db;
         1358  +  int rc;
         1359  +  char zBuf[100];
         1360  +
         1361  +  if( objc!=3 && objc!=2 ){
         1362  +    Tcl_AppendResult(interp, "wrong # args: should be \"", 
         1363  +       Tcl_GetString(objv[0]), " filename options-list", 0);
         1364  +    return TCL_ERROR;
         1365  +  }
  1404   1366   
  1405         -  if( makePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR;
         1367  +  zFilename = Tcl_GetString(objv[1]);
         1368  +  rc = sqlite3_open_new(zFilename, &db, 0);
         1369  +  
         1370  +  if( makePointerStr(interp, zBuf, db) ) return TCL_ERROR;
  1406   1371     Tcl_AppendResult(interp, zBuf, 0);
  1407   1372     return TCL_OK;
  1408   1373   }
  1409   1374   
         1375  +/*
         1376  +** Usage: sqlite3_open16 filename options
         1377  +*/
         1378  +static int test_open16(
         1379  +  void * clientData,
         1380  +  Tcl_Interp *interp,
         1381  +  int objc,
         1382  +  Tcl_Obj *CONST objv[]
         1383  +){
         1384  +  const void *zFilename;
         1385  +  sqlite3 *db;
         1386  +  int rc;
         1387  +  char zBuf[100];
         1388  +
         1389  +  if( objc!=3 ){
         1390  +    Tcl_AppendResult(interp, "wrong # args: should be \"", 
         1391  +       Tcl_GetString(objv[0]), " filename options-list", 0);
         1392  +    return TCL_ERROR;
         1393  +  }
         1394  +
         1395  +  zFilename = Tcl_GetByteArrayFromObj(objv[1], 0);
         1396  +  rc = sqlite3_open16(zFilename, &db, 0);
         1397  +  
         1398  +  if( makePointerStr(interp, zBuf, db) ) return TCL_ERROR;
         1399  +  Tcl_AppendResult(interp, zBuf, 0);
         1400  +  return TCL_OK;
         1401  +}
  1410   1402   
  1411   1403   /*
  1412   1404   ** This is a collating function named "REVERSE" which sorts text
  1413   1405   ** in reverse order.
  1414   1406   */
  1415   1407   static int reverseCollatingFunc(
  1416   1408     void *NotUsed,
................................................................................
  1463   1455        Tcl_CmdProc *xProc;
  1464   1456     } aCmd[] = {
  1465   1457        { "sqlite3_mprintf_int",           (Tcl_CmdProc*)sqlite3_mprintf_int    },
  1466   1458        { "sqlite3_mprintf_str",           (Tcl_CmdProc*)sqlite3_mprintf_str    },
  1467   1459        { "sqlite3_mprintf_double",        (Tcl_CmdProc*)sqlite3_mprintf_double },
  1468   1460        { "sqlite3_mprintf_scaled",        (Tcl_CmdProc*)sqlite3_mprintf_scaled },
  1469   1461        { "sqlite3_mprintf_z_test",        (Tcl_CmdProc*)test_mprintf_z        },
  1470         -     { "sqlite3_open",                  (Tcl_CmdProc*)sqlite_test_open      },
         1462  +//     { "sqlite3_open",                  (Tcl_CmdProc*)sqlite_test_open      },
  1471   1463        { "sqlite3_last_insert_rowid",     (Tcl_CmdProc*)test_last_rowid       },
  1472   1464        { "sqlite3_exec_printf",           (Tcl_CmdProc*)test_exec_printf      },
  1473   1465        { "sqlite3_get_table_printf",      (Tcl_CmdProc*)test_get_table_printf },
  1474   1466        { "sqlite3_close",                 (Tcl_CmdProc*)sqlite_test_close     },
  1475   1467        { "sqlite3_create_function",       (Tcl_CmdProc*)test_create_function  },
  1476   1468        { "sqlite3_create_aggregate",      (Tcl_CmdProc*)test_create_aggregate },
  1477   1469        { "sqlite_register_test_function", (Tcl_CmdProc*)test_register_func    },
  1478   1470        { "sqlite_abort",                  (Tcl_CmdProc*)sqlite_abort          },
  1479   1471        { "sqlite_datatypes",              (Tcl_CmdProc*)sqlite_datatypes      },
  1480   1472   #ifdef MEMORY_DEBUG
  1481   1473        { "sqlite_malloc_fail",            (Tcl_CmdProc*)sqlite_malloc_fail    },
  1482   1474        { "sqlite_malloc_stat",            (Tcl_CmdProc*)sqlite_malloc_stat    },
  1483   1475   #endif
  1484         -     { "sqlite_compile",                (Tcl_CmdProc*)test_compile          },
  1485         -     { "sqlite_step",                   (Tcl_CmdProc*)test_step             },
  1486         -     { "sqlite_finalize",               (Tcl_CmdProc*)test_finalize         },
  1487         -     { "sqlite_bind",                   (Tcl_CmdProc*)test_bind             },
  1488         -     { "sqlite_reset",                  (Tcl_CmdProc*)test_reset            },
  1489         -     { "breakpoint",                    (Tcl_CmdProc*)test_breakpoint       },
         1476  +     { "sqlite_step",                    (Tcl_CmdProc*)test_step             },
         1477  +     { "sqlite_finalize",                (Tcl_CmdProc*)test_finalize         },
         1478  +     { "sqlite_bind",                    (Tcl_CmdProc*)test_bind             },
         1479  +     { "sqlite_reset",                   (Tcl_CmdProc*)test_reset            },
         1480  +     { "breakpoint",                     (Tcl_CmdProc*)test_breakpoint       },
  1490   1481     };
  1491   1482     static struct {
  1492   1483        char *zName;
  1493   1484        Tcl_ObjCmdProc *xProc;
  1494   1485     } aObjCmd[] = {
  1495   1486        { "sqlite3_bind_int32",            (Tcl_ObjCmdProc*)test_bind_int32    },
  1496   1487        { "sqlite3_bind_int64",            (Tcl_ObjCmdProc*)test_bind_int64    },
................................................................................
  1500   1491        { "sqlite3_bind_text16",           (Tcl_ObjCmdProc*)test_bind_text16   },
  1501   1492        { "sqlite3_bind_blob",             (Tcl_ObjCmdProc*)test_bind_blob     },
  1502   1493        { "sqlite3_errcode",               (Tcl_ObjCmdProc*)test_errcode       },
  1503   1494        { "sqlite3_errmsg",                (Tcl_ObjCmdProc*)test_errmsg        },
  1504   1495        { "sqlite3_errmsg16",              (Tcl_ObjCmdProc*)test_errmsg16      },
  1505   1496        { "sqlite3_prepare",               (Tcl_ObjCmdProc*)test_prepare       },
  1506   1497        { "sqlite3_prepare16",             (Tcl_ObjCmdProc*)test_prepare16     },
         1498  +     { "sqlite3_open",                  (Tcl_ObjCmdProc*)test_open          },
         1499  +     { "sqlite3_open16",                (Tcl_ObjCmdProc*)test_open16        },
  1507   1500        { "add_reverse_collating_func",    (Tcl_ObjCmdProc*)reverse_collfunc   },
  1508   1501     };
  1509   1502     int i;
  1510   1503   
  1511   1504     for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
  1512   1505       Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
  1513   1506     }

Changes to test/attach2.test.

     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 is testing the ATTACH and DETACH commands
    13     13   # and related functionality.
    14     14   #
    15         -# $Id: attach2.test,v 1.7 2004/05/13 11:34:17 danielk1977 Exp $
           15  +# $Id: attach2.test,v 1.8 2004/05/21 01:47:27 danielk1977 Exp $
    16     16   #
    17     17   
    18     18   
    19     19   set testdir [file dirname $argv0]
    20     20   source $testdir/tester.tcl
    21     21   
    22     22   # Ticket #354
................................................................................
   120    120   } {1 {cannot commit - no transaction is active}}
   121    121   
   122    122   # Ticket #574:  Make sure it works usingi the non-callback API
   123    123   #
   124    124   do_test attach2-3.1 {
   125    125     db close
   126    126     set DB [sqlite db test.db]
   127         -  set rc [catch {sqlite_compile $DB "ATTACH 'test2.db' AS t2" TAIL} VM]
          127  +  set rc [catch {sqlite3_prepare $DB "ATTACH 'test2.db' AS t2" -1 TAIL} VM]
   128    128     if {$rc} {lappend rc $VM}
   129    129     sqlite_finalize $VM
   130    130     set rc
   131    131   } {0}
   132    132   do_test attach2-3.2 {
   133         -  set rc [catch {sqlite_compile $DB "DETACH t2" TAIL} VM]
          133  +  set rc [catch {sqlite3_prepare $DB "DETACH t2" -1 TAIL} VM]
   134    134     if {$rc} {lappend rc $VM}
   135    135     sqlite_finalize $VM
   136    136     set rc
   137    137   } {0}
   138    138   
   139    139   db close
   140    140   for {set i 2} {$i<=15} {incr i} {
   141    141     catch {db$i close}
   142    142   }
   143    143   file delete -force test2.db
   144    144   
   145    145   
   146    146   finish_test

Changes to test/bind.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 sqlite_bind API.
    13     13   #
    14         -# $Id: bind.test,v 1.3 2004/05/20 11:00:53 danielk1977 Exp $
           14  +# $Id: bind.test,v 1.4 2004/05/21 01:47:27 danielk1977 Exp $
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   do_test bind-1.1 {
    21     21     db close
    22     22     set DB [sqlite db test.db]
    23     23     execsql {CREATE TABLE t1(a,b,c)}
    24         -  set VM [sqlite_compile $DB {INSERT INTO t1 VALUES(?,?,?)} TAIL]
           24  +  set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(?,?,?)} -1 TAIL]
    25     25     set TAIL
    26     26   } {}
    27     27   do_test bind-1.2 {
    28     28     sqlite_step $VM N VALUES COLNAMES
    29     29   } {SQLITE_DONE}
    30     30   do_test bind-1.3 {
    31     31     execsql {SELECT rowid, * FROM t1}
................................................................................
    67     67     sqlite_finalize $VM
    68     68   } {}
    69     69   
    70     70   do_test bind-2.1 {
    71     71     execsql {
    72     72       DELETE FROM t1;
    73     73     }
    74         -  set VM [sqlite_compile $DB {INSERT INTO t1 VALUES(?,?,?)} TAIL]
           74  +  set VM [sqlite3_bind_int32 $DB {INSERT INTO t1 VALUES(?,?,?)} TAIL]
    75     75     set TAIL
    76     76   } {}
    77     77   
    78     78   # 32 bit Integers
    79     79   do_test bind-2.2 {
    80     80     sqlite3_bind_int32 $VM 1 123
    81     81     sqlite3_bind_int32 $VM 2 456

Changes to test/capi2.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: capi2.test,v 1.10 2003/08/05 13:13:38 drh Exp $
           14  +# $Id: capi2.test,v 1.11 2004/05/21 01:47:27 danielk1977 Exp $
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Check basic functionality
    21     21   #
    22     22   do_test capi2-1.1 {
    23     23     db close
    24     24     set DB [sqlite db test.db]
    25     25     execsql {CREATE TABLE t1(a,b,c)}
    26         -  set VM [sqlite_compile $DB {SELECT name, rowid FROM sqlite_master} TAIL]
           26  +  set VM [sqlite3_prepare $DB {SELECT name, rowid FROM sqlite_master} -1 TAIL]
    27     27     set TAIL
    28     28   } {}
    29     29   do_test capi2-1.2 {
    30     30     sqlite_step $VM N VALUES COLNAMES
    31     31   } {SQLITE_ROW}
    32     32   do_test capi2-1.3 {
    33     33     set N
................................................................................
    57     57     list $N $VALUES $COLNAMES
    58     58   } {0 {} {}}
    59     59   do_test capi2-1.10 {
    60     60     sqlite_finalize $VM
    61     61   } {}
    62     62   
    63     63   # Check to make sure that the "tail" of a multi-statement SQL script
    64         -# is returned by sqlite_compile.
           64  +# is returned by sqlite3_prepare.
    65     65   #
    66     66   do_test capi2-2.1 {
    67     67     set SQL {
    68     68       SELECT name, rowid FROM sqlite_master;
    69     69       SELECT name, rowid FROM sqlite_temp_master;
    70     70       -- A comment at the end
    71     71     }
    72         -  set VM [sqlite_compile $DB $SQL SQL]
           72  +  set VM [sqlite3_prepare $DB $SQL -1 SQL]
    73     73     set SQL
    74     74   } {
    75     75       SELECT name, rowid FROM sqlite_temp_master;
    76     76       -- A comment at the end
    77     77     }
    78     78   do_test capi2-2.2 {
    79     79     set r [sqlite_step $VM n val colname]
................................................................................
    83     83     set r [sqlite_step $VM n val colname]
    84     84     lappend r $n $val $colname
    85     85   } {SQLITE_DONE 2 {} {name rowid text INTEGER}}
    86     86   do_test capi2-2.4 {
    87     87     sqlite_finalize $VM
    88     88   } {}
    89     89   do_test capi2-2.5 {
    90         -  set VM [sqlite_compile $DB $SQL SQL]
           90  +  set VM [sqlite3_prepare $DB $SQL -1 SQL]
    91     91     set SQL
    92     92   } {
    93     93       -- A comment at the end
    94     94     }
    95     95   do_test capi2-2.6 {
    96     96     set r [sqlite_step $VM n val colname]
    97     97     lappend r $n $val $colname
    98     98   } {SQLITE_DONE 2 {} {name rowid text INTEGER}}
    99     99   do_test capi2-2.7 {
   100    100     sqlite_finalize $VM
   101    101   } {}
   102    102   do_test capi2-2.8 {
   103         -  set VM [sqlite_compile $DB $SQL SQL]
          103  +  set VM [sqlite3_prepare $DB $SQL -1 SQL]
   104    104     list $SQL $VM
   105    105   } {{} {}}
   106    106   
   107    107   # Check the error handling.
   108    108   #
   109    109   do_test capi2-3.1 {
   110    110     set rc [catch {
   111         -      sqlite_compile $DB {select bogus from sqlite_master} TAIL
          111  +      sqlite3_prepare $DB {select bogus from sqlite_master} -1 TAIL
   112    112     } msg]
   113    113     lappend rc $msg $TAIL
   114    114   } {1 {(1) no such column: bogus} {}}
   115    115   do_test capi2-3.2 {
   116    116     set rc [catch {
   117         -      sqlite_compile $DB {select bogus from } TAIL
          117  +      sqlite3_prepare $DB {select bogus from } -1 TAIL
   118    118     } msg]
   119    119     lappend rc $msg $TAIL
   120    120   } {1 {(1) near " ": syntax error} {}}
   121    121   do_test capi2-3.3 {
   122    122     set rc [catch {
   123         -      sqlite_compile $DB {;;;;select bogus from sqlite_master} TAIL
          123  +      sqlite3_prepare $DB {;;;;select bogus from sqlite_master} -1 TAIL
   124    124     } msg]
   125    125     lappend rc $msg $TAIL
   126    126   } {1 {(1) no such column: bogus} {}}
   127    127   do_test capi2-3.4 {
   128    128     set rc [catch {
   129         -      sqlite_compile $DB {select bogus from sqlite_master;x;} TAIL
          129  +      sqlite3_prepare $DB {select bogus from sqlite_master;x;} -1 TAIL
   130    130     } msg]
   131    131     lappend rc $msg $TAIL
   132    132   } {1 {(1) no such column: bogus} {x;}}
   133    133   do_test capi2-3.5 {
   134    134     set rc [catch {
   135         -      sqlite_compile $DB {select bogus from sqlite_master;;;x;} TAIL
          135  +      sqlite3_prepare $DB {select bogus from sqlite_master;;;x;} -1 TAIL
   136    136     } msg]
   137    137     lappend rc $msg $TAIL
   138    138   } {1 {(1) no such column: bogus} {;;x;}}
   139    139   do_test capi2-3.6 {
   140    140     set rc [catch {
   141         -      sqlite_compile $DB {select 5/0} TAIL
          141  +      sqlite3_prepare $DB {select 5/0} -1 TAIL
   142    142     } VM]
   143    143     lappend rc $TAIL
   144    144   } {0 {}}
   145    145   do_test capi2-3.7 {
   146    146     set N {}
   147    147     set VALUE {}
   148    148     set COLNAME {}
................................................................................
   149    149     list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
   150    150   } {SQLITE_ROW 1 {{}} {5/0 NUMERIC}}
   151    151   do_test capi2-3.8 {
   152    152     sqlite_finalize $VM
   153    153   } {}
   154    154   do_test capi2-3.9 {
   155    155     execsql {CREATE UNIQUE INDEX i1 ON t1(a)}
   156         -  set VM [sqlite_compile $DB {INSERT INTO t1 VALUES(1,2,3)} TAIL]
          156  +  set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(1,2,3)} -1 TAIL]
   157    157     set TAIL
   158    158   } {}
   159    159   do_test capi2-3.9b {db changes} {0}
   160    160   do_test capi2-3.10 {
   161    161     set N {}
   162    162     set VALUE {}
   163    163     set COLNAME {}
................................................................................
   168    168     sqlite_finalize $VM
   169    169   } {}
   170    170   do_test capi2-3.11b {db changes} {1}
   171    171   do_test capi2-3.12 {
   172    172     list [catch {sqlite_finalize $VM} msg] [set msg]
   173    173   } {1 {(21) library routine called out of sequence}}
   174    174   do_test capi2-3.13 {
   175         -  set VM [sqlite_compile $DB {INSERT INTO t1 VALUES(1,3,4)} TAIL]
          175  +  set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(1,3,4)} -1 TAIL]
   176    176     list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
   177    177   } {SQLITE_ERROR 0 {} {}}
   178    178   do_test capi2-3.13b {db changes} {0}
   179    179   do_test capi2-3.14 {
   180    180     list [catch {sqlite_finalize $VM} msg] [set msg]
   181    181   } {1 {(19) column a is not unique}}
   182    182   do_test capi2-3.15 {
   183         -  set VM [sqlite_compile $DB {CREATE TABLE t2(a NOT NULL, b)} TAIL]
          183  +  set VM [sqlite3_prepare $DB {CREATE TABLE t2(a NOT NULL, b)} -1 TAIL]
   184    184     set TAIL
   185    185   } {}
   186    186   do_test capi2-3.16 {
   187    187     list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
   188    188   } {SQLITE_DONE 0 {} {}}
   189    189   do_test capi2-3.17 {
   190    190     list [catch {sqlite_finalize $VM} msg] [set msg]
   191    191   } {0 {}}
   192    192   do_test capi2-3.18 {
   193         -  set VM [sqlite_compile $DB {INSERT INTO t2 VALUES(NULL,2)} TAIL]
          193  +  set VM [sqlite3_prepare $DB {INSERT INTO t2 VALUES(NULL,2)} -1 TAIL]
   194    194     list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
   195    195   } {SQLITE_ERROR 0 {} {}}
   196    196   do_test capi2-3.19 {
   197    197     list [catch {sqlite_finalize $VM} msg] [set msg]
   198    198   } {1 {(19) t2.a may not be NULL}}
   199    199   
   200    200   # Two or more virtual machines exists at the same time.
   201    201   #
   202    202   do_test capi2-4.1 {
   203         -  set VM1 [sqlite_compile $DB {INSERT INTO t2 VALUES(1,2)} TAIL]
          203  +  set VM1 [sqlite3_prepare $DB {INSERT INTO t2 VALUES(1,2)} -1 TAIL]
   204    204     set TAIL
   205    205   } {}
   206    206   do_test capi2-4.2 {
   207         -  set VM2 [sqlite_compile $DB {INSERT INTO t2 VALUES(2,3)} TAIL]
          207  +  set VM2 [sqlite3_prepare $DB {INSERT INTO t2 VALUES(2,3)} -1 TAIL]
   208    208     set TAIL
   209    209   } {}
   210    210   do_test capi2-4.3 {
   211         -  set VM3 [sqlite_compile $DB {INSERT INTO t2 VALUES(3,4)} TAIL]
          211  +  set VM3 [sqlite3_prepare $DB {INSERT INTO t2 VALUES(3,4)} -1 TAIL]
   212    212     set TAIL
   213    213   } {}
   214    214   do_test capi2-4.4 {
   215    215     list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
   216    216   } {SQLITE_DONE 0 {} {}}
   217    217   do_test capi2-4.5 {
   218    218     execsql {SELECT * FROM t2 ORDER BY a}
................................................................................
   238    238   do_test capi2-4.12 {
   239    239     list [catch {sqlite_finalize $VM1} msg] [set msg]
   240    240   } {0 {}}  
   241    241   
   242    242   # Interleaved SELECTs
   243    243   #
   244    244   do_test capi2-5.1 {
   245         -  set VM1 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
   246         -  set VM2 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
   247         -  set VM3 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
          245  +  set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL]
          246  +  set VM2 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL]
          247  +  set VM3 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL]
   248    248     list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
   249    249   } {SQLITE_ROW 2 {2 3} {a b {} {}}}
   250    250   do_test capi2-5.2 {
   251    251     list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
   252    252   } {SQLITE_ROW 2 {2 3} {a b {} {}}}
   253    253   do_test capi2-5.3 {
   254    254     list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
................................................................................
   293    293       INSERT INTO t3 VALUES(1);
   294    294       INSERT INTO t3 VALUES(2);
   295    295       INSERT INTO t3 SELECT x+2 FROM t3;
   296    296       INSERT INTO t3 SELECT x+4 FROM t3;
   297    297       INSERT INTO t3 SELECT x+8 FROM t3;
   298    298       COMMIT;
   299    299     }
   300         -  set VM1 [sqlite_compile $DB {SELECT * FROM t3} TAIL]
          300  +  set VM1 [sqlite3_prepare $DB {SELECT * FROM t3} -1 TAIL]
   301    301     sqlite db2 test.db
   302    302     execsql {BEGIN} db2
   303    303   } {}
   304    304   do_test capi2-6.2 {
   305    305     list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
   306    306   } {SQLITE_BUSY 0 {} {}}
   307    307   do_test capi2-6.3 {
................................................................................
   453    453     set x [stepsql $DB {EXPLAIN SELECT * FROM t1}]
   454    454     lindex $x 0
   455    455   } {0}
   456    456   
   457    457   # Ticket #261 - make sure we can finalize before the end of a query.
   458    458   #
   459    459   do_test capi2-8.1 {
   460         -  set VM1 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
          460  +  set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL]
   461    461     sqlite_finalize $VM1
   462    462   } {}
   463    463     
   464         -# Tickets #384 and #385 - make sure the TAIL argument to sqlite_compile
          464  +# Tickets #384 and #385 - make sure the TAIL argument to sqlite3_prepare
   465    465   # and all of the return pointers in sqlite_step can be null.
   466    466   #
   467    467   do_test capi2-9.1 {
   468         -  set VM1 [sqlite_compile $DB {SELECT * FROM t2}]
          468  +  set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 DUMMY]
   469    469     sqlite_step $VM1
   470    470     sqlite_finalize $VM1
   471    471   } {}
   472    472   
   473    473   db2 close
   474    474   
   475    475   finish_test

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.1 2004/05/20 11:00:53 danielk1977 Exp $
           14  +# $Id: capi3.test,v 1.2 2004/05/21 01:47:27 danielk1977 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.
................................................................................
    41     41   }
    42     42   
    43     43   # These tests complement those in capi2.test. They are organized
    44     44   # as follows:
    45     45   #
    46     46   # capi3-1.*: Test sqlite3_prepare 
    47     47   # capi3-2.*: Test sqlite3_prepare16
           48  +# capi3-3.*: Test sqlite3_open
           49  +# capi3-4.*: Test sqlite3_open16
    48     50   #
    49     51   
    50     52   db close
    51     53   set DB [sqlite db test.db]
    52     54   
    53     55   do_test capi3-1.1 {
    54     56     set STMT [sqlite3_prepare $DB {SELECT name FROM sqlite_master} -1 TAIL]
................................................................................
   100    102   } {1}
   101    103   do_test capi3-2.4 {
   102    104     sqlite3_errcode $DB
   103    105   } {SQLITE_ERROR}
   104    106   do_test capi3-2.5 {
   105    107     sqlite3_errmsg $DB
   106    108   } {no such column: namex}
          109  +
          110  +# rename sqlite3_open sqlite3_open_old
          111  +# proc sqlite3_open {fname options} {sqlite3_open_new $fname $options}
          112  +
          113  +do_test capi3-3.1 {
          114  +  set db2 [sqlite3_open test.db {}]
          115  +  sqlite3_errcode $db2
          116  +} {SQLITE_OK}
          117  +# FIX ME: Should test the db handle works.
          118  +do_test capi3-3.2 {
          119  +  sqlite3_close $db2
          120  +} {}
          121  +do_test capi3-3.3 {
          122  +  catch {
          123  +    set db2 [sqlite3_open /bogus/path/test.db {}]
          124  +  }
          125  +  sqlite3_errcode $db2
          126  +} {SQLITE_CANTOPEN}
          127  +do_test capi3-3.4 {
          128  +  sqlite3_errmsg $db2
          129  +} {unable to open database file}
          130  +do_test capi3-3.4 {
          131  +  sqlite3_close $db2
          132  +} {}
          133  +
          134  +# rename sqlite3_open ""
          135  +# rename sqlite3_open_old sqlite3_open
          136  +
          137  +do_test capi3-4.1 {
          138  +  set db2 [sqlite3_open16 [utf16 test.db] {}]
          139  +  sqlite3_errcode $db2
          140  +} {SQLITE_OK}
          141  +# FIX ME: Should test the db handle works.
          142  +do_test capi3-4.2 {
          143  +  sqlite3_close $db2
          144  +} {}
          145  +do_test capi3-4.3 {
          146  +  catch {
          147  +    set db2 [sqlite3_open16 [utf16 /bogus/path/test.db] {}]
          148  +  }
          149  +  sqlite3_errcode $db2
          150  +} {SQLITE_CANTOPEN}
          151  +do_test capi3-4.4 {
          152  +  utf8 [sqlite3_errmsg16 $db2]
          153  +} {unable to open database file}
          154  +do_test capi3-4.4 {
          155  +  sqlite3_close $db2
          156  +} {}
   107    157   
   108    158   finish_test
   109    159   
   110    160   

Changes to test/tester.tcl.

     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 some common TCL routines used for regression
    12     12   # testing the SQLite library
    13     13   #
    14         -# $Id: tester.tcl,v 1.33 2004/05/20 22:16:31 drh Exp $
           14  +# $Id: tester.tcl,v 1.34 2004/05/21 01:47:27 danielk1977 Exp $
    15     15   
    16     16   # Make sure tclsqlite was compiled correctly.  Abort now with an
    17     17   # error message if not.
    18     18   #
    19     19   if {[sqlite -tcl-uses-utf]} {
    20     20     if {"\u1234"=="u1234"} {
    21     21       puts stderr "***** BUILD PROBLEM *****"
................................................................................
   194    194   
   195    195   # Use the non-callback API to execute multiple SQL statements
   196    196   #
   197    197   proc stepsql {dbptr sql} {
   198    198     set sql [string trim $sql]
   199    199     set r 0
   200    200     while {[string length $sql]>0} {
   201         -    if {[catch {sqlite_compile $dbptr $sql sqltail} vm]} {
          201  +    if {[catch {sqlite3_prepare $dbptr $sql -1 sqltail} vm]} {
   202    202         return [list 1 $vm]
   203    203       }
   204    204       set sql [string trim $sqltail]
   205    205       while {[sqlite_step $vm N VAL COL]=="SQLITE_ROW"} {
   206    206         foreach v $VAL {lappend r $v}
   207    207       }
   208    208       if {[catch {sqlite_finalize $vm} errmsg]} {

Changes to test/vacuum.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 file is testing the VACUUM statement.
    13     13   #
    14         -# $Id: vacuum.test,v 1.15 2004/02/14 16:31:04 drh Exp $
           14  +# $Id: vacuum.test,v 1.16 2004/05/21 01:47:27 danielk1977 Exp $
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   proc cksum {{db db}} {
    20     20     set txt [$db eval {SELECT name, type, sql FROM sqlite_master}]\n
    21     21     foreach tbl [$db eval {SELECT name FROM sqlite_master WHERE type='table'}] {
................................................................................
   126    126     sqlite db test.db
   127    127     execsql {
   128    128       PRAGMA empty_result_callbacks=on;
   129    129       VACUUM;
   130    130     }
   131    131   } {}
   132    132   
   133         -# Ticket #464.  Make sure VACUUM works with the sqlite_compile() API.
          133  +# Ticket #464.  Make sure VACUUM works with the sqlite3_prepare() API.
   134    134   #
   135    135   do_test vacuum-4.1 {
   136    136     db close
   137    137     set DB [sqlite db test.db]
   138         -  set VM [sqlite_compile $DB {VACUUM} TAIL]
          138  +  set VM [sqlite3_prepare $DB {VACUUM} -1 TAIL]
   139    139     sqlite_step $VM N VALUES COLNAMES
   140    140   } {SQLITE_DONE}
   141    141   do_test vacuum-4.2 {
   142    142     sqlite_finalize $VM
   143    143   } {}
   144    144   
   145    145   # Ticket #515.  VACUUM after deleting and recreating the table that