Fossil SCM

Rebase. Generate sqlite3.[ch] from latest SQLite trunk. (still experimental)

jan.nijtmans 2013-07-26 12:27 UTC trunk merge
Commit 3719ad9579a7b96add38be695950c306f01f484f
4 files changed +176 -113 +176 -113 +31 -31 +31 -31
+176 -113
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -670,11 +670,11 @@
670670
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
671671
** [sqlite_version()] and [sqlite_source_id()].
672672
*/
673673
#define SQLITE_VERSION "3.8.0"
674674
#define SQLITE_VERSION_NUMBER 3008000
675
-#define SQLITE_SOURCE_ID "2013-07-18 14:50:56 5dcffa671f592ae9355628afa439ae9a2d26f0cd"
675
+#define SQLITE_SOURCE_ID "2013-07-25 17:07:03 8bcbb33fd0a970e16a920e1d35571836dbb9ba50"
676676
677677
/*
678678
** CAPI3REF: Run-Time Library Version Numbers
679679
** KEYWORDS: sqlite3_version, sqlite3_sourceid
680680
**
@@ -3122,11 +3122,12 @@
31223122
** interface is to keep a GUI updated during a large query.
31233123
**
31243124
** ^The parameter P is passed through as the only parameter to the
31253125
** callback function X. ^The parameter N is the approximate number of
31263126
** [virtual machine instructions] that are evaluated between successive
3127
-** invocations of the callback X.
3127
+** invocations of the callback X. ^If N is less than one then the progress
3128
+** handler is disabled.
31283129
**
31293130
** ^Only a single progress handler may be defined at one time per
31303131
** [database connection]; setting a new progress handler cancels the
31313132
** old one. ^Setting parameter X to NULL disables the progress handler.
31323133
** ^The progress handler is also disabled by setting N to a value less
@@ -4742,50 +4743,49 @@
47424743
SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
47434744
47444745
/*
47454746
** CAPI3REF: Function Auxiliary Data
47464747
**
4747
-** The following two functions may be used by scalar SQL functions to
4748
+** These functions may be used by (non-aggregate) SQL functions to
47484749
** associate metadata with argument values. If the same value is passed to
47494750
** multiple invocations of the same SQL function during query execution, under
4750
-** some circumstances the associated metadata may be preserved. This might
4751
-** be used, for example, in a regular-expression matching
4752
-** function. The compiled version of the regular expression is stored as
4753
-** metadata associated with the SQL value passed as the regular expression
4754
-** pattern. The compiled regular expression can be reused on multiple
4755
-** invocations of the same function so that the original pattern string
4756
-** does not need to be recompiled on each invocation.
4751
+** some circumstances the associated metadata may be preserved. An example
4752
+** of where this might be useful is in a regular-expression matching
4753
+** function. The compiled version of the regular expression can be stored as
4754
+** metadata associated with the pattern string.
4755
+** Then as long as the pattern string remains the same,
4756
+** the compiled regular expression can be reused on multiple
4757
+** invocations of the same function.
47574758
**
47584759
** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
47594760
** associated by the sqlite3_set_auxdata() function with the Nth argument
4760
-** value to the application-defined function. ^If no metadata has been ever
4761
-** been set for the Nth argument of the function, or if the corresponding
4762
-** function parameter has changed since the meta-data was set,
4763
-** then sqlite3_get_auxdata() returns a NULL pointer.
4761
+** value to the application-defined function. ^If there is no metadata
4762
+** associated with the function argument, this sqlite3_get_auxdata() interface
4763
+** returns a NULL pointer.
47644764
**
47654765
** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
47664766
** argument of the application-defined function. ^Subsequent
47674767
** calls to sqlite3_get_auxdata(C,N) return P from the most recent
4768
-** sqlite3_set_auxdata(C,N,P,X) call if the data has not been dropped, or
4769
-** NULL if the data has been dropped.
4770
-** ^(If it is not NULL, SQLite will invoke the destructor
4771
-** function X passed to sqlite3_set_auxdata(C,N,P,X) when <ul>
4772
-** <li> the corresponding function parameter changes,
4773
-** <li> [sqlite3_reset()] or [sqlite3_finalize()] is called for the
4774
-** SQL statement,
4775
-** <li> sqlite3_set_auxdata() is invoked again on the same parameter, or
4776
-** <li> a memory allocation error occurs. </ul>)^
4768
+** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or
4769
+** NULL if the metadata has been discarded.
4770
+** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL,
4771
+** SQLite will invoke the destructor function X with parameter P exactly
4772
+** once, when the metadata is discarded.
4773
+** SQLite is free to discard the metadata at any time, including: <ul>
4774
+** <li> when the corresponding function parameter changes, or
4775
+** <li> when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
4776
+** SQL statement, or
4777
+** <li> when sqlite3_set_auxdata() is invoked again on the same parameter, or
4778
+** <li> during the original sqlite3_set_auxdata() call when a memory
4779
+** allocation error occurs. </ul>)^
47774780
**
4778
-** SQLite is free to call the destructor and drop metadata on any
4779
-** parameter of any function at any time. ^The only guarantee is that
4780
-** the destructor will be called when the [prepared statement] is destroyed.
4781
-** Note in particular that the destructor X in the call to
4782
-** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before
4783
-** the sqlite3_set_auxdata() call even returns. Hence sqlite3_set_auxdata()
4781
+** Note the last bullet in particular. The destructor X in
4782
+** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
4783
+** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata()
47844784
** should be called near the end of the function implementation and the
4785
-** implementation should not make any use of P after sqlite3_set_auxdata()
4786
-** has been called.
4785
+** function implementation should not make any use of P after
4786
+** sqlite3_set_auxdata() has been called.
47874787
**
47884788
** ^(In practice, metadata is preserved between function calls for
47894789
** function parameters that are compile-time constants, including literal
47904790
** values and [parameters] and expressions composed from the same.)^
47914791
**
@@ -8824,11 +8824,10 @@
88248824
88258825
/*
88268826
** The names of the following types declared in vdbeInt.h are required
88278827
** for the VdbeOp definition.
88288828
*/
8829
-typedef struct VdbeFunc VdbeFunc;
88308829
typedef struct Mem Mem;
88318830
typedef struct SubProgram SubProgram;
88328831
88338832
/*
88348833
** A single instruction of the virtual machine has an opcode
@@ -8848,11 +8847,10 @@
88488847
void *p; /* Generic pointer */
88498848
char *z; /* Pointer to data for string (char array) types */
88508849
i64 *pI64; /* Used when p4type is P4_INT64 */
88518850
double *pReal; /* Used when p4type is P4_REAL */
88528851
FuncDef *pFunc; /* Used when p4type is P4_FUNCDEF */
8853
- VdbeFunc *pVdbeFunc; /* Used when p4type is P4_VDBEFUNC */
88548852
CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */
88558853
Mem *pMem; /* Used when p4type is P4_MEM */
88568854
VTable *pVtab; /* Used when p4type is P4_VTAB */
88578855
KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */
88588856
int *ai; /* Used when p4type is P4_INTARRAY */
@@ -8902,11 +8900,10 @@
89028900
#define P4_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */
89038901
#define P4_STATIC (-2) /* Pointer to a static string */
89048902
#define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */
89058903
#define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */
89068904
#define P4_KEYINFO (-6) /* P4 is a pointer to a KeyInfo structure */
8907
-#define P4_VDBEFUNC (-7) /* P4 is a pointer to a VdbeFunc structure */
89088905
#define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */
89098906
#define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */
89108907
#define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */
89118908
#define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */
89128909
#define P4_REAL (-12) /* P4 is a 64-bit floating point value */
@@ -13257,10 +13254,13 @@
1325713254
typedef struct VdbeSorter VdbeSorter;
1325813255
1325913256
/* Opaque type used by the explainer */
1326013257
typedef struct Explain Explain;
1326113258
13259
+/* Elements of the linked list at Vdbe.pAuxData */
13260
+typedef struct AuxData AuxData;
13261
+
1326213262
/*
1326313263
** A cursor is a pointer into a single BTree within a database file.
1326413264
** The cursor can seek to a BTree entry with a particular key, or
1326513265
** loop over all entries of the Btree. You can also insert new BTree
1326613266
** entries or retrieve the key or data from the entry that the cursor
@@ -13443,27 +13443,23 @@
1344313443
*/
1344413444
#ifdef SQLITE_DEBUG
1344513445
#define memIsValid(M) ((M)->flags & MEM_Invalid)==0
1344613446
#endif
1344713447
13448
-
13449
-/* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains
13450
-** additional information about auxiliary information bound to arguments
13451
-** of the function. This is used to implement the sqlite3_get_auxdata()
13452
-** and sqlite3_set_auxdata() APIs. The "auxdata" is some auxiliary data
13453
-** that can be associated with a constant argument to a function. This
13454
-** allows functions such as "regexp" to compile their constant regular
13455
-** expression argument once and reused the compiled code for multiple
13456
-** invocations.
13448
+/*
13449
+** Each auxilliary data pointer stored by a user defined function
13450
+** implementation calling sqlite3_set_auxdata() is stored in an instance
13451
+** of this structure. All such structures associated with a single VM
13452
+** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed
13453
+** when the VM is halted (if not before).
1345713454
*/
13458
-struct VdbeFunc {
13459
- FuncDef *pFunc; /* The definition of the function */
13460
- int nAux; /* Number of entries allocated for apAux[] */
13461
- struct AuxData {
13462
- void *pAux; /* Aux data for the i-th argument */
13463
- void (*xDelete)(void *); /* Destructor for the aux data */
13464
- } apAux[1]; /* One slot for each function argument */
13455
+struct AuxData {
13456
+ int iOp; /* Instruction number of OP_Function opcode */
13457
+ int iArg; /* Index of function argument. */
13458
+ void *pAux; /* Aux data pointer */
13459
+ void (*xDelete)(void *); /* Destructor for the aux data */
13460
+ AuxData *pNext; /* Next element in list */
1346513461
};
1346613462
1346713463
/*
1346813464
** The "context" argument for a installable function. A pointer to an
1346913465
** instance of this structure is the first argument to the routines used
@@ -13477,16 +13473,17 @@
1347713473
** This structure is defined inside of vdbeInt.h because it uses substructures
1347813474
** (Mem) which are only defined there.
1347913475
*/
1348013476
struct sqlite3_context {
1348113477
FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
13482
- VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */
1348313478
Mem s; /* The return value is stored here */
1348413479
Mem *pMem; /* Memory cell used to store aggregate context */
1348513480
CollSeq *pColl; /* Collating sequence */
1348613481
int isError; /* Error code returned by the function. */
1348713482
int skipFlag; /* Skip skip accumulator loading if true */
13483
+ int iOp; /* Instruction number of OP_Function */
13484
+ Vdbe *pVdbe; /* The VM that owns this context */
1348813485
};
1348913486
1349013487
/*
1349113488
** An Explain object accumulates indented output which is helpful
1349213489
** in describing recursive data structures.
@@ -13581,10 +13578,11 @@
1358113578
int nFrame; /* Number of frames in pFrame list */
1358213579
u32 expmask; /* Binding to these vars invalidates VM */
1358313580
SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
1358413581
int nOnceFlag; /* Size of array aOnceFlag[] */
1358513582
u8 *aOnceFlag; /* Flags for OP_Once */
13583
+ AuxData *pAuxData; /* Linked list of auxdata allocations */
1358613584
};
1358713585
1358813586
/*
1358913587
** The following are allowed values for Vdbe.magic
1359013588
*/
@@ -13604,11 +13602,11 @@
1360413602
#endif
1360513603
SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
1360613604
SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
1360713605
SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int);
1360813606
SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
13609
-SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(VdbeFunc*, int);
13607
+SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
1361013608
1361113609
int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
1361213610
SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
1361313611
SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *);
1361413612
SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
@@ -28376,10 +28374,14 @@
2837628374
*/
2837728375
static const char *unixTempFileDir(void){
2837828376
static const char *azDirs[] = {
2837928377
0,
2838028378
0,
28379
+#ifdef __CYGWIN__
28380
+ 0,
28381
+ 0,
28382
+#endif
2838128383
"/var/tmp",
2838228384
"/usr/tmp",
2838328385
"/tmp",
2838428386
0 /* List terminator */
2838528387
};
@@ -28387,10 +28389,14 @@
2838728389
struct stat buf;
2838828390
const char *zDir = 0;
2838928391
2839028392
azDirs[0] = sqlite3_temp_directory;
2839128393
if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
28394
+#ifdef __CYGWIN__
28395
+ if( !azDirs[2] ) azDirs[2] = getenv("TMP");
28396
+ if( !azDirs[3] ) azDirs[3] = getenv("TEMP");
28397
+#endif
2839228398
for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
2839328399
if( zDir==0 ) continue;
2839428400
if( osStat(zDir, &buf) ) continue;
2839528401
if( !S_ISDIR(buf.st_mode) ) continue;
2839628402
if( osAccess(zDir, 07) ) continue;
@@ -30735,11 +30741,11 @@
3073530741
3073630742
/*
3073730743
** Are most of the Win32 Unicode APIs available (i.e. with certain exceptions
3073830744
** based on the sub-platform)?
3073930745
*/
30740
-#if SQLITE_OS_WINCE || SQLITE_OS_WINNT || SQLITE_OS_WINRT
30746
+#if SQLITE_OS_WINCE || SQLITE_OS_WINNT || SQLITE_OS_WINRT || defined(__CYGWIN__)
3074130747
# define SQLITE_WIN32_HAS_WIDE
3074230748
#endif
3074330749
3074430750
/*
3074530751
** Do we need to manually define the Win32 file mapping APIs for use with WAL
@@ -34556,10 +34562,12 @@
3455634562
#endif
3455734563
/* caller will handle out of memory */
3455834564
return zConverted;
3455934565
}
3456034566
34567
+static int winIsDir(const void *zConverted);
34568
+
3456134569
/*
3456234570
** Create a temporary file name in zBuf. zBuf must be big enough to
3456334571
** hold at pVfs->mxPathname characters.
3456434572
*/
3456534573
static int getTempname(int nBuf, char *zBuf){
@@ -34580,11 +34588,53 @@
3458034588
memset(zTempPath, 0, MAX_PATH+2);
3458134589
3458234590
if( sqlite3_temp_directory ){
3458334591
sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
3458434592
}
34585
-#if !SQLITE_OS_WINRT
34593
+#if defined(__CYGWIN__)
34594
+ static const char *azDirs[] = {
34595
+ 0,
34596
+ 0,
34597
+ 0,
34598
+ 0,
34599
+ "/var/tmp",
34600
+ "/usr/tmp",
34601
+ "/tmp",
34602
+ 0
34603
+ };
34604
+ const char *zDir = 0;
34605
+ char *zConverted;
34606
+
34607
+ azDirs[0] = sqlite3_temp_directory;
34608
+ if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
34609
+ if( !azDirs[2] ) azDirs[2] = getenv("TMP");
34610
+ if( !azDirs[3] ) azDirs[3] = getenv("TEMP");
34611
+ for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
34612
+ if( zDir==0 || zDir[0]) continue;
34613
+ if( zDir[1]!=':' ){
34614
+ WCHAR zWidePath[MAX_PATH];
34615
+ cygwin_conv_path(CCP_POSIX_TO_WIN_W, zDir, zWidePath, MAX_PATH);
34616
+ zDir = unicodeToUtf8(zWidePath);
34617
+ if( zDir==0 ){
34618
+ OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
34619
+ return SQLITE_IOERR_NOMEM;
34620
+ }
34621
+ }
34622
+ /* Convert the filename to the system encoding. */
34623
+ zConverted = convertUtf8Filename(zDir);
34624
+ if( zConverted==0 ){
34625
+ OSTRACE(("TEMP-FILENAME, rc=SQLITE_IOERR_NOMEM"));
34626
+ return SQLITE_IOERR_NOMEM;
34627
+ }
34628
+ if( winIsDir(zConverted) ){
34629
+ sqlite3_free(zConverted);
34630
+ break;
34631
+ }
34632
+ sqlite3_free(zConverted);
34633
+ }
34634
+ sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zDir);
34635
+#elif !SQLITE_OS_WINRT
3458634636
else if( isNT() ){
3458734637
char *zMulti;
3458834638
WCHAR zWidePath[MAX_PATH];
3458934639
osGetTempPathW(MAX_PATH-30, zWidePath);
3459034640
zMulti = unicodeToUtf8(zWidePath);
@@ -60538,17 +60588,10 @@
6053860588
}
6053960589
case P4_MPRINTF: {
6054060590
if( db->pnBytesFreed==0 ) sqlite3_free(p4);
6054160591
break;
6054260592
}
60543
- case P4_VDBEFUNC: {
60544
- VdbeFunc *pVdbeFunc = (VdbeFunc *)p4;
60545
- freeEphemeralFunction(db, pVdbeFunc->pFunc);
60546
- if( db->pnBytesFreed==0 ) sqlite3VdbeDeleteAuxData(pVdbeFunc, 0);
60547
- sqlite3DbFree(db, pVdbeFunc);
60548
- break;
60549
- }
6055060593
case P4_FUNCDEF: {
6055160594
freeEphemeralFunction(db, (FuncDef*)p4);
6055260595
break;
6055360596
}
6055460597
case P4_MEM: {
@@ -61574,10 +61617,14 @@
6157461617
while( p->pDelFrame ){
6157561618
VdbeFrame *pDel = p->pDelFrame;
6157661619
p->pDelFrame = pDel->pParent;
6157761620
sqlite3VdbeFrameDelete(pDel);
6157861621
}
61622
+
61623
+ /* Delete any auxdata allocations made by the VM */
61624
+ sqlite3VdbeDeleteAuxData(p, -1, 0);
61625
+ assert( p->pAuxData==0 );
6157961626
}
6158061627
6158161628
/*
6158261629
** Clean up the VM after execution.
6158361630
**
@@ -62372,24 +62419,39 @@
6237262419
sqlite3VdbeDelete(p);
6237362420
return rc;
6237462421
}
6237562422
6237662423
/*
62377
-** Call the destructor for each auxdata entry in pVdbeFunc for which
62378
-** the corresponding bit in mask is clear. Auxdata entries beyond 31
62379
-** are always destroyed. To destroy all auxdata entries, call this
62380
-** routine with mask==0.
62424
+** If parameter iOp is less than zero, then invoke the destructor for
62425
+** all auxiliary data pointers currently cached by the VM passed as
62426
+** the first argument.
62427
+**
62428
+** Or, if iOp is greater than or equal to zero, then the destructor is
62429
+** only invoked for those auxiliary data pointers created by the user
62430
+** function invoked by the OP_Function opcode at instruction iOp of
62431
+** VM pVdbe, and only then if:
62432
+**
62433
+** * the associated function parameter is the 32nd or later (counting
62434
+** from left to right), or
62435
+**
62436
+** * the corresponding bit in argument mask is clear (where the first
62437
+** function parameter corrsponds to bit 0 etc.).
6238162438
*/
62382
-SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(VdbeFunc *pVdbeFunc, int mask){
62383
- int i;
62384
- for(i=0; i<pVdbeFunc->nAux; i++){
62385
- struct AuxData *pAux = &pVdbeFunc->apAux[i];
62386
- if( (i>31 || !(mask&(((u32)1)<<i))) && pAux->pAux ){
62439
+SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe *pVdbe, int iOp, int mask){
62440
+ AuxData **pp = &pVdbe->pAuxData;
62441
+ while( *pp ){
62442
+ AuxData *pAux = *pp;
62443
+ if( (iOp<0)
62444
+ || (pAux->iOp==iOp && (pAux->iArg>31 || !(mask & ((u32)1<<pAux->iArg))))
62445
+ ){
6238762446
if( pAux->xDelete ){
6238862447
pAux->xDelete(pAux->pAux);
6238962448
}
62390
- pAux->pAux = 0;
62449
+ *pp = pAux->pNext;
62450
+ sqlite3DbFree(pVdbe->db, pAux);
62451
+ }else{
62452
+ pp= &pAux->pNext;
6239162453
}
6239262454
}
6239362455
}
6239462456
6239562457
/*
@@ -63784,18 +63846,18 @@
6378463846
/*
6378563847
** Return the auxilary data pointer, if any, for the iArg'th argument to
6378663848
** the user-function defined by pCtx.
6378763849
*/
6378863850
SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
63789
- VdbeFunc *pVdbeFunc;
63851
+ AuxData *pAuxData;
6379063852
6379163853
assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63792
- pVdbeFunc = pCtx->pVdbeFunc;
63793
- if( !pVdbeFunc || iArg>=pVdbeFunc->nAux || iArg<0 ){
63794
- return 0;
63854
+ for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
63855
+ if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
6379563856
}
63796
- return pVdbeFunc->apAux[iArg].pAux;
63857
+
63858
+ return (pAuxData ? pAuxData->pAux : 0);
6379763859
}
6379863860
6379963861
/*
6380063862
** Set the auxilary data pointer and delete function, for the iArg'th
6380163863
** argument to the user-function defined by pCtx. Any previous value is
@@ -63805,33 +63867,30 @@
6380563867
sqlite3_context *pCtx,
6380663868
int iArg,
6380763869
void *pAux,
6380863870
void (*xDelete)(void*)
6380963871
){
63810
- struct AuxData *pAuxData;
63811
- VdbeFunc *pVdbeFunc;
63812
- if( iArg<0 ) goto failed;
63872
+ AuxData *pAuxData;
63873
+ Vdbe *pVdbe = pCtx->pVdbe;
6381363874
6381463875
assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63815
- pVdbeFunc = pCtx->pVdbeFunc;
63816
- if( !pVdbeFunc || pVdbeFunc->nAux<=iArg ){
63817
- int nAux = (pVdbeFunc ? pVdbeFunc->nAux : 0);
63818
- int nMalloc = sizeof(VdbeFunc) + sizeof(struct AuxData)*iArg;
63819
- pVdbeFunc = sqlite3DbRealloc(pCtx->s.db, pVdbeFunc, nMalloc);
63820
- if( !pVdbeFunc ){
63821
- goto failed;
63822
- }
63823
- pCtx->pVdbeFunc = pVdbeFunc;
63824
- memset(&pVdbeFunc->apAux[nAux], 0, sizeof(struct AuxData)*(iArg+1-nAux));
63825
- pVdbeFunc->nAux = iArg+1;
63826
- pVdbeFunc->pFunc = pCtx->pFunc;
63827
- }
63828
-
63829
- pAuxData = &pVdbeFunc->apAux[iArg];
63830
- if( pAuxData->pAux && pAuxData->xDelete ){
63876
+ if( iArg<0 ) goto failed;
63877
+
63878
+ for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
63879
+ if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
63880
+ }
63881
+ if( pAuxData==0 ){
63882
+ pAuxData = sqlite3DbMallocZero(pVdbe->db, sizeof(AuxData));
63883
+ if( !pAuxData ) goto failed;
63884
+ pAuxData->iOp = pCtx->iOp;
63885
+ pAuxData->iArg = iArg;
63886
+ pAuxData->pNext = pVdbe->pAuxData;
63887
+ pVdbe->pAuxData = pAuxData;
63888
+ }else if( pAuxData->xDelete ){
6383163889
pAuxData->xDelete(pAuxData->pAux);
6383263890
}
63891
+
6383363892
pAuxData->pAux = pAux;
6383463893
pAuxData->xDelete = xDelete;
6383563894
return;
6383663895
6383763896
failed:
@@ -65439,11 +65498,11 @@
6543965498
u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
6544065499
u8 encoding = ENC(db); /* The database encoding */
6544165500
int iCompare = 0; /* Result of last OP_Compare operation */
6544265501
unsigned nVmStep = 0; /* Number of virtual machine steps */
6544365502
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65444
- unsigned nProgressOps = 0; /* nVmStep at last progress callback. */
65503
+ unsigned nProgressLimit; /* Invoke xProgress() when nVmStep reaches this */
6544565504
#endif
6544665505
Mem *aMem = p->aMem; /* Copy of p->aMem */
6544765506
Mem *pIn1 = 0; /* 1st input operand */
6544865507
Mem *pIn2 = 0; /* 2nd input operand */
6544965508
Mem *pIn3 = 0; /* 3rd input operand */
@@ -65898,10 +65957,21 @@
6589865957
assert( p->explain==0 );
6589965958
p->pResultSet = 0;
6590065959
db->busyHandler.nBusy = 0;
6590165960
CHECK_FOR_INTERRUPT;
6590265961
sqlite3VdbeIOTraceSql(p);
65962
+#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65963
+ if( db->xProgress ){
65964
+ assert( 0 < db->nProgressOps );
65965
+ nProgressLimit = (unsigned)p->aCounter[SQLITE_STMTSTATUS_VM_STEP-1];
65966
+ if( nProgressLimit==0 ){
65967
+ nProgressLimit = db->nProgressOps;
65968
+ }else{
65969
+ nProgressLimit %= (unsigned)db->nProgressOps;
65970
+ }
65971
+ }
65972
+#endif
6590365973
#ifdef SQLITE_DEBUG
6590465974
sqlite3BeginBenignMalloc();
6590565975
if( p->pc==0 && (p->db->flags & SQLITE_VdbeListing)!=0 ){
6590665976
int i;
6590765977
printf("VDBE Program Listing:\n");
@@ -66058,18 +66128,20 @@
6605866128
** of VDBE ops have been executed (either since this invocation of
6605966129
** sqlite3VdbeExec() or since last time the progress callback was called).
6606066130
** If the progress callback returns non-zero, exit the virtual machine with
6606166131
** a return code SQLITE_ABORT.
6606266132
*/
66063
- if( db->xProgress!=0 && (nVmStep - nProgressOps)>=db->nProgressOps ){
66133
+ if( db->xProgress!=0 && nVmStep>=nProgressLimit ){
6606466134
int prc;
6606566135
prc = db->xProgress(db->pProgressArg);
6606666136
if( prc!=0 ){
6606766137
rc = SQLITE_INTERRUPT;
6606866138
goto vdbe_error_halt;
6606966139
}
66070
- nProgressOps = nVmStep;
66140
+ if( db->xProgress!=0 ){
66141
+ nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps);
66142
+ }
6607166143
}
6607266144
#endif
6607366145
6607466146
break;
6607566147
}
@@ -66751,23 +66823,18 @@
6675166823
Deephemeralize(u.ai.pArg);
6675266824
sqlite3VdbeMemStoreType(u.ai.pArg);
6675366825
REGISTER_TRACE(pOp->p2+u.ai.i, u.ai.pArg);
6675466826
}
6675566827
66756
- assert( pOp->p4type==P4_FUNCDEF || pOp->p4type==P4_VDBEFUNC );
66757
- if( pOp->p4type==P4_FUNCDEF ){
66758
- u.ai.ctx.pFunc = pOp->p4.pFunc;
66759
- u.ai.ctx.pVdbeFunc = 0;
66760
- }else{
66761
- u.ai.ctx.pVdbeFunc = (VdbeFunc*)pOp->p4.pVdbeFunc;
66762
- u.ai.ctx.pFunc = u.ai.ctx.pVdbeFunc->pFunc;
66763
- }
66764
-
66828
+ assert( pOp->p4type==P4_FUNCDEF );
66829
+ u.ai.ctx.pFunc = pOp->p4.pFunc;
6676566830
u.ai.ctx.s.flags = MEM_Null;
6676666831
u.ai.ctx.s.db = db;
6676766832
u.ai.ctx.s.xDel = 0;
6676866833
u.ai.ctx.s.zMalloc = 0;
66834
+ u.ai.ctx.iOp = pc;
66835
+ u.ai.ctx.pVdbe = p;
6676966836
6677066837
/* The output cell may already have a buffer allocated. Move
6677166838
** the pointer to u.ai.ctx.s so in case the user-function can use
6677266839
** the already allocated buffer instead of allocating a new one.
6677366840
*/
@@ -66786,15 +66853,11 @@
6678666853
lastRowid = db->lastRowid;
6678766854
6678866855
/* If any auxiliary data functions have been called by this user function,
6678966856
** immediately call the destructor for any non-static values.
6679066857
*/
66791
- if( u.ai.ctx.pVdbeFunc ){
66792
- sqlite3VdbeDeleteAuxData(u.ai.ctx.pVdbeFunc, pOp->p1);
66793
- pOp->p4.pVdbeFunc = u.ai.ctx.pVdbeFunc;
66794
- pOp->p4type = P4_VDBEFUNC;
66795
- }
66858
+ sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
6679666859
6679766860
if( db->mallocFailed ){
6679866861
/* Even though a malloc() has failed, the implementation of the
6679966862
** user function may have called an sqlite3_result_XXX() function
6680066863
** to return a value. The following call releases any resources
@@ -117728,11 +117791,11 @@
117728117791
db->autoCommit = 1;
117729117792
db->nextAutovac = -1;
117730117793
db->szMmap = sqlite3GlobalConfig.szMmap;
117731117794
db->nextPagesize = 0;
117732117795
db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger
117733
-#if !defined(SQLITE_DEAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
117796
+#if !defined(SQLITE_DEFAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
117734117797
| SQLITE_AutoIndex
117735117798
#endif
117736117799
#if SQLITE_DEFAULT_FILE_FORMAT<4
117737117800
| SQLITE_LegacyFileFmt
117738117801
#endif
117739117802
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -670,11 +670,11 @@
670 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
671 ** [sqlite_version()] and [sqlite_source_id()].
672 */
673 #define SQLITE_VERSION "3.8.0"
674 #define SQLITE_VERSION_NUMBER 3008000
675 #define SQLITE_SOURCE_ID "2013-07-18 14:50:56 5dcffa671f592ae9355628afa439ae9a2d26f0cd"
676
677 /*
678 ** CAPI3REF: Run-Time Library Version Numbers
679 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
680 **
@@ -3122,11 +3122,12 @@
3122 ** interface is to keep a GUI updated during a large query.
3123 **
3124 ** ^The parameter P is passed through as the only parameter to the
3125 ** callback function X. ^The parameter N is the approximate number of
3126 ** [virtual machine instructions] that are evaluated between successive
3127 ** invocations of the callback X.
 
3128 **
3129 ** ^Only a single progress handler may be defined at one time per
3130 ** [database connection]; setting a new progress handler cancels the
3131 ** old one. ^Setting parameter X to NULL disables the progress handler.
3132 ** ^The progress handler is also disabled by setting N to a value less
@@ -4742,50 +4743,49 @@
4742 SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
4743
4744 /*
4745 ** CAPI3REF: Function Auxiliary Data
4746 **
4747 ** The following two functions may be used by scalar SQL functions to
4748 ** associate metadata with argument values. If the same value is passed to
4749 ** multiple invocations of the same SQL function during query execution, under
4750 ** some circumstances the associated metadata may be preserved. This might
4751 ** be used, for example, in a regular-expression matching
4752 ** function. The compiled version of the regular expression is stored as
4753 ** metadata associated with the SQL value passed as the regular expression
4754 ** pattern. The compiled regular expression can be reused on multiple
4755 ** invocations of the same function so that the original pattern string
4756 ** does not need to be recompiled on each invocation.
4757 **
4758 ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
4759 ** associated by the sqlite3_set_auxdata() function with the Nth argument
4760 ** value to the application-defined function. ^If no metadata has been ever
4761 ** been set for the Nth argument of the function, or if the corresponding
4762 ** function parameter has changed since the meta-data was set,
4763 ** then sqlite3_get_auxdata() returns a NULL pointer.
4764 **
4765 ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
4766 ** argument of the application-defined function. ^Subsequent
4767 ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
4768 ** sqlite3_set_auxdata(C,N,P,X) call if the data has not been dropped, or
4769 ** NULL if the data has been dropped.
4770 ** ^(If it is not NULL, SQLite will invoke the destructor
4771 ** function X passed to sqlite3_set_auxdata(C,N,P,X) when <ul>
4772 ** <li> the corresponding function parameter changes,
4773 ** <li> [sqlite3_reset()] or [sqlite3_finalize()] is called for the
4774 ** SQL statement,
4775 ** <li> sqlite3_set_auxdata() is invoked again on the same parameter, or
4776 ** <li> a memory allocation error occurs. </ul>)^
 
 
 
4777 **
4778 ** SQLite is free to call the destructor and drop metadata on any
4779 ** parameter of any function at any time. ^The only guarantee is that
4780 ** the destructor will be called when the [prepared statement] is destroyed.
4781 ** Note in particular that the destructor X in the call to
4782 ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before
4783 ** the sqlite3_set_auxdata() call even returns. Hence sqlite3_set_auxdata()
4784 ** should be called near the end of the function implementation and the
4785 ** implementation should not make any use of P after sqlite3_set_auxdata()
4786 ** has been called.
4787 **
4788 ** ^(In practice, metadata is preserved between function calls for
4789 ** function parameters that are compile-time constants, including literal
4790 ** values and [parameters] and expressions composed from the same.)^
4791 **
@@ -8824,11 +8824,10 @@
8824
8825 /*
8826 ** The names of the following types declared in vdbeInt.h are required
8827 ** for the VdbeOp definition.
8828 */
8829 typedef struct VdbeFunc VdbeFunc;
8830 typedef struct Mem Mem;
8831 typedef struct SubProgram SubProgram;
8832
8833 /*
8834 ** A single instruction of the virtual machine has an opcode
@@ -8848,11 +8847,10 @@
8848 void *p; /* Generic pointer */
8849 char *z; /* Pointer to data for string (char array) types */
8850 i64 *pI64; /* Used when p4type is P4_INT64 */
8851 double *pReal; /* Used when p4type is P4_REAL */
8852 FuncDef *pFunc; /* Used when p4type is P4_FUNCDEF */
8853 VdbeFunc *pVdbeFunc; /* Used when p4type is P4_VDBEFUNC */
8854 CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */
8855 Mem *pMem; /* Used when p4type is P4_MEM */
8856 VTable *pVtab; /* Used when p4type is P4_VTAB */
8857 KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */
8858 int *ai; /* Used when p4type is P4_INTARRAY */
@@ -8902,11 +8900,10 @@
8902 #define P4_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */
8903 #define P4_STATIC (-2) /* Pointer to a static string */
8904 #define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */
8905 #define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */
8906 #define P4_KEYINFO (-6) /* P4 is a pointer to a KeyInfo structure */
8907 #define P4_VDBEFUNC (-7) /* P4 is a pointer to a VdbeFunc structure */
8908 #define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */
8909 #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */
8910 #define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */
8911 #define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */
8912 #define P4_REAL (-12) /* P4 is a 64-bit floating point value */
@@ -13257,10 +13254,13 @@
13257 typedef struct VdbeSorter VdbeSorter;
13258
13259 /* Opaque type used by the explainer */
13260 typedef struct Explain Explain;
13261
 
 
 
13262 /*
13263 ** A cursor is a pointer into a single BTree within a database file.
13264 ** The cursor can seek to a BTree entry with a particular key, or
13265 ** loop over all entries of the Btree. You can also insert new BTree
13266 ** entries or retrieve the key or data from the entry that the cursor
@@ -13443,27 +13443,23 @@
13443 */
13444 #ifdef SQLITE_DEBUG
13445 #define memIsValid(M) ((M)->flags & MEM_Invalid)==0
13446 #endif
13447
13448
13449 /* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains
13450 ** additional information about auxiliary information bound to arguments
13451 ** of the function. This is used to implement the sqlite3_get_auxdata()
13452 ** and sqlite3_set_auxdata() APIs. The "auxdata" is some auxiliary data
13453 ** that can be associated with a constant argument to a function. This
13454 ** allows functions such as "regexp" to compile their constant regular
13455 ** expression argument once and reused the compiled code for multiple
13456 ** invocations.
13457 */
13458 struct VdbeFunc {
13459 FuncDef *pFunc; /* The definition of the function */
13460 int nAux; /* Number of entries allocated for apAux[] */
13461 struct AuxData {
13462 void *pAux; /* Aux data for the i-th argument */
13463 void (*xDelete)(void *); /* Destructor for the aux data */
13464 } apAux[1]; /* One slot for each function argument */
13465 };
13466
13467 /*
13468 ** The "context" argument for a installable function. A pointer to an
13469 ** instance of this structure is the first argument to the routines used
@@ -13477,16 +13473,17 @@
13477 ** This structure is defined inside of vdbeInt.h because it uses substructures
13478 ** (Mem) which are only defined there.
13479 */
13480 struct sqlite3_context {
13481 FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
13482 VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */
13483 Mem s; /* The return value is stored here */
13484 Mem *pMem; /* Memory cell used to store aggregate context */
13485 CollSeq *pColl; /* Collating sequence */
13486 int isError; /* Error code returned by the function. */
13487 int skipFlag; /* Skip skip accumulator loading if true */
 
 
13488 };
13489
13490 /*
13491 ** An Explain object accumulates indented output which is helpful
13492 ** in describing recursive data structures.
@@ -13581,10 +13578,11 @@
13581 int nFrame; /* Number of frames in pFrame list */
13582 u32 expmask; /* Binding to these vars invalidates VM */
13583 SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
13584 int nOnceFlag; /* Size of array aOnceFlag[] */
13585 u8 *aOnceFlag; /* Flags for OP_Once */
 
13586 };
13587
13588 /*
13589 ** The following are allowed values for Vdbe.magic
13590 */
@@ -13604,11 +13602,11 @@
13604 #endif
13605 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
13606 SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
13607 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int);
13608 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
13609 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(VdbeFunc*, int);
13610
13611 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
13612 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
13613 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *);
13614 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
@@ -28376,10 +28374,14 @@
28376 */
28377 static const char *unixTempFileDir(void){
28378 static const char *azDirs[] = {
28379 0,
28380 0,
 
 
 
 
28381 "/var/tmp",
28382 "/usr/tmp",
28383 "/tmp",
28384 0 /* List terminator */
28385 };
@@ -28387,10 +28389,14 @@
28387 struct stat buf;
28388 const char *zDir = 0;
28389
28390 azDirs[0] = sqlite3_temp_directory;
28391 if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
 
 
 
 
28392 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
28393 if( zDir==0 ) continue;
28394 if( osStat(zDir, &buf) ) continue;
28395 if( !S_ISDIR(buf.st_mode) ) continue;
28396 if( osAccess(zDir, 07) ) continue;
@@ -30735,11 +30741,11 @@
30735
30736 /*
30737 ** Are most of the Win32 Unicode APIs available (i.e. with certain exceptions
30738 ** based on the sub-platform)?
30739 */
30740 #if SQLITE_OS_WINCE || SQLITE_OS_WINNT || SQLITE_OS_WINRT
30741 # define SQLITE_WIN32_HAS_WIDE
30742 #endif
30743
30744 /*
30745 ** Do we need to manually define the Win32 file mapping APIs for use with WAL
@@ -34556,10 +34562,12 @@
34556 #endif
34557 /* caller will handle out of memory */
34558 return zConverted;
34559 }
34560
 
 
34561 /*
34562 ** Create a temporary file name in zBuf. zBuf must be big enough to
34563 ** hold at pVfs->mxPathname characters.
34564 */
34565 static int getTempname(int nBuf, char *zBuf){
@@ -34580,11 +34588,53 @@
34580 memset(zTempPath, 0, MAX_PATH+2);
34581
34582 if( sqlite3_temp_directory ){
34583 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
34584 }
34585 #if !SQLITE_OS_WINRT
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34586 else if( isNT() ){
34587 char *zMulti;
34588 WCHAR zWidePath[MAX_PATH];
34589 osGetTempPathW(MAX_PATH-30, zWidePath);
34590 zMulti = unicodeToUtf8(zWidePath);
@@ -60538,17 +60588,10 @@
60538 }
60539 case P4_MPRINTF: {
60540 if( db->pnBytesFreed==0 ) sqlite3_free(p4);
60541 break;
60542 }
60543 case P4_VDBEFUNC: {
60544 VdbeFunc *pVdbeFunc = (VdbeFunc *)p4;
60545 freeEphemeralFunction(db, pVdbeFunc->pFunc);
60546 if( db->pnBytesFreed==0 ) sqlite3VdbeDeleteAuxData(pVdbeFunc, 0);
60547 sqlite3DbFree(db, pVdbeFunc);
60548 break;
60549 }
60550 case P4_FUNCDEF: {
60551 freeEphemeralFunction(db, (FuncDef*)p4);
60552 break;
60553 }
60554 case P4_MEM: {
@@ -61574,10 +61617,14 @@
61574 while( p->pDelFrame ){
61575 VdbeFrame *pDel = p->pDelFrame;
61576 p->pDelFrame = pDel->pParent;
61577 sqlite3VdbeFrameDelete(pDel);
61578 }
 
 
 
 
61579 }
61580
61581 /*
61582 ** Clean up the VM after execution.
61583 **
@@ -62372,24 +62419,39 @@
62372 sqlite3VdbeDelete(p);
62373 return rc;
62374 }
62375
62376 /*
62377 ** Call the destructor for each auxdata entry in pVdbeFunc for which
62378 ** the corresponding bit in mask is clear. Auxdata entries beyond 31
62379 ** are always destroyed. To destroy all auxdata entries, call this
62380 ** routine with mask==0.
 
 
 
 
 
 
 
 
 
 
62381 */
62382 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(VdbeFunc *pVdbeFunc, int mask){
62383 int i;
62384 for(i=0; i<pVdbeFunc->nAux; i++){
62385 struct AuxData *pAux = &pVdbeFunc->apAux[i];
62386 if( (i>31 || !(mask&(((u32)1)<<i))) && pAux->pAux ){
 
 
62387 if( pAux->xDelete ){
62388 pAux->xDelete(pAux->pAux);
62389 }
62390 pAux->pAux = 0;
 
 
 
62391 }
62392 }
62393 }
62394
62395 /*
@@ -63784,18 +63846,18 @@
63784 /*
63785 ** Return the auxilary data pointer, if any, for the iArg'th argument to
63786 ** the user-function defined by pCtx.
63787 */
63788 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
63789 VdbeFunc *pVdbeFunc;
63790
63791 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63792 pVdbeFunc = pCtx->pVdbeFunc;
63793 if( !pVdbeFunc || iArg>=pVdbeFunc->nAux || iArg<0 ){
63794 return 0;
63795 }
63796 return pVdbeFunc->apAux[iArg].pAux;
 
63797 }
63798
63799 /*
63800 ** Set the auxilary data pointer and delete function, for the iArg'th
63801 ** argument to the user-function defined by pCtx. Any previous value is
@@ -63805,33 +63867,30 @@
63805 sqlite3_context *pCtx,
63806 int iArg,
63807 void *pAux,
63808 void (*xDelete)(void*)
63809 ){
63810 struct AuxData *pAuxData;
63811 VdbeFunc *pVdbeFunc;
63812 if( iArg<0 ) goto failed;
63813
63814 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63815 pVdbeFunc = pCtx->pVdbeFunc;
63816 if( !pVdbeFunc || pVdbeFunc->nAux<=iArg ){
63817 int nAux = (pVdbeFunc ? pVdbeFunc->nAux : 0);
63818 int nMalloc = sizeof(VdbeFunc) + sizeof(struct AuxData)*iArg;
63819 pVdbeFunc = sqlite3DbRealloc(pCtx->s.db, pVdbeFunc, nMalloc);
63820 if( !pVdbeFunc ){
63821 goto failed;
63822 }
63823 pCtx->pVdbeFunc = pVdbeFunc;
63824 memset(&pVdbeFunc->apAux[nAux], 0, sizeof(struct AuxData)*(iArg+1-nAux));
63825 pVdbeFunc->nAux = iArg+1;
63826 pVdbeFunc->pFunc = pCtx->pFunc;
63827 }
63828
63829 pAuxData = &pVdbeFunc->apAux[iArg];
63830 if( pAuxData->pAux && pAuxData->xDelete ){
63831 pAuxData->xDelete(pAuxData->pAux);
63832 }
 
63833 pAuxData->pAux = pAux;
63834 pAuxData->xDelete = xDelete;
63835 return;
63836
63837 failed:
@@ -65439,11 +65498,11 @@
65439 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
65440 u8 encoding = ENC(db); /* The database encoding */
65441 int iCompare = 0; /* Result of last OP_Compare operation */
65442 unsigned nVmStep = 0; /* Number of virtual machine steps */
65443 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65444 unsigned nProgressOps = 0; /* nVmStep at last progress callback. */
65445 #endif
65446 Mem *aMem = p->aMem; /* Copy of p->aMem */
65447 Mem *pIn1 = 0; /* 1st input operand */
65448 Mem *pIn2 = 0; /* 2nd input operand */
65449 Mem *pIn3 = 0; /* 3rd input operand */
@@ -65898,10 +65957,21 @@
65898 assert( p->explain==0 );
65899 p->pResultSet = 0;
65900 db->busyHandler.nBusy = 0;
65901 CHECK_FOR_INTERRUPT;
65902 sqlite3VdbeIOTraceSql(p);
 
 
 
 
 
 
 
 
 
 
 
