/ Check-in [174116f7]
Login

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

Overview
Comment:Revisions to the interface design for 3.5. (CVS 4225)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 174116f7c0ceeceb5e32868b29fabf8a6943cbf6
User & Date: drh 2007-08-15 11:28:56
Context
2007-08-15
13:04
Add initial implementations of mutex and memory subsystem modules. (CVS 4226) check-in: c0fa3769 user: drh tags: trunk
11:28
Revisions to the interface design for 3.5. (CVS 4225) check-in: 174116f7 user: drh tags: trunk
2007-08-14
18:03
Clarify documentation on sqlite3_interrupt(). (CVS 4224) check-in: 0b5b526c user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/sqlite.h.in.

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
...
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
...
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
...
409
410
411
412
413
414
415
416


417
418
419
420
421
422
423
424
425
426
427
428























































429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452

453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468

469
470
471



472
473
474







475









476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
...
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587



588
589
590
591
592
593
594
595
596
597
598
599
600
601
602





603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
....
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013









1014
1015
1016
1017
























































1018
1019
1020
1021
1022
1023
1024
....
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
....
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
....
3043
3044
3045
3046
3047
3048
3049






































































































3050
3051
3052
3053
3054
3055
3056
** on how SQLite interfaces are suppose to operate.
**
** The name of this file under configuration management is "sqlite.h.in".
** The makefile makes some minor changes to this file (such as inserting
** the version number) and changes its name to "sqlite3.h" as
** part of the build process.
**
** @(#) $Id: sqlite.h.in,v 1.221 2007/08/14 18:03:15 drh Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
#include <stdarg.h>     /* Needed for the definition of va_list */

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

/*
** CAPI3REF: Flags For File Open Operations
**
** Combination of the following bit values are used as the
** third argument to the [sqlite3_open_v2()] interface and
** as fourth argument to the xOpen method of the
** [sqlite3_adaptor] object.
**
*/
#define SQLITE_OPEN_READONLY         0x00000001
#define SQLITE_OPEN_READWRITE        0x00000002
#define SQLITE_OPEN_CREATE           0x00000004
#define SQLITE_OPEN_DELETEONCLOSE    0x00000008
#define SQLITE_OPEN_EXCLUSIVE        0x00000010
................................................................................
#define SQLITE_IOCAP_SEQUENTIAL      0x00000400

/*
** CAPI3REF: File Locking Levels
**
** SQLite uses one of the following integer values as the second
** argument to calls it makes to the xLock() and xUnlock() methods
** of an [sqlite3_io_methods] object.  SQLite expects the return
*** value from the xGetLock() method to be one of these integers.
*/
#define SQLITE_LOCK_NONE          0
#define SQLITE_LOCK_SHARED        1
#define SQLITE_LOCK_RESERVED      2
#define SQLITE_LOCK_PENDING       3
#define SQLITE_LOCK_EXCLUSIVE     4

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

/*
** CAPI3REF: OS Interface Open File Handle
**
** An [sqlite3_file] object represents an open file in the OS
** interface layer.  Individual OS interface implementations will
** want to subclass this object by appending additional fields
** of their own use.


*/
typedef struct sqlite3_file sqlite3_file;
struct sqlite3_file {
  struct sqlite3_io_methods *pMethods;  /* Methods against the open file */
};

/*
** CAPI3REF: OS Interface File Virtual Methods Object
**
** Every open file in the OS interface layer contains a pointer to
** an instance of the following object.  This object defines the
** methods used to perform various operations against the open file.























































*/
typedef struct sqlite3_io_methods sqlite3_io_methods;
struct sqlite3_io_methods {
  int iVersion;
  int (*xClose)(sqlite3_file*);
  int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite_int64 iOfst);
  int (*xWrite)(sqlite3_file*, void*, int iAmt, sqlite_int64 iOfst);
  int (*xTruncate)(sqlite3_file*, sqlite_int64 size);
  int (*xSync)(sqlite3_file*, int flags);
  int (*xFileSize)(sqlite3_file*, sqlite_int64 *pSize);
  int (*xLock)(sqlite3_file*, int);
  int (*xUnlock)(sqlite3_file*, int);
  int (*xGetLock)(sqlite3_file*);
  int (*xBreakLock)(sqlite3_file*);
  int (*xSectorSize)(sqlite3_file*);
  int (*xDeviceCharacteristics)(sqlite3_file*);
  /* Additional methods may be added in future releases */
};

/*
** CAPI3REF: OS Interface Mutex Handle
**
** Each OS interface implementation defines an [sqlite3_mutex] according
** to its own needs.  The SQLite core only deals with pointers to

** [sqlite3_mutex] objects and knows nothing about their internal
** structure.
*/
typedef struct sqlite3_mutex sqlite3_mutex;

