/ Check-in [b4492173]
Login

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

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

Changes to src/main.c.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
....
1194
1195
1196
1197
1198
1199
1200













1201
1202
1203
1204
1205
1206
1207
....
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
....
1293
1294
1295
1296
1297
1298
1299


1300
1301
1302
1303
1304
1305
1306
....
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.183 2004/05/22 08:09:40 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/*
** A pointer to this structure is used to communicate information
................................................................................
  sqlite3 **ppDb,        /* OUT: Returned database handle */
  const char **options,  /* Null terminated list of db options, or null */
  u8 def_enc             /* One of TEXT_Utf8, TEXT_Utf16le or TEXT_Utf16be */
){
  sqlite3 *db;
  int rc, i;
  char *zErrMsg = 0;














  /* Allocate the sqlite data structure */
  db = sqliteMalloc( sizeof(sqlite) );
  if( db==0 ) goto opendb_out;
  db->onError = OE_Default;
  db->priorNewRowid = 0;
  db->magic = SQLITE_MAGIC_BUSY;
................................................................................
  *ppDb = db;
  return sqlite3_errcode(db);
}

/*
** Open a new database handle.
*/
int sqlite3_open_new(
  const char *zFilename, 
  sqlite3 **ppDb, 
  const char **options
){
  return openDatabase(zFilename, ppDb, options, TEXT_Utf8);
  /* return openDatabase(zFilename, ppDb, options, TEXT_Utf16le); */
}

sqlite *sqlite3_open(const char *zFilename, int mode, char **pzErrMsg){
  sqlite3 *db;
  int rc;
 
  rc = sqlite3_open_new(zFilename, &db, 0);
  if( rc!=SQLITE_OK && pzErrMsg ){
    char *err = sqlite3_errmsg(db);
    *pzErrMsg = malloc(strlen(err)+1);
    strcpy(*pzErrMsg, err);
  }
  return db;
}