65903 #ifdef SQLITE_DEBUG
65904 sqlite3BeginBenignMalloc();
65905 if( p->pc==0 && (p->db->flags & SQLITE_VdbeListing)!=0 ){
65906 int i;
65907 printf("VDBE Program Listing:\n");
@@ -66058,18 +66128,20 @@
66058 ** of VDBE ops have been executed (either since this invocation of
66059 ** sqlite3VdbeExec() or since last time the progress callback was called).
66060 ** If the progress callback returns non-zero, exit the virtual machine with
66061 ** a return code SQLITE_ABORT.
66062 */
66063 if( db->xProgress!=0 && (nVmStep - nProgressOps)>=db->nProgressOps ){
66064 int prc;
66065 prc = db->xProgress(db->pProgressArg);
66066 if( prc!=0 ){
66067 rc = SQLITE_INTERRUPT;
66068 goto vdbe_error_halt;
66069 }
66070 nProgressOps = nVmStep;
 
 
66071 }
66072 #endif
66073
66074 break;
66075 }
@@ -66751,23 +66823,18 @@
66751 Deephemeralize(u.ai.pArg);
66752 sqlite3VdbeMemStoreType(u.ai.pArg);
66753 REGISTER_TRACE(pOp->p2+u.ai.i, u.ai.pArg);
66754 }
66755
66756 assert( pOp->p4type==P4_FUNCDEF || pOp->p4type==P4_VDBEFUNC );
66757 if( pOp->p4type==P4_FUNCDEF ){
66758 u.ai.ctx.pFunc = pOp->p4.pFunc;
66759 u.ai.ctx.pVdbeFunc = 0;
66760 }else{
66761 u.ai.ctx.pVdbeFunc = (VdbeFunc*)pOp->p4.pVdbeFunc;
66762 u.ai.ctx.pFunc = u.ai.ctx.pVdbeFunc->pFunc;
66763 }
66764
66765 u.ai.ctx.s.flags = MEM_Null;
66766 u.ai.ctx.s.db = db;
66767 u.ai.ctx.s.xDel = 0;
66768 u.ai.ctx.s.zMalloc = 0;
 
 
66769
66770 /* The output cell may already have a buffer allocated. Move
66771 ** the pointer to u.ai.ctx.s so in case the user-function can use
66772 ** the already allocated buffer instead of allocating a new one.
66773 */
@@ -66786,15 +66853,11 @@
66786 lastRowid = db->lastRowid;
66787
66788 /* If any auxiliary data functions have been called by this user function,
66789 ** immediately call the destructor for any non-static values.
66790 */
66791 if( u.ai.ctx.pVdbeFunc ){
66792 sqlite3VdbeDeleteAuxData(u.ai.ctx.pVdbeFunc, pOp->p1);
66793 pOp->p4.pVdbeFunc = u.ai.ctx.pVdbeFunc;
66794 pOp->p4type = P4_VDBEFUNC;
66795 }
66796
66797 if( db->mallocFailed ){
66798 /* Even though a malloc() has failed, the implementation of the
66799 ** user function may have called an sqlite3_result_XXX() function
66800 ** to return a value. The following call releases any resources
@@ -117728,11 +117791,11 @@
117728 db->autoCommit = 1;
117729 db->nextAutovac = -1;
117730 db->szMmap = sqlite3GlobalConfig.szMmap;
117731 db->nextPagesize = 0;
117732 db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger
117733 #if !defined(SQLITE_DEAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
117734 | SQLITE_AutoIndex
117735 #endif
117736 #if SQLITE_DEFAULT_FILE_FORMAT<4
117737 | SQLITE_LegacyFileFmt
117738 #endif
117739
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -670,11 +670,11 @@
670 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
671 ** [sqlite_version()] and [sqlite_source_id()].
672 */
673 #define SQLITE_VERSION "3.8.0"
674 #define SQLITE_VERSION_NUMBER 3008000
675 #define SQLITE_SOURCE_ID "2013-07-25 17:07:03 8bcbb33fd0a970e16a920e1d35571836dbb9ba50"
676
677 /*
678 ** CAPI3REF: Run-Time Library Version Numbers
679 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
680 **
@@ -3122,11 +3122,12 @@
3122 ** interface is to keep a GUI updated during a large query.
3123 **
3124 ** ^The parameter P is passed through as the only parameter to the
3125 ** callback function X. ^The parameter N is the approximate number of
3126 ** [virtual machine instructions] that are evaluated between successive
3127 ** invocations of the callback X. ^If N is less than one then the progress
3128 ** handler is disabled.
3129 **
3130 ** ^Only a single progress handler may be defined at one time per
3131 ** [database connection]; setting a new progress handler cancels the
3132 ** old one. ^Setting parameter X to NULL disables the progress handler.
3133 ** ^The progress handler is also disabled by setting N to a value less
@@ -4742,50 +4743,49 @@
4743 SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
4744
4745 /*
4746 ** CAPI3REF: Function Auxiliary Data
4747 **
4748 ** These functions may be used by (non-aggregate) SQL functions to
4749 ** associate metadata with argument values. If the same value is passed to
4750 ** multiple invocations of the same SQL function during query execution, under
4751 ** some circumstances the associated metadata may be preserved. An example
4752 ** of where this might be useful is in a regular-expression matching
4753 ** function. The compiled version of the regular expression can be stored as
4754 ** metadata associated with the pattern string.
4755 ** Then as long as the pattern string remains the same,
4756 ** the compiled regular expression can be reused on multiple
4757 ** invocations of the same function.
4758 **
4759 ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
4760 ** associated by the sqlite3_set_auxdata() function with the Nth argument
4761 ** value to the application-defined function. ^If there is no metadata
4762 ** associated with the function argument, this sqlite3_get_auxdata() interface
4763 ** returns a NULL pointer.
 
4764 **
4765 ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
4766 ** argument of the application-defined function. ^Subsequent
4767 ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
4768 ** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or
4769 ** NULL if the metadata has been discarded.
4770 ** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL,
4771 ** SQLite will invoke the destructor function X with parameter P exactly
4772 ** once, when the metadata is discarded.
4773 ** SQLite is free to discard the metadata at any time, including: <ul>
4774 ** <li> when the corresponding function parameter changes, or
4775 ** <li> when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
4776 ** SQL statement, or
4777 ** <li> when sqlite3_set_auxdata() is invoked again on the same parameter, or
4778 ** <li> during the original sqlite3_set_auxdata() call when a memory
4779 ** allocation error occurs. </ul>)^
4780 **
4781 ** Note the last bullet in particular. The destructor X in
4782 ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
4783 ** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata()
 
 
 
4784 ** should be called near the end of the function implementation and the
4785 ** function implementation should not make any use of P after
4786 ** sqlite3_set_auxdata() has been called.
4787 **
4788 ** ^(In practice, metadata is preserved between function calls for
4789 ** function parameters that are compile-time constants, including literal
4790 ** values and [parameters] and expressions composed from the same.)^
4791 **
@@ -8824,11 +8824,10 @@
8824
8825 /*
8826 ** The names of the following types declared in vdbeInt.h are required
8827 ** for the VdbeOp definition.
8828 */
 
8829 typedef struct Mem Mem;
8830 typedef struct SubProgram SubProgram;
8831
8832 /*
8833 ** A single instruction of the virtual machine has an opcode
@@ -8848,11 +8847,10 @@
8847 void *p; /* Generic pointer */
8848 char *z; /* Pointer to data for string (char array) types */
8849 i64 *pI64; /* Used when p4type is P4_INT64 */
8850 double *pReal; /* Used when p4type is P4_REAL */
8851 FuncDef *pFunc; /* Used when p4type is P4_FUNCDEF */
 
8852 CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */
8853 Mem *pMem; /* Used when p4type is P4_MEM */
8854 VTable *pVtab; /* Used when p4type is P4_VTAB */
8855 KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */
8856 int *ai; /* Used when p4type is P4_INTARRAY */
@@ -8902,11 +8900,10 @@
8900 #define P4_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */
8901 #define P4_STATIC (-2) /* Pointer to a static string */
8902 #define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */
8903 #define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */
8904 #define P4_KEYINFO (-6) /* P4 is a pointer to a KeyInfo structure */
 
8905 #define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */
8906 #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */
8907 #define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */
8908 #define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */
8909 #define P4_REAL (-12) /* P4 is a 64-bit floating point value */
@@ -13257,10 +13254,13 @@
13254 typedef struct VdbeSorter VdbeSorter;
13255
13256 /* Opaque type used by the explainer */
13257 typedef struct Explain Explain;
13258
13259 /* Elements of the linked list at Vdbe.pAuxData */
13260 typedef struct AuxData AuxData;
13261
13262 /*
13263 ** A cursor is a pointer into a single BTree within a database file.
13264 ** The cursor can seek to a BTree entry with a particular key, or
13265 ** loop over all entries of the Btree. You can also insert new BTree
13266 ** entries or retrieve the key or data from the entry that the cursor
@@ -13443,27 +13443,23 @@
13443 */
13444 #ifdef SQLITE_DEBUG
13445 #define memIsValid(M) ((M)->flags & MEM_Invalid)==0
13446 #endif
13447
13448 /*
13449 ** Each auxilliary data pointer stored by a user defined function
13450 ** implementation calling sqlite3_set_auxdata() is stored in an instance
13451 ** of this structure. All such structures associated with a single VM
13452 ** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed
13453 ** when the VM is halted (if not before).
 
 
 
13454 */
13455 struct AuxData {
13456 int iOp; /* Instruction number of OP_Function opcode */
13457 int iArg; /* Index of function argument. */
13458 void *pAux; /* Aux data pointer */
13459 void (*xDelete)(void *); /* Destructor for the aux data */
13460 AuxData *pNext; /* Next element in list */
 
13461 };
13462
13463 /*
13464 ** The "context" argument for a installable function. A pointer to an
13465 ** instance of this structure is the first argument to the routines used
@@ -13477,16 +13473,17 @@
13473 ** This structure is defined inside of vdbeInt.h because it uses substructures
13474 ** (Mem) which are only defined there.
13475 */
13476 struct sqlite3_context {
13477 FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
 
13478 Mem s; /* The return value is stored here */
13479 Mem *pMem; /* Memory cell used to store aggregate context */
13480 CollSeq *pColl; /* Collating sequence */
13481 int isError; /* Error code returned by the function. */
13482 int skipFlag; /* Skip skip accumulator loading if true */
13483 int iOp; /* Instruction number of OP_Function */
13484 Vdbe *pVdbe; /* The VM that owns this context */
13485 };
13486
13487 /*
13488 ** An Explain object accumulates indented output which is helpful
13489 ** in describing recursive data structures.
@@ -13581,10 +13578,11 @@
13578 int nFrame; /* Number of frames in pFrame list */
13579 u32 expmask; /* Binding to these vars invalidates VM */
13580 SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
13581 int nOnceFlag; /* Size of array aOnceFlag[] */
13582 u8 *aOnceFlag; /* Flags for OP_Once */
13583 AuxData *pAuxData; /* Linked list of auxdata allocations */
13584 };
13585
13586 /*
13587 ** The following are allowed values for Vdbe.magic
13588 */
@@ -13604,11 +13602,11 @@
13602 #endif
13603 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
13604 SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
13605 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int);
13606 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
13607 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
13608
13609 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
13610 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
13611 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *);
13612 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
@@ -28376,10 +28374,14 @@
28374 */
28375 static const char *unixTempFileDir(void){
28376 static const char *azDirs[] = {
28377 0,
28378 0,
28379 #ifdef __CYGWIN__
28380 0,
28381 0,
28382 #endif
28383 "/var/tmp",
28384 "/usr/tmp",
28385 "/tmp",
28386 0 /* List terminator */
28387 };
@@ -28387,10 +28389,14 @@
28389 struct stat buf;
28390 const char *zDir = 0;
28391
28392 azDirs[0] = sqlite3_temp_directory;
28393 if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
28394 #ifdef __CYGWIN__
28395 if( !azDirs[2] ) azDirs[2] = getenv("TMP");
28396 if( !azDirs[3] ) azDirs[3] = getenv("TEMP");
28397 #endif
28398 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
28399 if( zDir==0 ) continue;
28400 if( osStat(zDir, &buf) ) continue;
28401 if( !S_ISDIR(buf.st_mode) ) continue;
28402 if( osAccess(zDir, 07) ) continue;
@@ -30735,11 +30741,11 @@
30741
30742 /*
30743 ** Are most of the Win32 Unicode APIs available (i.e. with certain exceptions
30744 ** based on the sub-platform)?
30745 */
30746 #if SQLITE_OS_WINCE || SQLITE_OS_WINNT || SQLITE_OS_WINRT || defined(__CYGWIN__)
30747 # define SQLITE_WIN32_HAS_WIDE
30748 #endif
30749
30750 /*
30751 ** Do we need to manually define the Win32 file mapping APIs for use with WAL
@@ -34556,10 +34562,12 @@
34562 #endif
34563 /* caller will handle out of memory */
34564 return zConverted;
34565 }
34566
34567 static int winIsDir(const void *zConverted);
34568
34569 /*
34570 ** Create a temporary file name in zBuf. zBuf must be big enough to
34571 ** hold at pVfs->mxPathname characters.
34572 */
34573 static int getTempname(int nBuf, char *zBuf){
@@ -34580,11 +34588,53 @@
34588 memset(zTempPath, 0, MAX_PATH+2);
34589
34590 if( sqlite3_temp_directory ){
34591 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
34592 }
34593 #if defined(__CYGWIN__)
34594 static const char *azDirs[] = {
34595 0,
34596 0,
34597 0,
34598 0,
34599 "/var/tmp",
34600 "/usr/tmp",
34601 "/tmp",
34602 0
34603 };
34604 const char *zDir = 0;
34605 char *zConverted;
34606
34607 azDirs[0] = sqlite3_temp_directory;
34608 if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
34609 if( !azDirs[2] ) azDirs[2] = getenv("TMP");
34610 if( !azDirs[3] ) azDirs[3] = getenv("TEMP");
34611 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
34612 if( zDir==0 || zDir[0]) continue;
34613 if( zDir[1]!=':' ){
34614 WCHAR zWidePath[MAX_PATH];
34615 cygwin_conv_path(CCP_POSIX_TO_WIN_W, zDir, zWidePath, MAX_PATH);
34616 zDir = unicodeToUtf8(zWidePath);
34617 if( zDir==0 ){
34618 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
34619 return SQLITE_IOERR_NOMEM;
34620 }
34621 }
34622 /* Convert the filename to the system encoding. */
34623 zConverted = convertUtf8Filename(zDir);
34624 if( zConverted==0 ){
34625 OSTRACE(("TEMP-FILENAME, rc=SQLITE_IOERR_NOMEM"));
34626 return SQLITE_IOERR_NOMEM;
34627 }
34628 if( winIsDir(zConverted) ){
34629 sqlite3_free(zConverted);
34630 break;
34631 }
34632 sqlite3_free(zConverted);
34633 }
34634 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zDir);
34635 #elif !SQLITE_OS_WINRT
34636 else if( isNT() ){
34637 char *zMulti;
34638 WCHAR zWidePath[MAX_PATH];
34639 osGetTempPathW(MAX_PATH-30, zWidePath);
34640 zMulti = unicodeToUtf8(zWidePath);
@@ -60538,17 +60588,10 @@
60588 }
60589 case P4_MPRINTF: {
60590 if( db->pnBytesFreed==0 ) sqlite3_free(p4);
60591 break;
60592 }
 
 
 
 
 
 
 
