Fossil SCM
Rebase. Generate sqlite3.[ch] from latest SQLite trunk. (still experimental)
Commit
3719ad9579a7b96add38be695950c306f01f484f
Parent
5af289e999c6ada…
4 files changed
+176
-113
+176
-113
+31
-31
+31
-31
+176
-113
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -670,11 +670,11 @@ | ||
| 670 | 670 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 671 | 671 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 672 | 672 | */ |
| 673 | 673 | #define SQLITE_VERSION "3.8.0" |
| 674 | 674 | #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" | |
| 676 | 676 | |
| 677 | 677 | /* |
| 678 | 678 | ** CAPI3REF: Run-Time Library Version Numbers |
| 679 | 679 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 680 | 680 | ** |
| @@ -3122,11 +3122,12 @@ | ||
| 3122 | 3122 | ** interface is to keep a GUI updated during a large query. |
| 3123 | 3123 | ** |
| 3124 | 3124 | ** ^The parameter P is passed through as the only parameter to the |
| 3125 | 3125 | ** callback function X. ^The parameter N is the approximate number of |
| 3126 | 3126 | ** [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. | |
| 3128 | 3129 | ** |
| 3129 | 3130 | ** ^Only a single progress handler may be defined at one time per |
| 3130 | 3131 | ** [database connection]; setting a new progress handler cancels the |
| 3131 | 3132 | ** old one. ^Setting parameter X to NULL disables the progress handler. |
| 3132 | 3133 | ** ^The progress handler is also disabled by setting N to a value less |
| @@ -4742,50 +4743,49 @@ | ||
| 4742 | 4743 | SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*); |
| 4743 | 4744 | |
| 4744 | 4745 | /* |
| 4745 | 4746 | ** CAPI3REF: Function Auxiliary Data |
| 4746 | 4747 | ** |
| 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 | |
| 4748 | 4749 | ** associate metadata with argument values. If the same value is passed to |
| 4749 | 4750 | ** 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. | |
| 4757 | 4758 | ** |
| 4758 | 4759 | ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata |
| 4759 | 4760 | ** 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. | |
| 4764 | 4764 | ** |
| 4765 | 4765 | ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th |
| 4766 | 4766 | ** argument of the application-defined function. ^Subsequent |
| 4767 | 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>)^ | |
| 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>)^ | |
| 4777 | 4780 | ** |
| 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() | |
| 4784 | 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. | |
| 4785 | +** function implementation should not make any use of P after | |
| 4786 | +** sqlite3_set_auxdata() has been called. | |
| 4787 | 4787 | ** |
| 4788 | 4788 | ** ^(In practice, metadata is preserved between function calls for |
| 4789 | 4789 | ** function parameters that are compile-time constants, including literal |
| 4790 | 4790 | ** values and [parameters] and expressions composed from the same.)^ |
| 4791 | 4791 | ** |
| @@ -8824,11 +8824,10 @@ | ||
| 8824 | 8824 | |
| 8825 | 8825 | /* |
| 8826 | 8826 | ** The names of the following types declared in vdbeInt.h are required |
| 8827 | 8827 | ** for the VdbeOp definition. |
| 8828 | 8828 | */ |
| 8829 | -typedef struct VdbeFunc VdbeFunc; | |
| 8830 | 8829 | typedef struct Mem Mem; |
| 8831 | 8830 | typedef struct SubProgram SubProgram; |
| 8832 | 8831 | |
| 8833 | 8832 | /* |
| 8834 | 8833 | ** A single instruction of the virtual machine has an opcode |
| @@ -8848,11 +8847,10 @@ | ||
| 8848 | 8847 | void *p; /* Generic pointer */ |
| 8849 | 8848 | char *z; /* Pointer to data for string (char array) types */ |
| 8850 | 8849 | i64 *pI64; /* Used when p4type is P4_INT64 */ |
| 8851 | 8850 | double *pReal; /* Used when p4type is P4_REAL */ |
| 8852 | 8851 | FuncDef *pFunc; /* Used when p4type is P4_FUNCDEF */ |
| 8853 | - VdbeFunc *pVdbeFunc; /* Used when p4type is P4_VDBEFUNC */ | |
| 8854 | 8852 | CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */ |
| 8855 | 8853 | Mem *pMem; /* Used when p4type is P4_MEM */ |
| 8856 | 8854 | VTable *pVtab; /* Used when p4type is P4_VTAB */ |
| 8857 | 8855 | KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */ |
| 8858 | 8856 | int *ai; /* Used when p4type is P4_INTARRAY */ |
| @@ -8902,11 +8900,10 @@ | ||
| 8902 | 8900 | #define P4_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */ |
| 8903 | 8901 | #define P4_STATIC (-2) /* Pointer to a static string */ |
| 8904 | 8902 | #define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */ |
| 8905 | 8903 | #define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */ |
| 8906 | 8904 | #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 | 8905 | #define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */ |
| 8909 | 8906 | #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */ |
| 8910 | 8907 | #define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */ |
| 8911 | 8908 | #define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */ |
| 8912 | 8909 | #define P4_REAL (-12) /* P4 is a 64-bit floating point value */ |
| @@ -13257,10 +13254,13 @@ | ||
| 13257 | 13254 | typedef struct VdbeSorter VdbeSorter; |
| 13258 | 13255 | |
| 13259 | 13256 | /* Opaque type used by the explainer */ |
| 13260 | 13257 | typedef struct Explain Explain; |
| 13261 | 13258 | |
| 13259 | +/* Elements of the linked list at Vdbe.pAuxData */ | |
| 13260 | +typedef struct AuxData AuxData; | |
| 13261 | + | |
| 13262 | 13262 | /* |
| 13263 | 13263 | ** A cursor is a pointer into a single BTree within a database file. |
| 13264 | 13264 | ** The cursor can seek to a BTree entry with a particular key, or |
| 13265 | 13265 | ** loop over all entries of the Btree. You can also insert new BTree |
| 13266 | 13266 | ** entries or retrieve the key or data from the entry that the cursor |
| @@ -13443,27 +13443,23 @@ | ||
| 13443 | 13443 | */ |
| 13444 | 13444 | #ifdef SQLITE_DEBUG |
| 13445 | 13445 | #define memIsValid(M) ((M)->flags & MEM_Invalid)==0 |
| 13446 | 13446 | #endif |
| 13447 | 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. | |
| 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). | |
| 13457 | 13454 | */ |
| 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 */ | |
| 13465 | 13461 | }; |
| 13466 | 13462 | |
| 13467 | 13463 | /* |
| 13468 | 13464 | ** The "context" argument for a installable function. A pointer to an |
| 13469 | 13465 | ** instance of this structure is the first argument to the routines used |
| @@ -13477,16 +13473,17 @@ | ||
| 13477 | 13473 | ** This structure is defined inside of vdbeInt.h because it uses substructures |
| 13478 | 13474 | ** (Mem) which are only defined there. |
| 13479 | 13475 | */ |
| 13480 | 13476 | struct sqlite3_context { |
| 13481 | 13477 | FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */ |
| 13482 | - VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */ | |
| 13483 | 13478 | Mem s; /* The return value is stored here */ |
| 13484 | 13479 | Mem *pMem; /* Memory cell used to store aggregate context */ |
| 13485 | 13480 | CollSeq *pColl; /* Collating sequence */ |
| 13486 | 13481 | int isError; /* Error code returned by the function. */ |
| 13487 | 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 */ | |
| 13488 | 13485 | }; |
| 13489 | 13486 | |
| 13490 | 13487 | /* |
| 13491 | 13488 | ** An Explain object accumulates indented output which is helpful |
| 13492 | 13489 | ** in describing recursive data structures. |
| @@ -13581,10 +13578,11 @@ | ||
| 13581 | 13578 | int nFrame; /* Number of frames in pFrame list */ |
| 13582 | 13579 | u32 expmask; /* Binding to these vars invalidates VM */ |
| 13583 | 13580 | SubProgram *pProgram; /* Linked list of all sub-programs used by VM */ |
| 13584 | 13581 | int nOnceFlag; /* Size of array aOnceFlag[] */ |
| 13585 | 13582 | u8 *aOnceFlag; /* Flags for OP_Once */ |
| 13583 | + AuxData *pAuxData; /* Linked list of auxdata allocations */ | |
| 13586 | 13584 | }; |
| 13587 | 13585 | |
| 13588 | 13586 | /* |
| 13589 | 13587 | ** The following are allowed values for Vdbe.magic |
| 13590 | 13588 | */ |
| @@ -13604,11 +13602,11 @@ | ||
| 13604 | 13602 | #endif |
| 13605 | 13603 | SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32); |
| 13606 | 13604 | SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int); |
| 13607 | 13605 | SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int); |
| 13608 | 13606 | SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); |
| 13609 | -SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(VdbeFunc*, int); | |
| 13607 | +SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int); | |
| 13610 | 13608 | |
| 13611 | 13609 | int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *); |
| 13612 | 13610 | SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*); |
| 13613 | 13611 | SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *); |
| 13614 | 13612 | SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*); |
| @@ -28376,10 +28374,14 @@ | ||
| 28376 | 28374 | */ |
| 28377 | 28375 | static const char *unixTempFileDir(void){ |
| 28378 | 28376 | static const char *azDirs[] = { |
| 28379 | 28377 | 0, |
| 28380 | 28378 | 0, |
| 28379 | +#ifdef __CYGWIN__ | |
| 28380 | + 0, | |
| 28381 | + 0, | |
| 28382 | +#endif | |
| 28381 | 28383 | "/var/tmp", |
| 28382 | 28384 | "/usr/tmp", |
| 28383 | 28385 | "/tmp", |
| 28384 | 28386 | 0 /* List terminator */ |
| 28385 | 28387 | }; |
| @@ -28387,10 +28389,14 @@ | ||
| 28387 | 28389 | struct stat buf; |
| 28388 | 28390 | const char *zDir = 0; |
| 28389 | 28391 | |
| 28390 | 28392 | azDirs[0] = sqlite3_temp_directory; |
| 28391 | 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 | |
| 28392 | 28398 | for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){ |
| 28393 | 28399 | if( zDir==0 ) continue; |
| 28394 | 28400 | if( osStat(zDir, &buf) ) continue; |
| 28395 | 28401 | if( !S_ISDIR(buf.st_mode) ) continue; |
| 28396 | 28402 | if( osAccess(zDir, 07) ) continue; |
| @@ -30735,11 +30741,11 @@ | ||
| 30735 | 30741 | |
| 30736 | 30742 | /* |
| 30737 | 30743 | ** Are most of the Win32 Unicode APIs available (i.e. with certain exceptions |
| 30738 | 30744 | ** based on the sub-platform)? |
| 30739 | 30745 | */ |
| 30740 | -#if SQLITE_OS_WINCE || SQLITE_OS_WINNT || SQLITE_OS_WINRT | |
| 30746 | +#if SQLITE_OS_WINCE || SQLITE_OS_WINNT || SQLITE_OS_WINRT || defined(__CYGWIN__) | |
| 30741 | 30747 | # define SQLITE_WIN32_HAS_WIDE |
| 30742 | 30748 | #endif |
| 30743 | 30749 | |
| 30744 | 30750 | /* |
| 30745 | 30751 | ** Do we need to manually define the Win32 file mapping APIs for use with WAL |
| @@ -34556,10 +34562,12 @@ | ||
| 34556 | 34562 | #endif |
| 34557 | 34563 | /* caller will handle out of memory */ |
| 34558 | 34564 | return zConverted; |
| 34559 | 34565 | } |
| 34560 | 34566 | |
| 34567 | +static int winIsDir(const void *zConverted); | |
| 34568 | + | |
| 34561 | 34569 | /* |
| 34562 | 34570 | ** Create a temporary file name in zBuf. zBuf must be big enough to |
| 34563 | 34571 | ** hold at pVfs->mxPathname characters. |
| 34564 | 34572 | */ |
| 34565 | 34573 | static int getTempname(int nBuf, char *zBuf){ |
| @@ -34580,11 +34588,53 @@ | ||
| 34580 | 34588 | memset(zTempPath, 0, MAX_PATH+2); |
| 34581 | 34589 | |
| 34582 | 34590 | if( sqlite3_temp_directory ){ |
| 34583 | 34591 | sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory); |
| 34584 | 34592 | } |
| 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 | |
| 34586 | 34636 | else if( isNT() ){ |
| 34587 | 34637 | char *zMulti; |
| 34588 | 34638 | WCHAR zWidePath[MAX_PATH]; |
| 34589 | 34639 | osGetTempPathW(MAX_PATH-30, zWidePath); |
| 34590 | 34640 | zMulti = unicodeToUtf8(zWidePath); |
| @@ -60538,17 +60588,10 @@ | ||
| 60538 | 60588 | } |
| 60539 | 60589 | case P4_MPRINTF: { |
| 60540 | 60590 | if( db->pnBytesFreed==0 ) sqlite3_free(p4); |
| 60541 | 60591 | break; |
| 60542 | 60592 | } |
| 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 | 60593 | case P4_FUNCDEF: { |
| 60551 | 60594 | freeEphemeralFunction(db, (FuncDef*)p4); |
| 60552 | 60595 | break; |
| 60553 | 60596 | } |
| 60554 | 60597 | case P4_MEM: { |
| @@ -61574,10 +61617,14 @@ | ||
| 61574 | 61617 | while( p->pDelFrame ){ |
| 61575 | 61618 | VdbeFrame *pDel = p->pDelFrame; |
| 61576 | 61619 | p->pDelFrame = pDel->pParent; |
| 61577 | 61620 | sqlite3VdbeFrameDelete(pDel); |
| 61578 | 61621 | } |
| 61622 | + | |
| 61623 | + /* Delete any auxdata allocations made by the VM */ | |
| 61624 | + sqlite3VdbeDeleteAuxData(p, -1, 0); | |
| 61625 | + assert( p->pAuxData==0 ); | |
| 61579 | 61626 | } |
| 61580 | 61627 | |
| 61581 | 61628 | /* |
| 61582 | 61629 | ** Clean up the VM after execution. |
| 61583 | 61630 | ** |
| @@ -62372,24 +62419,39 @@ | ||
| 62372 | 62419 | sqlite3VdbeDelete(p); |
| 62373 | 62420 | return rc; |
| 62374 | 62421 | } |
| 62375 | 62422 | |
| 62376 | 62423 | /* |
| 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.). | |
| 62381 | 62438 | */ |
| 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 | + ){ | |
| 62387 | 62446 | if( pAux->xDelete ){ |
| 62388 | 62447 | pAux->xDelete(pAux->pAux); |
| 62389 | 62448 | } |
| 62390 | - pAux->pAux = 0; | |
| 62449 | + *pp = pAux->pNext; | |
| 62450 | + sqlite3DbFree(pVdbe->db, pAux); | |
| 62451 | + }else{ | |
| 62452 | + pp= &pAux->pNext; | |
| 62391 | 62453 | } |
| 62392 | 62454 | } |
| 62393 | 62455 | } |
| 62394 | 62456 | |
| 62395 | 62457 | /* |
| @@ -63784,18 +63846,18 @@ | ||
| 63784 | 63846 | /* |
| 63785 | 63847 | ** Return the auxilary data pointer, if any, for the iArg'th argument to |
| 63786 | 63848 | ** the user-function defined by pCtx. |
| 63787 | 63849 | */ |
| 63788 | 63850 | SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){ |
| 63789 | - VdbeFunc *pVdbeFunc; | |
| 63851 | + AuxData *pAuxData; | |
| 63790 | 63852 | |
| 63791 | 63853 | 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; | |
| 63795 | 63856 | } |
| 63796 | - return pVdbeFunc->apAux[iArg].pAux; | |
| 63857 | + | |
| 63858 | + return (pAuxData ? pAuxData->pAux : 0); | |
| 63797 | 63859 | } |
| 63798 | 63860 | |
| 63799 | 63861 | /* |
| 63800 | 63862 | ** Set the auxilary data pointer and delete function, for the iArg'th |
| 63801 | 63863 | ** argument to the user-function defined by pCtx. Any previous value is |
| @@ -63805,33 +63867,30 @@ | ||
| 63805 | 63867 | sqlite3_context *pCtx, |
| 63806 | 63868 | int iArg, |
| 63807 | 63869 | void *pAux, |
| 63808 | 63870 | void (*xDelete)(void*) |
| 63809 | 63871 | ){ |
| 63810 | - struct AuxData *pAuxData; | |
| 63811 | - VdbeFunc *pVdbeFunc; | |
| 63812 | - if( iArg<0 ) goto failed; | |
| 63872 | + AuxData *pAuxData; | |
| 63873 | + Vdbe *pVdbe = pCtx->pVdbe; | |
| 63813 | 63874 | |
| 63814 | 63875 | 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 ){ | |
| 63831 | 63889 | pAuxData->xDelete(pAuxData->pAux); |
| 63832 | 63890 | } |
| 63891 | + | |
| 63833 | 63892 | pAuxData->pAux = pAux; |
| 63834 | 63893 | pAuxData->xDelete = xDelete; |
| 63835 | 63894 | return; |
| 63836 | 63895 | |
| 63837 | 63896 | failed: |
| @@ -65439,11 +65498,11 @@ | ||
| 65439 | 65498 | u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */ |
| 65440 | 65499 | u8 encoding = ENC(db); /* The database encoding */ |
| 65441 | 65500 | int iCompare = 0; /* Result of last OP_Compare operation */ |
| 65442 | 65501 | unsigned nVmStep = 0; /* Number of virtual machine steps */ |
| 65443 | 65502 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 65444 | - unsigned nProgressOps = 0; /* nVmStep at last progress callback. */ | |
| 65503 | + unsigned nProgressLimit; /* Invoke xProgress() when nVmStep reaches this */ | |
| 65445 | 65504 | #endif |
| 65446 | 65505 | Mem *aMem = p->aMem; /* Copy of p->aMem */ |
| 65447 | 65506 | Mem *pIn1 = 0; /* 1st input operand */ |
| 65448 | 65507 | Mem *pIn2 = 0; /* 2nd input operand */ |
| 65449 | 65508 | Mem *pIn3 = 0; /* 3rd input operand */ |
| @@ -65898,10 +65957,21 @@ | ||
| 65898 | 65957 | assert( p->explain==0 ); |
| 65899 | 65958 | p->pResultSet = 0; |
| 65900 | 65959 | db->busyHandler.nBusy = 0; |
| 65901 | 65960 | CHECK_FOR_INTERRUPT; |
| 65902 | 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 | |
| 65903 | 65973 | #ifdef SQLITE_DEBUG |
| 65904 | 65974 | sqlite3BeginBenignMalloc(); |
| 65905 | 65975 | if( p->pc==0 && (p->db->flags & SQLITE_VdbeListing)!=0 ){ |
| 65906 | 65976 | int i; |
| 65907 | 65977 | printf("VDBE Program Listing:\n"); |
| @@ -66058,18 +66128,20 @@ | ||
| 66058 | 66128 | ** of VDBE ops have been executed (either since this invocation of |
| 66059 | 66129 | ** sqlite3VdbeExec() or since last time the progress callback was called). |
| 66060 | 66130 | ** If the progress callback returns non-zero, exit the virtual machine with |
| 66061 | 66131 | ** a return code SQLITE_ABORT. |
| 66062 | 66132 | */ |
| 66063 | - if( db->xProgress!=0 && (nVmStep - nProgressOps)>=db->nProgressOps ){ | |
| 66133 | + if( db->xProgress!=0 && nVmStep>=nProgressLimit ){ | |
| 66064 | 66134 | int prc; |
| 66065 | 66135 | prc = db->xProgress(db->pProgressArg); |
| 66066 | 66136 | if( prc!=0 ){ |
| 66067 | 66137 | rc = SQLITE_INTERRUPT; |
| 66068 | 66138 | goto vdbe_error_halt; |
| 66069 | 66139 | } |
| 66070 | - nProgressOps = nVmStep; | |
| 66140 | + if( db->xProgress!=0 ){ | |
| 66141 | + nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps); | |
| 66142 | + } | |
| 66071 | 66143 | } |
| 66072 | 66144 | #endif |
| 66073 | 66145 | |
| 66074 | 66146 | break; |
| 66075 | 66147 | } |
| @@ -66751,23 +66823,18 @@ | ||
| 66751 | 66823 | Deephemeralize(u.ai.pArg); |
| 66752 | 66824 | sqlite3VdbeMemStoreType(u.ai.pArg); |
| 66753 | 66825 | REGISTER_TRACE(pOp->p2+u.ai.i, u.ai.pArg); |
| 66754 | 66826 | } |
| 66755 | 66827 | |
| 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; | |
| 66765 | 66830 | u.ai.ctx.s.flags = MEM_Null; |
| 66766 | 66831 | u.ai.ctx.s.db = db; |
| 66767 | 66832 | u.ai.ctx.s.xDel = 0; |
| 66768 | 66833 | u.ai.ctx.s.zMalloc = 0; |
| 66834 | + u.ai.ctx.iOp = pc; | |
| 66835 | + u.ai.ctx.pVdbe = p; | |
| 66769 | 66836 | |
| 66770 | 66837 | /* The output cell may already have a buffer allocated. Move |
| 66771 | 66838 | ** the pointer to u.ai.ctx.s so in case the user-function can use |
| 66772 | 66839 | ** the already allocated buffer instead of allocating a new one. |
| 66773 | 66840 | */ |
| @@ -66786,15 +66853,11 @@ | ||
| 66786 | 66853 | lastRowid = db->lastRowid; |
| 66787 | 66854 | |
| 66788 | 66855 | /* If any auxiliary data functions have been called by this user function, |
| 66789 | 66856 | ** immediately call the destructor for any non-static values. |
| 66790 | 66857 | */ |
| 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); | |
| 66796 | 66859 | |
| 66797 | 66860 | if( db->mallocFailed ){ |
| 66798 | 66861 | /* Even though a malloc() has failed, the implementation of the |
| 66799 | 66862 | ** user function may have called an sqlite3_result_XXX() function |
| 66800 | 66863 | ** to return a value. The following call releases any resources |
| @@ -117728,11 +117791,11 @@ | ||
| 117728 | 117791 | db->autoCommit = 1; |
| 117729 | 117792 | db->nextAutovac = -1; |
| 117730 | 117793 | db->szMmap = sqlite3GlobalConfig.szMmap; |
| 117731 | 117794 | db->nextPagesize = 0; |
| 117732 | 117795 | 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 | |
| 117734 | 117797 | | SQLITE_AutoIndex |
| 117735 | 117798 | #endif |
| 117736 | 117799 | #if SQLITE_DEFAULT_FILE_FORMAT<4 |
| 117737 | 117800 | | SQLITE_LegacyFileFmt |
| 117738 | 117801 | #endif |
| 117739 | 117802 |
| --- 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 @@ | ||
| 670 | 670 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 671 | 671 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 672 | 672 | */ |
| 673 | 673 | #define SQLITE_VERSION "3.8.0" |
| 674 | 674 | #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" | |
| 676 | 676 | |
| 677 | 677 | /* |
| 678 | 678 | ** CAPI3REF: Run-Time Library Version Numbers |
| 679 | 679 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 680 | 680 | ** |
| @@ -3122,11 +3122,12 @@ | ||
| 3122 | 3122 | ** interface is to keep a GUI updated during a large query. |
| 3123 | 3123 | ** |
| 3124 | 3124 | ** ^The parameter P is passed through as the only parameter to the |
| 3125 | 3125 | ** callback function X. ^The parameter N is the approximate number of |
| 3126 | 3126 | ** [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. | |
| 3128 | 3129 | ** |
| 3129 | 3130 | ** ^Only a single progress handler may be defined at one time per |
| 3130 | 3131 | ** [database connection]; setting a new progress handler cancels the |
| 3131 | 3132 | ** old one. ^Setting parameter X to NULL disables the progress handler. |
| 3132 | 3133 | ** ^The progress handler is also disabled by setting N to a value less |
| @@ -4742,50 +4743,49 @@ | ||
| 4742 | 4743 | SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*); |
| 4743 | 4744 | |
| 4744 | 4745 | /* |
| 4745 | 4746 | ** CAPI3REF: Function Auxiliary Data |
| 4746 | 4747 | ** |
| 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 | |
| 4748 | 4749 | ** associate metadata with argument values. If the same value is passed to |
| 4749 | 4750 | ** 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. | |
| 4757 | 4758 | ** |
| 4758 | 4759 | ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata |
| 4759 | 4760 | ** 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. | |
| 4764 | 4764 | ** |
| 4765 | 4765 | ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th |
| 4766 | 4766 | ** argument of the application-defined function. ^Subsequent |
| 4767 | 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>)^ | |
| 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>)^ | |
| 4777 | 4780 | ** |
| 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() | |
| 4784 | 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. | |
| 4785 | +** function implementation should not make any use of P after | |
| 4786 | +** sqlite3_set_auxdata() has been called. | |
| 4787 | 4787 | ** |
| 4788 | 4788 | ** ^(In practice, metadata is preserved between function calls for |
| 4789 | 4789 | ** function parameters that are compile-time constants, including literal |
| 4790 | 4790 | ** values and [parameters] and expressions composed from the same.)^ |
| 4791 | 4791 | ** |
| @@ -8824,11 +8824,10 @@ | ||
| 8824 | 8824 | |
| 8825 | 8825 | /* |
| 8826 | 8826 | ** The names of the following types declared in vdbeInt.h are required |
| 8827 | 8827 | ** for the VdbeOp definition. |
| 8828 | 8828 | */ |
| 8829 | -typedef struct VdbeFunc VdbeFunc; | |
| 8830 | 8829 | typedef struct Mem Mem; |
| 8831 | 8830 | typedef struct SubProgram SubProgram; |
| 8832 | 8831 | |
| 8833 | 8832 | /* |
| 8834 | 8833 | ** A single instruction of the virtual machine has an opcode |
| @@ -8848,11 +8847,10 @@ | ||
| 8848 | 8847 | void *p; /* Generic pointer */ |
| 8849 | 8848 | char *z; /* Pointer to data for string (char array) types */ |
| 8850 | 8849 | i64 *pI64; /* Used when p4type is P4_INT64 */ |
| 8851 | 8850 | double *pReal; /* Used when p4type is P4_REAL */ |
| 8852 | 8851 | FuncDef *pFunc; /* Used when p4type is P4_FUNCDEF */ |
| 8853 | - VdbeFunc *pVdbeFunc; /* Used when p4type is P4_VDBEFUNC */ | |
| 8854 | 8852 | CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */ |
| 8855 | 8853 | Mem *pMem; /* Used when p4type is P4_MEM */ |
| 8856 | 8854 | VTable *pVtab; /* Used when p4type is P4_VTAB */ |
| 8857 | 8855 | KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */ |
| 8858 | 8856 | int *ai; /* Used when p4type is P4_INTARRAY */ |
| @@ -8902,11 +8900,10 @@ | ||
| 8902 | 8900 | #define P4_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */ |
| 8903 | 8901 | #define P4_STATIC (-2) /* Pointer to a static string */ |
| 8904 | 8902 | #define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */ |
| 8905 | 8903 | #define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */ |
| 8906 | 8904 | #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 | 8905 | #define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */ |
| 8909 | 8906 | #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */ |
| 8910 | 8907 | #define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */ |
| 8911 | 8908 | #define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */ |
| 8912 | 8909 | #define P4_REAL (-12) /* P4 is a 64-bit floating point value */ |
| @@ -13257,10 +13254,13 @@ | ||
| 13257 | 13254 | typedef struct VdbeSorter VdbeSorter; |
| 13258 | 13255 | |
| 13259 | 13256 | /* Opaque type used by the explainer */ |
| 13260 | 13257 | typedef struct Explain Explain; |
| 13261 | 13258 | |
| 13259 | +/* Elements of the linked list at Vdbe.pAuxData */ | |
| 13260 | +typedef struct AuxData AuxData; | |
| 13261 | + | |
| 13262 | 13262 | /* |
| 13263 | 13263 | ** A cursor is a pointer into a single BTree within a database file. |
| 13264 | 13264 | ** The cursor can seek to a BTree entry with a particular key, or |
| 13265 | 13265 | ** loop over all entries of the Btree. You can also insert new BTree |
| 13266 | 13266 | ** entries or retrieve the key or data from the entry that the cursor |
| @@ -13443,27 +13443,23 @@ | ||
| 13443 | 13443 | */ |
| 13444 | 13444 | #ifdef SQLITE_DEBUG |
| 13445 | 13445 | #define memIsValid(M) ((M)->flags & MEM_Invalid)==0 |
| 13446 | 13446 | #endif |
| 13447 | 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. | |
| 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). | |
| 13457 | 13454 | */ |
| 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 */ | |
| 13465 | 13461 | }; |
| 13466 | 13462 | |
| 13467 | 13463 | /* |
| 13468 | 13464 | ** The "context" argument for a installable function. A pointer to an |
| 13469 | 13465 | ** instance of this structure is the first argument to the routines used |
| @@ -13477,16 +13473,17 @@ | ||
| 13477 | 13473 | ** This structure is defined inside of vdbeInt.h because it uses substructures |
| 13478 | 13474 | ** (Mem) which are only defined there. |
| 13479 | 13475 | */ |
| 13480 | 13476 | struct sqlite3_context { |
| 13481 | 13477 | FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */ |
| 13482 | - VdbeFunc *pVdbeFunc; /* Auxilary data, if created. */ | |
| 13483 | 13478 | Mem s; /* The return value is stored here */ |
| 13484 | 13479 | Mem *pMem; /* Memory cell used to store aggregate context */ |
| 13485 | 13480 | CollSeq *pColl; /* Collating sequence */ |
| 13486 | 13481 | int isError; /* Error code returned by the function. */ |
| 13487 | 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 */ | |
| 13488 | 13485 | }; |
| 13489 | 13486 | |
| 13490 | 13487 | /* |
| 13491 | 13488 | ** An Explain object accumulates indented output which is helpful |
| 13492 | 13489 | ** in describing recursive data structures. |
| @@ -13581,10 +13578,11 @@ | ||
| 13581 | 13578 | int nFrame; /* Number of frames in pFrame list */ |
| 13582 | 13579 | u32 expmask; /* Binding to these vars invalidates VM */ |
| 13583 | 13580 | SubProgram *pProgram; /* Linked list of all sub-programs used by VM */ |
| 13584 | 13581 | int nOnceFlag; /* Size of array aOnceFlag[] */ |
| 13585 | 13582 | u8 *aOnceFlag; /* Flags for OP_Once */ |
| 13583 | + AuxData *pAuxData; /* Linked list of auxdata allocations */ | |
| 13586 | 13584 | }; |
| 13587 | 13585 | |
| 13588 | 13586 | /* |
| 13589 | 13587 | ** The following are allowed values for Vdbe.magic |
| 13590 | 13588 | */ |
| @@ -13604,11 +13602,11 @@ | ||
| 13604 | 13602 | #endif |
| 13605 | 13603 | SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32); |
| 13606 | 13604 | SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int); |
| 13607 | 13605 | SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int); |
| 13608 | 13606 | SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); |
| 13609 | -SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(VdbeFunc*, int); | |
| 13607 | +SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int); | |
| 13610 | 13608 | |
| 13611 | 13609 | int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *); |
| 13612 | 13610 | SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*); |
| 13613 | 13611 | SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *); |
| 13614 | 13612 | SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*); |
| @@ -28376,10 +28374,14 @@ | ||
| 28376 | 28374 | */ |
| 28377 | 28375 | static const char *unixTempFileDir(void){ |
| 28378 | 28376 | static const char *azDirs[] = { |
| 28379 | 28377 | 0, |
| 28380 | 28378 | 0, |
| 28379 | +#ifdef __CYGWIN__ | |
| 28380 | + 0, | |
| 28381 | + 0, | |
| 28382 | +#endif | |
| 28381 | 28383 | "/var/tmp", |
| 28382 | 28384 | "/usr/tmp", |
| 28383 | 28385 | "/tmp", |
| 28384 | 28386 | 0 /* List terminator */ |
| 28385 | 28387 | }; |
| @@ -28387,10 +28389,14 @@ | ||
| 28387 | 28389 | struct stat buf; |
| 28388 | 28390 | const char *zDir = 0; |
| 28389 | 28391 | |
| 28390 | 28392 | azDirs[0] = sqlite3_temp_directory; |
| 28391 | 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 | |
| 28392 | 28398 | for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){ |
| 28393 | 28399 | if( zDir==0 ) continue; |
| 28394 | 28400 | if( osStat(zDir, &buf) ) continue; |
| 28395 | 28401 | if( !S_ISDIR(buf.st_mode) ) continue; |
| 28396 | 28402 | if( osAccess(zDir, 07) ) continue; |
| @@ -30735,11 +30741,11 @@ | ||
| 30735 | 30741 | |
| 30736 | 30742 | /* |
| 30737 | 30743 | ** Are most of the Win32 Unicode APIs available (i.e. with certain exceptions |
| 30738 | 30744 | ** based on the sub-platform)? |
| 30739 | 30745 | */ |
| 30740 | -#if SQLITE_OS_WINCE || SQLITE_OS_WINNT || SQLITE_OS_WINRT | |
| 30746 | +#if SQLITE_OS_WINCE || SQLITE_OS_WINNT || SQLITE_OS_WINRT || defined(__CYGWIN__) | |
| 30741 | 30747 | # define SQLITE_WIN32_HAS_WIDE |
| 30742 | 30748 | #endif |
| 30743 | 30749 | |
| 30744 | 30750 | /* |
| 30745 | 30751 | ** Do we need to manually define the Win32 file mapping APIs for use with WAL |
| @@ -34556,10 +34562,12 @@ | ||
| 34556 | 34562 | #endif |
| 34557 | 34563 | /* caller will handle out of memory */ |
| 34558 | 34564 | return zConverted; |
| 34559 | 34565 | } |
| 34560 | 34566 | |
| 34567 | +static int winIsDir(const void *zConverted); | |
| 34568 | + | |
| 34561 | 34569 | /* |
| 34562 | 34570 | ** Create a temporary file name in zBuf. zBuf must be big enough to |
| 34563 | 34571 | ** hold at pVfs->mxPathname characters. |
| 34564 | 34572 | */ |
| 34565 | 34573 | static int getTempname(int nBuf, char *zBuf){ |
| @@ -34580,11 +34588,53 @@ | ||
| 34580 | 34588 | memset(zTempPath, 0, MAX_PATH+2); |
| 34581 | 34589 | |
| 34582 | 34590 | if( sqlite3_temp_directory ){ |
| 34583 | 34591 | sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory); |
| 34584 | 34592 | } |
| 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 | |
| 34586 | 34636 | else if( isNT() ){ |
| 34587 | 34637 | char *zMulti; |
| 34588 | 34638 | WCHAR zWidePath[MAX_PATH]; |
| 34589 | 34639 | osGetTempPathW(MAX_PATH-30, zWidePath); |
| 34590 | 34640 | zMulti = unicodeToUtf8(zWidePath); |
| @@ -60538,17 +60588,10 @@ | ||
| 60538 | 60588 | } |
| 60539 | 60589 | case P4_MPRINTF: { |
| 60540 | 60590 | if( db->pnBytesFreed==0 ) sqlite3_free(p4); |
| 60541 | 60591 | break; |
| 60542 | 60592 | } |
| 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 | 60593 | case P4_FUNCDEF: { |
| 60551 | 60594 | freeEphemeralFunction(db, (FuncDef*)p4); |
| 60552 | 60595 | break; |
| 60553 | 60596 | } |
| 60554 | 60597 | case P4_MEM: { |
| @@ -61574,10 +61617,14 @@ | ||
| 61574 | 61617 | while( p->pDelFrame ){ |
| 61575 | 61618 | VdbeFrame *pDel = p->pDelFrame; |
| 61576 | 61619 | p->pDelFrame = pDel->pParent; |
| 61577 | 61620 | sqlite3VdbeFrameDelete(pDel); |
| 61578 | 61621 | } |
| 61622 | + | |
| 61623 | + /* Delete any auxdata allocations made by the VM */ | |
| 61624 | + sqlite3VdbeDeleteAuxData(p, -1, 0); | |
| 61625 | + assert( p->pAuxData==0 ); | |
| 61579 | 61626 | } |
| 61580 | 61627 | |
| 61581 | 61628 | /* |
| 61582 | 61629 | ** Clean up the VM after execution. |
| 61583 | 61630 | ** |
| @@ -62372,24 +62419,39 @@ | ||
| 62372 | 62419 | sqlite3VdbeDelete(p); |
| 62373 | 62420 | return rc; |
| 62374 | 62421 | } |
| 62375 | 62422 | |
| 62376 | 62423 | /* |
| 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.). | |
| 62381 | 62438 | */ |
| 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 | + ){ | |
| 62387 | 62446 | if( pAux->xDelete ){ |
| 62388 | 62447 | pAux->xDelete(pAux->pAux); |
| 62389 | 62448 | } |
| 62390 | - pAux->pAux = 0; | |
| 62449 | + *pp = pAux->pNext; | |
| 62450 | + sqlite3DbFree(pVdbe->db, pAux); | |
| 62451 | + }else{ | |
| 62452 | + pp= &pAux->pNext; | |
| 62391 | 62453 | } |
| 62392 | 62454 | } |
| 62393 | 62455 | } |
| 62394 | 62456 | |
| 62395 | 62457 | /* |
| @@ -63784,18 +63846,18 @@ | ||
| 63784 | 63846 | /* |
| 63785 | 63847 | ** Return the auxilary data pointer, if any, for the iArg'th argument to |
| 63786 | 63848 | ** the user-function defined by pCtx. |
| 63787 | 63849 | */ |
| 63788 | 63850 | SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){ |
| 63789 | - VdbeFunc *pVdbeFunc; | |
| 63851 | + AuxData *pAuxData; | |
| 63790 | 63852 | |
| 63791 | 63853 | 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; | |
| 63795 | 63856 | } |
| 63796 | - return pVdbeFunc->apAux[iArg].pAux; | |
| 63857 | + | |
| 63858 | + return (pAuxData ? pAuxData->pAux : 0); | |
| 63797 | 63859 | } |
| 63798 | 63860 | |
| 63799 | 63861 | /* |
| 63800 | 63862 | ** Set the auxilary data pointer and delete function, for the iArg'th |
| 63801 | 63863 | ** argument to the user-function defined by pCtx. Any previous value is |
| @@ -63805,33 +63867,30 @@ | ||
| 63805 | 63867 | sqlite3_context *pCtx, |
| 63806 | 63868 | int iArg, |
| 63807 | 63869 | void *pAux, |
| 63808 | 63870 | void (*xDelete)(void*) |
| 63809 | 63871 | ){ |
| 63810 | - struct AuxData *pAuxData; | |
| 63811 | - VdbeFunc *pVdbeFunc; | |
| 63812 | - if( iArg<0 ) goto failed; | |
| 63872 | + AuxData *pAuxData; | |
| 63873 | + Vdbe *pVdbe = pCtx->pVdbe; | |
| 63813 | 63874 | |
| 63814 | 63875 | 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 ){ | |
| 63831 | 63889 | pAuxData->xDelete(pAuxData->pAux); |
| 63832 | 63890 | } |
| 63891 | + | |
| 63833 | 63892 | pAuxData->pAux = pAux; |
| 63834 | 63893 | pAuxData->xDelete = xDelete; |
| 63835 | 63894 | return; |
| 63836 | 63895 | |
| 63837 | 63896 | failed: |
| @@ -65439,11 +65498,11 @@ | ||
| 65439 | 65498 | u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */ |
| 65440 | 65499 | u8 encoding = ENC(db); /* The database encoding */ |
| 65441 | 65500 | int iCompare = 0; /* Result of last OP_Compare operation */ |
| 65442 | 65501 | unsigned nVmStep = 0; /* Number of virtual machine steps */ |
| 65443 | 65502 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 65444 | - unsigned nProgressOps = 0; /* nVmStep at last progress callback. */ | |
| 65503 | + unsigned nProgressLimit; /* Invoke xProgress() when nVmStep reaches this */ | |
| 65445 | 65504 | #endif |
| 65446 | 65505 | Mem *aMem = p->aMem; /* Copy of p->aMem */ |
| 65447 | 65506 | Mem *pIn1 = 0; /* 1st input operand */ |
| 65448 | 65507 | Mem *pIn2 = 0; /* 2nd input operand */ |
| 65449 | 65508 | Mem *pIn3 = 0; /* 3rd input operand */ |
| @@ -65898,10 +65957,21 @@ | ||
| 65898 | 65957 | assert( p->explain==0 ); |
| 65899 | 65958 | p->pResultSet = 0; |
| 65900 | 65959 | db->busyHandler.nBusy = 0; |
| 65901 | 65960 | CHECK_FOR_INTERRUPT; |
| 65902 | 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 | |
| 65903 | 65973 | #ifdef SQLITE_DEBUG |
| 65904 | 65974 | sqlite3BeginBenignMalloc(); |
| 65905 | 65975 | if( p->pc==0 && (p->db->flags & SQLITE_VdbeListing)!=0 ){ |
| 65906 | 65976 | int i; |
| 65907 | 65977 | printf("VDBE Program Listing:\n"); |
| @@ -66058,18 +66128,20 @@ | ||
| 66058 | 66128 | ** of VDBE ops have been executed (either since this invocation of |
| 66059 | 66129 | ** sqlite3VdbeExec() or since last time the progress callback was called). |
| 66060 | 66130 | ** If the progress callback returns non-zero, exit the virtual machine with |
| 66061 | 66131 | ** a return code SQLITE_ABORT. |
| 66062 | 66132 | */ |
| 66063 | - if( db->xProgress!=0 && (nVmStep - nProgressOps)>=db->nProgressOps ){ | |
| 66133 | + if( db->xProgress!=0 && nVmStep>=nProgressLimit ){ | |
| 66064 | 66134 | int prc; |
| 66065 | 66135 | prc = db->xProgress(db->pProgressArg); |
| 66066 | 66136 | if( prc!=0 ){ |
| 66067 | 66137 | rc = SQLITE_INTERRUPT; |
| 66068 | 66138 | goto vdbe_error_halt; |
| 66069 | 66139 | } |
| 66070 | - nProgressOps = nVmStep; | |
| 66140 | + if( db->xProgress!=0 ){ | |
| 66141 | + nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps); | |
| 66142 | + } | |
| 66071 | 66143 | } |
| 66072 | 66144 | #endif |
| 66073 | 66145 | |
| 66074 | 66146 | break; |
| 66075 | 66147 | } |
| @@ -66751,23 +66823,18 @@ | ||
| 66751 | 66823 | Deephemeralize(u.ai.pArg); |
| 66752 | 66824 | sqlite3VdbeMemStoreType(u.ai.pArg); |
| 66753 | 66825 | REGISTER_TRACE(pOp->p2+u.ai.i, u.ai.pArg); |
| 66754 | 66826 | } |
| 66755 | 66827 | |
| 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; | |
| 66765 | 66830 | u.ai.ctx.s.flags = MEM_Null; |
| 66766 | 66831 | u.ai.ctx.s.db = db; |
| 66767 | 66832 | u.ai.ctx.s.xDel = 0; |
| 66768 | 66833 | u.ai.ctx.s.zMalloc = 0; |
| 66834 | + u.ai.ctx.iOp = pc; | |
| 66835 | + u.ai.ctx.pVdbe = p; | |
| 66769 | 66836 | |
| 66770 | 66837 | /* The output cell may already have a buffer allocated. Move |
| 66771 | 66838 | ** the pointer to u.ai.ctx.s so in case the user-function can use |
| 66772 | 66839 | ** the already allocated buffer instead of allocating a new one. |
| 66773 | 66840 | */ |
| @@ -66786,15 +66853,11 @@ | ||
| 66786 | 66853 | lastRowid = db->lastRowid; |
| 66787 | 66854 | |
| 66788 | 66855 | /* If any auxiliary data functions have been called by this user function, |
| 66789 | 66856 | ** immediately call the destructor for any non-static values. |
| 66790 | 66857 | */ |
| 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); | |
| 66796 | 66859 | |
| 66797 | 66860 | if( db->mallocFailed ){ |
| 66798 | 66861 | /* Even though a malloc() has failed, the implementation of the |
| 66799 | 66862 | ** user function may have called an sqlite3_result_XXX() function |
| 66800 | 66863 | ** to return a value. The following call releases any resources |
| @@ -117728,11 +117791,11 @@ | ||
| 117728 | 117791 | db->autoCommit = 1; |
| 117729 | 117792 | db->nextAutovac = -1; |
| 117730 | 117793 | db->szMmap = sqlite3GlobalConfig.szMmap; |
| 117731 | 117794 | db->nextPagesize = 0; |
| 117732 | 117795 | 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 | |
| 117734 | 117797 | | SQLITE_AutoIndex |
| 117735 | 117798 | #endif |
| 117736 | 117799 | #if SQLITE_DEFAULT_FILE_FORMAT<4 |
| 117737 | 117800 | | SQLITE_LegacyFileFmt |
| 117738 | 117801 | #endif |
| 117739 | 117802 |
| --- 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 @@ | ||
| 107 | 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | 109 | */ |
| 110 | 110 | #define SQLITE_VERSION "3.8.0" |
| 111 | 111 | #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" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| @@ -2559,11 +2559,12 @@ | ||
| 2559 | 2559 | ** interface is to keep a GUI updated during a large query. |
| 2560 | 2560 | ** |
| 2561 | 2561 | ** ^The parameter P is passed through as the only parameter to the |
| 2562 | 2562 | ** callback function X. ^The parameter N is the approximate number of |
| 2563 | 2563 | ** [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. | |
| 2565 | 2566 | ** |
| 2566 | 2567 | ** ^Only a single progress handler may be defined at one time per |
| 2567 | 2568 | ** [database connection]; setting a new progress handler cancels the |
| 2568 | 2569 | ** old one. ^Setting parameter X to NULL disables the progress handler. |
| 2569 | 2570 | ** ^The progress handler is also disabled by setting N to a value less |
| @@ -4179,50 +4180,49 @@ | ||
| 4179 | 4180 | SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*); |
| 4180 | 4181 | |
| 4181 | 4182 | /* |
| 4182 | 4183 | ** CAPI3REF: Function Auxiliary Data |
| 4183 | 4184 | ** |
| 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 | |
| 4185 | 4186 | ** associate metadata with argument values. If the same value is passed to |
| 4186 | 4187 | ** 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. | |
| 4194 | 4195 | ** |
| 4195 | 4196 | ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata |
| 4196 | 4197 | ** 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. | |
| 4201 | 4201 | ** |
| 4202 | 4202 | ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th |
| 4203 | 4203 | ** argument of the application-defined function. ^Subsequent |
| 4204 | 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>)^ | |
| 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>)^ | |
| 4214 | 4217 | ** |
| 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() | |
| 4221 | 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. | |
| 4222 | +** function implementation should not make any use of P after | |
| 4223 | +** sqlite3_set_auxdata() has been called. | |
| 4224 | 4224 | ** |
| 4225 | 4225 | ** ^(In practice, metadata is preserved between function calls for |
| 4226 | 4226 | ** function parameters that are compile-time constants, including literal |
| 4227 | 4227 | ** values and [parameters] and expressions composed from the same.)^ |
| 4228 | 4228 | ** |
| 4229 | 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-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 @@ | ||
| 107 | 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | 109 | */ |
| 110 | 110 | #define SQLITE_VERSION "3.8.0" |
| 111 | 111 | #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" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| @@ -2559,11 +2559,12 @@ | ||
| 2559 | 2559 | ** interface is to keep a GUI updated during a large query. |
| 2560 | 2560 | ** |
| 2561 | 2561 | ** ^The parameter P is passed through as the only parameter to the |
| 2562 | 2562 | ** callback function X. ^The parameter N is the approximate number of |
| 2563 | 2563 | ** [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. | |
| 2565 | 2566 | ** |
| 2566 | 2567 | ** ^Only a single progress handler may be defined at one time per |
| 2567 | 2568 | ** [database connection]; setting a new progress handler cancels the |
| 2568 | 2569 | ** old one. ^Setting parameter X to NULL disables the progress handler. |
| 2569 | 2570 | ** ^The progress handler is also disabled by setting N to a value less |
| @@ -4179,50 +4180,49 @@ | ||
| 4179 | 4180 | SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*); |
| 4180 | 4181 | |
| 4181 | 4182 | /* |
| 4182 | 4183 | ** CAPI3REF: Function Auxiliary Data |
| 4183 | 4184 | ** |
| 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 | |
| 4185 | 4186 | ** associate metadata with argument values. If the same value is passed to |
| 4186 | 4187 | ** 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. | |
| 4194 | 4195 | ** |
| 4195 | 4196 | ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata |
| 4196 | 4197 | ** 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. | |
| 4201 | 4201 | ** |
| 4202 | 4202 | ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th |
| 4203 | 4203 | ** argument of the application-defined function. ^Subsequent |
| 4204 | 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>)^ | |
| 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>)^ | |
| 4214 | 4217 | ** |
| 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() | |
| 4221 | 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. | |
| 4222 | +** function implementation should not make any use of P after | |
| 4223 | +** sqlite3_set_auxdata() has been called. | |
| 4224 | 4224 | ** |
| 4225 | 4225 | ** ^(In practice, metadata is preserved between function calls for |
| 4226 | 4226 | ** function parameters that are compile-time constants, including literal |
| 4227 | 4227 | ** values and [parameters] and expressions composed from the same.)^ |
| 4228 | 4228 | ** |
| 4229 | 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-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 |