/*
** CAPI3REF: OS Interface Object
**
** An instance of the [sqlite3_adaptor] object defines the OS interface
** for an SQLite database connection.  A pointer to an instance of
** this object is the fourth parameter to [sqlite3_open_v2()].  
**
** The iVersion field is initially 1 but may be larger for future
** versions.  szOsFile is the size of the subclassed [sqlite3_file]
** structure used by these methods.  szMutex is the size of the
** [sqlite3_mutex] structure.  mxPathname is the maximum length of

** an OS pathname.  By knowing all of these values in advance, we 
** intend for them to be allocated in advance so that the OS
** interface methods never need to malloc() for themselves.



** 
** The osMutex is a preallocated mutex.
** xDeallocateMutex() is never called for this mutex.







** 









** SQLite will guarantee that the zFilename string passed to
** xOpen() is a full pathname as generated by xFullPathname() and
** that the string will be valid and unchanged until xClose() is
** callled.  So the [sqlite3_file] can store a pointer to the
** filename if it needs to remember the filename for some reason.
** 
** The flags argument to xOpen() is a copy of the flags argument
** to [sqlite3_open_v2()].  If [sqlite3_open()] or [sqlite3_open16()]
** is used, then flags is [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
** If xOpen() opens a file read-only then it sets *pOutFlags to
** include [SQLITE_OPEN_READONLY].  Other bits in *pOutFlags may be
** set.
** 
** SQLite will also add one of the following flags to the xOpen()
** call, depending on the object being opened:
** 
** <ul>
** <li>  [SQLITE_OPEN_MAIN_DB]
** <li>  [SQLITE_OPEN_MAIN_JOURNAL]
** <li>  [SQLITE_OPEN_TEMP_DB]
** <li>  [SQLITE_OPEN_TEMP_JOURNAL]
** <li>  [SQLITE_OPEN_SUBJOURNAL]
** <li>  [SQLITE_OPEN_MASTER_JOURNAL]
** </ul>
** 
** The file I/O implementation can use the object type flags to
** changes the way it deals with files.  For example, an application
** that does not care about crash recovery or rollback, might make
** the open of a journal file a no-op.  Writes to this journal are
** also a no-op.  Any attempt to read the journal return [SQLITE_IOERR].
** Or the implementation might recognize the a database file will
** be doing page-aligned sector reads and writes in a random order
** and set up its I/O subsystem accordingly.
** 
** SQLite might also add one of the following flags to the xOpen
** method:
** 
................................................................................
** if a file is readable and writable, or SQLITE_ACCESS_READONLY
** to test to see if a file is read-only.  The file can be a 
** directory.
** 
** SQLite will always allocate at least mxPathname+1 byte for
** the output buffers for xGetTempName and xFullPathname.
** 
** The xGetGlobal and xSetGlobal methods access an associatative
** array of pointers to void.  SQLite always holds the osMutex 
** when using either routine.  The only currently defined value
** for iClass is SQLITE_CLASS_SHAREDCACHE.  The xGetGlobal
** routine returns a NULL pointer if the requested element does not
** exist.  xSetGlobal replaces an element with the new pointer.
** xSetGlobal returns either [SQLITE_OK], [SQLITE_FULL], [SQLITE_NOMEM],
** or [SQLITE_MISUSE].  The entry is deleted if the new pointer is 
** NULL.  The OS interface can implement these methods as a linked 
** list or as a hash table or anything else that seems appropriate.
** 
** The xMalloc(), xRealloc(), and xFree() methods are the traditional
** memory allocation and freeing routines.  The prior
** allocation pointer to xFree() and xRealloc() is always non-NULL.
** The new allocation size given to xRealloc() is always positive.
** 
** xReclaimAlloc(), xReclaimFree(), and xReclaimSetCallback() are
** memory allocation routines in which the memory can be reclaimed
** asynchronously by the memory allocation subsystem.  Only memory
** allocated by xReclaimAlloc() can be reclaimed in this way, and
** then only when a reclaim callback is registered on the allocation.
** xReclaimAlloc() and xReclaimFree() are distinct from xMalloc()
** and xFree() since we suspect the former versions will have 
** additional overhead and also be much less frequently used.
** 
** The xReclaimSetCallback() method declares to the memory subsystem 
** that a particular memory allocation can be reclaimed by the memory
** subsystem if it comes under memory pressure.  In order to reclaim
** the allocation, the memory subsystem must first hold the
** mutex given in the 3rd argument.  Then it invokes the callback
** of the 4th argument passing in a copy of the 5th argument and
** a pointer to the allocation.  If the callback returns 0 then
** the allocation is reclaimed.  If the callback returns anything
** other than 1, then the reclaim request is denied.  The xReclaimable
** method can be called with a NULL callback pointer to indicate
** that the allocation is no longer reclaimable.
** 
** The [sqlite3_release_memory()] and [sqlite3_soft_heap_limit()]
** interfaces are not part of the "core" SQLite where "core" is
** defined as the part of SQLite that uses the [sqlite3_adaptor].
** The [sqlite3_release_memory()] and [sqlite3_soft_heap_limit()]
** interfaces are part of the default memory subsystem.  If
** individual applications override the default memory subsystem,
** then [sqlite3_release_memory()] and [sqlite3_soft_heap_limit()]
** will not work on those applications.
** 
** The xRandomness() function attempts to return nBytes bytes
** of good-quality randomness into zOut.  The return value is
** the actual number of bytes of randomness generated.



** 
** Mutexes are recursive.  By this we mean that the same thread
** can enter a single mutex multiple times.  Other threads cannot
** enter the mutex until the original thread has leaf the mutex
** once for each time entered.  xEnterMutex returns 0 on success.
** If the blockFlag is 0 and another thread already holds the 
** mutex, then xEnterMutex returns 1.
*/
typedef struct sqlite3_adaptor sqlite3_adaptor;
struct sqlite3_adaptor {
  int iVersion;            /* Structure version number */
  int szOsFile;            /* Size of subclassed sqlite3_file */
  int szMutex;             /* Size of an sqlite3_mutex structure */
  int mxPathname;          /* Maximum file pathname length */
  sqlite3_mutex *osMutex;  /* A static mutex for this OS interface */