/*
** Open a new database handle.
*/
int sqlite3_open16(
  const void *zFilename, 
................................................................................
  assert( ppDb );

  zFilename8 = sqlite3utf16to8(zFilename, -1, SQLITE3_BIGENDIAN);
  if( !zFilename8 ){
    *ppDb = 0;
    return SQLITE_NOMEM;
  }



  if( SQLITE3_BIGENDIAN ){
    rc = openDatabase(zFilename8, ppDb, options, TEXT_Utf16be);
  }else{
    rc = openDatabase(zFilename8, ppDb, options, TEXT_Utf16le);
  }

................................................................................
*/
int sqlite3_reset_new(sqlite3_stmt *pStmt){
  int rc = sqlite3VdbeReset((Vdbe*)pStmt, 0);
  sqlite3VdbeMakeReady((Vdbe*)pStmt, -1, 0);
  return rc;
}

#if 0

/*
** sqlite3_open
**
*/
int sqlite3_open(const char *filename, sqlite3 **pDb, const char **options){
  *pDb = sqlite3_open(filename, 0, &errmsg);
  return (*pDb?SQLITE_OK:SQLITE_ERROR);
}
int sqlite3_open16(const void *filename, sqlite3 **pDb, const char **options){
  int rc;
  char * filename8;

  filename8 = sqlite3utf16to8(filename, -1, SQLITE3_BIGENDIAN);
  if( !filename8 ){
    return SQLITE_NOMEM;
  }

  rc = sqlite3_open(filename8, pDb, options);
  sqliteFree(filename8);

  return rc;
}

/*
** sqlite3_close
**
*/
int sqlite3_close(sqlite3 *db){
  return sqlite3_close(db);
}

/*
** sqlite3_errmsg
**
** TODO: !
*/
const char *sqlite3_errmsg(sqlite3 *db){
  assert(!"TODO");
}
const void *sqlite3_errmsg16(sqlite3 *db){
  assert(!"TODO");
}

/*
** sqlite3_errcode
**
** TODO: !
*/
int sqlite3_errcode(sqlite3 *db){
  assert(!"TODO");
}

struct sqlite_stmt {
};

/*
** sqlite3_finalize
*/
int sqlite3_finalize(sqlite3_stmt *stmt){
  return sqlite3_finalize(stmt, 0);
}

/*
** sqlite3_reset
*/
int sqlite3_reset(sqlite3_stmt*){
  return sqlite3_reset(stmt, 0);
}

/*
** sqlite3_step
*/
int sqlite3_step(sqlite3_stmt *pStmt){
  return sqlite3_step(pStmt);
}

int sqlite3_column_count(sqlite3_stmt*){
}

int sqlite3_column_type(sqlite3_stmt*,int){
}

const char *sqlite3_column_decltype(sqlite3_stmt*,int){
}

const void *sqlite3_column_decltype16(sqlite3_stmt*,int){
}

const char *sqlite3_column_name(sqlite3_stmt*,int){
}

const void *sqlite3_column_name16(sqlite3_stmt*,int){
}

const unsigned char *sqlite3_column_data(sqlite3_stmt*,int){
}

const void *sqlite3_column_data16(sqlite3_stmt*,int){
}

int sqlite3_column_bytes(sqlite3_stmt*,int){
}

long long int sqlite3_column_int(sqlite3_stmt*,int){
}

double sqlite3_column_float(sqlite3_stmt*,int){
}

#endif







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>







 







|





<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>
>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
....
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
....
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278














1279
1280
1281
1282
1283
1284
1285
....
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
....
1332
1333
1334
1335
1336
1337
1338
















































































































**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.184 2004/05/22 09:21:21 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/*
** A pointer to this structure is used to communicate information
................................................................................
  sqlite3 **ppDb,        /* OUT: Returned database handle */
  const char **options,  /* Null terminated list of db options, or null */
  u8 def_enc             /* One of TEXT_Utf8, TEXT_Utf16le or TEXT_Utf16be */
){
  sqlite3 *db;
  int rc, i;
  char *zErrMsg = 0;

#ifdef SQLITE_TEST
  for(i=0; options && options[i]; i++){
    char const *zOpt = options[i];
    if( 0==sqlite3StrICmp(zOpt, "-utf8") ){
      def_enc = TEXT_Utf8;
    }else if( 0==sqlite3StrICmp(zOpt, "-utf16le") ){
      def_enc = TEXT_Utf16le;
    }else if( 0==sqlite3StrICmp(zOpt, "-utf16be") ){
      def_enc = TEXT_Utf16be;
    }
  }
#endif

  /* Allocate the sqlite data structure */
  db = sqliteMalloc( sizeof(sqlite) );
  if( db==0 ) goto opendb_out;
  db->onError = OE_Default;
  db->priorNewRowid = 0;
  db->magic = SQLITE_MAGIC_BUSY;
................................................................................
  *ppDb = db;
  return sqlite3_errcode(db);
}

/*
** Open a new database handle.
*/
int sqlite3_open(
  const char *zFilename, 
  sqlite3 **ppDb, 
  const char **options
){
  return openDatabase(zFilename, ppDb, options, TEXT_Utf8);














}