60593 case P4_FUNCDEF: {
60594 freeEphemeralFunction(db, (FuncDef*)p4);
60595 break;
60596 }
60597 case P4_MEM: {
@@ -61574,10 +61617,14 @@
61617 while( p->pDelFrame ){
61618 VdbeFrame *pDel = p->pDelFrame;
61619 p->pDelFrame = pDel->pParent;
61620 sqlite3VdbeFrameDelete(pDel);
61621 }
61622
61623 /* Delete any auxdata allocations made by the VM */
61624 sqlite3VdbeDeleteAuxData(p, -1, 0);
61625 assert( p->pAuxData==0 );
61626 }
61627
61628 /*
61629 ** Clean up the VM after execution.
61630 **
@@ -62372,24 +62419,39 @@
62419 sqlite3VdbeDelete(p);
62420 return rc;
62421 }
62422
62423 /*
62424 ** If parameter iOp is less than zero, then invoke the destructor for
62425 ** all auxiliary data pointers currently cached by the VM passed as
62426 ** the first argument.
62427 **
62428 ** Or, if iOp is greater than or equal to zero, then the destructor is
62429 ** only invoked for those auxiliary data pointers created by the user
62430 ** function invoked by the OP_Function opcode at instruction iOp of
62431 ** VM pVdbe, and only then if:
62432 **
62433 ** * the associated function parameter is the 32nd or later (counting
62434 ** from left to right), or
62435 **
62436 ** * the corresponding bit in argument mask is clear (where the first
62437 ** function parameter corrsponds to bit 0 etc.).
62438 */
62439 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe *pVdbe, int iOp, int mask){
62440 AuxData **pp = &pVdbe->pAuxData;
62441 while( *pp ){
62442 AuxData *pAux = *pp;
62443 if( (iOp<0)
62444 || (pAux->iOp==iOp && (pAux->iArg>31 || !(mask & ((u32)1<<pAux->iArg))))
62445 ){
62446 if( pAux->xDelete ){
62447 pAux->xDelete(pAux->pAux);
62448 }
62449 *pp = pAux->pNext;
62450 sqlite3DbFree(pVdbe->db, pAux);
62451 }else{
62452 pp= &pAux->pNext;
62453 }
62454 }
62455 }
62456
62457 /*
@@ -63784,18 +63846,18 @@
63846 /*
63847 ** Return the auxilary data pointer, if any, for the iArg'th argument to
63848 ** the user-function defined by pCtx.
63849 */
63850 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
63851 AuxData *pAuxData;
63852
63853 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63854 for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
63855 if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
 