  void *pAppData;          /* Application context */
  int (*xOpen)(void *pAppData, const char *zName, sqlite3_file*,
               int flags, int *pOutFlags);
  int (*xDelete)(void *pAppData, const char *zName);
  int (*xAccess)(void *pAppData, const char *zName, int flags);
  int (*xGetTempName)(void *pAppData, char *zOut);
  int (*xFullPathname)(void *pAppData, const char *zName, char *zOut);
  void *(*xGetGlobal)(void *pAppData, int iClass, const char *zName);
  int (*xSetGlobal)(void *pAppData, int iClass, const char *zName, void*);
  void *(*xDlOpen)(void *pAppData, char *zFilename);
  void (*xDlError)(void*, int nByte, char *zErrMsg);
  void *(*xDlSym)(void*, const char *zSymbol);
  void (*xDlclose)(void*);
  void *(*xMalloc)(void *pAppData, unsigned int nSize);
  void *(*xRealloc)(void *pAppData, void *pOld, unsigned int nNewSize);
  void (*xFree)(void *pAppData, void*);
  void *(*xReclaimAlloc)(void *pAppData, unsigned int size);
  void (*xReclaimSetCallback)(void *pAppData, void *pAllocation,
      sqlite3_mutex*, int (*)(void*,void*), void*);
  void (*xReclaimFree)(void *pAppData, void*);
  int (*xRandomness)(void *pAppData, int nByte, char *zOut);
  int (*xSleep)(void *pAppData, int microseconds);
  int (*xCurrentTime)(void *pAppData, double*);
  int (*xAllocateMutex)(void *pAppData, sqlite3_mutex*);
  int (*xDeallocateMutex)(sqlite3_mutex*);
  int (*xEnterMutex)(sqlite3_mutex*, int blockFlag);
  int (*xLeaveMutex)(sqlite3_mutex*);
  int (*xInMutex)(sqlite3_mutex*);
  /* New fields may be appended in future versions.  The iVersion
  ** value will increment whenever this happens. */
};

/*
** CAPI3REF: Enable Or Disable Extended Result Codes
**
** This routine enables or disables the
................................................................................
char *sqlite3_mprintf(const char*,...);
char *sqlite3_vmprintf(const char*, va_list);
char *sqlite3_snprintf(int,char*,const char*, ...);

/*
** CAPI3REF: Memory Allocation Functions
**
** SQLite uses its own memory allocator.  On some installations, this
** memory allocator is identical to the standard malloc()/realloc()/free()
** and can be used interchangable.  On others, the implementations are
** different.  For maximum portability, it is best not to mix calls
** to the standard malloc/realloc/free with the sqlite versions.









*/
void *sqlite3_malloc(int);
void *sqlite3_realloc(void*, int);
void sqlite3_free(void*);

























