/*
** Open a new database handle.
*/
int sqlite3_open16(
  const void *zFilename, 
................................................................................
  assert( ppDb );

  zFilename8 = sqlite3utf16to8(zFilename, -1, SQLITE3_BIGENDIAN);
  if( !zFilename8 ){
    *ppDb = 0;
    return SQLITE_NOMEM;
  }

  /* FIX ME: Also need to translate the option strings */

  if( SQLITE3_BIGENDIAN ){
    rc = openDatabase(zFilename8, ppDb, options, TEXT_Utf16be);
  }else{
    rc = openDatabase(zFilename8, ppDb, options, TEXT_Utf16le);
  }

................................................................................
*/
int sqlite3_reset_new(sqlite3_stmt *pStmt){
  int rc = sqlite3VdbeReset((Vdbe*)pStmt, 0);
  sqlite3VdbeMakeReady((Vdbe*)pStmt, -1, 0);
  return rc;
}

















































































































Changes to src/shell.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code to implement the "sqlite" command line
** utility for accessing SQLite databases.
**
** $Id: shell.c,v 1.96 2004/05/14 11:00:53 danielk1977 Exp $
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "sqlite.h"
#include <ctype.h>

................................................................................

/*
** Make sure the database is open.  If it is not, then open it.  If
** the database fails to open, print an error message and exit.
*/
static void open_db(struct callback_data *p){
  if( p->db==0 ){
    char *zErrMsg = 0;
#ifdef SQLITE_HAS_CODEC
    int n = p->zKey ? strlen(p->zKey) : 0;
    db = p->db = sqlite3_open_encrypted(p->zDbFilename, p->zKey, n, 0, &zErrMsg);
#else
    db = p->db = sqlite3_open(p->zDbFilename, 0, &zErrMsg);
#endif
    if( p->db==0 ){
      if( zErrMsg ){
        fprintf(stderr,"Unable to open database \"%s\": %s\n", 
           p->zDbFilename, zErrMsg);
      }else{
        fprintf(stderr,"Unable to open database %s\n", p->zDbFilename);
      }
      exit(1);
    }
  }
}

/*
** If an input line begins with "." then invoke this routine to







|







 







<



|
|
|
|
|
|
|
|
<
<







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
506
507
508
509
510
511
512

513
514
515
516
517
518
519
520
521
522
523


524
525
526
527
528
529
530
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code to implement the "sqlite" command line
** utility for accessing SQLite databases.
**
** $Id: shell.c,v 1.97 2004/05/22 09:21:21 danielk1977 Exp $
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "sqlite.h"
#include <ctype.h>

................................................................................

/*
** Make sure the database is open.  If it is not, then open it.  If
** the database fails to open, print an error message and exit.
*/
static void open_db(struct callback_data *p){
  if( p->db==0 ){

#ifdef SQLITE_HAS_CODEC
    int n = p->zKey ? strlen(p->zKey) : 0;
    db = p->db = sqlite3_open_encrypted(p->zDbFilename, p->zKey, n, 0, &zErrMsg);
    assert(0); /* Encrypted databases are broken in SQLite 3 */
#else
    sqlite3_open(p->zDbFilename, &p->db, 0);
    db = p->db;
#endif
    if( SQLITE_OK!=sqlite3_errcode(db) ){
      fprintf(stderr,"Unable to open database \"%s\": %s\n", 
          p->zDbFilename, sqlite3_errmsg(db));


      exit(1);
    }
  }
}

/*
** If an input line begins with "." then invoke this routine to

Changes to src/sqlite.h.in.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
....
1199
1200
1201
1202
1203
1204
1205















1206
1207
1208
1209
1210
1211















1212
1213
1214
1215
1216
1217
1218
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the SQLite library
** presents to client programs.
**
** @(#) $Id: sqlite.h.in,v 1.68 2004/05/21 10:08:54 danielk1977 Exp $
*/
#ifndef _SQLITE_H_
#define _SQLITE_H_
#include <stdarg.h>     /* Needed for the definition of va_list */

/*
** Make sure we can call this stuff from C++.
................................................................................

/*
** Each open sqlite database is represented by an instance of the
** following opaque structure.
*/
typedef struct sqlite sqlite;

/*
** A function to open a new sqlite database.  
**
** If the database does not exist and mode indicates write
** permission, then a new database is created.  If the database
** does not exist and mode does not indicate write permission,
** then the open fails, an error message generated (if errmsg!=0)
** and the function returns 0.
** 
** If mode does not indicates user write permission, then the 
** database is opened read-only.
**
** The Truth:  As currently implemented, all databases are opened
** for writing all the time.  Maybe someday we will provide the
** ability to open a database readonly.  The mode parameters is
** provided in anticipation of that enhancement.
*/
sqlite *sqlite3_open(const char *filename, int mode, char **errmsg);

/*
** A function to close the database.
**
** Call this function with a pointer to a structure that was previously
** returned from sqlite3_open() and the corresponding database will by closed.
*/
void sqlite3_close(sqlite *);
................................................................................
** statement obtained by a previous call to sqlite3_prepare() or
** sqlite3_prepare16() back to it's initial state, ready to be re-executed.
** Any SQL statement variables that had values bound to them using
** the sqlite3_bind_*() API retain their values.
*/
int sqlite3_reset_new(sqlite3_stmt *pStmt);
















int sqlite3_open_new(
  const char *filename,   /* Database filename (UTF-8) */
  sqlite3 **ppDb,         /* OUT: SQLite db handle */
  const char **args       /* Null terminated array of option strings */
);
















int sqlite3_open16(
  const void *filename,   /* Database filename (UTF-16) */
  sqlite3 **ppDb,         /* OUT: SQLite db handle */
  const char **args       /* Null terminated array of option strings */
);

/*







|







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|





>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
54
55
56
57
58
59
60



















61
62
63
64
65
66
67
....
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the SQLite library
** presents to client programs.
**
** @(#) $Id: sqlite.h.in,v 1.69 2004/05/22 09:21:21 danielk1977 Exp $
*/
#ifndef _SQLITE_H_
#define _SQLITE_H_
#include <stdarg.h>     /* Needed for the definition of va_list */

/*
** Make sure we can call this stuff from C++.
................................................................................

/*
** Each open sqlite database is represented by an instance of the
** following opaque structure.
*/
typedef struct sqlite sqlite;




















/*
** A function to close the database.
**
** Call this function with a pointer to a structure that was previously
** returned from sqlite3_open() and the corresponding database will by closed.
*/
void sqlite3_close(sqlite *);
................................................................................
** statement obtained by a previous call to sqlite3_prepare() or
** sqlite3_prepare16() back to it's initial state, ready to be re-executed.
** Any SQL statement variables that had values bound to them using
** the sqlite3_bind_*() API retain their values.
*/
int sqlite3_reset_new(sqlite3_stmt *pStmt);

/*
** Open the sqlite database file "filename", where "filename" is UTF-8
** encoded. An sqlite3* handle is returned in *ppDb, even if an error 
** occurs. If the database is opened (or created) successfully, then 
** SQLITE_OK is returned. Otherwise an error code is returned and the
** sqlite3_errmsg() function may be used to obtain an English language
** explanation of the error.
**
** If the database file does not exist, then a new database is created
** using UTF-8 text encoding.
**
** Whether or not an error occurs when it is opened, resources associated
** with the sqlite3* handle should be released by passing it to
** sqlite3_close() when it is no longer required.
*/
int sqlite3_open(
  const char *filename,   /* Database filename (UTF-8) */
  sqlite3 **ppDb,         /* OUT: SQLite db handle */
  const char **args       /* Null terminated array of option strings */
);

/*
** Open the sqlite database file "filename", where "filename" is native
** byte order UTF-16 encoded. An sqlite3* handle is returned in *ppDb, even
** if an error occurs. If the database is opened (or created) successfully,
** then SQLITE_OK is returned. Otherwise an error code is returned and the
** sqlite3_errmsg() function may be used to obtain an English language
** explanation of the error.
**
** If the database file does not exist, then a new database is created
** using UTF-16 text encoding in the machines native byte order.
**
** Whether or not an error occurs when it is opened, resources associated
** with the sqlite3* handle should be released by passing it to
** sqlite3_close() when it is no longer required.
*/
int sqlite3_open16(
  const void *filename,   /* Database filename (UTF-16) */
  sqlite3 **ppDb,         /* OUT: SQLite db handle */
  const char **args       /* Null terminated array of option strings */
);

/*

Changes to src/tclsqlite.c.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
....
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029

1030
1031
1032
1033
1034
1035
1036
....
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090



1091





1092
1093
1094
1095
1096
1097
1098
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** A TCL Interface to SQLite
**
** $Id: tclsqlite.c,v 1.65 2004/05/11 06:17:22 danielk1977 Exp $
*/
#ifndef NO_TCL     /* Omit this whole file if TCL is unavailable */

#include "sqliteInt.h"
#include "tcl.h"
#include <stdlib.h>
#include <string.h>
................................................................................
**  sqlite -tcl-uses-utf
**
**       Return "1" if compiled with a Tcl uses UTF-8.  Return "0" if
**       not.  Used by tests to make sure the library was compiled 
**       correctly.
*/
static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
  int mode;
  SqliteDb *p;
  void *pKey = 0;
  int nKey = 0;
  const char *zArg;
  char *zErrMsg;
  const char *zFile;

  char zBuf[80];
  if( objc==2 ){
    zArg = Tcl_GetStringFromObj(objv[1], 0);
    if( strcmp(zArg,"-encoding")==0 ){
      Tcl_AppendResult(interp,sqlite3_encoding,0);
      return TCL_OK;
    }
................................................................................
      "HANDLE FILENAME ?-key CODEC-KEY?"
#else
      "HANDLE FILENAME ?MODE?"
#endif
    );
    return TCL_ERROR;
  }
  if( objc==3 ){
    mode = 0666;
  }else if( Tcl_GetIntFromObj(interp, objv[3], &mode)!=TCL_OK ){
    return TCL_ERROR;
  }
  zErrMsg = 0;
  p = (SqliteDb*)Tcl_Alloc( sizeof(*p) );
  if( p==0 ){
    Tcl_SetResult(interp, "malloc failed", TCL_STATIC);
    return TCL_ERROR;
  }
  memset(p, 0, sizeof(*p));
  zFile = Tcl_GetStringFromObj(objv[2], 0);