63856 }
63857
63858 return (pAuxData ? pAuxData->pAux : 0);
63859 }
63860
63861 /*
63862 ** Set the auxilary data pointer and delete function, for the iArg'th
63863 ** argument to the user-function defined by pCtx. Any previous value is
@@ -63805,33 +63867,30 @@
63867 sqlite3_context *pCtx,
63868 int iArg,
63869 void *pAux,
63870 void (*xDelete)(void*)
63871 ){
63872 AuxData *pAuxData;
63873 Vdbe *pVdbe = pCtx->pVdbe;
 
63874
63875 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63876 if( iArg<0 ) goto failed;
63877
63878 for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
63879 if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
63880 }
63881 if( pAuxData==0 ){
63882 pAuxData = sqlite3DbMallocZero(pVdbe->db, sizeof(AuxData));
63883 if( !pAuxData ) goto failed;
63884 pAuxData->iOp = pCtx->iOp;
63885 pAuxData->iArg = iArg;
63886 pAuxData->pNext = pVdbe->pAuxData;
63887 pVdbe->pAuxData = pAuxData;
63888 }else if( pAuxData->xDelete ){
 
 
 
63889 pAuxData->xDelete(pAuxData->pAux);
63890 }
63891
63892 pAuxData->pAux = pAux;
63893 pAuxData->xDelete = xDelete;
63894 return;
63895
63896 failed:
@@ -65439,11 +65498,11 @@
65498 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
65499 u8 encoding = ENC(db); /* The database encoding */
65500 int iCompare = 0; /* Result of last OP_Compare operation */
65501 unsigned nVmStep = 0; /* Number of virtual machine steps */
65502 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65503 unsigned nProgressLimit; /* Invoke xProgress() when nVmStep reaches this */
65504 #endif
65505 Mem *aMem = p->aMem; /* Copy of p->aMem */
65506 Mem *pIn1 = 0; /* 1st input operand */
65507 Mem *pIn2 = 0; /* 2nd input operand */
65508 Mem *pIn3 = 0; /* 3rd input operand */
@@ -65898,10 +65957,21 @@
65957 assert( p->explain==0 );
65958 p->pResultSet = 0;
65959 db->busyHandler.nBusy = 0;
65960 CHECK_FOR_INTERRUPT;
65961 sqlite3VdbeIOTraceSql(p);
65962 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65963 if( db->xProgress ){
65964 assert( 0 < db->nProgressOps );
65965 nProgressLimit = (unsigned)p->aCounter[SQLITE_STMTSTATUS_VM_STEP-1];
65966 if( nProgressLimit==0 ){
65967 nProgressLimit = db->nProgressOps;
65968 }else{
65969 nProgressLimit %= (unsigned)db->nProgressOps;
65970 }
65971 }
65972 #endif
65973 #ifdef SQLITE_DEBUG
65974 sqlite3BeginBenignMalloc();
65975 if( p->pc==0 && (p->db->flags & SQLITE_VdbeListing)!=0 ){
65976 int i;
65977 printf("VDBE Program Listing:\n");
@@ -66058,18 +66128,20 @@
66128 ** of VDBE ops have been executed (either since this invocation of
66129 ** sqlite3VdbeExec() or since last time the progress callback was called).
66130 ** If the progress callback returns non-zero, exit the virtual machine with
66131 ** a return code SQLITE_ABORT.
66132 */
66133 if( db->xProgress!=0 && nVmStep>=nProgressLimit ){
66134 int prc;
66135 prc = db->xProgress(db->pProgressArg);
66136 if( prc!=0 ){
66137 rc = SQLITE_INTERRUPT;
66138 goto vdbe_error_halt;
66139 }
66140 if( db->xProgress!=0 ){
66141 nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps);
66142 }
66143 }
66144 #endif
66145
66146 break;
66147 }
@@ -66751,23 +66823,18 @@
66823 Deephemeralize(u.ai.pArg);
66824 sqlite3VdbeMemStoreType(u.ai.pArg);
66825 REGISTER_TRACE(pOp->p2+u.ai.i, u.ai.pArg);
66826 }
66827
66828 assert( pOp->p4type==P4_FUNCDEF );
66829 u.ai.ctx.pFunc = pOp->p4.pFunc;
 
 
 
 
 
 
 
