Fossil SCM

(cherry-pick): Use SQLite 3.20.0 final

jan.nijtmans 2017-08-22 09:46 UTC branch-2.3
Commit 7eebec15bd420d9ca636ce7f3577919ac0f992709fe4de671c8c5943ab593f4d
2 files changed +520 -464 +26 -21
+520 -464
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1150,11 +1150,11 @@
11501150
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11511151
** [sqlite_version()] and [sqlite_source_id()].
11521152
*/
11531153
#define SQLITE_VERSION "3.20.0"
11541154
#define SQLITE_VERSION_NUMBER 3020000
1155
-#define SQLITE_SOURCE_ID "2017-07-15 13:49:56 47cf83a0682b7b3219cf255457f5fbe05f3c1f46be42f6bbab33b78a57a252f6"
1155
+#define SQLITE_SOURCE_ID "2017-08-01 13:24:15 9501e22dfeebdcefa783575e47c60b514d7c2e0cad73b2a496c0bc4b680900a8"
11561156
11571157
/*
11581158
** CAPI3REF: Run-Time Library Version Numbers
11591159
** KEYWORDS: sqlite3_version sqlite3_sourceid
11601160
**
@@ -4672,11 +4672,11 @@
46724672
);
46734673
SQLITE_API int sqlite3_prepare16_v3(
46744674
sqlite3 *db, /* Database handle */
46754675
const void *zSql, /* SQL statement, UTF-16 encoded */
46764676
int nByte, /* Maximum length of zSql in bytes. */
4677
- unsigned int prepFalgs, /* Zero or more SQLITE_PREPARE_ flags */
4677
+ unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
46784678
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
46794679
const void **pzTail /* OUT: Pointer to unused portion of zSql */
46804680
);
46814681
46824682
/*
@@ -4910,18 +4910,18 @@
49104910
** Zeroblobs are intended to serve as placeholders for BLOBs whose
49114911
** content is later written using
49124912
** [sqlite3_blob_open | incremental BLOB I/O] routines.
49134913
** ^A negative value for the zeroblob results in a zero-length BLOB.
49144914
**
4915
-** ^The sqlite3_bind_pointer(S,I,P) routine causes the I-th parameter in
4915
+** ^The sqlite3_bind_pointer(S,I,P,T,D) routine causes the I-th parameter in
49164916
** [prepared statement] S to have an SQL value of NULL, but to also be
4917
-** associated with the pointer P.
4918
-** ^The sqlite3_bind_pointer() routine can be used to pass
4919
-** host-language pointers into [application-defined SQL functions].
4920
-** ^A parameter that is initialized using [sqlite3_bind_pointer()] appears
4921
-** to be an ordinary SQL NULL value to everything other than
4922
-** [sqlite3_value_pointer()].
4917
+** associated with the pointer P of type T. ^D is either a NULL pointer or
4918
+** a pointer to a destructor function for P. ^SQLite will invoke the
4919
+** destructor D with a single argument of P when it is finished using
4920
+** P. The T parameter should be a static string, preferably a string
4921
+** literal. The sqlite3_bind_pointer() routine is part of the
4922
+** [pointer passing interface] added for SQLite 3.20.0.
49234923
**
49244924
** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
49254925
** for the [prepared statement] or with a prepared statement for which
49264926
** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
49274927
** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_()
@@ -4952,11 +4952,11 @@
49524952
SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
49534953
SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
49544954
SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
49554955
void(*)(void*), unsigned char encoding);
49564956
SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
4957
-SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*);
4957
+SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const char*,void(*)(void*));
49584958
SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
49594959
SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
49604960
49614961
/*
49624962
** CAPI3REF: Number Of SQL Parameters
@@ -5226,11 +5226,11 @@
52265226
** For all versions of SQLite up to and including 3.6.23.1, a call to
52275227
** [sqlite3_reset()] was required after sqlite3_step() returned anything
52285228
** other than [SQLITE_ROW] before any subsequent invocation of
52295229
** sqlite3_step(). Failure to reset the prepared statement using
52305230
** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
5231
-** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1],
5231
+** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1]),
52325232
** sqlite3_step() began
52335233
** calling [sqlite3_reset()] automatically in this circumstance rather
52345234
** than returning [SQLITE_MISUSE]. This is not considered a compatibility
52355235
** break because any application that ever receives an SQLITE_MISUSE error
52365236
** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option
@@ -5785,13 +5785,15 @@
57855785
** in the native byte-order of the host machine. ^The
57865786
** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
57875787
** extract UTF-16 strings as big-endian and little-endian respectively.
57885788
**
57895789
** ^If [sqlite3_value] object V was initialized
5790
-** using [sqlite3_bind_pointer(S,I,P)] or [sqlite3_result_pointer(C,P)], then
5791
-** sqlite3_value_pointer(V) will return the pointer P. Otherwise,
5792
-** sqlite3_value_pointer(V) returns a NULL.
5790
+** using [sqlite3_bind_pointer(S,I,P,X,D)] or [sqlite3_result_pointer(C,P,X,D)]
5791
+** and if X and Y are strings that compare equal according to strcmp(X,Y),
5792
+** then sqlite3_value_pointer(V,Y) will return the pointer P. ^Otherwise,
5793
+** sqlite3_value_pointer(V,Y) returns a NULL. The sqlite3_bind_pointer()
5794
+** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
57935795
**
57945796
** ^(The sqlite3_value_type(V) interface returns the
57955797
** [SQLITE_INTEGER | datatype code] for the initial datatype of the
57965798
** [sqlite3_value] object V. The returned value is one of [SQLITE_INTEGER],
57975799
** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].)^
@@ -5821,11 +5823,11 @@
58215823
*/
58225824
SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
58235825
SQLITE_API double sqlite3_value_double(sqlite3_value*);
58245826
SQLITE_API int sqlite3_value_int(sqlite3_value*);
58255827
SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
5826
-SQLITE_API void *sqlite3_value_pointer(sqlite3_value*);
5828
+SQLITE_API void *sqlite3_value_pointer(sqlite3_value*, const char*);
58275829
SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);
58285830
SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);
58295831
SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
58305832
SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
58315833
SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
@@ -6122,17 +6124,20 @@
61226124
** be deallocated after sqlite3_result_value() returns without harm.
61236125
** ^A [protected sqlite3_value] object may always be used where an
61246126
** [unprotected sqlite3_value] object is required, so either
61256127
** kind of [sqlite3_value] object can be used with this interface.
61266128
**
6127
-** ^The sqlite3_result_pointer(C,P) interface sets the result to an
6129
+** ^The sqlite3_result_pointer(C,P,T,D) interface sets the result to an
61286130
** SQL NULL value, just like [sqlite3_result_null(C)], except that it
6129
-** also associates the host-language pointer P with that NULL value such
6130
-** that the pointer can be retrieved within an
6131
+** also associates the host-language pointer P or type T with that
6132
+** NULL value such that the pointer can be retrieved within an
61316133
** [application-defined SQL function] using [sqlite3_value_pointer()].
6132
-** This mechanism can be used to pass non-SQL values between
6133
-** application-defined functions.
6134
+** ^If the D parameter is not NULL, then it is a pointer to a destructor
6135
+** for the P parameter. ^SQLite invokes D with P as its only argument
6136
+** when SQLite is finished with P. The T parameter should be a static
6137
+** string and preferably a string literal. The sqlite3_result_pointer()
6138
+** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
61346139
**
61356140
** If these routines are called from within the different thread
61366141
** than the one containing the application-defined function that received
61376142
** the [sqlite3_context] pointer, the results are undefined.
61386143
*/
@@ -6153,11 +6158,11 @@
61536158
void(*)(void*), unsigned char encoding);
61546159
SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
61556160
SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
61566161
SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
61576162
SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
6158
-SQLITE_API void sqlite3_result_pointer(sqlite3_context*, void*);
6163
+SQLITE_API void sqlite3_result_pointer(sqlite3_context*, void*,const char*,void(*)(void*));
61596164
SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
61606165
SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
61616166
61626167
61636168
/*
@@ -13750,16 +13755,16 @@
1375013755
#define OP_Copy 64 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
1375113756
#define OP_SCopy 65 /* synopsis: r[P2]=r[P1] */
1375213757
#define OP_IntCopy 66 /* synopsis: r[P2]=r[P1] */
1375313758
#define OP_ResultRow 67 /* synopsis: output=r[P1@P2] */
1375413759
#define OP_CollSeq 68
13755
-#define OP_Function0 69 /* synopsis: r[P3]=func(r[P2@P5]) */
13760
+#define OP_AddImm 69 /* synopsis: r[P1]=r[P1]+P2 */
1375613761
#define OP_Or 70 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
1375713762
#define OP_And 71 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
13758
-#define OP_Function 72 /* synopsis: r[P3]=func(r[P2@P5]) */
13759
-#define OP_AddImm 73 /* synopsis: r[P1]=r[P1]+P2 */
13760
-#define OP_RealAffinity 74
13763
+#define OP_RealAffinity 72
13764
+#define OP_Cast 73 /* synopsis: affinity(r[P1]) */
13765
+#define OP_Permutation 74
1376113766
#define OP_IsNull 75 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
1376213767
#define OP_NotNull 76 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
1376313768
#define OP_Ne 77 /* same as TK_NE, synopsis: IF r[P3]!=r[P1] */
1376413769
#define OP_Eq 78 /* same as TK_EQ, synopsis: IF r[P3]==r[P1] */
1376513770
#define OP_Gt 79 /* same as TK_GT, synopsis: IF r[P3]>r[P1] */
@@ -13775,82 +13780,84 @@
1377513780
#define OP_Subtract 89 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
1377613781
#define OP_Multiply 90 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
1377713782
#define OP_Divide 91 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
1377813783
#define OP_Remainder 92 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
1377913784
#define OP_Concat 93 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
13780
-#define OP_Cast 94 /* synopsis: affinity(r[P1]) */
13785
+#define OP_Compare 94 /* synopsis: r[P1@P3] <-> r[P2@P3] */
1378113786
#define OP_BitNot 95 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
13782
-#define OP_Permutation 96
13787
+#define OP_Column 96 /* synopsis: r[P3]=PX */
1378313788
#define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
13784
-#define OP_Compare 98 /* synopsis: r[P1@P3] <-> r[P2@P3] */
13785
-#define OP_Column 99 /* synopsis: r[P3]=PX */
13786
-#define OP_Affinity 100 /* synopsis: affinity(r[P1@P2]) */
13787
-#define OP_MakeRecord 101 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
13788
-#define OP_Count 102 /* synopsis: r[P2]=count() */
13789
-#define OP_ReadCookie 103
13790
-#define OP_SetCookie 104
13791
-#define OP_ReopenIdx 105 /* synopsis: root=P2 iDb=P3 */
13792
-#define OP_OpenRead 106 /* synopsis: root=P2 iDb=P3 */
13793
-#define OP_OpenWrite 107 /* synopsis: root=P2 iDb=P3 */
13794
-#define OP_OpenDup 108
13795
-#define OP_OpenAutoindex 109 /* synopsis: nColumn=P2 */
13796
-#define OP_OpenEphemeral 110 /* synopsis: nColumn=P2 */
13797
-#define OP_SorterOpen 111
13798
-#define OP_SequenceTest 112 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
13799
-#define OP_OpenPseudo 113 /* synopsis: P3 columns in r[P2] */
13800
-#define OP_Close 114
13801
-#define OP_ColumnsUsed 115
13802
-#define OP_Sequence 116 /* synopsis: r[P2]=cursor[P1].ctr++ */
13803
-#define OP_NewRowid 117 /* synopsis: r[P2]=rowid */
13804
-#define OP_Insert 118 /* synopsis: intkey=r[P3] data=r[P2] */
13805
-#define OP_InsertInt 119 /* synopsis: intkey=P3 data=r[P2] */
13806
-#define OP_Delete 120
13807
-#define OP_ResetCount 121
13808
-#define OP_SorterCompare 122 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
13809
-#define OP_SorterData 123 /* synopsis: r[P2]=data */
13810
-#define OP_RowData 124 /* synopsis: r[P2]=data */
13811
-#define OP_Rowid 125 /* synopsis: r[P2]=rowid */
13812
-#define OP_NullRow 126
13813
-#define OP_SorterInsert 127 /* synopsis: key=r[P2] */
13814
-#define OP_IdxInsert 128 /* synopsis: key=r[P2] */
13815
-#define OP_IdxDelete 129 /* synopsis: key=r[P2@P3] */
13816
-#define OP_DeferredSeek 130 /* synopsis: Move P3 to P1.rowid if needed */
13817
-#define OP_IdxRowid 131 /* synopsis: r[P2]=rowid */
13789
+#define OP_Affinity 98 /* synopsis: affinity(r[P1@P2]) */
13790
+#define OP_MakeRecord 99 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
13791
+#define OP_Count 100 /* synopsis: r[P2]=count() */
13792
+#define OP_ReadCookie 101
13793
+#define OP_SetCookie 102
13794
+#define OP_ReopenIdx 103 /* synopsis: root=P2 iDb=P3 */
13795
+#define OP_OpenRead 104 /* synopsis: root=P2 iDb=P3 */
13796
+#define OP_OpenWrite 105 /* synopsis: root=P2 iDb=P3 */
13797
+#define OP_OpenDup 106
13798
+#define OP_OpenAutoindex 107 /* synopsis: nColumn=P2 */
13799
+#define OP_OpenEphemeral 108 /* synopsis: nColumn=P2 */
13800
+#define OP_SorterOpen 109
13801
+#define OP_SequenceTest 110 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
13802
+#define OP_OpenPseudo 111 /* synopsis: P3 columns in r[P2] */
13803
+#define OP_Close 112
13804
+#define OP_ColumnsUsed 113
13805
+#define OP_Sequence 114 /* synopsis: r[P2]=cursor[P1].ctr++ */
13806
+#define OP_NewRowid 115 /* synopsis: r[P2]=rowid */
13807
+#define OP_Insert 116 /* synopsis: intkey=r[P3] data=r[P2] */
13808
+#define OP_InsertInt 117 /* synopsis: intkey=P3 data=r[P2] */
13809
+#define OP_Delete 118
13810
+#define OP_ResetCount 119
13811
+#define OP_SorterCompare 120 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
13812
+#define OP_SorterData 121 /* synopsis: r[P2]=data */
13813
+#define OP_RowData 122 /* synopsis: r[P2]=data */
13814
+#define OP_Rowid 123 /* synopsis: r[P2]=rowid */
13815
+#define OP_NullRow 124
13816
+#define OP_SorterInsert 125 /* synopsis: key=r[P2] */
13817
+#define OP_IdxInsert 126 /* synopsis: key=r[P2] */
13818
+#define OP_IdxDelete 127 /* synopsis: key=r[P2@P3] */
13819
+#define OP_DeferredSeek 128 /* synopsis: Move P3 to P1.rowid if needed */
13820
+#define OP_IdxRowid 129 /* synopsis: r[P2]=rowid */
13821
+#define OP_Destroy 130
13822
+#define OP_Clear 131
1381813823
#define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
13819
-#define OP_Destroy 133
13820
-#define OP_Clear 134
13821
-#define OP_ResetSorter 135
13822
-#define OP_CreateIndex 136 /* synopsis: r[P2]=root iDb=P1 */
13823
-#define OP_CreateTable 137 /* synopsis: r[P2]=root iDb=P1 */
13824
-#define OP_SqlExec 138
13825
-#define OP_ParseSchema 139
13826
-#define OP_LoadAnalysis 140
13827
-#define OP_DropTable 141
13828
-#define OP_DropIndex 142
13829
-#define OP_DropTrigger 143
13830
-#define OP_IntegrityCk 144
13831
-#define OP_RowSetAdd 145 /* synopsis: rowset(P1)=r[P2] */
13832
-#define OP_Param 146
13833
-#define OP_FkCounter 147 /* synopsis: fkctr[P1]+=P2 */
13834
-#define OP_MemMax 148 /* synopsis: r[P1]=max(r[P1],r[P2]) */
13835
-#define OP_OffsetLimit 149 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
13836
-#define OP_AggStep0 150 /* synopsis: accum=r[P3] step(r[P2@P5]) */
13837
-#define OP_AggStep 151 /* synopsis: accum=r[P3] step(r[P2@P5]) */
13838
-#define OP_AggFinal 152 /* synopsis: accum=r[P1] N=P2 */
13839
-#define OP_Expire 153
13840
-#define OP_TableLock 154 /* synopsis: iDb=P1 root=P2 write=P3 */
13841
-#define OP_VBegin 155
13842
-#define OP_VCreate 156
13843
-#define OP_VDestroy 157
13844
-#define OP_VOpen 158
13845
-#define OP_VColumn 159 /* synopsis: r[P3]=vcolumn(P2) */
13846
-#define OP_VRename 160
13847
-#define OP_Pagecount 161
13848
-#define OP_MaxPgcnt 162
13849
-#define OP_CursorHint 163
13850
-#define OP_Noop 164
13851
-#define OP_Explain 165
13824
+#define OP_ResetSorter 133
13825
+#define OP_CreateIndex 134 /* synopsis: r[P2]=root iDb=P1 */
13826
+#define OP_CreateTable 135 /* synopsis: r[P2]=root iDb=P1 */
13827
+#define OP_SqlExec 136
13828
+#define OP_ParseSchema 137
13829
+#define OP_LoadAnalysis 138
13830
+#define OP_DropTable 139
13831
+#define OP_DropIndex 140
13832
+#define OP_DropTrigger 141
13833
+#define OP_IntegrityCk 142
13834
+#define OP_RowSetAdd 143 /* synopsis: rowset(P1)=r[P2] */
13835
+#define OP_Param 144
13836
+#define OP_FkCounter 145 /* synopsis: fkctr[P1]+=P2 */
13837
+#define OP_MemMax 146 /* synopsis: r[P1]=max(r[P1],r[P2]) */
13838
+#define OP_OffsetLimit 147 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
13839
+#define OP_AggStep0 148 /* synopsis: accum=r[P3] step(r[P2@P5]) */
13840
+#define OP_AggStep 149 /* synopsis: accum=r[P3] step(r[P2@P5]) */
13841
+#define OP_AggFinal 150 /* synopsis: accum=r[P1] N=P2 */
13842
+#define OP_Expire 151
13843
+#define OP_TableLock 152 /* synopsis: iDb=P1 root=P2 write=P3 */
13844
+#define OP_VBegin 153
13845
+#define OP_VCreate 154
13846
+#define OP_VDestroy 155
13847
+#define OP_VOpen 156
13848
+#define OP_VColumn 157 /* synopsis: r[P3]=vcolumn(P2) */
13849
+#define OP_VRename 158
13850
+#define OP_Pagecount 159
13851
+#define OP_MaxPgcnt 160
13852
+#define OP_PureFunc0 161
13853
+#define OP_Function0 162 /* synopsis: r[P3]=func(r[P2@P5]) */
13854
+#define OP_PureFunc 163
13855
+#define OP_Function 164 /* synopsis: r[P3]=func(r[P2@P5]) */
13856
+#define OP_CursorHint 165
13857
+#define OP_Noop 166
13858
+#define OP_Explain 167
1385213859
1385313860
/* Properties such as "out2" or "jump" that are specified in
1385413861
** comments following the "case" for each opcode in the vdbe.c
1385513862
** are encoded into bitvectors as follows:
1385613863
*/
@@ -13867,23 +13874,24 @@
1386713874
/* 24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
1386813875
/* 32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
1386913876
/* 40 */ 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01, 0x03, 0x03,\
1387013877
/* 48 */ 0x03, 0x01, 0x01, 0x01, 0x02, 0x02, 0x08, 0x00,\
1387113878
/* 56 */ 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00,\
13872
-/* 64 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x26, 0x26,\
13873
-/* 72 */ 0x00, 0x02, 0x02, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\
13879
+/* 64 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x02, 0x26, 0x26,\
13880
+/* 72 */ 0x02, 0x02, 0x00, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\
1387413881
/* 80 */ 0x0b, 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26,\
13875
-/* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x02, 0x12,\
13876
-/* 96 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
13882
+/* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00, 0x12,\
13883
+/* 96 */ 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
1387713884
/* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13878
-/* 112 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
13879
-/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x04,\
13880
-/* 128 */ 0x04, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
13881
-/* 136 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13882
-/* 144 */ 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00,\
13883
-/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13884
-/* 160 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,}
13885
+/* 112 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
13886
+/* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00,\
13887
+/* 128 */ 0x00, 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10,\
13888
+/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,\
13889
+/* 144 */ 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00,\
13890
+/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
13891
+/* 160 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13892
+}
1388513893
1388613894
/* The sqlite3P2Values() routine is able to run faster if it knows
1388713895
** the value of the largest JUMP opcode. The smaller the maximum
1388813896
** JUMP opcode the better, so the mkopcodeh.tcl script that
1388913897
** generated this include file strives to group all JUMP opcodes
@@ -13977,10 +13985,12 @@
1397713985
SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
1397813986
1397913987
#ifndef SQLITE_OMIT_TRIGGER
1398013988
SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
1398113989
#endif
13990
+
13991
+SQLITE_PRIVATE int sqlite3NotPureFunc(sqlite3_context*);
1398213992
1398313993
/* Use SQLITE_ENABLE_COMMENTS to enable generation of extra comments on
1398413994
** each VDBE opcode.
1398513995
**
1398613996
** Use the SQLITE_ENABLE_MODULE_COMMENTS macro to see some extra no-op
@@ -15356,11 +15366,18 @@
1535615366
**
1535715367
** DFUNCTION(zName, nArg, iArg, bNC, xFunc)
1535815368
** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
1535915369
** adds the SQLITE_FUNC_SLOCHNG flag. Used for date & time functions
1536015370
** and functions like sqlite_version() that can change, but not during
15361
-** a single query.
15371
+** a single query. The iArg is ignored. The user-data is always set
15372
+** to a NULL pointer. The bNC parameter is not used.
15373
+**
15374
+** PURE_DATE(zName, nArg, iArg, bNC, xFunc)
15375
+** Used for "pure" date/time functions, this macro is like DFUNCTION
15376
+** except that it does set the SQLITE_FUNC_CONSTANT flags. iArg is
15377
+** ignored and the user-data for these functions is set to an
15378
+** arbitrary non-NULL pointer. The bNC parameter is not used.
1536215379
**
1536315380
** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
1536415381
** Used to create an aggregate function definition implemented by
1536515382
** the C functions xStep and xFinal. The first four parameters
1536615383
** are interpreted in the same way as the first 4 parameters to
@@ -15379,12 +15396,15 @@
1537915396
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
1538015397
#define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
1538115398
{nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1538215399
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
1538315400
#define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
15384
- {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
15385
- SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
15401
+ {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \
15402
+ 0, 0, xFunc, 0, #zName, {0} }
15403
+#define PURE_DATE(zName, nArg, iArg, bNC, xFunc) \
15404
+ {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
15405
+ (void*)&sqlite3Config, 0, xFunc, 0, #zName, {0} }
1538615406
#define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
1538715407
{nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
1538815408
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
1538915409
#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
1539015410
{nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
@@ -16681,12 +16701,12 @@
1668116701
int nErr; /* Number of errors seen */
1668216702
int nTab; /* Number of previously allocated VDBE cursors */
1668316703
int nMem; /* Number of memory cells used so far */
1668416704
int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */
1668516705
int szOpAlloc; /* Bytes of memory space allocated for Vdbe.aOp[] */
16686
- int ckBase; /* Base register of data during check constraints */
16687
- int iSelfTab; /* Table of an index whose exprs are being coded */
16706
+ int iSelfTab; /* Table for associated with an index on expr, or negative
16707
+ ** of the base register during check-constraint eval */
1668816708
int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
1668916709
int iCacheCnt; /* Counter used to generate aColCache[].lru values */
1669016710
int nLabel; /* Number of labels used */
1669116711
int *aLabel; /* Space to hold the labels */
1669216712
ExprList *pConstExpr;/* Constant expressions */
@@ -18628,12 +18648,12 @@
1862818648
*/
1862918649
struct sqlite3_value {
1863018650
union MemValue {
1863118651
double r; /* Real value used when MEM_Real is set in flags */
1863218652
i64 i; /* Integer value used when MEM_Int is set in flags */
18633
- int nZero; /* Used when bit MEM_Zero is set in flags */
18634
- void *pPtr; /* Pointer when flags=MEM_NULL and eSubtype='p' */
18653
+ int nZero; /* Extra zero bytes when MEM_Zero and MEM_Blob set */
18654
+ const char *zPType; /* Pointer type when MEM_Term|MEM_Subtype|MEM_Null */
1863518655
FuncDef *pDef; /* Used only when flags==MEM_Agg */
1863618656
RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
1863718657
VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
1863818658
} u;
1863918659
u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
@@ -18661,37 +18681,38 @@
1866118681
1866218682
/* One or more of the following flags are set to indicate the validOK
1866318683
** representations of the value stored in the Mem struct.
1866418684
**
1866518685
** If the MEM_Null flag is set, then the value is an SQL NULL value.
18666
-** No other flags may be set in this case.
18686
+** For a pointer type created using sqlite3_bind_pointer() or
18687
+** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set.
1866718688
**
1866818689
** If the MEM_Str flag is set then Mem.z points at a string representation.
1866918690
** Usually this is encoded in the same unicode encoding as the main
1867018691
** database (see below for exceptions). If the MEM_Term flag is also
1867118692
** set, then the string is nul terminated. The MEM_Int and MEM_Real
1867218693
** flags may coexist with the MEM_Str flag.
1867318694
*/
18674
-#define MEM_Null 0x0001 /* Value is NULL */
18695
+#define MEM_Null 0x0001 /* Value is NULL (or a pointer) */
1867518696
#define MEM_Str 0x0002 /* Value is a string */
1867618697
#define MEM_Int 0x0004 /* Value is an integer */
1867718698
#define MEM_Real 0x0008 /* Value is a real number */
1867818699
#define MEM_Blob 0x0010 /* Value is a BLOB */
1867918700
#define MEM_AffMask 0x001f /* Mask of affinity bits */
1868018701
#define MEM_RowSet 0x0020 /* Value is a RowSet object */
1868118702
#define MEM_Frame 0x0040 /* Value is a VdbeFrame object */
1868218703
#define MEM_Undefined 0x0080 /* Value is undefined */
1868318704
#define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */
18684
-#define MEM_TypeMask 0x81ff /* Mask of type bits */
18705
+#define MEM_TypeMask 0xc1ff /* Mask of type bits */
1868518706
1868618707
1868718708
/* Whenever Mem contains a valid string or blob representation, one of
1868818709
** the following flags must be set to determine the memory management
1868918710
** policy for Mem.z. The MEM_Term flag tells us whether or not the
1869018711
** string is \000 or \u0000 terminated
1869118712
*/
18692
-#define MEM_Term 0x0200 /* String rep is nul terminated */
18713
+#define MEM_Term 0x0200 /* String in Mem.z is zero terminated */
1869318714
#define MEM_Dyn 0x0400 /* Need to call Mem.xDel() on Mem.z */
1869418715
#define MEM_Static 0x0800 /* Mem.z points to a static string */
1869518716
#define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
1869618717
#define MEM_Agg 0x2000 /* Mem.z points to an agg function context */
1869718718
#define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
@@ -18915,11 +18936,11 @@
1891518936
#ifdef SQLITE_OMIT_FLOATING_POINT
1891618937
# define sqlite3VdbeMemSetDouble sqlite3VdbeMemSetInt64
1891718938
#else
1891818939
SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem*, double);
1891918940
#endif
18920
-SQLITE_PRIVATE void sqlite3VdbeMemSetPointer(Mem*, void*);
18941
+SQLITE_PRIVATE void sqlite3VdbeMemSetPointer(Mem*, void*, const char*, void(*)(void*));
1892118942
SQLITE_PRIVATE void sqlite3VdbeMemInit(Mem*,sqlite3*,u16);
1892218943
SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem*);
1892318944
SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem*,int);
1892418945
SQLITE_PRIVATE void sqlite3VdbeMemSetRowSet(Mem*);
1892518946
SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*);
@@ -19721,11 +19742,11 @@
1972119742
double r;
1972219743
if( parseYyyyMmDd(zDate,p)==0 ){
1972319744
return 0;
1972419745
}else if( parseHhMmSs(zDate, p)==0 ){
1972519746
return 0;
19726
- }else if( sqlite3StrICmp(zDate,"now")==0){
19747
+ }else if( sqlite3StrICmp(zDate,"now")==0 && sqlite3NotPureFunc(context) ){
1972719748
return setDateTimeToCurrent(context, p);
1972819749
}else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8) ){
1972919750
setRawDateNumber(p, r);
1973019751
return 0;
1973119752
}
@@ -20004,11 +20025,11 @@
2000420025
/* localtime
2000520026
**
2000620027
** Assuming the current time value is UTC (a.k.a. GMT), shift it to
2000720028
** show local time.
2000820029
*/
20009
- if( sqlite3_stricmp(z, "localtime")==0 ){
20030
+ if( sqlite3_stricmp(z, "localtime")==0 && sqlite3NotPureFunc(pCtx) ){
2001020031
computeJD(p);
2001120032
p->iJD += localtimeOffset(p, pCtx, &rc);
2001220033
clearYMD_HMS_TZ(p);
2001320034
}
2001420035
break;
@@ -20030,11 +20051,11 @@
2003020051
p->rawS = 0;
2003120052
rc = 0;
2003220053
}
2003320054
}
2003420055
#ifndef SQLITE_OMIT_LOCALTIME
20035
- else if( sqlite3_stricmp(z, "utc")==0 ){
20056
+ else if( sqlite3_stricmp(z, "utc")==0 && sqlite3NotPureFunc(pCtx) ){
2003620057
if( p->tzSet==0 ){
2003720058
sqlite3_int64 c1;
2003820059
computeJD(p);
2003920060
c1 = localtimeOffset(p, pCtx, &rc);
2004020061
if( rc==SQLITE_OK ){
@@ -20566,15 +20587,15 @@
2056620587
** external linkage.
2056720588
*/
2056820589
SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void){
2056920590
static FuncDef aDateTimeFuncs[] = {
2057020591
#ifndef SQLITE_OMIT_DATETIME_FUNCS
20571
- DFUNCTION(julianday, -1, 0, 0, juliandayFunc ),
20572
- DFUNCTION(date, -1, 0, 0, dateFunc ),
20573
- DFUNCTION(time, -1, 0, 0, timeFunc ),
20574
- DFUNCTION(datetime, -1, 0, 0, datetimeFunc ),
20575
- DFUNCTION(strftime, -1, 0, 0, strftimeFunc ),
20592
+ PURE_DATE(julianday, -1, 0, 0, juliandayFunc ),
20593
+ PURE_DATE(date, -1, 0, 0, dateFunc ),
20594
+ PURE_DATE(time, -1, 0, 0, timeFunc ),
20595
+ PURE_DATE(datetime, -1, 0, 0, datetimeFunc ),
20596
+ PURE_DATE(strftime, -1, 0, 0, strftimeFunc ),
2057620597
DFUNCTION(current_time, 0, 0, 0, ctimeFunc ),
2057720598
DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
2057820599
DFUNCTION(current_date, 0, 0, 0, cdateFunc ),
2057920600
#else
2058020601
STR_FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc),
@@ -30088,16 +30109,16 @@
3008830109
/* 64 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
3008930110
/* 65 */ "SCopy" OpHelp("r[P2]=r[P1]"),
3009030111
/* 66 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
3009130112
/* 67 */ "ResultRow" OpHelp("output=r[P1@P2]"),
3009230113
/* 68 */ "CollSeq" OpHelp(""),
30093
- /* 69 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
30114
+ /* 69 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
3009430115
/* 70 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
3009530116
/* 71 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
30096
- /* 72 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
30097
- /* 73 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
30098
- /* 74 */ "RealAffinity" OpHelp(""),
30117
+ /* 72 */ "RealAffinity" OpHelp(""),
30118
+ /* 73 */ "Cast" OpHelp("affinity(r[P1])"),
30119
+ /* 74 */ "Permutation" OpHelp(""),
3009930120
/* 75 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
3010030121
/* 76 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
3010130122
/* 77 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
3010230123
/* 78 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
3010330124
/* 79 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
@@ -30113,82 +30134,84 @@
3011330134
/* 89 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
3011430135
/* 90 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
3011530136
/* 91 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
3011630137
/* 92 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
3011730138
/* 93 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
30118
- /* 94 */ "Cast" OpHelp("affinity(r[P1])"),
30139
+ /* 94 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
3011930140
/* 95 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
30120
- /* 96 */ "Permutation" OpHelp(""),
30141
+ /* 96 */ "Column" OpHelp("r[P3]=PX"),
3012130142
/* 97 */ "String8" OpHelp("r[P2]='P4'"),
30122
- /* 98 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
30123
- /* 99 */ "Column" OpHelp("r[P3]=PX"),
30124
- /* 100 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
30125
- /* 101 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
30126
- /* 102 */ "Count" OpHelp("r[P2]=count()"),
30127
- /* 103 */ "ReadCookie" OpHelp(""),
30128
- /* 104 */ "SetCookie" OpHelp(""),
30129
- /* 105 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
30130
- /* 106 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
30131
- /* 107 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
30132
- /* 108 */ "OpenDup" OpHelp(""),
30133
- /* 109 */ "OpenAutoindex" OpHelp("nColumn=P2"),
30134
- /* 110 */ "OpenEphemeral" OpHelp("nColumn=P2"),
30135
- /* 111 */ "SorterOpen" OpHelp(""),
30136
- /* 112 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
30137
- /* 113 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
30138
- /* 114 */ "Close" OpHelp(""),
30139
- /* 115 */ "ColumnsUsed" OpHelp(""),
30140
- /* 116 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
30141
- /* 117 */ "NewRowid" OpHelp("r[P2]=rowid"),
30142
- /* 118 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
30143
- /* 119 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
30144
- /* 120 */ "Delete" OpHelp(""),
30145
- /* 121 */ "ResetCount" OpHelp(""),
30146
- /* 122 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
30147
- /* 123 */ "SorterData" OpHelp("r[P2]=data"),
30148
- /* 124 */ "RowData" OpHelp("r[P2]=data"),
30149
- /* 125 */ "Rowid" OpHelp("r[P2]=rowid"),
30150
- /* 126 */ "NullRow" OpHelp(""),
30151
- /* 127 */ "SorterInsert" OpHelp("key=r[P2]"),
30152
- /* 128 */ "IdxInsert" OpHelp("key=r[P2]"),
30153
- /* 129 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
30154
- /* 130 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
30155
- /* 131 */ "IdxRowid" OpHelp("r[P2]=rowid"),
30143
+ /* 98 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
30144
+ /* 99 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
30145
+ /* 100 */ "Count" OpHelp("r[P2]=count()"),
30146
+ /* 101 */ "ReadCookie" OpHelp(""),
30147
+ /* 102 */ "SetCookie" OpHelp(""),
30148
+ /* 103 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
30149
+ /* 104 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
30150
+ /* 105 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
30151
+ /* 106 */ "OpenDup" OpHelp(""),
30152
+ /* 107 */ "OpenAutoindex" OpHelp("nColumn=P2"),
30153
+ /* 108 */ "OpenEphemeral" OpHelp("nColumn=P2"),
30154
+ /* 109 */ "SorterOpen" OpHelp(""),
30155
+ /* 110 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
30156
+ /* 111 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
30157
+ /* 112 */ "Close" OpHelp(""),
30158
+ /* 113 */ "ColumnsUsed" OpHelp(""),
30159
+ /* 114 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
30160
+ /* 115 */ "NewRowid" OpHelp("r[P2]=rowid"),
30161
+ /* 116 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
30162
+ /* 117 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
30163
+ /* 118 */ "Delete" OpHelp(""),
30164
+ /* 119 */ "ResetCount" OpHelp(""),
30165
+ /* 120 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
30166
+ /* 121 */ "SorterData" OpHelp("r[P2]=data"),
30167
+ /* 122 */ "RowData" OpHelp("r[P2]=data"),
30168
+ /* 123 */ "Rowid" OpHelp("r[P2]=rowid"),
30169
+ /* 124 */ "NullRow" OpHelp(""),
30170
+ /* 125 */ "SorterInsert" OpHelp("key=r[P2]"),
30171
+ /* 126 */ "IdxInsert" OpHelp("key=r[P2]"),
30172
+ /* 127 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
30173
+ /* 128 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
30174
+ /* 129 */ "IdxRowid" OpHelp("r[P2]=rowid"),
30175
+ /* 130 */ "Destroy" OpHelp(""),
30176
+ /* 131 */ "Clear" OpHelp(""),
3015630177
/* 132 */ "Real" OpHelp("r[P2]=P4"),
30157
- /* 133 */ "Destroy" OpHelp(""),
30158
- /* 134 */ "Clear" OpHelp(""),
30159
- /* 135 */ "ResetSorter" OpHelp(""),
30160
- /* 136 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
30161
- /* 137 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
30162
- /* 138 */ "SqlExec" OpHelp(""),
30163
- /* 139 */ "ParseSchema" OpHelp(""),
30164
- /* 140 */ "LoadAnalysis" OpHelp(""),
30165
- /* 141 */ "DropTable" OpHelp(""),
30166
- /* 142 */ "DropIndex" OpHelp(""),
30167
- /* 143 */ "DropTrigger" OpHelp(""),
30168
- /* 144 */ "IntegrityCk" OpHelp(""),
30169
- /* 145 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
30170
- /* 146 */ "Param" OpHelp(""),
30171
- /* 147 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
30172
- /* 148 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
30173
- /* 149 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
30174
- /* 150 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
30175
- /* 151 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
30176
- /* 152 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
30177
- /* 153 */ "Expire" OpHelp(""),
30178
- /* 154 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
30179
- /* 155 */ "VBegin" OpHelp(""),
30180
- /* 156 */ "VCreate" OpHelp(""),
30181
- /* 157 */ "VDestroy" OpHelp(""),
30182
- /* 158 */ "VOpen" OpHelp(""),
30183
- /* 159 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
30184
- /* 160 */ "VRename" OpHelp(""),
30185
- /* 161 */ "Pagecount" OpHelp(""),
30186
- /* 162 */ "MaxPgcnt" OpHelp(""),
30187
- /* 163 */ "CursorHint" OpHelp(""),
30188
- /* 164 */ "Noop" OpHelp(""),
30189
- /* 165 */ "Explain" OpHelp(""),
30178
+ /* 133 */ "ResetSorter" OpHelp(""),
30179
+ /* 134 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
30180
+ /* 135 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
30181
+ /* 136 */ "SqlExec" OpHelp(""),
30182
+ /* 137 */ "ParseSchema" OpHelp(""),
30183
+ /* 138 */ "LoadAnalysis" OpHelp(""),
30184
+ /* 139 */ "DropTable" OpHelp(""),
30185
+ /* 140 */ "DropIndex" OpHelp(""),
30186
+ /* 141 */ "DropTrigger" OpHelp(""),
30187
+ /* 142 */ "IntegrityCk" OpHelp(""),
30188
+ /* 143 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
30189
+ /* 144 */ "Param" OpHelp(""),
30190
+ /* 145 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
30191
+ /* 146 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
30192
+ /* 147 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
30193
+ /* 148 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
30194
+ /* 149 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
30195
+ /* 150 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
30196
+ /* 151 */ "Expire" OpHelp(""),
30197
+ /* 152 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
30198
+ /* 153 */ "VBegin" OpHelp(""),
30199
+ /* 154 */ "VCreate" OpHelp(""),
30200
+ /* 155 */ "VDestroy" OpHelp(""),
30201
+ /* 156 */ "VOpen" OpHelp(""),
30202
+ /* 157 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
30203
+ /* 158 */ "VRename" OpHelp(""),
30204
+ /* 159 */ "Pagecount" OpHelp(""),
30205
+ /* 160 */ "MaxPgcnt" OpHelp(""),
30206
+ /* 161 */ "PureFunc0" OpHelp(""),
30207
+ /* 162 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
30208
+ /* 163 */ "PureFunc" OpHelp(""),
30209
+ /* 164 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
30210
+ /* 165 */ "CursorHint" OpHelp(""),
30211
+ /* 166 */ "Noop" OpHelp(""),
30212
+ /* 167 */ "Explain" OpHelp(""),
3019030213
};
3019130214
return azName[i];
3019230215
}
3019330216
#endif
3019430217
@@ -70249,11 +70272,11 @@
7024970272
** This routine is intended for use inside of assert() statements, like
7025070273
** this: assert( sqlite3VdbeCheckMemInvariants(pMem) );
7025170274
*/
7025270275
SQLITE_PRIVATE int sqlite3VdbeCheckMemInvariants(Mem *p){
7025370276
/* If MEM_Dyn is set then Mem.xDel!=0.
70254
- ** Mem.xDel is might not be initialized if MEM_Dyn is clear.
70277
+ ** Mem.xDel might not be initialized if MEM_Dyn is clear.
7025570278
*/
7025670279
assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
7025770280
7025870281
/* MEM_Dyn may only be set if Mem.szMalloc==0. In this way we
7025970282
** ensure that if Mem.szMalloc>0 then it is safe to do
@@ -70262,13 +70285,38 @@
7026270285
assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
7026370286
7026470287
/* Cannot be both MEM_Int and MEM_Real at the same time */
7026570288
assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
7026670289
70267
- /* Cannot be both MEM_Null and some other type */
70268
- assert( (p->flags & MEM_Null)==0 ||
70269
- (p->flags & (MEM_Int|MEM_Real|MEM_Str|MEM_Blob))==0 );
70290
+ if( p->flags & MEM_Null ){
70291
+ /* Cannot be both MEM_Null and some other type */
70292
+ assert( (p->flags & (MEM_Int|MEM_Real|MEM_Str|MEM_Blob
70293
+ |MEM_RowSet|MEM_Frame|MEM_Agg|MEM_Zero))==0 );
70294
+
70295
+ /* If MEM_Null is set, then either the value is a pure NULL (the usual
70296
+ ** case) or it is a pointer set using sqlite3_bind_pointer() or
70297
+ ** sqlite3_result_pointer(). If a pointer, then MEM_Term must also be
70298
+ ** set.
70299
+ */
70300
+ if( (p->flags & (MEM_Term|MEM_Subtype))==(MEM_Term|MEM_Subtype) ){
70301
+ /* This is a pointer type. There may be a flag to indicate what to
70302
+ ** do with the pointer. */
70303
+ assert( ((p->flags&MEM_Dyn)!=0 ? 1 : 0) +
70304
+ ((p->flags&MEM_Ephem)!=0 ? 1 : 0) +
70305
+ ((p->flags&MEM_Static)!=0 ? 1 : 0) <= 1 );
70306
+
70307
+ /* No other bits set */
70308
+ assert( (p->flags & ~(MEM_Null|MEM_Term|MEM_Subtype
70309
+ |MEM_Dyn|MEM_Ephem|MEM_Static))==0 );
70310
+ }else{
70311
+ /* A pure NULL might have other flags, such as MEM_Static, MEM_Dyn,
70312
+ ** MEM_Ephem, MEM_Cleared, or MEM_Subtype */
70313
+ }
70314
+ }else{
70315
+ /* The MEM_Cleared bit is only allowed on NULLs */
70316
+ assert( (p->flags & MEM_Cleared)==0 );
70317
+ }
7027070318
7027170319
/* The szMalloc field holds the correct memory allocation size */
7027270320
assert( p->szMalloc==0
7027370321
|| p->szMalloc==sqlite3DbMallocSize(p->db,p->zMalloc) );
7027470322
@@ -70927,19 +70975,29 @@
7092770975
pMem->u.i = val;
7092870976
pMem->flags = MEM_Int;
7092970977
}
7093070978
}
7093170979
70980
+/* A no-op destructor */
70981
+static void sqlite3NoopDestructor(void *p){ UNUSED_PARAMETER(p); }
70982
+
7093270983
/*
7093370984
** Set the value stored in *pMem should already be a NULL.
7093470985
** Also store a pointer to go with it.
7093570986
*/
70936
-SQLITE_PRIVATE void sqlite3VdbeMemSetPointer(Mem *pMem, void *pPtr){
70987
+SQLITE_PRIVATE void sqlite3VdbeMemSetPointer(
70988
+ Mem *pMem,
70989
+ void *pPtr,
70990
+ const char *zPType,
70991
+ void (*xDestructor)(void*)
70992
+){
7093770993
assert( pMem->flags==MEM_Null );
70938
- pMem->flags = MEM_Null|MEM_Subtype;
70939
- pMem->u.pPtr = pPtr;
70994
+ pMem->u.zPType = zPType ? zPType : "";
70995
+ pMem->z = pPtr;
70996
+ pMem->flags = MEM_Null|MEM_Dyn|MEM_Subtype|MEM_Term;
7094070997
pMem->eSubtype = 'p';
70998
+ pMem->xDel = xDestructor ? xDestructor : sqlite3NoopDestructor;
7094170999
}
7094271000
7094371001
#ifndef SQLITE_OMIT_FLOATING_POINT
7094471002
/*
7094571003
** Delete any previous value and set the value stored in *pMem to val,
@@ -76531,10 +76589,32 @@
7653176589
v->expmask |= 0x80000000;
7653276590
}else{
7653376591
v->expmask |= ((u32)1 << (iVar-1));
7653476592
}
7653576593
}
76594
+
76595
+/*
76596
+** Cause a function to throw an error if it was call from OP_PureFunc
76597
+** rather than OP_Function.
76598
+**
76599
+** OP_PureFunc means that the function must be deterministic, and should
76600
+** throw an error if it is given inputs that would make it non-deterministic.
76601
+** This routine is invoked by date/time functions that use non-deterministic
76602
+** features such as 'now'.
76603
+*/
76604
+SQLITE_PRIVATE int sqlite3NotPureFunc(sqlite3_context *pCtx){
76605
+#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
76606
+ if( pCtx->pVdbe==0 ) return 1;
76607
+#endif
76608
+ if( pCtx->pVdbe->aOp[pCtx->iOp].opcode==OP_PureFunc ){
76609
+ sqlite3_result_error(pCtx,
76610
+ "non-deterministic function in index expression or CHECK constraint",
76611
+ -1);
76612
+ return 0;
76613
+ }
76614
+ return 1;
76615
+}
7653676616
7653776617
#ifndef SQLITE_OMIT_VIRTUALTABLE
7653876618
/*
7653976619
** Transfer error message text from an sqlite3_vtab.zErrMsg (text stored
7654076620
** in memory obtained from sqlite3_malloc) into a Vdbe.zErrMsg (text stored
@@ -76841,14 +76921,19 @@
7684176921
}
7684276922
SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value *pVal){
7684376923
Mem *pMem = (Mem*)pVal;
7684476924
return ((pMem->flags & MEM_Subtype) ? pMem->eSubtype : 0);
7684576925
}
76846
-SQLITE_API void *sqlite3_value_pointer(sqlite3_value *pVal){
76926
+SQLITE_API void *sqlite3_value_pointer(sqlite3_value *pVal, const char *zPType){
7684776927
Mem *p = (Mem*)pVal;
76848
- if( (p->flags & MEM_TypeMask)==(MEM_Null|MEM_Subtype) && p->eSubtype=='p' ){
76849
- return p->u.pPtr;
76928
+ if( (p->flags&(MEM_TypeMask|MEM_Term|MEM_Subtype)) ==
76929
+ (MEM_Null|MEM_Term|MEM_Subtype)
76930
+ && zPType!=0
76931
+ && p->eSubtype=='p'
76932
+ && strcmp(p->u.zPType, zPType)==0
76933
+ ){
76934
+ return (void*)p->z;
7685076935
}else{
7685176936
return 0;
7685276937
}
7685376938
}
7685476939
SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value *pVal){
@@ -77027,15 +77112,20 @@
7702777112
}
7702877113
SQLITE_API void sqlite3_result_null(sqlite3_context *pCtx){
7702977114
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
7703077115
sqlite3VdbeMemSetNull(pCtx->pOut);
7703177116
}
77032
-SQLITE_API void sqlite3_result_pointer(sqlite3_context *pCtx, void *pPtr){
77117
+SQLITE_API void sqlite3_result_pointer(
77118
+ sqlite3_context *pCtx,
77119
+ void *pPtr,
77120
+ const char *zPType,
77121
+ void (*xDestructor)(void*)
77122
+){
7703377123
Mem *pOut = pCtx->pOut;
7703477124
assert( sqlite3_mutex_held(pOut->db->mutex) );
7703577125
sqlite3VdbeMemSetNull(pOut);
77036
- sqlite3VdbeMemSetPointer(pOut, pPtr);
77126
+ sqlite3VdbeMemSetPointer(pOut, pPtr, zPType, xDestructor);
7703777127
}
7703877128
SQLITE_API void sqlite3_result_subtype(sqlite3_context *pCtx, unsigned int eSubtype){
7703977129
Mem *pOut = pCtx->pOut;
7704077130
assert( sqlite3_mutex_held(pOut->db->mutex) );
7704177131
pOut->eSubtype = eSubtype & 0xff;
@@ -78036,17 +78126,25 @@
7803678126
if( rc==SQLITE_OK ){
7803778127
sqlite3_mutex_leave(p->db->mutex);
7803878128
}
7803978129
return rc;
7804078130
}
78041
-SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt *pStmt, int i, void *pPtr){
78131
+SQLITE_API int sqlite3_bind_pointer(
78132
+ sqlite3_stmt *pStmt,
78133
+ int i,
78134
+ void *pPtr,
78135
+ const char *zPTtype,
78136
+ void (*xDestructor)(void*)
78137
+){
7804278138
int rc;
7804378139
Vdbe *p = (Vdbe*)pStmt;
7804478140
rc = vdbeUnbind(p, i);
7804578141
if( rc==SQLITE_OK ){
78046
- sqlite3VdbeMemSetPointer(&p->aVar[i-1], pPtr);
78142
+ sqlite3VdbeMemSetPointer(&p->aVar[i-1], pPtr, zPTtype, xDestructor);
7804778143
sqlite3_mutex_leave(p->db->mutex);
78144
+ }else if( xDestructor ){
78145
+ xDestructor(pPtr);
7804878146
}
7804978147
return rc;
7805078148
}
7805178149
SQLITE_API int sqlite3_bind_text(
7805278150
sqlite3_stmt *pStmt,
@@ -80466,121 +80564,10 @@
8046680564
sqlite3VdbeMemSetInt64(&aMem[pOp->p1], 0);
8046780565
}
8046880566
break;
8046980567
}
8047080568
80471
-/* Opcode: Function0 P1 P2 P3 P4 P5
80472
-** Synopsis: r[P3]=func(r[P2@P5])
80473
-**
80474
-** Invoke a user function (P4 is a pointer to a FuncDef object that
80475
-** defines the function) with P5 arguments taken from register P2 and
80476
-** successors. The result of the function is stored in register P3.
80477
-** Register P3 must not be one of the function inputs.
80478
-**
80479
-** P1 is a 32-bit bitmask indicating whether or not each argument to the
80480
-** function was determined to be constant at compile time. If the first
80481
-** argument was constant then bit 0 of P1 is set. This is used to determine
80482
-** whether meta data associated with a user function argument using the
80483
-** sqlite3_set_auxdata() API may be safely retained until the next
80484
-** invocation of this opcode.
80485
-**
80486
-** See also: Function, AggStep, AggFinal
80487
-*/
80488
-/* Opcode: Function P1 P2 P3 P4 P5
80489
-** Synopsis: r[P3]=func(r[P2@P5])
80490
-**
80491
-** Invoke a user function (P4 is a pointer to an sqlite3_context object that
80492
-** contains a pointer to the function to be run) with P5 arguments taken
80493
-** from register P2 and successors. The result of the function is stored
80494
-** in register P3. Register P3 must not be one of the function inputs.
80495
-**
80496
-** P1 is a 32-bit bitmask indicating whether or not each argument to the
80497
-** function was determined to be constant at compile time. If the first
80498
-** argument was constant then bit 0 of P1 is set. This is used to determine
80499
-** whether meta data associated with a user function argument using the
80500
-** sqlite3_set_auxdata() API may be safely retained until the next
80501
-** invocation of this opcode.
80502
-**
80503
-** SQL functions are initially coded as OP_Function0 with P4 pointing
80504
-** to a FuncDef object. But on first evaluation, the P4 operand is
80505
-** automatically converted into an sqlite3_context object and the operation
80506
-** changed to this OP_Function opcode. In this way, the initialization of
80507
-** the sqlite3_context object occurs only once, rather than once for each
80508
-** evaluation of the function.
80509
-**
80510
-** See also: Function0, AggStep, AggFinal
80511
-*/
80512
-case OP_Function0: {
80513
- int n;
80514
- sqlite3_context *pCtx;
80515
-
80516
- assert( pOp->p4type==P4_FUNCDEF );
80517
- n = pOp->p5;
80518
- assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
80519
- assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem+1 - p->nCursor)+1) );
80520
- assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+n );
80521
- pCtx = sqlite3DbMallocRawNN(db, sizeof(*pCtx) + (n-1)*sizeof(sqlite3_value*));
80522
- if( pCtx==0 ) goto no_mem;
80523
- pCtx->pOut = 0;
80524
- pCtx->pFunc = pOp->p4.pFunc;
80525
- pCtx->iOp = (int)(pOp - aOp);
80526
- pCtx->pVdbe = p;
80527
- pCtx->argc = n;
80528
- pOp->p4type = P4_FUNCCTX;
80529
- pOp->p4.pCtx = pCtx;
80530
- pOp->opcode = OP_Function;
80531
- /* Fall through into OP_Function */
80532
-}
80533
-case OP_Function: {
80534
- int i;
80535
- sqlite3_context *pCtx;
80536
-
80537
- assert( pOp->p4type==P4_FUNCCTX );
80538
- pCtx = pOp->p4.pCtx;
80539
-
80540
- /* If this function is inside of a trigger, the register array in aMem[]
80541
- ** might change from one evaluation to the next. The next block of code
80542
- ** checks to see if the register array has changed, and if so it
80543
- ** reinitializes the relavant parts of the sqlite3_context object */
80544
- pOut = &aMem[pOp->p3];
80545
- if( pCtx->pOut != pOut ){
80546
- pCtx->pOut = pOut;
80547
- for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
80548
- }
80549
-
80550
- memAboutToChange(p, pOut);
80551
-#ifdef SQLITE_DEBUG
80552
- for(i=0; i<pCtx->argc; i++){
80553
- assert( memIsValid(pCtx->argv[i]) );
80554
- REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]);
80555
- }
80556
-#endif
80557
- MemSetTypeFlag(pOut, MEM_Null);
80558
- pCtx->fErrorOrAux = 0;
80559
- (*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */
80560
-
80561
- /* If the function returned an error, throw an exception */
80562
- if( pCtx->fErrorOrAux ){
80563
- if( pCtx->isError ){
80564
- sqlite3VdbeError(p, "%s", sqlite3_value_text(pOut));
80565
- rc = pCtx->isError;
80566
- }
80567
- sqlite3VdbeDeleteAuxData(db, &p->pAuxData, pCtx->iOp, pOp->p1);
80568
- if( rc ) goto abort_due_to_error;
80569
- }
80570
-
80571
- /* Copy the result of the function into register P3 */
80572
- if( pOut->flags & (MEM_Str|MEM_Blob) ){
80573
- sqlite3VdbeChangeEncoding(pOut, encoding);
80574
- if( sqlite3VdbeMemTooBig(pOut) ) goto too_big;
80575
- }
80576
-
80577
- REGISTER_TRACE(pOp->p3, pOut);
80578
- UPDATE_MAX_BLOBSIZE(pOut);
80579
- break;
80580
-}
80581
-
8058280569
/* Opcode: BitAnd P1 P2 P3 * *
8058380570
** Synopsis: r[P3]=r[P1]&r[P2]
8058480571
**
8058580572
** Take the bit-wise AND of the values in register P1 and P2 and
8058680573
** store the result in register P3.
@@ -85875,10 +85862,125 @@
8587585862
}
8587685863
pOut->u.i = sqlite3BtreeMaxPageCount(pBt, newMax);
8587785864
break;
8587885865
}
8587985866
#endif
85867
+
85868
+/* Opcode: Function0 P1 P2 P3 P4 P5
85869
+** Synopsis: r[P3]=func(r[P2@P5])
85870
+**
85871
+** Invoke a user function (P4 is a pointer to a FuncDef object that
85872
+** defines the function) with P5 arguments taken from register P2 and
85873
+** successors. The result of the function is stored in register P3.
85874
+** Register P3 must not be one of the function inputs.
85875
+**
85876
+** P1 is a 32-bit bitmask indicating whether or not each argument to the
85877
+** function was determined to be constant at compile time. If the first
85878
+** argument was constant then bit 0 of P1 is set. This is used to determine
85879
+** whether meta data associated with a user function argument using the
85880
+** sqlite3_set_auxdata() API may be safely retained until the next
85881
+** invocation of this opcode.
85882
+**
85883
+** See also: Function, AggStep, AggFinal
85884
+*/
85885
+/* Opcode: Function P1 P2 P3 P4 P5
85886
+** Synopsis: r[P3]=func(r[P2@P5])
85887
+**
85888
+** Invoke a user function (P4 is a pointer to an sqlite3_context object that
85889
+** contains a pointer to the function to be run) with P5 arguments taken
85890
+** from register P2 and successors. The result of the function is stored
85891
+** in register P3. Register P3 must not be one of the function inputs.
85892
+**
85893
+** P1 is a 32-bit bitmask indicating whether or not each argument to the
85894
+** function was determined to be constant at compile time. If the first
85895
+** argument was constant then bit 0 of P1 is set. This is used to determine
85896
+** whether meta data associated with a user function argument using the
85897
+** sqlite3_set_auxdata() API may be safely retained until the next
85898
+** invocation of this opcode.
85899
+**
85900
+** SQL functions are initially coded as OP_Function0 with P4 pointing
85901
+** to a FuncDef object. But on first evaluation, the P4 operand is
85902
+** automatically converted into an sqlite3_context object and the operation
85903
+** changed to this OP_Function opcode. In this way, the initialization of
85904
+** the sqlite3_context object occurs only once, rather than once for each
85905
+** evaluation of the function.
85906
+**
85907
+** See also: Function0, AggStep, AggFinal
85908
+*/
85909
+case OP_PureFunc0:
85910
+case OP_Function0: {
85911
+ int n;
85912
+ sqlite3_context *pCtx;
85913
+
85914
+ assert( pOp->p4type==P4_FUNCDEF );
85915
+ n = pOp->p5;
85916
+ assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
85917
+ assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem+1 - p->nCursor)+1) );
85918
+ assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+n );
85919
+ pCtx = sqlite3DbMallocRawNN(db, sizeof(*pCtx) + (n-1)*sizeof(sqlite3_value*));
85920
+ if( pCtx==0 ) goto no_mem;
85921
+ pCtx->pOut = 0;
85922
+ pCtx->pFunc = pOp->p4.pFunc;
85923
+ pCtx->iOp = (int)(pOp - aOp);
85924
+ pCtx->pVdbe = p;
85925
+ pCtx->argc = n;
85926
+ pOp->p4type = P4_FUNCCTX;
85927
+ pOp->p4.pCtx = pCtx;
85928
+ assert( OP_PureFunc == OP_PureFunc0+2 );
85929
+ assert( OP_Function == OP_Function0+2 );
85930
+ pOp->opcode += 2;
85931
+ /* Fall through into OP_Function */
85932
+}
85933
+case OP_PureFunc:
85934
+case OP_Function: {
85935
+ int i;
85936
+ sqlite3_context *pCtx;
85937
+
85938
+ assert( pOp->p4type==P4_FUNCCTX );
85939
+ pCtx = pOp->p4.pCtx;
85940
+
85941
+ /* If this function is inside of a trigger, the register array in aMem[]
85942
+ ** might change from one evaluation to the next. The next block of code
85943
+ ** checks to see if the register array has changed, and if so it
85944
+ ** reinitializes the relavant parts of the sqlite3_context object */
85945
+ pOut = &aMem[pOp->p3];
85946
+ if( pCtx->pOut != pOut ){
85947
+ pCtx->pOut = pOut;
85948
+ for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
85949
+ }
85950
+
85951
+ memAboutToChange(p, pOut);
85952
+#ifdef SQLITE_DEBUG
85953
+ for(i=0; i<pCtx->argc; i++){
85954
+ assert( memIsValid(pCtx->argv[i]) );
85955
+ REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]);
85956
+ }
85957
+#endif
85958
+ MemSetTypeFlag(pOut, MEM_Null);
85959
+ pCtx->fErrorOrAux = 0;
85960
+ (*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */
85961
+
85962
+ /* If the function returned an error, throw an exception */
85963
+ if( pCtx->fErrorOrAux ){
85964
+ if( pCtx->isError ){
85965
+ sqlite3VdbeError(p, "%s", sqlite3_value_text(pOut));
85966
+ rc = pCtx->isError;
85967
+ }
85968
+ sqlite3VdbeDeleteAuxData(db, &p->pAuxData, pCtx->iOp, pOp->p1);
85969
+ if( rc ) goto abort_due_to_error;
85970
+ }
85971
+
85972
+ /* Copy the result of the function into register P3 */
85973
+ if( pOut->flags & (MEM_Str|MEM_Blob) ){
85974
+ sqlite3VdbeChangeEncoding(pOut, encoding);
85975
+ if( sqlite3VdbeMemTooBig(pOut) ) goto too_big;
85976
+ }
85977
+
85978
+ REGISTER_TRACE(pOp->p3, pOut);
85979
+ UPDATE_MAX_BLOBSIZE(pOut);
85980
+ break;
85981
+}
8588085982
8588185983
8588285984
/* Opcode: Init P1 P2 * P4 *
8588385985
** Synopsis: Start at P2
8588485986
**
@@ -94727,12 +94829,13 @@
9472794829
){
9472894830
i16 iTabCol = pIdx->aiColumn[iIdxCol];
9472994831
if( iTabCol==XN_EXPR ){
9473094832
assert( pIdx->aColExpr );
9473194833
assert( pIdx->aColExpr->nExpr>iIdxCol );
94732
- pParse->iSelfTab = iTabCur;
94834
+ pParse->iSelfTab = iTabCur + 1;
9473394835
sqlite3ExprCodeCopy(pParse, pIdx->aColExpr->a[iIdxCol].pExpr, regOut);
94836
+ pParse->iSelfTab = 0;
9473494837
}else{
9473594838
sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pIdx->pTable, iTabCur,
9473694839
iTabCol, regOut);
9473794840
}
9473894841
}
@@ -94972,17 +95075,17 @@
9497295075
/* Otherwise, fall thru into the TK_COLUMN case */
9497395076
}
9497495077
case TK_COLUMN: {
9497595078
int iTab = pExpr->iTable;
9497695079
if( iTab<0 ){
94977
- if( pParse->ckBase>0 ){
95080
+ if( pParse->iSelfTab<0 ){
9497895081
/* Generating CHECK constraints or inserting into partial index */
94979
- return pExpr->iColumn + pParse->ckBase;
95082
+ return pExpr->iColumn - pParse->iSelfTab;
9498095083
}else{
9498195084
/* Coding an expression that is part of an index where column names
9498295085
** in the index refer to the table to which the index belongs */
94983
- iTab = pParse->iSelfTab;
95086
+ iTab = pParse->iSelfTab - 1;
9498495087
}
9498595088
}
9498695089
return sqlite3ExprCodeGetColumn(pParse, pExpr->pTab,
9498795090
pExpr->iColumn, iTab, target,
9498895091
pExpr->op2);
@@ -95315,12 +95418,12 @@
9531595418
#endif
9531695419
if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
9531795420
if( !pColl ) pColl = db->pDfltColl;
9531895421
sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
9531995422
}
95320
- sqlite3VdbeAddOp4(v, OP_Function0, constMask, r1, target,
95321
- (char*)pDef, P4_FUNCDEF);
95423
+ sqlite3VdbeAddOp4(v, pParse->iSelfTab ? OP_PureFunc0 : OP_Function0,
95424
+ constMask, r1, target, (char*)pDef, P4_FUNCDEF);
9532295425
sqlite3VdbeChangeP5(v, (u8)nFarg);
9532395426
if( nFarg && constMask==0 ){
9532495427
sqlite3ReleaseTempRange(pParse, r1, nFarg);
9532595428
}
9532695429
return target;
@@ -96744,12 +96847,12 @@
9674496847
*/
9674596848
#ifdef SQLITE_DEBUG
9674696849
SQLITE_PRIVATE int sqlite3NoTempsInRange(Parse *pParse, int iFirst, int iLast){
9674796850
int i;
9674896851
if( pParse->nRangeReg>0
96749
- && pParse->iRangeReg+pParse->nRangeReg<iLast
96750
- && pParse->iRangeReg>=iFirst
96852
+ && pParse->iRangeReg+pParse->nRangeReg > iFirst
96853
+ && pParse->iRangeReg <= iLast
9675196854
){
9675296855
return 0;
9675396856
}
9675496857
for(i=0; i<pParse->nTempReg; i++){
9675596858
if( pParse->aTempReg[i]>=iFirst && pParse->aTempReg[i]<=iLast ){
@@ -102088,19 +102191,10 @@
102088102191
pPk = sqlite3PrimaryKeyIndex(pTab);
102089102192
pTab->iPKey = -1;
102090102193
}else{
102091102194
pPk = sqlite3PrimaryKeyIndex(pTab);
102092102195
102093
- /* Bypass the creation of the PRIMARY KEY btree and the sqlite_master
102094
- ** table entry. This is only required if currently generating VDBE
102095
- ** code for a CREATE TABLE (not when parsing one as part of reading
102096
- ** a database schema). */
102097
- if( v ){
102098
- assert( db->init.busy==0 );
102099
- sqlite3VdbeChangeOpcode(v, pPk->tnum, OP_Goto);
102100
- }
102101
-
102102102196
/*
102103102197
** Remove all redundant columns from the PRIMARY KEY. For example, change
102104102198
** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)". Later
102105102199
** code assumes the PRIMARY KEY contains no repeated columns.
102106102200
*/
@@ -102115,10 +102209,19 @@
102115102209
}
102116102210
assert( pPk!=0 );
102117102211
pPk->isCovering = 1;
102118102212
if( !db->init.imposterTable ) pPk->uniqNotNull = 1;
102119102213
nPk = pPk->nKeyCol;
102214
+
102215
+ /* Bypass the creation of the PRIMARY KEY btree and the sqlite_master
102216
+ ** table entry. This is only required if currently generating VDBE
102217
+ ** code for a CREATE TABLE (not when parsing one as part of reading
102218
+ ** a database schema). */
102219
+ if( v && pPk->tnum>0 ){
102220
+ assert( db->init.busy==0 );
102221
+ sqlite3VdbeChangeOpcode(v, pPk->tnum, OP_Goto);
102222
+ }
102120102223
102121102224
/* The root page of the PRIMARY KEY is the table root page */
102122102225
pPk->tnum = pTab->tnum;
102123102226
102124102227
/* Update the in-memory representation of all UNIQUE indices by converting
@@ -106134,14 +106237,15 @@
106134106237
int nCol;
106135106238
106136106239
if( piPartIdxLabel ){
106137106240
if( pIdx->pPartIdxWhere ){
106138106241
*piPartIdxLabel = sqlite3VdbeMakeLabel(v);
106139
- pParse->iSelfTab = iDataCur;
106242
+ pParse->iSelfTab = iDataCur + 1;
106140106243
sqlite3ExprCachePush(pParse);
106141106244
sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel,
106142106245
SQLITE_JUMPIFNULL);
106246
+ pParse->iSelfTab = 0;
106143106247
}else{
106144106248
*piPartIdxLabel = 0;
106145106249
}
106146106250
}
106147106251
nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
@@ -110823,11 +110927,11 @@
110823110927
/* Test all CHECK constraints
110824110928
*/
110825110929
#ifndef SQLITE_OMIT_CHECK
110826110930
if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
110827110931
ExprList *pCheck = pTab->pCheck;
110828
- pParse->ckBase = regNewData+1;
110932
+ pParse->iSelfTab = -(regNewData+1);
110829110933
onError = overrideError!=OE_Default ? overrideError : OE_Abort;
110830110934
for(i=0; i<pCheck->nExpr; i++){
110831110935
int allOk;
110832110936
Expr *pExpr = pCheck->a[i].pExpr;
110833110937
if( aiChng && checkConstraintUnchanged(pExpr, aiChng, pkChng) ) continue;
@@ -110843,10 +110947,11 @@
110843110947
onError, zName, P4_TRANSIENT,
110844110948
P5_ConstraintCheck);
110845110949
}
110846110950
sqlite3VdbeResolveLabel(v, allOk);
110847110951
}
110952
+ pParse->iSelfTab = 0;
110848110953
}
110849110954
#endif /* !defined(SQLITE_OMIT_CHECK) */
110850110955
110851110956
/* If rowid is changing, make sure the new rowid does not previously
110852110957
** exist in the table.
@@ -110987,14 +111092,14 @@
110987111092
addrUniqueOk = sqlite3VdbeMakeLabel(v);
110988111093
110989111094
/* Skip partial indices for which the WHERE clause is not true */
110990111095
if( pIdx->pPartIdxWhere ){
110991111096
sqlite3VdbeAddOp2(v, OP_Null, 0, aRegIdx[ix]);
110992
- pParse->ckBase = regNewData+1;
111097
+ pParse->iSelfTab = -(regNewData+1);
110993111098
sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, addrUniqueOk,
110994111099
SQLITE_JUMPIFNULL);
110995
- pParse->ckBase = 0;
111100
+ pParse->iSelfTab = 0;
110996111101
}
110997111102
110998111103
/* Create a record for this index entry as it should appear after
110999111104
** the insert or update. Store that record in the aRegIdx[ix] register
111000111105
*/
@@ -111001,13 +111106,13 @@
111001111106
regIdx = aRegIdx[ix]+1;
111002111107
for(i=0; i<pIdx->nColumn; i++){
111003111108
int iField = pIdx->aiColumn[i];
111004111109
int x;
111005111110
if( iField==XN_EXPR ){
111006
- pParse->ckBase = regNewData+1;
111111
+ pParse->iSelfTab = -(regNewData+1);
111007111112
sqlite3ExprCodeCopy(pParse, pIdx->aColExpr->a[i].pExpr, regIdx+i);
111008
- pParse->ckBase = 0;
111113
+ pParse->iSelfTab = 0;
111009111114
VdbeComment((v, "%s column %d", pIdx->zName, i));
111010111115
}else{
111011111116
if( iField==XN_ROWID || iField==pTab->iPKey ){
111012111117
x = regNewData;
111013111118
}else{
@@ -112207,13 +112312,13 @@
112207112312
/* Version 3.20.0 and later */
112208112313
int (*prepare_v3)(sqlite3*,const char*,int,unsigned int,
112209112314
sqlite3_stmt**,const char**);
112210112315
int (*prepare16_v3)(sqlite3*,const void*,int,unsigned int,
112211112316
sqlite3_stmt**,const void**);
112212
- int (*bind_pointer)(sqlite3_stmt*,int,void*);
112213
- void (*result_pointer)(sqlite3_context*,void*);
112214
- void *(*value_pointer)(sqlite3_value*);
112317
+ int (*bind_pointer)(sqlite3_stmt*,int,void*,const char*,void(*)(void*));
112318
+ void (*result_pointer)(sqlite3_context*,void*,const char*,void(*)(void*));
112319
+ void *(*value_pointer)(sqlite3_value*,const char*);
112215112320
};
112216112321
112217112322
/*
112218112323
** This is the function signature used for all extension entry points. It
112219112324
** is also defined in the file "loadext.c".
@@ -115461,10 +115566,11 @@
115461115566
}
115462115567
aRoot[cnt] = 0;
115463115568
115464115569
/* Make sure sufficient number of registers have been allocated */
115465115570
pParse->nMem = MAX( pParse->nMem, 8+mxIdx );
115571
+ sqlite3ClearTempRegCache(pParse);
115466115572
115467115573
/* Do the b-tree integrity checks */
115468115574
sqlite3VdbeAddOp4(v, OP_IntegrityCk, 2, cnt, 1, (char*)aRoot,P4_INTARRAY);
115469115575
sqlite3VdbeChangeP5(v, (u8)i);
115470115576
addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
@@ -115526,18 +115632,19 @@
115526115632
if( db->mallocFailed==0 ){
115527115633
int addrCkFault = sqlite3VdbeMakeLabel(v);
115528115634
int addrCkOk = sqlite3VdbeMakeLabel(v);
115529115635
char *zErr;
115530115636
int k;
115531
- pParse->iSelfTab = iDataCur;
115637
+ pParse->iSelfTab = iDataCur + 1;
115532115638
sqlite3ExprCachePush(pParse);
115533115639
for(k=pCheck->nExpr-1; k>0; k--){
115534115640
sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
115535115641
}
115536115642
sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk,
115537115643
SQLITE_JUMPIFNULL);
115538115644
sqlite3VdbeResolveLabel(v, addrCkFault);
115645
+ pParse->iSelfTab = 0;
115539115646
zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
115540115647
pTab->zName);
115541115648
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
115542115649
integrityCheckResultRow(v, 3);
115543115650
sqlite3VdbeResolveLabel(v, addrCkOk);
@@ -115875,11 +115982,12 @@
115875115982
** pragmas run by future database connections.
115876115983
**
115877115984
** 0x0008 (Not yet implemented) Create indexes that might have
115878115985
** been helpful to recent queries
115879115986
**
115880
- ** The default MASK is and always shall be 0xfffe. 0xfffe means perform all ** of the optimizations listed above except Debug Mode, including new
115987
+ ** The default MASK is and always shall be 0xfffe. 0xfffe means perform all
115988
+ ** of the optimizations listed above except Debug Mode, including new
115881115989
** optimizations that have not yet been invented. If new optimizations are
115882115990
** ever added that should be off by default, those off-by-default
115883115991
** optimizations will have bitmasks of 0x10000 or larger.
115884115992
**
115885115993
** DETERMINATION OF WHEN TO RUN ANALYZE
@@ -116302,14 +116410,18 @@
116302116410
UNUSED_PARAMETER(idxNum);
116303116411
UNUSED_PARAMETER(idxStr);
116304116412
pragmaVtabCursorClear(pCsr);
116305116413
j = (pTab->pName->mPragFlg & PragFlg_Result1)!=0 ? 0 : 1;
116306116414
for(i=0; i<argc; i++, j++){
116415
+ const char *zText = (const char*)sqlite3_value_text(argv[i]);
116307116416
assert( j<ArraySize(pCsr->azArg) );
116308
- pCsr->azArg[j] = sqlite3_mprintf("%s", sqlite3_value_text(argv[i]));
116309
- if( pCsr->azArg[j]==0 ){
116310
- return SQLITE_NOMEM;
116417
+ assert( pCsr->azArg[j]==0 );
116418
+ if( zText ){
116419
+ pCsr->azArg[j] = sqlite3_mprintf("%s", zText);
116420
+ if( pCsr->azArg[j]==0 ){
116421
+ return SQLITE_NOMEM;
116422
+ }
116311116423
}
116312116424
}
116313116425
sqlite3StrAccumInit(&acc, 0, 0, 0, pTab->db->aLimit[SQLITE_LIMIT_SQL_LENGTH]);
116314116426
sqlite3StrAccumAppendAll(&acc, "PRAGMA ");
116315116427
if( pCsr->azArg[1] ){
@@ -118758,17 +118870,14 @@
118758118870
if( pS ){
118759118871
/* The "table" is actually a sub-select or a view in the FROM clause
118760118872
** of the SELECT statement. Return the declaration type and origin
118761118873
** data for the result-set column of the sub-select.
118762118874
*/
118763
- if( iCol>=0 && ALWAYS(iCol<pS->pEList->nExpr) ){
118875
+ if( iCol>=0 && iCol<pS->pEList->nExpr ){
118764118876
/* If iCol is less than zero, then the expression requests the
118765118877
** rowid of the sub-select or view. This expression is legal (see
118766118878
** test case misc2.2.2) - it always evaluates to NULL.
118767
- **
118768
- ** The ALWAYS() is because iCol>=pS->pEList->nExpr will have been
118769
- ** caught already by name resolution.
118770118879
*/
118771118880
NameContext sNC;
118772118881
Expr *p = pS->pEList->a[iCol].pExpr;
118773118882
sNC.pSrcList = pS->pSrc;
118774118883
sNC.pNext = pNC;
@@ -118874,22 +118983,10 @@
118874118983
sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
118875118984
}
118876118985
#endif /* !defined(SQLITE_OMIT_DECLTYPE) */
118877118986
}
118878118987
118879
-/*
118880
-** Return the Table objecct in the SrcList that has cursor iCursor.
118881
-** Or return NULL if no such Table object exists in the SrcList.
118882
-*/
118883
-static Table *tableWithCursor(SrcList *pList, int iCursor){
118884
- int j;
118885
- for(j=0; j<pList->nSrc; j++){
118886
- if( pList->a[j].iCursor==iCursor ) return pList->a[j].pTab;
118887
- }
118888
- return 0;
118889
-}
118890
-
118891118988
118892118989
/*
118893118990
** Compute the column names for a SELECT statement.
118894118991
**
118895118992
** The only guarantee that SQLite makes about column names is that if the
@@ -118919,28 +119016,33 @@
118919119016
** then the result column name with the table name
118920119017
** prefix, ex: TABLE.COLUMN. Otherwise use zSpan.
118921119018
*/
118922119019
static void generateColumnNames(
118923119020
Parse *pParse, /* Parser context */
118924
- SrcList *pTabList, /* The FROM clause of the SELECT */
118925
- ExprList *pEList /* Expressions defining the result set */
119021
+ Select *pSelect /* Generate column names for this SELECT statement */
118926119022
){
118927119023
Vdbe *v = pParse->pVdbe;
118928119024
int i;
118929119025
Table *pTab;
119026
+ SrcList *pTabList;
119027
+ ExprList *pEList;
118930119028
sqlite3 *db = pParse->db;
118931
- int fullName; /* TABLE.COLUMN if no AS clause and is a direct table ref */
118932
- int srcName; /* COLUMN or TABLE.COLUMN if no AS clause and is direct */
119029
+ int fullName; /* TABLE.COLUMN if no AS clause and is a direct table ref */
119030
+ int srcName; /* COLUMN or TABLE.COLUMN if no AS clause and is direct */
118933119031
118934119032
#ifndef SQLITE_OMIT_EXPLAIN
118935119033
/* If this is an EXPLAIN, skip this step */
118936119034
if( pParse->explain ){
118937119035
return;
118938119036
}
118939119037
#endif
118940119038
118941119039
if( pParse->colNamesSet || db->mallocFailed ) return;
119040
+ /* Column names are determined by the left-most term of a compound select */
119041
+ while( pSelect->pPrior ) pSelect = pSelect->pPrior;
119042
+ pTabList = pSelect->pSrc;
119043
+ pEList = pSelect->pEList;
118942119044
assert( v!=0 );
118943119045
assert( pTabList!=0 );
118944119046
pParse->colNamesSet = 1;
118945119047
fullName = (db->flags & SQLITE_FullColNames)!=0;
118946119048
srcName = (db->flags & SQLITE_ShortColNames)!=0 || fullName;
@@ -118951,16 +119053,15 @@
118951119053
assert( p!=0 );
118952119054
if( pEList->a[i].zName ){
118953119055
/* An AS clause always takes first priority */
118954119056
char *zName = pEList->a[i].zName;
118955119057
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
118956
- }else if( srcName
118957
- && (p->op==TK_COLUMN || p->op==TK_AGG_COLUMN)
118958
- && (pTab = tableWithCursor(pTabList, p->iTable))!=0
118959
- ){
119058
+ }else if( srcName && p->op==TK_COLUMN ){
118960119059
char *zCol;
118961119060
int iCol = p->iColumn;
119061
+ pTab = p->pTab;
119062
+ assert( pTab!=0 );
118962119063
if( iCol<0 ) iCol = pTab->iPKey;
118963119064
assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
118964119065
if( iCol<0 ){
118965119066
zCol = "rowid";
118966119067
}else{
@@ -119788,15 +119889,10 @@
119788119889
*/
119789119890
assert( unionTab==dest.iSDParm || dest.eDest!=priorOp );
119790119891
if( dest.eDest!=priorOp ){
119791119892
int iCont, iBreak, iStart;
119792119893
assert( p->pEList );
119793
- if( dest.eDest==SRT_Output ){
119794
- Select *pFirst = p;
119795
- while( pFirst->pPrior ) pFirst = pFirst->pPrior;
119796
- generateColumnNames(pParse, pFirst->pSrc, pFirst->pEList);
119797
- }
119798119894
iBreak = sqlite3VdbeMakeLabel(v);
119799119895
iCont = sqlite3VdbeMakeLabel(v);
119800119896
computeLimitRegisters(pParse, p, iBreak);
119801119897
sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
119802119898
iStart = sqlite3VdbeCurrentAddr(v);
@@ -119863,15 +119959,10 @@
119863119959
119864119960
/* Generate code to take the intersection of the two temporary
119865119961
** tables.
119866119962
*/
119867119963
assert( p->pEList );
119868
- if( dest.eDest==SRT_Output ){
119869
- Select *pFirst = p;
119870
- while( pFirst->pPrior ) pFirst = pFirst->pPrior;
119871
- generateColumnNames(pParse, pFirst->pSrc, pFirst->pEList);
119872
- }
119873119964
iBreak = sqlite3VdbeMakeLabel(v);
119874119965
iCont = sqlite3VdbeMakeLabel(v);
119875119966
computeLimitRegisters(pParse, p, iBreak);
119876119967
sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
119877119968
r1 = sqlite3GetTempReg(pParse);
@@ -120475,18 +120566,10 @@
120475120566
120476120567
/* Jump to the this point in order to terminate the query.
120477120568
*/
120478120569
sqlite3VdbeResolveLabel(v, labelEnd);
120479120570
120480
- /* Set the number of output columns
120481
- */
120482
- if( pDest->eDest==SRT_Output ){
120483
- Select *pFirst = pPrior;
120484
- while( pFirst->pPrior ) pFirst = pFirst->pPrior;
120485
- generateColumnNames(pParse, pFirst->pSrc, pFirst->pEList);
120486
- }
120487
-
120488120571
/* Reassembly the compound query so that it will be freed correctly
120489120572
** by the calling function */
120490120573
if( p->pPrior ){
120491120574
sqlite3SelectDelete(db, p->pPrior);
120492120575
}
@@ -120659,12 +120742,13 @@
120659120742
** and (2b) the outer query does not use subqueries other than the one
120660120743
** FROM-clause subquery that is a candidate for flattening. (2b is
120661120744
** due to ticket [2f7170d73bf9abf80] from 2015-02-09.)
120662120745
**
120663120746
** (3) The subquery is not the right operand of a LEFT JOIN
120664
-** or the subquery is not itself a join and the outer query is not
120665
-** an aggregate.
120747
+** or (a) the subquery is not itself a join and (b) the FROM clause
120748
+** of the subquery does not contain a virtual table and (c) the
120749
+** outer query is not an aggregate.
120666120750
**
120667120751
** (4) The subquery is not DISTINCT.
120668120752
**
120669120753
** (**) At one point restrictions (4) and (5) defined a subset of DISTINCT
120670120754
** sub-queries that were excluded from this optimization. Restriction
@@ -120776,11 +120860,10 @@
120776120860
Select *pParent; /* Current UNION ALL term of the other query */
120777120861
Select *pSub; /* The inner query or "subquery" */
120778120862
Select *pSub1; /* Pointer to the rightmost select in sub-query */
120779120863
SrcList *pSrc; /* The FROM clause of the outer query */
120780120864
SrcList *pSubSrc; /* The FROM clause of the subquery */
120781
- ExprList *pList; /* The result set of the outer query */
120782120865
int iParent; /* VDBE cursor number of the pSub result set temp table */
120783120866
int iNewParent = -1;/* Replacement table for iParent */
120784120867
int isLeftJoin = 0; /* True if pSub is the right side of a LEFT JOIN */
120785120868
int i; /* Loop counter */
120786120869
Expr *pWhere; /* The WHERE clause */
@@ -120865,11 +120948,11 @@
120865120948
**
120866120949
** See also tickets #306, #350, and #3300.
120867120950
*/
120868120951
if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
120869120952
isLeftJoin = 1;
120870
- if( pSubSrc->nSrc>1 || isAgg ){
120953
+ if( pSubSrc->nSrc>1 || isAgg || IsVirtual(pSubSrc->a[0].pTab) ){
120871120954
return 0; /* Restriction (3) */
120872120955
}
120873120956
}
120874120957
#ifdef SQLITE_EXTRA_IFNULLROW
120875120958
else if( iFrom>0 && !isAgg ){
@@ -121101,18 +121184,10 @@
121101121184
** \_____________________ outer query ______________________________/
121102121185
**
121103121186
** We look at every expression in the outer query and every place we see
121104121187
** "a" we substitute "x*3" and every place we see "b" we substitute "y+10".
121105121188
*/
121106
- pList = pParent->pEList;
121107
- for(i=0; i<pList->nExpr; i++){
121108
- if( pList->a[i].zName==0 ){
121109
- char *zName = sqlite3DbStrDup(db, pList->a[i].zSpan);
121110
- sqlite3Dequote(zName);
121111
- pList->a[i].zName = zName;
121112
- }
121113
- }
121114121189
if( pSub->pOrderBy ){
121115121190
/* At this point, any non-zero iOrderByCol values indicate that the
121116121191
** ORDER BY column expression is identical to the iOrderByCol'th
121117121192
** expression returned by SELECT statement pSub. Since these values
121118121193
** do not necessarily correspond to columns in SELECT statement pParent,
@@ -122537,10 +122612,18 @@
122537122612
if( sqlite3SelectTrace & 0x100 ){
122538122613
SELECTTRACE(0x100,pParse,p, ("after name resolution:\n"));
122539122614
sqlite3TreeViewSelect(0, p, 0);
122540122615
}
122541122616
#endif
122617
+
122618
+ /* Get a pointer the VDBE under construction, allocating a new VDBE if one
122619
+ ** does not already exist */
122620
+ v = sqlite3GetVdbe(pParse);
122621
+ if( v==0 ) goto select_end;
122622
+ if( pDest->eDest==SRT_Output ){
122623
+ generateColumnNames(pParse, p);
122624
+ }
122542122625
122543122626
/* Try to flatten subqueries in the FROM clause up into the main query
122544122627
*/
122545122628
#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
122546122629
for(i=0; !p->pPrior && i<pTabList->nSrc; i++){
@@ -122573,15 +122656,10 @@
122573122656
sSort.pOrderBy = p->pOrderBy;
122574122657
}
122575122658
}
122576122659
#endif
122577122660
122578
- /* Get a pointer the VDBE under construction, allocating a new VDBE if one
122579
- ** does not already exist */
122580
- v = sqlite3GetVdbe(pParse);
122581
- if( v==0 ) goto select_end;
122582
-
122583122661
#ifndef SQLITE_OMIT_COMPOUND_SELECT
122584122662
/* Handle compound SELECT statements using the separate multiSelect()
122585122663
** procedure.
122586122664
*/
122587122665
if( p->pPrior ){
@@ -123377,16 +123455,10 @@
123377123455
** successful coding of the SELECT.
123378123456
*/
123379123457
select_end:
123380123458
explainSetInteger(pParse->iSelectId, iRestoreSelectId);
123381123459
123382
- /* Identify column names if results of the SELECT are to be output.
123383
- */
123384
- if( rc==SQLITE_OK && pDest->eDest==SRT_Output ){
123385
- generateColumnNames(pParse, pTabList, pEList);
123386
- }
123387
-
123388123460
sqlite3DbFree(db, sAggInfo.aCol);
123389123461
sqlite3DbFree(db, sAggInfo.aFunc);
123390123462
#if SELECTTRACE_ENABLED
123391123463
SELECTTRACE(1,pParse,p,("end processing\n"));
123392123464
pParse->nSelectIndent--;
@@ -131980,10 +132052,19 @@
131980132052
Bitmask notReady /* Tables in outer loops of the join */
131981132053
){
131982132054
char aff;
131983132055
if( pTerm->leftCursor!=pSrc->iCursor ) return 0;
131984132056
if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) return 0;
132057
+ if( (pSrc->fg.jointype & JT_LEFT)
132058
+ && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
132059
+ && (pTerm->eOperator & WO_IS)
132060
+ ){
132061
+ /* Cannot use an IS term from the WHERE clause as an index driver for
132062
+ ** the RHS of a LEFT JOIN. Such a term can only be used if it is from
132063
+ ** the ON clause. */
132064
+ return 0;
132065
+ }
131985132066
if( (pTerm->prereqRight & notReady)!=0 ) return 0;
131986132067
if( pTerm->u.leftColumn<0 ) return 0;
131987132068
aff = pSrc->pTab->aCol[pTerm->u.leftColumn].affinity;
131988132069
if( !sqlite3IndexAffinityOk(pTerm->pExpr, aff) ) return 0;
131989132070
testcase( pTerm->pExpr->op==TK_IS );
@@ -150278,11 +150359,11 @@
150278150359
assert( iCol>=0 && iCol<=p->nColumn+2 );
150279150360
150280150361
switch( iCol-p->nColumn ){
150281150362
case 0:
150282150363
/* The special 'table-name' column */
150283
- sqlite3_result_pointer(pCtx, pCsr);
150364
+ sqlite3_result_pointer(pCtx, pCsr, "fts3cursor", 0);
150284150365
break;
150285150366
150286150367
case 1:
150287150368
/* The docid column */
150288150369
sqlite3_result_int64(pCtx, pCsr->iPrevId);
@@ -150497,11 +150578,11 @@
150497150578
const char *zFunc, /* Function name */
150498150579
sqlite3_value *pVal, /* argv[0] passed to function */
150499150580
Fts3Cursor **ppCsr /* OUT: Store cursor handle here */
150500150581
){
150501150582
int rc;
150502
- *ppCsr = (Fts3Cursor*)sqlite3_value_pointer(pVal);
150583
+ *ppCsr = (Fts3Cursor*)sqlite3_value_pointer(pVal, "fts3cursor");
150503150584
if( (*ppCsr)!=0 ){
150504150585
rc = SQLITE_OK;
150505150586
}else{
150506150587
char *zErr = sqlite3_mprintf("illegal first argument to %s", zFunc);
150507150588
sqlite3_result_error(pContext, zErr, -1);
@@ -165512,26 +165593,18 @@
165512165593
int (*xQueryFunc)(sqlite3_rtree_query_info*);
165513165594
void (*xDestructor)(void*);
165514165595
void *pContext;
165515165596
};
165516165597
165517
-
165518
-/*
165519
-** Value for the first field of every RtreeMatchArg object. The MATCH
165520
-** operator tests that the first field of a blob operand matches this
165521
-** value to avoid operating on invalid blobs (which could cause a segfault).
165522
-*/
165523
-#define RTREE_GEOMETRY_MAGIC 0x891245AB
165524
-
165525165598
/*
165526165599
** An instance of this structure (in the form of a BLOB) is returned by
165527165600
** the SQL functions that sqlite3_rtree_geometry_callback() and
165528165601
** sqlite3_rtree_query_callback() create, and is read as the right-hand
165529165602
** operand to the MATCH operator of an R-Tree.
165530165603
*/
165531165604
struct RtreeMatchArg {
165532
- u32 magic; /* Always RTREE_GEOMETRY_MAGIC */
165605
+ u32 iSize; /* Size of this object */
165533165606
RtreeGeomCallback cb; /* Info about the callback functions */
165534165607
int nParam; /* Number of parameters to the SQL function */
165535165608
sqlite3_value **apSqlParam; /* Original SQL parameter values */
165536165609
RtreeDValue aParam[1]; /* Values for parameters to the SQL function */
165537165610
};
@@ -166822,37 +166895,21 @@
166822166895
** as the second argument for a MATCH constraint. The value passed as the
166823166896
** first argument to this function is the right-hand operand to the MATCH
166824166897
** operator.
166825166898
*/
166826166899
static int deserializeGeometry(sqlite3_value *pValue, RtreeConstraint *pCons){
166827
- RtreeMatchArg *pBlob; /* BLOB returned by geometry function */
166900
+ RtreeMatchArg *pBlob, *pSrc; /* BLOB returned by geometry function */
166828166901
sqlite3_rtree_query_info *pInfo; /* Callback information */
166829
- int nBlob; /* Size of the geometry function blob */
166830
- int nExpected; /* Expected size of the BLOB */
166831
-
166832
- /* Check that value is actually a blob. */
166833
- if( sqlite3_value_type(pValue)!=SQLITE_BLOB ) return SQLITE_ERROR;
166834
-
166835
- /* Check that the blob is roughly the right size. */
166836
- nBlob = sqlite3_value_bytes(pValue);
166837
- if( nBlob<(int)sizeof(RtreeMatchArg) ){
166838
- return SQLITE_ERROR;
166839
- }
166840
-
166841
- pInfo = (sqlite3_rtree_query_info*)sqlite3_malloc( sizeof(*pInfo)+nBlob );
166902
+
166903
+ pSrc = sqlite3_value_pointer(pValue, "RtreeMatchArg");
166904
+ if( pSrc==0 ) return SQLITE_ERROR;
166905
+ pInfo = (sqlite3_rtree_query_info*)
166906
+ sqlite3_malloc64( sizeof(*pInfo)+pSrc->iSize );
166842166907
if( !pInfo ) return SQLITE_NOMEM;
166843166908
memset(pInfo, 0, sizeof(*pInfo));
166844166909
pBlob = (RtreeMatchArg*)&pInfo[1];
166845
-
166846
- memcpy(pBlob, sqlite3_value_blob(pValue), nBlob);
166847
- nExpected = (int)(sizeof(RtreeMatchArg) +
166848
- pBlob->nParam*sizeof(sqlite3_value*) +
166849
- (pBlob->nParam-1)*sizeof(RtreeDValue));
166850
- if( pBlob->magic!=RTREE_GEOMETRY_MAGIC || nBlob!=nExpected ){
166851
- sqlite3_free(pInfo);
166852
- return SQLITE_ERROR;
166853
- }
166910
+ memcpy(pBlob, pSrc, pSrc->iSize);
166854166911
pInfo->pContext = pBlob->cb.pContext;
166855166912
pInfo->nParam = pBlob->nParam;
166856166913
pInfo->aParam = pBlob->aParam;
166857166914
pInfo->apSqlParam = pBlob->apSqlParam;
166858166915
@@ -168886,11 +168943,11 @@
168886168943
pBlob = (RtreeMatchArg *)sqlite3_malloc(nBlob);
168887168944
if( !pBlob ){
168888168945
sqlite3_result_error_nomem(ctx);
168889168946
}else{
168890168947
int i;
168891
- pBlob->magic = RTREE_GEOMETRY_MAGIC;
168948
+ pBlob->iSize = nBlob;
168892168949
pBlob->cb = pGeomCtx[0];
168893168950
pBlob->apSqlParam = (sqlite3_value**)&pBlob->aParam[nArg];
168894168951
pBlob->nParam = nArg;
168895168952
for(i=0; i<nArg; i++){
168896168953
pBlob->apSqlParam[i] = sqlite3_value_dup(aArg[i]);
@@ -168903,11 +168960,11 @@
168903168960
}
168904168961
if( memErr ){
168905168962
sqlite3_result_error_nomem(ctx);
168906168963
rtreeMatchArgFree(pBlob);
168907168964
}else{
168908
- sqlite3_result_blob(ctx, pBlob, nBlob, rtreeMatchArgFree);
168965
+ sqlite3_result_pointer(ctx, pBlob, "RtreeMatchArg", rtreeMatchArgFree);
168909168966
}
168910168967
}
168911168968
}
168912168969
168913168970
/*
@@ -200196,19 +200253,18 @@
200196200253
}
200197200254
200198200255
static void fts5Fts5Func(
200199200256
sqlite3_context *pCtx, /* Function call context */
200200200257
int nArg, /* Number of args */
200201
- sqlite3_value **apUnused /* Function arguments */
200258
+ sqlite3_value **apArg /* Function arguments */
200202200259
){
200203200260
Fts5Global *pGlobal = (Fts5Global*)sqlite3_user_data(pCtx);
200204
- char buf[8];
200205
- UNUSED_PARAM2(nArg, apUnused);
200206
- assert( nArg==0 );
200207
- assert( sizeof(buf)>=sizeof(pGlobal) );
200208
- memcpy(buf, (void*)&pGlobal, sizeof(pGlobal));
200209
- sqlite3_result_blob(pCtx, buf, sizeof(pGlobal), SQLITE_TRANSIENT);
200261
+ fts5_api **ppApi;
200262
+ UNUSED_PARAM(nArg);
200263
+ assert( nArg==1 );
200264
+ ppApi = (fts5_api**)sqlite3_value_pointer(apArg[0], "fts5_api_ptr");
200265
+ if( ppApi ) *ppApi = &pGlobal->api;
200210200266
}
200211200267
200212200268
/*
200213200269
** Implementation of fts5_source_id() function.
200214200270
*/
@@ -200217,11 +200273,11 @@
200217200273
int nArg, /* Number of args */
200218200274
sqlite3_value **apUnused /* Function arguments */
200219200275
){
200220200276
assert( nArg==0 );
200221200277
UNUSED_PARAM2(nArg, apUnused);
200222
- sqlite3_result_text(pCtx, "fts5: 2017-07-15 13:49:56 47cf83a0682b7b3219cf255457f5fbe05f3c1f46be42f6bbab33b78a57a252f6", -1, SQLITE_TRANSIENT);
200278
+ sqlite3_result_text(pCtx, "fts5: 2017-08-01 13:24:15 9501e22dfeebdcefa783575e47c60b514d7c2e0cad73b2a496c0bc4b680900a8", -1, SQLITE_TRANSIENT);
200223200279
}
200224200280
200225200281
static int fts5Init(sqlite3 *db){
200226200282
static const sqlite3_module fts5Mod = {
200227200283
/* iVersion */ 2,
@@ -200269,11 +200325,11 @@
200269200325
if( rc==SQLITE_OK ) rc = sqlite3Fts5AuxInit(&pGlobal->api);
200270200326
if( rc==SQLITE_OK ) rc = sqlite3Fts5TokenizerInit(&pGlobal->api);
200271200327
if( rc==SQLITE_OK ) rc = sqlite3Fts5VocabInit(pGlobal, db);
200272200328
if( rc==SQLITE_OK ){
200273200329
rc = sqlite3_create_function(
200274
- db, "fts5", 0, SQLITE_UTF8, p, fts5Fts5Func, 0, 0
200330
+ db, "fts5", 1, SQLITE_UTF8, p, fts5Fts5Func, 0, 0
200275200331
);
200276200332
}
200277200333
if( rc==SQLITE_OK ){
200278200334
rc = sqlite3_create_function(
200279200335
db, "fts5_source_id", 0, SQLITE_UTF8, p, fts5SourceIdFunc, 0, 0
200280200336
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1150,11 +1150,11 @@
1150 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1151 ** [sqlite_version()] and [sqlite_source_id()].
1152 */
1153 #define SQLITE_VERSION "3.20.0"
1154 #define SQLITE_VERSION_NUMBER 3020000
1155 #define SQLITE_SOURCE_ID "2017-07-15 13:49:56 47cf83a0682b7b3219cf255457f5fbe05f3c1f46be42f6bbab33b78a57a252f6"
1156
1157 /*
1158 ** CAPI3REF: Run-Time Library Version Numbers
1159 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1160 **
@@ -4672,11 +4672,11 @@
4672 );
4673 SQLITE_API int sqlite3_prepare16_v3(
4674 sqlite3 *db, /* Database handle */
4675 const void *zSql, /* SQL statement, UTF-16 encoded */
4676 int nByte, /* Maximum length of zSql in bytes. */
4677 unsigned int prepFalgs, /* Zero or more SQLITE_PREPARE_ flags */
4678 sqlite3_stmt **ppStmt, /* OUT: Statement handle */
4679 const void **pzTail /* OUT: Pointer to unused portion of zSql */
4680 );
4681
4682 /*
@@ -4910,18 +4910,18 @@
4910 ** Zeroblobs are intended to serve as placeholders for BLOBs whose
4911 ** content is later written using
4912 ** [sqlite3_blob_open | incremental BLOB I/O] routines.
4913 ** ^A negative value for the zeroblob results in a zero-length BLOB.
4914 **
4915 ** ^The sqlite3_bind_pointer(S,I,P) routine causes the I-th parameter in
4916 ** [prepared statement] S to have an SQL value of NULL, but to also be
4917 ** associated with the pointer P.
4918 ** ^The sqlite3_bind_pointer() routine can be used to pass
4919 ** host-language pointers into [application-defined SQL functions].
4920 ** ^A parameter that is initialized using [sqlite3_bind_pointer()] appears
4921 ** to be an ordinary SQL NULL value to everything other than
4922 ** [sqlite3_value_pointer()].
4923 **
4924 ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
4925 ** for the [prepared statement] or with a prepared statement for which
4926 ** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
4927 ** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_()
@@ -4952,11 +4952,11 @@
4952 SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
4953 SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
4954 SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
4955 void(*)(void*), unsigned char encoding);
4956 SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
4957 SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*);
4958 SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
4959 SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
4960
4961 /*
4962 ** CAPI3REF: Number Of SQL Parameters
@@ -5226,11 +5226,11 @@
5226 ** For all versions of SQLite up to and including 3.6.23.1, a call to
5227 ** [sqlite3_reset()] was required after sqlite3_step() returned anything
5228 ** other than [SQLITE_ROW] before any subsequent invocation of
5229 ** sqlite3_step(). Failure to reset the prepared statement using
5230 ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
5231 ** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1],
5232 ** sqlite3_step() began
5233 ** calling [sqlite3_reset()] automatically in this circumstance rather
5234 ** than returning [SQLITE_MISUSE]. This is not considered a compatibility
5235 ** break because any application that ever receives an SQLITE_MISUSE error
5236 ** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option
@@ -5785,13 +5785,15 @@
5785 ** in the native byte-order of the host machine. ^The
5786 ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
5787 ** extract UTF-16 strings as big-endian and little-endian respectively.
5788 **
5789 ** ^If [sqlite3_value] object V was initialized
5790 ** using [sqlite3_bind_pointer(S,I,P)] or [sqlite3_result_pointer(C,P)], then
5791 ** sqlite3_value_pointer(V) will return the pointer P. Otherwise,
5792 ** sqlite3_value_pointer(V) returns a NULL.
 
 
5793 **
5794 ** ^(The sqlite3_value_type(V) interface returns the
5795 ** [SQLITE_INTEGER | datatype code] for the initial datatype of the
5796 ** [sqlite3_value] object V. The returned value is one of [SQLITE_INTEGER],
5797 ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].)^
@@ -5821,11 +5823,11 @@
5821 */
5822 SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
5823 SQLITE_API double sqlite3_value_double(sqlite3_value*);
5824 SQLITE_API int sqlite3_value_int(sqlite3_value*);
5825 SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
5826 SQLITE_API void *sqlite3_value_pointer(sqlite3_value*);
5827 SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);
5828 SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);
5829 SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
5830 SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
5831 SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
@@ -6122,17 +6124,20 @@
6122 ** be deallocated after sqlite3_result_value() returns without harm.
6123 ** ^A [protected sqlite3_value] object may always be used where an
6124 ** [unprotected sqlite3_value] object is required, so either
6125 ** kind of [sqlite3_value] object can be used with this interface.
6126 **
6127 ** ^The sqlite3_result_pointer(C,P) interface sets the result to an
6128 ** SQL NULL value, just like [sqlite3_result_null(C)], except that it
6129 ** also associates the host-language pointer P with that NULL value such
6130 ** that the pointer can be retrieved within an
6131 ** [application-defined SQL function] using [sqlite3_value_pointer()].
6132 ** This mechanism can be used to pass non-SQL values between
6133 ** application-defined functions.
 
 
 
6134 **
6135 ** If these routines are called from within the different thread
6136 ** than the one containing the application-defined function that received
6137 ** the [sqlite3_context] pointer, the results are undefined.
6138 */
@@ -6153,11 +6158,11 @@
6153 void(*)(void*), unsigned char encoding);
6154 SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
6155 SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
6156 SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
6157 SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
6158 SQLITE_API void sqlite3_result_pointer(sqlite3_context*, void*);
6159 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
6160 SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
6161
6162
6163 /*
@@ -13750,16 +13755,16 @@
13750 #define OP_Copy 64 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
13751 #define OP_SCopy 65 /* synopsis: r[P2]=r[P1] */
13752 #define OP_IntCopy 66 /* synopsis: r[P2]=r[P1] */
13753 #define OP_ResultRow 67 /* synopsis: output=r[P1@P2] */
13754 #define OP_CollSeq 68
13755 #define OP_Function0 69 /* synopsis: r[P3]=func(r[P2@P5]) */
13756 #define OP_Or 70 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
13757 #define OP_And 71 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
13758 #define OP_Function 72 /* synopsis: r[P3]=func(r[P2@P5]) */
13759 #define OP_AddImm 73 /* synopsis: r[P1]=r[P1]+P2 */
13760 #define OP_RealAffinity 74
13761 #define OP_IsNull 75 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
13762 #define OP_NotNull 76 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
13763 #define OP_Ne 77 /* same as TK_NE, synopsis: IF r[P3]!=r[P1] */
13764 #define OP_Eq 78 /* same as TK_EQ, synopsis: IF r[P3]==r[P1] */
13765 #define OP_Gt 79 /* same as TK_GT, synopsis: IF r[P3]>r[P1] */
@@ -13775,82 +13780,84 @@
13775 #define OP_Subtract 89 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
13776 #define OP_Multiply 90 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
13777 #define OP_Divide 91 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
13778 #define OP_Remainder 92 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
13779 #define OP_Concat 93 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
13780 #define OP_Cast 94 /* synopsis: affinity(r[P1]) */
13781 #define OP_BitNot 95 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
13782 #define OP_Permutation 96
13783 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
13784 #define OP_Compare 98 /* synopsis: r[P1@P3] <-> r[P2@P3] */
13785 #define OP_Column 99 /* synopsis: r[P3]=PX */
13786 #define OP_Affinity 100 /* synopsis: affinity(r[P1@P2]) */
13787 #define OP_MakeRecord 101 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
13788 #define OP_Count 102 /* synopsis: r[P2]=count() */
13789 #define OP_ReadCookie 103
13790 #define OP_SetCookie 104
13791 #define OP_ReopenIdx 105 /* synopsis: root=P2 iDb=P3 */
13792 #define OP_OpenRead 106 /* synopsis: root=P2 iDb=P3 */
13793 #define OP_OpenWrite 107 /* synopsis: root=P2 iDb=P3 */
13794 #define OP_OpenDup 108
13795 #define OP_OpenAutoindex 109 /* synopsis: nColumn=P2 */
13796 #define OP_OpenEphemeral 110 /* synopsis: nColumn=P2 */
13797 #define OP_SorterOpen 111
13798 #define OP_SequenceTest 112 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
13799 #define OP_OpenPseudo 113 /* synopsis: P3 columns in r[P2] */
13800 #define OP_Close 114
13801 #define OP_ColumnsUsed 115
13802 #define OP_Sequence 116 /* synopsis: r[P2]=cursor[P1].ctr++ */
13803 #define OP_NewRowid 117 /* synopsis: r[P2]=rowid */
13804 #define OP_Insert 118 /* synopsis: intkey=r[P3] data=r[P2] */
13805 #define OP_InsertInt 119 /* synopsis: intkey=P3 data=r[P2] */
13806 #define OP_Delete 120
13807 #define OP_ResetCount 121
13808 #define OP_SorterCompare 122 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
13809 #define OP_SorterData 123 /* synopsis: r[P2]=data */
13810 #define OP_RowData 124 /* synopsis: r[P2]=data */
13811 #define OP_Rowid 125 /* synopsis: r[P2]=rowid */
13812 #define OP_NullRow 126
13813 #define OP_SorterInsert 127 /* synopsis: key=r[P2] */
13814 #define OP_IdxInsert 128 /* synopsis: key=r[P2] */
13815 #define OP_IdxDelete 129 /* synopsis: key=r[P2@P3] */
13816 #define OP_DeferredSeek 130 /* synopsis: Move P3 to P1.rowid if needed */
13817 #define OP_IdxRowid 131 /* synopsis: r[P2]=rowid */
13818 #define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
13819 #define OP_Destroy 133
13820 #define OP_Clear 134
13821 #define OP_ResetSorter 135
13822 #define OP_CreateIndex 136 /* synopsis: r[P2]=root iDb=P1 */
13823 #define OP_CreateTable 137 /* synopsis: r[P2]=root iDb=P1 */
13824 #define OP_SqlExec 138
13825 #define OP_ParseSchema 139
13826 #define OP_LoadAnalysis 140
13827 #define OP_DropTable 141
13828 #define OP_DropIndex 142
13829 #define OP_DropTrigger 143
13830 #define OP_IntegrityCk 144
13831 #define OP_RowSetAdd 145 /* synopsis: rowset(P1)=r[P2] */
13832 #define OP_Param 146
13833 #define OP_FkCounter 147 /* synopsis: fkctr[P1]+=P2 */
13834 #define OP_MemMax 148 /* synopsis: r[P1]=max(r[P1],r[P2]) */
13835 #define OP_OffsetLimit 149 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
13836 #define OP_AggStep0 150 /* synopsis: accum=r[P3] step(r[P2@P5]) */
13837 #define OP_AggStep 151 /* synopsis: accum=r[P3] step(r[P2@P5]) */
13838 #define OP_AggFinal 152 /* synopsis: accum=r[P1] N=P2 */
13839 #define OP_Expire 153
13840 #define OP_TableLock 154 /* synopsis: iDb=P1 root=P2 write=P3 */
13841 #define OP_VBegin 155
13842 #define OP_VCreate 156
13843 #define OP_VDestroy 157
13844 #define OP_VOpen 158
13845 #define OP_VColumn 159 /* synopsis: r[P3]=vcolumn(P2) */
13846 #define OP_VRename 160
13847 #define OP_Pagecount 161
13848 #define OP_MaxPgcnt 162
13849 #define OP_CursorHint 163
13850 #define OP_Noop 164
13851 #define OP_Explain 165
 
 
13852
13853 /* Properties such as "out2" or "jump" that are specified in
13854 ** comments following the "case" for each opcode in the vdbe.c
13855 ** are encoded into bitvectors as follows:
13856 */
@@ -13867,23 +13874,24 @@
13867 /* 24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
13868 /* 32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
13869 /* 40 */ 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01, 0x03, 0x03,\
13870 /* 48 */ 0x03, 0x01, 0x01, 0x01, 0x02, 0x02, 0x08, 0x00,\
13871 /* 56 */ 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00,\
13872 /* 64 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x26, 0x26,\
13873 /* 72 */ 0x00, 0x02, 0x02, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\
13874 /* 80 */ 0x0b, 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26,\
13875 /* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x02, 0x12,\
13876 /* 96 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
13877 /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13878 /* 112 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
13879 /* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x04,\
13880 /* 128 */ 0x04, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
13881 /* 136 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13882 /* 144 */ 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00,\
13883 /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13884 /* 160 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,}
 
13885
13886 /* The sqlite3P2Values() routine is able to run faster if it knows
13887 ** the value of the largest JUMP opcode. The smaller the maximum
13888 ** JUMP opcode the better, so the mkopcodeh.tcl script that
13889 ** generated this include file strives to group all JUMP opcodes
@@ -13977,10 +13985,12 @@
13977 SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
13978
13979 #ifndef SQLITE_OMIT_TRIGGER
13980 SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
13981 #endif
 
 
13982
13983 /* Use SQLITE_ENABLE_COMMENTS to enable generation of extra comments on
13984 ** each VDBE opcode.
13985 **
13986 ** Use the SQLITE_ENABLE_MODULE_COMMENTS macro to see some extra no-op
@@ -15356,11 +15366,18 @@
15356 **
15357 ** DFUNCTION(zName, nArg, iArg, bNC, xFunc)
15358 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
15359 ** adds the SQLITE_FUNC_SLOCHNG flag. Used for date & time functions
15360 ** and functions like sqlite_version() that can change, but not during
15361 ** a single query.
 
 
 
 
 
 
 
15362 **
15363 ** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
15364 ** Used to create an aggregate function definition implemented by
15365 ** the C functions xStep and xFinal. The first four parameters
15366 ** are interpreted in the same way as the first 4 parameters to
@@ -15379,12 +15396,15 @@
15379 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
15380 #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
15381 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
15382 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
15383 #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
15384 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
15385 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
 
 
 
15386 #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
15387 {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
15388 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
15389 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
15390 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
@@ -16681,12 +16701,12 @@
16681 int nErr; /* Number of errors seen */
16682 int nTab; /* Number of previously allocated VDBE cursors */
16683 int nMem; /* Number of memory cells used so far */
16684 int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */
16685 int szOpAlloc; /* Bytes of memory space allocated for Vdbe.aOp[] */
16686 int ckBase; /* Base register of data during check constraints */
16687 int iSelfTab; /* Table of an index whose exprs are being coded */
16688 int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
16689 int iCacheCnt; /* Counter used to generate aColCache[].lru values */
16690 int nLabel; /* Number of labels used */
16691 int *aLabel; /* Space to hold the labels */
16692 ExprList *pConstExpr;/* Constant expressions */
@@ -18628,12 +18648,12 @@
18628 */
18629 struct sqlite3_value {
18630 union MemValue {
18631 double r; /* Real value used when MEM_Real is set in flags */
18632 i64 i; /* Integer value used when MEM_Int is set in flags */
18633 int nZero; /* Used when bit MEM_Zero is set in flags */
18634 void *pPtr; /* Pointer when flags=MEM_NULL and eSubtype='p' */
18635 FuncDef *pDef; /* Used only when flags==MEM_Agg */
18636 RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
18637 VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
18638 } u;
18639 u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
@@ -18661,37 +18681,38 @@
18661
18662 /* One or more of the following flags are set to indicate the validOK
18663 ** representations of the value stored in the Mem struct.
18664 **
18665 ** If the MEM_Null flag is set, then the value is an SQL NULL value.
18666 ** No other flags may be set in this case.
 
18667 **
18668 ** If the MEM_Str flag is set then Mem.z points at a string representation.
18669 ** Usually this is encoded in the same unicode encoding as the main
18670 ** database (see below for exceptions). If the MEM_Term flag is also
18671 ** set, then the string is nul terminated. The MEM_Int and MEM_Real
18672 ** flags may coexist with the MEM_Str flag.
18673 */
18674 #define MEM_Null 0x0001 /* Value is NULL */
18675 #define MEM_Str 0x0002 /* Value is a string */
18676 #define MEM_Int 0x0004 /* Value is an integer */
18677 #define MEM_Real 0x0008 /* Value is a real number */
18678 #define MEM_Blob 0x0010 /* Value is a BLOB */
18679 #define MEM_AffMask 0x001f /* Mask of affinity bits */
18680 #define MEM_RowSet 0x0020 /* Value is a RowSet object */
18681 #define MEM_Frame 0x0040 /* Value is a VdbeFrame object */
18682 #define MEM_Undefined 0x0080 /* Value is undefined */
18683 #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */
18684 #define MEM_TypeMask 0x81ff /* Mask of type bits */
18685
18686
18687 /* Whenever Mem contains a valid string or blob representation, one of
18688 ** the following flags must be set to determine the memory management
18689 ** policy for Mem.z. The MEM_Term flag tells us whether or not the
18690 ** string is \000 or \u0000 terminated
18691 */
18692 #define MEM_Term 0x0200 /* String rep is nul terminated */
18693 #define MEM_Dyn 0x0400 /* Need to call Mem.xDel() on Mem.z */
18694 #define MEM_Static 0x0800 /* Mem.z points to a static string */
18695 #define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
18696 #define MEM_Agg 0x2000 /* Mem.z points to an agg function context */
18697 #define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
@@ -18915,11 +18936,11 @@
18915 #ifdef SQLITE_OMIT_FLOATING_POINT
18916 # define sqlite3VdbeMemSetDouble sqlite3VdbeMemSetInt64
18917 #else
18918 SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem*, double);
18919 #endif
18920 SQLITE_PRIVATE void sqlite3VdbeMemSetPointer(Mem*, void*);
18921 SQLITE_PRIVATE void sqlite3VdbeMemInit(Mem*,sqlite3*,u16);
18922 SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem*);
18923 SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem*,int);
18924 SQLITE_PRIVATE void sqlite3VdbeMemSetRowSet(Mem*);
18925 SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*);
@@ -19721,11 +19742,11 @@
19721 double r;
19722 if( parseYyyyMmDd(zDate,p)==0 ){
19723 return 0;
19724 }else if( parseHhMmSs(zDate, p)==0 ){
19725 return 0;
19726 }else if( sqlite3StrICmp(zDate,"now")==0){
19727 return setDateTimeToCurrent(context, p);
19728 }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8) ){
19729 setRawDateNumber(p, r);
19730 return 0;
19731 }
@@ -20004,11 +20025,11 @@
20004 /* localtime
20005 **
20006 ** Assuming the current time value is UTC (a.k.a. GMT), shift it to
20007 ** show local time.
20008 */
20009 if( sqlite3_stricmp(z, "localtime")==0 ){
20010 computeJD(p);
20011 p->iJD += localtimeOffset(p, pCtx, &rc);
20012 clearYMD_HMS_TZ(p);
20013 }
20014 break;
@@ -20030,11 +20051,11 @@
20030 p->rawS = 0;
20031 rc = 0;
20032 }
20033 }
20034 #ifndef SQLITE_OMIT_LOCALTIME
20035 else if( sqlite3_stricmp(z, "utc")==0 ){
20036 if( p->tzSet==0 ){
20037 sqlite3_int64 c1;
20038 computeJD(p);
20039 c1 = localtimeOffset(p, pCtx, &rc);
20040 if( rc==SQLITE_OK ){
@@ -20566,15 +20587,15 @@
20566 ** external linkage.
20567 */
20568 SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void){
20569 static FuncDef aDateTimeFuncs[] = {
20570 #ifndef SQLITE_OMIT_DATETIME_FUNCS
20571 DFUNCTION(julianday, -1, 0, 0, juliandayFunc ),
20572 DFUNCTION(date, -1, 0, 0, dateFunc ),
20573 DFUNCTION(time, -1, 0, 0, timeFunc ),
20574 DFUNCTION(datetime, -1, 0, 0, datetimeFunc ),
20575 DFUNCTION(strftime, -1, 0, 0, strftimeFunc ),
20576 DFUNCTION(current_time, 0, 0, 0, ctimeFunc ),
20577 DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
20578 DFUNCTION(current_date, 0, 0, 0, cdateFunc ),
20579 #else
20580 STR_FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc),
@@ -30088,16 +30109,16 @@
30088 /* 64 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
30089 /* 65 */ "SCopy" OpHelp("r[P2]=r[P1]"),
30090 /* 66 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
30091 /* 67 */ "ResultRow" OpHelp("output=r[P1@P2]"),
30092 /* 68 */ "CollSeq" OpHelp(""),
30093 /* 69 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
30094 /* 70 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
30095 /* 71 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
30096 /* 72 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
30097 /* 73 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
30098 /* 74 */ "RealAffinity" OpHelp(""),
30099 /* 75 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
30100 /* 76 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
30101 /* 77 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
30102 /* 78 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
30103 /* 79 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
@@ -30113,82 +30134,84 @@
30113 /* 89 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
30114 /* 90 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
30115 /* 91 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
30116 /* 92 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
30117 /* 93 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
30118 /* 94 */ "Cast" OpHelp("affinity(r[P1])"),
30119 /* 95 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
30120 /* 96 */ "Permutation" OpHelp(""),
30121 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
30122 /* 98 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
30123 /* 99 */ "Column" OpHelp("r[P3]=PX"),
30124 /* 100 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
30125 /* 101 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
30126 /* 102 */ "Count" OpHelp("r[P2]=count()"),
30127 /* 103 */ "ReadCookie" OpHelp(""),
30128 /* 104 */ "SetCookie" OpHelp(""),
30129 /* 105 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
30130 /* 106 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
30131 /* 107 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
30132 /* 108 */ "OpenDup" OpHelp(""),
30133 /* 109 */ "OpenAutoindex" OpHelp("nColumn=P2"),
30134 /* 110 */ "OpenEphemeral" OpHelp("nColumn=P2"),
30135 /* 111 */ "SorterOpen" OpHelp(""),
30136 /* 112 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
30137 /* 113 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
30138 /* 114 */ "Close" OpHelp(""),
30139 /* 115 */ "ColumnsUsed" OpHelp(""),
30140 /* 116 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
30141 /* 117 */ "NewRowid" OpHelp("r[P2]=rowid"),
30142 /* 118 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
30143 /* 119 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
30144 /* 120 */ "Delete" OpHelp(""),
30145 /* 121 */ "ResetCount" OpHelp(""),
30146 /* 122 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
30147 /* 123 */ "SorterData" OpHelp("r[P2]=data"),
30148 /* 124 */ "RowData" OpHelp("r[P2]=data"),
30149 /* 125 */ "Rowid" OpHelp("r[P2]=rowid"),
30150 /* 126 */ "NullRow" OpHelp(""),
30151 /* 127 */ "SorterInsert" OpHelp("key=r[P2]"),
30152 /* 128 */ "IdxInsert" OpHelp("key=r[P2]"),
30153 /* 129 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
30154 /* 130 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
30155 /* 131 */ "IdxRowid" OpHelp("r[P2]=rowid"),
30156 /* 132 */ "Real" OpHelp("r[P2]=P4"),
30157 /* 133 */ "Destroy" OpHelp(""),
30158 /* 134 */ "Clear" OpHelp(""),
30159 /* 135 */ "ResetSorter" OpHelp(""),
30160 /* 136 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
30161 /* 137 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
30162 /* 138 */ "SqlExec" OpHelp(""),
30163 /* 139 */ "ParseSchema" OpHelp(""),
30164 /* 140 */ "LoadAnalysis" OpHelp(""),
30165 /* 141 */ "DropTable" OpHelp(""),
30166 /* 142 */ "DropIndex" OpHelp(""),
30167 /* 143 */ "DropTrigger" OpHelp(""),
30168 /* 144 */ "IntegrityCk" OpHelp(""),
30169 /* 145 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
30170 /* 146 */ "Param" OpHelp(""),
30171 /* 147 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
30172 /* 148 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
30173 /* 149 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
30174 /* 150 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
30175 /* 151 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
30176 /* 152 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
30177 /* 153 */ "Expire" OpHelp(""),
30178 /* 154 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
30179 /* 155 */ "VBegin" OpHelp(""),
30180 /* 156 */ "VCreate" OpHelp(""),
30181 /* 157 */ "VDestroy" OpHelp(""),
30182 /* 158 */ "VOpen" OpHelp(""),
30183 /* 159 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
30184 /* 160 */ "VRename" OpHelp(""),
30185 /* 161 */ "Pagecount" OpHelp(""),
30186 /* 162 */ "MaxPgcnt" OpHelp(""),
30187 /* 163 */ "CursorHint" OpHelp(""),
30188 /* 164 */ "Noop" OpHelp(""),
30189 /* 165 */ "Explain" OpHelp(""),
 
 
30190 };
30191 return azName[i];
30192 }
30193 #endif
30194
@@ -70249,11 +70272,11 @@
70249 ** This routine is intended for use inside of assert() statements, like
70250 ** this: assert( sqlite3VdbeCheckMemInvariants(pMem) );
70251 */
70252 SQLITE_PRIVATE int sqlite3VdbeCheckMemInvariants(Mem *p){
70253 /* If MEM_Dyn is set then Mem.xDel!=0.
70254 ** Mem.xDel is might not be initialized if MEM_Dyn is clear.
70255 */
70256 assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
70257
70258 /* MEM_Dyn may only be set if Mem.szMalloc==0. In this way we
70259 ** ensure that if Mem.szMalloc>0 then it is safe to do
@@ -70262,13 +70285,38 @@
70262 assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
70263
70264 /* Cannot be both MEM_Int and MEM_Real at the same time */
70265 assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
70266
70267 /* Cannot be both MEM_Null and some other type */
70268 assert( (p->flags & MEM_Null)==0 ||
70269 (p->flags & (MEM_Int|MEM_Real|MEM_Str|MEM_Blob))==0 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70270
70271 /* The szMalloc field holds the correct memory allocation size */
70272 assert( p->szMalloc==0
70273 || p->szMalloc==sqlite3DbMallocSize(p->db,p->zMalloc) );
70274
@@ -70927,19 +70975,29 @@
70927 pMem->u.i = val;
70928 pMem->flags = MEM_Int;
70929 }
70930 }
70931
 
 
 
70932 /*
70933 ** Set the value stored in *pMem should already be a NULL.
70934 ** Also store a pointer to go with it.
70935 */
70936 SQLITE_PRIVATE void sqlite3VdbeMemSetPointer(Mem *pMem, void *pPtr){
 
 
 
 
 
70937 assert( pMem->flags==MEM_Null );
70938 pMem->flags = MEM_Null|MEM_Subtype;
70939 pMem->u.pPtr = pPtr;
 
70940 pMem->eSubtype = 'p';
 
70941 }
70942
70943 #ifndef SQLITE_OMIT_FLOATING_POINT
70944 /*
70945 ** Delete any previous value and set the value stored in *pMem to val,
@@ -76531,10 +76589,32 @@
76531 v->expmask |= 0x80000000;
76532 }else{
76533 v->expmask |= ((u32)1 << (iVar-1));
76534 }
76535 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76536
76537 #ifndef SQLITE_OMIT_VIRTUALTABLE
76538 /*
76539 ** Transfer error message text from an sqlite3_vtab.zErrMsg (text stored
76540 ** in memory obtained from sqlite3_malloc) into a Vdbe.zErrMsg (text stored
@@ -76841,14 +76921,19 @@
76841 }
76842 SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value *pVal){
76843 Mem *pMem = (Mem*)pVal;
76844 return ((pMem->flags & MEM_Subtype) ? pMem->eSubtype : 0);
76845 }
76846 SQLITE_API void *sqlite3_value_pointer(sqlite3_value *pVal){
76847 Mem *p = (Mem*)pVal;
76848 if( (p->flags & MEM_TypeMask)==(MEM_Null|MEM_Subtype) && p->eSubtype=='p' ){
76849 return p->u.pPtr;
 
 
 
 
 
76850 }else{
76851 return 0;
76852 }
76853 }
76854 SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value *pVal){
@@ -77027,15 +77112,20 @@
77027 }
77028 SQLITE_API void sqlite3_result_null(sqlite3_context *pCtx){
77029 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
77030 sqlite3VdbeMemSetNull(pCtx->pOut);
77031 }
77032 SQLITE_API void sqlite3_result_pointer(sqlite3_context *pCtx, void *pPtr){
 
 
 
 
 
77033 Mem *pOut = pCtx->pOut;
77034 assert( sqlite3_mutex_held(pOut->db->mutex) );
77035 sqlite3VdbeMemSetNull(pOut);
77036 sqlite3VdbeMemSetPointer(pOut, pPtr);
77037 }
77038 SQLITE_API void sqlite3_result_subtype(sqlite3_context *pCtx, unsigned int eSubtype){
77039 Mem *pOut = pCtx->pOut;
77040 assert( sqlite3_mutex_held(pOut->db->mutex) );
77041 pOut->eSubtype = eSubtype & 0xff;
@@ -78036,17 +78126,25 @@
78036 if( rc==SQLITE_OK ){
78037 sqlite3_mutex_leave(p->db->mutex);
78038 }
78039 return rc;
78040 }
78041 SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt *pStmt, int i, void *pPtr){
 
 
 
 
 
 
78042 int rc;
78043 Vdbe *p = (Vdbe*)pStmt;
78044 rc = vdbeUnbind(p, i);
78045 if( rc==SQLITE_OK ){
78046 sqlite3VdbeMemSetPointer(&p->aVar[i-1], pPtr);
78047 sqlite3_mutex_leave(p->db->mutex);
 
 
78048 }
78049 return rc;
78050 }
78051 SQLITE_API int sqlite3_bind_text(
78052 sqlite3_stmt *pStmt,
@@ -80466,121 +80564,10 @@
80466 sqlite3VdbeMemSetInt64(&aMem[pOp->p1], 0);
80467 }
80468 break;
80469 }
80470
80471 /* Opcode: Function0 P1 P2 P3 P4 P5
80472 ** Synopsis: r[P3]=func(r[P2@P5])
80473 **
80474 ** Invoke a user function (P4 is a pointer to a FuncDef object that
80475 ** defines the function) with P5 arguments taken from register P2 and
80476 ** successors. The result of the function is stored in register P3.
80477 ** Register P3 must not be one of the function inputs.
80478 **
80479 ** P1 is a 32-bit bitmask indicating whether or not each argument to the
80480 ** function was determined to be constant at compile time. If the first
80481 ** argument was constant then bit 0 of P1 is set. This is used to determine
80482 ** whether meta data associated with a user function argument using the
80483 ** sqlite3_set_auxdata() API may be safely retained until the next
80484 ** invocation of this opcode.
80485 **
80486 ** See also: Function, AggStep, AggFinal
80487 */
80488 /* Opcode: Function P1 P2 P3 P4 P5
80489 ** Synopsis: r[P3]=func(r[P2@P5])
80490 **
80491 ** Invoke a user function (P4 is a pointer to an sqlite3_context object that
80492 ** contains a pointer to the function to be run) with P5 arguments taken
80493 ** from register P2 and successors. The result of the function is stored
80494 ** in register P3. Register P3 must not be one of the function inputs.
80495 **
80496 ** P1 is a 32-bit bitmask indicating whether or not each argument to the
80497 ** function was determined to be constant at compile time. If the first
80498 ** argument was constant then bit 0 of P1 is set. This is used to determine
80499 ** whether meta data associated with a user function argument using the
80500 ** sqlite3_set_auxdata() API may be safely retained until the next
80501 ** invocation of this opcode.
80502 **
80503 ** SQL functions are initially coded as OP_Function0 with P4 pointing
80504 ** to a FuncDef object. But on first evaluation, the P4 operand is
80505 ** automatically converted into an sqlite3_context object and the operation
80506 ** changed to this OP_Function opcode. In this way, the initialization of
80507 ** the sqlite3_context object occurs only once, rather than once for each
80508 ** evaluation of the function.
80509 **
80510 ** See also: Function0, AggStep, AggFinal
80511 */
80512 case OP_Function0: {
80513 int n;
80514 sqlite3_context *pCtx;
80515
80516 assert( pOp->p4type==P4_FUNCDEF );
80517 n = pOp->p5;
80518 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
80519 assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem+1 - p->nCursor)+1) );
80520 assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+n );
80521 pCtx = sqlite3DbMallocRawNN(db, sizeof(*pCtx) + (n-1)*sizeof(sqlite3_value*));
80522 if( pCtx==0 ) goto no_mem;
80523 pCtx->pOut = 0;
80524 pCtx->pFunc = pOp->p4.pFunc;
80525 pCtx->iOp = (int)(pOp - aOp);
80526 pCtx->pVdbe = p;
80527 pCtx->argc = n;
80528 pOp->p4type = P4_FUNCCTX;
80529 pOp->p4.pCtx = pCtx;
80530 pOp->opcode = OP_Function;
80531 /* Fall through into OP_Function */
80532 }
80533 case OP_Function: {
80534 int i;
80535 sqlite3_context *pCtx;
80536
80537 assert( pOp->p4type==P4_FUNCCTX );
80538 pCtx = pOp->p4.pCtx;
80539
80540 /* If this function is inside of a trigger, the register array in aMem[]
80541 ** might change from one evaluation to the next. The next block of code
80542 ** checks to see if the register array has changed, and if so it
80543 ** reinitializes the relavant parts of the sqlite3_context object */
80544 pOut = &aMem[pOp->p3];
80545 if( pCtx->pOut != pOut ){
80546 pCtx->pOut = pOut;
80547 for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
80548 }
80549
80550 memAboutToChange(p, pOut);
80551 #ifdef SQLITE_DEBUG
80552 for(i=0; i<pCtx->argc; i++){
80553 assert( memIsValid(pCtx->argv[i]) );
80554 REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]);
80555 }
80556 #endif
80557 MemSetTypeFlag(pOut, MEM_Null);
80558 pCtx->fErrorOrAux = 0;
80559 (*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */
80560
80561 /* If the function returned an error, throw an exception */
80562 if( pCtx->fErrorOrAux ){
80563 if( pCtx->isError ){
80564 sqlite3VdbeError(p, "%s", sqlite3_value_text(pOut));
80565 rc = pCtx->isError;
80566 }
80567 sqlite3VdbeDeleteAuxData(db, &p->pAuxData, pCtx->iOp, pOp->p1);
80568 if( rc ) goto abort_due_to_error;
80569 }
80570
80571 /* Copy the result of the function into register P3 */
80572 if( pOut->flags & (MEM_Str|MEM_Blob) ){
80573 sqlite3VdbeChangeEncoding(pOut, encoding);
80574 if( sqlite3VdbeMemTooBig(pOut) ) goto too_big;
80575 }
80576
80577 REGISTER_TRACE(pOp->p3, pOut);
80578 UPDATE_MAX_BLOBSIZE(pOut);
80579 break;
80580 }
80581
80582 /* Opcode: BitAnd P1 P2 P3 * *
80583 ** Synopsis: r[P3]=r[P1]&r[P2]
80584 **
80585 ** Take the bit-wise AND of the values in register P1 and P2 and
80586 ** store the result in register P3.
@@ -85875,10 +85862,125 @@
85875 }
85876 pOut->u.i = sqlite3BtreeMaxPageCount(pBt, newMax);
85877 break;
85878 }
85879 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85880
85881
85882 /* Opcode: Init P1 P2 * P4 *
85883 ** Synopsis: Start at P2
85884 **
@@ -94727,12 +94829,13 @@
94727 ){
94728 i16 iTabCol = pIdx->aiColumn[iIdxCol];
94729 if( iTabCol==XN_EXPR ){
94730 assert( pIdx->aColExpr );
94731 assert( pIdx->aColExpr->nExpr>iIdxCol );
94732 pParse->iSelfTab = iTabCur;
94733 sqlite3ExprCodeCopy(pParse, pIdx->aColExpr->a[iIdxCol].pExpr, regOut);
 
94734 }else{
94735 sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pIdx->pTable, iTabCur,
94736 iTabCol, regOut);
94737 }
94738 }
@@ -94972,17 +95075,17 @@
94972 /* Otherwise, fall thru into the TK_COLUMN case */
94973 }
94974 case TK_COLUMN: {
94975 int iTab = pExpr->iTable;
94976 if( iTab<0 ){
94977 if( pParse->ckBase>0 ){
94978 /* Generating CHECK constraints or inserting into partial index */
94979 return pExpr->iColumn + pParse->ckBase;
94980 }else{
94981 /* Coding an expression that is part of an index where column names
94982 ** in the index refer to the table to which the index belongs */
94983 iTab = pParse->iSelfTab;
94984 }
94985 }
94986 return sqlite3ExprCodeGetColumn(pParse, pExpr->pTab,
94987 pExpr->iColumn, iTab, target,
94988 pExpr->op2);
@@ -95315,12 +95418,12 @@
95315 #endif
95316 if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
95317 if( !pColl ) pColl = db->pDfltColl;
95318 sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
95319 }
95320 sqlite3VdbeAddOp4(v, OP_Function0, constMask, r1, target,
95321 (char*)pDef, P4_FUNCDEF);
95322 sqlite3VdbeChangeP5(v, (u8)nFarg);
95323 if( nFarg && constMask==0 ){
95324 sqlite3ReleaseTempRange(pParse, r1, nFarg);
95325 }
95326 return target;
@@ -96744,12 +96847,12 @@
96744 */
96745 #ifdef SQLITE_DEBUG
96746 SQLITE_PRIVATE int sqlite3NoTempsInRange(Parse *pParse, int iFirst, int iLast){
96747 int i;
96748 if( pParse->nRangeReg>0
96749 && pParse->iRangeReg+pParse->nRangeReg<iLast
96750 && pParse->iRangeReg>=iFirst
96751 ){
96752 return 0;
96753 }
96754 for(i=0; i<pParse->nTempReg; i++){
96755 if( pParse->aTempReg[i]>=iFirst && pParse->aTempReg[i]<=iLast ){
@@ -102088,19 +102191,10 @@
102088 pPk = sqlite3PrimaryKeyIndex(pTab);
102089 pTab->iPKey = -1;
102090 }else{
102091 pPk = sqlite3PrimaryKeyIndex(pTab);
102092
102093 /* Bypass the creation of the PRIMARY KEY btree and the sqlite_master
102094 ** table entry. This is only required if currently generating VDBE
102095 ** code for a CREATE TABLE (not when parsing one as part of reading
102096 ** a database schema). */
102097 if( v ){
102098 assert( db->init.busy==0 );
102099 sqlite3VdbeChangeOpcode(v, pPk->tnum, OP_Goto);
102100 }
102101
102102 /*
102103 ** Remove all redundant columns from the PRIMARY KEY. For example, change
102104 ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)". Later
102105 ** code assumes the PRIMARY KEY contains no repeated columns.
102106 */
@@ -102115,10 +102209,19 @@
102115 }
102116 assert( pPk!=0 );
102117 pPk->isCovering = 1;
102118 if( !db->init.imposterTable ) pPk->uniqNotNull = 1;
102119 nPk = pPk->nKeyCol;
 
 
 
 
 
 
 
 
 
102120
102121 /* The root page of the PRIMARY KEY is the table root page */
102122 pPk->tnum = pTab->tnum;
102123
102124 /* Update the in-memory representation of all UNIQUE indices by converting
@@ -106134,14 +106237,15 @@
106134 int nCol;
106135
106136 if( piPartIdxLabel ){
106137 if( pIdx->pPartIdxWhere ){
106138 *piPartIdxLabel = sqlite3VdbeMakeLabel(v);
106139 pParse->iSelfTab = iDataCur;
106140 sqlite3ExprCachePush(pParse);
106141 sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel,
106142 SQLITE_JUMPIFNULL);
 
106143 }else{
106144 *piPartIdxLabel = 0;
106145 }
106146 }
106147 nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
@@ -110823,11 +110927,11 @@
110823 /* Test all CHECK constraints
110824 */
110825 #ifndef SQLITE_OMIT_CHECK
110826 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
110827 ExprList *pCheck = pTab->pCheck;
110828 pParse->ckBase = regNewData+1;
110829 onError = overrideError!=OE_Default ? overrideError : OE_Abort;
110830 for(i=0; i<pCheck->nExpr; i++){
110831 int allOk;
110832 Expr *pExpr = pCheck->a[i].pExpr;
110833 if( aiChng && checkConstraintUnchanged(pExpr, aiChng, pkChng) ) continue;
@@ -110843,10 +110947,11 @@
110843 onError, zName, P4_TRANSIENT,
110844 P5_ConstraintCheck);
110845 }
110846 sqlite3VdbeResolveLabel(v, allOk);
110847 }
 