/*
** CAPI3REF: Compile-Time Authorization Callbacks
***
** This routine registers a authorizer callback with the SQLite library.  
** The authorizer callback is invoked as SQL statements are being compiled
** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
................................................................................
** not previously exist, an error is returned.  The second option opens
** the database for reading and writing but the database must already
** exist or an error is returned.  The third option opens the database
** for reading and writing and creates it if it does not already exist.
** The third options is behavior that is used always for sqlite3_open()
** and sqlite3_open16().
**
** The fourth parameter to sqlite3_open_v2() is a pointer to an
** [sqlite3_adaptor] object that defines the operating system 
** interface that the new database connection should use.  If the
** fourth parameter is a NULL pointer then a default suitable for
** the host environment is substituted.
**
** Note to windows users:  The encoding used for the filename argument
** of sqlite3_open() must be UTF-8, not whatever codepage is currently
** defined.  Filenames containing international characters must be converted
................................................................................
  const void *filename,   /* Database filename (UTF-16) */
  sqlite3 **ppDb          /* OUT: SQLite db handle */
);
int sqlite3_open_v2(
  const void *filename,   /* Database filename (UTF-16) */
  sqlite3 **ppDb,         /* OUT: SQLite db handle */
  int flags,              /* Flags */
  sqlite3_adaptor*        /* The OS interface layer */
);

/*
** CAPI3REF: Error Codes And Messages
**
** The sqlite3_errcode() interface returns the numeric
** [SQLITE_OK | result code] or [SQLITE_IOERR_READ | extended result code]
................................................................................
**
** On success, SQLITE_OK is returned. Otherwise, an 
** [SQLITE_ERROR | SQLite error code] or an
** [SQLITE_IOERR_READ | extended error code] is returned.
*/
int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);









































































































/*
** Undo the hack that converts floating point types to integer for
** builds on processors without floating point support.
*/
#ifdef SQLITE_OMIT_FLOATING_POINT







|







 







|







 







|
<







 







|
>
>









|


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












|







|

|
|
>
|
<






|
|
|


|
<
|
>
|
|
|
>
>
>

<
<
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>



|

|

|
|

|













|




|







 







|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


|
>
>
>
|
<
<
<
<
<
<

|
|


<

<
>
>
>
>
>







<
<




<
<
<
<
<
<
<



<
<
<
<
<
|







 







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




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







 







|
|







 







|







 







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







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
...
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
...
371
372
373
374
375
376
377
378

379
380
381
382
383
384
385
...
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
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
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
...
605
606
607
608
609
610
611
612
613
614











































615
616
617
618
619
620
621






622
623
624
625
626

627

628
629
630
631
632
633
634
635
636
637
638
639


640
641
642
643







644
645
646