66830 u.ai.ctx.s.flags = MEM_Null;
66831 u.ai.ctx.s.db = db;
66832 u.ai.ctx.s.xDel = 0;
66833 u.ai.ctx.s.zMalloc = 0;
66834 u.ai.ctx.iOp = pc;
66835 u.ai.ctx.pVdbe = p;
66836
66837 /* The output cell may already have a buffer allocated. Move
66838 ** the pointer to u.ai.ctx.s so in case the user-function can use
66839 ** the already allocated buffer instead of allocating a new one.
66840 */
@@ -66786,15 +66853,11 @@
66853 lastRowid = db->lastRowid;
66854
66855 /* If any auxiliary data functions have been called by this user function,
66856 ** immediately call the destructor for any non-static values.
66857 */
66858 sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
 
 
 
 
66859
66860 if( db->mallocFailed ){
66861 /* Even though a malloc() has failed, the implementation of the
66862 ** user function may have called an sqlite3_result_XXX() function
66863 ** to return a value. The following call releases any resources
@@ -117728,11 +117791,11 @@
117791 db->autoCommit = 1;
117792 db->nextAutovac = -1;
117793 db->szMmap = sqlite3GlobalConfig.szMmap;
117794 db->nextPagesize = 0;
117795 db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger
117796 #if !defined(SQLITE_DEFAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
117797 | SQLITE_AutoIndex
117798 #endif
117799 #if SQLITE_DEFAULT_FILE_FORMAT<4
117800 | SQLITE_LegacyFileFmt
117801 #endif
117802
+176 -113
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -670,11 +670,11 @@
670670
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
671671
** [sqlite_version()] and [sqlite_source_id()].
672672
*/
673673
#define SQLITE_VERSION "3.8.0"
674674
#define SQLITE_VERSION_NUMBER 3008000
675
-#define SQLITE_SOURCE_ID "2013-07-18 14:50:56 5dcffa671f592ae9355628afa439ae9a2d26f0cd"
675
+#define SQLITE_SOURCE_ID "2013-07-25 17:07:03 8bcbb33fd0a970e16a920e1d35571836dbb9ba50"
676676
677677
/*
678678
** CAPI3REF: Run-Time Library Version Numbers
679679
** KEYWORDS: sqlite3_version, sqlite3_sourceid
680680
**
@@ -3122,11 +3122,12 @@
31223122
** interface is to keep a GUI updated during a large query.
31233123
**
31243124
** ^The parameter P is passed through as the only parameter to the
31253125
** callback function X. ^The parameter N is the approximate number of
31263126
** [virtual machine instructions] that are evaluated between successive
3127
-** invocations of the callback X.
3127
+** invocations of the callback X. ^If N is less than one then the progress
3128
+** handler is disabled.
31283129
**
31293130
** ^Only a single progress handler may be defined at one time per
31303131
** [database connection]; setting a new progress handler cancels the
31313132
** old one. ^Setting parameter X to NULL disables the progress handler.
31323133
** ^The progress handler is also disabled by setting N to a value less
@@ -4742,50 +4743,49 @@
47424743
SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
47434744
47444745
/*
47454746
** CAPI3REF: Function Auxiliary Data
47464747
**
4747
-** The following two functions may be used by scalar SQL functions to
4748
+** These functions may be used by (non-aggregate) SQL functions to
47484749
** associate metadata with argument values. If the same value is passed to
47494750
** multiple invocations of the same SQL function during query execution, under
4750
-** some circumstances the associated metadata may be preserved. This might
4751
-** be used, for example, in a regular-expression matching
4752
-** function. The compiled version of the regular expression is stored as
4753
-** metadata associated with the SQL value passed as the regular expression
4754
-** pattern. The compiled regular expression can be reused on multiple
4755
-** invocations of the same function so that the original pattern string
4756
-** does not need to be recompiled on each invocation.
4751
+** some circumstances the associated metadata may be preserved. An example
4752
+** of where this might be useful is in a regular-expression matching
4753
+** function. The compiled version of the regular expression can be stored as
4754
+** metadata associated with the pattern string.
4755
+** Then as long as the pattern string remains the same,
4756
+** the compiled regular expression can be reused on multiple
4757
+** invocations of the same function.
47574758
**
47584759
** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
47594760
** associated by the sqlite3_set_auxdata() function with the Nth argument
4760
-** value to the application-defined function. ^If no metadata has been ever
4761
-** been set for the Nth argument of the function, or if the corresponding
4762
-** function parameter has changed since the meta-data was set,
4763
-** then sqlite3_get_auxdata() returns a NULL pointer.
4761
+** value to the application-defined function. ^If there is no metadata
4762
+** associated with the function argument, this sqlite3_get_auxdata() interface
4763
+** returns a NULL pointer.
47644764
**
47654765
** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
47664766
** argument of the application-defined function. ^Subsequent
47674767
** calls to sqlite3_get_auxdata(C,N) return P from the most recent
4768
-** sqlite3_set_auxdata(C,N,P,X) call if the data has not been dropped, or
4769
-** NULL if the data has been dropped.
4770
-** ^(If it is not NULL, SQLite will invoke the destructor
4771
-** function X passed to sqlite3_set_auxdata(C,N,P,X) when <ul>
4772
-** <li> the corresponding function parameter changes,
4773
-** <li> [sqlite3_reset()] or [sqlite3_finalize()] is called for the
4774
-** SQL statement,
4775
-** <li> sqlite3_set_auxdata() is invoked again on the same parameter, or
4776
-** <li> a memory allocation error occurs. </ul>)^
4768
+** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or
4769
+** NULL if the metadata has been discarded.
4770
+** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL,
4771
+** SQLite will invoke the destructor function X with parameter P exactly
4772
+** once, when the metadata is discarded.
4773
+** SQLite is free to discard the metadata at any time, including: <ul>
4774
+** <li> when the corresponding function parameter changes, or
4775
+** <li> when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
4776
+** SQL statement, or
4777
+** <li> when sqlite3_set_auxdata() is invoked again on the same parameter, or
4778
+** <li> during the original sqlite3_set_auxdata() call when a memory
4779
+** allocation error occurs. </ul>)^
47774780
**
4778
-** SQLite is free to call the destructor and drop metadata on any
4779
-** parameter of any function at any time. ^The only guarantee is that
4780
-** the destructor will be called when the [prepared statement] is destroyed.
4781
-** Note in particular that the destructor X in the call to
4782
-** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before
4783
-** the sqlite3_set_auxdata() call even returns. Hence sqlite3_set_auxdata()
4781
+** Note the last bullet in particular. The destructor X in
4782
+** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
4783
+** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata()
47844784
** should be called near the end of the function implementation and the
4785
-** implementation should not make any use of P after sqlite3_set_auxdata()
4786
-** has been called.
4785
+** function implementation should not make any use of P after
4786
+** sqlite3_set_auxdata() has been called.
47874787
**
47884788
** ^(In practice, metadata is preserved between function calls for
47894789
** function parameters that are compile-time constants, including literal
47904790
** values and [parameters] and expressions composed from the same.)^
47914791
**
@@ -8824,11 +8824,10 @@
88248824
88258825
/*
88268826
** The names of the following types declared in vdbeInt.h are required
88278827
** for the VdbeOp definition.
88288828
*/
8829
-typedef struct VdbeFunc VdbeFunc;
88308829
typedef struct Mem Mem;
88318830
typedef struct SubProgram SubProgram;
88328831
88338832
/*
88348833
** A single instruction of the virtual machine has an opcode
@@ -8848,11 +8847,10 @@
88488847
void *p; /* Generic pointer */
88498848
char *z; /* Pointer to data for string (char array) types */
88508849
i64 *pI64; /* Used when p4type is P4_INT64 */
88518850
double *pReal; /* Used when p4type is P4_REAL */
88528851
FuncDef *pFunc; /* Used when p4type is P4_FUNCDEF */
8853
- VdbeFunc *pVdbeFunc; /* Used when p4type is P4_VDBEFUNC */
88548852
CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */
88558853
Mem *pMem; /* Used when p4type is P4_MEM */
88568854
VTable *pVtab; /* Used when p4type is P4_VTAB */
88578855
KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */
88588856
int *ai; /* Used when p4type is P4_INTARRAY */
@@ -8902,11 +8900,10 @@
89028900
#define P4_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */
89038901
#define P4_STATIC (-2) /* Pointer to a static string */
89048902
#define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */
89058903
#define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */
89068904
#define P4_KEYINFO (-6) /* P4 is a pointer to a KeyInfo structure */
8907
-#define P4_VDBEFUNC (-7) /* P4 is a pointer to a VdbeFunc structure */
89088905
#define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */
89098906
#define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */
89108907
#define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */
89118908
#define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */
89128909
#define P4_REAL (-12) /* P4 is a 64-bit floating point value */
@@ -13257,10 +13254,13 @@
1325713254
typedef struct VdbeSorter VdbeSorter;
1325813255
1325913256
/* Opaque type used by the explainer */
1326013257
typedef struct Explain Explain;
1326113258
13259
+/* Elements of the linked list at Vdbe.pAuxData */
13260
+typedef struct AuxData AuxData;
13261
+
1326213262
/*
1326313263
** A cursor is a pointer into a single BTree within a database file.
1326413264
** The cursor can seek to a BTree entry with a particular key, or
1326513265
** loop over all entries of the Btree. You can also insert new BTree
1326613266
** entries or retrieve the key or data from the entry that the cursor
@@ -13443,27 +13443,23 @@
1344313443
*/
1344413444
#ifdef SQLITE_DEBUG
1344513445
#define memIsValid(M) ((M)->flags & MEM_Invalid)==0
1344613446
#endif
1344713447
13448
-
13449
-/* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains
13450
-** additional information about auxiliary information bound to arguments
13451
-** of the function. This is used to implement the sqlite3_get_auxdata()
13452
-** and sqlite3_set_auxdata() APIs. The "auxdata" is some auxiliary data
13453
-** that can be associated with a constant argument to a function. This
13454
-** allows functions such as "regexp" to compile their constant regular
13455
-** expression argument once and reused the compiled code for multiple
13456
-** invocations.
13448
+/*
13449
+** Each auxilliary data pointer stored by a user defined function
13450
+** implementation calling sqlite3_set_auxdata() is stored in an instance
13451
+** of this structure. All such structures associated with a single VM
13452
+** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed
13453
+** when the VM is halted (if not before).
1345713454
*/
13458
-struct VdbeFunc {
13459
- FuncDef *pFunc; /* The definition of the function */
13460
- int nAux; /* Number of entries allocated for apAux[] */
13461
- struct AuxData {
13462
- void *pAux; /* Aux data for the i-th argument */
13463
- void (*xDelete)(void *); /* Destructor for the aux data */
13464
- } apAux[1]; /* One slot for each function argument */
13455
+struct AuxData {
13456
+ int iOp; /* Instruction number of OP_Function opcode */
13457
+ int iArg; /* Index of function argument. */
13458
+ void *pAux; /* Aux data pointer */
13459
+ void (*xDelete)(void *); /* Destructor for the aux data */
13460
+ AuxData *pNext; /* Next element in list */
1346513461
};
1346613462
1346713463
/*
1346813464
** The "context" argument for a installable function. A pointer to an
1346913465
** instance of this structure is the first argument to the routines used
@@ -13477,16 +13473,17 @@
1347713473
** This structure is defined inside of vdbeInt.h because it uses substructures
1347813474
** (Mem) which are only defined there.
1347913475
*/
1348013476
struct sqlite3_context {
1348113477
FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
13482
- VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */
1348313478
Mem s; /* The return value is stored here */
1348413479
Mem *pMem; /* Memory cell used to store aggregate context */
1348513480
CollSeq *pColl; /* Collating sequence */
1348613481
int isError; /* Error code returned by the function. */
1348713482
int skipFlag; /* Skip skip accumulator loading if true */
13483
+ int iOp; /* Instruction number of OP_Function */
13484
+ Vdbe *pVdbe; /* The VM that owns this context */
1348813485
};
1348913486
1349013487
/*
1349113488
** An Explain object accumulates indented output which is helpful
1349213489
** in describing recursive data structures.
@@ -13581,10 +13578,11 @@
1358113578
int nFrame; /* Number of frames in pFrame list */
1358213579
u32 expmask; /* Binding to these vars invalidates VM */
1358313580
SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
1358413581
int nOnceFlag; /* Size of array aOnceFlag[] */
1358513582
u8 *aOnceFlag; /* Flags for OP_Once */
13583
+ AuxData *pAuxData; /* Linked list of auxdata allocations */
1358613584
};
1358713585
1358813586
/*
1358913587
** The following are allowed values for Vdbe.magic
1359013588
*/
@@ -13604,11 +13602,11 @@
1360413602
#endif
1360513603
SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
1360613604
SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
1360713605
SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int);
1360813606
SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
13609
-SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(VdbeFunc*, int);
13607
+SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
1361013608
1361113609
int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
1361213610
SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
1361313611
SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *);
1361413612
SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
@@ -28376,10 +28374,14 @@
2837628374
*/
2837728375
static const char *unixTempFileDir(void){
2837828376
static const char *azDirs[] = {
2837928377
0,
2838028378
0,
28379
+#ifdef __CYGWIN__
28380
+ 0,
28381
+ 0,
28382
+#endif
2838128383
"/var/tmp",
2838228384
"/usr/tmp",
2838328385
"/tmp",
2838428386
0 /* List terminator */
2838528387
};
@@ -28387,10 +28389,14 @@
2838728389
struct stat buf;
2838828390
const char *zDir = 0;
2838928391
2839028392
azDirs[0] = sqlite3_temp_directory;
2839128393
if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
28394
+#ifdef __CYGWIN__
28395
+ if( !azDirs[2] ) azDirs[2] = getenv("TMP");
28396
+ if( !azDirs[3] ) azDirs[3] = getenv("TEMP");
28397
+#endif
2839228398
for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
2839328399
if( zDir==0 ) continue;
2839428400
if( osStat(zDir, &buf) ) continue;
2839528401
if( !S_ISDIR(buf.st_mode) ) continue;
2839628402
if( osAccess(zDir, 07) ) continue;
@@ -30735,11 +30741,11 @@
3073530741
3073630742
/*
3073730743
** Are most of the Win32 Unicode APIs available (i.e. with certain exceptions
3073830744
** based on the sub-platform)?
3073930745
*/
30740
-#if SQLITE_OS_WINCE || SQLITE_OS_WINNT || SQLITE_OS_WINRT
30746
+#if SQLITE_OS_WINCE || SQLITE_OS_WINNT || SQLITE_OS_WINRT || defined(__CYGWIN__)
3074130747
# define SQLITE_WIN32_HAS_WIDE
3074230748
#endif
3074330749
3074430750
/*
3074530751
** Do we need to manually define the Win32 file mapping APIs for use with WAL
@@ -34556,10 +34562,12 @@
3455634562
#endif
3455734563
/* caller will handle out of memory */
3455834564
return zConverted;
3455934565
}
3456034566
34567
+static int winIsDir(const void *zConverted);
34568
+
3456134569
/*
3456234570
** Create a temporary file name in zBuf. zBuf must be big enough to
3456334571
** hold at pVfs->mxPathname characters.
3456434572
*/
3456534573
static int getTempname(int nBuf, char *zBuf){
@@ -34580,11 +34588,53 @@
3458034588
memset(zTempPath, 0, MAX_PATH+2);
3458134589
3458234590
if( sqlite3_temp_directory ){
3458334591
sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
3458434592
}
34585
-#if !SQLITE_OS_WINRT
34593
+#if defined(__CYGWIN__)
34594
+ static const char *azDirs[] = {
34595
+ 0,
34596
+ 0,
34597
+ 0,
34598
+ 0,
34599
+ "/var/tmp",
34600
+ "/usr/tmp",
34601
+ "/tmp",
34602
+ 0
34603
+ };
34604
+ const char *zDir = 0;
34605
+ char *zConverted;
34606
+
34607
+ azDirs[0] = sqlite3_temp_directory;
34608
+ if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
34609
+ if( !azDirs[2] ) azDirs[2] = getenv("TMP");
34610
+ if( !azDirs[3] ) azDirs[3] = getenv("TEMP");
34611
+ for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
34612
+ if( zDir==0 || zDir[0]) continue;
34613
+ if( zDir[1]!=':' ){
34614
+ WCHAR zWidePath[MAX_PATH];
34615
+ cygwin_conv_path(CCP_POSIX_TO_WIN_W, zDir, zWidePath, MAX_PATH);
34616
+ zDir = unicodeToUtf8(zWidePath);
34617
+ if( zDir==0 ){
34618
+ OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
34619
+ return SQLITE_IOERR_NOMEM;
34620
+ }
34621
+ }
34622
+ /* Convert the filename to the system encoding. */
34623
+ zConverted = convertUtf8Filename(zDir);
34624
+ if( zConverted==0 ){
34625
+ OSTRACE(("TEMP-FILENAME, rc=SQLITE_IOERR_NOMEM"));
34626
+ return SQLITE_IOERR_NOMEM;
34627
+ }
34628
+ if( winIsDir(zConverted) ){
34629
+ sqlite3_free(zConverted);
34630
+ break;
34631
+ }
34632
+ sqlite3_free(zConverted);
34633
+ }
34634
+ sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zDir);
34635
+#elif !SQLITE_OS_WINRT
3458634636
else if( isNT() ){
3458734637
char *zMulti;
3458834638
WCHAR zWidePath[MAX_PATH];
3458934639
osGetTempPathW(MAX_PATH-30, zWidePath);
3459034640
zMulti = unicodeToUtf8(zWidePath);
@@ -60538,17 +60588,10 @@
6053860588
}
6053960589
case P4_MPRINTF: {
6054060590
if( db->pnBytesFreed==0 ) sqlite3_free(p4);
6054160591
break;
6054260592
}
60543
- case P4_VDBEFUNC: {
60544
- VdbeFunc *pVdbeFunc = (VdbeFunc *)p4;
60545
- freeEphemeralFunction(db, pVdbeFunc->pFunc);
60546
- if( db->pnBytesFreed==0 ) sqlite3VdbeDeleteAuxData(pVdbeFunc, 0);
60547
- sqlite3DbFree(db, pVdbeFunc);
60548
- break;
60549
- }
6055060593
case P4_FUNCDEF: {
6055160594
freeEphemeralFunction(db, (FuncDef*)p4);
6055260595
break;
6055360596
}
6055460597
case P4_MEM: {
@@ -61574,10 +61617,14 @@
6157461617
while( p->pDelFrame ){
6157561618
VdbeFrame *pDel = p->pDelFrame;
6157661619
p->pDelFrame = pDel->pParent;
6157761620
sqlite3VdbeFrameDelete(pDel);
6157861621
}
61622
+
61623
+ /* Delete any auxdata allocations made by the VM */
61624
+ sqlite3VdbeDeleteAuxData(p, -1, 0);
61625
+ assert( p->pAuxData==0 );
6157961626
}
6158061627
6158161628
/*
6158261629
** Clean up the VM after execution.
6158361630
**
@@ -62372,24 +62419,39 @@
6237262419
sqlite3VdbeDelete(p);
6237362420
return rc;
6237462421
}
6237562422
6237662423
/*
62377
-** Call the destructor for each auxdata entry in pVdbeFunc for which
62378
-** the corresponding bit in mask is clear. Auxdata entries beyond 31
62379
-** are always destroyed. To destroy all auxdata entries, call this
62380
-** routine with mask==0.
62424
+** If parameter iOp is less than zero, then invoke the destructor for
62425
+** all auxiliary data pointers currently cached by the VM passed as
62426
+** the first argument.
62427
+**
62428
+** Or, if iOp is greater than or equal to zero, then the destructor is
62429
+** only invoked for those auxiliary data pointers created by the user
62430
+** function invoked by the OP_Function opcode at instruction iOp of
62431
+** VM pVdbe, and only then if:
62432
+**
62433
+** * the associated function parameter is the 32nd or later (counting
62434
+** from left to right), or
62435
+**
62436
+** * the corresponding bit in argument mask is clear (where the first
62437
+** function parameter corrsponds to bit 0 etc.).
6238162438
*/
62382
-SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(VdbeFunc *pVdbeFunc, int mask){
62383
- int i;
62384
- for(i=0; i<pVdbeFunc->nAux; i++){
62385
- struct AuxData *pAux = &pVdbeFunc->apAux[i];
62386
- if( (i>31 || !(mask&(((u32)1)<<i))) && pAux->pAux ){
62439
+SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe *pVdbe, int iOp, int mask){
62440
+ AuxData **pp = &pVdbe->pAuxData;
62441
+ while( *pp ){
62442
+ AuxData *pAux = *pp;
62443
+ if( (iOp<0)
62444
+ || (pAux->iOp==iOp && (pAux->iArg>31 || !(mask & ((u32)1<<pAux->iArg))))
62445
+ ){
6238762446
if( pAux->xDelete ){
6238862447
pAux->xDelete(pAux->pAux);
6238962448
}
62390
- pAux->pAux = 0;
62449
+ *pp = pAux->pNext;
62450
+ sqlite3DbFree(pVdbe->db, pAux);
62451
+ }else{
62452
+ pp= &pAux->pNext;
6239162453
}
6239262454
}
6239362455
}
6239462456
6239562457
/*
@@ -63784,18 +63846,18 @@
6378463846
/*
6378563847
** Return the auxilary data pointer, if any, for the iArg'th argument to
6378663848
** the user-function defined by pCtx.
6378763849
*/
6378863850
SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
63789
- VdbeFunc *pVdbeFunc;
63851
+ AuxData *pAuxData;
6379063852
6379163853
assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63792
- pVdbeFunc = pCtx->pVdbeFunc;
63793
- if( !pVdbeFunc || iArg>=pVdbeFunc->nAux || iArg<0 ){
63794
- return 0;
63854
+ for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
63855
+ if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
6379563856
}
63796
- return pVdbeFunc->apAux[iArg].pAux;
63857
+
63858
+ return (pAuxData ? pAuxData->pAux : 0);
6379763859
}
6379863860
6379963861
/*
6380063862
** Set the auxilary data pointer and delete function, for the iArg'th
6380163863
** argument to the user-function defined by pCtx. Any previous value is
@@ -63805,33 +63867,30 @@
6380563867
sqlite3_context *pCtx,
6380663868
int iArg,
6380763869
void *pAux,
6380863870
void (*xDelete)(void*)
6380963871
){
63810
- struct AuxData *pAuxData;
63811
- VdbeFunc *pVdbeFunc;
63812
- if( iArg<0 ) goto failed;
63872
+ AuxData *pAuxData;
63873
+ Vdbe *pVdbe = pCtx->pVdbe;
6381363874
6381463875
assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63815
- pVdbeFunc = pCtx->pVdbeFunc;
63816
- if( !pVdbeFunc || pVdbeFunc->nAux<=iArg ){
63817
- int nAux = (pVdbeFunc ? pVdbeFunc->nAux : 0);
63818
- int nMalloc = sizeof(VdbeFunc) + sizeof(struct AuxData)*iArg;
63819
- pVdbeFunc = sqlite3DbRealloc(pCtx->s.db, pVdbeFunc, nMalloc);
63820
- if( !pVdbeFunc ){
63821
- goto failed;
63822
- }
63823
- pCtx->pVdbeFunc = pVdbeFunc;
63824
- memset(&pVdbeFunc->apAux[nAux], 0, sizeof(struct AuxData)*(iArg+1-nAux));
63825
- pVdbeFunc->nAux = iArg+1;
63826
- pVdbeFunc->pFunc = pCtx->pFunc;
63827
- }
63828
-
63829
- pAuxData = &pVdbeFunc->apAux[iArg];
63830
- if( pAuxData->pAux && pAuxData->xDelete ){
63876
+ if( iArg<0 ) goto failed;
63877
+
63878
+ for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
63879
+ if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
63880
+ }
63881
+ if( pAuxData==0 ){
63882
+ pAuxData = sqlite3DbMallocZero(pVdbe->db, sizeof(AuxData));
63883
+ if( !pAuxData ) goto failed;
63884
+ pAuxData->iOp = pCtx->iOp;
63885
+ pAuxData->iArg = iArg;
63886
+ pAuxData->pNext = pVdbe->pAuxData;
63887
+ pVdbe->pAuxData = pAuxData;
63888
+ }else if( pAuxData->xDelete ){
6383163889
pAuxData->xDelete(pAuxData->pAux);
6383263890
}
63891
+
6383363892
pAuxData->pAux = pAux;
6383463893
pAuxData->xDelete = xDelete;
6383563894
return;
6383663895
6383763896
failed:
@@ -65439,11 +65498,11 @@
6543965498
u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
6544065499
u8 encoding = ENC(db); /* The database encoding */
6544165500
int iCompare = 0; /* Result of last OP_Compare operation */
6544265501
unsigned nVmStep = 0; /* Number of virtual machine steps */
6544365502
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65444
- unsigned nProgressOps = 0; /* nVmStep at last progress callback. */
65503
+ unsigned nProgressLimit; /* Invoke xProgress() when nVmStep reaches this */
6544565504
#endif
6544665505
Mem *aMem = p->aMem; /* Copy of p->aMem */
6544765506
Mem *pIn1 = 0; /* 1st input operand */
6544865507
Mem *pIn2 = 0; /* 2nd input operand */
6544965508
Mem *pIn3 = 0; /* 3rd input operand */
@@ -65898,10 +65957,21 @@
6589865957
assert( p->explain==0 );
6589965958
p->pResultSet = 0;
6590065959
db->busyHandler.nBusy = 0;
6590165960
CHECK_FOR_INTERRUPT;
6590265961
sqlite3VdbeIOTraceSql(p);
65962
+#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65963
+ if( db->xProgress ){
65964
+ assert( 0 < db->nProgressOps );
65965
+ nProgressLimit = (unsigned)p->aCounter[SQLITE_STMTSTATUS_VM_STEP-1];
65966
+ if( nProgressLimit==0 ){
65967
+ nProgressLimit = db->nProgressOps;
65968
+ }else{
65969
+ nProgressLimit %= (unsigned)db->nProgressOps;
65970
+ }
65971
+ }
65972
+#endif
6590365973
#ifdef SQLITE_DEBUG
6590465974
sqlite3BeginBenignMalloc();
6590565975
if( p->pc==0 && (p->db->flags & SQLITE_VdbeListing)!=0 ){
6590665976
int i;
6590765977
printf("VDBE Program Listing:\n");
@@ -66058,18 +66128,20 @@
6605866128
** of VDBE ops have been executed (either since this invocation of
6605966129
** sqlite3VdbeExec() or since last time the progress callback was called).
6606066130
** If the progress callback returns non-zero, exit the virtual machine with
6606166131
** a return code SQLITE_ABORT.
6606266132
*/
66063
- if( db->xProgress!=0 && (nVmStep - nProgressOps)>=db->nProgressOps ){
66133
+ if( db->xProgress!=0 && nVmStep>=nProgressLimit ){
6606466134
int prc;
6606566135
prc = db->xProgress(db->pProgressArg);
6606666136
if( prc!=0 ){
6606766137
rc = SQLITE_INTERRUPT;
6606866138
goto vdbe_error_halt;
6606966139
}
66070
- nProgressOps = nVmStep;
66140
+ if( db->xProgress!=0 ){
66141
+ nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps);
66142
+ }
6607166143
}
6607266144
#endif
6607366145
6607466146
break;
6607566147
}
@@ -66751,23 +66823,18 @@
6675166823
Deephemeralize(u.ai.pArg);
6675266824
sqlite3VdbeMemStoreType(u.ai.pArg);
6675366825
REGISTER_TRACE(pOp->p2+u.ai.i, u.ai.pArg);
6675466826
}
6675566827
66756
- assert( pOp->p4type==P4_FUNCDEF || pOp->p4type==P4_VDBEFUNC );
66757
- if( pOp->p4type==P4_FUNCDEF ){
66758
- u.ai.ctx.pFunc = pOp->p4.pFunc;
66759
- u.ai.ctx.pVdbeFunc = 0;
66760
- }else{
66761
- u.ai.ctx.pVdbeFunc = (VdbeFunc*)pOp->p4.pVdbeFunc;
66762
- u.ai.ctx.pFunc = u.ai.ctx.pVdbeFunc->pFunc;
66763
- }
66764
-
66828
+ assert( pOp->p4type==P4_FUNCDEF );
66829
+ u.ai.ctx.pFunc = pOp->p4.pFunc;
6676566830
u.ai.ctx.s.flags = MEM_Null;
6676666831
u.ai.ctx.s.db = db;
6676766832
u.ai.ctx.s.xDel = 0;
6676866833
u.ai.ctx.s.zMalloc = 0;
66834
+ u.ai.ctx.iOp = pc;
66835
+ u.ai.ctx.pVdbe = p;
6676966836
6677066837
/* The output cell may already have a buffer allocated. Move
6677166838
** the pointer to u.ai.ctx.s so in case the user-function can use
6677266839
** the already allocated buffer instead of allocating a new one.
6677366840
*/
@@ -66786,15 +66853,11 @@
6678666853
lastRowid = db->lastRowid;
6678766854
6678866855
/* If any auxiliary data functions have been called by this user function,
6678966856
** immediately call the destructor for any non-static values.
6679066857
*/
66791
- if( u.ai.ctx.pVdbeFunc ){
66792
- sqlite3VdbeDeleteAuxData(u.ai.ctx.pVdbeFunc, pOp->p1);
66793
- pOp->p4.pVdbeFunc = u.ai.ctx.pVdbeFunc;
66794
- pOp->p4type = P4_VDBEFUNC;
66795
- }
66858
+ sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
6679666859
6679766860
if( db->mallocFailed ){
6679866861
/* Even though a malloc() has failed, the implementation of the
6679966862
** user function may have called an sqlite3_result_XXX() function
6680066863
** to return a value. The following call releases any resources
@@ -117728,11 +117791,11 @@
117728117791
db->autoCommit = 1;
117729117792
db->nextAutovac = -1;
117730117793
db->szMmap = sqlite3GlobalConfig.szMmap;
117731117794
db->nextPagesize = 0;
117732117795
db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger
117733
-#if !defined(SQLITE_DEAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
117796
+#if !defined(SQLITE_DEFAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
117734117797
| SQLITE_AutoIndex
117735117798
#endif
117736117799
#if SQLITE_DEFAULT_FILE_FORMAT<4
117737117800
| SQLITE_LegacyFileFmt
117738117801
#endif
117739117802
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -670,11 +670,11 @@
670 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
671 ** [sqlite_version()] and [sqlite_source_id()].
672 */
673 #define SQLITE_VERSION "3.8.0"
674 #define SQLITE_VERSION_NUMBER 3008000
675 #define SQLITE_SOURCE_ID "2013-07-18 14:50:56 5dcffa671f592ae9355628afa439ae9a2d26f0cd"
676
677 /*
678 ** CAPI3REF: Run-Time Library Version Numbers
679 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
680 **
@@ -3122,11 +3122,12 @@
3122 ** interface is to keep a GUI updated during a large query.
3123 **
3124 ** ^The parameter P is passed through as the only parameter to the
3125 ** callback function X. ^The parameter N is the approximate number of
3126 ** [virtual machine instructions] that are evaluated between successive
3127 ** invocations of the callback X.
 
3128 **
3129 ** ^Only a single progress handler may be defined at one time per
3130 ** [database connection]; setting a new progress handler cancels the
3131 ** old one. ^Setting parameter X to NULL disables the progress handler.
3132 ** ^The progress handler is also disabled by setting N to a value less
@@ -4742,50 +4743,49 @@
4742 SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
4743
4744 /*
4745 ** CAPI3REF: Function Auxiliary Data
4746 **
4747 ** The following two functions may be used by scalar SQL functions to
4748 ** associate metadata with argument values. If the same value is passed to
4749 ** multiple invocations of the same SQL function during query execution, under
4750 ** some circumstances the associated metadata may be preserved. This might
4751 ** be used, for example, in a regular-expression matching
4752 ** function. The compiled version of the regular expression is stored as
4753 ** metadata associated with the SQL value passed as the regular expression
4754 ** pattern. The compiled regular expression can be reused on multiple
4755 ** invocations of the same function so that the original pattern string
4756 ** does not need to be recompiled on each invocation.
4757 **
4758 ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
4759 ** associated by the sqlite3_set_auxdata() function with the Nth argument
4760 ** value to the application-defined function. ^If no metadata has been ever
4761 ** been set for the Nth argument of the function, or if the corresponding
4762 ** function parameter has changed since the meta-data was set,
4763 ** then sqlite3_get_auxdata() returns a NULL pointer.
4764 **
4765 ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
4766 ** argument of the application-defined function. ^Subsequent
4767 ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
4768 ** sqlite3_set_auxdata(C,N,P,X) call if the data has not been dropped, or
4769 ** NULL if the data has been dropped.
4770 ** ^(If it is not NULL, SQLite will invoke the destructor
4771 ** function X passed to sqlite3_set_auxdata(C,N,P,X) when <ul>
4772 ** <li> the corresponding function parameter changes,
4773 ** <li> [sqlite3_reset()] or [sqlite3_finalize()] is called for the
4774 ** SQL statement,
4775 ** <li> sqlite3_set_auxdata() is invoked again on the same parameter, or
4776 ** <li> a memory allocation error occurs. </ul>)^
 
 
 
4777 **
4778 ** SQLite is free to call the destructor and drop metadata on any
4779 ** parameter of any function at any time. ^The only guarantee is that
4780 ** the destructor will be called when the [prepared statement] is destroyed.
4781 ** Note in particular that the destructor X in the call to
4782 ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before
4783 ** the sqlite3_set_auxdata() call even returns. Hence sqlite3_set_auxdata()
4784 ** should be called near the end of the function implementation and the
4785 ** implementation should not make any use of P after sqlite3_set_auxdata()
4786 ** has been called.
4787 **
4788 ** ^(In practice, metadata is preserved between function calls for
4789 ** function parameters that are compile-time constants, including literal
4790 ** values and [parameters] and expressions composed from the same.)^
4791 **
@@ -8824,11 +8824,10 @@
8824
8825 /*
8826 ** The names of the following types declared in vdbeInt.h are required
8827 ** for the VdbeOp definition.
8828 */
8829 typedef struct VdbeFunc VdbeFunc;
8830 typedef struct Mem Mem;
8831 typedef struct SubProgram SubProgram;
8832
8833 /*
8834 ** A single instruction of the virtual machine has an opcode
@@ -8848,11 +8847,10 @@
8848 void *p; /* Generic pointer */
8849 char *z; /* Pointer to data for string (char array) types */
8850 i64 *pI64; /* Used when p4type is P4_INT64 */
8851 double *pReal; /* Used when p4type is P4_REAL */
8852 FuncDef *pFunc; /* Used when p4type is P4_FUNCDEF */
8853 VdbeFunc *pVdbeFunc; /* Used when p4type is P4_VDBEFUNC */
8854 CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */
8855 Mem *pMem; /* Used when p4type is P4_MEM */
8856 VTable *pVtab; /* Used when p4type is P4_VTAB */
8857 KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */
8858 int *ai; /* Used when p4type is P4_INTARRAY */
@@ -8902,11 +8900,10 @@
8902 #define P4_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */
8903 #define P4_STATIC (-2) /* Pointer to a static string */
8904 #define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */
8905 #define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */
8906 #define P4_KEYINFO (-6) /* P4 is a pointer to a KeyInfo structure */
8907 #define P4_VDBEFUNC (-7) /* P4 is a pointer to a VdbeFunc structure */
8908 #define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */
8909 #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */
8910 #define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */
8911 #define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */
8912 #define P4_REAL (-12) /* P4 is a 64-bit floating point value */
@@ -13257,10 +13254,13 @@
13257 typedef struct VdbeSorter VdbeSorter;
13258
13259 /* Opaque type used by the explainer */
13260 typedef struct Explain Explain;
13261
 
 
 
13262 /*
13263 ** A cursor is a pointer into a single BTree within a database file.
13264 ** The cursor can seek to a BTree entry with a particular key, or
13265 ** loop over all entries of the Btree. You can also insert new BTree
13266 ** entries or retrieve the key or data from the entry that the cursor
@@ -13443,27 +13443,23 @@
13443 */
13444 #ifdef SQLITE_DEBUG
13445 #define memIsValid(M) ((M)->flags & MEM_Invalid)==0
13446 #endif
13447
13448
13449 /* A VdbeFunc is just a FuncDef (defined in sqliteInt.h) that contains
13450 ** additional information about auxiliary information bound to arguments
13451 ** of the function. This is used to implement the sqlite3_get_auxdata()
13452 ** and sqlite3_set_auxdata() APIs. The "auxdata" is some auxiliary data
13453 ** that can be associated with a constant argument to a function. This
13454 ** allows functions such as "regexp" to compile their constant regular
13455 ** expression argument once and reused the compiled code for multiple
13456 ** invocations.
13457 */
13458 struct VdbeFunc {
13459 FuncDef *pFunc; /* The definition of the function */
13460 int nAux; /* Number of entries allocated for apAux[] */
13461 struct AuxData {
13462 void *pAux; /* Aux data for the i-th argument */
13463 void (*xDelete)(void *); /* Destructor for the aux data */
13464 } apAux[1]; /* One slot for each function argument */
13465 };
13466
13467 /*
13468 ** The "context" argument for a installable function. A pointer to an
13469 ** instance of this structure is the first argument to the routines used
@@ -13477,16 +13473,17 @@
13477 ** This structure is defined inside of vdbeInt.h because it uses substructures
13478 ** (Mem) which are only defined there.
13479 */
13480 struct sqlite3_context {
13481 FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
13482 VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */
13483 Mem s; /* The return value is stored here */
13484 Mem *pMem; /* Memory cell used to store aggregate context */
13485 CollSeq *pColl; /* Collating sequence */
13486 int isError; /* Error code returned by the function. */
13487 int skipFlag; /* Skip skip accumulator loading if true */
 
 
13488 };
13489
13490 /*
13491 ** An Explain object accumulates indented output which is helpful
13492 ** in describing recursive data structures.
@@ -13581,10 +13578,11 @@
13581 int nFrame; /* Number of frames in pFrame list */
13582 u32 expmask; /* Binding to these vars invalidates VM */
13583 SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
13584 int nOnceFlag; /* Size of array aOnceFlag[] */
13585 u8 *aOnceFlag; /* Flags for OP_Once */
 
13586 };
13587
13588 /*
13589 ** The following are allowed values for Vdbe.magic
13590 */
@@ -13604,11 +13602,11 @@
13604 #endif
13605 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
13606 SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
13607 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int);
13608 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
13609 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(VdbeFunc*, int);
13610
13611 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
13612 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
13613 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *);
13614 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
@@ -28376,10 +28374,14 @@
28376 */
28377 static const char *unixTempFileDir(void){
28378 static const char *azDirs[] = {
28379 0,
28380 0,
 
 
 
 
28381 "/var/tmp",
28382 "/usr/tmp",
28383 "/tmp",
28384 0 /* List terminator */
28385 };
@@ -28387,10 +28389,14 @@
28387 struct stat buf;
28388 const char *zDir = 0;
28389
28390 azDirs[0] = sqlite3_temp_directory;
28391 if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
 
 
 
 
28392 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
28393 if( zDir==0 ) continue;
28394 if( osStat(zDir, &buf) ) continue;
28395 if( !S_ISDIR(buf.st_mode) ) continue;
28396 if( osAccess(zDir, 07) ) continue;
@@ -30735,11 +30741,11 @@
30735
30736 /*
30737 ** Are most of the Win32 Unicode APIs available (i.e. with certain exceptions
30738 ** based on the sub-platform)?
30739 */
30740 #if SQLITE_OS_WINCE || SQLITE_OS_WINNT || SQLITE_OS_WINRT
30741 # define SQLITE_WIN32_HAS_WIDE
30742 #endif
30743
30744 /*
30745 ** Do we need to manually define the Win32 file mapping APIs for use with WAL
@@ -34556,10 +34562,12 @@
34556 #endif
34557 /* caller will handle out of memory */
34558 return zConverted;
34559 }
34560
 
 
34561 /*
34562 ** Create a temporary file name in zBuf. zBuf must be big enough to
34563 ** hold at pVfs->mxPathname characters.
34564 */
34565 static int getTempname(int nBuf, char *zBuf){
@@ -34580,11 +34588,53 @@
34580 memset(zTempPath, 0, MAX_PATH+2);
34581
34582 if( sqlite3_temp_directory ){
34583 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
34584 }
34585 #if !SQLITE_OS_WINRT
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34586 else if( isNT() ){
34587 char *zMulti;
34588 WCHAR zWidePath[MAX_PATH];
34589 osGetTempPathW(MAX_PATH-30, zWidePath);
34590 zMulti = unicodeToUtf8(zWidePath);
@@ -60538,17 +60588,10 @@
60538 }
60539 case P4_MPRINTF: {
60540 if( db->pnBytesFreed==0 ) sqlite3_free(p4);
60541 break;
60542 }
60543 case P4_VDBEFUNC: {
60544 VdbeFunc *pVdbeFunc = (VdbeFunc *)p4;
60545 freeEphemeralFunction(db, pVdbeFunc->pFunc);
60546 if( db->pnBytesFreed==0 ) sqlite3VdbeDeleteAuxData(pVdbeFunc, 0);
60547 sqlite3DbFree(db, pVdbeFunc);
60548 break;
60549 }
60550 case P4_FUNCDEF: {
60551 freeEphemeralFunction(db, (FuncDef*)p4);
60552 break;
60553 }
60554 case P4_MEM: {
@@ -61574,10 +61617,14 @@
61574 while( p->pDelFrame ){
61575 VdbeFrame *pDel = p->pDelFrame;
61576 p->pDelFrame = pDel->pParent;
61577 sqlite3VdbeFrameDelete(pDel);
61578 }
 
 
 
 
61579 }
61580
61581 /*
61582 ** Clean up the VM after execution.
61583 **
@@ -62372,24 +62419,39 @@
62372 sqlite3VdbeDelete(p);
62373 return rc;
62374 }
62375
62376 /*
62377 ** Call the destructor for each auxdata entry in pVdbeFunc for which
62378 ** the corresponding bit in mask is clear. Auxdata entries beyond 31
62379 ** are always destroyed. To destroy all auxdata entries, call this
62380 ** routine with mask==0.
 
 
 
 
 
 
 
 
 
 
62381 */
62382 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(VdbeFunc *pVdbeFunc, int mask){
62383 int i;
62384 for(i=0; i<pVdbeFunc->nAux; i++){
62385 struct AuxData *pAux = &pVdbeFunc->apAux[i];
62386 if( (i>31 || !(mask&(((u32)1)<<i))) && pAux->pAux ){
 
 
62387 if( pAux->xDelete ){
62388 pAux->xDelete(pAux->pAux);
62389 }
62390 pAux->pAux = 0;
 
 
 
62391 }
62392 }
62393 }
62394
62395 /*
@@ -63784,18 +63846,18 @@
63784 /*
63785 ** Return the auxilary data pointer, if any, for the iArg'th argument to
63786 ** the user-function defined by pCtx.
63787 */
63788 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
63789 VdbeFunc *pVdbeFunc;
63790
63791 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63792 pVdbeFunc = pCtx->pVdbeFunc;
63793 if( !pVdbeFunc || iArg>=pVdbeFunc->nAux || iArg<0 ){
63794 return 0;
63795 }
63796 return pVdbeFunc->apAux[iArg].pAux;
 
63797 }
63798
63799 /*
63800 ** Set the auxilary data pointer and delete function, for the iArg'th
63801 ** argument to the user-function defined by pCtx. Any previous value is
@@ -63805,33 +63867,30 @@
63805 sqlite3_context *pCtx,
63806 int iArg,
63807 void *pAux,
63808 void (*xDelete)(void*)
63809 ){
63810 struct AuxData *pAuxData;
63811 VdbeFunc *pVdbeFunc;
63812 if( iArg<0 ) goto failed;
63813
63814 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63815 pVdbeFunc = pCtx->pVdbeFunc;
63816 if( !pVdbeFunc || pVdbeFunc->nAux<=iArg ){
63817 int nAux = (pVdbeFunc ? pVdbeFunc->nAux : 0);
63818 int nMalloc = sizeof(VdbeFunc) + sizeof(struct AuxData)*iArg;
63819 pVdbeFunc = sqlite3DbRealloc(pCtx->s.db, pVdbeFunc, nMalloc);
63820 if( !pVdbeFunc ){
63821 goto failed;
63822 }
63823 pCtx->pVdbeFunc = pVdbeFunc;
63824 memset(&pVdbeFunc->apAux[nAux], 0, sizeof(struct AuxData)*(iArg+1-nAux));
63825 pVdbeFunc->nAux = iArg+1;
63826 pVdbeFunc->pFunc = pCtx->pFunc;
63827 }
63828
63829 pAuxData = &pVdbeFunc->apAux[iArg];
63830 if( pAuxData->pAux && pAuxData->xDelete ){
63831 pAuxData->xDelete(pAuxData->pAux);
63832 }
 
63833 pAuxData->pAux = pAux;
63834 pAuxData->xDelete = xDelete;
63835 return;
63836
63837 failed:
@@ -65439,11 +65498,11 @@
65439 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
65440 u8 encoding = ENC(db); /* The database encoding */
65441 int iCompare = 0; /* Result of last OP_Compare operation */
65442 unsigned nVmStep = 0; /* Number of virtual machine steps */
65443 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65444 unsigned nProgressOps = 0; /* nVmStep at last progress callback. */
65445 #endif
65446 Mem *aMem = p->aMem; /* Copy of p->aMem */
65447 Mem *pIn1 = 0; /* 1st input operand */
65448 Mem *pIn2 = 0; /* 2nd input operand */
65449 Mem *pIn3 = 0; /* 3rd input operand */
@@ -65898,10 +65957,21 @@
65898 assert( p->explain==0 );
65899 p->pResultSet = 0;
65900 db->busyHandler.nBusy = 0;
65901 CHECK_FOR_INTERRUPT;
65902 sqlite3VdbeIOTraceSql(p);
 
 
 
 
 
 
 
 
 
 
 