#ifdef SQLITE_HAS_CODEC
  p->db = sqlite3_open_encrypted(zFile, pKey, nKey, 0, &zErrMsg);
#else



  p->db = sqlite3_open(zFile, mode, &zErrMsg);





#endif
  if( p->db==0 ){
    Tcl_SetResult(interp, zErrMsg, TCL_VOLATILE);
    Tcl_Free((char*)p);
    free(zErrMsg);
    return TCL_ERROR;
  }







|







 







<






>







 







<
<
<
<
<











>
>
>
|
>
>
>
>
>







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
....
1016
1017
1018
1019
1020
1021
1022

1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
....
1068
1069
1070
1071
1072
1073
1074





1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** A TCL Interface to SQLite
**
** $Id: tclsqlite.c,v 1.66 2004/05/22 09:21:21 danielk1977 Exp $
*/
#ifndef NO_TCL     /* Omit this whole file if TCL is unavailable */

#include "sqliteInt.h"
#include "tcl.h"
#include <stdlib.h>
#include <string.h>
................................................................................
**  sqlite -tcl-uses-utf
**
**       Return "1" if compiled with a Tcl uses UTF-8.  Return "0" if
**       not.  Used by tests to make sure the library was compiled 
**       correctly.
*/
static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){

  SqliteDb *p;
  void *pKey = 0;
  int nKey = 0;
  const char *zArg;
  char *zErrMsg;
  const char *zFile;
  const char *zOpts[2] = {0, 0};
  char zBuf[80];
  if( objc==2 ){
    zArg = Tcl_GetStringFromObj(objv[1], 0);
    if( strcmp(zArg,"-encoding")==0 ){
      Tcl_AppendResult(interp,sqlite3_encoding,0);
      return TCL_OK;
    }
................................................................................
      "HANDLE FILENAME ?-key CODEC-KEY?"
#else
      "HANDLE FILENAME ?MODE?"
#endif
    );
    return TCL_ERROR;
  }





  zErrMsg = 0;
  p = (SqliteDb*)Tcl_Alloc( sizeof(*p) );
  if( p==0 ){
    Tcl_SetResult(interp, "malloc failed", TCL_STATIC);
    return TCL_ERROR;
  }
  memset(p, 0, sizeof(*p));
  zFile = Tcl_GetStringFromObj(objv[2], 0);