647
648
649
650
651
652
653
654
....
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
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
1102
1103
1104
1105
....
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
....
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
....
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
** on how SQLite interfaces are suppose to operate.
**
** The name of this file under configuration management is "sqlite.h.in".
** The makefile makes some minor changes to this file (such as inserting
** the version number) and changes its name to "sqlite3.h" as
** part of the build process.
**
** @(#) $Id: sqlite.h.in,v 1.222 2007/08/15 11:28:56 drh Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
#include <stdarg.h>     /* Needed for the definition of va_list */

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

/*
** CAPI3REF: Flags For File Open Operations
**
** Combination of the following bit values are used as the
** third argument to the [sqlite3_open_v2()] interface and
** as fourth argument to the xOpen method of the
** [sqlite3_vfs] object.
**
*/
#define SQLITE_OPEN_READONLY         0x00000001
#define SQLITE_OPEN_READWRITE        0x00000002
#define SQLITE_OPEN_CREATE           0x00000004
#define SQLITE_OPEN_DELETEONCLOSE    0x00000008
#define SQLITE_OPEN_EXCLUSIVE        0x00000010
................................................................................
#define SQLITE_IOCAP_SEQUENTIAL      0x00000400

/*
** CAPI3REF: File Locking Levels
**
** SQLite uses one of the following integer values as the second
** argument to calls it makes to the xLock() and xUnlock() methods
** of an [sqlite3_io_methods] object.

*/
#define SQLITE_LOCK_NONE          0
#define SQLITE_LOCK_SHARED        1
#define SQLITE_LOCK_RESERVED      2
#define SQLITE_LOCK_PENDING       3
#define SQLITE_LOCK_EXCLUSIVE     4

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

/*
** CAPI3REF: OS Interface Open File Handle
**
** An [sqlite3_file] object represents an open file in the OS
** interface layer.  Individual OS interface implementations will
** want to subclass this object by appending additional fields
** of their own use.  The pMethods entry is a pointer to an
** [sqlite3_io_methods] object that defines methods for performing
** I/O operations on the open file.
*/
typedef struct sqlite3_file sqlite3_file;
struct sqlite3_file {
  struct sqlite3_io_methods *pMethods;  /* Methods against the open file */
};

/*
** CAPI3REF: OS Interface File Virtual Methods Object
**
** Every open file in the [sqlite3_vfs] xOpen method contains a pointer to
** an instance of the following object.  This object defines the
** methods used to perform various operations against the open file.
**
** The flags argument to xSync may be one of SQLITE_SYNC_BARRIER,
** SQLITE_SYNC_NORMAL, SQLITE_SYNC_FULL.  The first choice means that
** data is not necessarily synced to disk completely, only that
** all writes that occur before the sync complete before any
** writes that occur after the sync.  The second flag is the
** normal fsync().  The third flag is a OS-X style fullsync.
** The SQLITE_SYNC_DATA flag may be ORed in to indicate that only
** the data of the file and not its inode needs to be synced.
** 
** The integer values to xLock() and xUnlock() are one of
** SQLITE_LOCK_NONE, SQLITE_LOCK_READ, SQLITE_LOCK_RESERVED,
** SQLITE_LOCK_PENDING, or SQLITE_LOCK_EXCLUSIVE.  xLock()
** increases the lock. xUnlock() decreases the lock.  
** The xCheckReservedLock() method looks
** to see if any database connection, either in this
** process or in some other process, is holding an RESERVED,
** PENDING, or EXCLUSIVE lock on the file.  It returns true
** if such a lock exists and false if not.
** 
** xBreakLock() attempts to break a lock held by another process.
** This can be used to remove a stale dot-file lock, for example.
** It returns 0 on success and non-zero for a failure.
**
** The xSectorSize() method returns the sector size of the
** device that underlies the file.  The sector size is the
** minimum write that can be performed without disturbing
** other bytes in the file.  The xDeviceCharacteristics()
** method returns a bit vector describing behaviors of the
** underlying device:
**
** <ul>
** <li> SQLITE_IOCAP_ATOMIC
** <li> SQLITE_IOCAP_ATOMIC512
** <li> SQLITE_IOCAP_ATOMIC1K
** <li> SQLITE_IOCAP_ATOMIC2K
** <li> SQLITE_IOCAP_ATOMIC4K
** <li> SQLITE_IOCAP_ATOMIC8K
** <li> SQLITE_IOCAP_ATOMIC16K
** <li> SQLITE_IOCAP_ATOMIC32K
** <li> SQLITE_IOCAP_ATOMIC64K
** <li> SQLITE_IOCAP_SAFE_APPEND
** <li> SQLITE_IOCAP_SEQUENTIAL
** </ul>
**
** The SQLITE_IOCAP_ATOMIC property means that all writes of
** any size are atomic.  The SQLITE_IOCAP_ATOMICnnn values
** mean that writes of blocks that are nnn bytes in size and
** are aligned to an address which is an integer multiple of
** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
** that when data is appended to a file, the data is appended
** first then the size of the file is extended, never the other
** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
** information is written to disk in the same order as calls
** to xWrite().
*/
typedef struct sqlite3_io_methods sqlite3_io_methods;
struct sqlite3_io_methods {
  int iVersion;
  int (*xClose)(sqlite3_file*);
  int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite_int64 iOfst);
  int (*xWrite)(sqlite3_file*, void*, int iAmt, sqlite_int64 iOfst);
  int (*xTruncate)(sqlite3_file*, sqlite_int64 size);
  int (*xSync)(sqlite3_file*, int flags);
  int (*xFileSize)(sqlite3_file*, sqlite_int64 *pSize);
  int (*xLock)(sqlite3_file*, int);
  int (*xUnlock)(sqlite3_file*, int);
  int (*xCheckReservedLock)(sqlite3_file*);
  int (*xBreakLock)(sqlite3_file*);
  int (*xSectorSize)(sqlite3_file*);
  int (*xDeviceCharacteristics)(sqlite3_file*);
  /* Additional methods may be added in future releases */
};

/*
** CAPI3REF: Mutex Handle
**
** The mutex module within SQLite defines [sqlite3_mutex] to be an
** abstract type for a mutex object.  The SQLite core never looks
** at the internal representation of an [sqlite3_mutex].  It only
** deals with pointers to the [sqlite3_mutex] object.

*/
typedef struct sqlite3_mutex sqlite3_mutex;