110848 }
110849 #endif /* !defined(SQLITE_OMIT_CHECK) */
110850
110851 /* If rowid is changing, make sure the new rowid does not previously
110852 ** exist in the table.
@@ -110987,14 +111092,14 @@
110987 addrUniqueOk = sqlite3VdbeMakeLabel(v);
110988
110989 /* Skip partial indices for which the WHERE clause is not true */
110990 if( pIdx->pPartIdxWhere ){
110991 sqlite3VdbeAddOp2(v, OP_Null, 0, aRegIdx[ix]);
110992 pParse->ckBase = regNewData+1;
110993 sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, addrUniqueOk,
110994 SQLITE_JUMPIFNULL);
110995 pParse->ckBase = 0;
110996 }
110997
110998 /* Create a record for this index entry as it should appear after
110999 ** the insert or update. Store that record in the aRegIdx[ix] register
111000 */
@@ -111001,13 +111106,13 @@
111001 regIdx = aRegIdx[ix]+1;
111002 for(i=0; i<pIdx->nColumn; i++){
111003 int iField = pIdx->aiColumn[i];
111004 int x;
111005 if( iField==XN_EXPR ){
111006 pParse->ckBase = regNewData+1;
111007 sqlite3ExprCodeCopy(pParse, pIdx->aColExpr->a[i].pExpr, regIdx+i);
111008 pParse->ckBase = 0;
111009 VdbeComment((v, "%s column %d", pIdx->zName, i));
111010 }else{
111011 if( iField==XN_ROWID || iField==pTab->iPKey ){
111012 x = regNewData;
111013 }else{
@@ -112207,13 +112312,13 @@
112207 /* Version 3.20.0 and later */
112208 int (*prepare_v3)(sqlite3*,const char*,int,unsigned int,
112209 sqlite3_stmt**,const char**);
112210 int (*prepare16_v3)(sqlite3*,const void*,int,unsigned int,
112211 sqlite3_stmt**,const void**);
112212 int (*bind_pointer)(sqlite3_stmt*,int,void*);
112213 void (*result_pointer)(sqlite3_context*,void*);
112214 void *(*value_pointer)(sqlite3_value*);
112215 };
112216
112217 /*
112218 ** This is the function signature used for all extension entry points. It
112219 ** is also defined in the file "loadext.c".
@@ -115461,10 +115566,11 @@
115461 }
115462 aRoot[cnt] = 0;
115463
115464 /* Make sure sufficient number of registers have been allocated */
115465 pParse->nMem = MAX( pParse->nMem, 8+mxIdx );
 
115466
115467 /* Do the b-tree integrity checks */
115468 sqlite3VdbeAddOp4(v, OP_IntegrityCk, 2, cnt, 1, (char*)aRoot,P4_INTARRAY);
115469 sqlite3VdbeChangeP5(v, (u8)i);
115470 addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
@@ -115526,18 +115632,19 @@
115526 if( db->mallocFailed==0 ){
115527 int addrCkFault = sqlite3VdbeMakeLabel(v);
115528 int addrCkOk = sqlite3VdbeMakeLabel(v);
115529 char *zErr;
115530 int k;
115531 pParse->iSelfTab = iDataCur;
115532 sqlite3ExprCachePush(pParse);
115533 for(k=pCheck->nExpr-1; k>0; k--){
115534 sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
115535 }
115536 sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk,
115537 SQLITE_JUMPIFNULL);
115538 sqlite3VdbeResolveLabel(v, addrCkFault);
 
115539 zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
115540 pTab->zName);
115541 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
115542 integrityCheckResultRow(v, 3);
115543 sqlite3VdbeResolveLabel(v, addrCkOk);
@@ -115875,11 +115982,12 @@
115875 ** pragmas run by future database connections.
115876 **
115877 ** 0x0008 (Not yet implemented) Create indexes that might have
115878 ** been helpful to recent queries
115879 **
115880 ** The default MASK is and always shall be 0xfffe. 0xfffe means perform all ** of the optimizations listed above except Debug Mode, including new
 
115881 ** optimizations that have not yet been invented. If new optimizations are
115882 ** ever added that should be off by default, those off-by-default
115883 ** optimizations will have bitmasks of 0x10000 or larger.
115884 **
115885 ** DETERMINATION OF WHEN TO RUN ANALYZE
@@ -116302,14 +116410,18 @@
116302 UNUSED_PARAMETER(idxNum);
116303 UNUSED_PARAMETER(idxStr);
116304 pragmaVtabCursorClear(pCsr);
116305 j = (pTab->pName->mPragFlg & PragFlg_Result1)!=0 ? 0 : 1;
116306 for(i=0; i<argc; i++, j++){
 
116307 assert( j<ArraySize(pCsr->azArg) );
116308 pCsr->azArg[j] = sqlite3_mprintf("%s", sqlite3_value_text(argv[i]));
116309 if( pCsr->azArg[j]==0 ){
116310 return SQLITE_NOMEM;
 
 
 
116311 }
116312 }
116313 sqlite3StrAccumInit(&acc, 0, 0, 0, pTab->db->aLimit[SQLITE_LIMIT_SQL_LENGTH]);
116314 sqlite3StrAccumAppendAll(&acc, "PRAGMA ");
116315 if( pCsr->azArg[1] ){
@@ -118758,17 +118870,14 @@
118758 if( pS ){
118759 /* The "table" is actually a sub-select or a view in the FROM clause
118760 ** of the SELECT statement. Return the declaration type and origin
118761 ** data for the result-set column of the sub-select.
118762 */
118763 if( iCol>=0 && ALWAYS(iCol<pS->pEList->nExpr) ){
118764 /* If iCol is less than zero, then the expression requests the
118765 ** rowid of the sub-select or view. This expression is legal (see
118766 ** test case misc2.2.2) - it always evaluates to NULL.
118767 **
118768 ** The ALWAYS() is because iCol>=pS->pEList->nExpr will have been
118769 ** caught already by name resolution.
118770 */
118771 NameContext sNC;
118772 Expr *p = pS->pEList->a[iCol].pExpr;
118773 sNC.pSrcList = pS->pSrc;
118774 sNC.pNext = pNC;
@@ -118874,22 +118983,10 @@
118874 sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
118875 }
118876 #endif /* !defined(SQLITE_OMIT_DECLTYPE) */
118877 }
118878
118879 /*
118880 ** Return the Table objecct in the SrcList that has cursor iCursor.
118881 ** Or return NULL if no such Table object exists in the SrcList.
118882 */
118883 static Table *tableWithCursor(SrcList *pList, int iCursor){
118884 int j;
118885 for(j=0; j<pList->nSrc; j++){
118886 if( pList->a[j].iCursor==iCursor ) return pList->a[j].pTab;
118887 }
118888 return 0;
118889 }
118890
118891
118892 /*
118893 ** Compute the column names for a SELECT statement.
118894 **
118895 ** The only guarantee that SQLite makes about column names is that if the
@@ -118919,28 +119016,33 @@
118919 ** then the result column name with the table name
118920 ** prefix, ex: TABLE.COLUMN. Otherwise use zSpan.
118921 */
118922 static void generateColumnNames(
118923 Parse *pParse, /* Parser context */
118924 SrcList *pTabList, /* The FROM clause of the SELECT */
118925 ExprList *pEList /* Expressions defining the result set */
118926 ){
118927 Vdbe *v = pParse->pVdbe;
118928 int i;
118929 Table *pTab;
 
 
118930 sqlite3 *db = pParse->db;
118931 int fullName; /* TABLE.COLUMN if no AS clause and is a direct table ref */
118932 int srcName; /* COLUMN or TABLE.COLUMN if no AS clause and is direct */
118933
118934 #ifndef SQLITE_OMIT_EXPLAIN
118935 /* If this is an EXPLAIN, skip this step */
118936 if( pParse->explain ){
118937 return;
118938 }
118939 #endif
118940
118941 if( pParse->colNamesSet || db->mallocFailed ) return;
 
 
 
 
118942 assert( v!=0 );
118943 assert( pTabList!=0 );
118944 pParse->colNamesSet = 1;
118945 fullName = (db->flags & SQLITE_FullColNames)!=0;
118946 srcName = (db->flags & SQLITE_ShortColNames)!=0 || fullName;
@@ -118951,16 +119053,15 @@
118951 assert( p!=0 );
118952 if( pEList->a[i].zName ){
118953 /* An AS clause always takes first priority */
118954 char *zName = pEList->a[i].zName;
118955 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
118956 }else if( srcName
118957 && (p->op==TK_COLUMN || p->op==TK_AGG_COLUMN)
118958 && (pTab = tableWithCursor(pTabList, p->iTable))!=0
118959 ){
118960 char *zCol;
118961 int iCol = p->iColumn;
 
 
118962 if( iCol<0 ) iCol = pTab->iPKey;
118963 assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
118964 if( iCol<0 ){
118965 zCol = "rowid";
118966 }else{
@@ -119788,15 +119889,10 @@
119788 */
119789 assert( unionTab==dest.iSDParm || dest.eDest!=priorOp );
119790 if( dest.eDest!=priorOp ){
119791 int iCont, iBreak, iStart;
119792 assert( p->pEList );
119793 if( dest.eDest==SRT_Output ){
119794 Select *pFirst = p;
119795 while( pFirst->pPrior ) pFirst = pFirst->pPrior;
119796 generateColumnNames(pParse, pFirst->pSrc, pFirst->pEList);
119797 }
119798 iBreak = sqlite3VdbeMakeLabel(v);
119799 iCont = sqlite3VdbeMakeLabel(v);
119800 computeLimitRegisters(pParse, p, iBreak);
119801 sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
119802 iStart = sqlite3VdbeCurrentAddr(v);
@@ -119863,15 +119959,10 @@
119863
119864 /* Generate code to take the intersection of the two temporary
119865 ** tables.
119866 */
119867 assert( p->pEList );
119868 if( dest.eDest==SRT_Output ){
119869 Select *pFirst = p;
119870 while( pFirst->pPrior ) pFirst = pFirst->pPrior;
119871 generateColumnNames(pParse, pFirst->pSrc, pFirst->pEList);
119872 }
119873 iBreak = sqlite3VdbeMakeLabel(v);
119874 iCont = sqlite3VdbeMakeLabel(v);
119875 computeLimitRegisters(pParse, p, iBreak);
119876 sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
119877 r1 = sqlite3GetTempReg(pParse);
@@ -120475,18 +120566,10 @@
120475
120476 /* Jump to the this point in order to terminate the query.
120477 */
120478 sqlite3VdbeResolveLabel(v, labelEnd);
120479
120480 /* Set the number of output columns
120481 */
120482 if( pDest->eDest==SRT_Output ){
120483 Select *pFirst = pPrior;
120484 while( pFirst->pPrior ) pFirst = pFirst->pPrior;
120485 generateColumnNames(pParse, pFirst->pSrc, pFirst->pEList);
120486 }
120487
120488 /* Reassembly the compound query so that it will be freed correctly
120489 ** by the calling function */
120490 if( p->pPrior ){
120491 sqlite3SelectDelete(db, p->pPrior);
120492 }
@@ -120659,12 +120742,13 @@
120659 ** and (2b) the outer query does not use subqueries other than the one
120660 ** FROM-clause subquery that is a candidate for flattening. (2b is
120661 ** due to ticket [2f7170d73bf9abf80] from 2015-02-09.)
120662 **
120663 ** (3) The subquery is not the right operand of a LEFT JOIN
120664 ** or the subquery is not itself a join and the outer query is not
120665 ** an aggregate.
 
120666 **
120667 ** (4) The subquery is not DISTINCT.
120668 **
120669 ** (**) At one point restrictions (4) and (5) defined a subset of DISTINCT
120670 ** sub-queries that were excluded from this optimization. Restriction
@@ -120776,11 +120860,10 @@
120776 Select *pParent; /* Current UNION ALL term of the other query */
120777 Select *pSub; /* The inner query or "subquery" */
120778 Select *pSub1; /* Pointer to the rightmost select in sub-query */
120779 SrcList *pSrc; /* The FROM clause of the outer query */
120780 SrcList *pSubSrc; /* The FROM clause of the subquery */
120781 ExprList *pList; /* The result set of the outer query */
120782 int iParent; /* VDBE cursor number of the pSub result set temp table */
120783 int iNewParent = -1;/* Replacement table for iParent */
120784 int isLeftJoin = 0; /* True if pSub is the right side of a LEFT JOIN */
120785 int i; /* Loop counter */
120786 Expr *pWhere; /* The WHERE clause */
@@ -120865,11 +120948,11 @@
120865 **
120866 ** See also tickets #306, #350, and #3300.
120867 */
120868 if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
120869 isLeftJoin = 1;
120870 if( pSubSrc->nSrc>1 || isAgg ){
120871 return 0; /* Restriction (3) */
120872 }
120873 }
120874 #ifdef SQLITE_EXTRA_IFNULLROW
120875 else if( iFrom>0 && !isAgg ){
@@ -121101,18 +121184,10 @@
121101 ** \_____________________ outer query ______________________________/
121102 **
121103 ** We look at every expression in the outer query and every place we see
121104 ** "a" we substitute "x*3" and every place we see "b" we substitute "y+10".
121105 */
121106 pList = pParent->pEList;
121107 for(i=0; i<pList->nExpr; i++){
121108 if( pList->a[i].zName==0 ){
121109 char *zName = sqlite3DbStrDup(db, pList->a[i].zSpan);
121110 sqlite3Dequote(zName);
121111 pList->a[i].zName = zName;
121112 }
121113 }
121114 if( pSub->pOrderBy ){
121115 /* At this point, any non-zero iOrderByCol values indicate that the
121116 ** ORDER BY column expression is identical to the iOrderByCol'th
121117 ** expression returned by SELECT statement pSub. Since these values
121118 ** do not necessarily correspond to columns in SELECT statement pParent,
@@ -122537,10 +122612,18 @@
122537 if( sqlite3SelectTrace & 0x100 ){
122538 SELECTTRACE(0x100,pParse,p, ("after name resolution:\n"));
122539 sqlite3TreeViewSelect(0, p, 0);
122540 }
122541 #endif
 
 
 
 
 
 
 
 
122542
122543 /* Try to flatten subqueries in the FROM clause up into the main query
122544 */
122545 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
122546 for(i=0; !p->pPrior && i<pTabList->nSrc; i++){
@@ -122573,15 +122656,10 @@
122573 sSort.pOrderBy = p->pOrderBy;
122574 }
122575 }
122576 #endif
122577
122578 /* Get a pointer the VDBE under construction, allocating a new VDBE if one
122579 ** does not already exist */
122580 v = sqlite3GetVdbe(pParse);
122581 if( v==0 ) goto select_end;
122582
122583 #ifndef SQLITE_OMIT_COMPOUND_SELECT
122584 /* Handle compound SELECT statements using the separate multiSelect()
122585 ** procedure.
122586 */
122587 if( p->pPrior ){
@@ -123377,16 +123455,10 @@
123377 ** successful coding of the SELECT.
123378 */
123379 select_end:
123380 explainSetInteger(pParse->iSelectId, iRestoreSelectId);
123381
123382 /* Identify column names if results of the SELECT are to be output.
123383 */
123384 if( rc==SQLITE_OK && pDest->eDest==SRT_Output ){
123385 generateColumnNames(pParse, pTabList, pEList);
123386 }
123387
123388 sqlite3DbFree(db, sAggInfo.aCol);
123389 sqlite3DbFree(db, sAggInfo.aFunc);
123390 #if SELECTTRACE_ENABLED
123391 SELECTTRACE(1,pParse,p,("end processing\n"));
123392 pParse->nSelectIndent--;
@@ -131980,10 +132052,19 @@
131980 Bitmask notReady /* Tables in outer loops of the join */
131981 ){
131982 char aff;
131983 if( pTerm->leftCursor!=pSrc->iCursor ) return 0;
131984 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) return 0;
 
 
 
 
 
 
 
 
 
131985 if( (pTerm->prereqRight & notReady)!=0 ) return 0;
131986 if( pTerm->u.leftColumn<0 ) return 0;
131987 aff = pSrc->pTab->aCol[pTerm->u.leftColumn].affinity;
131988 if( !sqlite3IndexAffinityOk(pTerm->pExpr, aff) ) return 0;
131989 testcase( pTerm->pExpr->op==TK_IS );
@@ -150278,11 +150359,11 @@
150278 assert( iCol>=0 && iCol<=p->nColumn+2 );
150279
150280 switch( iCol-p->nColumn ){
150281 case 0:
150282 /* The special 'table-name' column */
150283 sqlite3_result_pointer(pCtx, pCsr);
150284 break;
150285
150286 case 1:
150287 /* The docid column */
150288 sqlite3_result_int64(pCtx, pCsr->iPrevId);
@@ -150497,11 +150578,11 @@
150497 const char *zFunc, /* Function name */
150498 sqlite3_value *pVal, /* argv[0] passed to function */
150499 Fts3Cursor **ppCsr /* OUT: Store cursor handle here */
150500 ){
150501 int rc;
150502 *ppCsr = (Fts3Cursor*)sqlite3_value_pointer(pVal);
150503 if( (*ppCsr)!=0 ){
150504 rc = SQLITE_OK;
150505 }else{
150506 char *zErr = sqlite3_mprintf("illegal first argument to %s", zFunc);
150507 sqlite3_result_error(pContext, zErr, -1);
@@ -165512,26 +165593,18 @@
165512 int (*xQueryFunc)(sqlite3_rtree_query_info*);
165513 void (*xDestructor)(void*);
165514 void *pContext;
165515 };
165516
165517
165518 /*
165519 ** Value for the first field of every RtreeMatchArg object. The MATCH
165520 ** operator tests that the first field of a blob operand matches this
165521 ** value to avoid operating on invalid blobs (which could cause a segfault).
165522 */
165523 #define RTREE_GEOMETRY_MAGIC 0x891245AB
165524
165525 /*
165526 ** An instance of this structure (in the form of a BLOB) is returned by
165527 ** the SQL functions that sqlite3_rtree_geometry_callback() and
165528 ** sqlite3_rtree_query_callback() create, and is read as the right-hand
165529 ** operand to the MATCH operator of an R-Tree.
165530 */
165531 struct RtreeMatchArg {
165532 u32 magic; /* Always RTREE_GEOMETRY_MAGIC */
165533 RtreeGeomCallback cb; /* Info about the callback functions */
165534 int nParam; /* Number of parameters to the SQL function */
165535 sqlite3_value **apSqlParam; /* Original SQL parameter values */
165536 RtreeDValue aParam[1]; /* Values for parameters to the SQL function */
165537 };
@@ -166822,37 +166895,21 @@
166822 ** as the second argument for a MATCH constraint. The value passed as the
166823 ** first argument to this function is the right-hand operand to the MATCH
166824 ** operator.
166825 */
166826 static int deserializeGeometry(sqlite3_value *pValue, RtreeConstraint *pCons){
166827 RtreeMatchArg *pBlob; /* BLOB returned by geometry function */
166828 sqlite3_rtree_query_info *pInfo; /* Callback information */
166829 int nBlob; /* Size of the geometry function blob */
166830 int nExpected; /* Expected size of the BLOB */
166831
166832 /* Check that value is actually a blob. */
166833 if( sqlite3_value_type(pValue)!=SQLITE_BLOB ) return SQLITE_ERROR;
166834
166835 /* Check that the blob is roughly the right size. */
166836 nBlob = sqlite3_value_bytes(pValue);
166837 if( nBlob<(int)sizeof(RtreeMatchArg) ){
166838 return SQLITE_ERROR;
166839 }
166840
166841 pInfo = (sqlite3_rtree_query_info*)sqlite3_malloc( sizeof(*pInfo)+nBlob );
166842 if( !pInfo ) return SQLITE_NOMEM;
166843 memset(pInfo, 0, sizeof(*pInfo));
166844 pBlob = (RtreeMatchArg*)&pInfo[1];
166845
166846 memcpy(pBlob, sqlite3_value_blob(pValue), nBlob);
166847 nExpected = (int)(sizeof(RtreeMatchArg) +
166848 pBlob->nParam*sizeof(sqlite3_value*) +
166849 (pBlob->nParam-1)*sizeof(RtreeDValue));
166850 if( pBlob->magic!=RTREE_GEOMETRY_MAGIC || nBlob!=nExpected ){
166851 sqlite3_free(pInfo);
166852 return SQLITE_ERROR;
166853 }
166854 pInfo->pContext = pBlob->cb.pContext;
166855 pInfo->nParam = pBlob->nParam;
166856 pInfo->aParam = pBlob->aParam;
166857 pInfo->apSqlParam = pBlob->apSqlParam;
166858
@@ -168886,11 +168943,11 @@
168886 pBlob = (RtreeMatchArg *)sqlite3_malloc(nBlob);
168887 if( !pBlob ){
168888 sqlite3_result_error_nomem(ctx);
168889 }else{
168890 int i;
168891 pBlob->magic = RTREE_GEOMETRY_MAGIC;
168892 pBlob->cb = pGeomCtx[0];
168893 pBlob->apSqlParam = (sqlite3_value**)&pBlob->aParam[nArg];
168894 pBlob->nParam = nArg;
168895 for(i=0; i<nArg; i++){
168896 pBlob->apSqlParam[i] = sqlite3_value_dup(aArg[i]);
@@ -168903,11 +168960,11 @@
168903 }
168904 if( memErr ){
168905 sqlite3_result_error_nomem(ctx);
168906 rtreeMatchArgFree(pBlob);
168907 }else{
168908 sqlite3_result_blob(ctx, pBlob, nBlob, rtreeMatchArgFree);
168909 }
168910 }
168911 }
168912
168913 /*
@@ -200196,19 +200253,18 @@
200196 }
200197
200198 static void fts5Fts5Func(
200199 sqlite3_context *pCtx, /* Function call context */
200200 int nArg, /* Number of args */
200201 sqlite3_value **apUnused /* Function arguments */
200202 ){
200203 Fts5Global *pGlobal = (Fts5Global*)sqlite3_user_data(pCtx);
200204 char buf[8];
200205 UNUSED_PARAM2(nArg, apUnused);
200206 assert( nArg==0 );
200207 assert( sizeof(buf)>=sizeof(pGlobal) );
200208 memcpy(buf, (void*)&pGlobal, sizeof(pGlobal));
200209 sqlite3_result_blob(pCtx, buf, sizeof(pGlobal), SQLITE_TRANSIENT);
200210 }
200211
200212 /*
200213 ** Implementation of fts5_source_id() function.
200214 */
@@ -200217,11 +200273,11 @@
200217 int nArg, /* Number of args */
200218 sqlite3_value **apUnused /* Function arguments */
200219 ){
200220 assert( nArg==0 );
200221 UNUSED_PARAM2(nArg, apUnused);
200222 sqlite3_result_text(pCtx, "fts5: 2017-07-15 13:49:56 47cf83a0682b7b3219cf255457f5fbe05f3c1f46be42f6bbab33b78a57a252f6", -1, SQLITE_TRANSIENT);
200223 }
200224
200225 static int fts5Init(sqlite3 *db){
200226 static const sqlite3_module fts5Mod = {
200227 /* iVersion */ 2,
@@ -200269,11 +200325,11 @@
200269 if( rc==SQLITE_OK ) rc = sqlite3Fts5AuxInit(&pGlobal->api);
200270 if( rc==SQLITE_OK ) rc = sqlite3Fts5TokenizerInit(&pGlobal->api);
200271 if( rc==SQLITE_OK ) rc = sqlite3Fts5VocabInit(pGlobal, db);
200272 if( rc==SQLITE_OK ){
200273 rc = sqlite3_create_function(
200274 db, "fts5", 0, SQLITE_UTF8, p, fts5Fts5Func, 0, 0
200275 );
200276 }
200277 if( rc==SQLITE_OK ){
200278 rc = sqlite3_create_function(
200279 db, "fts5_source_id", 0, SQLITE_UTF8, p, fts5SourceIdFunc, 0, 0
200280
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1150,11 +1150,11 @@
1150 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1151 ** [sqlite_version()] and [sqlite_source_id()].
1152 */
1153 #define SQLITE_VERSION "3.20.0"
1154 #define SQLITE_VERSION_NUMBER 3020000
1155 #define SQLITE_SOURCE_ID "2017-08-01 13:24:15 9501e22dfeebdcefa783575e47c60b514d7c2e0cad73b2a496c0bc4b680900a8"
1156
1157 /*
1158 ** CAPI3REF: Run-Time Library Version Numbers
1159 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1160 **
@@ -4672,11 +4672,11 @@
4672 );
4673 SQLITE_API int sqlite3_prepare16_v3(
4674 sqlite3 *db, /* Database handle */
4675 const void *zSql, /* SQL statement, UTF-16 encoded */
4676 int nByte, /* Maximum length of zSql in bytes. */
4677 unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
4678 sqlite3_stmt **ppStmt, /* OUT: Statement handle */
4679 const void **pzTail /* OUT: Pointer to unused portion of zSql */
4680 );
4681
4682 /*
@@ -4910,18 +4910,18 @@
4910 ** Zeroblobs are intended to serve as placeholders for BLOBs whose
4911 ** content is later written using
4912 ** [sqlite3_blob_open | incremental BLOB I/O] routines.
4913 ** ^A negative value for the zeroblob results in a zero-length BLOB.
4914 **
4915 ** ^The sqlite3_bind_pointer(S,I,P,T,D) routine causes the I-th parameter in
4916 ** [prepared statement] S to have an SQL value of NULL, but to also be
4917 ** associated with the pointer P of type T. ^D is either a NULL pointer or
4918 ** a pointer to a destructor function for P. ^SQLite will invoke the
4919 ** destructor D with a single argument of P when it is finished using
4920 ** P. The T parameter should be a static string, preferably a string
4921 ** literal. The sqlite3_bind_pointer() routine is part of the
4922 ** [pointer passing interface] added for SQLite 3.20.0.
4923 **
4924 ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
4925 ** for the [prepared statement] or with a prepared statement for which
4926 ** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
4927 ** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_()
@@ -4952,11 +4952,11 @@
4952 SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
4953 SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
4954 SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
4955 void(*)(void*), unsigned char encoding);
4956 SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
4957 SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const char*,void(*)(void*));
4958 SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
4959 SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
4960
4961 /*
4962 ** CAPI3REF: Number Of SQL Parameters
@@ -5226,11 +5226,11 @@
5226 ** For all versions of SQLite up to and including 3.6.23.1, a call to
5227 ** [sqlite3_reset()] was required after sqlite3_step() returned anything
5228 ** other than [SQLITE_ROW] before any subsequent invocation of
5229 ** sqlite3_step(). Failure to reset the prepared statement using
5230 ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
5231 ** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1]),
5232 ** sqlite3_step() began
5233 ** calling [sqlite3_reset()] automatically in this circumstance rather
5234 ** than returning [SQLITE_MISUSE]. This is not considered a compatibility
5235 ** break because any application that ever receives an SQLITE_MISUSE error
5236 ** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option
@@ -5785,13 +5785,15 @@
5785 ** in the native byte-order of the host machine. ^The
5786 ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
5787 ** extract UTF-16 strings as big-endian and little-endian respectively.
5788 **
5789 ** ^If [sqlite3_value] object V was initialized
5790 ** using [sqlite3_bind_pointer(S,I,P,X,D)] or [sqlite3_result_pointer(C,P,X,D)]
5791 ** and if X and Y are strings that compare equal according to strcmp(X,Y),
5792 ** then sqlite3_value_pointer(V,Y) will return the pointer P. ^Otherwise,
5793 ** sqlite3_value_pointer(V,Y) returns a NULL. The sqlite3_bind_pointer()
5794 ** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
5795 **
5796 ** ^(The sqlite3_value_type(V) interface returns the
5797 ** [SQLITE_INTEGER | datatype code] for the initial datatype of the
5798 ** [sqlite3_value] object V. The returned value is one of [SQLITE_INTEGER],
5799 ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].)^
@@ -5821,11 +5823,11 @@
5823 */
5824 SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
5825 SQLITE_API double sqlite3_value_double(sqlite3_value*);
5826 SQLITE_API int sqlite3_value_int(sqlite3_value*);
5827 SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
5828 SQLITE_API void *sqlite3_value_pointer(sqlite3_value*, const char*);
5829 SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);
5830 SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);
5831 SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
5832 SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
5833 SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
@@ -6122,17 +6124,20 @@
6124 ** be deallocated after sqlite3_result_value() returns without harm.
6125 ** ^A [protected sqlite3_value] object may always be used where an
6126 ** [unprotected sqlite3_value] object is required, so either
6127 ** kind of [sqlite3_value] object can be used with this interface.
6128 **
6129 ** ^The sqlite3_result_pointer(C,P,T,D) interface sets the result to an
6130 ** SQL NULL value, just like [sqlite3_result_null(C)], except that it
6131 ** also associates the host-language pointer P or type T with that
6132 ** NULL value such that the pointer can be retrieved within an
6133 ** [application-defined SQL function] using [sqlite3_value_pointer()].
6134 ** ^If the D parameter is not NULL, then it is a pointer to a destructor
6135 ** for the P parameter. ^SQLite invokes D with P as its only argument
6136 ** when SQLite is finished with P. The T parameter should be a static
6137 ** string and preferably a string literal. The sqlite3_result_pointer()
6138 ** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
6139 **
6140 ** If these routines are called from within the different thread
6141 ** than the one containing the application-defined function that received
6142 ** the [sqlite3_context] pointer, the results are undefined.
6143 */
@@ -6153,11 +6158,11 @@
6158 void(*)(void*), unsigned char encoding);
6159 SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
6160 SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
6161 SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
6162 SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
6163 SQLITE_API void sqlite3_result_pointer(sqlite3_context*, void*,const char*,void(*)(void*));
6164 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
6165 SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
6166
6167
6168 /*
@@ -13750,16 +13755,16 @@
13755 #define OP_Copy 64 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
13756 #define OP_SCopy 65 /* synopsis: r[P2]=r[P1] */
13757 #define OP_IntCopy 66 /* synopsis: r[P2]=r[P1] */
13758 #define OP_ResultRow 67 /* synopsis: output=r[P1@P2] */
13759 #define OP_CollSeq 68
13760 #define OP_AddImm 69 /* synopsis: r[P1]=r[P1]+P2 */
13761 #define OP_Or 70 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
13762 #define OP_And 71 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
13763 #define OP_RealAffinity 72
13764 #define OP_Cast 73 /* synopsis: affinity(r[P1]) */
13765 #define OP_Permutation 74
13766 #define OP_IsNull 75 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
13767 #define OP_NotNull 76 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
13768 #define OP_Ne 77 /* same as TK_NE, synopsis: IF r[P3]!=r[P1] */
13769 #define OP_Eq 78 /* same as TK_EQ, synopsis: IF r[P3]==r[P1] */
13770 #define OP_Gt 79 /* same as TK_GT, synopsis: IF r[P3]>r[P1] */
@@ -13775,82 +13780,84 @@
13780 #define OP_Subtract 89 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
13781 #define OP_Multiply 90 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
13782 #define OP_Divide 91 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
13783 #define OP_Remainder 92 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
13784 #define OP_Concat 93 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
13785 #define OP_Compare 94 /* synopsis: r[P1@P3] <-> r[P2@P3] */
13786 #define OP_BitNot 95 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
13787 #define OP_Column 96 /* synopsis: r[P3]=PX */
13788 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
13789 #define OP_Affinity 98 /* synopsis: affinity(r[P1@P2]) */
13790 #define OP_MakeRecord 99 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
13791 #define OP_Count 100 /* synopsis: r[P2]=count() */
13792 #define OP_ReadCookie 101
13793 #define OP_SetCookie 102
13794 #define OP_ReopenIdx 103 /* synopsis: root=P2 iDb=P3 */
13795 #define OP_OpenRead 104 /* synopsis: root=P2 iDb=P3 */
13796 #define OP_OpenWrite 105 /* synopsis: root=P2 iDb=P3 */
13797 #define OP_OpenDup 106
13798 #define OP_OpenAutoindex 107 /* synopsis: nColumn=P2 */
13799 #define OP_OpenEphemeral 108 /* synopsis: nColumn=P2 */
13800 #define OP_SorterOpen 109
13801 #define OP_SequenceTest 110 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
13802 #define OP_OpenPseudo 111 /* synopsis: P3 columns in r[P2] */
13803 #define OP_Close 112
13804 #define OP_ColumnsUsed 113
13805 #define OP_Sequence 114 /* synopsis: r[P2]=cursor[P1].ctr++ */
13806 #define OP_NewRowid 115 /* synopsis: r[P2]=rowid */
13807 #define OP_Insert 116 /* synopsis: intkey=r[P3] data=r[P2] */
13808 #define OP_InsertInt 117 /* synopsis: intkey=P3 data=r[P2] */
13809 #define OP_Delete 118
13810 #define OP_ResetCount 119
13811 #define OP_SorterCompare 120 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
13812 #define OP_SorterData 121 /* synopsis: r[P2]=data */
13813 #define OP_RowData 122 /* synopsis: r[P2]=data */
13814 #define OP_Rowid 123 /* synopsis: r[P2]=rowid */
13815 #define OP_NullRow 124
13816 #define OP_SorterInsert 125 /* synopsis: key=r[P2] */
13817 #define OP_IdxInsert 126 /* synopsis: key=r[P2] */
13818 #define OP_IdxDelete 127 /* synopsis: key=r[P2@P3] */
13819 #define OP_DeferredSeek 128 /* synopsis: Move P3 to P1.rowid if needed */
13820 #define OP_IdxRowid 129 /* synopsis: r[P2]=rowid */
13821 #define OP_Destroy 130
13822 #define OP_Clear 131
13823 #define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
13824 #define OP_ResetSorter 133
13825 #define OP_CreateIndex 134 /* synopsis: r[P2]=root iDb=P1 */
13826 #define OP_CreateTable 135 /* synopsis: r[P2]=root iDb=P1 */
13827 #define OP_SqlExec 136
13828 #define OP_ParseSchema 137
13829 #define OP_LoadAnalysis 138
13830 #define OP_DropTable 139
13831 #define OP_DropIndex 140
13832 #define OP_DropTrigger 141
13833 #define OP_IntegrityCk 142
13834 #define OP_RowSetAdd 143 /* synopsis: rowset(P1)=r[P2] */
13835 #define OP_Param 144
13836 #define OP_FkCounter 145 /* synopsis: fkctr[P1]+=P2 */
13837 #define OP_MemMax 146 /* synopsis: r[P1]=max(r[P1],r[P2]) */
13838 #define OP_OffsetLimit 147 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
13839 #define OP_AggStep0 148 /* synopsis: accum=r[P3] step(r[P2@P5]) */
13840 #define OP_AggStep 149 /* synopsis: accum=r[P3] step(r[P2@P5]) */
13841 #define OP_AggFinal 150 /* synopsis: accum=r[P1] N=P2 */
13842 #define OP_Expire 151
13843 #define OP_TableLock 152 /* synopsis: iDb=P1 root=P2 write=P3 */
13844 #define OP_VBegin 153
13845 #define OP_VCreate 154
13846 #define OP_VDestroy 155
13847 #define OP_VOpen 156
13848 #define OP_VColumn 157 /* synopsis: r[P3]=vcolumn(P2) */
13849 #define OP_VRename 158
13850 #define OP_Pagecount 159
13851 #define OP_MaxPgcnt 160
13852 #define OP_PureFunc0 161
13853 #define OP_Function0 162 /* synopsis: r[P3]=func(r[P2@P5]) */
13854 #define OP_PureFunc 163
13855 #define OP_Function 164 /* synopsis: r[P3]=func(r[P2@P5]) */
13856 #define OP_CursorHint 165
13857 #define OP_Noop 166
13858 #define OP_Explain 167
13859
13860 /* Properties such as "out2" or "jump" that are specified in
13861 ** comments following the "case" for each opcode in the vdbe.c
13862 ** are encoded into bitvectors as follows:
13863 */
@@ -13867,23 +13874,24 @@
13874 /* 24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
13875 /* 32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
13876 /* 40 */ 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01, 0x03, 0x03,\
13877 /* 48 */ 0x03, 0x01, 0x01, 0x01, 0x02, 0x02, 0x08, 0x00,\
13878 /* 56 */ 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00,\
13879 /* 64 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x02, 0x26, 0x26,\
13880 /* 72 */ 0x02, 0x02, 0x00, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\
13881 /* 80 */ 0x0b, 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26,\
13882 /* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00, 0x12,\
13883 /* 96 */ 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
13884 /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13885 /* 112 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
13886 /* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00,\
13887 /* 128 */ 0x00, 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10,\
13888 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,\
13889 /* 144 */ 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00,\
13890 /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
13891 /* 160 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13892 }
13893
13894 /* The sqlite3P2Values() routine is able to run faster if it knows
13895 ** the value of the largest JUMP opcode. The smaller the maximum
13896 ** JUMP opcode the better, so the mkopcodeh.tcl script that
13897 ** generated this include file strives to group all JUMP opcodes
@@ -13977,10 +13985,12 @@
13985 SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
13986
13987 #ifndef SQLITE_OMIT_TRIGGER
13988 SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
13989 #endif
13990
13991 SQLITE_PRIVATE int sqlite3NotPureFunc(sqlite3_context*);
13992
13993 /* Use SQLITE_ENABLE_COMMENTS to enable generation of extra comments on
13994 ** each VDBE opcode.
13995 **
13996 ** Use the SQLITE_ENABLE_MODULE_COMMENTS macro to see some extra no-op
@@ -15356,11 +15366,18 @@
15366 **
15367 ** DFUNCTION(zName, nArg, iArg, bNC, xFunc)
15368 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
15369 ** adds the SQLITE_FUNC_SLOCHNG flag. Used for date & time functions
15370 ** and functions like sqlite_version() that can change, but not during
15371 ** a single query. The iArg is ignored. The user-data is always set
15372 ** to a NULL pointer. The bNC parameter is not used.
15373 **
15374 ** PURE_DATE(zName, nArg, iArg, bNC, xFunc)
15375 ** Used for "pure" date/time functions, this macro is like DFUNCTION
15376 ** except that it does set the SQLITE_FUNC_CONSTANT flags. iArg is
15377 ** ignored and the user-data for these functions is set to an
15378 ** arbitrary non-NULL pointer. The bNC parameter is not used.
15379 **
15380 ** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
15381 ** Used to create an aggregate function definition implemented by
15382 ** the C functions xStep and xFinal. The first four parameters
15383 ** are interpreted in the same way as the first 4 parameters to
@@ -15379,12 +15396,15 @@
15396 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
15397 #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
15398 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
15399 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
15400 #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
15401 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \
15402 0, 0, xFunc, 0, #zName, {0} }
15403 #define PURE_DATE(zName, nArg, iArg, bNC, xFunc) \
15404 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
15405 (void*)&sqlite3Config, 0, xFunc, 0, #zName, {0} }
15406 #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
15407 {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
15408 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
15409 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
15410 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
@@ -16681,12 +16701,12 @@
16701 int nErr; /* Number of errors seen */
16702 int nTab; /* Number of previously allocated VDBE cursors */
16703 int nMem; /* Number of memory cells used so far */
16704 int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */
16705 int szOpAlloc; /* Bytes of memory space allocated for Vdbe.aOp[] */
16706 int iSelfTab; /* Table for associated with an index on expr, or negative
16707 ** of the base register during check-constraint eval */
16708 int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
16709 int iCacheCnt; /* Counter used to generate aColCache[].lru values */
16710 int nLabel; /* Number of labels used */
16711 int *aLabel; /* Space to hold the labels */
16712 ExprList *pConstExpr;/* Constant expressions */
@@ -18628,12 +18648,12 @@
18648 */
18649 struct sqlite3_value {
18650 union MemValue {
18651 double r; /* Real value used when MEM_Real is set in flags */
18652 i64 i; /* Integer value used when MEM_Int is set in flags */
18653 int nZero; /* Extra zero bytes when MEM_Zero and MEM_Blob set */
18654 const char *zPType; /* Pointer type when MEM_Term|MEM_Subtype|MEM_Null */
18655 FuncDef *pDef; /* Used only when flags==MEM_Agg */
18656 RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
18657 VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
18658 } u;
18659 u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
@@ -18661,37 +18681,38 @@
18681
18682 /* One or more of the following flags are set to indicate the validOK
18683 ** representations of the value stored in the Mem struct.
18684 **
18685 ** If the MEM_Null flag is set, then the value is an SQL NULL value.
18686 ** For a pointer type created using sqlite3_bind_pointer() or
18687 ** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set.
18688 **
18689 ** If the MEM_Str flag is set then Mem.z points at a string representation.
18690 ** Usually this is encoded in the same unicode encoding as the main
18691 ** database (see below for exceptions). If the MEM_Term flag is also
18692 ** set, then the string is nul terminated. The MEM_Int and MEM_Real
18693 ** flags may coexist with the MEM_Str flag.
18694 */
18695 #define MEM_Null 0x0001 /* Value is NULL (or a pointer) */
18696 #define MEM_Str 0x0002 /* Value is a string */
18697 #define MEM_Int 0x0004 /* Value is an integer */
18698 #define MEM_Real 0x0008 /* Value is a real number */
18699 #define MEM_Blob 0x0010 /* Value is a BLOB */
18700 #define MEM_AffMask 0x001f /* Mask of affinity bits */
18701 #define MEM_RowSet 0x0020 /* Value is a RowSet object */
18702 #define MEM_Frame 0x0040 /* Value is a VdbeFrame object */
18703 #define MEM_Undefined 0x0080 /* Value is undefined */
18704 #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */
18705 #define MEM_TypeMask 0xc1ff /* Mask of type bits */
18706
18707
18708 /* Whenever Mem contains a valid string or blob representation, one of
18709 ** the following flags must be set to determine the memory management
18710 ** policy for Mem.z. The MEM_Term flag tells us whether or not the
18711 ** string is \000 or \u0000 terminated
18712 */
18713 #define MEM_Term 0x0200 /* String in Mem.z is zero terminated */
18714 #define MEM_Dyn 0x0400 /* Need to call Mem.xDel() on Mem.z */
18715 #define MEM_Static 0x0800 /* Mem.z points to a static string */
18716 #define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
18717 #define MEM_Agg 0x2000 /* Mem.z points to an agg function context */
18718 #define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
@@ -18915,11 +18936,11 @@
18936 #ifdef SQLITE_OMIT_FLOATING_POINT
18937 # define sqlite3VdbeMemSetDouble sqlite3VdbeMemSetInt64
18938 #else
18939 SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem*, double);
18940 #endif
18941 SQLITE_PRIVATE void sqlite3VdbeMemSetPointer(Mem*, void*, const char*, void(*)(void*));
18942 SQLITE_PRIVATE void sqlite3VdbeMemInit(Mem*,sqlite3*,u16);
18943 SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem*);
18944 SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem*,int);
18945 SQLITE_PRIVATE void sqlite3VdbeMemSetRowSet(Mem*);
18946 SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*);
@@ -19721,11 +19742,11 @@
19742 double r;
19743 if( parseYyyyMmDd(zDate,p)==0 ){
19744 return 0;
19745 }else if( parseHhMmSs(zDate, p)==0 ){
19746 return 0;
19747 }else if( sqlite3StrICmp(zDate,"now")==0 && sqlite3NotPureFunc(context) ){
19748 return setDateTimeToCurrent(context, p);
19749 }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8) ){
19750 setRawDateNumber(p, r);
19751 return 0;
19752 }
@@ -20004,11 +20025,11 @@
20025 /* localtime
20026 **
20027 ** Assuming the current time value is UTC (a.k.a. GMT), shift it to
20028 ** show local time.
20029 */
20030 if( sqlite3_stricmp(z, "localtime")==0 && sqlite3NotPureFunc(pCtx) ){
20031 computeJD(p);
20032 p->iJD += localtimeOffset(p, pCtx, &rc);
20033 clearYMD_HMS_TZ(p);
20034 }
20035 break;
@@ -20030,11 +20051,11 @@
20051 p->rawS = 0;
20052 rc = 0;
20053 }
20054 }
20055 #ifndef SQLITE_OMIT_LOCALTIME
20056 else if( sqlite3_stricmp(z, "utc")==0 && sqlite3NotPureFunc(pCtx) ){
20057 if( p->tzSet==0 ){
20058 sqlite3_int64 c1;
20059 computeJD(p);
20060 c1 = localtimeOffset(p, pCtx, &rc);
20061 if( rc==SQLITE_OK ){
@@ -20566,15 +20587,15 @@
20587 ** external linkage.
20588 */
20589 SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void){
20590 static FuncDef aDateTimeFuncs[] = {
20591 #ifndef SQLITE_OMIT_DATETIME_FUNCS
20592 PURE_DATE(julianday, -1, 0, 0, juliandayFunc ),
20593 PURE_DATE(date, -1, 0, 0, dateFunc ),
20594 PURE_DATE(time, -1, 0, 0, timeFunc ),
20595 PURE_DATE(datetime, -1, 0, 0, datetimeFunc ),
20596 PURE_DATE(strftime, -1, 0, 0, strftimeFunc ),
20597 DFUNCTION(current_time, 0, 0, 0, ctimeFunc ),
20598 DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
20599 DFUNCTION(current_date, 0, 0, 0, cdateFunc ),
20600 #else
20601 STR_FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc),
@@ -30088,16 +30109,16 @@
30109 /* 64 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
30110 /* 65 */ "SCopy" OpHelp("r[P2]=r[P1]"),
30111 /* 66 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
30112 /* 67 */ "ResultRow" OpHelp("output=r[P1@P2]"),
30113 /* 68 */ "CollSeq" OpHelp(""),
30114 /* 69 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
30115 /* 70 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
30116 /* 71 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
30117 /* 72 */ "RealAffinity" OpHelp(""),
30118 /* 73 */ "Cast" OpHelp("affinity(r[P1])"),
30119 /* 74 */ "Permutation" OpHelp(""),
30120 /* 75 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
30121 /* 76 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
30122 /* 77 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
30123 /* 78 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
30124 /* 79 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
@@ -30113,82 +30134,84 @@
30134 /* 89 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
30135 /* 90 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
30136 /* 91 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
30137 /* 92 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
30138 /* 93 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
30139 /* 94 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
30140 /* 95 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
30141 /* 96 */ "Column" OpHelp("r[P3]=PX"),
30142 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
30143 /* 98 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
30144 /* 99 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
30145 /* 100 */ "Count" OpHelp("r[P2]=count()"),
30146 /* 101 */ "ReadCookie" OpHelp(""),
30147 /* 102 */ "SetCookie" OpHelp(""),
30148 /* 103 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
30149 /* 104 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
30150 /* 105 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
30151 /* 106 */ "OpenDup" OpHelp(""),
30152 /* 107 */ "OpenAutoindex" OpHelp("nColumn=P2"),
30153 /* 108 */ "OpenEphemeral" OpHelp("nColumn=P2"),
30154 /* 109 */ "SorterOpen" OpHelp(""),
30155 /* 110 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
30156 /* 111 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
30157 /* 112 */ "Close" OpHelp(""),
30158 /* 113 */ "ColumnsUsed" OpHelp(""),
30159 /* 114 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
30160 /* 115 */ "NewRowid" OpHelp("r[P2]=rowid"),
30161 /* 116 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
30162 /* 117 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
30163 /* 118 */ "Delete" OpHelp(""),
30164 /* 119 */ "ResetCount" OpHelp(""),
30165 /* 120 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
30166 /* 121 */ "SorterData" OpHelp("r[P2]=data"),
30167 /* 122 */ "RowData" OpHelp("r[P2]=data"),
30168 /* 123 */ "Rowid" OpHelp("r[P2]=rowid"),
30169 /* 124 */ "NullRow" OpHelp(""),
30170 /* 125 */ "SorterInsert" OpHelp("key=r[P2]"),
30171 /* 126 */ "IdxInsert" OpHelp("key=r[P2]"),
30172 /* 127 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
30173 /* 128 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
30174 /* 129 */ "IdxRowid" OpHelp("r[P2]=rowid"),
30175 /* 130 */ "Destroy" OpHelp(""),
30176 /* 131 */ "Clear" OpHelp(""),
30177 /* 132 */ "Real" OpHelp("r[P2]=P4"),
30178 /* 133 */ "ResetSorter" OpHelp(""),
30179 /* 134 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
30180 /* 135 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
30181 /* 136 */ "SqlExec" OpHelp(""),
30182 /* 137 */ "ParseSchema" OpHelp(""),
30183 /* 138 */ "LoadAnalysis" OpHelp(""),
30184 /* 139 */ "DropTable" OpHelp(""),
30185 /* 140 */ "DropIndex" OpHelp(""),
30186 /* 141 */ "DropTrigger" OpHelp(""),
30187 /* 142 */ "IntegrityCk" OpHelp(""),
30188 /* 143 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
30189 /* 144 */ "Param" OpHelp(""),
30190 /* 145 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
30191 /* 146 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
30192 /* 147 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
30193 /* 148 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
30194 /* 149 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
30195 /* 150 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
30196 /* 151 */ "Expire" OpHelp(""),
30197 /* 152 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
30198 /* 153 */ "VBegin" OpHelp(""),
30199 /* 154 */ "VCreate" OpHelp(""),
30200 /* 155 */ "VDestroy" OpHelp(""),
30201 /* 156 */ "VOpen" OpHelp(""),
30202 /* 157 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
30203 /* 158 */ "VRename" OpHelp(""),
30204 /* 159 */ "Pagecount" OpHelp(""),
30205 /* 160 */ "MaxPgcnt" OpHelp(""),
30206 /* 161 */ "PureFunc0" OpHelp(""),
30207 /* 162 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
30208 /* 163 */ "PureFunc" OpHelp(""),
30209 /* 164 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
30210 /* 165 */ "CursorHint" OpHelp(""),
30211 /* 166 */ "Noop" OpHelp(""),
30212 /* 167 */ "Explain" OpHelp(""),
30213 };
30214 return azName[i];
30215 }
30216 #endif
30217
@@ -70249,11 +70272,11 @@
70272 ** This routine is intended for use inside of assert() statements, like
70273 ** this: assert( sqlite3VdbeCheckMemInvariants(pMem) );
70274 */
70275 SQLITE_PRIVATE int sqlite3VdbeCheckMemInvariants(Mem *p){
70276 /* If MEM_Dyn is set then Mem.xDel!=0.
70277 ** Mem.xDel might not be initialized if MEM_Dyn is clear.
70278 */
70279 assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
70280
70281 /* MEM_Dyn may only be set if Mem.szMalloc==0. In this way we
70282 ** ensure that if Mem.szMalloc>0 then it is safe to do
@@ -70262,13 +70285,38 @@
70285 assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
70286
70287 /* Cannot be both MEM_Int and MEM_Real at the same time */
70288 assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
70289
70290 if( p->flags & MEM_Null ){
70291 /* Cannot be both MEM_Null and some other type */
70292 assert( (p->flags & (MEM_Int|MEM_Real|MEM_Str|MEM_Blob
70293 |MEM_RowSet|MEM_Frame|MEM_Agg|MEM_Zero))==0 );
70294
70295 /* If MEM_Null is set, then either the value is a pure NULL (the usual
70296 ** case) or it is a pointer set using sqlite3_bind_pointer() or
70297 ** sqlite3_result_pointer(). If a pointer, then MEM_Term must also be
70298 ** set.
70299 */
70300 if( (p->flags & (MEM_Term|MEM_Subtype))==(MEM_Term|MEM_Subtype) ){
70301 /* This is a pointer type. There may be a flag to indicate what to
70302 ** do with the pointer. */
70303 assert( ((p->flags&MEM_Dyn)!=0 ? 1 : 0) +
70304 ((p->flags&MEM_Ephem)!=0 ? 1 : 0) +
70305 ((p->flags&MEM_Static)!=0 ? 1 : 0) <= 1 );
70306
70307 /* No other bits set */
70308 assert( (p->flags & ~(MEM_Null|MEM_Term|MEM_Subtype
70309 |MEM_Dyn|MEM_Ephem|MEM_Static))==0 );
70310 }else{
70311 /* A pure NULL might have other flags, such as MEM_Static, MEM_Dyn,
70312 ** MEM_Ephem, MEM_Cleared, or MEM_Subtype */
70313 }
70314 }else{
70315 /* The MEM_Cleared bit is only allowed on NULLs */
70316 assert( (p->flags & MEM_Cleared)==0 );
70317 }
70318
70319 /* The szMalloc field holds the correct memory allocation size */
70320 assert( p->szMalloc==0
70321 || p->szMalloc==sqlite3DbMallocSize(p->db,p->zMalloc) );
70322
@@ -70927,19 +70975,29 @@
70975 pMem->u.i = val;
70976 pMem->flags = MEM_Int;
70977 }
70978 }
70979
70980 /* A no-op destructor */
70981 static void sqlite3NoopDestructor(void *p){ UNUSED_PARAMETER(p); }
70982
70983 /*
70984 ** Set the value stored in *pMem should already be a NULL.
70985 ** Also store a pointer to go with it.
70986 */
70987 SQLITE_PRIVATE void sqlite3VdbeMemSetPointer(
70988 Mem *pMem,
70989 void *pPtr,
70990 const char *zPType,
70991 void (*xDestructor)(void*)
70992 ){
70993 assert( pMem->flags==MEM_Null );
70994 pMem->u.zPType = zPType ? zPType : "";
70995 pMem->z = pPtr;
70996 pMem->flags = MEM_Null|MEM_Dyn|MEM_Subtype|MEM_Term;
70997 pMem->eSubtype = 'p';
70998 pMem->xDel = xDestructor ? xDestructor : sqlite3NoopDestructor;
70999 }
71000
71001 #ifndef SQLITE_OMIT_FLOATING_POINT
71002 /*
71003 ** Delete any previous value and set the value stored in *pMem to val,
@@ -76531,10 +76589,32 @@
76589 v->expmask |= 0x80000000;
76590 }else{
76591 v->expmask |= ((u32)1 << (iVar-1));
76592 }
76593 }
76594
76595 /*
76596 ** Cause a function to throw an error if it was call from OP_PureFunc
76597 ** rather than OP_Function.
76598 **
76599 ** OP_PureFunc means that the function must be deterministic, and should
76600 ** throw an error if it is given inputs that would make it non-deterministic.
76601 ** This routine is invoked by date/time functions that use non-deterministic
76602 ** features such as 'now'.
76603 */
76604 SQLITE_PRIVATE int sqlite3NotPureFunc(sqlite3_context *pCtx){
76605 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
76606 if( pCtx->pVdbe==0 ) return 1;
76607 #endif
76608 if( pCtx->pVdbe->aOp[pCtx->iOp].opcode==OP_PureFunc ){
76609 sqlite3_result_error(pCtx,
76610 "non-deterministic function in index expression or CHECK constraint",
76611 -1);
76612 return 0;
76613 }
76614 return 1;
76615 }
76616
76617 #ifndef SQLITE_OMIT_VIRTUALTABLE
76618 /*
76619 ** Transfer error message text from an sqlite3_vtab.zErrMsg (text stored
76620 ** in memory obtained from sqlite3_malloc) into a Vdbe.zErrMsg (text stored
@@ -76841,14 +76921,19 @@
76921 }
76922 SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value *pVal){
76923 Mem *pMem = (Mem*)pVal;
76924 return ((pMem->flags & MEM_Subtype) ? pMem->eSubtype : 0);
76925 }
76926 SQLITE_API void *sqlite3_value_pointer(sqlite3_value *pVal, const char *zPType){
76927 Mem *p = (Mem*)pVal;
76928 if( (p->flags&(MEM_TypeMask|MEM_Term|MEM_Subtype)) ==
76929 (MEM_Null|MEM_Term|MEM_Subtype)
76930 && zPType!=0
76931 && p->eSubtype=='p'
76932 && strcmp(p->u.zPType, zPType)==0
76933 ){
76934 return (void*)p->z;
76935 }else{
76936 return 0;
76937 }
76938 }
76939 SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value *pVal){
@@ -77027,15 +77112,20 @@
77112 }
77113 SQLITE_API void sqlite3_result_null(sqlite3_context *pCtx){
77114 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
77115 sqlite3VdbeMemSetNull(pCtx->pOut);
77116 }
77117 SQLITE_API void sqlite3_result_pointer(
77118 sqlite3_context *pCtx,
77119 void *pPtr,
77120 const char *zPType,
77121 void (*xDestructor)(void*)
77122 ){
77123 Mem *pOut = pCtx->pOut;
77124 assert( sqlite3_mutex_held(pOut->db->mutex) );
77125 sqlite3VdbeMemSetNull(pOut);
77126 sqlite3VdbeMemSetPointer(pOut, pPtr, zPType, xDestructor);
77127 }
77128 SQLITE_API void sqlite3_result_subtype(sqlite3_context *pCtx, unsigned int eSubtype){
77129 Mem *pOut = pCtx->pOut;
77130 assert( sqlite3_mutex_held(pOut->db->mutex) );
77131 pOut->eSubtype = eSubtype & 0xff;
@@ -78036,17 +78126,25 @@
78126 if( rc==SQLITE_OK ){
78127 sqlite3_mutex_leave(p->db->mutex);
78128 }
78129 return rc;
78130 }
78131 SQLITE_API int sqlite3_bind_pointer(
78132 sqlite3_stmt *pStmt,
78133 int i,
78134 void *pPtr,
78135 const char *zPTtype,
78136 void (*xDestructor)(void*)
78137 ){
78138 int rc;
78139 Vdbe *p = (Vdbe*)pStmt;
78140 rc = vdbeUnbind(p, i);
78141 if( rc==SQLITE_OK ){
78142 sqlite3VdbeMemSetPointer(&p->aVar[i-1], pPtr, zPTtype, xDestructor);
78143 sqlite3_mutex_leave(p->db->mutex);
78144 }else if( xDestructor ){
78145 xDestructor(pPtr);
78146 }
78147 return rc;
78148 }
78149 SQLITE_API int sqlite3_bind_text(
78150 sqlite3_stmt *pStmt,
@@ -80466,121 +80564,10 @@
80564 sqlite3VdbeMemSetInt64(&aMem[pOp->p1], 0);
80565 }
80566 break;
80567 }
80568
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80569 /* Opcode: BitAnd P1 P2 P3 * *
80570 ** Synopsis: r[P3]=r[P1]&r[P2]
80571 **
80572 ** Take the bit-wise AND of the values in register P1 and P2 and
80573 ** store the result in register P3.
@@ -85875,10 +85862,125 @@
85862 }
85863 pOut->u.i = sqlite3BtreeMaxPageCount(pBt, newMax);
85864 break;
85865 }
85866 #endif
85867
85868 /* Opcode: Function0 P1 P2 P3 P4 P5
85869 ** Synopsis: r[P3]=func(r[P2@P5])
85870 **
85871 ** Invoke a user function (P4 is a pointer to a FuncDef object that
85872 ** defines the function) with P5 arguments taken from register P2 and
85873 ** successors. The result of the function is stored in register P3.
85874 ** Register P3 must not be one of the function inputs.
85875 **
85876 ** P1 is a 32-bit bitmask indicating whether or not each argument to the
85877 ** function was determined to be constant at compile time. If the first
85878 ** argument was constant then bit 0 of P1 is set. This is used to determine
85879 ** whether meta data associated with a user function argument using the
85880 ** sqlite3_set_auxdata() API may be safely retained until the next
85881 ** invocation of this opcode.
85882 **
85883 ** See also: Function, AggStep, AggFinal
85884 */
85885 /* Opcode: Function P1 P2 P3 P4 P5
85886 ** Synopsis: r[P3]=func(r[P2@P5])
85887 **
85888 ** Invoke a user function (P4 is a pointer to an sqlite3_context object that
85889 ** contains a pointer to the function to be run) with P5 arguments taken
85890 ** from register P2 and successors. The result of the function is stored
85891 ** in register P3. Register P3 must not be one of the function inputs.
85892 **
85893 ** P1 is a 32-bit bitmask indicating whether or not each argument to the
85894 ** function was determined to be constant at compile time. If the first
85895 ** argument was constant then bit 0 of P1 is set. This is used to determine
85896 ** whether meta data associated with a user function argument using the
85897 ** sqlite3_set_auxdata() API may be safely retained until the next
85898 ** invocation of this opcode.
85899 **
85900 ** SQL functions are initially coded as OP_Function0 with P4 pointing
85901 ** to a FuncDef object. But on first evaluation, the P4 operand is
85902 ** automatically converted into an sqlite3_context object and the operation
85903 ** changed to this OP_Function opcode. In this way, the initialization of
85904 ** the sqlite3_context object occurs only once, rather than once for each
85905 ** evaluation of the function.
85906 **
85907 ** See also: Function0, AggStep, AggFinal
85908 */
85909 case OP_PureFunc0:
85910 case OP_Function0: {
85911 int n;
85912 sqlite3_context *pCtx;
85913
85914 assert( pOp->p4type==P4_FUNCDEF );
85915 n = pOp->p5;
85916 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
85917 assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem+1 - p->nCursor)+1) );
85918 assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+n );
85919 pCtx = sqlite3DbMallocRawNN(db, sizeof(*pCtx) + (n-1)*sizeof(sqlite3_value*));
85920 if( pCtx==0 ) goto no_mem;
85921 pCtx->pOut = 0;
85922 pCtx->pFunc = pOp->p4.pFunc;
85923 pCtx->iOp = (int)(pOp - aOp);
85924 pCtx->pVdbe = p;
85925 pCtx->argc = n;
85926 pOp->p4type = P4_FUNCCTX;
85927 pOp->p4.pCtx = pCtx;
85928 assert( OP_PureFunc == OP_PureFunc0+2 );
85929 assert( OP_Function == OP_Function0+2 );
85930 pOp->opcode += 2;
85931 /* Fall through into OP_Function */
85932 }
85933 case OP_PureFunc:
85934 case OP_Function: {
85935 int i;
85936 sqlite3_context *pCtx;
85937
85938 assert( pOp->p4type==P4_FUNCCTX );
85939 pCtx = pOp->p4.pCtx;
85940
85941 /* If this function is inside of a trigger, the register array in aMem[]
85942 ** might change from one evaluation to the next. The next block of code
85943 ** checks to see if the register array has changed, and if so it
85944 ** reinitializes the relavant parts of the sqlite3_context object */
85945 pOut = &aMem[pOp->p3];
85946 if( pCtx->pOut != pOut ){
85947 pCtx->pOut = pOut;
85948 for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
85949 }
85950
85951 memAboutToChange(p, pOut);
85952 #ifdef SQLITE_DEBUG
85953 for(i=0; i<pCtx->argc; i++){
85954 assert( memIsValid(pCtx->argv[i]) );
85955 REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]);
85956 }
85957 #endif
85958 MemSetTypeFlag(pOut, MEM_Null);
85959 pCtx->fErrorOrAux = 0;
85960 (*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */
85961
85962 /* If the function returned an error, throw an exception */
85963 if( pCtx->fErrorOrAux ){
85964 if( pCtx->isError ){
85965 sqlite3VdbeError(p, "%s", sqlite3_value_text(pOut));
85966 rc = pCtx->isError;
85967 }
85968 sqlite3VdbeDeleteAuxData(db, &p->pAuxData, pCtx->iOp, pOp->p1);
85969 if( rc ) goto abort_due_to_error;
85970 }
85971
85972 /* Copy the result of the function into register P3 */
85973 if( pOut->flags & (MEM_Str|MEM_Blob) ){
85974 sqlite3VdbeChangeEncoding(pOut, encoding);
85975 if( sqlite3VdbeMemTooBig(pOut) ) goto too_big;
85976 }
85977
85978 REGISTER_TRACE(pOp->p3, pOut);
85979 UPDATE_MAX_BLOBSIZE(pOut);
85980 break;
85981 }
85982
85983
85984 /* Opcode: Init P1 P2 * P4 *
85985 ** Synopsis: Start at P2
85986 **
@@ -94727,12 +94829,13 @@
94829 ){
94830 i16 iTabCol = pIdx->aiColumn[iIdxCol];
94831 if( iTabCol==XN_EXPR ){
94832 assert( pIdx->aColExpr );
94833 assert( pIdx->aColExpr->nExpr>iIdxCol );
94834 pParse->iSelfTab = iTabCur + 1;
94835 sqlite3ExprCodeCopy(pParse, pIdx->aColExpr->a[iIdxCol].pExpr, regOut);
94836 pParse->iSelfTab = 0;
94837 }else{
94838 sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pIdx->pTable, iTabCur,
94839 iTabCol, regOut);
94840 }
94841 }
@@ -94972,17 +95075,17 @@
95075 /* Otherwise, fall thru into the TK_COLUMN case */
95076 }
95077 case TK_COLUMN: {
95078 int iTab = pExpr->iTable;
95079 if( iTab<0 ){
95080 if( pParse->iSelfTab<0 ){
95081 /* Generating CHECK constraints or inserting into partial index */
95082 return pExpr->iColumn - pParse->iSelfTab;
95083 }else{
95084 /* Coding an expression that is part of an index where column names
95085 ** in the index refer to the table to which the index belongs */
95086 iTab = pParse->iSelfTab - 1;
95087 }
95088 }
95089 return sqlite3ExprCodeGetColumn(pParse, pExpr->pTab,
95090 pExpr->iColumn, iTab, target,
95091 pExpr->op2);
@@ -95315,12 +95418,12 @@
95418 #endif
95419 if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
95420 if( !pColl ) pColl = db->pDfltColl;
95421 sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
95422 }
95423 sqlite3VdbeAddOp4(v, pParse->iSelfTab ? OP_PureFunc0 : OP_Function0,
95424 constMask, r1, target, (char*)pDef, P4_FUNCDEF);
95425 sqlite3VdbeChangeP5(v, (u8)nFarg);
95426 if( nFarg && constMask==0 ){
95427 sqlite3ReleaseTempRange(pParse, r1, nFarg);
95428 }
95429 return target;
@@ -96744,12 +96847,12 @@
96847 */
96848 #ifdef SQLITE_DEBUG
96849 SQLITE_PRIVATE int sqlite3NoTempsInRange(Parse *pParse, int iFirst, int iLast){
96850 int i;
96851 if( pParse->nRangeReg>0
96852 && pParse->iRangeReg+pParse->nRangeReg > iFirst
96853 && pParse->iRangeReg <= iLast
96854 ){
96855 return 0;
96856 }
96857 for(i=0; i<pParse->nTempReg; i++){
96858 if( pParse->aTempReg[i]>=iFirst && pParse->aTempReg[i]<=iLast ){
@@ -102088,19 +102191,10 @@
102191 pPk = sqlite3PrimaryKeyIndex(pTab);
102192 pTab->iPKey = -1;
102193 }else{
102194 pPk = sqlite3PrimaryKeyIndex(pTab);
102195
 
 
 
 
 
 
 
 
 
102196 /*
102197 ** Remove all redundant columns from the PRIMARY KEY. For example, change
102198 ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)". Later
102199 ** code assumes the PRIMARY KEY contains no repeated columns.
102200 */
@@ -102115,10 +102209,19 @@
102209 }
102210 assert( pPk!=0 );
102211 pPk->isCovering = 1;
102212 if( !db->init.imposterTable ) pPk->uniqNotNull = 1;
102213 nPk = pPk->nKeyCol;
102214
102215 /* Bypass the creation of the PRIMARY KEY btree and the sqlite_master
102216 ** table entry. This is only required if currently generating VDBE
102217 ** code for a CREATE TABLE (not when parsing one as part of reading
102218 ** a database schema). */
102219 if( v && pPk->tnum>0 ){
102220 assert( db->init.busy==0 );
102221 sqlite3VdbeChangeOpcode(v, pPk->tnum, OP_Goto);
102222 }
102223
102224 /* The root page of the PRIMARY KEY is the table root page */
102225 pPk->tnum = pTab->tnum;
102226
102227 /* Update the in-memory representation of all UNIQUE indices by converting
@@ -106134,14 +106237,15 @@
106237 int nCol;
106238
106239 if( piPartIdxLabel ){
106240 if( pIdx->pPartIdxWhere ){
106241 *piPartIdxLabel = sqlite3VdbeMakeLabel(v);
106242 pParse->iSelfTab = iDataCur + 1;
106243 sqlite3ExprCachePush(pParse);
106244 sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel,
106245 SQLITE_JUMPIFNULL);
106246 pParse->iSelfTab = 0;
106247 }else{
106248 *piPartIdxLabel = 0;
106249 }
106250 }
106251 nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
@@ -110823,11 +110927,11 @@
110927 /* Test all CHECK constraints
110928 */
110929 #ifndef SQLITE_OMIT_CHECK
110930 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
110931 ExprList *pCheck = pTab->pCheck;
110932 pParse->iSelfTab = -(regNewData+1);
110933 onError = overrideError!=OE_Default ? overrideError : OE_Abort;
110934 for(i=0; i<pCheck->nExpr; i++){
110935 int allOk;
110936 Expr *pExpr = pCheck->a[i].pExpr;
110937 if( aiChng && checkConstraintUnchanged(pExpr, aiChng, pkChng) ) continue;
@@ -110843,10 +110947,11 @@
110947 onError, zName, P4_TRANSIENT,
110948 P5_ConstraintCheck);
110949 }
110950 sqlite3VdbeResolveLabel(v, allOk);
110951 }
110952 pParse->iSelfTab = 0;
110953 }
110954 #endif /* !defined(SQLITE_OMIT_CHECK) */
110955
110956 /* If rowid is changing, make sure the new rowid does not previously
110957 ** exist in the table.
@@ -110987,14 +111092,14 @@
111092 addrUniqueOk = sqlite3VdbeMakeLabel(v);
111093
111094 /* Skip partial indices for which the WHERE clause is not true */
111095 if( pIdx->pPartIdxWhere ){
111096 sqlite3VdbeAddOp2(v, OP_Null, 0, aRegIdx[ix]);
111097 pParse->iSelfTab = -(regNewData+1);
111098 sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, addrUniqueOk,
111099 SQLITE_JUMPIFNULL);
111100 pParse->iSelfTab = 0;
111101 }
111102
111103 /* Create a record for this index entry as it should appear after
111104 ** the insert or update. Store that record in the aRegIdx[ix] register
111105 */
@@ -111001,13 +111106,13 @@
111106 regIdx = aRegIdx[ix]+1;
111107 for(i=0; i<pIdx->nColumn; i++){
111108 int iField = pIdx->aiColumn[i];
111109 int x;
111110 if( iField==XN_EXPR ){
111111 pParse->iSelfTab = -(regNewData+1);
111112 sqlite3ExprCodeCopy(pParse, pIdx->aColExpr->a[i].pExpr, regIdx+i);
111113 pParse->iSelfTab = 0;
111114 VdbeComment((v, "%s column %d", pIdx->zName, i));
111115 }else{
111116 if( iField==XN_ROWID || iField==pTab->iPKey ){
111117 x = regNewData;
111118 }else{
@@ -112207,13 +112312,13 @@
112312 /* Version 3.20.0 and later */
112313 int (*prepare_v3)(sqlite3*,const char*,int,unsigned int,
112314 sqlite3_stmt**,const char**);
112315 int (*prepare16_v3)(sqlite3*,const void*,int,unsigned int,
112316 sqlite3_stmt**,const void**);
112317 int (*bind_pointer)(sqlite3_stmt*,int,void*,const char*,void(*)(void*));
112318 void (*result_pointer)(sqlite3_context*,void*,const char*,void(*)(void*));
112319 void *(*value_pointer)(sqlite3_value*,const char*);
112320 };
112321
112322 /*
112323 ** This is the function signature used for all extension entry points. It
112324 ** is also defined in the file "loadext.c".
@@ -115461,10 +115566,11 @@
115566 }
115567 aRoot[cnt] = 0;
115568
115569 /* Make sure sufficient number of registers have been allocated */
115570 pParse->nMem = MAX( pParse->nMem, 8+mxIdx );
115571 sqlite3ClearTempRegCache(pParse);
115572
115573 /* Do the b-tree integrity checks */
115574 sqlite3VdbeAddOp4(v, OP_IntegrityCk, 2, cnt, 1, (char*)aRoot,P4_INTARRAY);
115575 sqlite3VdbeChangeP5(v, (u8)i);
115576 addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
@@ -115526,18 +115632,19 @@
115632 if( db->mallocFailed==0 ){
115633 int addrCkFault = sqlite3VdbeMakeLabel(v);
115634 int addrCkOk = sqlite3VdbeMakeLabel(v);
115635 char *zErr;
115636 int k;
115637 pParse->iSelfTab = iDataCur + 1;
115638 sqlite3ExprCachePush(pParse);
115639 for(k=pCheck->nExpr-1; k>0; k--){
115640 sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
115641 }
115642 sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk,
115643 SQLITE_JUMPIFNULL);
115644 sqlite3VdbeResolveLabel(v, addrCkFault);
115645 pParse->iSelfTab = 0;
115646 zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
115647 pTab->zName);
115648 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
115649 integrityCheckResultRow(v, 3);
115650 sqlite3VdbeResolveLabel(v, addrCkOk);
@@ -115875,11 +115982,12 @@
115982 ** pragmas run by future database connections.
115983 **
115984 ** 0x0008 (Not yet implemented) Create indexes that might have
115985 ** been helpful to recent queries
115986 **
115987 ** The default MASK is and always shall be 0xfffe. 0xfffe means perform all
115988 ** of the optimizations listed above except Debug Mode, including new
115989 ** optimizations that have not yet been invented. If new optimizations are
115990 ** ever added that should be off by default, those off-by-default
115991 ** optimizations will have bitmasks of 0x10000 or larger.
115992 **
115993 ** DETERMINATION OF WHEN TO RUN ANALYZE
@@ -116302,14 +116410,18 @@
116410 UNUSED_PARAMETER(idxNum);
116411 UNUSED_PARAMETER(idxStr);
116412 pragmaVtabCursorClear(pCsr);
116413 j = (pTab->pName->mPragFlg & PragFlg_Result1)!=0 ? 0 : 1;
116414 for(i=0; i<argc; i++, j++){
116415 const char *zText = (const char*)sqlite3_value_text(argv[i]);
116416 assert( j<ArraySize(pCsr->azArg) );
116417 assert( pCsr->azArg[j]==0 );
116418 if( zText ){
116419 pCsr->azArg[j] = sqlite3_mprintf("%s", zText);
116420 if( pCsr->azArg[j]==0 ){
116421 return SQLITE_NOMEM;
116422 }
116423 }
116424 }
116425 sqlite3StrAccumInit(&acc, 0, 0, 0, pTab->db->aLimit[SQLITE_LIMIT_SQL_LENGTH]);
116426 sqlite3StrAccumAppendAll(&acc, "PRAGMA ");
116427 if( pCsr->azArg[1] ){
@@ -118758,17 +118870,14 @@
118870 if( pS ){
118871 /* The "table" is actually a sub-select or a view in the FROM clause
118872 ** of the SELECT statement. Return the declaration type and origin
118873 ** data for the result-set column of the sub-select.
118874 */
118875 if( iCol>=0 && iCol<pS->pEList->nExpr ){
118876 /* If iCol is less than zero, then the expression requests the
118877 ** rowid of the sub-select or view. This expression is legal (see
118878 ** test case misc2.2.2) - it always evaluates to NULL.
 
 
 
118879 */
118880 NameContext sNC;
118881 Expr *p = pS->pEList->a[iCol].pExpr;
118882 sNC.pSrcList = pS->pSrc;
118883 sNC.pNext = pNC;
@@ -118874,22 +118983,10 @@
118983 sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
118984 }
118985 #endif /* !defined(SQLITE_OMIT_DECLTYPE) */
118986 }
118987
 
 
 
 
 
 
 
 
 
 
 
 
118988
118989 /*
118990 ** Compute the column names for a SELECT statement.
118991 **
118992 ** The only guarantee that SQLite makes about column names is that if the
@@ -118919,28 +119016,33 @@
119016 ** then the result column name with the table name
119017 ** prefix, ex: TABLE.COLUMN. Otherwise use zSpan.
119018 */
119019 static void generateColumnNames(
119020 Parse *pParse, /* Parser context */
119021 Select *pSelect /* Generate column names for this SELECT statement */
 
119022 ){
119023 Vdbe *v = pParse->pVdbe;
119024 int i;
119025 Table *pTab;
119026 SrcList *pTabList;
119027 ExprList *pEList;
119028 sqlite3 *db = pParse->db;
119029 int fullName; /* TABLE.COLUMN if no AS clause and is a direct table ref */
119030 int srcName; /* COLUMN or TABLE.COLUMN if no AS clause and is direct */
119031
119032 #ifndef SQLITE_OMIT_EXPLAIN
119033 /* If this is an EXPLAIN, skip this step */
119034 if( pParse->explain ){
119035 return;
119036 }
119037 #endif
119038
119039 if( pParse->colNamesSet || db->mallocFailed ) return;
119040 /* Column names are determined by the left-most term of a compound select */
119041 while( pSelect->pPrior ) pSelect = pSelect->pPrior;
119042 pTabList = pSelect->pSrc;
119043 pEList = pSelect->pEList;
119044 assert( v!=0 );
119045 assert( pTabList!=0 );
119046 pParse->colNamesSet = 1;
119047 fullName = (db->flags & SQLITE_FullColNames)!=0;
119048 srcName = (db->flags & SQLITE_ShortColNames)!=0 || fullName;
@@ -118951,16 +119053,15 @@
119053 assert( p!=0 );
119054 if( pEList->a[i].zName ){
119055 /* An AS clause always takes first priority */
119056 char *zName = pEList->a[i].zName;
119057 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
119058 }else if( srcName && p->op==TK_COLUMN ){
 
 
 
119059 char *zCol;
119060 int iCol = p->iColumn;
119061 pTab = p->pTab;
119062 assert( pTab!=0 );
119063 if( iCol<0 ) iCol = pTab->iPKey;
119064 assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
119065 if( iCol<0 ){
119066 zCol = "rowid";
119067 }else{
@@ -119788,15 +119889,10 @@
119889 */
119890 assert( unionTab==dest.iSDParm || dest.eDest!=priorOp );
119891 if( dest.eDest!=priorOp ){
119892 int iCont, iBreak, iStart;
119893 assert( p->pEList );
 
 
 
 
 
119894 iBreak = sqlite3VdbeMakeLabel(v);
119895 iCont = sqlite3VdbeMakeLabel(v);
119896 computeLimitRegisters(pParse, p, iBreak);
119897 sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
119898 iStart = sqlite3VdbeCurrentAddr(v);
@@ -119863,15 +119959,10 @@
119959
119960 /* Generate code to take the intersection of the two temporary
119961 ** tables.
119962 */
119963 assert( p->pEList );
 
 
 
 
 
119964 iBreak = sqlite3VdbeMakeLabel(v);
119965 iCont = sqlite3VdbeMakeLabel(v);
119966 computeLimitRegisters(pParse, p, iBreak);
119967 sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
119968 r1 = sqlite3GetTempReg(pParse);
@@ -120475,18 +120566,10 @@
120566
120567 /* Jump to the this point in order to terminate the query.
120568 */
120569 sqlite3VdbeResolveLabel(v, labelEnd);
120570
 
 
 
 
 
 
 
 
120571 /* Reassembly the compound query so that it will be freed correctly
120572 ** by the calling function */
120573 if( p->pPrior ){
120574 sqlite3SelectDelete(db, p->pPrior);
120575 }
@@ -120659,12 +120742,13 @@
120742 ** and (2b) the outer query does not use subqueries other than the one
120743 ** FROM-clause subquery that is a candidate for flattening. (2b is
120744 ** due to ticket [2f7170d73bf9abf80] from 2015-02-09.)
120745 **
120746 ** (3) The subquery is not the right operand of a LEFT JOIN
120747 ** or (a) the subquery is not itself a join and (b) the FROM clause
120748 ** of the subquery does not contain a virtual table and (c) the
120749 ** outer query is not an aggregate.
120750 **
120751 ** (4) The subquery is not DISTINCT.
120752 **
120753 ** (**) At one point restrictions (4) and (5) defined a subset of DISTINCT
120754 ** sub-queries that were excluded from this optimization. Restriction
@@ -120776,11 +120860,10 @@
120860 Select *pParent; /* Current UNION ALL term of the other query */
120861 Select *pSub; /* The inner query or "subquery" */
120862 Select *pSub1; /* Pointer to the rightmost select in sub-query */
120863 SrcList *pSrc; /* The FROM clause of the outer query */
120864 SrcList *pSubSrc; /* The FROM clause of the subquery */
 
120865 int iParent; /* VDBE cursor number of the pSub result set temp table */
120866 int iNewParent = -1;/* Replacement table for iParent */
120867 int isLeftJoin = 0; /* True if pSub is the right side of a LEFT JOIN */
120868 int i; /* Loop counter */
120869 Expr *pWhere; /* The WHERE clause */
@@ -120865,11 +120948,11 @@
120948 **
120949 ** See also tickets #306, #350, and #3300.
120950 */
120951 if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
120952 isLeftJoin = 1;
120953 if( pSubSrc->nSrc>1 || isAgg || IsVirtual(pSubSrc->a[0].pTab) ){
120954 return 0; /* Restriction (3) */
120955 }
120956 }
120957 #ifdef SQLITE_EXTRA_IFNULLROW
120958 else if( iFrom>0 && !isAgg ){
@@ -121101,18 +121184,10 @@
121184 ** \_____________________ outer query ______________________________/
121185 **
121186 ** We look at every expression in the outer query and every place we see
121187 ** "a" we substitute "x*3" and every place we see "b" we substitute "y+10".
121188 */
 
 
 
 
 
 
 
 
121189 if( pSub->pOrderBy ){
121190 /* At this point, any non-zero iOrderByCol values indicate that the
121191 ** ORDER BY column expression is identical to the iOrderByCol'th
121192 ** expression returned by SELECT statement pSub. Since these values
121193 ** do not necessarily correspond to columns in SELECT statement pParent,
@@ -122537,10 +122612,18 @@
122612 if( sqlite3SelectTrace & 0x100 ){
122613 SELECTTRACE(0x100,pParse,p, ("after name resolution:\n"));
122614 sqlite3TreeViewSelect(0, p, 0);
122615 }
122616 #endif
122617
122618 /* Get a pointer the VDBE under construction, allocating a new VDBE if one
122619 ** does not already exist */
122620 v = sqlite3GetVdbe(pParse);
122621 if( v==0 ) goto select_end;
122622 if( pDest->eDest==SRT_Output ){
122623 generateColumnNames(pParse, p);
122624 }
122625
122626 /* Try to flatten subqueries in the FROM clause up into the main query
122627 */
122628 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
122629 for(i=0; !p->pPrior && i<pTabList->nSrc; i++){
@@ -122573,15 +122656,10 @@
122656 sSort.pOrderBy = p->pOrderBy;
122657 }
122658 }
122659 #endif
122660
 
 
 
 
 
122661 #ifndef SQLITE_OMIT_COMPOUND_SELECT
122662 /* Handle compound SELECT statements using the separate multiSelect()
122663 ** procedure.
122664 */
122665 if( p->pPrior ){
@@ -123377,16 +123455,10 @@
123455 ** successful coding of the SELECT.
123456 */
123457 select_end:
123458 explainSetInteger(pParse->iSelectId, iRestoreSelectId);
123459
 
 
 
 
 
 
123460 sqlite3DbFree(db, sAggInfo.aCol);
123461 sqlite3DbFree(db, sAggInfo.aFunc);
123462 #if SELECTTRACE_ENABLED
123463 SELECTTRACE(1,pParse,p,("end processing\n"));
123464 pParse->nSelectIndent--;
@@ -131980,10 +132052,19 @@
132052 Bitmask notReady /* Tables in outer loops of the join */
132053 ){
132054 char aff;
132055 if( pTerm->leftCursor!=pSrc->iCursor ) return 0;
132056 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) return 0;
132057 if( (pSrc->fg.jointype & JT_LEFT)
132058 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
132059 && (pTerm->eOperator & WO_IS)
132060 ){
132061 /* Cannot use an IS term from the WHERE clause as an index driver for
132062 ** the RHS of a LEFT JOIN. Such a term can only be used if it is from
132063 ** the ON clause. */
132064 return 0;
132065 }
132066 if( (pTerm->prereqRight & notReady)!=0 ) return 0;
132067 if( pTerm->u.leftColumn<0 ) return 0;
132068 aff = pSrc->pTab->aCol[pTerm->u.leftColumn].affinity;
132069 if( !sqlite3IndexAffinityOk(pTerm->pExpr, aff) ) return 0;
132070 testcase( pTerm->pExpr->op==TK_IS );
@@ -150278,11 +150359,11 @@
150359 assert( iCol>=0 && iCol<=p->nColumn+2 );
150360
150361 switch( iCol-p->nColumn ){
150362 case 0:
150363 /* The special 'table-name' column */
150364 sqlite3_result_pointer(pCtx, pCsr, "fts3cursor", 0);
150365 break;
150366
150367 case 1:
150368 /* The docid column */
150369 sqlite3_result_int64(pCtx, pCsr->iPrevId);
@@ -150497,11 +150578,11 @@
150578 const char *zFunc, /* Function name */
150579 sqlite3_value *pVal, /* argv[0] passed to function */
150580 Fts3Cursor **ppCsr /* OUT: Store cursor handle here */
150581 ){
150582 int rc;
150583 *ppCsr = (Fts3Cursor*)sqlite3_value_pointer(pVal, "fts3cursor");
150584 if( (*ppCsr)!=0 ){
150585 rc = SQLITE_OK;
150586 }else{
150587 char *zErr = sqlite3_mprintf("illegal first argument to %s", zFunc);
150588 sqlite3_result_error(pContext, zErr, -1);
@@ -165512,26 +165593,18 @@
165593 int (*xQueryFunc)(sqlite3_rtree_query_info*);
165594 void (*xDestructor)(void*);
165595 void *pContext;
165596 };
165597
 
 
 
 
 
 
 
 
165598 /*
165599 ** An instance of this structure (in the form of a BLOB) is returned by
165600 ** the SQL functions that sqlite3_rtree_geometry_callback() and
165601 ** sqlite3_rtree_query_callback() create, and is read as the right-hand
165602 ** operand to the MATCH operator of an R-Tree.
165603 */
165604 struct RtreeMatchArg {
165605 u32 iSize; /* Size of this object */
165606 RtreeGeomCallback cb; /* Info about the callback functions */
165607 int nParam; /* Number of parameters to the SQL function */
165608 sqlite3_value **apSqlParam; /* Original SQL parameter values */
165609 RtreeDValue aParam[1]; /* Values for parameters to the SQL function */
165610 };
@@ -166822,37 +166895,21 @@
166895 ** as the second argument for a MATCH constraint. The value passed as the
166896 ** first argument to this function is the right-hand operand to the MATCH
166897 ** operator.
166898 */
166899 static int deserializeGeometry(sqlite3_value *pValue, RtreeConstraint *pCons){
166900 RtreeMatchArg *pBlob, *pSrc; /* BLOB returned by geometry function */
166901 sqlite3_rtree_query_info *pInfo; /* Callback information */
166902
166903 pSrc = sqlite3_value_pointer(pValue, "RtreeMatchArg");
166904 if( pSrc==0 ) return SQLITE_ERROR;
166905 pInfo = (sqlite3_rtree_query_info*)
166906 sqlite3_malloc64( sizeof(*pInfo)+pSrc->iSize );
 
 
 
 
 
 
 
 
166907 if( !pInfo ) return SQLITE_NOMEM;
166908 memset(pInfo, 0, sizeof(*pInfo));
166909 pBlob = (RtreeMatchArg*)&pInfo[1];
166910 memcpy(pBlob, pSrc, pSrc->iSize);
 
 
 
 
 
 
 
 
166911 pInfo->pContext = pBlob->cb.pContext;
166912 pInfo->nParam = pBlob->nParam;
166913 pInfo->aParam = pBlob->aParam;
166914 pInfo->apSqlParam = pBlob->apSqlParam;
166915
@@ -168886,11 +168943,11 @@
168943 pBlob = (RtreeMatchArg *)sqlite3_malloc(nBlob);
168944 if( !pBlob ){
168945 sqlite3_result_error_nomem(ctx);
168946 }else{
168947 int i;
168948 pBlob->iSize = nBlob;
168949 pBlob->cb = pGeomCtx[0];
168950 pBlob->apSqlParam = (sqlite3_value**)&pBlob->aParam[nArg];
168951 pBlob->nParam = nArg;
168952 for(i=0; i<nArg; i++){
168953 pBlob->apSqlParam[i] = sqlite3_value_dup(aArg[i]);
@@ -168903,11 +168960,11 @@
168960 }
168961 if( memErr ){
168962 sqlite3_result_error_nomem(ctx);
168963 rtreeMatchArgFree(pBlob);
168964 }else{
168965 sqlite3_result_pointer(ctx, pBlob, "RtreeMatchArg", rtreeMatchArgFree);
168966 }
168967 }
168968 }
168969
168970 /*
@@ -200196,19 +200253,18 @@
200253 }
200254
200255 static void fts5Fts5Func(
200256 sqlite3_context *pCtx, /* Function call context */
200257 int nArg, /* Number of args */
200258 sqlite3_value **apArg /* Function arguments */
200259 ){
200260 Fts5Global *pGlobal = (Fts5Global*)sqlite3_user_data(pCtx);
200261 fts5_api **ppApi;
200262 UNUSED_PARAM(nArg);
200263 assert( nArg==1 );
200264 ppApi = (fts5_api**)sqlite3_value_pointer(apArg[0], "fts5_api_ptr");
200265 if( ppApi ) *ppApi = &pGlobal->api;
 
200266 }
200267
200268 /*
200269 ** Implementation of fts5_source_id() function.
200270 */
@@ -200217,11 +200273,11 @@
200273 int nArg, /* Number of args */
200274 sqlite3_value **apUnused /* Function arguments */
200275 ){
200276 assert( nArg==0 );
200277 UNUSED_PARAM2(nArg, apUnused);
200278 sqlite3_result_text(pCtx, "fts5: 2017-08-01 13:24:15 9501e22dfeebdcefa783575e47c60b514d7c2e0cad73b2a496c0bc4b680900a8", -1, SQLITE_TRANSIENT);
200279 }
200280
200281 static int fts5Init(sqlite3 *db){
200282 static const sqlite3_module fts5Mod = {
200283 /* iVersion */ 2,
@@ -200269,11 +200325,11 @@
200325 if( rc==SQLITE_OK ) rc = sqlite3Fts5AuxInit(&pGlobal->api);
200326 if( rc==SQLITE_OK ) rc = sqlite3Fts5TokenizerInit(&pGlobal->api);
200327 if( rc==SQLITE_OK ) rc = sqlite3Fts5VocabInit(pGlobal, db);
200328 if( rc==SQLITE_OK ){
200329 rc = sqlite3_create_function(
200330 db, "fts5", 1, SQLITE_UTF8, p, fts5Fts5Func, 0, 0
200331 );
200332 }
200333 if( rc==SQLITE_OK ){
200334 rc = sqlite3_create_function(
200335 db, "fts5_source_id", 0, SQLITE_UTF8, p, fts5SourceIdFunc, 0, 0
200336
+26 -21
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,11 +121,11 @@
121121
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122122
** [sqlite_version()] and [sqlite_source_id()].
123123
*/
124124
#define SQLITE_VERSION "3.20.0"
125125
#define SQLITE_VERSION_NUMBER 3020000
126
-#define SQLITE_SOURCE_ID "2017-07-15 13:49:56 47cf83a0682b7b3219cf255457f5fbe05f3c1f46be42f6bbab33b78a57a252f6"
126
+#define SQLITE_SOURCE_ID "2017-08-01 13:24:15 9501e22dfeebdcefa783575e47c60b514d7c2e0cad73b2a496c0bc4b680900a8"
127127
128128
/*
129129
** CAPI3REF: Run-Time Library Version Numbers
130130
** KEYWORDS: sqlite3_version sqlite3_sourceid
131131
**
@@ -3643,11 +3643,11 @@
36433643
);
36443644
SQLITE_API int sqlite3_prepare16_v3(
36453645
sqlite3 *db, /* Database handle */
36463646
const void *zSql, /* SQL statement, UTF-16 encoded */
36473647
int nByte, /* Maximum length of zSql in bytes. */
3648
- unsigned int prepFalgs, /* Zero or more SQLITE_PREPARE_ flags */
3648
+ unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
36493649
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
36503650
const void **pzTail /* OUT: Pointer to unused portion of zSql */
36513651
);
36523652
36533653
/*
@@ -3881,18 +3881,18 @@
38813881
** Zeroblobs are intended to serve as placeholders for BLOBs whose
38823882
** content is later written using
38833883
** [sqlite3_blob_open | incremental BLOB I/O] routines.
38843884
** ^A negative value for the zeroblob results in a zero-length BLOB.
38853885
**
3886
-** ^The sqlite3_bind_pointer(S,I,P) routine causes the I-th parameter in
3886
+** ^The sqlite3_bind_pointer(S,I,P,T,D) routine causes the I-th parameter in
38873887
** [prepared statement] S to have an SQL value of NULL, but to also be
3888
-** associated with the pointer P.
3889
-** ^The sqlite3_bind_pointer() routine can be used to pass
3890
-** host-language pointers into [application-defined SQL functions].
3891
-** ^A parameter that is initialized using [sqlite3_bind_pointer()] appears
3892
-** to be an ordinary SQL NULL value to everything other than
3893
-** [sqlite3_value_pointer()].
3888
+** associated with the pointer P of type T. ^D is either a NULL pointer or
3889
+** a pointer to a destructor function for P. ^SQLite will invoke the
3890
+** destructor D with a single argument of P when it is finished using
3891
+** P. The T parameter should be a static string, preferably a string
3892
+** literal. The sqlite3_bind_pointer() routine is part of the
3893
+** [pointer passing interface] added for SQLite 3.20.0.
38943894
**
38953895
** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
38963896
** for the [prepared statement] or with a prepared statement for which
38973897
** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
38983898
** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_()
@@ -3923,11 +3923,11 @@
39233923
SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
39243924
SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
39253925
SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
39263926
void(*)(void*), unsigned char encoding);
39273927
SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3928
-SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*);
3928
+SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const char*,void(*)(void*));
39293929
SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
39303930
SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
39313931
39323932
/*
39333933
** CAPI3REF: Number Of SQL Parameters
@@ -4197,11 +4197,11 @@
41974197
** For all versions of SQLite up to and including 3.6.23.1, a call to
41984198
** [sqlite3_reset()] was required after sqlite3_step() returned anything
41994199
** other than [SQLITE_ROW] before any subsequent invocation of
42004200
** sqlite3_step(). Failure to reset the prepared statement using
42014201
** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
4202
-** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1],
4202
+** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1]),
42034203
** sqlite3_step() began
42044204
** calling [sqlite3_reset()] automatically in this circumstance rather
42054205
** than returning [SQLITE_MISUSE]. This is not considered a compatibility
42064206
** break because any application that ever receives an SQLITE_MISUSE error
42074207
** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option
@@ -4756,13 +4756,15 @@
47564756
** in the native byte-order of the host machine. ^The
47574757
** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
47584758
** extract UTF-16 strings as big-endian and little-endian respectively.
47594759
**
47604760
** ^If [sqlite3_value] object V was initialized
4761
-** using [sqlite3_bind_pointer(S,I,P)] or [sqlite3_result_pointer(C,P)], then
4762
-** sqlite3_value_pointer(V) will return the pointer P. Otherwise,
4763
-** sqlite3_value_pointer(V) returns a NULL.
4761
+** using [sqlite3_bind_pointer(S,I,P,X,D)] or [sqlite3_result_pointer(C,P,X,D)]
4762
+** and if X and Y are strings that compare equal according to strcmp(X,Y),
4763
+** then sqlite3_value_pointer(V,Y) will return the pointer P. ^Otherwise,
4764
+** sqlite3_value_pointer(V,Y) returns a NULL. The sqlite3_bind_pointer()
4765
+** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
47644766
**
47654767
** ^(The sqlite3_value_type(V) interface returns the
47664768
** [SQLITE_INTEGER | datatype code] for the initial datatype of the
47674769
** [sqlite3_value] object V. The returned value is one of [SQLITE_INTEGER],
47684770
** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].)^
@@ -4792,11 +4794,11 @@
47924794
*/
47934795
SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
47944796
SQLITE_API double sqlite3_value_double(sqlite3_value*);
47954797
SQLITE_API int sqlite3_value_int(sqlite3_value*);
47964798
SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
4797
-SQLITE_API void *sqlite3_value_pointer(sqlite3_value*);
4799
+SQLITE_API void *sqlite3_value_pointer(sqlite3_value*, const char*);
47984800
SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);
47994801
SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);
48004802
SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
48014803
SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
48024804
SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
@@ -5093,17 +5095,20 @@
50935095
** be deallocated after sqlite3_result_value() returns without harm.
50945096
** ^A [protected sqlite3_value] object may always be used where an
50955097
** [unprotected sqlite3_value] object is required, so either
50965098
** kind of [sqlite3_value] object can be used with this interface.
50975099
**
5098
-** ^The sqlite3_result_pointer(C,P) interface sets the result to an
5100
+** ^The sqlite3_result_pointer(C,P,T,D) interface sets the result to an
50995101
** SQL NULL value, just like [sqlite3_result_null(C)], except that it
5100
-** also associates the host-language pointer P with that NULL value such
5101
-** that the pointer can be retrieved within an
5102
+** also associates the host-language pointer P or type T with that
5103
+** NULL value such that the pointer can be retrieved within an
51025104
** [application-defined SQL function] using [sqlite3_value_pointer()].
5103
-** This mechanism can be used to pass non-SQL values between
5104
-** application-defined functions.
5105
+** ^If the D parameter is not NULL, then it is a pointer to a destructor
5106
+** for the P parameter. ^SQLite invokes D with P as its only argument
5107
+** when SQLite is finished with P. The T parameter should be a static
5108
+** string and preferably a string literal. The sqlite3_result_pointer()
5109
+** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
51055110
**
51065111
** If these routines are called from within the different thread
51075112
** than the one containing the application-defined function that received
51085113
** the [sqlite3_context] pointer, the results are undefined.
51095114
*/
@@ -5124,11 +5129,11 @@
51245129
void(*)(void*), unsigned char encoding);
51255130
SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
51265131
SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
51275132
SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
51285133
SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
5129
-SQLITE_API void sqlite3_result_pointer(sqlite3_context*, void*);
5134
+SQLITE_API void sqlite3_result_pointer(sqlite3_context*, void*,const char*,void(*)(void*));
51305135
SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
51315136
SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
51325137
51335138
51345139
/*
51355140
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,11 +121,11 @@
121 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122 ** [sqlite_version()] and [sqlite_source_id()].
123 */
124 #define SQLITE_VERSION "3.20.0"
125 #define SQLITE_VERSION_NUMBER 3020000
126 #define SQLITE_SOURCE_ID "2017-07-15 13:49:56 47cf83a0682b7b3219cf255457f5fbe05f3c1f46be42f6bbab33b78a57a252f6"
127
128 /*
129 ** CAPI3REF: Run-Time Library Version Numbers
130 ** KEYWORDS: sqlite3_version sqlite3_sourceid
131 **
@@ -3643,11 +3643,11 @@
3643 );
3644 SQLITE_API int sqlite3_prepare16_v3(
3645 sqlite3 *db, /* Database handle */
3646 const void *zSql, /* SQL statement, UTF-16 encoded */
3647 int nByte, /* Maximum length of zSql in bytes. */
3648 unsigned int prepFalgs, /* Zero or more SQLITE_PREPARE_ flags */
3649 sqlite3_stmt **ppStmt, /* OUT: Statement handle */
3650 const void **pzTail /* OUT: Pointer to unused portion of zSql */
3651 );
3652
3653 /*
@@ -3881,18 +3881,18 @@
3881 ** Zeroblobs are intended to serve as placeholders for BLOBs whose
3882 ** content is later written using
3883 ** [sqlite3_blob_open | incremental BLOB I/O] routines.
3884 ** ^A negative value for the zeroblob results in a zero-length BLOB.
3885 **
3886 ** ^The sqlite3_bind_pointer(S,I,P) routine causes the I-th parameter in
3887 ** [prepared statement] S to have an SQL value of NULL, but to also be
3888 ** associated with the pointer P.
3889 ** ^The sqlite3_bind_pointer() routine can be used to pass
3890 ** host-language pointers into [application-defined SQL functions].
3891 ** ^A parameter that is initialized using [sqlite3_bind_pointer()] appears
3892 ** to be an ordinary SQL NULL value to everything other than
3893 ** [sqlite3_value_pointer()].
3894 **
3895 ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
3896 ** for the [prepared statement] or with a prepared statement for which
3897 ** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
3898 ** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_()
@@ -3923,11 +3923,11 @@
3923 SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
3924 SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
3925 SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
3926 void(*)(void*), unsigned char encoding);
3927 SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3928 SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*);
3929 SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3930 SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
3931
3932 /*
3933 ** CAPI3REF: Number Of SQL Parameters
@@ -4197,11 +4197,11 @@
4197 ** For all versions of SQLite up to and including 3.6.23.1, a call to
4198 ** [sqlite3_reset()] was required after sqlite3_step() returned anything
4199 ** other than [SQLITE_ROW] before any subsequent invocation of
4200 ** sqlite3_step(). Failure to reset the prepared statement using
4201 ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
4202 ** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1],
4203 ** sqlite3_step() began
4204 ** calling [sqlite3_reset()] automatically in this circumstance rather
4205 ** than returning [SQLITE_MISUSE]. This is not considered a compatibility
4206 ** break because any application that ever receives an SQLITE_MISUSE error
4207 ** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option
@@ -4756,13 +4756,15 @@
4756 ** in the native byte-order of the host machine. ^The
4757 ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
4758 ** extract UTF-16 strings as big-endian and little-endian respectively.
4759 **
4760 ** ^If [sqlite3_value] object V was initialized
4761 ** using [sqlite3_bind_pointer(S,I,P)] or [sqlite3_result_pointer(C,P)], then
4762 ** sqlite3_value_pointer(V) will return the pointer P. Otherwise,
4763 ** sqlite3_value_pointer(V) returns a NULL.
 
 
4764 **
4765 ** ^(The sqlite3_value_type(V) interface returns the
4766 ** [SQLITE_INTEGER | datatype code] for the initial datatype of the
4767 ** [sqlite3_value] object V. The returned value is one of [SQLITE_INTEGER],
4768 ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].)^
@@ -4792,11 +4794,11 @@
4792 */
4793 SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
4794 SQLITE_API double sqlite3_value_double(sqlite3_value*);
4795 SQLITE_API int sqlite3_value_int(sqlite3_value*);
4796 SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
4797 SQLITE_API void *sqlite3_value_pointer(sqlite3_value*);
4798 SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);
4799 SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);
4800 SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
4801 SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
4802 SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
@@ -5093,17 +5095,20 @@
5093 ** be deallocated after sqlite3_result_value() returns without harm.
5094 ** ^A [protected sqlite3_value] object may always be used where an
5095 ** [unprotected sqlite3_value] object is required, so either
5096 ** kind of [sqlite3_value] object can be used with this interface.
5097 **
5098 ** ^The sqlite3_result_pointer(C,P) interface sets the result to an
5099 ** SQL NULL value, just like [sqlite3_result_null(C)], except that it
5100 ** also associates the host-language pointer P with that NULL value such
5101 ** that the pointer can be retrieved within an
5102 ** [application-defined SQL function] using [sqlite3_value_pointer()].
5103 ** This mechanism can be used to pass non-SQL values between
5104 ** application-defined functions.
 
 
 
5105 **
5106 ** If these routines are called from within the different thread
5107 ** than the one containing the application-defined function that received
5108 ** the [sqlite3_context] pointer, the results are undefined.
5109 */
@@ -5124,11 +5129,11 @@
5124 void(*)(void*), unsigned char encoding);
5125 SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
5126 SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
5127 SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
5128 SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
5129 SQLITE_API void sqlite3_result_pointer(sqlite3_context*, void*);
5130 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
5131 SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
5132
5133
5134 /*
5135
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,11 +121,11 @@
121 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122 ** [sqlite_version()] and [sqlite_source_id()].
123 */
124 #define SQLITE_VERSION "3.20.0"
125 #define SQLITE_VERSION_NUMBER 3020000
126 #define SQLITE_SOURCE_ID "2017-08-01 13:24:15 9501e22dfeebdcefa783575e47c60b514d7c2e0cad73b2a496c0bc4b680900a8"
127
128 /*
129 ** CAPI3REF: Run-Time Library Version Numbers
130 ** KEYWORDS: sqlite3_version sqlite3_sourceid
131 **
@@ -3643,11 +3643,11 @@
3643 );
3644 SQLITE_API int sqlite3_prepare16_v3(
3645 sqlite3 *db, /* Database handle */
3646 const void *zSql, /* SQL statement, UTF-16 encoded */
3647 int nByte, /* Maximum length of zSql in bytes. */
3648 unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
3649 sqlite3_stmt **ppStmt, /* OUT: Statement handle */
3650 const void **pzTail /* OUT: Pointer to unused portion of zSql */
3651 );
3652
3653 /*
@@ -3881,18 +3881,18 @@
3881 ** Zeroblobs are intended to serve as placeholders for BLOBs whose
3882 ** content is later written using
3883 ** [sqlite3_blob_open | incremental BLOB I/O] routines.
3884 ** ^A negative value for the zeroblob results in a zero-length BLOB.
3885 **
3886 ** ^The sqlite3_bind_pointer(S,I,P,T,D) routine causes the I-th parameter in
3887 ** [prepared statement] S to have an SQL value of NULL, but to also be
3888 ** associated with the pointer P of type T. ^D is either a NULL pointer or
3889 ** a pointer to a destructor function for P. ^SQLite will invoke the
3890 ** destructor D with a single argument of P when it is finished using
3891 ** P. The T parameter should be a static string, preferably a string
3892 ** literal. The sqlite3_bind_pointer() routine is part of the
3893 ** [pointer passing interface] added for SQLite 3.20.0.
3894 **
3895 ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
3896 ** for the [prepared statement] or with a prepared statement for which
3897 ** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
3898 ** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_()
@@ -3923,11 +3923,11 @@
3923 SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
3924 SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
3925 SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
3926 void(*)(void*), unsigned char encoding);
3927 SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
3928 SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const char*,void(*)(void*));
3929 SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
3930 SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
3931
3932 /*
3933 ** CAPI3REF: Number Of SQL Parameters
@@ -4197,11 +4197,11 @@
4197 ** For all versions of SQLite up to and including 3.6.23.1, a call to
4198 ** [sqlite3_reset()] was required after sqlite3_step() returned anything
4199 ** other than [SQLITE_ROW] before any subsequent invocation of
4200 ** sqlite3_step(). Failure to reset the prepared statement using
4201 ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
4202 ** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1]),
4203 ** sqlite3_step() began
4204 ** calling [sqlite3_reset()] automatically in this circumstance rather
4205 ** than returning [SQLITE_MISUSE]. This is not considered a compatibility
4206 ** break because any application that ever receives an SQLITE_MISUSE error
4207 ** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option
@@ -4756,13 +4756,15 @@
4756 ** in the native byte-order of the host machine. ^The
4757 ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
4758 ** extract UTF-16 strings as big-endian and little-endian respectively.
4759 **
4760 ** ^If [sqlite3_value] object V was initialized
4761 ** using [sqlite3_bind_pointer(S,I,P,X,D)] or [sqlite3_result_pointer(C,P,X,D)]
4762 ** and if X and Y are strings that compare equal according to strcmp(X,Y),
4763 ** then sqlite3_value_pointer(V,Y) will return the pointer P. ^Otherwise,
4764 ** sqlite3_value_pointer(V,Y) returns a NULL. The sqlite3_bind_pointer()
4765 ** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
4766 **
4767 ** ^(The sqlite3_value_type(V) interface returns the
4768 ** [SQLITE_INTEGER | datatype code] for the initial datatype of the
4769 ** [sqlite3_value] object V. The returned value is one of [SQLITE_INTEGER],
4770 ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].)^
@@ -4792,11 +4794,11 @@
4794 */
4795 SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
4796 SQLITE_API double sqlite3_value_double(sqlite3_value*);
4797 SQLITE_API int sqlite3_value_int(sqlite3_value*);
4798 SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
4799 SQLITE_API void *sqlite3_value_pointer(sqlite3_value*, const char*);
4800 SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);
4801 SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);
4802 SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
4803 SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
4804 SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
@@ -5093,17 +5095,20 @@
5095 ** be deallocated after sqlite3_result_value() returns without harm.
5096 ** ^A [protected sqlite3_value] object may always be used where an
5097 ** [unprotected sqlite3_value] object is required, so either
5098 ** kind of [sqlite3_value] object can be used with this interface.
5099 **
5100 ** ^The sqlite3_result_pointer(C,P,T,D) interface sets the result to an
5101 ** SQL NULL value, just like [sqlite3_result_null(C)], except that it
5102 ** also associates the host-language pointer P or type T with that
5103 ** NULL value such that the pointer can be retrieved within an
5104 ** [application-defined SQL function] using [sqlite3_value_pointer()].
5105 ** ^If the D parameter is not NULL, then it is a pointer to a destructor
5106 ** for the P parameter. ^SQLite invokes D with P as its only argument
5107 ** when SQLite is finished with P. The T parameter should be a static
5108 ** string and preferably a string literal. The sqlite3_result_pointer()
5109 ** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
5110 **
5111 ** If these routines are called from within the different thread
5112 ** than the one containing the application-defined function that received
5113 ** the [sqlite3_context] pointer, the results are undefined.
5114 */
@@ -5124,11 +5129,11 @@
5129 void(*)(void*), unsigned char encoding);
5130 SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
5131 SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
5132 SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
5133 SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
5134 SQLITE_API void sqlite3_result_pointer(sqlite3_context*, void*,const char*,void(*)(void*));
5135 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
5136 SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
5137
5138
5139 /*
5140

Keyboard Shortcuts

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