#ifdef SQLITE_HAS_CODEC
  p->db = sqlite3_open_encrypted(zFile, pKey, nKey, 0, &zErrMsg);
#else
  if( objc>3 ){
    zOpts[0] = Tcl_GetString(objv[3]);
  }
  sqlite3_open(zFile, &p->db, zOpts);
  if( SQLITE_OK!=sqlite3_errcode(p->db) ){
    zErrMsg = strdup(sqlite3_errmsg(p->db));
    sqlite3_close(p->db);
    p->db = 0;
  }
#endif
  if( p->db==0 ){
    Tcl_SetResult(interp, zErrMsg, TCL_VOLATILE);
    Tcl_Free((char*)p);
    free(zErrMsg);
    return TCL_ERROR;
  }

Changes to src/test1.c.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
....
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
**    May you share freely, never taking more than you give.
**
*************************************************************************
** Code for testing the printf() interface to SQLite.  This code
** is not included in the SQLite library.  It is used for automated
** testing of the SQLite library.
**
** $Id: test1.c,v 1.45 2004/05/21 10:08:54 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include "os.h"
#include <stdlib.h>
#include <string.h>

................................................................................
  if( objc!=3 && objc!=2 ){
    Tcl_AppendResult(interp, "wrong # args: should be \"", 
       Tcl_GetString(objv[0]), " filename options-list", 0);
    return TCL_ERROR;
  }

  zFilename = Tcl_GetString(objv[1]);
  rc = sqlite3_open_new(zFilename, &db, 0);
  
  if( makePointerStr(interp, zBuf, db) ) return TCL_ERROR;
  Tcl_AppendResult(interp, zBuf, 0);
  return TCL_OK;
}