/*
** CAPI3REF: OS Interface Object
**
** An instance of this object defines the interface between the
** SQLite core and the underlying operating system.  The "vfs"
** in the name of the object stands for "virtual file system".
**
** The iVersion field is initially 1 but may be larger for future
** versions.  szOsFile is the size of the subclassed sqlite3_file

** structure used by this VFS.  mxPathname is the maximum length of
** a pathname in this VFS.
**
** The nRef field is incremented and decremented by SQLite to keep
** count of the number of users of the VFS.  This field and
** vfsMutex, pNext, and pPrev are the only fields in the sqlite3_vfs 
** structure that SQLite will ever modify.  These fields are modified 
** within an sqlite3_mutex_serialize() call so that updates are threadsafe.
** 


** The sqlite3_vfs.vfsMutex is a mutex used by the OS interface.
** It should initially be NULL.  SQLite will initialize this field
** using sqlite3_mutex_allocate() upon first use of the adaptor
** by sqlite3_open_v2() and will deallocate the mutex when the
** last user closes.  In other words, vfsMutex will be allocated
** when nRef transitions from 0 to 1 and will be deallocated when
** nRef transitions from 1 to 0.
**
** Registered vfs modules are kept on a linked list formed by
** the pNext and pPrev pointers.  The [sqlite3_register_vfs()]
** and [sqlite3_unregister_vfs()] interfaces manage this list
** in a thread-safe way.  The [sqlite3_find_vfs()] searches the
** list.
**
** The zName field holds the name of the VFS module.  The name must
** be unique across all VFS modules.
**
** SQLite will guarantee that the zFilename string passed to
** xOpen() is a full pathname as generated by xFullPathname() and
** that the string will be valid and unchanged until xClose() is
** called.  So the sqlite3_file can store a pointer to the
** filename if it needs to remember the filename for some reason.
**
** The flags argument to xOpen() is a copy of the flags argument
** to sqlite3_open_v2().  If sqlite3_open() or sqlite3_open16()
** is used, then flags is SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE.
** If xOpen() opens a file read-only then it sets *pOutFlags to
** include SQLITE_OPEN_READONLY.  Other bits in *pOutFlags may be
** set.
** 
** SQLite will also add one of the following flags to the xOpen()
** call, depending on the object being opened:
** 
** <ul>
** <li>  [SQLITE_OPEN_MAIN_DB]
** <li>  [SQLITE_OPEN_MAIN_JOURNAL]
** <li>  [SQLITE_OPEN_TEMP_DB]
** <li>  [SQLITE_OPEN_TEMP_JOURNAL]
** <li>  [SQLITE_OPEN_SUBJOURNAL]
** <li>  [SQLITE_OPEN_MASTER_JOURNAL]
** </ul>
**
** The file I/O implementation can use the object type flags to
** changes the way it deals with files.  For example, an application
** that does not care about crash recovery or rollback, might make
** the open of a journal file a no-op.  Writes to this journal are
** also a no-op.  Any attempt to read the journal return SQLITE_IOERR.
** Or the implementation might recognize the a database file will
** be doing page-aligned sector reads and writes in a random order
** and set up its I/O subsystem accordingly.
** 
** SQLite might also add one of the following flags to the xOpen
** method:
** 
................................................................................
** if a file is readable and writable, or SQLITE_ACCESS_READONLY
** to test to see if a file is read-only.  The file can be a 
** directory.
** 
** SQLite will always allocate at least mxPathname+1 byte for
** the output buffers for xGetTempName and xFullPathname.
** 
** The xRandomness(), xSleep(), and xCurrentTime() interfaces
** are not strictly a part of the filesystem, but they are
** included in the VFS structure for completeness.











































** The xRandomness() function attempts to return nBytes bytes
** of good-quality randomness into zOut.  The return value is
** the actual number of bytes of randomness generated.  The
** xSleep() method cause the calling thread to sleep for at
** least the number of microseconds given.  The xCurrentTime()
** method returns a Julian Day Number for the current date and
** time.






*/
typedef struct sqlite3_vfs sqlite3_vfs;
struct sqlite3_vfs {
  int iVersion;            /* Structure version number */
  int szOsFile;            /* Size of subclassed sqlite3_file */

  int mxPathname;          /* Maximum file pathname length */

  int nRef;                /* Number of references to this structure */
  sqlite3_mutex *vfsMutex; /* A mutex for this VFS */
  sqlite3_vfs *pNext;      /* Next registered VFS */
  sqlite3_vfs *pPrev;      /* Previous registered VFS */
  const char *zName;       /* Name of this virtual file system */
  void *pAppData;          /* Application context */
  int (*xOpen)(void *pAppData, const char *zName, sqlite3_file*,
               int flags, int *pOutFlags);
  int (*xDelete)(void *pAppData, const char *zName);
  int (*xAccess)(void *pAppData, const char *zName, int flags);
  int (*xGetTempName)(void *pAppData, char *zOut);
  int (*xFullPathname)(void *pAppData, const char *zName, char *zOut);


  void *(*xDlOpen)(void *pAppData, char *zFilename);
  void (*xDlError)(void*, int nByte, char *zErrMsg);
  void *(*xDlSym)(void*, const char *zSymbol);
  void (*xDlclose)(void*);







  int (*xRandomness)(void *pAppData, int nByte, char *zOut);
  int (*xSleep)(void *pAppData, int microseconds);
  int (*xCurrentTime)(void *pAppData, double*);





  /* New fields may be appended in figure versions.  The iVersion
  ** value will increment whenever this happens. */
};