65903 #ifdef SQLITE_DEBUG
65904 sqlite3BeginBenignMalloc();
65905 if( p->pc==0 && (p->db->flags & SQLITE_VdbeListing)!=0 ){
65906 int i;
65907 printf("VDBE Program Listing:\n");
@@ -66058,18 +66128,20 @@
66058 ** of VDBE ops have been executed (either since this invocation of
66059 ** sqlite3VdbeExec() or since last time the progress callback was called).
66060 ** If the progress callback returns non-zero, exit the virtual machine with
66061 ** a return code SQLITE_ABORT.
66062 */
66063 if( db->xProgress!=0 && (nVmStep - nProgressOps)>=db->nProgressOps ){
66064 int prc;
66065 prc = db->xProgress(db->pProgressArg);
66066 if( prc!=0 ){
66067 rc = SQLITE_INTERRUPT;
66068 goto vdbe_error_halt;
66069 }
66070 nProgressOps = nVmStep;
 
 
66071 }
66072 #endif
66073
66074 break;
66075 }
@@ -66751,23 +66823,18 @@
66751 Deephemeralize(u.ai.pArg);
66752 sqlite3VdbeMemStoreType(u.ai.pArg);
66753 REGISTER_TRACE(pOp->p2+u.ai.i, u.ai.pArg);
66754 }
66755
66756 assert( pOp->p4type==P4_FUNCDEF || pOp->p4type==P4_VDBEFUNC );
66757 if( pOp->p4type==P4_FUNCDEF ){
66758 u.ai.ctx.pFunc = pOp->p4.pFunc;
66759 u.ai.ctx.pVdbeFunc = 0;
66760 }else{
66761 u.ai.ctx.pVdbeFunc = (VdbeFunc*)pOp->p4.pVdbeFunc;
66762 u.ai.ctx.pFunc = u.ai.ctx.pVdbeFunc->pFunc;
66763 }
66764
66765 u.ai.ctx.s.flags = MEM_Null;
66766 u.ai.ctx.s.db = db;
66767 u.ai.ctx.s.xDel = 0;
66768 u.ai.ctx.s.zMalloc = 0;
 
 
66769
66770 /* The output cell may already have a buffer allocated. Move
66771 ** the pointer to u.ai.ctx.s so in case the user-function can use
66772 ** the already allocated buffer instead of allocating a new one.
66773 */
@@ -66786,15 +66853,11 @@
66786 lastRowid = db->lastRowid;
66787
66788 /* If any auxiliary data functions have been called by this user function,
66789 ** immediately call the destructor for any non-static values.
66790 */
66791 if( u.ai.ctx.pVdbeFunc ){
66792 sqlite3VdbeDeleteAuxData(u.ai.ctx.pVdbeFunc, pOp->p1);
66793 pOp->p4.pVdbeFunc = u.ai.ctx.pVdbeFunc;
66794 pOp->p4type = P4_VDBEFUNC;
66795 }
66796
66797 if( db->mallocFailed ){
66798 /* Even though a malloc() has failed, the implementation of the
66799 ** user function may have called an sqlite3_result_XXX() function
66800 ** to return a value. The following call releases any resources
@@ -117728,11 +117791,11 @@
117728 db->autoCommit = 1;
117729 db->nextAutovac = -1;
117730 db->szMmap = sqlite3GlobalConfig.szMmap;
117731 db->nextPagesize = 0;
117732 db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger
117733 #if !defined(SQLITE_DEAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
117734 | SQLITE_AutoIndex
117735 #endif
117736 #if SQLITE_DEFAULT_FILE_FORMAT<4
117737 | SQLITE_LegacyFileFmt
117738 #endif
117739
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -670,11 +670,11 @@
670 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
671 ** [sqlite_version()] and [sqlite_source_id()].
672 */
673 #define SQLITE_VERSION "3.8.0"
674 #define SQLITE_VERSION_NUMBER 3008000
675 #define SQLITE_SOURCE_ID "2013-07-25 17:07:03 8bcbb33fd0a970e16a920e1d35571836dbb9ba50"
676
677 /*
678 ** CAPI3REF: Run-Time Library Version Numbers
679 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
680 **
@@ -3122,11 +3122,12 @@
3122 ** interface is to keep a GUI updated during a large query.
3123 **
3124 ** ^The parameter P is passed through as the only parameter to the
3125 ** callback function X. ^The parameter N is the approximate number of
3126 ** [virtual machine instructions] that are evaluated between successive
3127 ** invocations of the callback X. ^If N is less than one then the progress
3128 ** handler is disabled.
3129 **
3130 ** ^Only a single progress handler may be defined at one time per
3131 ** [database connection]; setting a new progress handler cancels the
3132 ** old one. ^Setting parameter X to NULL disables the progress handler.
3133 ** ^The progress handler is also disabled by setting N to a value less
@@ -4742,50 +4743,49 @@
4743 SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
4744
4745 /*
4746 ** CAPI3REF: Function Auxiliary Data
4747 **
4748 ** These functions may be used by (non-aggregate) SQL functions to
4749 ** associate metadata with argument values. If the same value is passed to
4750 ** multiple invocations of the same SQL function during query execution, under
4751 ** some circumstances the associated metadata may be preserved. An example
4752 ** of where this might be useful is in a regular-expression matching
4753 ** function. The compiled version of the regular expression can be stored as
4754 ** metadata associated with the pattern string.
4755 ** Then as long as the pattern string remains the same,
4756 ** the compiled regular expression can be reused on multiple
4757 ** invocations of the same function.
4758 **
4759 ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
4760 ** associated by the sqlite3_set_auxdata() function with the Nth argument
4761 ** value to the application-defined function. ^If there is no metadata
4762 ** associated with the function argument, this sqlite3_get_auxdata() interface
4763 ** returns a NULL pointer.
 
4764 **
4765 ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
4766 ** argument of the application-defined function. ^Subsequent
4767 ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
4768 ** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or
4769 ** NULL if the metadata has been discarded.
4770 ** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL,
4771 ** SQLite will invoke the destructor function X with parameter P exactly
4772 ** once, when the metadata is discarded.
4773 ** SQLite is free to discard the metadata at any time, including: <ul>
4774 ** <li> when the corresponding function parameter changes, or
4775 ** <li> when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
4776 ** SQL statement, or
4777 ** <li> when sqlite3_set_auxdata() is invoked again on the same parameter, or
4778 ** <li> during the original sqlite3_set_auxdata() call when a memory
4779 ** allocation error occurs. </ul>)^
4780 **
4781 ** Note the last bullet in particular. The destructor X in
4782 ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
4783 ** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata()
 
 
 
4784 ** should be called near the end of the function implementation and the
4785 ** function implementation should not make any use of P after
4786 ** sqlite3_set_auxdata() has been called.
4787 **
4788 ** ^(In practice, metadata is preserved between function calls for
4789 ** function parameters that are compile-time constants, including literal
4790 ** values and [parameters] and expressions composed from the same.)^
4791 **
@@ -8824,11 +8824,10 @@
8824
8825 /*
8826 ** The names of the following types declared in vdbeInt.h are required
8827 ** for the VdbeOp definition.
8828 */
 
8829 typedef struct Mem Mem;
8830 typedef struct SubProgram SubProgram;
8831
8832 /*
8833 ** A single instruction of the virtual machine has an opcode
@@ -8848,11 +8847,10 @@
8847 void *p; /* Generic pointer */
8848 char *z; /* Pointer to data for string (char array) types */
8849 i64 *pI64; /* Used when p4type is P4_INT64 */
8850 double *pReal; /* Used when p4type is P4_REAL */
8851 FuncDef *pFunc; /* Used when p4type is P4_FUNCDEF */
 
8852 CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */
8853 Mem *pMem; /* Used when p4type is P4_MEM */
8854 VTable *pVtab; /* Used when p4type is P4_VTAB */
8855 KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */
8856 int *ai; /* Used when p4type is P4_INTARRAY */
@@ -8902,11 +8900,10 @@
8900 #define P4_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */
8901 #define P4_STATIC (-2) /* Pointer to a static string */
8902 #define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */
8903 #define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */
8904 #define P4_KEYINFO (-6) /* P4 is a pointer to a KeyInfo structure */
 
8905 #define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */
8906 #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */
8907 #define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */
8908 #define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */
8909 #define P4_REAL (-12) /* P4 is a 64-bit floating point value */
@@ -13257,10 +13254,13 @@
13254 typedef struct VdbeSorter VdbeSorter;
13255
13256 /* Opaque type used by the explainer */
13257 typedef struct Explain Explain;
13258
13259 /* Elements of the linked list at Vdbe.pAuxData */
13260 typedef struct AuxData AuxData;
13261
13262 /*
13263 ** A cursor is a pointer into a single BTree within a database file.
13264 ** The cursor can seek to a BTree entry with a particular key, or
13265 ** loop over all entries of the Btree. You can also insert new BTree
13266 ** entries or retrieve the key or data from the entry that the cursor
@@ -13443,27 +13443,23 @@
13443 */
13444 #ifdef SQLITE_DEBUG
13445 #define memIsValid(M) ((M)->flags & MEM_Invalid)==0
13446 #endif
13447
13448 /*
13449 ** Each auxilliary data pointer stored by a user defined function
13450 ** implementation calling sqlite3_set_auxdata() is stored in an instance
13451 ** of this structure. All such structures associated with a single VM
13452 ** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed
13453 ** when the VM is halted (if not before).
 
 
 
13454 */
13455 struct AuxData {
13456 int iOp; /* Instruction number of OP_Function opcode */
13457 int iArg; /* Index of function argument. */
13458 void *pAux; /* Aux data pointer */
13459 void (*xDelete)(void *); /* Destructor for the aux data */
13460 AuxData *pNext; /* Next element in list */
 
13461 };
13462
13463 /*
13464 ** The "context" argument for a installable function. A pointer to an
13465 ** instance of this structure is the first argument to the routines used
@@ -13477,16 +13473,17 @@
13473 ** This structure is defined inside of vdbeInt.h because it uses substructures
13474 ** (Mem) which are only defined there.
13475 */
13476 struct sqlite3_context {
13477 FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */
 
13478 Mem s; /* The return value is stored here */
13479 Mem *pMem; /* Memory cell used to store aggregate context */
13480 CollSeq *pColl; /* Collating sequence */
13481 int isError; /* Error code returned by the function. */
13482 int skipFlag; /* Skip skip accumulator loading if true */
13483 int iOp; /* Instruction number of OP_Function */
13484 Vdbe *pVdbe; /* The VM that owns this context */
13485 };
13486
13487 /*
13488 ** An Explain object accumulates indented output which is helpful
13489 ** in describing recursive data structures.
@@ -13581,10 +13578,11 @@
13578 int nFrame; /* Number of frames in pFrame list */
13579 u32 expmask; /* Binding to these vars invalidates VM */
13580 SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
13581 int nOnceFlag; /* Size of array aOnceFlag[] */
13582 u8 *aOnceFlag; /* Flags for OP_Once */
13583 AuxData *pAuxData; /* Linked list of auxdata allocations */
13584 };
13585
13586 /*
13587 ** The following are allowed values for Vdbe.magic
13588 */
@@ -13604,11 +13602,11 @@
13602 #endif
13603 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
13604 SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
13605 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int);
13606 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
13607 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
13608
13609 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
13610 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
13611 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *);
13612 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
@@ -28376,10 +28374,14 @@
28374 */
28375 static const char *unixTempFileDir(void){
28376 static const char *azDirs[] = {
28377 0,
28378 0,
28379 #ifdef __CYGWIN__
28380 0,
28381 0,
28382 #endif
28383 "/var/tmp",
28384 "/usr/tmp",
28385 "/tmp",
28386 0 /* List terminator */
28387 };
@@ -28387,10 +28389,14 @@
28389 struct stat buf;
28390 const char *zDir = 0;
28391
28392 azDirs[0] = sqlite3_temp_directory;
28393 if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
28394 #ifdef __CYGWIN__
28395 if( !azDirs[2] ) azDirs[2] = getenv("TMP");
28396 if( !azDirs[3] ) azDirs[3] = getenv("TEMP");
28397 #endif
28398 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
28399 if( zDir==0 ) continue;
28400 if( osStat(zDir, &buf) ) continue;
28401 if( !S_ISDIR(buf.st_mode) ) continue;
28402 if( osAccess(zDir, 07) ) continue;
@@ -30735,11 +30741,11 @@
30741
30742 /*
30743 ** Are most of the Win32 Unicode APIs available (i.e. with certain exceptions
30744 ** based on the sub-platform)?
30745 */
30746 #if SQLITE_OS_WINCE || SQLITE_OS_WINNT || SQLITE_OS_WINRT || defined(__CYGWIN__)
30747 # define SQLITE_WIN32_HAS_WIDE
30748 #endif
30749
30750 /*
30751 ** Do we need to manually define the Win32 file mapping APIs for use with WAL
@@ -34556,10 +34562,12 @@
34562 #endif
34563 /* caller will handle out of memory */
34564 return zConverted;
34565 }
34566
34567 static int winIsDir(const void *zConverted);
34568
34569 /*
34570 ** Create a temporary file name in zBuf. zBuf must be big enough to
34571 ** hold at pVfs->mxPathname characters.
34572 */
34573 static int getTempname(int nBuf, char *zBuf){
@@ -34580,11 +34588,53 @@
34588 memset(zTempPath, 0, MAX_PATH+2);
34589
34590 if( sqlite3_temp_directory ){
34591 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
34592 }
34593 #if defined(__CYGWIN__)
34594 static const char *azDirs[] = {
34595 0,
34596 0,
34597 0,
34598 0,
34599 "/var/tmp",
34600 "/usr/tmp",
34601 "/tmp",
34602 0
34603 };
34604 const char *zDir = 0;
34605 char *zConverted;
34606
34607 azDirs[0] = sqlite3_temp_directory;
34608 if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
34609 if( !azDirs[2] ) azDirs[2] = getenv("TMP");
34610 if( !azDirs[3] ) azDirs[3] = getenv("TEMP");
34611 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
34612 if( zDir==0 || zDir[0]) continue;
34613 if( zDir[1]!=':' ){
34614 WCHAR zWidePath[MAX_PATH];
34615 cygwin_conv_path(CCP_POSIX_TO_WIN_W, zDir, zWidePath, MAX_PATH);
34616 zDir = unicodeToUtf8(zWidePath);
34617 if( zDir==0 ){
34618 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
34619 return SQLITE_IOERR_NOMEM;
34620 }
34621 }
34622 /* Convert the filename to the system encoding. */
34623 zConverted = convertUtf8Filename(zDir);
34624 if( zConverted==0 ){
34625 OSTRACE(("TEMP-FILENAME, rc=SQLITE_IOERR_NOMEM"));
34626 return SQLITE_IOERR_NOMEM;
34627 }
34628 if( winIsDir(zConverted) ){
34629 sqlite3_free(zConverted);
34630 break;
34631 }
34632 sqlite3_free(zConverted);
34633 }
34634 sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zDir);
34635 #elif !SQLITE_OS_WINRT
34636 else if( isNT() ){
34637 char *zMulti;
34638 WCHAR zWidePath[MAX_PATH];
34639 osGetTempPathW(MAX_PATH-30, zWidePath);
34640 zMulti = unicodeToUtf8(zWidePath);
@@ -60538,17 +60588,10 @@
60588 }
60589 case P4_MPRINTF: {
60590 if( db->pnBytesFreed==0 ) sqlite3_free(p4);
60591 break;
60592 }
 
 
 
 
 
 
 