/*







|







 







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
....
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
**    May you share freely, never taking more than you give.
**
*************************************************************************
** Code for testing the printf() interface to SQLite.  This code
** is not included in the SQLite library.  It is used for automated
** testing of the SQLite library.
**
** $Id: test1.c,v 1.46 2004/05/22 09:21:21 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include "os.h"
#include <stdlib.h>
#include <string.h>

................................................................................
  if( objc!=3 && objc!=2 ){
    Tcl_AppendResult(interp, "wrong # args: should be \"", 
       Tcl_GetString(objv[0]), " filename options-list", 0);
    return TCL_ERROR;
  }

  zFilename = Tcl_GetString(objv[1]);
  rc = sqlite3_open(zFilename, &db, 0);
  
  if( makePointerStr(interp, zBuf, db) ) return TCL_ERROR;
  Tcl_AppendResult(interp, zBuf, 0);
  return TCL_OK;
}

/*

Changes to src/test4.c.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
61
62
63
64
65
66
67
68





69
70
71
72
73
74
75
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** Code for testing the the SQLite library in a multithreaded environment.
**
** $Id: test4.c,v 1.5 2004/05/10 10:34:53 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#if defined(OS_UNIX) && OS_UNIX==1 && defined(THREADSAFE) && THREADSAFE==1
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
................................................................................
** The main loop for a thread.  Threads use busy waiting. 
*/
static void *thread_main(void *pArg){
  Thread *p = (Thread*)pArg;
  if( p->db ){
    sqlite3_close(p->db);
  }
  p->db = sqlite3_open(p->zFilename, 0, &p->zErr);





  p->vm = 0;
  p->completed = 1;
  while( p->opnum<=p->completed ) sched_yield();
  while( p->xOp ){
    if( p->zErr && p->zErr!=p->zStaticErr ){
      sqlite3_freemem(p->zErr);
      p->zErr = 0;







|







 







|
>
>
>
>
>







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

Changes to src/vacuum.c.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
262
263
264
265
266
267
268
269
270
271
272

273
274
275
276
277
278
279
...
309
310
311
312
313
314
315

316
317
318
319
320
321
322
323
**
*************************************************************************
** This file contains code used to implement the VACUUM command.
**
** Most of the code in this file may be omitted by defining the
** SQLITE_OMIT_VACUUM macro.
**
** $Id: vacuum.c,v 1.15 2004/05/10 10:35:00 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"

/*
** A structure for holding a dynamic string - a string that can grow
** without bound. 
................................................................................
  if( i>=10 ){
    sqlite3SetString(pzErrMsg, "unable to create a temporary database file "
       "in the same directory as the original database", (char*)0);
    goto end_of_vacuum;
  }

  
  dbNew = sqlite3_open(zTemp, 0, &zErrMsg);
  if( dbNew==0 ){
    sqlite3SetString(pzErrMsg, "unable to open a temporary database at ",
       zTemp, " - ", zErrMsg, (char*)0);

    goto end_of_vacuum;
  }
  if( (rc = execsql(pzErrMsg, db, "BEGIN"))!=0 ) goto end_of_vacuum;
  if( (rc = execsql(pzErrMsg, dbNew, "PRAGMA synchronous=off; BEGIN"))!=0 ){
    goto end_of_vacuum;
  }
  
................................................................................
  }
  sqlite3_exec(db, "ROLLBACK", 0, 0, 0);
  if( dbNew ) sqlite3_close(dbNew);
  sqlite3OsDelete(zTemp);
  sqliteFree(zTemp);
  sqliteFree(sVac.s1.z);
  sqliteFree(sVac.s2.z);

  if( zErrMsg ) sqlite3_freemem(zErrMsg);
  if( rc==SQLITE_ABORT ) sVac.rc = SQLITE_ERROR;
  return sVac.rc;
#endif
}










|







 







|
<

<
>







 







>








10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
262
263
264
265
266
267
268
269

270

271
272
273
274
275
276
277
278
...
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
**
*************************************************************************
** This file contains code used to implement the VACUUM command.
**
** Most of the code in this file may be omitted by defining the
** SQLITE_OMIT_VACUUM macro.
**
** $Id: vacuum.c,v 1.16 2004/05/22 09:21:21 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"

/*
** A structure for holding a dynamic string - a string that can grow
** without bound. 
................................................................................
  if( i>=10 ){
    sqlite3SetString(pzErrMsg, "unable to create a temporary database file "
       "in the same directory as the original database", (char*)0);
    goto end_of_vacuum;
  }

  
  if( SQLITE_OK!=sqlite3_open(zTemp, &dbNew, 0) ){

    sqlite3SetString(pzErrMsg, "unable to open a temporary database at ",

       zTemp, " - ", sqlite3_errmsg(dbNew), (char*)0);
    goto end_of_vacuum;
  }
  if( (rc = execsql(pzErrMsg, db, "BEGIN"))!=0 ) goto end_of_vacuum;
  if( (rc = execsql(pzErrMsg, dbNew, "PRAGMA synchronous=off; BEGIN"))!=0 ){
    goto end_of_vacuum;
  }
  
................................................................................
  }
  sqlite3_exec(db, "ROLLBACK", 0, 0, 0);
  if( dbNew ) sqlite3_close(dbNew);
  sqlite3OsDelete(zTemp);
  sqliteFree(zTemp);
  sqliteFree(sVac.s1.z);
  sqliteFree(sVac.s2.z);
  if( dbNew ) sqlite3_close(dbNew);
  if( zErrMsg ) sqlite3_freemem(zErrMsg);
  if( rc==SQLITE_ABORT ) sVac.rc = SQLITE_ERROR;
  return sVac.rc;
#endif
}