/*
** CAPI3REF: Enable Or Disable Extended Result Codes
**
** This routine enables or disables the
................................................................................
char *sqlite3_mprintf(const char*,...);
char *sqlite3_vmprintf(const char*, va_list);
char *sqlite3_snprintf(int,char*,const char*, ...);

/*
** CAPI3REF: Memory Allocation Functions
**
** The SQLite sources include a memory allocation subsystem
** that implements the interfaces shown here.
**
** The SQLite core uses these three routines for all of its own
** internal memory allocation needs.  The default implementation
** of the memory allocation subsystem uses the malloc(), realloc()
** and free() provided by the standard C library.  However, if 
** SQLite is compiled with the following C preprocessor macro
**
** <blockquote>SQLITE_OMIT_MEMORY_ALLOCATION</blockquote>
**
** then no implementation is provided for these routines by
** SQLite.  The application that links against SQLite is
** expected to provide its own implementation.
*/
void *sqlite3_malloc(int);
void *sqlite3_realloc(void*, int);
void sqlite3_free(void*);

/*
** CAPI3REF: Memory Allocator Statistics
**
** In addition to the basic three allocation routines 
** [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()],
** the memory allocation subsystem included with the SQLite
** sources provides the interfaces shown below.
**
** The first of these two routines returns the amount of memory 
** currently outstanding (malloced but not freed).  The second
** returns the largest instantaneous amount of outstanding
** memory.  The highwater mark is reset if the argument is
** true.  The SQLite core does not use either of these routines
** and so they do not have to be implemented by the application
** if SQLITE_OMIT_MEMORY_ALLOCATION is defined.  These routines
** are provided by the default memory subsystem for diagnostic
** purposes.
*/
sqlite3_uint64 sqlite3_memory_used(void);
sqlite3_uint64 sqlite3_memory_highwater(int resetFlag);

/*
** CAPI3REF: Memory Allocation Alarms
**
** The [sqlite3_memory_alarm] routine is used to register
** a callback on memory allocation events.
**
** This routine registers or clears a callbacks that fires when
** the amount of memory allocated exceeds iThreshold.  Only
** a single callback can be registered at a time.  Each call
** to [sqlite3_memory_alarm()] overwrites the previous callback.
** The callback is disabled by setting xCallback to a NULL
** pointer.
** 
** The parameters to the callback are the pArg value, the 
** amount of memory currently in use, and the size of the
** allocation that provoked the callback.  The callback will
** presumably invoke [sqlite3_free()] to free up memory space.
** The callback may invoke [sqlite3_malloc()] or [sqlite3_realloc()]
** but if it does, no additional callbacks will be invoked by
** the recursive calls.
**
** The [sqlite3_soft_heap_limit()] interface works by registering
** a memory alarm at the soft heap limit and invoking 
** [sqlite3_release_memory()] in the alarm callback.  Application
** programs should not attempt to use the [sqlite3_memory_alarm()]
** interface because doing so will interfere with the
** [sqlite3_soft_heap_limit()] module.
*/
int sqlite3_memory_alarm(
  void(*xCallback)(void *pArg, sqlite3_uint64 used, unsigned int N),
  void *pArg,
  sqlite3_uint64 iThreshold
);


/*
** CAPI3REF: Compile-Time Authorization Callbacks
***
** This routine registers a authorizer callback with the SQLite library.  
** The authorizer callback is invoked as SQL statements are being compiled
** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
................................................................................
** not previously exist, an error is returned.  The second option opens
** the database for reading and writing but the database must already
** exist or an error is returned.  The third option opens the database
** for reading and writing and creates it if it does not already exist.
** The third options is behavior that is used always for sqlite3_open()
** and sqlite3_open16().
**
** The fourth parameter to sqlite3_open_v2() is the name of the
** [sqlite3_vfs] object that defines the operating system 
** interface that the new database connection should use.  If the
** fourth parameter is a NULL pointer then a default suitable for
** the host environment is substituted.
**
** Note to windows users:  The encoding used for the filename argument
** of sqlite3_open() must be UTF-8, not whatever codepage is currently
** defined.  Filenames containing international characters must be converted
................................................................................
  const void *filename,   /* Database filename (UTF-16) */
  sqlite3 **ppDb          /* OUT: SQLite db handle */
);
int sqlite3_open_v2(
  const void *filename,   /* Database filename (UTF-16) */
  sqlite3 **ppDb,         /* OUT: SQLite db handle */
  int flags,              /* Flags */
  const char *zVfs        /* Name of VFS module to use */
);

/*
** CAPI3REF: Error Codes And Messages
**
** The sqlite3_errcode() interface returns the numeric
** [SQLITE_OK | result code] or [SQLITE_IOERR_READ | extended result code]
................................................................................
**
** On success, SQLITE_OK is returned. Otherwise, an 
** [SQLITE_ERROR | SQLite error code] or an
** [SQLITE_IOERR_READ | extended error code] is returned.
*/
int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);