60593 case P4_FUNCDEF: {
60594 freeEphemeralFunction(db, (FuncDef*)p4);
60595 break;
60596 }
60597 case P4_MEM: {
@@ -61574,10 +61617,14 @@
61617 while( p->pDelFrame ){
61618 VdbeFrame *pDel = p->pDelFrame;
61619 p->pDelFrame = pDel->pParent;
61620 sqlite3VdbeFrameDelete(pDel);
61621 }
61622
61623 /* Delete any auxdata allocations made by the VM */
61624 sqlite3VdbeDeleteAuxData(p, -1, 0);
61625 assert( p->pAuxData==0 );
61626 }
61627
61628 /*
61629 ** Clean up the VM after execution.
61630 **
@@ -62372,24 +62419,39 @@
62419 sqlite3VdbeDelete(p);
62420 return rc;
62421 }
62422
62423 /*
62424 ** If parameter iOp is less than zero, then invoke the destructor for
62425 ** all auxiliary data pointers currently cached by the VM passed as
62426 ** the first argument.
62427 **
62428 ** Or, if iOp is greater than or equal to zero, then the destructor is
62429 ** only invoked for those auxiliary data pointers created by the user
62430 ** function invoked by the OP_Function opcode at instruction iOp of
62431 ** VM pVdbe, and only then if:
62432 **
62433 ** * the associated function parameter is the 32nd or later (counting
62434 ** from left to right), or
62435 **
62436 ** * the corresponding bit in argument mask is clear (where the first
62437 ** function parameter corrsponds to bit 0 etc.).
62438 */
62439 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe *pVdbe, int iOp, int mask){
62440 AuxData **pp = &pVdbe->pAuxData;
62441 while( *pp ){
62442 AuxData *pAux = *pp;
62443 if( (iOp<0)
62444 || (pAux->iOp==iOp && (pAux->iArg>31 || !(mask & ((u32)1<<pAux->iArg))))
62445 ){
62446 if( pAux->xDelete ){
62447 pAux->xDelete(pAux->pAux);
62448 }
62449 *pp = pAux->pNext;
62450 sqlite3DbFree(pVdbe->db, pAux);
62451 }else{
62452 pp= &pAux->pNext;
62453 }
62454 }
62455 }
62456
62457 /*
@@ -63784,18 +63846,18 @@
63846 /*
63847 ** Return the auxilary data pointer, if any, for the iArg'th argument to
63848 ** the user-function defined by pCtx.
63849 */
63850 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
63851 AuxData *pAuxData;
63852
63853 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63854 for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
63855 if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
 
63856 }
63857
63858 return (pAuxData ? pAuxData->pAux : 0);
63859 }
63860
63861 /*
63862 ** Set the auxilary data pointer and delete function, for the iArg'th
63863 ** argument to the user-function defined by pCtx. Any previous value is
@@ -63805,33 +63867,30 @@
63867 sqlite3_context *pCtx,
63868 int iArg,
63869 void *pAux,
63870 void (*xDelete)(void*)
63871 ){
63872 AuxData *pAuxData;
63873 Vdbe *pVdbe = pCtx->pVdbe;
 
63874
63875 assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
63876 if( iArg<0 ) goto failed;
63877
63878 for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
63879 if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
63880 }
63881 if( pAuxData==0 ){
63882 pAuxData = sqlite3DbMallocZero(pVdbe->db, sizeof(AuxData));
63883 if( !pAuxData ) goto failed;
63884 pAuxData->iOp = pCtx->iOp;
63885 pAuxData->iArg = iArg;
63886 pAuxData->pNext = pVdbe->pAuxData;
63887 pVdbe->pAuxData = pAuxData;
63888 }else if( pAuxData->xDelete ){
 
 
 
63889 pAuxData->xDelete(pAuxData->pAux);
63890 }
63891
63892 pAuxData->pAux = pAux;
63893 pAuxData->xDelete = xDelete;
63894 return;
63895
63896 failed:
@@ -65439,11 +65498,11 @@
65498 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
65499 u8 encoding = ENC(db); /* The database encoding */
65500 int iCompare = 0; /* Result of last OP_Compare operation */
65501 unsigned nVmStep = 0; /* Number of virtual machine steps */
65502 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65503 unsigned nProgressLimit; /* Invoke xProgress() when nVmStep reaches this */
65504 #endif
65505 Mem *aMem = p->aMem; /* Copy of p->aMem */
65506 Mem *pIn1 = 0; /* 1st input operand */
65507 Mem *pIn2 = 0; /* 2nd input operand */
65508 Mem *pIn3 = 0; /* 3rd input operand */
@@ -65898,10 +65957,21 @@
65957 assert( p->explain==0 );
65958 p->pResultSet = 0;
65959 db->busyHandler.nBusy = 0;
65960 CHECK_FOR_INTERRUPT;
65961 sqlite3VdbeIOTraceSql(p);
65962 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65963 if( db->xProgress ){
65964 assert( 0 < db->nProgressOps );
65965 nProgressLimit = (unsigned)p->aCounter[SQLITE_STMTSTATUS_VM_STEP-1];
65966 if( nProgressLimit==0 ){
65967 nProgressLimit = db->nProgressOps;
65968 }else{
65969 nProgressLimit %= (unsigned)db->nProgressOps;
65970 }
65971 }
65972 #endif
65973 #ifdef SQLITE_DEBUG
65974 sqlite3BeginBenignMalloc();
65975 if( p->pc==0 && (p->db->flags & SQLITE_VdbeListing)!=0 ){
65976 int i;
65977 printf("VDBE Program Listing:\n");
@@ -66058,18 +66128,20 @@
66128 ** of VDBE ops have been executed (either since this invocation of
66129 ** sqlite3VdbeExec() or since last time the progress callback was called).
66130 ** If the progress callback returns non-zero, exit the virtual machine with
66131 ** a return code SQLITE_ABORT.
66132 */
66133 if( db->xProgress!=0 && nVmStep>=nProgressLimit ){
66134 int prc;
66135 prc = db->xProgress(db->pProgressArg);
66136 if( prc!=0 ){
66137 rc = SQLITE_INTERRUPT;
66138 goto vdbe_error_halt;
66139 }
66140 if( db->xProgress!=0 ){
66141 nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps);
66142 }
66143 }
66144 #endif
66145
66146 break;
66147 }
@@ -66751,23 +66823,18 @@
66823 Deephemeralize(u.ai.pArg);
66824 sqlite3VdbeMemStoreType(u.ai.pArg);
66825 REGISTER_TRACE(pOp->p2+u.ai.i, u.ai.pArg);
66826 }
66827
66828 assert( pOp->p4type==P4_FUNCDEF );
66829 u.ai.ctx.pFunc = pOp->p4.pFunc;
 
 
 
 
 
 
 