/*
** CAPI3REF:  Virtual File System Objects
**
** A virtual filesystem (VFS) is an [sqlite3_vfs] object
** that SQLite uses to interact
** with the underlying operating system.  Most builds come with a
** single default VFS that is appropriate for the host computer.
** New VFSes can be registered and existing VFSes can be unregistered.
** The following interfaces are provided.
**
** The sqlite3_find_vfs() interface returns a pointer to a VFS given its
** name.  Names are case sensitive.  If there is no match, a NULL
** pointer is returned.  If zVfsName is NULL then the default 
** VFS is returned.
**
** New VFSes are registered with sqlite3_register_vfs().  Each
** new VFS becomes the default VFS if the makeDflt flag is set.
** The same VFS can be registered multiple times without injury.
** To make an existing VFS into the default VFS, register it again
** with the makeDflt flag set.
** 
** Unregister a VFS with the sqlite3_unregister_vfs() interface.
** If the default VFS is unregistered, another VFS is chosen as
** the default.  The choice for the new VFS is arbitrary.
*/
sqlite3_vfs *sqlite3_find_vfs(const char *zVfsName);
int sqlite3_register_vfs(sqlite3_vfs*, int makeDflt);
int sqlite3_unregister_vfs(sqlite3_vfs*);

/*
** CAPI3REF: Mutexes
**
** The SQLite core uses these routines for thread
** synchronization.  Though they are intended for internal
** use by SQLite, code that links against SQLite is
** permitted to use any of these routines.
**
** The SQLite source code contains multiple implementations 
** of these mutex routines that can be selected at compile-time
** by defining one of the following C preprocessor macros:
**
** <ul>
** <li>   SQLITE_MUTEX_PTHREAD
** <li>   SQLITE_MUTEX_WIN32
** <li>   SQLITE_MUTEX_NOOP
** <li>   SQLITE_MUTEX_APPDEF
** </ul>
**
** If none of the above macros is defined, the code uses
** a default implementation.  
** 
** The SQLITE_MUTEX_NOOP implementation is a set of routines 
** that does no real locking and is appropriate for use in 
** a single-threaded application.
** 
** If the SQLITE_MUTEX_APPDEF is defined, then no mutex
** implementation is included with the library.  The
** mutex interface routines defined above are external
** references in the SQLite library for which implementations
** must be provided by the application.
**
** The sqlite3_mutex_alloc() routine allocates a new
** mutex and returns a pointer to it.  If it returns NULL
** that means that a mutex could not be allocated.  SQLite
** will unwind its stack and return an error.  The argument
** to sqlite3_mutex_alloc() is usually zero, which causes
** any space required for the mutex to be obtained from
** sqlite3_malloc().  However if the argument is a positive
** integer less than SQLITE_NUM_STATIC_MUTEX, then a pointer
** to a static mutex is returned.  There are a finite number
** of static mutexes.  Static mutexes should not be passed
** to sqlite3_mutex_free().  Static mutexes are used internally
** by the SQLite core and should not be used by the application.
**
** The sqlite3_mutex_free() routine deallocates a previously
** allocated mutex.  SQLite is careful to deallocate every
** mutex that it allocates.
**
** The sqlite3_mutex_enter() routine attempts to enter a
** mutex.  If another thread is already within the mutex,
** sqlite3_mutex_enter() will return SQLITE_BUSY if blockFlag
** is zero, or it will block and wait for the other thread to
** exit if blockFlag is non-zero.  Mutexes are recursive.  The
** same thread can enter a single mutex multiple times.  Each
** entrance must be matched with a corresponding exit before
** another thread is able to enter the mutex.
**
** The sqlite3_mutex_exit() routine exits a mutex that was
** previously entered by the same thread.  The behavior
** is undefined if the mutex is not currently entered or
** is not currently allocated.  SQLite will never do either.
**
** The sqlite3_mutex_serialize() routine is used to serialize 
** a subroutine.  The subroutine given in the argument is invoked
** while holding a static mutex.  This ensures that no other
** thread is running this same subroutine at the same time.
*/
sqlite3_mutex *sqlite3_mutex_alloc(int);
void sqlite3_mutex_free(sqlite3_mutex*);
int sqlite3_mutex_enter(sqlite3_mutex*, int blockFlag);
void sqlite3_mutex_leave(sqlite3_mutex*);
int sqlite3_mutex_serialize(void(*)(void*), void*);


/*
** Undo the hack that converts floating point types to integer for
** builds on processors without floating point support.
*/
#ifdef SQLITE_OMIT_FLOATING_POINT