66830 u.ai.ctx.s.flags = MEM_Null;
66831 u.ai.ctx.s.db = db;
66832 u.ai.ctx.s.xDel = 0;
66833 u.ai.ctx.s.zMalloc = 0;
66834 u.ai.ctx.iOp = pc;
66835 u.ai.ctx.pVdbe = p;
66836
66837 /* The output cell may already have a buffer allocated. Move
66838 ** the pointer to u.ai.ctx.s so in case the user-function can use
66839 ** the already allocated buffer instead of allocating a new one.
66840 */
@@ -66786,15 +66853,11 @@
66853 lastRowid = db->lastRowid;
66854
66855 /* If any auxiliary data functions have been called by this user function,
66856 ** immediately call the destructor for any non-static values.
66857 */
66858 sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
 
 
 
 
66859
66860 if( db->mallocFailed ){
66861 /* Even though a malloc() has failed, the implementation of the
66862 ** user function may have called an sqlite3_result_XXX() function
66863 ** to return a value. The following call releases any resources
@@ -117728,11 +117791,11 @@
117791 db->autoCommit = 1;
117792 db->nextAutovac = -1;
117793 db->szMmap = sqlite3GlobalConfig.szMmap;
117794 db->nextPagesize = 0;
117795 db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger
117796 #if !defined(SQLITE_DEFAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
117797 | SQLITE_AutoIndex
117798 #endif
117799 #if SQLITE_DEFAULT_FILE_FORMAT<4
117800 | SQLITE_LegacyFileFmt
117801 #endif
117802
+31 -31
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.8.0"
111111
#define SQLITE_VERSION_NUMBER 3008000
112
-#define SQLITE_SOURCE_ID "2013-07-18 14:50:56 5dcffa671f592ae9355628afa439ae9a2d26f0cd"
112
+#define SQLITE_SOURCE_ID "2013-07-25 17:07:03 8bcbb33fd0a970e16a920e1d35571836dbb9ba50"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -2559,11 +2559,12 @@
25592559
** interface is to keep a GUI updated during a large query.
25602560
**
25612561
** ^The parameter P is passed through as the only parameter to the
25622562
** callback function X. ^The parameter N is the approximate number of
25632563
** [virtual machine instructions] that are evaluated between successive
2564
-** invocations of the callback X.
2564
+** invocations of the callback X. ^If N is less than one then the progress
2565
+** handler is disabled.
25652566
**
25662567
** ^Only a single progress handler may be defined at one time per
25672568
** [database connection]; setting a new progress handler cancels the
25682569
** old one. ^Setting parameter X to NULL disables the progress handler.
25692570
** ^The progress handler is also disabled by setting N to a value less
@@ -4179,50 +4180,49 @@
41794180
SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
41804181
41814182
/*
41824183
** CAPI3REF: Function Auxiliary Data
41834184
**
4184
-** The following two functions may be used by scalar SQL functions to
4185
+** These functions may be used by (non-aggregate) SQL functions to
41854186
** associate metadata with argument values. If the same value is passed to
41864187
** multiple invocations of the same SQL function during query execution, under
4187
-** some circumstances the associated metadata may be preserved. This might
4188
-** be used, for example, in a regular-expression matching
4189
-** function. The compiled version of the regular expression is stored as
4190
-** metadata associated with the SQL value passed as the regular expression
4191
-** pattern. The compiled regular expression can be reused on multiple
4192
-** invocations of the same function so that the original pattern string
4193
-** does not need to be recompiled on each invocation.
4188
+** some circumstances the associated metadata may be preserved. An example
4189
+** of where this might be useful is in a regular-expression matching
4190
+** function. The compiled version of the regular expression can be stored as
4191
+** metadata associated with the pattern string.
4192
+** Then as long as the pattern string remains the same,
4193
+** the compiled regular expression can be reused on multiple
4194
+** invocations of the same function.
41944195
**
41954196
** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
41964197
** associated by the sqlite3_set_auxdata() function with the Nth argument
4197
-** value to the application-defined function. ^If no metadata has been ever
4198
-** been set for the Nth argument of the function, or if the corresponding
4199
-** function parameter has changed since the meta-data was set,
4200
-** then sqlite3_get_auxdata() returns a NULL pointer.
4198
+** value to the application-defined function. ^If there is no metadata
4199
+** associated with the function argument, this sqlite3_get_auxdata() interface
4200
+** returns a NULL pointer.
42014201
**
42024202
** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
42034203
** argument of the application-defined function. ^Subsequent
42044204
** calls to sqlite3_get_auxdata(C,N) return P from the most recent
4205
-** sqlite3_set_auxdata(C,N,P,X) call if the data has not been dropped, or
4206
-** NULL if the data has been dropped.
4207
-** ^(If it is not NULL, SQLite will invoke the destructor
4208
-** function X passed to sqlite3_set_auxdata(C,N,P,X) when <ul>
4209
-** <li> the corresponding function parameter changes,
4210
-** <li> [sqlite3_reset()] or [sqlite3_finalize()] is called for the
4211
-** SQL statement,
4212
-** <li> sqlite3_set_auxdata() is invoked again on the same parameter, or
4213
-** <li> a memory allocation error occurs. </ul>)^
4205
+** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or
4206
+** NULL if the metadata has been discarded.
4207
+** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL,
4208
+** SQLite will invoke the destructor function X with parameter P exactly
4209
+** once, when the metadata is discarded.
4210
+** SQLite is free to discard the metadata at any time, including: <ul>
4211
+** <li> when the corresponding function parameter changes, or
4212
+** <li> when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
4213
+** SQL statement, or
4214
+** <li> when sqlite3_set_auxdata() is invoked again on the same parameter, or
4215
+** <li> during the original sqlite3_set_auxdata() call when a memory
4216
+** allocation error occurs. </ul>)^
42144217
**
4215
-** SQLite is free to call the destructor and drop metadata on any
4216
-** parameter of any function at any time. ^The only guarantee is that
4217
-** the destructor will be called when the [prepared statement] is destroyed.
4218
-** Note in particular that the destructor X in the call to
4219
-** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before
4220
-** the sqlite3_set_auxdata() call even returns. Hence sqlite3_set_auxdata()
4218
+** Note the last bullet in particular. The destructor X in
4219
+** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
4220
+** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata()
42214221
** should be called near the end of the function implementation and the
4222
-** implementation should not make any use of P after sqlite3_set_auxdata()
4223
-** has been called.
4222
+** function implementation should not make any use of P after
4223
+** sqlite3_set_auxdata() has been called.
42244224
**
42254225
** ^(In practice, metadata is preserved between function calls for
42264226
** function parameters that are compile-time constants, including literal
42274227
** values and [parameters] and expressions composed from the same.)^
42284228
**
42294229
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.0"
111 #define SQLITE_VERSION_NUMBER 3008000
112 #define SQLITE_SOURCE_ID "2013-07-18 14:50:56 5dcffa671f592ae9355628afa439ae9a2d26f0cd"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -2559,11 +2559,12 @@
2559 ** interface is to keep a GUI updated during a large query.
2560 **
2561 ** ^The parameter P is passed through as the only parameter to the
2562 ** callback function X. ^The parameter N is the approximate number of
2563 ** [virtual machine instructions] that are evaluated between successive
2564 ** invocations of the callback X.
 
2565 **
2566 ** ^Only a single progress handler may be defined at one time per
2567 ** [database connection]; setting a new progress handler cancels the
2568 ** old one. ^Setting parameter X to NULL disables the progress handler.
2569 ** ^The progress handler is also disabled by setting N to a value less
@@ -4179,50 +4180,49 @@
4179 SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
4180
4181 /*
4182 ** CAPI3REF: Function Auxiliary Data
4183 **
4184 ** The following two functions may be used by scalar SQL functions to
4185 ** associate metadata with argument values. If the same value is passed to
4186 ** multiple invocations of the same SQL function during query execution, under
4187 ** some circumstances the associated metadata may be preserved. This might
4188 ** be used, for example, in a regular-expression matching
4189 ** function. The compiled version of the regular expression is stored as
4190 ** metadata associated with the SQL value passed as the regular expression
4191 ** pattern. The compiled regular expression can be reused on multiple
4192 ** invocations of the same function so that the original pattern string
4193 ** does not need to be recompiled on each invocation.
4194 **
4195 ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
4196 ** associated by the sqlite3_set_auxdata() function with the Nth argument
4197 ** value to the application-defined function. ^If no metadata has been ever
4198 ** been set for the Nth argument of the function, or if the corresponding
4199 ** function parameter has changed since the meta-data was set,
4200 ** then sqlite3_get_auxdata() returns a NULL pointer.
4201 **
4202 ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
4203 ** argument of the application-defined function. ^Subsequent
4204 ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
4205 ** sqlite3_set_auxdata(C,N,P,X) call if the data has not been dropped, or
4206 ** NULL if the data has been dropped.
4207 ** ^(If it is not NULL, SQLite will invoke the destructor
4208 ** function X passed to sqlite3_set_auxdata(C,N,P,X) when <ul>
4209 ** <li> the corresponding function parameter changes,
4210 ** <li> [sqlite3_reset()] or [sqlite3_finalize()] is called for the
4211 ** SQL statement,
4212 ** <li> sqlite3_set_auxdata() is invoked again on the same parameter, or
4213 ** <li> a memory allocation error occurs. </ul>)^
 
 
 
4214 **
4215 ** SQLite is free to call the destructor and drop metadata on any
4216 ** parameter of any function at any time. ^The only guarantee is that
4217 ** the destructor will be called when the [prepared statement] is destroyed.
4218 ** Note in particular that the destructor X in the call to
4219 ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before
4220 ** the sqlite3_set_auxdata() call even returns. Hence sqlite3_set_auxdata()
4221 ** should be called near the end of the function implementation and the
4222 ** implementation should not make any use of P after sqlite3_set_auxdata()
4223 ** has been called.
4224 **
4225 ** ^(In practice, metadata is preserved between function calls for
4226 ** function parameters that are compile-time constants, including literal
4227 ** values and [parameters] and expressions composed from the same.)^
4228 **
4229
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.0"
111 #define SQLITE_VERSION_NUMBER 3008000
112 #define SQLITE_SOURCE_ID "2013-07-25 17:07:03 8bcbb33fd0a970e16a920e1d35571836dbb9ba50"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -2559,11 +2559,12 @@
2559 ** interface is to keep a GUI updated during a large query.
2560 **
2561 ** ^The parameter P is passed through as the only parameter to the
2562 ** callback function X. ^The parameter N is the approximate number of
2563 ** [virtual machine instructions] that are evaluated between successive
2564 ** invocations of the callback X. ^If N is less than one then the progress
2565 ** handler is disabled.
2566 **
2567 ** ^Only a single progress handler may be defined at one time per
2568 ** [database connection]; setting a new progress handler cancels the
2569 ** old one. ^Setting parameter X to NULL disables the progress handler.
2570 ** ^The progress handler is also disabled by setting N to a value less
@@ -4179,50 +4180,49 @@
4180 SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
4181
4182 /*
4183 ** CAPI3REF: Function Auxiliary Data
4184 **
4185 ** These functions may be used by (non-aggregate) SQL functions to
4186 ** associate metadata with argument values. If the same value is passed to
4187 ** multiple invocations of the same SQL function during query execution, under
4188 ** some circumstances the associated metadata may be preserved. An example
4189 ** of where this might be useful is in a regular-expression matching
4190 ** function. The compiled version of the regular expression can be stored as
4191 ** metadata associated with the pattern string.
4192 ** Then as long as the pattern string remains the same,
4193 ** the compiled regular expression can be reused on multiple
4194 ** invocations of the same function.
4195 **
4196 ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
4197 ** associated by the sqlite3_set_auxdata() function with the Nth argument
4198 ** value to the application-defined function. ^If there is no metadata
4199 ** associated with the function argument, this sqlite3_get_auxdata() interface
4200 ** returns a NULL pointer.
 
4201 **
4202 ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
4203 ** argument of the application-defined function. ^Subsequent
4204 ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
4205 ** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or
4206 ** NULL if the metadata has been discarded.
4207 ** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL,
4208 ** SQLite will invoke the destructor function X with parameter P exactly
4209 ** once, when the metadata is discarded.
4210 ** SQLite is free to discard the metadata at any time, including: <ul>
4211 ** <li> when the corresponding function parameter changes, or
4212 ** <li> when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
4213 ** SQL statement, or
4214 ** <li> when sqlite3_set_auxdata() is invoked again on the same parameter, or
4215 ** <li> during the original sqlite3_set_auxdata() call when a memory
4216 ** allocation error occurs. </ul>)^
4217 **
4218 ** Note the last bullet in particular. The destructor X in
4219 ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
4220 ** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata()
 
 
 
4221 ** should be called near the end of the function implementation and the
4222 ** function implementation should not make any use of P after
4223 ** sqlite3_set_auxdata() has been called.
4224 **
4225 ** ^(In practice, metadata is preserved between function calls for
4226 ** function parameters that are compile-time constants, including literal
4227 ** values and [parameters] and expressions composed from the same.)^
4228 **
4229
+31 -31
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.8.0"
111111
#define SQLITE_VERSION_NUMBER 3008000
112
-#define SQLITE_SOURCE_ID "2013-07-18 14:50:56 5dcffa671f592ae9355628afa439ae9a2d26f0cd"
112
+#define SQLITE_SOURCE_ID "2013-07-25 17:07:03 8bcbb33fd0a970e16a920e1d35571836dbb9ba50"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -2559,11 +2559,12 @@
25592559
** interface is to keep a GUI updated during a large query.
25602560
**
25612561
** ^The parameter P is passed through as the only parameter to the
25622562
** callback function X. ^The parameter N is the approximate number of
25632563
** [virtual machine instructions] that are evaluated between successive
2564
-** invocations of the callback X.
2564
+** invocations of the callback X. ^If N is less than one then the progress
2565
+** handler is disabled.
25652566
**
25662567
** ^Only a single progress handler may be defined at one time per
25672568
** [database connection]; setting a new progress handler cancels the
25682569
** old one. ^Setting parameter X to NULL disables the progress handler.
25692570
** ^The progress handler is also disabled by setting N to a value less
@@ -4179,50 +4180,49 @@
41794180
SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
41804181
41814182
/*
41824183
** CAPI3REF: Function Auxiliary Data
41834184
**
4184
-** The following two functions may be used by scalar SQL functions to
4185
+** These functions may be used by (non-aggregate) SQL functions to
41854186
** associate metadata with argument values. If the same value is passed to
41864187
** multiple invocations of the same SQL function during query execution, under
4187
-** some circumstances the associated metadata may be preserved. This might
4188
-** be used, for example, in a regular-expression matching
4189
-** function. The compiled version of the regular expression is stored as
4190
-** metadata associated with the SQL value passed as the regular expression
4191
-** pattern. The compiled regular expression can be reused on multiple
4192
-** invocations of the same function so that the original pattern string
4193
-** does not need to be recompiled on each invocation.
4188
+** some circumstances the associated metadata may be preserved. An example
4189
+** of where this might be useful is in a regular-expression matching
4190
+** function. The compiled version of the regular expression can be stored as
4191
+** metadata associated with the pattern string.
4192
+** Then as long as the pattern string remains the same,
4193
+** the compiled regular expression can be reused on multiple
4194
+** invocations of the same function.
41944195
**
41954196
** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
41964197
** associated by the sqlite3_set_auxdata() function with the Nth argument
4197
-** value to the application-defined function. ^If no metadata has been ever
4198
-** been set for the Nth argument of the function, or if the corresponding
4199
-** function parameter has changed since the meta-data was set,
4200
-** then sqlite3_get_auxdata() returns a NULL pointer.
4198
+** value to the application-defined function. ^If there is no metadata
4199
+** associated with the function argument, this sqlite3_get_auxdata() interface
4200
+** returns a NULL pointer.
42014201
**
42024202
** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
42034203
** argument of the application-defined function. ^Subsequent
42044204
** calls to sqlite3_get_auxdata(C,N) return P from the most recent
4205
-** sqlite3_set_auxdata(C,N,P,X) call if the data has not been dropped, or
4206
-** NULL if the data has been dropped.
4207
-** ^(If it is not NULL, SQLite will invoke the destructor
4208
-** function X passed to sqlite3_set_auxdata(C,N,P,X) when <ul>
4209
-** <li> the corresponding function parameter changes,
4210
-** <li> [sqlite3_reset()] or [sqlite3_finalize()] is called for the
4211
-** SQL statement,
4212
-** <li> sqlite3_set_auxdata() is invoked again on the same parameter, or
4213
-** <li> a memory allocation error occurs. </ul>)^
4205
+** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or
4206
+** NULL if the metadata has been discarded.
4207
+** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL,
4208
+** SQLite will invoke the destructor function X with parameter P exactly
4209
+** once, when the metadata is discarded.
4210
+** SQLite is free to discard the metadata at any time, including: <ul>
4211
+** <li> when the corresponding function parameter changes, or
4212
+** <li> when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
4213
+** SQL statement, or
4214
+** <li> when sqlite3_set_auxdata() is invoked again on the same parameter, or
4215
+** <li> during the original sqlite3_set_auxdata() call when a memory
4216
+** allocation error occurs. </ul>)^
42144217
**
4215
-** SQLite is free to call the destructor and drop metadata on any
4216
-** parameter of any function at any time. ^The only guarantee is that
4217
-** the destructor will be called when the [prepared statement] is destroyed.
4218
-** Note in particular that the destructor X in the call to
4219
-** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before
4220
-** the sqlite3_set_auxdata() call even returns. Hence sqlite3_set_auxdata()
4218
+** Note the last bullet in particular. The destructor X in
4219
+** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
4220
+** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata()
42214221
** should be called near the end of the function implementation and the
4222
-** implementation should not make any use of P after sqlite3_set_auxdata()
4223
-** has been called.
4222
+** function implementation should not make any use of P after
4223
+** sqlite3_set_auxdata() has been called.
42244224
**
42254225
** ^(In practice, metadata is preserved between function calls for
42264226
** function parameters that are compile-time constants, including literal
42274227
** values and [parameters] and expressions composed from the same.)^
42284228
**
42294229
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.0"
111 #define SQLITE_VERSION_NUMBER 3008000
112 #define SQLITE_SOURCE_ID "2013-07-18 14:50:56 5dcffa671f592ae9355628afa439ae9a2d26f0cd"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -2559,11 +2559,12 @@
2559 ** interface is to keep a GUI updated during a large query.
2560 **
2561 ** ^The parameter P is passed through as the only parameter to the
2562 ** callback function X. ^The parameter N is the approximate number of
2563 ** [virtual machine instructions] that are evaluated between successive
2564 ** invocations of the callback X.
 
2565 **
2566 ** ^Only a single progress handler may be defined at one time per
2567 ** [database connection]; setting a new progress handler cancels the
2568 ** old one. ^Setting parameter X to NULL disables the progress handler.
2569 ** ^The progress handler is also disabled by setting N to a value less
@@ -4179,50 +4180,49 @@
4179 SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
4180
4181 /*
4182 ** CAPI3REF: Function Auxiliary Data
4183 **
4184 ** The following two functions may be used by scalar SQL functions to
4185 ** associate metadata with argument values. If the same value is passed to
4186 ** multiple invocations of the same SQL function during query execution, under
4187 ** some circumstances the associated metadata may be preserved. This might
4188 ** be used, for example, in a regular-expression matching
4189 ** function. The compiled version of the regular expression is stored as
4190 ** metadata associated with the SQL value passed as the regular expression
4191 ** pattern. The compiled regular expression can be reused on multiple
4192 ** invocations of the same function so that the original pattern string
4193 ** does not need to be recompiled on each invocation.
4194 **
4195 ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
4196 ** associated by the sqlite3_set_auxdata() function with the Nth argument
4197 ** value to the application-defined function. ^If no metadata has been ever
4198 ** been set for the Nth argument of the function, or if the corresponding
4199 ** function parameter has changed since the meta-data was set,
4200 ** then sqlite3_get_auxdata() returns a NULL pointer.
4201 **
4202 ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
4203 ** argument of the application-defined function. ^Subsequent
4204 ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
4205 ** sqlite3_set_auxdata(C,N,P,X) call if the data has not been dropped, or
4206 ** NULL if the data has been dropped.
4207 ** ^(If it is not NULL, SQLite will invoke the destructor
4208 ** function X passed to sqlite3_set_auxdata(C,N,P,X) when <ul>
4209 ** <li> the corresponding function parameter changes,
4210 ** <li> [sqlite3_reset()] or [sqlite3_finalize()] is called for the
4211 ** SQL statement,
4212 ** <li> sqlite3_set_auxdata() is invoked again on the same parameter, or
4213 ** <li> a memory allocation error occurs. </ul>)^
 
 
 
4214 **
4215 ** SQLite is free to call the destructor and drop metadata on any
4216 ** parameter of any function at any time. ^The only guarantee is that
4217 ** the destructor will be called when the [prepared statement] is destroyed.
4218 ** Note in particular that the destructor X in the call to
4219 ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before
4220 ** the sqlite3_set_auxdata() call even returns. Hence sqlite3_set_auxdata()
4221 ** should be called near the end of the function implementation and the
4222 ** implementation should not make any use of P after sqlite3_set_auxdata()
4223 ** has been called.
4224 **
4225 ** ^(In practice, metadata is preserved between function calls for
4226 ** function parameters that are compile-time constants, including literal
4227 ** values and [parameters] and expressions composed from the same.)^
4228 **
4229
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.0"
111 #define SQLITE_VERSION_NUMBER 3008000
112 #define SQLITE_SOURCE_ID "2013-07-25 17:07:03 8bcbb33fd0a970e16a920e1d35571836dbb9ba50"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -2559,11 +2559,12 @@
2559 ** interface is to keep a GUI updated during a large query.
2560 **
2561 ** ^The parameter P is passed through as the only parameter to the
2562 ** callback function X. ^The parameter N is the approximate number of
2563 ** [virtual machine instructions] that are evaluated between successive
2564 ** invocations of the callback X. ^If N is less than one then the progress
2565 ** handler is disabled.
2566 **
2567 ** ^Only a single progress handler may be defined at one time per
2568 ** [database connection]; setting a new progress handler cancels the
2569 ** old one. ^Setting parameter X to NULL disables the progress handler.
2570 ** ^The progress handler is also disabled by setting N to a value less
@@ -4179,50 +4180,49 @@
4180 SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
4181
4182 /*
4183 ** CAPI3REF: Function Auxiliary Data
4184 **
4185 ** These functions may be used by (non-aggregate) SQL functions to
4186 ** associate metadata with argument values. If the same value is passed to
4187 ** multiple invocations of the same SQL function during query execution, under
4188 ** some circumstances the associated metadata may be preserved. An example
4189 ** of where this might be useful is in a regular-expression matching
4190 ** function. The compiled version of the regular expression can be stored as
4191 ** metadata associated with the pattern string.
4192 ** Then as long as the pattern string remains the same,
4193 ** the compiled regular expression can be reused on multiple
4194 ** invocations of the same function.
4195 **
4196 ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
4197 ** associated by the sqlite3_set_auxdata() function with the Nth argument
4198 ** value to the application-defined function. ^If there is no metadata
4199 ** associated with the function argument, this sqlite3_get_auxdata() interface
4200 ** returns a NULL pointer.
 
4201 **
4202 ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
4203 ** argument of the application-defined function. ^Subsequent
4204 ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
4205 ** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or
4206 ** NULL if the metadata has been discarded.
4207 ** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL,
4208 ** SQLite will invoke the destructor function X with parameter P exactly
4209 ** once, when the metadata is discarded.
4210 ** SQLite is free to discard the metadata at any time, including: <ul>
4211 ** <li> when the corresponding function parameter changes, or
4212 ** <li> when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
4213 ** SQL statement, or
4214 ** <li> when sqlite3_set_auxdata() is invoked again on the same parameter, or
4215 ** <li> during the original sqlite3_set_auxdata() call when a memory
4216 ** allocation error occurs. </ul>)^
4217 **
4218 ** Note the last bullet in particular. The destructor X in
4219 ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
4220 ** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata()
 
 
 
4221 ** should be called near the end of the function implementation and the
4222 ** function implementation should not make any use of P after
4223 ** sqlite3_set_auxdata() has been called.
4224 **
4225 ** ^(In practice, metadata is preserved between function calls for
4226 ** function parameters that are compile-time constants, including literal
4227 ** values and [parameters] and expressions composed from the same.)^
4228 **
4229

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button