| | @@ -1,8 +1,8 @@ |
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | | -** version 3.35.4. By combining all the individual C code files into this |
| 3 | +** version 3.36.0. By combining all the individual C code files into this |
| 4 | 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| | @@ -1184,13 +1184,13 @@ |
| 1184 | 1184 | ** |
| 1185 | 1185 | ** See also: [sqlite3_libversion()], |
| 1186 | 1186 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1187 | 1187 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1188 | 1188 | */ |
| 1189 | | -#define SQLITE_VERSION "3.35.4" |
| 1190 | | -#define SQLITE_VERSION_NUMBER 3035004 |
| 1191 | | -#define SQLITE_SOURCE_ID "2021-03-31 17:49:52 3b916924cef383f3d395e1f10aed6584d22d39a26f3b3c9919bd1afc0db635aa" |
| 1189 | +#define SQLITE_VERSION "3.36.0" |
| 1190 | +#define SQLITE_VERSION_NUMBER 3036000 |
| 1191 | +#define SQLITE_SOURCE_ID "2021-04-07 18:17:53 a2ddb89b206c13876d34c5f9e3db41cda72d6eb3fea31ffa8cc6daa1e1580e16" |
| 1192 | 1192 | |
| 1193 | 1193 | /* |
| 1194 | 1194 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1195 | 1195 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1196 | 1196 | ** |
| | @@ -2189,10 +2189,23 @@ |
| 2189 | 2189 | ** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint |
| 2190 | 2190 | ** in wal mode after the client has finished copying pages from the wal |
| 2191 | 2191 | ** file to the database file, but before the *-shm file is updated to |
| 2192 | 2192 | ** record the fact that the pages have been checkpointed. |
| 2193 | 2193 | ** </ul> |
| 2194 | +** |
| 2195 | +** <li>[[SQLITE_FCNTL_EXTERNAL_READER]] |
| 2196 | +** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect |
| 2197 | +** whether or not there is a database client in another process with a wal-mode |
| 2198 | +** transaction open on the database or not. It is only available on unix.The |
| 2199 | +** (void*) argument passed with this file-control should be a pointer to a |
| 2200 | +** value of type (int). The integer value is set to 1 if the database is a wal |
| 2201 | +** mode database and there exists at least one client in another process that |
| 2202 | +** currently has an SQL transaction open on the database. It is set to 0 if |
| 2203 | +** the database is not a wal-mode db, or if there is no such connection in any |
| 2204 | +** other process. This opcode cannot be used to detect transactions opened |
| 2205 | +** by clients within the current process, only within other processes. |
| 2206 | +** </ul> |
| 2194 | 2207 | */ |
| 2195 | 2208 | #define SQLITE_FCNTL_LOCKSTATE 1 |
| 2196 | 2209 | #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2 |
| 2197 | 2210 | #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3 |
| 2198 | 2211 | #define SQLITE_FCNTL_LAST_ERRNO 4 |
| | @@ -2228,10 +2241,12 @@ |
| 2228 | 2241 | #define SQLITE_FCNTL_DATA_VERSION 35 |
| 2229 | 2242 | #define SQLITE_FCNTL_SIZE_LIMIT 36 |
| 2230 | 2243 | #define SQLITE_FCNTL_CKPT_DONE 37 |
| 2231 | 2244 | #define SQLITE_FCNTL_RESERVE_BYTES 38 |
| 2232 | 2245 | #define SQLITE_FCNTL_CKPT_START 39 |
| 2246 | + |
| 2247 | +#define SQLITE_FCNTL_EXTERNAL_READER 40 |
| 2233 | 2248 | |
| 2234 | 2249 | /* deprecated names */ |
| 2235 | 2250 | #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE |
| 2236 | 2251 | #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE |
| 2237 | 2252 | #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO |
| | @@ -15758,11 +15773,11 @@ |
| 15758 | 15773 | #define OP_Eq 53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */ |
| 15759 | 15774 | #define OP_Gt 54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */ |
| 15760 | 15775 | #define OP_Le 55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */ |
| 15761 | 15776 | #define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */ |
| 15762 | 15777 | #define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */ |
| 15763 | | -#define OP_ElseNotEq 58 /* jump, same as TK_ESCAPE */ |
| 15778 | +#define OP_ElseEq 58 /* jump, same as TK_ESCAPE */ |
| 15764 | 15779 | #define OP_DecrJumpZero 59 /* jump, synopsis: if (--r[P1])==0 goto P2 */ |
| 15765 | 15780 | #define OP_IncrVacuum 60 /* jump */ |
| 15766 | 15781 | #define OP_VNext 61 /* jump */ |
| 15767 | 15782 | #define OP_Init 62 /* jump, synopsis: Start at P2 */ |
| 15768 | 15783 | #define OP_PureFunc 63 /* synopsis: r[P3]=func(r[P2@NP]) */ |
| | @@ -15789,23 +15804,23 @@ |
| 15789 | 15804 | #define OP_RealAffinity 84 |
| 15790 | 15805 | #define OP_Cast 85 /* synopsis: affinity(r[P1]) */ |
| 15791 | 15806 | #define OP_Permutation 86 |
| 15792 | 15807 | #define OP_Compare 87 /* synopsis: r[P1@P3] <-> r[P2@P3] */ |
| 15793 | 15808 | #define OP_IsTrue 88 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */ |
| 15794 | | -#define OP_Offset 89 /* synopsis: r[P3] = sqlite_offset(P1) */ |
| 15795 | | -#define OP_Column 90 /* synopsis: r[P3]=PX */ |
| 15796 | | -#define OP_Affinity 91 /* synopsis: affinity(r[P1@P2]) */ |
| 15797 | | -#define OP_MakeRecord 92 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ |
| 15798 | | -#define OP_Count 93 /* synopsis: r[P2]=count() */ |
| 15799 | | -#define OP_ReadCookie 94 |
| 15800 | | -#define OP_SetCookie 95 |
| 15801 | | -#define OP_ReopenIdx 96 /* synopsis: root=P2 iDb=P3 */ |
| 15802 | | -#define OP_OpenRead 97 /* synopsis: root=P2 iDb=P3 */ |
| 15803 | | -#define OP_OpenWrite 98 /* synopsis: root=P2 iDb=P3 */ |
| 15804 | | -#define OP_OpenDup 99 |
| 15805 | | -#define OP_OpenAutoindex 100 /* synopsis: nColumn=P2 */ |
| 15806 | | -#define OP_OpenEphemeral 101 /* synopsis: nColumn=P2 */ |
| 15809 | +#define OP_ZeroOrNull 89 /* synopsis: r[P2] = 0 OR NULL */ |
| 15810 | +#define OP_Offset 90 /* synopsis: r[P3] = sqlite_offset(P1) */ |
| 15811 | +#define OP_Column 91 /* synopsis: r[P3]=PX */ |
| 15812 | +#define OP_Affinity 92 /* synopsis: affinity(r[P1@P2]) */ |
| 15813 | +#define OP_MakeRecord 93 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ |
| 15814 | +#define OP_Count 94 /* synopsis: r[P2]=count() */ |
| 15815 | +#define OP_ReadCookie 95 |
| 15816 | +#define OP_SetCookie 96 |
| 15817 | +#define OP_ReopenIdx 97 /* synopsis: root=P2 iDb=P3 */ |
| 15818 | +#define OP_OpenRead 98 /* synopsis: root=P2 iDb=P3 */ |
| 15819 | +#define OP_OpenWrite 99 /* synopsis: root=P2 iDb=P3 */ |
| 15820 | +#define OP_OpenDup 100 |
| 15821 | +#define OP_OpenAutoindex 101 /* synopsis: nColumn=P2 */ |
| 15807 | 15822 | #define OP_BitAnd 102 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */ |
| 15808 | 15823 | #define OP_BitOr 103 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */ |
| 15809 | 15824 | #define OP_ShiftLeft 104 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */ |
| 15810 | 15825 | #define OP_ShiftRight 105 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */ |
| 15811 | 15826 | #define OP_Add 106 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */ |
| | @@ -15812,77 +15827,78 @@ |
| 15812 | 15827 | #define OP_Subtract 107 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */ |
| 15813 | 15828 | #define OP_Multiply 108 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */ |
| 15814 | 15829 | #define OP_Divide 109 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */ |
| 15815 | 15830 | #define OP_Remainder 110 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */ |
| 15816 | 15831 | #define OP_Concat 111 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */ |
| 15817 | | -#define OP_SorterOpen 112 |
| 15832 | +#define OP_OpenEphemeral 112 /* synopsis: nColumn=P2 */ |
| 15818 | 15833 | #define OP_BitNot 113 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */ |
| 15819 | | -#define OP_SequenceTest 114 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ |
| 15820 | | -#define OP_OpenPseudo 115 /* synopsis: P3 columns in r[P2] */ |
| 15834 | +#define OP_SorterOpen 114 |
| 15835 | +#define OP_SequenceTest 115 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ |
| 15821 | 15836 | #define OP_String8 116 /* same as TK_STRING, synopsis: r[P2]='P4' */ |
| 15822 | | -#define OP_Close 117 |
| 15823 | | -#define OP_ColumnsUsed 118 |
| 15824 | | -#define OP_SeekScan 119 /* synopsis: Scan-ahead up to P1 rows */ |
| 15825 | | -#define OP_SeekHit 120 /* synopsis: set P2<=seekHit<=P3 */ |
| 15826 | | -#define OP_Sequence 121 /* synopsis: r[P2]=cursor[P1].ctr++ */ |
| 15827 | | -#define OP_NewRowid 122 /* synopsis: r[P2]=rowid */ |
| 15828 | | -#define OP_Insert 123 /* synopsis: intkey=r[P3] data=r[P2] */ |
| 15829 | | -#define OP_RowCell 124 |
| 15830 | | -#define OP_Delete 125 |
| 15831 | | -#define OP_ResetCount 126 |
| 15832 | | -#define OP_SorterCompare 127 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ |
| 15833 | | -#define OP_SorterData 128 /* synopsis: r[P2]=data */ |
| 15834 | | -#define OP_RowData 129 /* synopsis: r[P2]=data */ |
| 15835 | | -#define OP_Rowid 130 /* synopsis: r[P2]=rowid */ |
| 15836 | | -#define OP_NullRow 131 |
| 15837 | | -#define OP_SeekEnd 132 |
| 15838 | | -#define OP_IdxInsert 133 /* synopsis: key=r[P2] */ |
| 15839 | | -#define OP_SorterInsert 134 /* synopsis: key=r[P2] */ |
| 15840 | | -#define OP_IdxDelete 135 /* synopsis: key=r[P2@P3] */ |
| 15841 | | -#define OP_DeferredSeek 136 /* synopsis: Move P3 to P1.rowid if needed */ |
| 15842 | | -#define OP_IdxRowid 137 /* synopsis: r[P2]=rowid */ |
| 15843 | | -#define OP_FinishSeek 138 |
| 15844 | | -#define OP_Destroy 139 |
| 15845 | | -#define OP_Clear 140 |
| 15846 | | -#define OP_ResetSorter 141 |
| 15847 | | -#define OP_CreateBtree 142 /* synopsis: r[P2]=root iDb=P1 flags=P3 */ |
| 15848 | | -#define OP_SqlExec 143 |
| 15849 | | -#define OP_ParseSchema 144 |
| 15850 | | -#define OP_LoadAnalysis 145 |
| 15851 | | -#define OP_DropTable 146 |
| 15852 | | -#define OP_DropIndex 147 |
| 15853 | | -#define OP_DropTrigger 148 |
| 15854 | | -#define OP_IntegrityCk 149 |
| 15855 | | -#define OP_RowSetAdd 150 /* synopsis: rowset(P1)=r[P2] */ |
| 15856 | | -#define OP_Param 151 |
| 15837 | +#define OP_OpenPseudo 117 /* synopsis: P3 columns in r[P2] */ |
| 15838 | +#define OP_Close 118 |
| 15839 | +#define OP_ColumnsUsed 119 |
| 15840 | +#define OP_SeekScan 120 /* synopsis: Scan-ahead up to P1 rows */ |
| 15841 | +#define OP_SeekHit 121 /* synopsis: set P2<=seekHit<=P3 */ |
| 15842 | +#define OP_Sequence 122 /* synopsis: r[P2]=cursor[P1].ctr++ */ |
| 15843 | +#define OP_NewRowid 123 /* synopsis: r[P2]=rowid */ |
| 15844 | +#define OP_Insert 124 /* synopsis: intkey=r[P3] data=r[P2] */ |
| 15845 | +#define OP_RowCell 125 |
| 15846 | +#define OP_Delete 126 |
| 15847 | +#define OP_ResetCount 127 |
| 15848 | +#define OP_SorterCompare 128 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ |
| 15849 | +#define OP_SorterData 129 /* synopsis: r[P2]=data */ |
| 15850 | +#define OP_RowData 130 /* synopsis: r[P2]=data */ |
| 15851 | +#define OP_Rowid 131 /* synopsis: r[P2]=rowid */ |
| 15852 | +#define OP_NullRow 132 |
| 15853 | +#define OP_SeekEnd 133 |
| 15854 | +#define OP_IdxInsert 134 /* synopsis: key=r[P2] */ |
| 15855 | +#define OP_SorterInsert 135 /* synopsis: key=r[P2] */ |
| 15856 | +#define OP_IdxDelete 136 /* synopsis: key=r[P2@P3] */ |
| 15857 | +#define OP_DeferredSeek 137 /* synopsis: Move P3 to P1.rowid if needed */ |
| 15858 | +#define OP_IdxRowid 138 /* synopsis: r[P2]=rowid */ |
| 15859 | +#define OP_FinishSeek 139 |
| 15860 | +#define OP_Destroy 140 |
| 15861 | +#define OP_Clear 141 |
| 15862 | +#define OP_ResetSorter 142 |
| 15863 | +#define OP_CreateBtree 143 /* synopsis: r[P2]=root iDb=P1 flags=P3 */ |
| 15864 | +#define OP_SqlExec 144 |
| 15865 | +#define OP_ParseSchema 145 |
| 15866 | +#define OP_LoadAnalysis 146 |
| 15867 | +#define OP_DropTable 147 |
| 15868 | +#define OP_DropIndex 148 |
| 15869 | +#define OP_DropTrigger 149 |
| 15870 | +#define OP_IntegrityCk 150 |
| 15871 | +#define OP_RowSetAdd 151 /* synopsis: rowset(P1)=r[P2] */ |
| 15857 | 15872 | #define OP_Real 152 /* same as TK_FLOAT, synopsis: r[P2]=P4 */ |
| 15858 | | -#define OP_FkCounter 153 /* synopsis: fkctr[P1]+=P2 */ |
| 15859 | | -#define OP_MemMax 154 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 15860 | | -#define OP_OffsetLimit 155 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ |
| 15861 | | -#define OP_AggInverse 156 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */ |
| 15862 | | -#define OP_AggStep 157 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 15863 | | -#define OP_AggStep1 158 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 15864 | | -#define OP_AggValue 159 /* synopsis: r[P3]=value N=P2 */ |
| 15865 | | -#define OP_AggFinal 160 /* synopsis: accum=r[P1] N=P2 */ |
| 15866 | | -#define OP_Expire 161 |
| 15867 | | -#define OP_CursorLock 162 |
| 15868 | | -#define OP_CursorUnlock 163 |
| 15869 | | -#define OP_TableLock 164 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 15870 | | -#define OP_VBegin 165 |
| 15871 | | -#define OP_VCreate 166 |
| 15872 | | -#define OP_VDestroy 167 |
| 15873 | | -#define OP_VOpen 168 |
| 15874 | | -#define OP_VColumn 169 /* synopsis: r[P3]=vcolumn(P2) */ |
| 15875 | | -#define OP_VRename 170 |
| 15876 | | -#define OP_Pagecount 171 |
| 15877 | | -#define OP_MaxPgcnt 172 |
| 15878 | | -#define OP_Trace 173 |
| 15879 | | -#define OP_CursorHint 174 |
| 15880 | | -#define OP_ReleaseReg 175 /* synopsis: release r[P1@P2] mask P3 */ |
| 15881 | | -#define OP_Noop 176 |
| 15882 | | -#define OP_Explain 177 |
| 15883 | | -#define OP_Abortable 178 |
| 15873 | +#define OP_Param 153 |
| 15874 | +#define OP_FkCounter 154 /* synopsis: fkctr[P1]+=P2 */ |
| 15875 | +#define OP_MemMax 155 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 15876 | +#define OP_OffsetLimit 156 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ |
| 15877 | +#define OP_AggInverse 157 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */ |
| 15878 | +#define OP_AggStep 158 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 15879 | +#define OP_AggStep1 159 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 15880 | +#define OP_AggValue 160 /* synopsis: r[P3]=value N=P2 */ |
| 15881 | +#define OP_AggFinal 161 /* synopsis: accum=r[P1] N=P2 */ |
| 15882 | +#define OP_Expire 162 |
| 15883 | +#define OP_CursorLock 163 |
| 15884 | +#define OP_CursorUnlock 164 |
| 15885 | +#define OP_TableLock 165 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 15886 | +#define OP_VBegin 166 |
| 15887 | +#define OP_VCreate 167 |
| 15888 | +#define OP_VDestroy 168 |
| 15889 | +#define OP_VOpen 169 |
| 15890 | +#define OP_VColumn 170 /* synopsis: r[P3]=vcolumn(P2) */ |
| 15891 | +#define OP_VRename 171 |
| 15892 | +#define OP_Pagecount 172 |
| 15893 | +#define OP_MaxPgcnt 173 |
| 15894 | +#define OP_Trace 174 |
| 15895 | +#define OP_CursorHint 175 |
| 15896 | +#define OP_ReleaseReg 176 /* synopsis: release r[P1@P2] mask P3 */ |
| 15897 | +#define OP_Noop 177 |
| 15898 | +#define OP_Explain 178 |
| 15899 | +#define OP_Abortable 179 |
| 15884 | 15900 | |
| 15885 | 15901 | /* Properties such as "out2" or "jump" that are specified in |
| 15886 | 15902 | ** comments following the "case" for each opcode in the vdbe.c |
| 15887 | 15903 | ** are encoded into bitvectors as follows: |
| 15888 | 15904 | */ |
| | @@ -15902,22 +15918,22 @@ |
| 15902 | 15918 | /* 48 */ 0x03, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\ |
| 15903 | 15919 | /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x01, 0x01, 0x01, 0x00,\ |
| 15904 | 15920 | /* 64 */ 0x00, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10,\ |
| 15905 | 15921 | /* 72 */ 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10,\ |
| 15906 | 15922 | /* 80 */ 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,\ |
| 15907 | | -/* 88 */ 0x12, 0x20, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\ |
| 15923 | +/* 88 */ 0x12, 0x1e, 0x20, 0x00, 0x00, 0x00, 0x10, 0x10,\ |
| 15908 | 15924 | /* 96 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x26,\ |
| 15909 | 15925 | /* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\ |
| 15910 | 15926 | /* 112 */ 0x00, 0x12, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,\ |
| 15911 | | -/* 120 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 15912 | | -/* 128 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x04, 0x04, 0x00,\ |
| 15913 | | -/* 136 */ 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00,\ |
| 15914 | | -/* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10,\ |
| 15915 | | -/* 152 */ 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00,\ |
| 15927 | +/* 120 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\ |
| 15928 | +/* 128 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x04, 0x04,\ |
| 15929 | +/* 136 */ 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10,\ |
| 15930 | +/* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,\ |
| 15931 | +/* 152 */ 0x10, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00,\ |
| 15916 | 15932 | /* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 15917 | | -/* 168 */ 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,\ |
| 15918 | | -/* 176 */ 0x00, 0x00, 0x00,} |
| 15933 | +/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\ |
| 15934 | +/* 176 */ 0x00, 0x00, 0x00, 0x00,} |
| 15919 | 15935 | |
| 15920 | 15936 | /* The sqlite3P2Values() routine is able to run faster if it knows |
| 15921 | 15937 | ** the value of the largest JUMP opcode. The smaller the maximum |
| 15922 | 15938 | ** JUMP opcode the better, so the mkopcodeh.tcl script that |
| 15923 | 15939 | ** generated this include file strives to group all JUMP opcodes |
| | @@ -17005,14 +17021,11 @@ |
| 17005 | 17021 | u8 iDb; /* Which db file is being initialized */ |
| 17006 | 17022 | u8 busy; /* TRUE if currently initializing */ |
| 17007 | 17023 | unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */ |
| 17008 | 17024 | unsigned imposterTable : 1; /* Building an imposter table */ |
| 17009 | 17025 | unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */ |
| 17010 | | - unsigned bDropColumn : 1; /* Doing schema check after DROP COLUMN */ |
| 17011 | 17026 | char **azInit; /* "type", "name", and "tbl_name" columns */ |
| 17012 | | - /* or if bDropColumn, then azInit[0] is the */ |
| 17013 | | - /* name of the column being dropped */ |
| 17014 | 17027 | } init; |
| 17015 | 17028 | int nVdbeActive; /* Number of VDBEs currently running */ |
| 17016 | 17029 | int nVdbeRead; /* Number of active VDBEs that read or write */ |
| 17017 | 17030 | int nVdbeWrite; /* Number of active VDBEs that read and write */ |
| 17018 | 17031 | int nVdbeExec; /* Number of nested calls to VdbeExec() */ |
| | @@ -17579,13 +17592,11 @@ |
| 17579 | 17592 | ** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL. |
| 17580 | 17593 | ** It causes an assert() to fire if either operand to a comparison |
| 17581 | 17594 | ** operator is NULL. It is added to certain comparison operators to |
| 17582 | 17595 | ** prove that the operands are always NOT NULL. |
| 17583 | 17596 | */ |
| 17584 | | -#define SQLITE_KEEPNULL 0x08 /* Used by vector == or <> */ |
| 17585 | 17597 | #define SQLITE_JUMPIFNULL 0x10 /* jumps if either operand is NULL */ |
| 17586 | | -#define SQLITE_STOREP2 0x20 /* Store result in reg[P2] rather than jump */ |
| 17587 | 17598 | #define SQLITE_NULLEQ 0x80 /* NULL=NULL */ |
| 17588 | 17599 | #define SQLITE_NOTNULL 0x90 /* Assert that operands are never NULL */ |
| 17589 | 17600 | |
| 17590 | 17601 | /* |
| 17591 | 17602 | ** An object of this type is created for each virtual table present in |
| | @@ -18078,10 +18089,11 @@ |
| 18078 | 18089 | struct AggInfo_func { /* For each aggregate function */ |
| 18079 | 18090 | Expr *pFExpr; /* Expression encoding the function */ |
| 18080 | 18091 | FuncDef *pFunc; /* The aggregate function implementation */ |
| 18081 | 18092 | int iMem; /* Memory location that acts as accumulator */ |
| 18082 | 18093 | int iDistinct; /* Ephemeral table used to enforce DISTINCT */ |
| 18094 | + int iDistAddr; /* Address of OP_OpenEphemeral */ |
| 18083 | 18095 | } *aFunc; |
| 18084 | 18096 | int nFunc; /* Number of entries in aFunc[] */ |
| 18085 | 18097 | u32 selId; /* Select to which this AggInfo belongs */ |
| 18086 | 18098 | }; |
| 18087 | 18099 | |
| | @@ -18350,10 +18362,11 @@ |
| 18350 | 18362 | ** ENAME_SPAN Text of the original result set |
| 18351 | 18363 | ** expression. |
| 18352 | 18364 | */ |
| 18353 | 18365 | struct ExprList { |
| 18354 | 18366 | int nExpr; /* Number of expressions on the list */ |
| 18367 | + int nAlloc; /* Number of a[] slots allocated */ |
| 18355 | 18368 | struct ExprList_item { /* For each expression in the list */ |
| 18356 | 18369 | Expr *pExpr; /* The parse tree for this expression */ |
| 18357 | 18370 | char *zEName; /* Token associated with this expression */ |
| 18358 | 18371 | u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */ |
| 18359 | 18372 | unsigned eEName :2; /* Meaning of zEName */ |
| | @@ -18494,11 +18507,11 @@ |
| 18494 | 18507 | ** the OR optimization */ |
| 18495 | 18508 | #define WHERE_GROUPBY 0x0040 /* pOrderBy is really a GROUP BY */ |
| 18496 | 18509 | #define WHERE_DISTINCTBY 0x0080 /* pOrderby is really a DISTINCT clause */ |
| 18497 | 18510 | #define WHERE_WANT_DISTINCT 0x0100 /* All output needs to be distinct */ |
| 18498 | 18511 | #define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */ |
| 18499 | | - /* 0x0400 not currently used */ |
| 18512 | +#define WHERE_AGG_DISTINCT 0x0400 /* Query is "SELECT agg(DISTINCT ...)" */ |
| 18500 | 18513 | #define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */ |
| 18501 | 18514 | /* 0x1000 not currently used */ |
| 18502 | 18515 | /* 0x2000 not currently used */ |
| 18503 | 18516 | #define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */ |
| 18504 | 18517 | /* 0x8000 not currently used */ |
| | @@ -20213,10 +20226,13 @@ |
| 20213 | 20226 | SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); |
| 20214 | 20227 | #ifndef SQLITE_AMALGAMATION |
| 20215 | 20228 | SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[]; |
| 20216 | 20229 | SQLITE_PRIVATE const char sqlite3StrBINARY[]; |
| 20217 | 20230 | SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[]; |
| 20231 | +SQLITE_PRIVATE const unsigned char *sqlite3aLTb; |
| 20232 | +SQLITE_PRIVATE const unsigned char *sqlite3aEQb; |
| 20233 | +SQLITE_PRIVATE const unsigned char *sqlite3aGTb; |
| 20218 | 20234 | SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[]; |
| 20219 | 20235 | SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config; |
| 20220 | 20236 | SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions; |
| 20221 | 20237 | #ifndef SQLITE_OMIT_WSD |
| 20222 | 20238 | SQLITE_PRIVATE int sqlite3PendingByte; |
| | @@ -20679,11 +20695,11 @@ |
| 20679 | 20695 | 162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179, |
| 20680 | 20696 | 180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197, |
| 20681 | 20697 | 198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215, |
| 20682 | 20698 | 216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233, |
| 20683 | 20699 | 234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251, |
| 20684 | | - 252,253,254,255 |
| 20700 | + 252,253,254,255, |
| 20685 | 20701 | #endif |
| 20686 | 20702 | #ifdef SQLITE_EBCDIC |
| 20687 | 20703 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 0x */ |
| 20688 | 20704 | 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, /* 1x */ |
| 20689 | 20705 | 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, /* 2x */ |
| | @@ -20699,11 +20715,39 @@ |
| 20699 | 20715 | 192,129,130,131,132,133,134,135,136,137,202,203,204,205,206,207, /* Cx */ |
| 20700 | 20716 | 208,145,146,147,148,149,150,151,152,153,218,219,220,221,222,223, /* Dx */ |
| 20701 | 20717 | 224,225,162,163,164,165,166,167,168,169,234,235,236,237,238,239, /* Ex */ |
| 20702 | 20718 | 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255, /* Fx */ |
| 20703 | 20719 | #endif |
| 20720 | +/* All of the upper-to-lower conversion data is above. The following |
| 20721 | +** 18 integers are completely unrelated. They are appended to the |
| 20722 | +** sqlite3UpperToLower[] array to avoid UBSAN warnings. Here's what is |
| 20723 | +** going on: |
| 20724 | +** |
| 20725 | +** The SQL comparison operators (<>, =, >, <=, <, and >=) are implemented |
| 20726 | +** by invoking sqlite3MemCompare(A,B) which compares values A and B and |
| 20727 | +** returns negative, zero, or positive if A is less then, equal to, or |
| 20728 | +** greater than B, respectively. Then the true false results is found by |
| 20729 | +** consulting sqlite3aLTb[opcode], sqlite3aEQb[opcode], or |
| 20730 | +** sqlite3aGTb[opcode] depending on whether the result of compare(A,B) |
| 20731 | +** is negative, zero, or positive, where opcode is the specific opcode. |
| 20732 | +** The only works because the comparison opcodes are consecutive and in |
| 20733 | +** this order: NE EQ GT LE LT GE. Various assert()s throughout the code |
| 20734 | +** ensure that is the case. |
| 20735 | +** |
| 20736 | +** These elements must be appended to another array. Otherwise the |
| 20737 | +** index (here shown as [256-OP_Ne]) would be out-of-bounds and thus |
| 20738 | +** be undefined behavior. That's goofy, but the C-standards people thought |
| 20739 | +** it was a good idea, so here we are. |
| 20740 | +*/ |
| 20741 | +/* NE EQ GT LE LT GE */ |
| 20742 | + 1, 0, 0, 1, 1, 0, /* aLTb[]: Use when compare(A,B) less than zero */ |
| 20743 | + 0, 1, 0, 1, 0, 1, /* aEQb[]: Use when compare(A,B) equals zero */ |
| 20744 | + 1, 0, 1, 0, 0, 1 /* aGTb[]: Use when compare(A,B) greater than zero*/ |
| 20704 | 20745 | }; |
| 20746 | +SQLITE_PRIVATE const unsigned char *sqlite3aLTb = &sqlite3UpperToLower[256-OP_Ne]; |
| 20747 | +SQLITE_PRIVATE const unsigned char *sqlite3aEQb = &sqlite3UpperToLower[256+6-OP_Ne]; |
| 20748 | +SQLITE_PRIVATE const unsigned char *sqlite3aGTb = &sqlite3UpperToLower[256+12-OP_Ne]; |
| 20705 | 20749 | |
| 20706 | 20750 | /* |
| 20707 | 20751 | ** The following 256 byte lookup table is used to support SQLites built-in |
| 20708 | 20752 | ** equivalents to the following standard library functions: |
| 20709 | 20753 | ** |
| | @@ -23472,11 +23516,11 @@ |
| 23472 | 23516 | return rc; |
| 23473 | 23517 | } |
| 23474 | 23518 | SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ |
| 23475 | 23519 | DO_OS_MALLOC_TEST(0); |
| 23476 | 23520 | assert( dirSync==0 || dirSync==1 ); |
| 23477 | | - return pVfs->xDelete(pVfs, zPath, dirSync); |
| 23521 | + return pVfs->xDelete!=0 ? pVfs->xDelete(pVfs, zPath, dirSync) : SQLITE_OK; |
| 23478 | 23522 | } |
| 23479 | 23523 | SQLITE_PRIVATE int sqlite3OsAccess( |
| 23480 | 23524 | sqlite3_vfs *pVfs, |
| 23481 | 23525 | const char *zPath, |
| 23482 | 23526 | int flags, |
| | @@ -28461,11 +28505,11 @@ |
| 28461 | 28505 | /* The rest are extensions, not normally found in printf() */ |
| 28462 | 28506 | #define etSQLESCAPE 9 /* Strings with '\'' doubled. %q */ |
| 28463 | 28507 | #define etSQLESCAPE2 10 /* Strings with '\'' doubled and enclosed in '', |
| 28464 | 28508 | NULL pointers replaced by SQL NULL. %Q */ |
| 28465 | 28509 | #define etTOKEN 11 /* a pointer to a Token structure */ |
| 28466 | | -#define etSRCLIST 12 /* a pointer to a SrcList */ |
| 28510 | +#define etSRCITEM 12 /* a pointer to a SrcItem */ |
| 28467 | 28511 | #define etPOINTER 13 /* The %p conversion */ |
| 28468 | 28512 | #define etSQLESCAPE3 14 /* %w -> Strings with '\"' doubled */ |
| 28469 | 28513 | #define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */ |
| 28470 | 28514 | #define etDECIMAL 16 /* %d or %u, but not %x, %o */ |
| 28471 | 28515 | |
| | @@ -28527,13 +28571,19 @@ |
| 28527 | 28571 | { '%', 0, 0, etPERCENT, 0, 0 }, |
| 28528 | 28572 | { 'p', 16, 0, etPOINTER, 0, 1 }, |
| 28529 | 28573 | |
| 28530 | 28574 | /* All the rest are undocumented and are for internal use only */ |
| 28531 | 28575 | { 'T', 0, 0, etTOKEN, 0, 0 }, |
| 28532 | | - { 'S', 0, 0, etSRCLIST, 0, 0 }, |
| 28576 | + { 'S', 0, 0, etSRCITEM, 0, 0 }, |
| 28533 | 28577 | { 'r', 10, 1, etORDINAL, 0, 0 }, |
| 28534 | 28578 | }; |
| 28579 | + |
| 28580 | +/* Notes: |
| 28581 | +** |
| 28582 | +** %S Takes a pointer to SrcItem. Shows name or database.name |
| 28583 | +** %!S Like %S but prefer the zName over the zAlias |
| 28584 | +*/ |
| 28535 | 28585 | |
| 28536 | 28586 | /* Floating point constants used for rounding */ |
| 28537 | 28587 | static const double arRound[] = { |
| 28538 | 28588 | 5.0e-01, 5.0e-02, 5.0e-03, 5.0e-04, 5.0e-05, |
| 28539 | 28589 | 5.0e-06, 5.0e-07, 5.0e-08, 5.0e-09, 5.0e-10, |
| | @@ -29285,25 +29335,28 @@ |
| 29285 | 29335 | sqlite3_str_append(pAccum, (const char*)pToken->z, pToken->n); |
| 29286 | 29336 | } |
| 29287 | 29337 | length = width = 0; |
| 29288 | 29338 | break; |
| 29289 | 29339 | } |
| 29290 | | - case etSRCLIST: { |
| 29291 | | - SrcList *pSrc; |
| 29292 | | - int k; |
| 29340 | + case etSRCITEM: { |
| 29293 | 29341 | SrcItem *pItem; |
| 29294 | 29342 | if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return; |
| 29295 | | - pSrc = va_arg(ap, SrcList*); |
| 29296 | | - k = va_arg(ap, int); |
| 29297 | | - pItem = &pSrc->a[k]; |
| 29343 | + pItem = va_arg(ap, SrcItem*); |
| 29298 | 29344 | assert( bArgList==0 ); |
| 29299 | | - assert( k>=0 && k<pSrc->nSrc ); |
| 29300 | | - if( pItem->zDatabase ){ |
| 29301 | | - sqlite3_str_appendall(pAccum, pItem->zDatabase); |
| 29302 | | - sqlite3_str_append(pAccum, ".", 1); |
| 29345 | + if( pItem->zAlias && !flag_altform2 ){ |
| 29346 | + sqlite3_str_appendall(pAccum, pItem->zAlias); |
| 29347 | + }else if( pItem->zName ){ |
| 29348 | + if( pItem->zDatabase ){ |
| 29349 | + sqlite3_str_appendall(pAccum, pItem->zDatabase); |
| 29350 | + sqlite3_str_append(pAccum, ".", 1); |
| 29351 | + } |
| 29352 | + sqlite3_str_appendall(pAccum, pItem->zName); |
| 29353 | + }else if( pItem->zAlias ){ |
| 29354 | + sqlite3_str_appendall(pAccum, pItem->zAlias); |
| 29355 | + }else if( ALWAYS(pItem->pSelect) ){ |
| 29356 | + sqlite3_str_appendf(pAccum, "SUBQUERY %u", pItem->pSelect->selId); |
| 29303 | 29357 | } |
| 29304 | | - sqlite3_str_appendall(pAccum, pItem->zName); |
| 29305 | 29358 | length = width = 0; |
| 29306 | 29359 | break; |
| 29307 | 29360 | } |
| 29308 | 29361 | default: { |
| 29309 | 29362 | assert( xtype==etINVALID ); |
| | @@ -29879,23 +29932,15 @@ |
| 29879 | 29932 | for(i=0; i<pSrc->nSrc; i++){ |
| 29880 | 29933 | const SrcItem *pItem = &pSrc->a[i]; |
| 29881 | 29934 | StrAccum x; |
| 29882 | 29935 | char zLine[100]; |
| 29883 | 29936 | sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); |
| 29884 | | - sqlite3_str_appendf(&x, "{%d:*}", pItem->iCursor); |
| 29885 | | - if( pItem->zDatabase ){ |
| 29886 | | - sqlite3_str_appendf(&x, " %s.%s", pItem->zDatabase, pItem->zName); |
| 29887 | | - }else if( pItem->zName ){ |
| 29888 | | - sqlite3_str_appendf(&x, " %s", pItem->zName); |
| 29889 | | - } |
| 29937 | + sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem); |
| 29890 | 29938 | if( pItem->pTab ){ |
| 29891 | 29939 | sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx", |
| 29892 | 29940 | pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, pItem->colUsed); |
| 29893 | 29941 | } |
| 29894 | | - if( pItem->zAlias ){ |
| 29895 | | - sqlite3_str_appendf(&x, " (AS %s)", pItem->zAlias); |
| 29896 | | - } |
| 29897 | 29942 | if( pItem->fg.jointype & JT_LEFT ){ |
| 29898 | 29943 | sqlite3_str_appendf(&x, " LEFT-JOIN"); |
| 29899 | 29944 | } |
| 29900 | 29945 | if( pItem->fg.fromDDL ){ |
| 29901 | 29946 | sqlite3_str_appendf(&x, " DDL"); |
| | @@ -33531,11 +33576,11 @@ |
| 33531 | 33576 | /* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"), |
| 33532 | 33577 | /* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"), |
| 33533 | 33578 | /* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"), |
| 33534 | 33579 | /* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"), |
| 33535 | 33580 | /* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"), |
| 33536 | | - /* 58 */ "ElseNotEq" OpHelp(""), |
| 33581 | + /* 58 */ "ElseEq" OpHelp(""), |
| 33537 | 33582 | /* 59 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"), |
| 33538 | 33583 | /* 60 */ "IncrVacuum" OpHelp(""), |
| 33539 | 33584 | /* 61 */ "VNext" OpHelp(""), |
| 33540 | 33585 | /* 62 */ "Init" OpHelp("Start at P2"), |
| 33541 | 33586 | /* 63 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"), |
| | @@ -33562,23 +33607,23 @@ |
| 33562 | 33607 | /* 84 */ "RealAffinity" OpHelp(""), |
| 33563 | 33608 | /* 85 */ "Cast" OpHelp("affinity(r[P1])"), |
| 33564 | 33609 | /* 86 */ "Permutation" OpHelp(""), |
| 33565 | 33610 | /* 87 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"), |
| 33566 | 33611 | /* 88 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"), |
| 33567 | | - /* 89 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"), |
| 33568 | | - /* 90 */ "Column" OpHelp("r[P3]=PX"), |
| 33569 | | - /* 91 */ "Affinity" OpHelp("affinity(r[P1@P2])"), |
| 33570 | | - /* 92 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), |
| 33571 | | - /* 93 */ "Count" OpHelp("r[P2]=count()"), |
| 33572 | | - /* 94 */ "ReadCookie" OpHelp(""), |
| 33573 | | - /* 95 */ "SetCookie" OpHelp(""), |
| 33574 | | - /* 96 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), |
| 33575 | | - /* 97 */ "OpenRead" OpHelp("root=P2 iDb=P3"), |
| 33576 | | - /* 98 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), |
| 33577 | | - /* 99 */ "OpenDup" OpHelp(""), |
| 33578 | | - /* 100 */ "OpenAutoindex" OpHelp("nColumn=P2"), |
| 33579 | | - /* 101 */ "OpenEphemeral" OpHelp("nColumn=P2"), |
| 33612 | + /* 89 */ "ZeroOrNull" OpHelp("r[P2] = 0 OR NULL"), |
| 33613 | + /* 90 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"), |
| 33614 | + /* 91 */ "Column" OpHelp("r[P3]=PX"), |
| 33615 | + /* 92 */ "Affinity" OpHelp("affinity(r[P1@P2])"), |
| 33616 | + /* 93 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), |
| 33617 | + /* 94 */ "Count" OpHelp("r[P2]=count()"), |
| 33618 | + /* 95 */ "ReadCookie" OpHelp(""), |
| 33619 | + /* 96 */ "SetCookie" OpHelp(""), |
| 33620 | + /* 97 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), |
| 33621 | + /* 98 */ "OpenRead" OpHelp("root=P2 iDb=P3"), |
| 33622 | + /* 99 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), |
| 33623 | + /* 100 */ "OpenDup" OpHelp(""), |
| 33624 | + /* 101 */ "OpenAutoindex" OpHelp("nColumn=P2"), |
| 33580 | 33625 | /* 102 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"), |
| 33581 | 33626 | /* 103 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"), |
| 33582 | 33627 | /* 104 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"), |
| 33583 | 33628 | /* 105 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"), |
| 33584 | 33629 | /* 106 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"), |
| | @@ -33585,77 +33630,78 @@ |
| 33585 | 33630 | /* 107 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"), |
| 33586 | 33631 | /* 108 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"), |
| 33587 | 33632 | /* 109 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"), |
| 33588 | 33633 | /* 110 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"), |
| 33589 | 33634 | /* 111 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"), |
| 33590 | | - /* 112 */ "SorterOpen" OpHelp(""), |
| 33635 | + /* 112 */ "OpenEphemeral" OpHelp("nColumn=P2"), |
| 33591 | 33636 | /* 113 */ "BitNot" OpHelp("r[P2]= ~r[P1]"), |
| 33592 | | - /* 114 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), |
| 33593 | | - /* 115 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), |
| 33637 | + /* 114 */ "SorterOpen" OpHelp(""), |
| 33638 | + /* 115 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), |
| 33594 | 33639 | /* 116 */ "String8" OpHelp("r[P2]='P4'"), |
| 33595 | | - /* 117 */ "Close" OpHelp(""), |
| 33596 | | - /* 118 */ "ColumnsUsed" OpHelp(""), |
| 33597 | | - /* 119 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"), |
| 33598 | | - /* 120 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"), |
| 33599 | | - /* 121 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), |
| 33600 | | - /* 122 */ "NewRowid" OpHelp("r[P2]=rowid"), |
| 33601 | | - /* 123 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), |
| 33602 | | - /* 124 */ "RowCell" OpHelp(""), |
| 33603 | | - /* 125 */ "Delete" OpHelp(""), |
| 33604 | | - /* 126 */ "ResetCount" OpHelp(""), |
| 33605 | | - /* 127 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), |
| 33606 | | - /* 128 */ "SorterData" OpHelp("r[P2]=data"), |
| 33607 | | - /* 129 */ "RowData" OpHelp("r[P2]=data"), |
| 33608 | | - /* 130 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 33609 | | - /* 131 */ "NullRow" OpHelp(""), |
| 33610 | | - /* 132 */ "SeekEnd" OpHelp(""), |
| 33611 | | - /* 133 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 33612 | | - /* 134 */ "SorterInsert" OpHelp("key=r[P2]"), |
| 33613 | | - /* 135 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 33614 | | - /* 136 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"), |
| 33615 | | - /* 137 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 33616 | | - /* 138 */ "FinishSeek" OpHelp(""), |
| 33617 | | - /* 139 */ "Destroy" OpHelp(""), |
| 33618 | | - /* 140 */ "Clear" OpHelp(""), |
| 33619 | | - /* 141 */ "ResetSorter" OpHelp(""), |
| 33620 | | - /* 142 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"), |
| 33621 | | - /* 143 */ "SqlExec" OpHelp(""), |
| 33622 | | - /* 144 */ "ParseSchema" OpHelp(""), |
| 33623 | | - /* 145 */ "LoadAnalysis" OpHelp(""), |
| 33624 | | - /* 146 */ "DropTable" OpHelp(""), |
| 33625 | | - /* 147 */ "DropIndex" OpHelp(""), |
| 33626 | | - /* 148 */ "DropTrigger" OpHelp(""), |
| 33627 | | - /* 149 */ "IntegrityCk" OpHelp(""), |
| 33628 | | - /* 150 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), |
| 33629 | | - /* 151 */ "Param" OpHelp(""), |
| 33640 | + /* 117 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), |
| 33641 | + /* 118 */ "Close" OpHelp(""), |
| 33642 | + /* 119 */ "ColumnsUsed" OpHelp(""), |
| 33643 | + /* 120 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"), |
| 33644 | + /* 121 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"), |
| 33645 | + /* 122 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), |
| 33646 | + /* 123 */ "NewRowid" OpHelp("r[P2]=rowid"), |
| 33647 | + /* 124 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), |
| 33648 | + /* 125 */ "RowCell" OpHelp(""), |
| 33649 | + /* 126 */ "Delete" OpHelp(""), |
| 33650 | + /* 127 */ "ResetCount" OpHelp(""), |
| 33651 | + /* 128 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), |
| 33652 | + /* 129 */ "SorterData" OpHelp("r[P2]=data"), |
| 33653 | + /* 130 */ "RowData" OpHelp("r[P2]=data"), |
| 33654 | + /* 131 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 33655 | + /* 132 */ "NullRow" OpHelp(""), |
| 33656 | + /* 133 */ "SeekEnd" OpHelp(""), |
| 33657 | + /* 134 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 33658 | + /* 135 */ "SorterInsert" OpHelp("key=r[P2]"), |
| 33659 | + /* 136 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 33660 | + /* 137 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"), |
| 33661 | + /* 138 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 33662 | + /* 139 */ "FinishSeek" OpHelp(""), |
| 33663 | + /* 140 */ "Destroy" OpHelp(""), |
| 33664 | + /* 141 */ "Clear" OpHelp(""), |
| 33665 | + /* 142 */ "ResetSorter" OpHelp(""), |
| 33666 | + /* 143 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"), |
| 33667 | + /* 144 */ "SqlExec" OpHelp(""), |
| 33668 | + /* 145 */ "ParseSchema" OpHelp(""), |
| 33669 | + /* 146 */ "LoadAnalysis" OpHelp(""), |
| 33670 | + /* 147 */ "DropTable" OpHelp(""), |
| 33671 | + /* 148 */ "DropIndex" OpHelp(""), |
| 33672 | + /* 149 */ "DropTrigger" OpHelp(""), |
| 33673 | + /* 150 */ "IntegrityCk" OpHelp(""), |
| 33674 | + /* 151 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), |
| 33630 | 33675 | /* 152 */ "Real" OpHelp("r[P2]=P4"), |
| 33631 | | - /* 153 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), |
| 33632 | | - /* 154 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), |
| 33633 | | - /* 155 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), |
| 33634 | | - /* 156 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"), |
| 33635 | | - /* 157 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 33636 | | - /* 158 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 33637 | | - /* 159 */ "AggValue" OpHelp("r[P3]=value N=P2"), |
| 33638 | | - /* 160 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), |
| 33639 | | - /* 161 */ "Expire" OpHelp(""), |
| 33640 | | - /* 162 */ "CursorLock" OpHelp(""), |
| 33641 | | - /* 163 */ "CursorUnlock" OpHelp(""), |
| 33642 | | - /* 164 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 33643 | | - /* 165 */ "VBegin" OpHelp(""), |
| 33644 | | - /* 166 */ "VCreate" OpHelp(""), |
| 33645 | | - /* 167 */ "VDestroy" OpHelp(""), |
| 33646 | | - /* 168 */ "VOpen" OpHelp(""), |
| 33647 | | - /* 169 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), |
| 33648 | | - /* 170 */ "VRename" OpHelp(""), |
| 33649 | | - /* 171 */ "Pagecount" OpHelp(""), |
| 33650 | | - /* 172 */ "MaxPgcnt" OpHelp(""), |
| 33651 | | - /* 173 */ "Trace" OpHelp(""), |
| 33652 | | - /* 174 */ "CursorHint" OpHelp(""), |
| 33653 | | - /* 175 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"), |
| 33654 | | - /* 176 */ "Noop" OpHelp(""), |
| 33655 | | - /* 177 */ "Explain" OpHelp(""), |
| 33656 | | - /* 178 */ "Abortable" OpHelp(""), |
| 33676 | + /* 153 */ "Param" OpHelp(""), |
| 33677 | + /* 154 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), |
| 33678 | + /* 155 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), |
| 33679 | + /* 156 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), |
| 33680 | + /* 157 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"), |
| 33681 | + /* 158 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 33682 | + /* 159 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 33683 | + /* 160 */ "AggValue" OpHelp("r[P3]=value N=P2"), |
| 33684 | + /* 161 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), |
| 33685 | + /* 162 */ "Expire" OpHelp(""), |
| 33686 | + /* 163 */ "CursorLock" OpHelp(""), |
| 33687 | + /* 164 */ "CursorUnlock" OpHelp(""), |
| 33688 | + /* 165 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 33689 | + /* 166 */ "VBegin" OpHelp(""), |
| 33690 | + /* 167 */ "VCreate" OpHelp(""), |
| 33691 | + /* 168 */ "VDestroy" OpHelp(""), |
| 33692 | + /* 169 */ "VOpen" OpHelp(""), |
| 33693 | + /* 170 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), |
| 33694 | + /* 171 */ "VRename" OpHelp(""), |
| 33695 | + /* 172 */ "Pagecount" OpHelp(""), |
| 33696 | + /* 173 */ "MaxPgcnt" OpHelp(""), |
| 33697 | + /* 174 */ "Trace" OpHelp(""), |
| 33698 | + /* 175 */ "CursorHint" OpHelp(""), |
| 33699 | + /* 176 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"), |
| 33700 | + /* 177 */ "Noop" OpHelp(""), |
| 33701 | + /* 178 */ "Explain" OpHelp(""), |
| 33702 | + /* 179 */ "Abortable" OpHelp(""), |
| 33657 | 33703 | }; |
| 33658 | 33704 | return azName[i]; |
| 33659 | 33705 | } |
| 33660 | 33706 | #endif |
| 33661 | 33707 | |
| | @@ -37810,10 +37856,11 @@ |
| 37810 | 37856 | } |
| 37811 | 37857 | } |
| 37812 | 37858 | |
| 37813 | 37859 | /* Forward declaration */ |
| 37814 | 37860 | static int unixGetTempname(int nBuf, char *zBuf); |
| 37861 | +static int unixFcntlExternalReader(unixFile*, int*); |
| 37815 | 37862 | |
| 37816 | 37863 | /* |
| 37817 | 37864 | ** Information and control of an open file handle. |
| 37818 | 37865 | */ |
| 37819 | 37866 | static int unixFileControl(sqlite3_file *id, int op, void *pArg){ |
| | @@ -37926,10 +37973,14 @@ |
| 37926 | 37973 | case SQLITE_FCNTL_SET_LOCKPROXYFILE: |
| 37927 | 37974 | case SQLITE_FCNTL_GET_LOCKPROXYFILE: { |
| 37928 | 37975 | return proxyFileControl(id,op,pArg); |
| 37929 | 37976 | } |
| 37930 | 37977 | #endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */ |
| 37978 | + |
| 37979 | + case SQLITE_FCNTL_EXTERNAL_READER: { |
| 37980 | + return unixFcntlExternalReader((unixFile*)id, (int*)pArg); |
| 37981 | + } |
| 37931 | 37982 | } |
| 37932 | 37983 | return SQLITE_NOTFOUND; |
| 37933 | 37984 | } |
| 37934 | 37985 | |
| 37935 | 37986 | /* |
| | @@ -38170,10 +38221,44 @@ |
| 38170 | 38221 | /* |
| 38171 | 38222 | ** Constants used for locking |
| 38172 | 38223 | */ |
| 38173 | 38224 | #define UNIX_SHM_BASE ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */ |
| 38174 | 38225 | #define UNIX_SHM_DMS (UNIX_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */ |
| 38226 | + |
| 38227 | +/* |
| 38228 | +** Use F_GETLK to check whether or not there are any readers with open |
| 38229 | +** wal-mode transactions in other processes on database file pFile. If |
| 38230 | +** no error occurs, return SQLITE_OK and set (*piOut) to 1 if there are |
| 38231 | +** such transactions, or 0 otherwise. If an error occurs, return an |
| 38232 | +** SQLite error code. The final value of *piOut is undefined in this |
| 38233 | +** case. |
| 38234 | +*/ |
| 38235 | +static int unixFcntlExternalReader(unixFile *pFile, int *piOut){ |
| 38236 | + int rc = SQLITE_OK; |
| 38237 | + *piOut = 0; |
| 38238 | + if( pFile->pShm){ |
| 38239 | + unixShmNode *pShmNode = pFile->pShm->pShmNode; |
| 38240 | + struct flock f; |
| 38241 | + |
| 38242 | + memset(&f, 0, sizeof(f)); |
| 38243 | + f.l_type = F_WRLCK; |
| 38244 | + f.l_whence = SEEK_SET; |
| 38245 | + f.l_start = UNIX_SHM_BASE + 3; |
| 38246 | + f.l_len = SQLITE_SHM_NLOCK - 3; |
| 38247 | + |
| 38248 | + sqlite3_mutex_enter(pShmNode->pShmMutex); |
| 38249 | + if( osFcntl(pShmNode->hShm, F_GETLK, &f)<0 ){ |
| 38250 | + rc = SQLITE_IOERR_LOCK; |
| 38251 | + }else{ |
| 38252 | + *piOut = (f.l_type!=F_UNLCK); |
| 38253 | + } |
| 38254 | + sqlite3_mutex_leave(pShmNode->pShmMutex); |
| 38255 | + } |
| 38256 | + |
| 38257 | + return rc; |
| 38258 | +} |
| 38259 | + |
| 38175 | 38260 | |
| 38176 | 38261 | /* |
| 38177 | 38262 | ** Apply posix advisory locks for all bytes from ofst through ofst+n-1. |
| 38178 | 38263 | ** |
| 38179 | 38264 | ** Locks block if the mask is exactly UNIX_SHM_C and are non-blocking |
| | @@ -56081,11 +56166,12 @@ |
| 56081 | 56166 | ** Once this function has been called, the transaction must either be |
| 56082 | 56167 | ** rolled back or committed. It is not safe to call this function and |
| 56083 | 56168 | ** then continue writing to the database. |
| 56084 | 56169 | */ |
| 56085 | 56170 | SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){ |
| 56086 | | - assert( pPager->dbSize>=nPage ); |
| 56171 | + assert( pPager->dbSize>=nPage || CORRUPT_DB ); |
| 56172 | + testcase( pPager->dbSize<nPage ); |
| 56087 | 56173 | assert( pPager->eState>=PAGER_WRITER_CACHEMOD ); |
| 56088 | 56174 | pPager->dbSize = nPage; |
| 56089 | 56175 | |
| 56090 | 56176 | /* At one point the code here called assertTruncateConstraint() to |
| 56091 | 56177 | ** ensure that all pages being truncated away by this operation are, |
| | @@ -70348,11 +70434,13 @@ |
| 70348 | 70434 | ** to the last entry in the b-tree. */ |
| 70349 | 70435 | int ii; |
| 70350 | 70436 | for(ii=0; ii<pCur->iPage; ii++){ |
| 70351 | 70437 | assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell ); |
| 70352 | 70438 | } |
| 70353 | | - assert( pCur->ix==pCur->pPage->nCell-1 ); |
| 70439 | + assert( pCur->ix==pCur->pPage->nCell-1 || CORRUPT_DB ); |
| 70440 | + testcase( pCur->ix!=pCur->pPage->nCell-1 ); |
| 70441 | + /* ^-- dbsqlfuzz b92b72e4de80b5140c30ab71372ca719b8feb618 */ |
| 70354 | 70442 | assert( pCur->pPage->leaf ); |
| 70355 | 70443 | #endif |
| 70356 | 70444 | *pRes = 0; |
| 70357 | 70445 | return SQLITE_OK; |
| 70358 | 70446 | } |
| | @@ -71115,11 +71203,11 @@ |
| 71115 | 71203 | closest = 0; |
| 71116 | 71204 | } |
| 71117 | 71205 | |
| 71118 | 71206 | iPage = get4byte(&aData[8+closest*4]); |
| 71119 | 71207 | testcase( iPage==mxPage ); |
| 71120 | | - if( iPage>mxPage ){ |
| 71208 | + if( iPage>mxPage || iPage<2 ){ |
| 71121 | 71209 | rc = SQLITE_CORRUPT_PGNO(iTrunk); |
| 71122 | 71210 | goto end_allocate_page; |
| 71123 | 71211 | } |
| 71124 | 71212 | testcase( iPage==mxPage ); |
| 71125 | 71213 | if( !searchList |
| | @@ -74062,11 +74150,11 @@ |
| 74062 | 74150 | assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 ); |
| 74063 | 74151 | if( pCur->eState==CURSOR_REQUIRESEEK ){ |
| 74064 | 74152 | rc = btreeRestoreCursorPosition(pCur); |
| 74065 | 74153 | if( rc ) return rc; |
| 74066 | 74154 | } |
| 74067 | | - assert( pCur->eState==CURSOR_VALID ); |
| 74155 | + assert( CORRUPT_DB || pCur->eState==CURSOR_VALID ); |
| 74068 | 74156 | |
| 74069 | 74157 | iCellDepth = pCur->iPage; |
| 74070 | 74158 | iCellIdx = pCur->ix; |
| 74071 | 74159 | pPage = pCur->pPage; |
| 74072 | 74160 | pCell = findCell(pPage, iCellIdx); |
| | @@ -79862,15 +79950,11 @@ |
| 79862 | 79950 | if( zOpName[nOpName+1] ){ |
| 79863 | 79951 | int seenCom = 0; |
| 79864 | 79952 | char c; |
| 79865 | 79953 | zSynopsis = zOpName += nOpName + 1; |
| 79866 | 79954 | if( strncmp(zSynopsis,"IF ",3)==0 ){ |
| 79867 | | - if( pOp->p5 & SQLITE_STOREP2 ){ |
| 79868 | | - sqlite3_snprintf(sizeof(zAlt), zAlt, "r[P2] = (%s)", zSynopsis+3); |
| 79869 | | - }else{ |
| 79870 | | - sqlite3_snprintf(sizeof(zAlt), zAlt, "if %s goto P2", zSynopsis+3); |
| 79871 | | - } |
| 79955 | + sqlite3_snprintf(sizeof(zAlt), zAlt, "if %s goto P2", zSynopsis+3); |
| 79872 | 79956 | zSynopsis = zAlt; |
| 79873 | 79957 | } |
| 79874 | 79958 | for(ii=0; (c = zSynopsis[ii])!=0; ii++){ |
| 79875 | 79959 | if( c=='P' ){ |
| 79876 | 79960 | c = zSynopsis[++ii]; |
| | @@ -87438,11 +87522,11 @@ |
| 87438 | 87522 | */ |
| 87439 | 87523 | case OP_ResultRow: { |
| 87440 | 87524 | Mem *pMem; |
| 87441 | 87525 | int i; |
| 87442 | 87526 | assert( p->nResColumn==pOp->p2 ); |
| 87443 | | - assert( pOp->p1>0 ); |
| 87527 | + assert( pOp->p1>0 || CORRUPT_DB ); |
| 87444 | 87528 | assert( pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1 ); |
| 87445 | 87529 | |
| 87446 | 87530 | /* Invalidate all ephemeral cursor row caches */ |
| 87447 | 87531 | p->cacheCtr = (p->cacheCtr + 2)|1; |
| 87448 | 87532 | |
| | @@ -87880,12 +87964,11 @@ |
| 87880 | 87964 | |
| 87881 | 87965 | /* Opcode: Eq P1 P2 P3 P4 P5 |
| 87882 | 87966 | ** Synopsis: IF r[P3]==r[P1] |
| 87883 | 87967 | ** |
| 87884 | 87968 | ** Compare the values in register P1 and P3. If reg(P3)==reg(P1) then |
| 87885 | | -** jump to address P2. Or if the SQLITE_STOREP2 flag is set in P5, then |
| 87886 | | -** store the result of comparison in register P2. |
| 87969 | +** jump to address P2. |
| 87887 | 87970 | ** |
| 87888 | 87971 | ** The SQLITE_AFF_MASK portion of P5 must be an affinity character - |
| 87889 | 87972 | ** SQLITE_AFF_TEXT, SQLITE_AFF_INTEGER, and so forth. An attempt is made |
| 87890 | 87973 | ** to coerce both inputs according to this affinity before the |
| 87891 | 87974 | ** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric |
| | @@ -87907,31 +87990,25 @@ |
| 87907 | 87990 | ** true or false and is never NULL. If both operands are NULL then the result |
| 87908 | 87991 | ** of comparison is true. If either operand is NULL then the result is false. |
| 87909 | 87992 | ** If neither operand is NULL the result is the same as it would be if |
| 87910 | 87993 | ** the SQLITE_NULLEQ flag were omitted from P5. |
| 87911 | 87994 | ** |
| 87912 | | -** If both SQLITE_STOREP2 and SQLITE_KEEPNULL flags are set then the |
| 87913 | | -** content of r[P2] is only changed if the new value is NULL or 0 (false). |
| 87914 | | -** In other words, a prior r[P2] value will not be overwritten by 1 (true). |
| 87995 | +** This opcode saves the result of comparison for use by the new |
| 87996 | +** OP_Jump opcode. |
| 87915 | 87997 | */ |
| 87916 | 87998 | /* Opcode: Ne P1 P2 P3 P4 P5 |
| 87917 | 87999 | ** Synopsis: IF r[P3]!=r[P1] |
| 87918 | 88000 | ** |
| 87919 | 88001 | ** This works just like the Eq opcode except that the jump is taken if |
| 87920 | 88002 | ** the operands in registers P1 and P3 are not equal. See the Eq opcode for |
| 87921 | 88003 | ** additional information. |
| 87922 | | -** |
| 87923 | | -** If both SQLITE_STOREP2 and SQLITE_KEEPNULL flags are set then the |
| 87924 | | -** content of r[P2] is only changed if the new value is NULL or 1 (true). |
| 87925 | | -** In other words, a prior r[P2] value will not be overwritten by 0 (false). |
| 87926 | 88004 | */ |
| 87927 | 88005 | /* Opcode: Lt P1 P2 P3 P4 P5 |
| 87928 | 88006 | ** Synopsis: IF r[P3]<r[P1] |
| 87929 | 88007 | ** |
| 87930 | 88008 | ** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then |
| 87931 | | -** jump to address P2. Or if the SQLITE_STOREP2 flag is set in P5 store |
| 87932 | | -** the result of comparison (0 or 1 or NULL) into register P2. |
| 88009 | +** jump to address P2. |
| 87933 | 88010 | ** |
| 87934 | 88011 | ** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or |
| 87935 | 88012 | ** reg(P3) is NULL then the take the jump. If the SQLITE_JUMPIFNULL |
| 87936 | 88013 | ** bit is clear then fall through if either operand is NULL. |
| 87937 | 88014 | ** |
| | @@ -87950,10 +88027,13 @@ |
| 87950 | 88027 | ** P4 is used to do the comparison. If P4 is not specified then |
| 87951 | 88028 | ** memcmp() is used to compare text string. If both values are |
| 87952 | 88029 | ** numeric, then a numeric comparison is used. If the two values |
| 87953 | 88030 | ** are of different types, then numbers are considered less than |
| 87954 | 88031 | ** strings and strings are considered less than blobs. |
| 88032 | +** |
| 88033 | +** This opcode saves the result of comparison for use by the new |
| 88034 | +** OP_Jump opcode. |
| 87955 | 88035 | */ |
| 87956 | 88036 | /* Opcode: Le P1 P2 P3 P4 P5 |
| 87957 | 88037 | ** Synopsis: IF r[P3]<=r[P1] |
| 87958 | 88038 | ** |
| 87959 | 88039 | ** This works just like the Lt opcode except that the jump is taken if |
| | @@ -88009,21 +88089,14 @@ |
| 88009 | 88089 | }else{ |
| 88010 | 88090 | /* SQLITE_NULLEQ is clear and at least one operand is NULL, |
| 88011 | 88091 | ** then the result is always NULL. |
| 88012 | 88092 | ** The jump is taken if the SQLITE_JUMPIFNULL bit is set. |
| 88013 | 88093 | */ |
| 88014 | | - if( pOp->p5 & SQLITE_STOREP2 ){ |
| 88015 | | - pOut = &aMem[pOp->p2]; |
| 88016 | | - iCompare = 1; /* Operands are not equal */ |
| 88017 | | - memAboutToChange(p, pOut); |
| 88018 | | - MemSetTypeFlag(pOut, MEM_Null); |
| 88019 | | - REGISTER_TRACE(pOp->p2, pOut); |
| 88020 | | - }else{ |
| 88021 | | - VdbeBranchTaken(2,3); |
| 88022 | | - if( pOp->p5 & SQLITE_JUMPIFNULL ){ |
| 88023 | | - goto jump_to_p2; |
| 88024 | | - } |
| 88094 | + iCompare = 1; /* Operands are not equal */ |
| 88095 | + VdbeBranchTaken(2,3); |
| 88096 | + if( pOp->p5 & SQLITE_JUMPIFNULL ){ |
| 88097 | + goto jump_to_p2; |
| 88025 | 88098 | } |
| 88026 | 88099 | break; |
| 88027 | 88100 | } |
| 88028 | 88101 | }else{ |
| 88029 | 88102 | /* Neither operand is NULL. Do a comparison. */ |
| | @@ -88076,88 +88149,58 @@ |
| 88076 | 88149 | ** operator actually is. The next block of code depends on the fact |
| 88077 | 88150 | ** that the 6 comparison operators are consecutive integers in this |
| 88078 | 88151 | ** order: NE, EQ, GT, LE, LT, GE */ |
| 88079 | 88152 | assert( OP_Eq==OP_Ne+1 ); assert( OP_Gt==OP_Ne+2 ); assert( OP_Le==OP_Ne+3 ); |
| 88080 | 88153 | assert( OP_Lt==OP_Ne+4 ); assert( OP_Ge==OP_Ne+5 ); |
| 88081 | | - if( res<0 ){ /* ne, eq, gt, le, lt, ge */ |
| 88082 | | - static const unsigned char aLTb[] = { 1, 0, 0, 1, 1, 0 }; |
| 88083 | | - res2 = aLTb[pOp->opcode - OP_Ne]; |
| 88154 | + if( res<0 ){ |
| 88155 | + res2 = sqlite3aLTb[pOp->opcode]; |
| 88084 | 88156 | }else if( res==0 ){ |
| 88085 | | - static const unsigned char aEQb[] = { 0, 1, 0, 1, 0, 1 }; |
| 88086 | | - res2 = aEQb[pOp->opcode - OP_Ne]; |
| 88157 | + res2 = sqlite3aEQb[pOp->opcode]; |
| 88087 | 88158 | }else{ |
| 88088 | | - static const unsigned char aGTb[] = { 1, 0, 1, 0, 0, 1 }; |
| 88089 | | - res2 = aGTb[pOp->opcode - OP_Ne]; |
| 88159 | + res2 = sqlite3aGTb[pOp->opcode]; |
| 88090 | 88160 | } |
| 88161 | + iCompare = res; |
| 88091 | 88162 | |
| 88092 | 88163 | /* Undo any changes made by applyAffinity() to the input registers. */ |
| 88093 | 88164 | assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) ); |
| 88094 | 88165 | pIn3->flags = flags3; |
| 88095 | 88166 | assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) ); |
| 88096 | 88167 | pIn1->flags = flags1; |
| 88097 | 88168 | |
| 88098 | | - if( pOp->p5 & SQLITE_STOREP2 ){ |
| 88099 | | - pOut = &aMem[pOp->p2]; |
| 88100 | | - iCompare = res; |
| 88101 | | - if( (pOp->p5 & SQLITE_KEEPNULL)!=0 ){ |
| 88102 | | - /* The KEEPNULL flag prevents OP_Eq from overwriting a NULL with 1 |
| 88103 | | - ** and prevents OP_Ne from overwriting NULL with 0. This flag |
| 88104 | | - ** is only used in contexts where either: |
| 88105 | | - ** (1) op==OP_Eq && (r[P2]==NULL || r[P2]==0) |
| 88106 | | - ** (2) op==OP_Ne && (r[P2]==NULL || r[P2]==1) |
| 88107 | | - ** Therefore it is not necessary to check the content of r[P2] for |
| 88108 | | - ** NULL. */ |
| 88109 | | - assert( pOp->opcode==OP_Ne || pOp->opcode==OP_Eq ); |
| 88110 | | - assert( res2==0 || res2==1 ); |
| 88111 | | - testcase( res2==0 && pOp->opcode==OP_Eq ); |
| 88112 | | - testcase( res2==1 && pOp->opcode==OP_Eq ); |
| 88113 | | - testcase( res2==0 && pOp->opcode==OP_Ne ); |
| 88114 | | - testcase( res2==1 && pOp->opcode==OP_Ne ); |
| 88115 | | - if( (pOp->opcode==OP_Eq)==res2 ) break; |
| 88116 | | - } |
| 88117 | | - memAboutToChange(p, pOut); |
| 88118 | | - MemSetTypeFlag(pOut, MEM_Int); |
| 88119 | | - pOut->u.i = res2; |
| 88120 | | - REGISTER_TRACE(pOp->p2, pOut); |
| 88121 | | - }else{ |
| 88122 | | - VdbeBranchTaken(res2!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3); |
| 88123 | | - if( res2 ){ |
| 88124 | | - goto jump_to_p2; |
| 88125 | | - } |
| 88169 | + VdbeBranchTaken(res2!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3); |
| 88170 | + if( res2 ){ |
| 88171 | + goto jump_to_p2; |
| 88126 | 88172 | } |
| 88127 | 88173 | break; |
| 88128 | 88174 | } |
| 88129 | 88175 | |
| 88130 | | -/* Opcode: ElseNotEq * P2 * * * |
| 88176 | +/* Opcode: ElseEq * P2 * * * |
| 88131 | 88177 | ** |
| 88132 | 88178 | ** This opcode must follow an OP_Lt or OP_Gt comparison operator. There |
| 88133 | 88179 | ** can be zero or more OP_ReleaseReg opcodes intervening, but no other |
| 88134 | 88180 | ** opcodes are allowed to occur between this instruction and the previous |
| 88135 | | -** OP_Lt or OP_Gt. Furthermore, the prior OP_Lt or OP_Gt must have the |
| 88136 | | -** SQLITE_STOREP2 bit set in the P5 field. |
| 88181 | +** OP_Lt or OP_Gt. |
| 88137 | 88182 | ** |
| 88138 | 88183 | ** If result of an OP_Eq comparison on the same two operands as the |
| 88139 | | -** prior OP_Lt or OP_Gt would have been NULL or false (0), then then |
| 88140 | | -** jump to P2. If the result of an OP_Eq comparison on the two previous |
| 88141 | | -** operands would have been true (1), then fall through. |
| 88184 | +** prior OP_Lt or OP_Gt would have been true, then jump to P2. |
| 88185 | +** If the result of an OP_Eq comparison on the two previous |
| 88186 | +** operands would have been false or NULL, then fall through. |
| 88142 | 88187 | */ |
| 88143 | | -case OP_ElseNotEq: { /* same as TK_ESCAPE, jump */ |
| 88188 | +case OP_ElseEq: { /* same as TK_ESCAPE, jump */ |
| 88144 | 88189 | |
| 88145 | 88190 | #ifdef SQLITE_DEBUG |
| 88146 | 88191 | /* Verify the preconditions of this opcode - that it follows an OP_Lt or |
| 88147 | | - ** OP_Gt with the SQLITE_STOREP2 flag set, with zero or more intervening |
| 88148 | | - ** OP_ReleaseReg opcodes */ |
| 88192 | + ** OP_Gt with zero or more intervening OP_ReleaseReg opcodes */ |
| 88149 | 88193 | int iAddr; |
| 88150 | 88194 | for(iAddr = (int)(pOp - aOp) - 1; ALWAYS(iAddr>=0); iAddr--){ |
| 88151 | 88195 | if( aOp[iAddr].opcode==OP_ReleaseReg ) continue; |
| 88152 | 88196 | assert( aOp[iAddr].opcode==OP_Lt || aOp[iAddr].opcode==OP_Gt ); |
| 88153 | | - assert( aOp[iAddr].p5 & SQLITE_STOREP2 ); |
| 88154 | 88197 | break; |
| 88155 | 88198 | } |
| 88156 | 88199 | #endif /* SQLITE_DEBUG */ |
| 88157 | | - VdbeBranchTaken(iCompare!=0, 2); |
| 88158 | | - if( iCompare!=0 ) goto jump_to_p2; |
| 88200 | + VdbeBranchTaken(iCompare==0, 2); |
| 88201 | + if( iCompare==0 ) goto jump_to_p2; |
| 88159 | 88202 | break; |
| 88160 | 88203 | } |
| 88161 | 88204 | |
| 88162 | 88205 | |
| 88163 | 88206 | /* Opcode: Permutation * * * P4 * |
| | @@ -88463,10 +88506,28 @@ |
| 88463 | 88506 | if( (pIn1->flags & MEM_Null)!=0 ){ |
| 88464 | 88507 | goto jump_to_p2; |
| 88465 | 88508 | } |
| 88466 | 88509 | break; |
| 88467 | 88510 | } |
| 88511 | + |
| 88512 | +/* Opcode: ZeroOrNull P1 P2 P3 * * |
| 88513 | +** Synopsis: r[P2] = 0 OR NULL |
| 88514 | +** |
| 88515 | +** If all both registers P1 and P3 are NOT NULL, then store a zero in |
| 88516 | +** register P2. If either registers P1 or P3 are NULL then put |
| 88517 | +** a NULL in register P2. |
| 88518 | +*/ |
| 88519 | +case OP_ZeroOrNull: { /* in1, in2, out2, in3 */ |
| 88520 | + if( (aMem[pOp->p1].flags & MEM_Null)!=0 |
| 88521 | + || (aMem[pOp->p3].flags & MEM_Null)!=0 |
| 88522 | + ){ |
| 88523 | + sqlite3VdbeMemSetNull(aMem + pOp->p2); |
| 88524 | + }else{ |
| 88525 | + sqlite3VdbeMemSetInt64(aMem + pOp->p2, 0); |
| 88526 | + } |
| 88527 | + break; |
| 88528 | +} |
| 88468 | 88529 | |
| 88469 | 88530 | /* Opcode: NotNull P1 P2 * * * |
| 88470 | 88531 | ** Synopsis: if r[P1]!=NULL goto P2 |
| 88471 | 88532 | ** |
| 88472 | 88533 | ** Jump to P2 if the value in register P1 is not NULL. |
| | @@ -99001,12 +99062,14 @@ |
| 99001 | 99062 | pTab = 0; |
| 99002 | 99063 | #ifndef SQLITE_OMIT_TRIGGER |
| 99003 | 99064 | if( pParse->pTriggerTab!=0 ){ |
| 99004 | 99065 | int op = pParse->eTriggerOp; |
| 99005 | 99066 | assert( op==TK_DELETE || op==TK_UPDATE || op==TK_INSERT ); |
| 99006 | | - if( pParse->bReturning && (pNC->ncFlags & NC_UBaseReg)!=0 ){ |
| 99007 | | - if( zTab==0 || sqlite3StrICmp(zTab,pParse->pTriggerTab->zName)==0 ){ |
| 99067 | + if( pParse->bReturning ){ |
| 99068 | + if( (pNC->ncFlags & NC_UBaseReg)!=0 |
| 99069 | + && (zTab==0 || sqlite3StrICmp(zTab,pParse->pTriggerTab->zName)==0) |
| 99070 | + ){ |
| 99008 | 99071 | pExpr->iTable = op!=TK_DELETE; |
| 99009 | 99072 | pTab = pParse->pTriggerTab; |
| 99010 | 99073 | } |
| 99011 | 99074 | }else if( op!=TK_DELETE && zTab && sqlite3StrICmp("new",zTab) == 0 ){ |
| 99012 | 99075 | pExpr->iTable = 1; |
| | @@ -99186,11 +99249,10 @@ |
| 99186 | 99249 | */ |
| 99187 | 99250 | if( cnt==0 && zTab==0 ){ |
| 99188 | 99251 | assert( pExpr->op==TK_ID ); |
| 99189 | 99252 | if( ExprHasProperty(pExpr,EP_DblQuoted) |
| 99190 | 99253 | && areDoubleQuotedStringsEnabled(db, pTopNC) |
| 99191 | | - && (db->init.bDropColumn==0 || sqlite3StrICmp(zCol, db->init.azInit[0])!=0) |
| 99192 | 99254 | ){ |
| 99193 | 99255 | /* If a double-quoted identifier does not match any known column name, |
| 99194 | 99256 | ** then treat it as a string. |
| 99195 | 99257 | ** |
| 99196 | 99258 | ** This hack was added in the early days of SQLite in a misguided attempt |
| | @@ -99201,15 +99263,10 @@ |
| 99201 | 99263 | ** programmers. To all those frustrated programmers, my apologies. |
| 99202 | 99264 | ** |
| 99203 | 99265 | ** Someday, I hope to get rid of this hack. Unfortunately there is |
| 99204 | 99266 | ** a huge amount of legacy SQL that uses it. So for now, we just |
| 99205 | 99267 | ** issue a warning. |
| 99206 | | - ** |
| 99207 | | - ** 2021-03-15: ticket 1c24a659e6d7f3a1 |
| 99208 | | - ** Do not do the ID-to-STRING conversion when doing the schema |
| 99209 | | - ** sanity check following a DROP COLUMN if the identifer name matches |
| 99210 | | - ** the name of the column being dropped. |
| 99211 | 99268 | */ |
| 99212 | 99269 | sqlite3_log(SQLITE_WARNING, |
| 99213 | 99270 | "double-quoted string literal: \"%w\"", zCol); |
| 99214 | 99271 | #ifdef SQLITE_ENABLE_NORMALIZE |
| 99215 | 99272 | sqlite3VdbeAddDblquoteStr(db, pParse->pVdbe, zCol); |
| | @@ -101259,10 +101316,11 @@ |
| 101259 | 101316 | int nLeft = sqlite3ExprVectorSize(pLeft); |
| 101260 | 101317 | int i; |
| 101261 | 101318 | int regLeft = 0; |
| 101262 | 101319 | int regRight = 0; |
| 101263 | 101320 | u8 opx = op; |
| 101321 | + int addrCmp = 0; |
| 101264 | 101322 | int addrDone = sqlite3VdbeMakeLabel(pParse); |
| 101265 | 101323 | int isCommuted = ExprHasProperty(pExpr,EP_Commuted); |
| 101266 | 101324 | |
| 101267 | 101325 | assert( !ExprHasVVAProperty(pExpr,EP_Immutable) ); |
| 101268 | 101326 | if( pParse->nErr ) return; |
| | @@ -101278,53 +101336,62 @@ |
| 101278 | 101336 | assert( pExpr->op==op || (pExpr->op==TK_IS && op==TK_EQ) |
| 101279 | 101337 | || (pExpr->op==TK_ISNOT && op==TK_NE) ); |
| 101280 | 101338 | assert( p5==0 || pExpr->op!=op ); |
| 101281 | 101339 | assert( p5==SQLITE_NULLEQ || pExpr->op==op ); |
| 101282 | 101340 | |
| 101283 | | - p5 |= SQLITE_STOREP2; |
| 101284 | | - if( opx==TK_LE ) opx = TK_LT; |
| 101285 | | - if( opx==TK_GE ) opx = TK_GT; |
| 101341 | + if( op==TK_LE ) opx = TK_LT; |
| 101342 | + if( op==TK_GE ) opx = TK_GT; |
| 101343 | + if( op==TK_NE ) opx = TK_EQ; |
| 101286 | 101344 | |
| 101287 | 101345 | regLeft = exprCodeSubselect(pParse, pLeft); |
| 101288 | 101346 | regRight = exprCodeSubselect(pParse, pRight); |
| 101289 | 101347 | |
| 101348 | + sqlite3VdbeAddOp2(v, OP_Integer, 1, dest); |
| 101290 | 101349 | for(i=0; 1 /*Loop exits by "break"*/; i++){ |
| 101291 | 101350 | int regFree1 = 0, regFree2 = 0; |
| 101292 | 101351 | Expr *pL, *pR; |
| 101293 | 101352 | int r1, r2; |
| 101294 | 101353 | assert( i>=0 && i<nLeft ); |
| 101354 | + if( addrCmp ) sqlite3VdbeJumpHere(v, addrCmp); |
| 101295 | 101355 | r1 = exprVectorRegister(pParse, pLeft, i, regLeft, &pL, ®Free1); |
| 101296 | 101356 | r2 = exprVectorRegister(pParse, pRight, i, regRight, &pR, ®Free2); |
| 101297 | | - codeCompare(pParse, pL, pR, opx, r1, r2, dest, p5, isCommuted); |
| 101357 | + addrCmp = sqlite3VdbeCurrentAddr(v); |
| 101358 | + codeCompare(pParse, pL, pR, opx, r1, r2, addrDone, p5, isCommuted); |
| 101298 | 101359 | testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt); |
| 101299 | 101360 | testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le); |
| 101300 | 101361 | testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt); |
| 101301 | 101362 | testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge); |
| 101302 | 101363 | testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq); |
| 101303 | 101364 | testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne); |
| 101304 | 101365 | sqlite3ReleaseTempReg(pParse, regFree1); |
| 101305 | 101366 | sqlite3ReleaseTempReg(pParse, regFree2); |
| 101367 | + if( (opx==TK_LT || opx==TK_GT) && i<nLeft-1 ){ |
| 101368 | + addrCmp = sqlite3VdbeAddOp0(v, OP_ElseEq); |
| 101369 | + testcase(opx==TK_LT); VdbeCoverageIf(v,opx==TK_LT); |
| 101370 | + testcase(opx==TK_GT); VdbeCoverageIf(v,opx==TK_GT); |
| 101371 | + } |
| 101372 | + if( p5==SQLITE_NULLEQ ){ |
| 101373 | + sqlite3VdbeAddOp2(v, OP_Integer, 0, dest); |
| 101374 | + }else{ |
| 101375 | + sqlite3VdbeAddOp3(v, OP_ZeroOrNull, r1, dest, r2); |
| 101376 | + } |
| 101306 | 101377 | if( i==nLeft-1 ){ |
| 101307 | 101378 | break; |
| 101308 | 101379 | } |
| 101309 | 101380 | if( opx==TK_EQ ){ |
| 101310 | | - sqlite3VdbeAddOp2(v, OP_IfNot, dest, addrDone); VdbeCoverage(v); |
| 101311 | | - p5 |= SQLITE_KEEPNULL; |
| 101312 | | - }else if( opx==TK_NE ){ |
| 101313 | | - sqlite3VdbeAddOp2(v, OP_If, dest, addrDone); VdbeCoverage(v); |
| 101314 | | - p5 |= SQLITE_KEEPNULL; |
| 101381 | + sqlite3VdbeAddOp2(v, OP_NotNull, dest, addrDone); VdbeCoverage(v); |
| 101315 | 101382 | }else{ |
| 101316 | 101383 | assert( op==TK_LT || op==TK_GT || op==TK_LE || op==TK_GE ); |
| 101317 | | - sqlite3VdbeAddOp2(v, OP_ElseNotEq, 0, addrDone); |
| 101318 | | - VdbeCoverageIf(v, op==TK_LT); |
| 101319 | | - VdbeCoverageIf(v, op==TK_GT); |
| 101320 | | - VdbeCoverageIf(v, op==TK_LE); |
| 101321 | | - VdbeCoverageIf(v, op==TK_GE); |
| 101384 | + sqlite3VdbeAddOp2(v, OP_Goto, 0, addrDone); |
| 101322 | 101385 | if( i==nLeft-2 ) opx = op; |
| 101323 | 101386 | } |
| 101324 | 101387 | } |
| 101388 | + sqlite3VdbeJumpHere(v, addrCmp); |
| 101325 | 101389 | sqlite3VdbeResolveLabel(v, addrDone); |
| 101390 | + if( op==TK_NE ){ |
| 101391 | + sqlite3VdbeAddOp2(v, OP_Not, dest, dest); |
| 101392 | + } |
| 101326 | 101393 | } |
| 101327 | 101394 | |
| 101328 | 101395 | #if SQLITE_MAX_EXPR_DEPTH>0 |
| 101329 | 101396 | /* |
| 101330 | 101397 | ** Check that argument nHeight is less than or equal to the maximum |
| | @@ -102142,10 +102209,11 @@ |
| 102142 | 102209 | assert( db!=0 ); |
| 102143 | 102210 | if( p==0 ) return 0; |
| 102144 | 102211 | pNew = sqlite3DbMallocRawNN(db, sqlite3DbMallocSize(db, p)); |
| 102145 | 102212 | if( pNew==0 ) return 0; |
| 102146 | 102213 | pNew->nExpr = p->nExpr; |
| 102214 | + pNew->nAlloc = p->nAlloc; |
| 102147 | 102215 | pItem = pNew->a; |
| 102148 | 102216 | pOldItem = p->a; |
| 102149 | 102217 | for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){ |
| 102150 | 102218 | Expr *pOldExpr = pOldItem->pExpr; |
| 102151 | 102219 | Expr *pNewExpr; |
| | @@ -102314,45 +102382,68 @@ |
| 102314 | 102382 | ** |
| 102315 | 102383 | ** If a memory allocation error occurs, the entire list is freed and |
| 102316 | 102384 | ** NULL is returned. If non-NULL is returned, then it is guaranteed |
| 102317 | 102385 | ** that the new entry was successfully appended. |
| 102318 | 102386 | */ |
| 102387 | +static const struct ExprList_item zeroItem = {0}; |
| 102388 | +SQLITE_PRIVATE SQLITE_NOINLINE ExprList *sqlite3ExprListAppendNew( |
| 102389 | + sqlite3 *db, /* Database handle. Used for memory allocation */ |
| 102390 | + Expr *pExpr /* Expression to be appended. Might be NULL */ |
| 102391 | +){ |
| 102392 | + struct ExprList_item *pItem; |
| 102393 | + ExprList *pList; |
| 102394 | + |
| 102395 | + pList = sqlite3DbMallocRawNN(db, sizeof(ExprList)+sizeof(pList->a[0])*4 ); |
| 102396 | + if( pList==0 ){ |
| 102397 | + sqlite3ExprDelete(db, pExpr); |
| 102398 | + return 0; |
| 102399 | + } |
| 102400 | + pList->nAlloc = 4; |
| 102401 | + pList->nExpr = 1; |
| 102402 | + pItem = &pList->a[0]; |
| 102403 | + *pItem = zeroItem; |
| 102404 | + pItem->pExpr = pExpr; |
| 102405 | + return pList; |
| 102406 | +} |
| 102407 | +SQLITE_PRIVATE SQLITE_NOINLINE ExprList *sqlite3ExprListAppendGrow( |
| 102408 | + sqlite3 *db, /* Database handle. Used for memory allocation */ |
| 102409 | + ExprList *pList, /* List to which to append. Might be NULL */ |
| 102410 | + Expr *pExpr /* Expression to be appended. Might be NULL */ |
| 102411 | +){ |
| 102412 | + struct ExprList_item *pItem; |
| 102413 | + ExprList *pNew; |
| 102414 | + pList->nAlloc *= 2; |
| 102415 | + pNew = sqlite3DbRealloc(db, pList, |
| 102416 | + sizeof(*pList)+(pList->nAlloc-1)*sizeof(pList->a[0])); |
| 102417 | + if( pNew==0 ){ |
| 102418 | + sqlite3ExprListDelete(db, pList); |
| 102419 | + sqlite3ExprDelete(db, pExpr); |
| 102420 | + return 0; |
| 102421 | + }else{ |
| 102422 | + pList = pNew; |
| 102423 | + } |
| 102424 | + pItem = &pList->a[pList->nExpr++]; |
| 102425 | + *pItem = zeroItem; |
| 102426 | + pItem->pExpr = pExpr; |
| 102427 | + return pList; |
| 102428 | +} |
| 102319 | 102429 | SQLITE_PRIVATE ExprList *sqlite3ExprListAppend( |
| 102320 | 102430 | Parse *pParse, /* Parsing context */ |
| 102321 | 102431 | ExprList *pList, /* List to which to append. Might be NULL */ |
| 102322 | 102432 | Expr *pExpr /* Expression to be appended. Might be NULL */ |
| 102323 | 102433 | ){ |
| 102324 | 102434 | struct ExprList_item *pItem; |
| 102325 | | - sqlite3 *db = pParse->db; |
| 102326 | | - assert( db!=0 ); |
| 102327 | | - if( pList==0 ){ |
| 102328 | | - pList = sqlite3DbMallocRawNN(db, sizeof(ExprList) ); |
| 102329 | | - if( pList==0 ){ |
| 102330 | | - goto no_mem; |
| 102331 | | - } |
| 102332 | | - pList->nExpr = 0; |
| 102333 | | - }else if( (pList->nExpr & (pList->nExpr-1))==0 ){ |
| 102334 | | - ExprList *pNew; |
| 102335 | | - pNew = sqlite3DbRealloc(db, pList, |
| 102336 | | - sizeof(*pList)+(2*(sqlite3_int64)pList->nExpr-1)*sizeof(pList->a[0])); |
| 102337 | | - if( pNew==0 ){ |
| 102338 | | - goto no_mem; |
| 102339 | | - } |
| 102340 | | - pList = pNew; |
| 102435 | + if( pList==0 ){ |
| 102436 | + return sqlite3ExprListAppendNew(pParse->db,pExpr); |
| 102437 | + } |
| 102438 | + if( pList->nAlloc<pList->nExpr+1 ){ |
| 102439 | + return sqlite3ExprListAppendGrow(pParse->db,pList,pExpr); |
| 102341 | 102440 | } |
| 102342 | 102441 | pItem = &pList->a[pList->nExpr++]; |
| 102343 | | - assert( offsetof(struct ExprList_item,zEName)==sizeof(pItem->pExpr) ); |
| 102344 | | - assert( offsetof(struct ExprList_item,pExpr)==0 ); |
| 102345 | | - memset(&pItem->zEName,0,sizeof(*pItem)-offsetof(struct ExprList_item,zEName)); |
| 102442 | + *pItem = zeroItem; |
| 102346 | 102443 | pItem->pExpr = pExpr; |
| 102347 | 102444 | return pList; |
| 102348 | | - |
| 102349 | | -no_mem: |
| 102350 | | - /* Avoid leaking memory if malloc has failed. */ |
| 102351 | | - sqlite3ExprDelete(db, pExpr); |
| 102352 | | - sqlite3ExprListDelete(db, pList); |
| 102353 | | - return 0; |
| 102354 | 102445 | } |
| 102355 | 102446 | |
| 102356 | 102447 | /* |
| 102357 | 102448 | ** pColumns and pExpr form a vector assignment which is part of the SET |
| 102358 | 102449 | ** clause of an UPDATE statement. Like this: |
| | @@ -104003,10 +104094,11 @@ |
| 104003 | 104094 | destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse); |
| 104004 | 104095 | } |
| 104005 | 104096 | if( pParse->nErr ) goto sqlite3ExprCodeIN_finished; |
| 104006 | 104097 | for(i=0; i<nVector; i++){ |
| 104007 | 104098 | Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i); |
| 104099 | + if( pParse->db->mallocFailed ) goto sqlite3ExprCodeIN_oom_error; |
| 104008 | 104100 | if( sqlite3ExprCanBeNull(p) ){ |
| 104009 | 104101 | sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2); |
| 104010 | 104102 | VdbeCoverage(v); |
| 104011 | 104103 | } |
| 104012 | 104104 | } |
| | @@ -104694,19 +104786,25 @@ |
| 104694 | 104786 | if( sqlite3ExprIsVector(pLeft) ){ |
| 104695 | 104787 | codeVectorCompare(pParse, pExpr, target, op, p5); |
| 104696 | 104788 | }else{ |
| 104697 | 104789 | r1 = sqlite3ExprCodeTemp(pParse, pLeft, ®Free1); |
| 104698 | 104790 | r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, ®Free2); |
| 104699 | | - codeCompare(pParse, pLeft, pExpr->pRight, op, |
| 104700 | | - r1, r2, inReg, SQLITE_STOREP2 | p5, |
| 104791 | + sqlite3VdbeAddOp2(v, OP_Integer, 1, inReg); |
| 104792 | + codeCompare(pParse, pLeft, pExpr->pRight, op, r1, r2, |
| 104793 | + sqlite3VdbeCurrentAddr(v)+2, p5, |
| 104701 | 104794 | ExprHasProperty(pExpr,EP_Commuted)); |
| 104702 | 104795 | assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt); |
| 104703 | 104796 | assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le); |
| 104704 | 104797 | assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt); |
| 104705 | 104798 | assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge); |
| 104706 | 104799 | assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq); |
| 104707 | 104800 | assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne); |
| 104801 | + if( p5==SQLITE_NULLEQ ){ |
| 104802 | + sqlite3VdbeAddOp2(v, OP_Integer, 0, inReg); |
| 104803 | + }else{ |
| 104804 | + sqlite3VdbeAddOp3(v, OP_ZeroOrNull, r1, inReg, r2); |
| 104805 | + } |
| 104708 | 104806 | testcase( regFree1==0 ); |
| 104709 | 104807 | testcase( regFree2==0 ); |
| 104710 | 104808 | } |
| 104711 | 104809 | break; |
| 104712 | 104810 | } |
| | @@ -106820,31 +106918,55 @@ |
| 106820 | 106918 | static void renameTestSchema( |
| 106821 | 106919 | Parse *pParse, /* Parse context */ |
| 106822 | 106920 | const char *zDb, /* Name of db to verify schema of */ |
| 106823 | 106921 | int bTemp, /* True if this is the temp db */ |
| 106824 | 106922 | const char *zWhen, /* "when" part of error message */ |
| 106825 | | - const char *zDropColumn /* Name of column being dropped */ |
| 106923 | + int bNoDQS /* Do not allow DQS in the schema */ |
| 106826 | 106924 | ){ |
| 106827 | 106925 | pParse->colNamesSet = 1; |
| 106828 | 106926 | sqlite3NestedParse(pParse, |
| 106829 | 106927 | "SELECT 1 " |
| 106830 | 106928 | "FROM \"%w\"." DFLT_SCHEMA_TABLE " " |
| 106831 | 106929 | "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'" |
| 106832 | 106930 | " AND sql NOT LIKE 'create virtual%%'" |
| 106833 | | - " AND sqlite_rename_test(%Q, sql, type, name, %d, %Q, %Q)=NULL ", |
| 106931 | + " AND sqlite_rename_test(%Q, sql, type, name, %d, %Q, %d)=NULL ", |
| 106834 | 106932 | zDb, |
| 106835 | | - zDb, bTemp, zWhen, zDropColumn |
| 106933 | + zDb, bTemp, zWhen, bNoDQS |
| 106836 | 106934 | ); |
| 106837 | 106935 | |
| 106838 | 106936 | if( bTemp==0 ){ |
| 106839 | 106937 | sqlite3NestedParse(pParse, |
| 106840 | 106938 | "SELECT 1 " |
| 106841 | 106939 | "FROM temp." DFLT_SCHEMA_TABLE " " |
| 106842 | 106940 | "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'" |
| 106843 | 106941 | " AND sql NOT LIKE 'create virtual%%'" |
| 106844 | | - " AND sqlite_rename_test(%Q, sql, type, name, 1, %Q, %Q)=NULL ", |
| 106845 | | - zDb, zWhen, zDropColumn |
| 106942 | + " AND sqlite_rename_test(%Q, sql, type, name, 1, %Q, %d)=NULL ", |
| 106943 | + zDb, zWhen, bNoDQS |
| 106944 | + ); |
| 106945 | + } |
| 106946 | +} |
| 106947 | + |
| 106948 | +/* |
| 106949 | +** Generate VM code to replace any double-quoted strings (but not double-quoted |
| 106950 | +** identifiers) within the "sql" column of the sqlite_schema table in |
| 106951 | +** database zDb with their single-quoted equivalents. If argument bTemp is |
| 106952 | +** not true, similarly update all SQL statements in the sqlite_schema table |
| 106953 | +** of the temp db. |
| 106954 | +*/ |
| 106955 | +static void renameFixQuotes(Parse *pParse, const char *zDb, int bTemp){ |
| 106956 | + sqlite3NestedParse(pParse, |
| 106957 | + "UPDATE \"%w\"." DFLT_SCHEMA_TABLE |
| 106958 | + " SET sql = sqlite_rename_quotefix(%Q, sql)" |
| 106959 | + "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'" |
| 106960 | + " AND sql NOT LIKE 'create virtual%%'" , zDb, zDb |
| 106961 | + ); |
| 106962 | + if( bTemp==0 ){ |
| 106963 | + sqlite3NestedParse(pParse, |
| 106964 | + "UPDATE temp." DFLT_SCHEMA_TABLE |
| 106965 | + " SET sql = sqlite_rename_quotefix('temp', sql)" |
| 106966 | + "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'" |
| 106967 | + " AND sql NOT LIKE 'create virtual%%'" |
| 106846 | 106968 | ); |
| 106847 | 106969 | } |
| 106848 | 106970 | } |
| 106849 | 106971 | |
| 106850 | 106972 | /* |
| | @@ -107003,11 +107125,11 @@ |
| 107003 | 107125 | sqlite3NestedParse(pParse, |
| 107004 | 107126 | "UPDATE sqlite_temp_schema SET " |
| 107005 | 107127 | "sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, 1), " |
| 107006 | 107128 | "tbl_name = " |
| 107007 | 107129 | "CASE WHEN tbl_name=%Q COLLATE nocase AND " |
| 107008 | | - " sqlite_rename_test(%Q, sql, type, name, 1, 'after rename',0) " |
| 107130 | + " sqlite_rename_test(%Q, sql, type, name, 1, 'after rename', 0) " |
| 107009 | 107131 | "THEN %Q ELSE tbl_name END " |
| 107010 | 107132 | "WHERE type IN ('view', 'trigger')" |
| 107011 | 107133 | , zDb, zTabName, zName, zTabName, zDb, zName); |
| 107012 | 107134 | } |
| 107013 | 107135 | |
| | @@ -107361,10 +107483,14 @@ |
| 107361 | 107483 | } |
| 107362 | 107484 | if( iCol==pTab->nCol ){ |
| 107363 | 107485 | sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zOld); |
| 107364 | 107486 | goto exit_rename_column; |
| 107365 | 107487 | } |
| 107488 | + |
| 107489 | + /* Ensure the schema contains no double-quoted strings */ |
| 107490 | + renameTestSchema(pParse, zDb, iSchema==1, "", 0); |
| 107491 | + renameFixQuotes(pParse, zDb, iSchema==1); |
| 107366 | 107492 | |
| 107367 | 107493 | /* Do the rename operation using a recursive UPDATE statement that |
| 107368 | 107494 | ** uses the sqlite_rename_column() SQL function to compute the new |
| 107369 | 107495 | ** CREATE statement text for the sqlite_schema table. |
| 107370 | 107496 | */ |
| | @@ -107391,11 +107517,11 @@ |
| 107391 | 107517 | zDb, pTab->zName, iCol, zNew, bQuote |
| 107392 | 107518 | ); |
| 107393 | 107519 | |
| 107394 | 107520 | /* Drop and reload the database schema. */ |
| 107395 | 107521 | renameReloadSchema(pParse, iSchema, INITFLAG_AlterRename); |
| 107396 | | - renameTestSchema(pParse, zDb, iSchema==1, "after rename", 0); |
| 107522 | + renameTestSchema(pParse, zDb, iSchema==1, "after rename", 1); |
| 107397 | 107523 | |
| 107398 | 107524 | exit_rename_column: |
| 107399 | 107525 | sqlite3SrcListDelete(db, pSrc); |
| 107400 | 107526 | sqlite3DbFree(db, zOld); |
| 107401 | 107527 | sqlite3DbFree(db, zNew); |
| | @@ -107815,21 +107941,16 @@ |
| 107815 | 107941 | static int renameParseSql( |
| 107816 | 107942 | Parse *p, /* Memory to use for Parse object */ |
| 107817 | 107943 | const char *zDb, /* Name of schema SQL belongs to */ |
| 107818 | 107944 | sqlite3 *db, /* Database handle */ |
| 107819 | 107945 | const char *zSql, /* SQL to parse */ |
| 107820 | | - int bTemp, /* True if SQL is from temp schema */ |
| 107821 | | - const char *zDropColumn /* Name of column being dropped */ |
| 107946 | + int bTemp /* True if SQL is from temp schema */ |
| 107822 | 107947 | ){ |
| 107823 | 107948 | int rc; |
| 107824 | 107949 | char *zErr = 0; |
| 107825 | 107950 | |
| 107826 | 107951 | db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb); |
| 107827 | | - if( zDropColumn ){ |
| 107828 | | - db->init.bDropColumn = 1; |
| 107829 | | - db->init.azInit = (char**)&zDropColumn; |
| 107830 | | - } |
| 107831 | 107952 | |
| 107832 | 107953 | /* Parse the SQL statement passed as the first argument. If no error |
| 107833 | 107954 | ** occurs and the parse does not result in a new table, index or |
| 107834 | 107955 | ** trigger object, the database must be corrupt. */ |
| 107835 | 107956 | memset(p, 0, sizeof(Parse)); |
| | @@ -107858,11 +107979,10 @@ |
| 107858 | 107979 | } |
| 107859 | 107980 | } |
| 107860 | 107981 | #endif |
| 107861 | 107982 | |
| 107862 | 107983 | db->init.iDb = 0; |
| 107863 | | - db->init.bDropColumn = 0; |
| 107864 | 107984 | return rc; |
| 107865 | 107985 | } |
| 107866 | 107986 | |
| 107867 | 107987 | /* |
| 107868 | 107988 | ** This function edits SQL statement zSql, replacing each token identified |
| | @@ -107882,51 +108002,76 @@ |
| 107882 | 108002 | ){ |
| 107883 | 108003 | int nNew = sqlite3Strlen30(zNew); |
| 107884 | 108004 | int nSql = sqlite3Strlen30(zSql); |
| 107885 | 108005 | sqlite3 *db = sqlite3_context_db_handle(pCtx); |
| 107886 | 108006 | int rc = SQLITE_OK; |
| 107887 | | - char *zQuot; |
| 108007 | + char *zQuot = 0; |
| 107888 | 108008 | char *zOut; |
| 107889 | | - int nQuot; |
| 107890 | | - |
| 107891 | | - /* Set zQuot to point to a buffer containing a quoted copy of the |
| 107892 | | - ** identifier zNew. If the corresponding identifier in the original |
| 107893 | | - ** ALTER TABLE statement was quoted (bQuote==1), then set zNew to |
| 107894 | | - ** point to zQuot so that all substitutions are made using the |
| 107895 | | - ** quoted version of the new column name. */ |
| 107896 | | - zQuot = sqlite3MPrintf(db, "\"%w\"", zNew); |
| 107897 | | - if( zQuot==0 ){ |
| 107898 | | - return SQLITE_NOMEM; |
| 107899 | | - }else{ |
| 107900 | | - nQuot = sqlite3Strlen30(zQuot); |
| 107901 | | - } |
| 107902 | | - if( bQuote ){ |
| 107903 | | - zNew = zQuot; |
| 107904 | | - nNew = nQuot; |
| 108009 | + int nQuot = 0; |
| 108010 | + char *zBuf1 = 0; |
| 108011 | + char *zBuf2 = 0; |
| 108012 | + |
| 108013 | + if( zNew ){ |
| 108014 | + /* Set zQuot to point to a buffer containing a quoted copy of the |
| 108015 | + ** identifier zNew. If the corresponding identifier in the original |
| 108016 | + ** ALTER TABLE statement was quoted (bQuote==1), then set zNew to |
| 108017 | + ** point to zQuot so that all substitutions are made using the |
| 108018 | + ** quoted version of the new column name. */ |
| 108019 | + zQuot = sqlite3MPrintf(db, "\"%w\" ", zNew); |
| 108020 | + if( zQuot==0 ){ |
| 108021 | + return SQLITE_NOMEM; |
| 108022 | + }else{ |
| 108023 | + nQuot = sqlite3Strlen30(zQuot)-1; |
| 108024 | + } |
| 108025 | + |
| 108026 | + assert( nQuot>=nNew ); |
| 108027 | + zOut = sqlite3DbMallocZero(db, nSql + pRename->nList*nQuot + 1); |
| 108028 | + }else{ |
| 108029 | + zOut = (char*)sqlite3DbMallocZero(db, (nSql*2+1) * 3); |
| 108030 | + if( zOut ){ |
| 108031 | + zBuf1 = &zOut[nSql*2+1]; |
| 108032 | + zBuf2 = &zOut[nSql*4+2]; |
| 108033 | + } |
| 107905 | 108034 | } |
| 107906 | 108035 | |
| 107907 | 108036 | /* At this point pRename->pList contains a list of RenameToken objects |
| 107908 | 108037 | ** corresponding to all tokens in the input SQL that must be replaced |
| 107909 | | - ** with the new column name. All that remains is to construct and |
| 107910 | | - ** return the edited SQL string. */ |
| 107911 | | - assert( nQuot>=nNew ); |
| 107912 | | - zOut = sqlite3DbMallocZero(db, nSql + pRename->nList*nQuot + 1); |
| 108038 | + ** with the new column name, or with single-quoted versions of themselves. |
| 108039 | + ** All that remains is to construct and return the edited SQL string. */ |
| 107913 | 108040 | if( zOut ){ |
| 107914 | 108041 | int nOut = nSql; |
| 107915 | 108042 | memcpy(zOut, zSql, nSql); |
| 107916 | 108043 | while( pRename->pList ){ |
| 107917 | 108044 | int iOff; /* Offset of token to replace in zOut */ |
| 107918 | | - RenameToken *pBest = renameColumnTokenNext(pRename); |
| 107919 | | - |
| 107920 | 108045 | u32 nReplace; |
| 107921 | 108046 | const char *zReplace; |
| 107922 | | - if( sqlite3IsIdChar(*pBest->t.z) ){ |
| 107923 | | - nReplace = nNew; |
| 107924 | | - zReplace = zNew; |
| 108047 | + RenameToken *pBest = renameColumnTokenNext(pRename); |
| 108048 | + |
| 108049 | + if( zNew ){ |
| 108050 | + if( bQuote==0 && sqlite3IsIdChar(*pBest->t.z) ){ |
| 108051 | + nReplace = nNew; |
| 108052 | + zReplace = zNew; |
| 108053 | + }else{ |
| 108054 | + nReplace = nQuot; |
| 108055 | + zReplace = zQuot; |
| 108056 | + if( pBest->t.z[pBest->t.n]=='"' ) nReplace++; |
| 108057 | + } |
| 107925 | 108058 | }else{ |
| 107926 | | - nReplace = nQuot; |
| 107927 | | - zReplace = zQuot; |
| 108059 | + /* Dequote the double-quoted token. Then requote it again, this time |
| 108060 | + ** using single quotes. If the character immediately following the |
| 108061 | + ** original token within the input SQL was a single quote ('), then |
| 108062 | + ** add another space after the new, single-quoted version of the |
| 108063 | + ** token. This is so that (SELECT "string"'alias') maps to |
| 108064 | + ** (SELECT 'string' 'alias'), and not (SELECT 'string''alias'). */ |
| 108065 | + memcpy(zBuf1, pBest->t.z, pBest->t.n); |
| 108066 | + zBuf1[pBest->t.n] = 0; |
| 108067 | + sqlite3Dequote(zBuf1); |
| 108068 | + sqlite3_snprintf(nSql*2, zBuf2, "%Q%s", zBuf1, |
| 108069 | + pBest->t.z[pBest->t.n]=='\'' ? " " : "" |
| 108070 | + ); |
| 108071 | + zReplace = zBuf2; |
| 108072 | + nReplace = sqlite3Strlen30(zReplace); |
| 107928 | 108073 | } |
| 107929 | 108074 | |
| 107930 | 108075 | iOff = pBest->t.z - zSql; |
| 107931 | 108076 | if( pBest->t.n!=nReplace ){ |
| 107932 | 108077 | memmove(&zOut[iOff + nReplace], &zOut[iOff + pBest->t.n], |
| | @@ -108160,11 +108305,11 @@ |
| 108160 | 108305 | sCtx.iCol = ((iCol==pTab->iPKey) ? -1 : iCol); |
| 108161 | 108306 | |
| 108162 | 108307 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 108163 | 108308 | db->xAuth = 0; |
| 108164 | 108309 | #endif |
| 108165 | | - rc = renameParseSql(&sParse, zDb, db, zSql, bTemp, 0); |
| 108310 | + rc = renameParseSql(&sParse, zDb, db, zSql, bTemp); |
| 108166 | 108311 | |
| 108167 | 108312 | /* Find tokens that need to be replaced. */ |
| 108168 | 108313 | memset(&sWalker, 0, sizeof(Walker)); |
| 108169 | 108314 | sWalker.pParse = &sParse; |
| 108170 | 108315 | sWalker.xExprCallback = renameColumnExprCb; |
| | @@ -108364,11 +108509,11 @@ |
| 108364 | 108509 | sWalker.pParse = &sParse; |
| 108365 | 108510 | sWalker.xExprCallback = renameTableExprCb; |
| 108366 | 108511 | sWalker.xSelectCallback = renameTableSelectCb; |
| 108367 | 108512 | sWalker.u.pRename = &sCtx; |
| 108368 | 108513 | |
| 108369 | | - rc = renameParseSql(&sParse, zDb, db, zInput, bTemp, 0); |
| 108514 | + rc = renameParseSql(&sParse, zDb, db, zInput, bTemp); |
| 108370 | 108515 | |
| 108371 | 108516 | if( rc==SQLITE_OK ){ |
| 108372 | 108517 | int isLegacy = (db->flags & SQLITE_LegacyAlter); |
| 108373 | 108518 | if( sParse.pNewTable ){ |
| 108374 | 108519 | Table *pTab = sParse.pNewTable; |
| | @@ -108466,10 +108611,123 @@ |
| 108466 | 108611 | #endif |
| 108467 | 108612 | } |
| 108468 | 108613 | |
| 108469 | 108614 | return; |
| 108470 | 108615 | } |
| 108616 | + |
| 108617 | +static int renameQuotefixExprCb(Walker *pWalker, Expr *pExpr){ |
| 108618 | + if( pExpr->op==TK_STRING && (pExpr->flags & EP_DblQuoted) ){ |
| 108619 | + renameTokenFind(pWalker->pParse, pWalker->u.pRename, (void*)pExpr); |
| 108620 | + } |
| 108621 | + return WRC_Continue; |
| 108622 | +} |
| 108623 | + |
| 108624 | +/* |
| 108625 | +** The implementation of an SQL scalar function that rewrites DDL statements |
| 108626 | +** so that any string literals that use double-quotes are modified so that |
| 108627 | +** they use single quotes. |
| 108628 | +** |
| 108629 | +** Two arguments must be passed: |
| 108630 | +** |
| 108631 | +** 0: Database name ("main", "temp" etc.). |
| 108632 | +** 1: SQL statement to edit. |
| 108633 | +** |
| 108634 | +** The returned value is the modified SQL statement. For example, given |
| 108635 | +** the database schema: |
| 108636 | +** |
| 108637 | +** CREATE TABLE t1(a, b, c); |
| 108638 | +** |
| 108639 | +** SELECT sqlite_rename_quotefix('main', |
| 108640 | +** 'CREATE VIEW v1 AS SELECT "a", "string" FROM t1' |
| 108641 | +** ); |
| 108642 | +** |
| 108643 | +** returns the string: |
| 108644 | +** |
| 108645 | +** CREATE VIEW v1 AS SELECT "a", 'string' FROM t1 |
| 108646 | +*/ |
| 108647 | +static void renameQuotefixFunc( |
| 108648 | + sqlite3_context *context, |
| 108649 | + int NotUsed, |
| 108650 | + sqlite3_value **argv |
| 108651 | +){ |
| 108652 | + sqlite3 *db = sqlite3_context_db_handle(context); |
| 108653 | + char const *zDb = (const char*)sqlite3_value_text(argv[0]); |
| 108654 | + char const *zInput = (const char*)sqlite3_value_text(argv[1]); |
| 108655 | + |
| 108656 | +#ifndef SQLITE_OMIT_AUTHORIZATION |
| 108657 | + sqlite3_xauth xAuth = db->xAuth; |
| 108658 | + db->xAuth = 0; |
| 108659 | +#endif |
| 108660 | + |
| 108661 | + sqlite3BtreeEnterAll(db); |
| 108662 | + |
| 108663 | + UNUSED_PARAMETER(NotUsed); |
| 108664 | + if( zDb && zInput ){ |
| 108665 | + int rc; |
| 108666 | + Parse sParse; |
| 108667 | + rc = renameParseSql(&sParse, zDb, db, zInput, 0); |
| 108668 | + |
| 108669 | + if( rc==SQLITE_OK ){ |
| 108670 | + RenameCtx sCtx; |
| 108671 | + Walker sWalker; |
| 108672 | + |
| 108673 | + /* Walker to find tokens that need to be replaced. */ |
| 108674 | + memset(&sCtx, 0, sizeof(RenameCtx)); |
| 108675 | + memset(&sWalker, 0, sizeof(Walker)); |
| 108676 | + sWalker.pParse = &sParse; |
| 108677 | + sWalker.xExprCallback = renameQuotefixExprCb; |
| 108678 | + sWalker.xSelectCallback = renameColumnSelectCb; |
| 108679 | + sWalker.u.pRename = &sCtx; |
| 108680 | + |
| 108681 | + if( sParse.pNewTable ){ |
| 108682 | + Select *pSelect = sParse.pNewTable->pSelect; |
| 108683 | + if( pSelect ){ |
| 108684 | + pSelect->selFlags &= ~SF_View; |
| 108685 | + sParse.rc = SQLITE_OK; |
| 108686 | + sqlite3SelectPrep(&sParse, pSelect, 0); |
| 108687 | + rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc); |
| 108688 | + if( rc==SQLITE_OK ){ |
| 108689 | + sqlite3WalkSelect(&sWalker, pSelect); |
| 108690 | + } |
| 108691 | + }else{ |
| 108692 | + int i; |
| 108693 | + sqlite3WalkExprList(&sWalker, sParse.pNewTable->pCheck); |
| 108694 | +#ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 108695 | + for(i=0; i<sParse.pNewTable->nCol; i++){ |
| 108696 | + sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt); |
| 108697 | + } |
| 108698 | +#endif /* SQLITE_OMIT_GENERATED_COLUMNS */ |
| 108699 | + } |
| 108700 | + }else if( sParse.pNewIndex ){ |
| 108701 | + sqlite3WalkExprList(&sWalker, sParse.pNewIndex->aColExpr); |
| 108702 | + sqlite3WalkExpr(&sWalker, sParse.pNewIndex->pPartIdxWhere); |
| 108703 | + }else{ |
| 108704 | +#ifndef SQLITE_OMIT_TRIGGER |
| 108705 | + rc = renameResolveTrigger(&sParse); |
| 108706 | + if( rc==SQLITE_OK ){ |
| 108707 | + renameWalkTrigger(&sWalker, sParse.pNewTrigger); |
| 108708 | + } |
| 108709 | +#endif /* SQLITE_OMIT_TRIGGER */ |
| 108710 | + } |
| 108711 | + |
| 108712 | + if( rc==SQLITE_OK ){ |
| 108713 | + rc = renameEditSql(context, &sCtx, zInput, 0, 0); |
| 108714 | + } |
| 108715 | + renameTokenFree(db, sCtx.pList); |
| 108716 | + } |
| 108717 | + if( rc!=SQLITE_OK ){ |
| 108718 | + sqlite3_result_error_code(context, rc); |
| 108719 | + } |
| 108720 | + renameParseCleanup(&sParse); |
| 108721 | + } |
| 108722 | + |
| 108723 | +#ifndef SQLITE_OMIT_AUTHORIZATION |
| 108724 | + db->xAuth = xAuth; |
| 108725 | +#endif |
| 108726 | + |
| 108727 | + sqlite3BtreeLeaveAll(db); |
| 108728 | +} |
| 108471 | 108729 | |
| 108472 | 108730 | /* |
| 108473 | 108731 | ** An SQL user function that checks that there are no parse or symbol |
| 108474 | 108732 | ** resolution problems in a CREATE TRIGGER|TABLE|VIEW|INDEX statement. |
| 108475 | 108733 | ** After an ALTER TABLE .. RENAME operation is performed and the schema |
| | @@ -108480,11 +108738,11 @@ |
| 108480 | 108738 | ** 1: SQL statement. |
| 108481 | 108739 | ** 2: Object type ("view", "table", "trigger" or "index"). |
| 108482 | 108740 | ** 3: Object name. |
| 108483 | 108741 | ** 4: True if object is from temp schema. |
| 108484 | 108742 | ** 5: "when" part of error message. |
| 108485 | | -** 6: Name of column being dropped, or NULL. |
| 108743 | +** 6: True to disable the DQS quirk when parsing SQL. |
| 108486 | 108744 | ** |
| 108487 | 108745 | ** Unless it finds an error, this function normally returns NULL. However, it |
| 108488 | 108746 | ** returns integer value 1 if: |
| 108489 | 108747 | ** |
| 108490 | 108748 | ** * the SQL argument creates a trigger, and |
| | @@ -108499,22 +108757,26 @@ |
| 108499 | 108757 | char const *zDb = (const char*)sqlite3_value_text(argv[0]); |
| 108500 | 108758 | char const *zInput = (const char*)sqlite3_value_text(argv[1]); |
| 108501 | 108759 | int bTemp = sqlite3_value_int(argv[4]); |
| 108502 | 108760 | int isLegacy = (db->flags & SQLITE_LegacyAlter); |
| 108503 | 108761 | char const *zWhen = (const char*)sqlite3_value_text(argv[5]); |
| 108504 | | - char const *zDropColumn = (const char*)sqlite3_value_text(argv[6]); |
| 108762 | + int bNoDQS = sqlite3_value_int(argv[6]); |
| 108505 | 108763 | |
| 108506 | 108764 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 108507 | 108765 | sqlite3_xauth xAuth = db->xAuth; |
| 108508 | 108766 | db->xAuth = 0; |
| 108509 | 108767 | #endif |
| 108510 | 108768 | |
| 108511 | 108769 | UNUSED_PARAMETER(NotUsed); |
| 108770 | + |
| 108512 | 108771 | if( zDb && zInput ){ |
| 108513 | 108772 | int rc; |
| 108514 | 108773 | Parse sParse; |
| 108515 | | - rc = renameParseSql(&sParse, zDb, db, zInput, bTemp, zDropColumn); |
| 108774 | + int flags = db->flags; |
| 108775 | + if( bNoDQS ) db->flags &= ~(SQLITE_DqsDML|SQLITE_DqsDDL); |
| 108776 | + rc = renameParseSql(&sParse, zDb, db, zInput, bTemp); |
| 108777 | + db->flags |= (flags & (SQLITE_DqsDML|SQLITE_DqsDDL)); |
| 108516 | 108778 | if( rc==SQLITE_OK ){ |
| 108517 | 108779 | if( isLegacy==0 && sParse.pNewTable && sParse.pNewTable->pSelect ){ |
| 108518 | 108780 | NameContext sNC; |
| 108519 | 108781 | memset(&sNC, 0, sizeof(sNC)); |
| 108520 | 108782 | sNC.pParse = &sParse; |
| | @@ -108578,11 +108840,11 @@ |
| 108578 | 108840 | sqlite3_xauth xAuth = db->xAuth; |
| 108579 | 108841 | db->xAuth = 0; |
| 108580 | 108842 | #endif |
| 108581 | 108843 | |
| 108582 | 108844 | UNUSED_PARAMETER(NotUsed); |
| 108583 | | - rc = renameParseSql(&sParse, zDb, db, zSql, iSchema==1, 0); |
| 108845 | + rc = renameParseSql(&sParse, zDb, db, zSql, iSchema==1); |
| 108584 | 108846 | if( rc!=SQLITE_OK ) goto drop_column_done; |
| 108585 | 108847 | pTab = sParse.pNewTable; |
| 108586 | 108848 | if( pTab==0 || pTab->nCol==1 || iCol>=pTab->nCol ){ |
| 108587 | 108849 | /* This can happen if the sqlite_schema table is corrupt */ |
| 108588 | 108850 | rc = SQLITE_CORRUPT_BKPT; |
| | @@ -108672,20 +108934,21 @@ |
| 108672 | 108934 | /* Edit the sqlite_schema table */ |
| 108673 | 108935 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 108674 | 108936 | assert( iDb>=0 ); |
| 108675 | 108937 | zDb = db->aDb[iDb].zDbSName; |
| 108676 | 108938 | renameTestSchema(pParse, zDb, iDb==1, "", 0); |
| 108939 | + renameFixQuotes(pParse, zDb, iDb==1); |
| 108677 | 108940 | sqlite3NestedParse(pParse, |
| 108678 | 108941 | "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET " |
| 108679 | 108942 | "sql = sqlite_drop_column(%d, sql, %d) " |
| 108680 | 108943 | "WHERE (type=='table' AND tbl_name=%Q COLLATE nocase)" |
| 108681 | 108944 | , zDb, iDb, iCol, pTab->zName |
| 108682 | 108945 | ); |
| 108683 | 108946 | |
| 108684 | 108947 | /* Drop and reload the database schema. */ |
| 108685 | 108948 | renameReloadSchema(pParse, iDb, INITFLAG_AlterDrop); |
| 108686 | | - renameTestSchema(pParse, zDb, iDb==1, "after drop column", zCol); |
| 108949 | + renameTestSchema(pParse, zDb, iDb==1, "after drop column", 1); |
| 108687 | 108950 | |
| 108688 | 108951 | /* Edit rows of table on disk */ |
| 108689 | 108952 | if( pParse->nErr==0 && (pTab->aCol[iCol].colFlags & COLFLAG_VIRTUAL)==0 ){ |
| 108690 | 108953 | int i; |
| 108691 | 108954 | int addr; |
| | @@ -108697,31 +108960,37 @@ |
| 108697 | 108960 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 108698 | 108961 | iCur = pParse->nTab++; |
| 108699 | 108962 | sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenWrite); |
| 108700 | 108963 | addr = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v); |
| 108701 | 108964 | reg = ++pParse->nMem; |
| 108702 | | - pParse->nMem += pTab->nCol; |
| 108703 | 108965 | if( HasRowid(pTab) ){ |
| 108704 | 108966 | sqlite3VdbeAddOp2(v, OP_Rowid, iCur, reg); |
| 108967 | + pParse->nMem += pTab->nCol; |
| 108705 | 108968 | }else{ |
| 108706 | 108969 | pPk = sqlite3PrimaryKeyIndex(pTab); |
| 108970 | + pParse->nMem += pPk->nColumn; |
| 108971 | + for(i=0; i<pPk->nKeyCol; i++){ |
| 108972 | + sqlite3VdbeAddOp3(v, OP_Column, iCur, i, reg+i+1); |
| 108973 | + } |
| 108974 | + nField = pPk->nKeyCol; |
| 108707 | 108975 | } |
| 108976 | + regRec = ++pParse->nMem; |
| 108708 | 108977 | for(i=0; i<pTab->nCol; i++){ |
| 108709 | 108978 | if( i!=iCol && (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){ |
| 108710 | 108979 | int regOut; |
| 108711 | 108980 | if( pPk ){ |
| 108712 | 108981 | int iPos = sqlite3TableColumnToIndex(pPk, i); |
| 108713 | 108982 | int iColPos = sqlite3TableColumnToIndex(pPk, iCol); |
| 108983 | + if( iPos<pPk->nKeyCol ) continue; |
| 108714 | 108984 | regOut = reg+1+iPos-(iPos>iColPos); |
| 108715 | 108985 | }else{ |
| 108716 | 108986 | regOut = reg+1+nField; |
| 108717 | 108987 | } |
| 108718 | 108988 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut); |
| 108719 | 108989 | nField++; |
| 108720 | 108990 | } |
| 108721 | 108991 | } |
| 108722 | | - regRec = reg + pTab->nCol; |
| 108723 | 108992 | sqlite3VdbeAddOp3(v, OP_MakeRecord, reg+1, nField, regRec); |
| 108724 | 108993 | if( pPk ){ |
| 108725 | 108994 | sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iCur, regRec, reg+1, pPk->nKeyCol); |
| 108726 | 108995 | }else{ |
| 108727 | 108996 | sqlite3VdbeAddOp3(v, OP_Insert, iCur, regRec, reg); |
| | @@ -108743,10 +109012,11 @@ |
| 108743 | 109012 | static FuncDef aAlterTableFuncs[] = { |
| 108744 | 109013 | INTERNAL_FUNCTION(sqlite_rename_column, 9, renameColumnFunc), |
| 108745 | 109014 | INTERNAL_FUNCTION(sqlite_rename_table, 7, renameTableFunc), |
| 108746 | 109015 | INTERNAL_FUNCTION(sqlite_rename_test, 7, renameTableTest), |
| 108747 | 109016 | INTERNAL_FUNCTION(sqlite_drop_column, 3, dropColumnFunc), |
| 109017 | + INTERNAL_FUNCTION(sqlite_rename_quotefix,2, renameQuotefixFunc), |
| 108748 | 109018 | }; |
| 108749 | 109019 | sqlite3InsertBuiltinFuncs(aAlterTableFuncs, ArraySize(aAlterTableFuncs)); |
| 108750 | 109020 | } |
| 108751 | 109021 | #endif /* SQLITE_ALTER_TABLE */ |
| 108752 | 109022 | |
| | @@ -112737,21 +113007,10 @@ |
| 112737 | 113007 | pTable->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) ); |
| 112738 | 113008 | #endif |
| 112739 | 113009 | assert( pParse->pNewTable==0 ); |
| 112740 | 113010 | pParse->pNewTable = pTable; |
| 112741 | 113011 | |
| 112742 | | - /* If this is the magic sqlite_sequence table used by autoincrement, |
| 112743 | | - ** then record a pointer to this table in the main database structure |
| 112744 | | - ** so that INSERT can find the table easily. |
| 112745 | | - */ |
| 112746 | | -#ifndef SQLITE_OMIT_AUTOINCREMENT |
| 112747 | | - if( !pParse->nested && strcmp(zName, "sqlite_sequence")==0 ){ |
| 112748 | | - assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 112749 | | - pTable->pSchema->pSeqTab = pTable; |
| 112750 | | - } |
| 112751 | | -#endif |
| 112752 | | - |
| 112753 | 113012 | /* Begin generating the code that will insert the table record into |
| 112754 | 113013 | ** the schema table. Note in particular that we must go ahead |
| 112755 | 113014 | ** and allocate the record number for the table entry now. Before any |
| 112756 | 113015 | ** PRIMARY KEY or UNIQUE keywords are parsed. Those keywords will cause |
| 112757 | 113016 | ** indices to be created and the table record must come before the |
| | @@ -114192,11 +114451,11 @@ |
| 114192 | 114451 | |
| 114193 | 114452 | #ifndef SQLITE_OMIT_AUTOINCREMENT |
| 114194 | 114453 | /* Check to see if we need to create an sqlite_sequence table for |
| 114195 | 114454 | ** keeping track of autoincrement keys. |
| 114196 | 114455 | */ |
| 114197 | | - if( (p->tabFlags & TF_Autoincrement)!=0 ){ |
| 114456 | + if( (p->tabFlags & TF_Autoincrement)!=0 && !IN_SPECIAL_PARSE ){ |
| 114198 | 114457 | Db *pDb = &db->aDb[iDb]; |
| 114199 | 114458 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 114200 | 114459 | if( pDb->pSchema->pSeqTab==0 ){ |
| 114201 | 114460 | sqlite3NestedParse(pParse, |
| 114202 | 114461 | "CREATE TABLE %Q.sqlite_sequence(name,seq)", |
| | @@ -114223,10 +114482,21 @@ |
| 114223 | 114482 | sqlite3OomFault(db); |
| 114224 | 114483 | return; |
| 114225 | 114484 | } |
| 114226 | 114485 | pParse->pNewTable = 0; |
| 114227 | 114486 | db->mDbFlags |= DBFLAG_SchemaChange; |
| 114487 | + |
| 114488 | + /* If this is the magic sqlite_sequence table used by autoincrement, |
| 114489 | + ** then record a pointer to this table in the main database structure |
| 114490 | + ** so that INSERT can find the table easily. */ |
| 114491 | + assert( !pParse->nested ); |
| 114492 | +#ifndef SQLITE_OMIT_AUTOINCREMENT |
| 114493 | + if( strcmp(p->zName, "sqlite_sequence")==0 ){ |
| 114494 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 114495 | + p->pSchema->pSeqTab = p; |
| 114496 | + } |
| 114497 | +#endif |
| 114228 | 114498 | } |
| 114229 | 114499 | |
| 114230 | 114500 | #ifndef SQLITE_OMIT_ALTERTABLE |
| 114231 | 114501 | if( !pSelect && !p->pSelect ){ |
| 114232 | 114502 | assert( pCons && pEnd ); |
| | @@ -114266,10 +114536,20 @@ |
| 114266 | 114536 | goto create_view_fail; |
| 114267 | 114537 | } |
| 114268 | 114538 | sqlite3StartTable(pParse, pName1, pName2, isTemp, 1, 0, noErr); |
| 114269 | 114539 | p = pParse->pNewTable; |
| 114270 | 114540 | if( p==0 || pParse->nErr ) goto create_view_fail; |
| 114541 | + |
| 114542 | + /* Legacy versions of SQLite allowed the use of the magic "rowid" column |
| 114543 | + ** on a view, even though views do not have rowids. The following flag |
| 114544 | + ** setting fixes this problem. But the fix can be disabled by compiling |
| 114545 | + ** with -DSQLITE_ALLOW_ROWID_IN_VIEW in case there are legacy apps that |
| 114546 | + ** depend upon the old buggy behavior. */ |
| 114547 | +#ifndef SQLITE_ALLOW_ROWID_IN_VIEW |
| 114548 | + p->tabFlags |= TF_NoVisibleRowid; |
| 114549 | +#endif |
| 114550 | + |
| 114271 | 114551 | sqlite3TwoPartName(pParse, pName1, pName2, &pName); |
| 114272 | 114552 | iDb = sqlite3SchemaToIndex(db, p->pSchema); |
| 114273 | 114553 | sqlite3FixInit(&sFix, pParse, iDb, "view", pName); |
| 114274 | 114554 | if( sqlite3FixSelect(&sFix, pSelect) ) goto create_view_fail; |
| 114275 | 114555 | |
| | @@ -115827,11 +116107,11 @@ |
| 115827 | 116107 | goto exit_drop_index; |
| 115828 | 116108 | } |
| 115829 | 116109 | pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase); |
| 115830 | 116110 | if( pIndex==0 ){ |
| 115831 | 116111 | if( !ifExists ){ |
| 115832 | | - sqlite3ErrorMsg(pParse, "no such index: %S", pName, 0); |
| 116112 | + sqlite3ErrorMsg(pParse, "no such index: %S", pName->a); |
| 115833 | 116113 | }else{ |
| 115834 | 116114 | sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase); |
| 115835 | 116115 | } |
| 115836 | 116116 | pParse->checkSchema = 1; |
| 115837 | 116117 | goto exit_drop_index; |
| | @@ -122970,11 +123250,11 @@ |
| 122970 | 123250 | if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){ |
| 122971 | 123251 | ipkColumn = i; |
| 122972 | 123252 | bIdListInOrder = 0; |
| 122973 | 123253 | }else{ |
| 122974 | 123254 | sqlite3ErrorMsg(pParse, "table %S has no column named %s", |
| 122975 | | - pTabList, 0, pColumn->a[i].zName); |
| 123255 | + pTabList->a, pColumn->a[i].zName); |
| 122976 | 123256 | pParse->checkSchema = 1; |
| 122977 | 123257 | goto insert_cleanup; |
| 122978 | 123258 | } |
| 122979 | 123259 | } |
| 122980 | 123260 | } |
| | @@ -123098,11 +123378,11 @@ |
| 123098 | 123378 | } |
| 123099 | 123379 | } |
| 123100 | 123380 | if( nColumn!=(pTab->nCol-nHidden) ){ |
| 123101 | 123381 | sqlite3ErrorMsg(pParse, |
| 123102 | 123382 | "table %S has %d columns but %d values were supplied", |
| 123103 | | - pTabList, 0, pTab->nCol-nHidden, nColumn); |
| 123383 | + pTabList->a, pTab->nCol-nHidden, nColumn); |
| 123104 | 123384 | goto insert_cleanup; |
| 123105 | 123385 | } |
| 123106 | 123386 | } |
| 123107 | 123387 | if( pColumn!=0 && nColumn!=pColumn->nId ){ |
| 123108 | 123388 | sqlite3ErrorMsg(pParse, "%d values for %d columns", nColumn, pColumn->nId); |
| | @@ -123401,11 +123681,11 @@ |
| 123401 | 123681 | sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError); |
| 123402 | 123682 | sqlite3MayAbort(pParse); |
| 123403 | 123683 | }else |
| 123404 | 123684 | #endif |
| 123405 | 123685 | { |
| 123406 | | - int isReplace; /* Set to true if constraints may cause a replace */ |
| 123686 | + int isReplace = 0;/* Set to true if constraints may cause a replace */ |
| 123407 | 123687 | int bUseSeek; /* True to use OPFLAG_SEEKRESULT */ |
| 123408 | 123688 | sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur, |
| 123409 | 123689 | regIns, 0, ipkColumn>=0, onError, endOfLoop, &isReplace, 0, pUpsert |
| 123410 | 123690 | ); |
| 123411 | 123691 | sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0); |
| | @@ -123421,10 +123701,17 @@ |
| 123421 | 123701 | bUseSeek = (isReplace==0 || !sqlite3VdbeHasSubProgram(v)); |
| 123422 | 123702 | sqlite3CompleteInsertion(pParse, pTab, iDataCur, iIdxCur, |
| 123423 | 123703 | regIns, aRegIdx, 0, appendFlag, bUseSeek |
| 123424 | 123704 | ); |
| 123425 | 123705 | } |
| 123706 | +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW |
| 123707 | + }else if( pParse->bReturning ){ |
| 123708 | + /* If there is a RETURNING clause, populate the rowid register with |
| 123709 | + ** constant value -1, in case one or more of the returned expressions |
| 123710 | + ** refer to the "rowid" of the view. */ |
| 123711 | + sqlite3VdbeAddOp2(v, OP_Integer, -1, regRowid); |
| 123712 | +#endif |
| 123426 | 123713 | } |
| 123427 | 123714 | |
| 123428 | 123715 | /* Update the count of rows that are inserted |
| 123429 | 123716 | */ |
| 123430 | 123717 | if( regRowCount ){ |
| | @@ -130625,10 +130912,11 @@ |
| 130625 | 130912 | ** will be closed immediately after reading the meta-value. */ |
| 130626 | 130913 | if( sqlite3BtreeTxnState(pBt)==SQLITE_TXN_NONE ){ |
| 130627 | 130914 | rc = sqlite3BtreeBeginTrans(pBt, 0, 0); |
| 130628 | 130915 | if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){ |
| 130629 | 130916 | sqlite3OomFault(db); |
| 130917 | + pParse->rc = SQLITE_NOMEM; |
| 130630 | 130918 | } |
| 130631 | 130919 | if( rc!=SQLITE_OK ) return; |
| 130632 | 130920 | openedTransaction = 1; |
| 130633 | 130921 | } |
| 130634 | 130922 | |
| | @@ -130860,10 +131148,11 @@ |
| 130860 | 131148 | if( db->init.busy==0 ){ |
| 130861 | 131149 | sqlite3VdbeSetSql(sParse.pVdbe, zSql, (int)(sParse.zTail-zSql), prepFlags); |
| 130862 | 131150 | } |
| 130863 | 131151 | if( db->mallocFailed ){ |
| 130864 | 131152 | sParse.rc = SQLITE_NOMEM_BKPT; |
| 131153 | + sParse.checkSchema = 0; |
| 130865 | 131154 | } |
| 130866 | 131155 | if( sParse.rc!=SQLITE_OK && sParse.rc!=SQLITE_DONE ){ |
| 130867 | 131156 | if( sParse.checkSchema ){ |
| 130868 | 131157 | schemaIsValid(&sParse); |
| 130869 | 131158 | } |
| | @@ -131884,35 +132173,159 @@ |
| 131884 | 132173 | VdbeComment((v, "OFFSET")); |
| 131885 | 132174 | } |
| 131886 | 132175 | } |
| 131887 | 132176 | |
| 131888 | 132177 | /* |
| 131889 | | -** Add code that will check to make sure the N registers starting at iMem |
| 131890 | | -** form a distinct entry. iTab is a sorting index that holds previously |
| 131891 | | -** seen combinations of the N values. A new entry is made in iTab |
| 131892 | | -** if the current N values are new. |
| 132178 | +** Add code that will check to make sure the array of registers starting at |
| 132179 | +** iMem form a distinct entry. This is used by both "SELECT DISTINCT ..." and |
| 132180 | +** distinct aggregates ("SELECT count(DISTINCT <expr>) ..."). Three strategies |
| 132181 | +** are available. Which is used depends on the value of parameter eTnctType, |
| 132182 | +** as follows: |
| 131893 | 132183 | ** |
| 131894 | | -** A jump to addrRepeat is made and the N+1 values are popped from the |
| 131895 | | -** stack if the top N elements are not distinct. |
| 132184 | +** WHERE_DISTINCT_UNORDERED/WHERE_DISTINCT_NOOP: |
| 132185 | +** Build an ephemeral table that contains all entries seen before and |
| 132186 | +** skip entries which have been seen before. |
| 132187 | +** |
| 132188 | +** Parameter iTab is the cursor number of an ephemeral table that must |
| 132189 | +** be opened before the VM code generated by this routine is executed. |
| 132190 | +** The ephemeral cursor table is queried for a record identical to the |
| 132191 | +** record formed by the current array of registers. If one is found, |
| 132192 | +** jump to VM address addrRepeat. Otherwise, insert a new record into |
| 132193 | +** the ephemeral cursor and proceed. |
| 132194 | +** |
| 132195 | +** The returned value in this case is a copy of parameter iTab. |
| 132196 | +** |
| 132197 | +** WHERE_DISTINCT_ORDERED: |
| 132198 | +** In this case rows are being delivered sorted order. The ephermal |
| 132199 | +** table is not required. Instead, the current set of values |
| 132200 | +** is compared against previous row. If they match, the new row |
| 132201 | +** is not distinct and control jumps to VM address addrRepeat. Otherwise, |
| 132202 | +** the VM program proceeds with processing the new row. |
| 132203 | +** |
| 132204 | +** The returned value in this case is the register number of the first |
| 132205 | +** in an array of registers used to store the previous result row so that |
| 132206 | +** it can be compared to the next. The caller must ensure that this |
| 132207 | +** register is initialized to NULL. (The fixDistinctOpenEph() routine |
| 132208 | +** will take care of this initialization.) |
| 132209 | +** |
| 132210 | +** WHERE_DISTINCT_UNIQUE: |
| 132211 | +** In this case it has already been determined that the rows are distinct. |
| 132212 | +** No special action is required. The return value is zero. |
| 132213 | +** |
| 132214 | +** Parameter pEList is the list of expressions used to generated the |
| 132215 | +** contents of each row. It is used by this routine to determine (a) |
| 132216 | +** how many elements there are in the array of registers and (b) the |
| 132217 | +** collation sequences that should be used for the comparisons if |
| 132218 | +** eTnctType is WHERE_DISTINCT_ORDERED. |
| 131896 | 132219 | */ |
| 131897 | | -static void codeDistinct( |
| 132220 | +static int codeDistinct( |
| 131898 | 132221 | Parse *pParse, /* Parsing and code generating context */ |
| 132222 | + int eTnctType, /* WHERE_DISTINCT_* value */ |
| 131899 | 132223 | int iTab, /* A sorting index used to test for distinctness */ |
| 131900 | 132224 | int addrRepeat, /* Jump to here if not distinct */ |
| 131901 | | - int N, /* Number of elements */ |
| 131902 | | - int iMem /* First element */ |
| 132225 | + ExprList *pEList, /* Expression for each element */ |
| 132226 | + int regElem /* First element */ |
| 131903 | 132227 | ){ |
| 131904 | | - Vdbe *v; |
| 131905 | | - int r1; |
| 131906 | | - |
| 131907 | | - v = pParse->pVdbe; |
| 131908 | | - r1 = sqlite3GetTempReg(pParse); |
| 131909 | | - sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); VdbeCoverage(v); |
| 131910 | | - sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1); |
| 131911 | | - sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r1, iMem, N); |
| 131912 | | - sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); |
| 131913 | | - sqlite3ReleaseTempReg(pParse, r1); |
| 132228 | + int iRet = 0; |
| 132229 | + int nResultCol = pEList->nExpr; |
| 132230 | + Vdbe *v = pParse->pVdbe; |
| 132231 | + |
| 132232 | + switch( eTnctType ){ |
| 132233 | + case WHERE_DISTINCT_ORDERED: { |
| 132234 | + int i; |
| 132235 | + int iJump; /* Jump destination */ |
| 132236 | + int regPrev; /* Previous row content */ |
| 132237 | + |
| 132238 | + /* Allocate space for the previous row */ |
| 132239 | + iRet = regPrev = pParse->nMem+1; |
| 132240 | + pParse->nMem += nResultCol; |
| 132241 | + |
| 132242 | + iJump = sqlite3VdbeCurrentAddr(v) + nResultCol; |
| 132243 | + for(i=0; i<nResultCol; i++){ |
| 132244 | + CollSeq *pColl = sqlite3ExprCollSeq(pParse, pEList->a[i].pExpr); |
| 132245 | + if( i<nResultCol-1 ){ |
| 132246 | + sqlite3VdbeAddOp3(v, OP_Ne, regElem+i, iJump, regPrev+i); |
| 132247 | + VdbeCoverage(v); |
| 132248 | + }else{ |
| 132249 | + sqlite3VdbeAddOp3(v, OP_Eq, regElem+i, addrRepeat, regPrev+i); |
| 132250 | + VdbeCoverage(v); |
| 132251 | + } |
| 132252 | + sqlite3VdbeChangeP4(v, -1, (const char *)pColl, P4_COLLSEQ); |
| 132253 | + sqlite3VdbeChangeP5(v, SQLITE_NULLEQ); |
| 132254 | + } |
| 132255 | + assert( sqlite3VdbeCurrentAddr(v)==iJump || pParse->db->mallocFailed ); |
| 132256 | + sqlite3VdbeAddOp3(v, OP_Copy, regElem, regPrev, nResultCol-1); |
| 132257 | + break; |
| 132258 | + } |
| 132259 | + |
| 132260 | + case WHERE_DISTINCT_UNIQUE: { |
| 132261 | + /* nothing to do */ |
| 132262 | + break; |
| 132263 | + } |
| 132264 | + |
| 132265 | + default: { |
| 132266 | + int r1 = sqlite3GetTempReg(pParse); |
| 132267 | + sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, regElem, nResultCol); |
| 132268 | + VdbeCoverage(v); |
| 132269 | + sqlite3VdbeAddOp3(v, OP_MakeRecord, regElem, nResultCol, r1); |
| 132270 | + sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r1, regElem, nResultCol); |
| 132271 | + sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); |
| 132272 | + sqlite3ReleaseTempReg(pParse, r1); |
| 132273 | + iRet = iTab; |
| 132274 | + break; |
| 132275 | + } |
| 132276 | + } |
| 132277 | + |
| 132278 | + return iRet; |
| 132279 | +} |
| 132280 | + |
| 132281 | +/* |
| 132282 | +** This routine runs after codeDistinct(). It makes necessary |
| 132283 | +** adjustments to the OP_OpenEphemeral opcode that the codeDistinct() |
| 132284 | +** routine made use of. This processing must be done separately since |
| 132285 | +** sometimes codeDistinct is called before the OP_OpenEphemeral is actually |
| 132286 | +** laid down. |
| 132287 | +** |
| 132288 | +** WHERE_DISTINCT_NOOP: |
| 132289 | +** WHERE_DISTINCT_UNORDERED: |
| 132290 | +** |
| 132291 | +** No adjustments necessary. This function is a no-op. |
| 132292 | +** |
| 132293 | +** WHERE_DISTINCT_UNIQUE: |
| 132294 | +** |
| 132295 | +** The ephemeral table is not needed. So change the |
| 132296 | +** OP_OpenEphemeral opcode into an OP_Noop. |
| 132297 | +** |
| 132298 | +** WHERE_DISTINCT_ORDERED: |
| 132299 | +** |
| 132300 | +** The ephemeral table is not needed. But we do need register |
| 132301 | +** iVal to be initialized to NULL. So change the OP_OpenEphemeral |
| 132302 | +** into an OP_Null on the iVal register. |
| 132303 | +*/ |
| 132304 | +static void fixDistinctOpenEph( |
| 132305 | + Parse *pParse, /* Parsing and code generating context */ |
| 132306 | + int eTnctType, /* WHERE_DISTINCT_* value */ |
| 132307 | + int iVal, /* Value returned by codeDistinct() */ |
| 132308 | + int iOpenEphAddr /* Address of OP_OpenEphemeral instruction for iTab */ |
| 132309 | +){ |
| 132310 | + if( eTnctType==WHERE_DISTINCT_UNIQUE || eTnctType==WHERE_DISTINCT_ORDERED ){ |
| 132311 | + Vdbe *v = pParse->pVdbe; |
| 132312 | + sqlite3VdbeChangeToNoop(v, iOpenEphAddr); |
| 132313 | + if( sqlite3VdbeGetOp(v, iOpenEphAddr+1)->opcode==OP_Explain ){ |
| 132314 | + sqlite3VdbeChangeToNoop(v, iOpenEphAddr+1); |
| 132315 | + } |
| 132316 | + if( eTnctType==WHERE_DISTINCT_ORDERED ){ |
| 132317 | + /* Change the OP_OpenEphemeral to an OP_Null that sets the MEM_Cleared |
| 132318 | + ** bit on the first register of the previous value. This will cause the |
| 132319 | + ** OP_Ne added in codeDistinct() to always fail on the first iteration of |
| 132320 | + ** the loop even if the first row is all NULLs. */ |
| 132321 | + VdbeOp *pOp = sqlite3VdbeGetOp(v, iOpenEphAddr); |
| 132322 | + pOp->opcode = OP_Null; |
| 132323 | + pOp->p1 = 1; |
| 132324 | + pOp->p2 = iVal; |
| 132325 | + } |
| 132326 | + } |
| 131914 | 132327 | } |
| 131915 | 132328 | |
| 131916 | 132329 | #ifdef SQLITE_ENABLE_SORTER_REFERENCES |
| 131917 | 132330 | /* |
| 131918 | 132331 | ** This function is called as part of inner-loop generation for a SELECT |
| | @@ -132156,63 +132569,15 @@ |
| 132156 | 132569 | /* If the DISTINCT keyword was present on the SELECT statement |
| 132157 | 132570 | ** and this row has been seen before, then do not make this row |
| 132158 | 132571 | ** part of the result. |
| 132159 | 132572 | */ |
| 132160 | 132573 | if( hasDistinct ){ |
| 132161 | | - switch( pDistinct->eTnctType ){ |
| 132162 | | - case WHERE_DISTINCT_ORDERED: { |
| 132163 | | - VdbeOp *pOp; /* No longer required OpenEphemeral instr. */ |
| 132164 | | - int iJump; /* Jump destination */ |
| 132165 | | - int regPrev; /* Previous row content */ |
| 132166 | | - |
| 132167 | | - /* Allocate space for the previous row */ |
| 132168 | | - regPrev = pParse->nMem+1; |
| 132169 | | - pParse->nMem += nResultCol; |
| 132170 | | - |
| 132171 | | - /* Change the OP_OpenEphemeral coded earlier to an OP_Null |
| 132172 | | - ** sets the MEM_Cleared bit on the first register of the |
| 132173 | | - ** previous value. This will cause the OP_Ne below to always |
| 132174 | | - ** fail on the first iteration of the loop even if the first |
| 132175 | | - ** row is all NULLs. |
| 132176 | | - */ |
| 132177 | | - sqlite3VdbeChangeToNoop(v, pDistinct->addrTnct); |
| 132178 | | - pOp = sqlite3VdbeGetOp(v, pDistinct->addrTnct); |
| 132179 | | - pOp->opcode = OP_Null; |
| 132180 | | - pOp->p1 = 1; |
| 132181 | | - pOp->p2 = regPrev; |
| 132182 | | - pOp = 0; /* Ensure pOp is not used after sqlite3VdbeAddOp() */ |
| 132183 | | - |
| 132184 | | - iJump = sqlite3VdbeCurrentAddr(v) + nResultCol; |
| 132185 | | - for(i=0; i<nResultCol; i++){ |
| 132186 | | - CollSeq *pColl = sqlite3ExprCollSeq(pParse, p->pEList->a[i].pExpr); |
| 132187 | | - if( i<nResultCol-1 ){ |
| 132188 | | - sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i); |
| 132189 | | - VdbeCoverage(v); |
| 132190 | | - }else{ |
| 132191 | | - sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i); |
| 132192 | | - VdbeCoverage(v); |
| 132193 | | - } |
| 132194 | | - sqlite3VdbeChangeP4(v, -1, (const char *)pColl, P4_COLLSEQ); |
| 132195 | | - sqlite3VdbeChangeP5(v, SQLITE_NULLEQ); |
| 132196 | | - } |
| 132197 | | - assert( sqlite3VdbeCurrentAddr(v)==iJump || pParse->db->mallocFailed ); |
| 132198 | | - sqlite3VdbeAddOp3(v, OP_Copy, regResult, regPrev, nResultCol-1); |
| 132199 | | - break; |
| 132200 | | - } |
| 132201 | | - |
| 132202 | | - case WHERE_DISTINCT_UNIQUE: { |
| 132203 | | - sqlite3VdbeChangeToNoop(v, pDistinct->addrTnct); |
| 132204 | | - break; |
| 132205 | | - } |
| 132206 | | - |
| 132207 | | - default: { |
| 132208 | | - assert( pDistinct->eTnctType==WHERE_DISTINCT_UNORDERED ); |
| 132209 | | - codeDistinct(pParse, pDistinct->tabTnct, iContinue, nResultCol, |
| 132210 | | - regResult); |
| 132211 | | - break; |
| 132212 | | - } |
| 132213 | | - } |
| 132574 | + int eType = pDistinct->eTnctType; |
| 132575 | + int iTab = pDistinct->tabTnct; |
| 132576 | + assert( nResultCol==p->pEList->nExpr ); |
| 132577 | + iTab = codeDistinct(pParse, eType, iTab, iContinue, p->pEList, regResult); |
| 132578 | + fixDistinctOpenEph(pParse, eType, iTab, pDistinct->addrTnct); |
| 132214 | 132579 | if( pSort==0 ){ |
| 132215 | 132580 | codeOffset(v, p->iOffset, iContinue); |
| 132216 | 132581 | } |
| 132217 | 132582 | } |
| 132218 | 132583 | |
| | @@ -132874,11 +133239,17 @@ |
| 132874 | 133239 | if( pS ){ |
| 132875 | 133240 | /* The "table" is actually a sub-select or a view in the FROM clause |
| 132876 | 133241 | ** of the SELECT statement. Return the declaration type and origin |
| 132877 | 133242 | ** data for the result-set column of the sub-select. |
| 132878 | 133243 | */ |
| 132879 | | - if( iCol>=0 && iCol<pS->pEList->nExpr ){ |
| 133244 | + if( iCol<pS->pEList->nExpr |
| 133245 | +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW |
| 133246 | + && iCol>=0 |
| 133247 | +#else |
| 133248 | + && ALWAYS(iCol>=0) |
| 133249 | +#endif |
| 133250 | + ){ |
| 132880 | 133251 | /* If iCol is less than zero, then the expression requests the |
| 132881 | 133252 | ** rowid of the sub-select or view. This expression is legal (see |
| 132882 | 133253 | ** test case misc2.2.2) - it always evaluates to NULL. |
| 132883 | 133254 | */ |
| 132884 | 133255 | NameContext sNC; |
| | @@ -133804,11 +134175,11 @@ |
| 133804 | 134175 | /* Generate code for the left and right SELECT statements. |
| 133805 | 134176 | */ |
| 133806 | 134177 | switch( p->op ){ |
| 133807 | 134178 | case TK_ALL: { |
| 133808 | 134179 | int addr = 0; |
| 133809 | | - int nLimit; |
| 134180 | + int nLimit = 0; /* Initialize to suppress harmless compiler warning */ |
| 133810 | 134181 | assert( !pPrior->pLimit ); |
| 133811 | 134182 | pPrior->iLimit = p->iLimit; |
| 133812 | 134183 | pPrior->iOffset = p->iOffset; |
| 133813 | 134184 | pPrior->pLimit = p->pLimit; |
| 133814 | 134185 | rc = sqlite3Select(pParse, pPrior, &dest); |
| | @@ -134660,13 +135031,16 @@ |
| 134660 | 135031 | } |
| 134661 | 135032 | if( pExpr->op==TK_COLUMN |
| 134662 | 135033 | && pExpr->iTable==pSubst->iTable |
| 134663 | 135034 | && !ExprHasProperty(pExpr, EP_FixedCol) |
| 134664 | 135035 | ){ |
| 135036 | +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW |
| 134665 | 135037 | if( pExpr->iColumn<0 ){ |
| 134666 | 135038 | pExpr->op = TK_NULL; |
| 134667 | | - }else{ |
| 135039 | + }else |
| 135040 | +#endif |
| 135041 | + { |
| 134668 | 135042 | Expr *pNew; |
| 134669 | 135043 | Expr *pCopy = pSubst->pEList->a[pExpr->iColumn].pExpr; |
| 134670 | 135044 | Expr ifNullRow; |
| 134671 | 135045 | assert( pSubst->pEList!=0 && pExpr->iColumn<pSubst->pEList->nExpr ); |
| 134672 | 135046 | assert( pExpr->pRight==0 ); |
| | @@ -136301,11 +136675,17 @@ |
| 136301 | 136675 | } |
| 136302 | 136676 | while( pSel->pPrior ){ pSel = pSel->pPrior; } |
| 136303 | 136677 | sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol); |
| 136304 | 136678 | pTab->iPKey = -1; |
| 136305 | 136679 | pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) ); |
| 136306 | | - pTab->tabFlags |= TF_Ephemeral; |
| 136680 | +#ifndef SQLITE_ALLOW_ROWID_IN_VIEW |
| 136681 | + /* The usual case - do not allow ROWID on a subquery */ |
| 136682 | + pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid; |
| 136683 | +#else |
| 136684 | + pTab->tabFlags |= TF_Ephemeral; /* Legacy compatibility mode */ |
| 136685 | +#endif |
| 136686 | + |
| 136307 | 136687 | |
| 136308 | 136688 | return pParse->nErr ? SQLITE_ERROR : SQLITE_OK; |
| 136309 | 136689 | } |
| 136310 | 136690 | |
| 136311 | 136691 | /* |
| | @@ -136788,12 +137168,14 @@ |
| 136788 | 137168 | sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one " |
| 136789 | 137169 | "argument"); |
| 136790 | 137170 | pFunc->iDistinct = -1; |
| 136791 | 137171 | }else{ |
| 136792 | 137172 | KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pE->x.pList,0,0); |
| 136793 | | - sqlite3VdbeAddOp4(v, OP_OpenEphemeral, pFunc->iDistinct, 0, 0, |
| 136794 | | - (char*)pKeyInfo, P4_KEYINFO); |
| 137173 | + pFunc->iDistAddr = sqlite3VdbeAddOp4(v, OP_OpenEphemeral, |
| 137174 | + pFunc->iDistinct, 0, 0, (char*)pKeyInfo, P4_KEYINFO); |
| 137175 | + ExplainQueryPlan((pParse, 0, "USE TEMP B-TREE FOR %s(DISTINCT)", |
| 137176 | + pFunc->pFunc->zName)); |
| 136795 | 137177 | } |
| 136796 | 137178 | } |
| 136797 | 137179 | } |
| 136798 | 137180 | } |
| 136799 | 137181 | |
| | @@ -136821,11 +137203,16 @@ |
| 136821 | 137203 | ** If regAcc is non-zero and there are no min() or max() aggregates |
| 136822 | 137204 | ** in pAggInfo, then only populate the pAggInfo->nAccumulator accumulator |
| 136823 | 137205 | ** registers if register regAcc contains 0. The caller will take care |
| 136824 | 137206 | ** of setting and clearing regAcc. |
| 136825 | 137207 | */ |
| 136826 | | -static void updateAccumulator(Parse *pParse, int regAcc, AggInfo *pAggInfo){ |
| 137208 | +static void updateAccumulator( |
| 137209 | + Parse *pParse, |
| 137210 | + int regAcc, |
| 137211 | + AggInfo *pAggInfo, |
| 137212 | + int eDistinctType |
| 137213 | +){ |
| 136827 | 137214 | Vdbe *v = pParse->pVdbe; |
| 136828 | 137215 | int i; |
| 136829 | 137216 | int regHit = 0; |
| 136830 | 137217 | int addrHitTest = 0; |
| 136831 | 137218 | struct AggInfo_func *pF; |
| | @@ -136867,17 +137254,16 @@ |
| 136867 | 137254 | sqlite3ExprCodeExprList(pParse, pList, regAgg, 0, SQLITE_ECEL_DUP); |
| 136868 | 137255 | }else{ |
| 136869 | 137256 | nArg = 0; |
| 136870 | 137257 | regAgg = 0; |
| 136871 | 137258 | } |
| 136872 | | - if( pF->iDistinct>=0 ){ |
| 137259 | + if( pF->iDistinct>=0 && pList ){ |
| 136873 | 137260 | if( addrNext==0 ){ |
| 136874 | 137261 | addrNext = sqlite3VdbeMakeLabel(pParse); |
| 136875 | 137262 | } |
| 136876 | | - testcase( nArg==0 ); /* Error condition */ |
| 136877 | | - testcase( nArg>1 ); /* Also an error */ |
| 136878 | | - codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg); |
| 137263 | + pF->iDistinct = codeDistinct(pParse, eDistinctType, |
| 137264 | + pF->iDistinct, addrNext, pList, regAgg); |
| 136879 | 137265 | } |
| 136880 | 137266 | if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| 136881 | 137267 | CollSeq *pColl = 0; |
| 136882 | 137268 | struct ExprList_item *pItem; |
| 136883 | 137269 | int j; |
| | @@ -136925,11 +137311,11 @@ |
| 136925 | 137311 | Table *pTab, /* Table being queried */ |
| 136926 | 137312 | Index *pIdx /* Index used to optimize scan, or NULL */ |
| 136927 | 137313 | ){ |
| 136928 | 137314 | if( pParse->explain==2 ){ |
| 136929 | 137315 | int bCover = (pIdx!=0 && (HasRowid(pTab) || !IsPrimaryKeyIndex(pIdx))); |
| 136930 | | - sqlite3VdbeExplain(pParse, 0, "SCAN TABLE %s%s%s", |
| 137316 | + sqlite3VdbeExplain(pParse, 0, "SCAN %s%s%s", |
| 136931 | 137317 | pTab->zName, |
| 136932 | 137318 | bCover ? " USING COVERING INDEX " : "", |
| 136933 | 137319 | bCover ? pIdx->zName : "" |
| 136934 | 137320 | ); |
| 136935 | 137321 | } |
| | @@ -137498,14 +137884,14 @@ |
| 137498 | 137884 | */ |
| 137499 | 137885 | int addrTop = sqlite3VdbeCurrentAddr(v)+1; |
| 137500 | 137886 | |
| 137501 | 137887 | pItem->regReturn = ++pParse->nMem; |
| 137502 | 137888 | sqlite3VdbeAddOp3(v, OP_InitCoroutine, pItem->regReturn, 0, addrTop); |
| 137503 | | - VdbeComment((v, "%s", pItem->pTab->zName)); |
| 137889 | + VdbeComment((v, "%!S", pItem)); |
| 137504 | 137890 | pItem->addrFillSub = addrTop; |
| 137505 | 137891 | sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn); |
| 137506 | | - ExplainQueryPlan((pParse, 1, "CO-ROUTINE %u", pSub->selId)); |
| 137892 | + ExplainQueryPlan((pParse, 1, "CO-ROUTINE %!S", pItem)); |
| 137507 | 137893 | sqlite3Select(pParse, pSub, &dest); |
| 137508 | 137894 | pItem->pTab->nRowLogEst = pSub->nSelectRow; |
| 137509 | 137895 | pItem->fg.viaCoroutine = 1; |
| 137510 | 137896 | pItem->regResult = dest.iSdst; |
| 137511 | 137897 | sqlite3VdbeEndCoroutine(v, pItem->regReturn); |
| | @@ -137545,21 +137931,21 @@ |
| 137545 | 137931 | if( pItem->fg.isCorrelated==0 ){ |
| 137546 | 137932 | /* If the subquery is not correlated and if we are not inside of |
| 137547 | 137933 | ** a trigger, then we only need to compute the value of the subquery |
| 137548 | 137934 | ** once. */ |
| 137549 | 137935 | onceAddr = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v); |
| 137550 | | - VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName)); |
| 137936 | + VdbeComment((v, "materialize %!S", pItem)); |
| 137551 | 137937 | }else{ |
| 137552 | | - VdbeNoopComment((v, "materialize \"%s\"", pItem->pTab->zName)); |
| 137938 | + VdbeNoopComment((v, "materialize %!S", pItem)); |
| 137553 | 137939 | } |
| 137554 | 137940 | sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor); |
| 137555 | | - ExplainQueryPlan((pParse, 1, "MATERIALIZE %u", pSub->selId)); |
| 137941 | + ExplainQueryPlan((pParse, 1, "MATERIALIZE %!S", pItem)); |
| 137556 | 137942 | sqlite3Select(pParse, pSub, &dest); |
| 137557 | 137943 | pItem->pTab->nRowLogEst = pSub->nSelectRow; |
| 137558 | 137944 | if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr); |
| 137559 | 137945 | retAddr = sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn); |
| 137560 | | - VdbeComment((v, "end %s", pItem->pTab->zName)); |
| 137946 | + VdbeComment((v, "end %!S", pItem)); |
| 137561 | 137947 | sqlite3VdbeChangeP1(v, topAddr, retAddr); |
| 137562 | 137948 | sqlite3ClearTempRegCache(pParse); |
| 137563 | 137949 | if( pItem->fg.isCte && pItem->fg.isCorrelated==0 ){ |
| 137564 | 137950 | CteUse *pCteUse = pItem->u2.pCteUse; |
| 137565 | 137951 | pCteUse->addrM9e = pItem->addrFillSub; |
| | @@ -137905,10 +138291,24 @@ |
| 137905 | 138291 | int addrSetAbort; /* Set the abort flag and return */ |
| 137906 | 138292 | int addrTopOfLoop; /* Top of the input loop */ |
| 137907 | 138293 | int addrSortingIdx; /* The OP_OpenEphemeral for the sorting index */ |
| 137908 | 138294 | int addrReset; /* Subroutine for resetting the accumulator */ |
| 137909 | 138295 | int regReset; /* Return address register for reset subroutine */ |
| 138296 | + ExprList *pDistinct = 0; |
| 138297 | + u16 distFlag = 0; |
| 138298 | + int eDist = WHERE_DISTINCT_NOOP; |
| 138299 | + |
| 138300 | + if( pAggInfo->nFunc==1 |
| 138301 | + && pAggInfo->aFunc[0].iDistinct>=0 |
| 138302 | + && pAggInfo->aFunc[0].pFExpr->x.pList |
| 138303 | + ){ |
| 138304 | + Expr *pExpr = pAggInfo->aFunc[0].pFExpr->x.pList->a[0].pExpr; |
| 138305 | + pExpr = sqlite3ExprDup(db, pExpr, 0); |
| 138306 | + pDistinct = sqlite3ExprListDup(db, pGroupBy, 0); |
| 138307 | + pDistinct = sqlite3ExprListAppend(pParse, pDistinct, pExpr); |
| 138308 | + distFlag = pDistinct ? (WHERE_WANT_DISTINCT|WHERE_AGG_DISTINCT) : 0; |
| 138309 | + } |
| 137910 | 138310 | |
| 137911 | 138311 | /* If there is a GROUP BY clause we might need a sorting index to |
| 137912 | 138312 | ** implement it. Allocate that sorting index now. If it turns out |
| 137913 | 138313 | ** that we do not need it after all, the OP_SorterOpen instruction |
| 137914 | 138314 | ** will be converted into a Noop. |
| | @@ -137941,14 +138341,16 @@ |
| 137941 | 138341 | ** it might be a single loop that uses an index to extract information |
| 137942 | 138342 | ** in the right order to begin with. |
| 137943 | 138343 | */ |
| 137944 | 138344 | sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset); |
| 137945 | 138345 | SELECTTRACE(1,pParse,p,("WhereBegin\n")); |
| 137946 | | - pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, 0, |
| 137947 | | - WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0), 0 |
| 138346 | + pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, pDistinct, |
| 138347 | + WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0 |
| 137948 | 138348 | ); |
| 138349 | + sqlite3ExprListDelete(db, pDistinct); |
| 137949 | 138350 | if( pWInfo==0 ) goto select_end; |
| 138351 | + eDist = sqlite3WhereIsDistinct(pWInfo); |
| 137950 | 138352 | SELECTTRACE(1,pParse,p,("WhereBegin returns\n")); |
| 137951 | 138353 | if( sqlite3WhereIsOrdered(pWInfo)==pGroupBy->nExpr ){ |
| 137952 | 138354 | /* The optimizer is able to deliver rows in group by order so |
| 137953 | 138355 | ** we do not have to sort. The OP_OpenEphemeral table will be |
| 137954 | 138356 | ** cancelled later because we still need to use the pKeyInfo |
| | @@ -138062,11 +138464,11 @@ |
| 138062 | 138464 | |
| 138063 | 138465 | /* Update the aggregate accumulators based on the content of |
| 138064 | 138466 | ** the current row |
| 138065 | 138467 | */ |
| 138066 | 138468 | sqlite3VdbeJumpHere(v, addr1); |
| 138067 | | - updateAccumulator(pParse, iUseFlag, pAggInfo); |
| 138469 | + updateAccumulator(pParse, iUseFlag, pAggInfo, eDist); |
| 138068 | 138470 | sqlite3VdbeAddOp2(v, OP_Integer, 1, iUseFlag); |
| 138069 | 138471 | VdbeComment((v, "indicate data in accumulator")); |
| 138070 | 138472 | |
| 138071 | 138473 | /* End of the loop |
| 138072 | 138474 | */ |
| | @@ -138119,10 +138521,14 @@ |
| 138119 | 138521 | resetAccumulator(pParse, pAggInfo); |
| 138120 | 138522 | sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag); |
| 138121 | 138523 | VdbeComment((v, "indicate accumulator empty")); |
| 138122 | 138524 | sqlite3VdbeAddOp1(v, OP_Return, regReset); |
| 138123 | 138525 | |
| 138526 | + if( eDist!=WHERE_DISTINCT_NOOP ){ |
| 138527 | + struct AggInfo_func *pF = &pAggInfo->aFunc[0]; |
| 138528 | + fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr); |
| 138529 | + } |
| 138124 | 138530 | } /* endif pGroupBy. Begin aggregate queries without GROUP BY: */ |
| 138125 | 138531 | else { |
| 138126 | 138532 | Table *pTab; |
| 138127 | 138533 | if( (pTab = isSimpleCount(p, pAggInfo))!=0 ){ |
| 138128 | 138534 | /* If isSimpleCount() returns a pointer to a Table structure, then |
| | @@ -138182,10 +138588,13 @@ |
| 138182 | 138588 | sqlite3VdbeAddOp2(v, OP_Count, iCsr, pAggInfo->aFunc[0].iMem); |
| 138183 | 138589 | sqlite3VdbeAddOp1(v, OP_Close, iCsr); |
| 138184 | 138590 | explainSimpleCount(pParse, pTab, pBest); |
| 138185 | 138591 | }else{ |
| 138186 | 138592 | int regAcc = 0; /* "populate accumulators" flag */ |
| 138593 | + ExprList *pDistinct = 0; |
| 138594 | + u16 distFlag = 0; |
| 138595 | + int eDist; |
| 138187 | 138596 | |
| 138188 | 138597 | /* If there are accumulator registers but no min() or max() functions |
| 138189 | 138598 | ** without FILTER clauses, allocate register regAcc. Register regAcc |
| 138190 | 138599 | ** will contain 0 the first time the inner loop runs, and 1 thereafter. |
| 138191 | 138600 | ** The code generated by updateAccumulator() uses this to ensure |
| | @@ -138205,10 +138614,13 @@ |
| 138205 | 138614 | } |
| 138206 | 138615 | if( i==pAggInfo->nFunc ){ |
| 138207 | 138616 | regAcc = ++pParse->nMem; |
| 138208 | 138617 | sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc); |
| 138209 | 138618 | } |
| 138619 | + }else if( pAggInfo->nFunc==1 && pAggInfo->aFunc[0].iDistinct>=0 ){ |
| 138620 | + pDistinct = pAggInfo->aFunc[0].pFExpr->x.pList; |
| 138621 | + distFlag = pDistinct ? (WHERE_WANT_DISTINCT|WHERE_AGG_DISTINCT) : 0; |
| 138210 | 138622 | } |
| 138211 | 138623 | |
| 138212 | 138624 | /* This case runs if the aggregate has no GROUP BY clause. The |
| 138213 | 138625 | ** processing is much simpler since there is only a single row |
| 138214 | 138626 | ** of output. |
| | @@ -138224,16 +138636,22 @@ |
| 138224 | 138636 | assert( minMaxFlag==WHERE_ORDERBY_NORMAL || pMinMaxOrderBy!=0 ); |
| 138225 | 138637 | assert( pMinMaxOrderBy==0 || pMinMaxOrderBy->nExpr==1 ); |
| 138226 | 138638 | |
| 138227 | 138639 | SELECTTRACE(1,pParse,p,("WhereBegin\n")); |
| 138228 | 138640 | pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy, |
| 138229 | | - 0, minMaxFlag, 0); |
| 138641 | + pDistinct, minMaxFlag|distFlag, 0); |
| 138230 | 138642 | if( pWInfo==0 ){ |
| 138231 | 138643 | goto select_end; |
| 138232 | 138644 | } |
| 138233 | 138645 | SELECTTRACE(1,pParse,p,("WhereBegin returns\n")); |
| 138234 | | - updateAccumulator(pParse, regAcc, pAggInfo); |
| 138646 | + eDist = sqlite3WhereIsDistinct(pWInfo); |
| 138647 | + updateAccumulator(pParse, regAcc, pAggInfo, eDist); |
| 138648 | + if( eDist!=WHERE_DISTINCT_NOOP ){ |
| 138649 | + struct AggInfo_func *pF = &pAggInfo->aFunc[0]; |
| 138650 | + fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr); |
| 138651 | + } |
| 138652 | + |
| 138235 | 138653 | if( regAcc ) sqlite3VdbeAddOp2(v, OP_Integer, 1, regAcc); |
| 138236 | 138654 | if( minMaxFlag ){ |
| 138237 | 138655 | sqlite3WhereMinMaxOptEarlyOut(v, pWInfo); |
| 138238 | 138656 | } |
| 138239 | 138657 | SELECTTRACE(1,pParse,p,("WhereEnd\n")); |
| | @@ -138576,11 +138994,15 @@ |
| 138576 | 138994 | if( pTrig->pTabSchema==pTab->pSchema |
| 138577 | 138995 | && 0==sqlite3StrICmp(pTrig->table, pTab->zName) |
| 138578 | 138996 | ){ |
| 138579 | 138997 | pTrig->pNext = pList; |
| 138580 | 138998 | pList = pTrig; |
| 138581 | | - }else if( pTrig->op==TK_RETURNING ){ |
| 138999 | + }else if( pTrig->op==TK_RETURNING |
| 139000 | +#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 139001 | + && pParse->db->pVtabCtx==0 |
| 139002 | +#endif |
| 139003 | + ){ |
| 138582 | 139004 | assert( pParse->bReturning ); |
| 138583 | 139005 | assert( &(pParse->u1.pReturning->retTrig) == pTrig ); |
| 138584 | 139006 | pTrig->table = pTab->zName; |
| 138585 | 139007 | pTrig->pTabSchema = pTab->pSchema; |
| 138586 | 139008 | pTrig->pNext = pList; |
| | @@ -138716,16 +139138,16 @@ |
| 138716 | 139138 | /* INSTEAD of triggers are only for views and views only support INSTEAD |
| 138717 | 139139 | ** of triggers. |
| 138718 | 139140 | */ |
| 138719 | 139141 | if( pTab->pSelect && tr_tm!=TK_INSTEAD ){ |
| 138720 | 139142 | sqlite3ErrorMsg(pParse, "cannot create %s trigger on view: %S", |
| 138721 | | - (tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName, 0); |
| 139143 | + (tr_tm == TK_BEFORE)?"BEFORE":"AFTER", pTableName->a); |
| 138722 | 139144 | goto trigger_orphan_error; |
| 138723 | 139145 | } |
| 138724 | 139146 | if( !pTab->pSelect && tr_tm==TK_INSTEAD ){ |
| 138725 | 139147 | sqlite3ErrorMsg(pParse, "cannot create INSTEAD OF" |
| 138726 | | - " trigger on table: %S", pTableName, 0); |
| 139148 | + " trigger on table: %S", pTableName->a); |
| 138727 | 139149 | goto trigger_orphan_error; |
| 138728 | 139150 | } |
| 138729 | 139151 | |
| 138730 | 139152 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 138731 | 139153 | if( !IN_RENAME_OBJECT ){ |
| | @@ -139118,11 +139540,11 @@ |
| 139118 | 139540 | pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName); |
| 139119 | 139541 | if( pTrigger ) break; |
| 139120 | 139542 | } |
| 139121 | 139543 | if( !pTrigger ){ |
| 139122 | 139544 | if( !noErr ){ |
| 139123 | | - sqlite3ErrorMsg(pParse, "no such trigger: %S", pName, 0); |
| 139545 | + sqlite3ErrorMsg(pParse, "no such trigger: %S", pName->a); |
| 139124 | 139546 | }else{ |
| 139125 | 139547 | sqlite3CodeVerifyNamedSchema(pParse, zDb); |
| 139126 | 139548 | } |
| 139127 | 139549 | pParse->checkSchema = 1; |
| 139128 | 139550 | goto drop_trigger_cleanup; |
| | @@ -139650,12 +140072,12 @@ |
| 139650 | 140072 | /* If one was specified, code the WHEN clause. If it evaluates to false |
| 139651 | 140073 | ** (or NULL) the sub-vdbe is immediately halted by jumping to the |
| 139652 | 140074 | ** OP_Halt inserted at the end of the program. */ |
| 139653 | 140075 | if( pTrigger->pWhen ){ |
| 139654 | 140076 | pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0); |
| 139655 | | - if( SQLITE_OK==sqlite3ResolveExprNames(&sNC, pWhen) |
| 139656 | | - && db->mallocFailed==0 |
| 140077 | + if( db->mallocFailed==0 |
| 140078 | + && SQLITE_OK==sqlite3ResolveExprNames(&sNC, pWhen) |
| 139657 | 140079 | ){ |
| 139658 | 140080 | iEndTrigger = sqlite3VdbeMakeLabel(pSubParse); |
| 139659 | 140081 | sqlite3ExprIfFalse(pSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL); |
| 139660 | 140082 | } |
| 139661 | 140083 | sqlite3ExprDelete(db, pWhen); |
| | @@ -140709,11 +141131,16 @@ |
| 140709 | 141131 | } |
| 140710 | 141132 | } |
| 140711 | 141133 | |
| 140712 | 141134 | /* Top of the update loop */ |
| 140713 | 141135 | if( eOnePass!=ONEPASS_OFF ){ |
| 140714 | | - if( !isView && aiCurOnePass[0]!=iDataCur && aiCurOnePass[1]!=iDataCur ){ |
| 141136 | + if( aiCurOnePass[0]!=iDataCur |
| 141137 | + && aiCurOnePass[1]!=iDataCur |
| 141138 | +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW |
| 141139 | + && !isView |
| 141140 | +#endif |
| 141141 | + ){ |
| 140715 | 141142 | assert( pPk ); |
| 140716 | 141143 | sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey,nKey); |
| 140717 | 141144 | VdbeCoverage(v); |
| 140718 | 141145 | } |
| 140719 | 141146 | if( eOnePass!=ONEPASS_SINGLE ){ |
| | @@ -144040,20 +144467,12 @@ |
| 144040 | 144467 | isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0 |
| 144041 | 144468 | || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0)) |
| 144042 | 144469 | || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX)); |
| 144043 | 144470 | |
| 144044 | 144471 | sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH); |
| 144045 | | - sqlite3_str_appendall(&str, isSearch ? "SEARCH" : "SCAN"); |
| 144046 | | - if( pItem->pSelect ){ |
| 144047 | | - sqlite3_str_appendf(&str, " SUBQUERY %u", pItem->pSelect->selId); |
| 144048 | | - }else{ |
| 144049 | | - sqlite3_str_appendf(&str, " TABLE %s", pItem->zName); |
| 144050 | | - } |
| 144051 | | - |
| 144052 | | - if( pItem->zAlias ){ |
| 144053 | | - sqlite3_str_appendf(&str, " AS %s", pItem->zAlias); |
| 144054 | | - } |
| 144472 | + str.printfFlags = SQLITE_PRINTF_INTERNAL; |
| 144473 | + sqlite3_str_appendf(&str, "%s %S", isSearch ? "SEARCH" : "SCAN", pItem); |
| 144055 | 144474 | if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){ |
| 144056 | 144475 | const char *zFmt = 0; |
| 144057 | 144476 | Index *pIdx; |
| 144058 | 144477 | |
| 144059 | 144478 | assert( pLoop->u.btree.pIndex!=0 ); |
| | @@ -146348,10 +146767,11 @@ |
| 146348 | 146767 | testcase( pAlt->eOperator & WO_IN ); |
| 146349 | 146768 | VdbeModuleComment((v, "begin transitive constraint")); |
| 146350 | 146769 | sEAlt = *pAlt->pExpr; |
| 146351 | 146770 | sEAlt.pLeft = pE->pLeft; |
| 146352 | 146771 | sqlite3ExprIfFalse(pParse, &sEAlt, addrCont, SQLITE_JUMPIFNULL); |
| 146772 | + pAlt->wtFlags |= TERM_CODED; |
| 146353 | 146773 | } |
| 146354 | 146774 | |
| 146355 | 146775 | /* For a LEFT OUTER JOIN, generate code that will record the fact that |
| 146356 | 146776 | ** at least one row of the right table has matched the left table. |
| 146357 | 146777 | */ |
| | @@ -148784,11 +149204,11 @@ |
| 148784 | 149204 | const char *zColl = pIdx->azColl[iCol]; |
| 148785 | 149205 | |
| 148786 | 149206 | for(i=0; i<pList->nExpr; i++){ |
| 148787 | 149207 | Expr *p = sqlite3ExprSkipCollateAndLikely(pList->a[i].pExpr); |
| 148788 | 149208 | if( ALWAYS(p!=0) |
| 148789 | | - && p->op==TK_COLUMN |
| 149209 | + && (p->op==TK_COLUMN || p->op==TK_AGG_COLUMN) |
| 148790 | 149210 | && p->iColumn==pIdx->aiColumn[iCol] |
| 148791 | 149211 | && p->iTable==iBase |
| 148792 | 149212 | ){ |
| 148793 | 149213 | CollSeq *pColl = sqlite3ExprNNCollSeq(pParse, pList->a[i].pExpr); |
| 148794 | 149214 | if( 0==sqlite3StrICmp(pColl->zName, zColl) ){ |
| | @@ -148849,11 +149269,12 @@ |
| 148849 | 149269 | ** current SELECT is a correlated sub-query. |
| 148850 | 149270 | */ |
| 148851 | 149271 | for(i=0; i<pDistinct->nExpr; i++){ |
| 148852 | 149272 | Expr *p = sqlite3ExprSkipCollateAndLikely(pDistinct->a[i].pExpr); |
| 148853 | 149273 | if( NEVER(p==0) ) continue; |
| 148854 | | - if( p->op==TK_COLUMN && p->iTable==iBase && p->iColumn<0 ) return 1; |
| 149274 | + if( p->op!=TK_COLUMN && p->op!=TK_AGG_COLUMN ) continue; |
| 149275 | + if( p->iTable==iBase && p->iColumn<0 ) return 1; |
| 148855 | 149276 | } |
| 148856 | 149277 | |
| 148857 | 149278 | /* Loop through all indices on the table, checking each to see if it makes |
| 148858 | 149279 | ** the DISTINCT qualifier redundant. It does so if: |
| 148859 | 149280 | ** |
| | @@ -148867,10 +149288,11 @@ |
| 148867 | 149288 | ** 3. All of those index columns for which the WHERE clause does not |
| 148868 | 149289 | ** contain a "col=X" term are subject to a NOT NULL constraint. |
| 148869 | 149290 | */ |
| 148870 | 149291 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 148871 | 149292 | if( !IsUniqueIndex(pIdx) ) continue; |
| 149293 | + if( pIdx->pPartIdxWhere ) continue; |
| 148872 | 149294 | for(i=0; i<pIdx->nKeyCol; i++){ |
| 148873 | 149295 | if( 0==sqlite3WhereFindTerm(pWC, iBase, i, ~(Bitmask)0, WO_EQ, pIdx) ){ |
| 148874 | 149296 | if( findIndexCol(pParse, pDistinct, iBase, pIdx, i)<0 ) break; |
| 148875 | 149297 | if( indexColumnNotNull(pIdx, i)==0 ) break; |
| 148876 | 149298 | } |
| | @@ -148921,18 +149343,18 @@ |
| 148921 | 149343 | pOp->opcode = OP_Copy; |
| 148922 | 149344 | pOp->p1 = pOp->p2 + iRegister; |
| 148923 | 149345 | pOp->p2 = pOp->p3; |
| 148924 | 149346 | pOp->p3 = 0; |
| 148925 | 149347 | }else if( pOp->opcode==OP_Rowid ){ |
| 148926 | | - if( iAutoidxCur ){ |
| 148927 | | - pOp->opcode = OP_Sequence; |
| 148928 | | - pOp->p1 = iAutoidxCur; |
| 148929 | | - }else{ |
| 149348 | + pOp->opcode = OP_Sequence; |
| 149349 | + pOp->p1 = iAutoidxCur; |
| 149350 | +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW |
| 149351 | + if( iAutoidxCur==0 ){ |
| 148930 | 149352 | pOp->opcode = OP_Null; |
| 148931 | | - pOp->p1 = 0; |
| 148932 | 149353 | pOp->p3 = 0; |
| 148933 | 149354 | } |
| 149355 | +#endif |
| 148934 | 149356 | } |
| 148935 | 149357 | } |
| 148936 | 149358 | } |
| 148937 | 149359 | |
| 148938 | 149360 | /* |
| | @@ -149093,11 +149515,11 @@ |
| 149093 | 149515 | pLoop->aLTerm[nKeyCol++] = pTerm; |
| 149094 | 149516 | idxCols |= cMask; |
| 149095 | 149517 | } |
| 149096 | 149518 | } |
| 149097 | 149519 | } |
| 149098 | | - assert( nKeyCol>0 ); |
| 149520 | + assert( nKeyCol>0 || pParse->db->mallocFailed ); |
| 149099 | 149521 | pLoop->u.btree.nEq = pLoop->nLTerm = nKeyCol; |
| 149100 | 149522 | pLoop->wsFlags = WHERE_COLUMN_EQ | WHERE_IDX_ONLY | WHERE_INDEXED |
| 149101 | 149523 | | WHERE_AUTO_INDEX; |
| 149102 | 149524 | |
| 149103 | 149525 | /* Count the number of additional columns needed to create a |
| | @@ -152114,11 +152536,11 @@ |
| 152114 | 152536 | */ |
| 152115 | 152537 | for(i=0; i<nOrderBy; i++){ |
| 152116 | 152538 | if( MASKBIT(i) & obSat ) continue; |
| 152117 | 152539 | pOBExpr = sqlite3ExprSkipCollateAndLikely(pOrderBy->a[i].pExpr); |
| 152118 | 152540 | if( NEVER(pOBExpr==0) ) continue; |
| 152119 | | - if( pOBExpr->op!=TK_COLUMN ) continue; |
| 152541 | + if( pOBExpr->op!=TK_COLUMN && pOBExpr->op!=TK_AGG_COLUMN ) continue; |
| 152120 | 152542 | if( pOBExpr->iTable!=iCur ) continue; |
| 152121 | 152543 | pTerm = sqlite3WhereFindTerm(&pWInfo->sWC, iCur, pOBExpr->iColumn, |
| 152122 | 152544 | ~ready, eqOpMask, 0); |
| 152123 | 152545 | if( pTerm==0 ) continue; |
| 152124 | 152546 | if( pTerm->eOperator==WO_IN ){ |
| | @@ -152243,11 +152665,11 @@ |
| 152243 | 152665 | testcase( wctrlFlags & WHERE_GROUPBY ); |
| 152244 | 152666 | testcase( wctrlFlags & WHERE_DISTINCTBY ); |
| 152245 | 152667 | if( NEVER(pOBExpr==0) ) continue; |
| 152246 | 152668 | if( (wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY))==0 ) bOnce = 0; |
| 152247 | 152669 | if( iColumn>=XN_ROWID ){ |
| 152248 | | - if( pOBExpr->op!=TK_COLUMN ) continue; |
| 152670 | + if( pOBExpr->op!=TK_COLUMN && pOBExpr->op!=TK_AGG_COLUMN ) continue; |
| 152249 | 152671 | if( pOBExpr->iTable!=iCur ) continue; |
| 152250 | 152672 | if( pOBExpr->iColumn!=iColumn ) continue; |
| 152251 | 152673 | }else{ |
| 152252 | 152674 | Expr *pIdxExpr = pIndex->aColExpr->a[j].pExpr; |
| 152253 | 152675 | if( sqlite3ExprCompareSkip(pOBExpr, pIdxExpr, iCur) ){ |
| | @@ -153344,11 +153766,12 @@ |
| 153344 | 153766 | ** LEFT JOIN t2 |
| 153345 | 153767 | ** LEFT JOIN t3 ON (t1.ipk=t3.ipk) |
| 153346 | 153768 | */ |
| 153347 | 153769 | notReady = ~(Bitmask)0; |
| 153348 | 153770 | if( pWInfo->nLevel>=2 |
| 153349 | | - && pResultSet!=0 /* guarantees condition (1) above */ |
| 153771 | + && pResultSet!=0 /* these two combine to guarantee */ |
| 153772 | + && 0==(wctrlFlags & WHERE_AGG_DISTINCT) /* condition (1) above */ |
| 153350 | 153773 | && OptimizationEnabled(db, SQLITE_OmitNoopJoin) |
| 153351 | 153774 | ){ |
| 153352 | 153775 | int i; |
| 153353 | 153776 | Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet); |
| 153354 | 153777 | if( sWLB.pOrderBy ){ |
| | @@ -153857,11 +154280,11 @@ |
| 153857 | 154280 | assert( pOp->opcode!=OP_Rowid || pOp->p1!=pLevel->iTabCur ); |
| 153858 | 154281 | assert( pOp->opcode!=OP_IfNullRow || pOp->p1!=pLevel->iTabCur ); |
| 153859 | 154282 | #endif |
| 153860 | 154283 | pOp = sqlite3VdbeGetOp(v, k); |
| 153861 | 154284 | pLastOp = pOp + (last - k); |
| 153862 | | - assert( pOp<pLastOp || (pParse->nErr>0 && pOp==pLastOp) ); |
| 154285 | + assert( pOp<=pLastOp ); |
| 153863 | 154286 | do{ |
| 153864 | 154287 | if( pOp->p1!=pLevel->iTabCur ){ |
| 153865 | 154288 | /* no-op */ |
| 153866 | 154289 | }else if( pOp->opcode==OP_Column |
| 153867 | 154290 | #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC |
| | @@ -154709,10 +155132,11 @@ |
| 154709 | 155132 | /* no break */ deliberate_fall_through |
| 154710 | 155133 | |
| 154711 | 155134 | case TK_AGG_FUNCTION: |
| 154712 | 155135 | case TK_COLUMN: { |
| 154713 | 155136 | int iCol = -1; |
| 155137 | + if( pParse->db->mallocFailed ) return WRC_Abort; |
| 154714 | 155138 | if( p->pSub ){ |
| 154715 | 155139 | int i; |
| 154716 | 155140 | for(i=0; i<p->pSub->nExpr; i++){ |
| 154717 | 155141 | if( 0==sqlite3ExprCompare(0, p->pSub->a[i].pExpr, pExpr, -1) ){ |
| 154718 | 155142 | iCol = i; |
| | @@ -154818,13 +155242,18 @@ |
| 154818 | 155242 | ){ |
| 154819 | 155243 | if( pAppend ){ |
| 154820 | 155244 | int i; |
| 154821 | 155245 | int nInit = pList ? pList->nExpr : 0; |
| 154822 | 155246 | for(i=0; i<pAppend->nExpr; i++){ |
| 154823 | | - Expr *pDup = sqlite3ExprDup(pParse->db, pAppend->a[i].pExpr, 0); |
| 155247 | + sqlite3 *db = pParse->db; |
| 155248 | + Expr *pDup = sqlite3ExprDup(db, pAppend->a[i].pExpr, 0); |
| 154824 | 155249 | assert( pDup==0 || !ExprHasProperty(pDup, EP_MemToken) ); |
| 154825 | | - if( bIntToNull && pDup ){ |
| 155250 | + if( db->mallocFailed ){ |
| 155251 | + sqlite3ExprDelete(db, pDup); |
| 155252 | + break; |
| 155253 | + } |
| 155254 | + if( bIntToNull ){ |
| 154826 | 155255 | int iDummy; |
| 154827 | 155256 | Expr *pSub; |
| 154828 | 155257 | for(pSub=pDup; ExprHasProperty(pSub, EP_Skip); pSub=pSub->pLeft){ |
| 154829 | 155258 | assert( pSub ); |
| 154830 | 155259 | } |
| | @@ -155601,19 +156030,19 @@ |
| 155601 | 156030 | VdbeCoverage(v); |
| 155602 | 156031 | sqlite3ReleaseTempReg(pParse, regTmp); |
| 155603 | 156032 | } |
| 155604 | 156033 | |
| 155605 | 156034 | if( pWin->bExprArgs ){ |
| 155606 | | - int iStart = sqlite3VdbeCurrentAddr(v); |
| 155607 | | - VdbeOp *pOp, *pEnd; |
| 156035 | + int iOp = sqlite3VdbeCurrentAddr(v); |
| 156036 | + int iEnd; |
| 155608 | 156037 | |
| 155609 | 156038 | nArg = pWin->pOwner->x.pList->nExpr; |
| 155610 | 156039 | regArg = sqlite3GetTempRange(pParse, nArg); |
| 155611 | 156040 | sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0); |
| 155612 | 156041 | |
| 155613 | | - pEnd = sqlite3VdbeGetOp(v, -1); |
| 155614 | | - for(pOp=sqlite3VdbeGetOp(v, iStart); pOp<=pEnd; pOp++){ |
| 156042 | + for(iEnd=sqlite3VdbeCurrentAddr(v); iOp<iEnd; iOp++){ |
| 156043 | + VdbeOp *pOp = sqlite3VdbeGetOp(v, iOp); |
| 155615 | 156044 | if( pOp->opcode==OP_Column && pOp->p1==pWin->iEphCsr ){ |
| 155616 | 156045 | pOp->p1 = csr; |
| 155617 | 156046 | } |
| 155618 | 156047 | } |
| 155619 | 156048 | } |
| | @@ -155968,11 +156397,11 @@ |
| 155968 | 156397 | ** is OP_Ge, the generated code is equivalent to: |
| 155969 | 156398 | ** |
| 155970 | 156399 | ** if( csr1.peerVal - regVal <= csr2.peerVal ) goto lbl; |
| 155971 | 156400 | ** |
| 155972 | 156401 | ** A special type of arithmetic is used such that if csr1.peerVal is not |
| 155973 | | -** a numeric type (real or integer), then the result of the addition addition |
| 156402 | +** a numeric type (real or integer), then the result of the addition |
| 155974 | 156403 | ** or subtraction is a a copy of csr1.peerVal. |
| 155975 | 156404 | */ |
| 155976 | 156405 | static void windowCodeRangeTest( |
| 155977 | 156406 | WindowCodeArg *p, |
| 155978 | 156407 | int op, /* OP_Ge, OP_Gt, or OP_Le */ |
| | @@ -155987,11 +156416,16 @@ |
| 155987 | 156416 | int reg1 = sqlite3GetTempReg(pParse); /* Reg. for csr1.peerVal+regVal */ |
| 155988 | 156417 | int reg2 = sqlite3GetTempReg(pParse); /* Reg. for csr2.peerVal */ |
| 155989 | 156418 | int regString = ++pParse->nMem; /* Reg. for constant value '' */ |
| 155990 | 156419 | int arith = OP_Add; /* OP_Add or OP_Subtract */ |
| 155991 | 156420 | int addrGe; /* Jump destination */ |
| 156421 | + int addrDone = sqlite3VdbeMakeLabel(pParse); /* Address past OP_Ge */ |
| 155992 | 156422 | CollSeq *pColl; |
| 156423 | + |
| 156424 | + /* Read the peer-value from each cursor into a register */ |
| 156425 | + windowReadPeerValues(p, csr1, reg1); |
| 156426 | + windowReadPeerValues(p, csr2, reg2); |
| 155993 | 156427 | |
| 155994 | 156428 | assert( op==OP_Ge || op==OP_Gt || op==OP_Le ); |
| 155995 | 156429 | assert( pOrderBy && pOrderBy->nExpr==1 ); |
| 155996 | 156430 | if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){ |
| 155997 | 156431 | switch( op ){ |
| | @@ -156000,38 +156434,15 @@ |
| 156000 | 156434 | default: assert( op==OP_Le ); op = OP_Ge; break; |
| 156001 | 156435 | } |
| 156002 | 156436 | arith = OP_Subtract; |
| 156003 | 156437 | } |
| 156004 | 156438 | |
| 156005 | | - /* Read the peer-value from each cursor into a register */ |
| 156006 | | - windowReadPeerValues(p, csr1, reg1); |
| 156007 | | - windowReadPeerValues(p, csr2, reg2); |
| 156008 | | - |
| 156009 | 156439 | VdbeModuleComment((v, "CodeRangeTest: if( R%d %s R%d %s R%d ) goto lbl", |
| 156010 | 156440 | reg1, (arith==OP_Add ? "+" : "-"), regVal, |
| 156011 | 156441 | ((op==OP_Ge) ? ">=" : (op==OP_Le) ? "<=" : (op==OP_Gt) ? ">" : "<"), reg2 |
| 156012 | 156442 | )); |
| 156013 | 156443 | |
| 156014 | | - /* Register reg1 currently contains csr1.peerVal (the peer-value from csr1). |
| 156015 | | - ** This block adds (or subtracts for DESC) the numeric value in regVal |
| 156016 | | - ** from it. Or, if reg1 is not numeric (it is a NULL, a text value or a blob), |
| 156017 | | - ** then leave reg1 as it is. In pseudo-code, this is implemented as: |
| 156018 | | - ** |
| 156019 | | - ** if( reg1>='' ) goto addrGe; |
| 156020 | | - ** reg1 = reg1 +/- regVal |
| 156021 | | - ** addrGe: |
| 156022 | | - ** |
| 156023 | | - ** Since all strings and blobs are greater-than-or-equal-to an empty string, |
| 156024 | | - ** the add/subtract is skipped for these, as required. If reg1 is a NULL, |
| 156025 | | - ** then the arithmetic is performed, but since adding or subtracting from |
| 156026 | | - ** NULL is always NULL anyway, this case is handled as required too. */ |
| 156027 | | - sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC); |
| 156028 | | - addrGe = sqlite3VdbeAddOp3(v, OP_Ge, regString, 0, reg1); |
| 156029 | | - VdbeCoverage(v); |
| 156030 | | - sqlite3VdbeAddOp3(v, arith, regVal, reg1, reg1); |
| 156031 | | - sqlite3VdbeJumpHere(v, addrGe); |
| 156032 | | - |
| 156033 | 156444 | /* If the BIGNULL flag is set for the ORDER BY, then it is required to |
| 156034 | 156445 | ** consider NULL values to be larger than all other values, instead of |
| 156035 | 156446 | ** the usual smaller. The VDBE opcodes OP_Ge and so on do not handle this |
| 156036 | 156447 | ** (and adding that capability causes a performance regression), so |
| 156037 | 156448 | ** instead if the BIGNULL flag is set then cases where either reg1 or |
| | @@ -156064,27 +156475,50 @@ |
| 156064 | 156475 | sqlite3VdbeAddOp2(v, OP_IsNull, reg2, lbl); |
| 156065 | 156476 | VdbeCoverage(v); |
| 156066 | 156477 | break; |
| 156067 | 156478 | default: assert( op==OP_Lt ); /* no-op */ break; |
| 156068 | 156479 | } |
| 156069 | | - sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+3); |
| 156480 | + sqlite3VdbeAddOp2(v, OP_Goto, 0, addrDone); |
| 156070 | 156481 | |
| 156071 | 156482 | /* This block runs if reg1 is not NULL, but reg2 is. */ |
| 156072 | 156483 | sqlite3VdbeJumpHere(v, addr); |
| 156073 | 156484 | sqlite3VdbeAddOp2(v, OP_IsNull, reg2, lbl); VdbeCoverage(v); |
| 156074 | 156485 | if( op==OP_Gt || op==OP_Ge ){ |
| 156075 | | - sqlite3VdbeChangeP2(v, -1, sqlite3VdbeCurrentAddr(v)+1); |
| 156486 | + sqlite3VdbeChangeP2(v, -1, addrDone); |
| 156076 | 156487 | } |
| 156077 | 156488 | } |
| 156489 | + |
| 156490 | + /* Register reg1 currently contains csr1.peerVal (the peer-value from csr1). |
| 156491 | + ** This block adds (or subtracts for DESC) the numeric value in regVal |
| 156492 | + ** from it. Or, if reg1 is not numeric (it is a NULL, a text value or a blob), |
| 156493 | + ** then leave reg1 as it is. In pseudo-code, this is implemented as: |
| 156494 | + ** |
| 156495 | + ** if( reg1>='' ) goto addrGe; |
| 156496 | + ** reg1 = reg1 +/- regVal |
| 156497 | + ** addrGe: |
| 156498 | + ** |
| 156499 | + ** Since all strings and blobs are greater-than-or-equal-to an empty string, |
| 156500 | + ** the add/subtract is skipped for these, as required. If reg1 is a NULL, |
| 156501 | + ** then the arithmetic is performed, but since adding or subtracting from |
| 156502 | + ** NULL is always NULL anyway, this case is handled as required too. */ |
| 156503 | + sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC); |
| 156504 | + addrGe = sqlite3VdbeAddOp3(v, OP_Ge, regString, 0, reg1); |
| 156505 | + VdbeCoverage(v); |
| 156506 | + if( (op==OP_Ge && arith==OP_Add) || (op==OP_Le && arith==OP_Subtract) ){ |
| 156507 | + sqlite3VdbeAddOp3(v, op, reg2, lbl, reg1); VdbeCoverage(v); |
| 156508 | + } |
| 156509 | + sqlite3VdbeAddOp3(v, arith, regVal, reg1, reg1); |
| 156510 | + sqlite3VdbeJumpHere(v, addrGe); |
| 156078 | 156511 | |
| 156079 | 156512 | /* Compare registers reg2 and reg1, taking the jump if required. Note that |
| 156080 | 156513 | ** control skips over this test if the BIGNULL flag is set and either |
| 156081 | 156514 | ** reg1 or reg2 contain a NULL value. */ |
| 156082 | 156515 | sqlite3VdbeAddOp3(v, op, reg2, lbl, reg1); VdbeCoverage(v); |
| 156083 | 156516 | pColl = sqlite3ExprNNCollSeq(pParse, pOrderBy->a[0].pExpr); |
| 156084 | 156517 | sqlite3VdbeAppendP4(v, (void*)pColl, P4_COLLSEQ); |
| 156085 | 156518 | sqlite3VdbeChangeP5(v, SQLITE_NULLEQ); |
| 156519 | + sqlite3VdbeResolveLabel(v, addrDone); |
| 156086 | 156520 | |
| 156087 | 156521 | assert( op==OP_Ge || op==OP_Gt || op==OP_Lt || op==OP_Le ); |
| 156088 | 156522 | testcase(op==OP_Ge); VdbeCoverageIf(v, op==OP_Ge); |
| 156089 | 156523 | testcase(op==OP_Lt); VdbeCoverageIf(v, op==OP_Lt); |
| 156090 | 156524 | testcase(op==OP_Le); VdbeCoverageIf(v, op==OP_Le); |
| | @@ -169758,11 +170192,11 @@ |
| 169758 | 170192 | /* |
| 169759 | 170193 | ** The assert_fts3_nc() macro is similar to the assert() macro, except that it |
| 169760 | 170194 | ** is used for assert() conditions that are true only if it can be |
| 169761 | 170195 | ** guranteed that the database is not corrupt. |
| 169762 | 170196 | */ |
| 169763 | | -#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) |
| 170197 | +#ifdef SQLITE_DEBUG |
| 169764 | 170198 | SQLITE_API extern int sqlite3_fts3_may_be_corrupt; |
| 169765 | 170199 | # define assert_fts3_nc(x) assert(sqlite3_fts3_may_be_corrupt || (x)) |
| 169766 | 170200 | #else |
| 169767 | 170201 | # define assert_fts3_nc(x) assert(x) |
| 169768 | 170202 | #endif |
| | @@ -170314,11 +170748,13 @@ |
| 170314 | 170748 | ** This variable is set to false when running tests for which the on disk |
| 170315 | 170749 | ** structures should not be corrupt. Otherwise, true. If it is false, extra |
| 170316 | 170750 | ** assert() conditions in the fts3 code are activated - conditions that are |
| 170317 | 170751 | ** only true if it is guaranteed that the fts3 database is not corrupt. |
| 170318 | 170752 | */ |
| 170753 | +#ifdef SQLITE_DEBUG |
| 170319 | 170754 | SQLITE_API int sqlite3_fts3_may_be_corrupt = 1; |
| 170755 | +#endif |
| 170320 | 170756 | |
| 170321 | 170757 | /* |
| 170322 | 170758 | ** Write a 64-bit variable-length integer to memory starting at p[0]. |
| 170323 | 170759 | ** The length of data written will be between 1 and FTS3_VARINT_MAX bytes. |
| 170324 | 170760 | ** The number of bytes written is returned. |
| | @@ -173574,18 +174010,24 @@ |
| 173574 | 174010 | /* |
| 173575 | 174011 | ** Implementation of xBegin() method. |
| 173576 | 174012 | */ |
| 173577 | 174013 | static int fts3BeginMethod(sqlite3_vtab *pVtab){ |
| 173578 | 174014 | Fts3Table *p = (Fts3Table*)pVtab; |
| 174015 | + int rc; |
| 173579 | 174016 | UNUSED_PARAMETER(pVtab); |
| 173580 | 174017 | assert( p->pSegments==0 ); |
| 173581 | 174018 | assert( p->nPendingData==0 ); |
| 173582 | 174019 | assert( p->inTransaction!=1 ); |
| 173583 | | - TESTONLY( p->inTransaction = 1 ); |
| 173584 | | - TESTONLY( p->mxSavepoint = -1; ); |
| 173585 | 174020 | p->nLeafAdd = 0; |
| 173586 | | - return fts3SetHasStat(p); |
| 174021 | + rc = fts3SetHasStat(p); |
| 174022 | +#ifdef SQLITE_DEBUG |
| 174023 | + if( rc==SQLITE_OK ){ |
| 174024 | + p->inTransaction = 1; |
| 174025 | + p->mxSavepoint = -1; |
| 174026 | + } |
| 174027 | +#endif |
| 174028 | + return rc; |
| 173587 | 174029 | } |
| 173588 | 174030 | |
| 173589 | 174031 | /* |
| 173590 | 174032 | ** Implementation of xCommit() method. This is a no-op. The contents of |
| 173591 | 174033 | ** the pending-terms hash-table have already been flushed into the database |
| | @@ -195860,10 +196302,14 @@ |
| 195860 | 196302 | if( sqlite3_value_type(pVal)==SQLITE_BLOB |
| 195861 | 196303 | && (nByte = sqlite3_value_bytes(pVal))>=(4+6*sizeof(GeoCoord)) |
| 195862 | 196304 | ){ |
| 195863 | 196305 | const unsigned char *a = sqlite3_value_blob(pVal); |
| 195864 | 196306 | int nVertex; |
| 196307 | + if( a==0 ){ |
| 196308 | + sqlite3_result_error_nomem(pCtx); |
| 196309 | + return 0; |
| 196310 | + } |
| 195865 | 196311 | nVertex = (a[1]<<16) + (a[2]<<8) + a[3]; |
| 195866 | 196312 | if( (a[0]==0 || a[0]==1) |
| 195867 | 196313 | && (nVertex*2*sizeof(GeoCoord) + 4)==(unsigned int)nByte |
| 195868 | 196314 | ){ |
| 195869 | 196315 | p = sqlite3_malloc64( sizeof(*p) + (nVertex-1)*2*sizeof(GeoCoord) ); |
| | @@ -196233,11 +196679,11 @@ |
| 196233 | 196679 | aCoord[0].f = mnX; |
| 196234 | 196680 | aCoord[1].f = mxX; |
| 196235 | 196681 | aCoord[2].f = mnY; |
| 196236 | 196682 | aCoord[3].f = mxY; |
| 196237 | 196683 | } |
| 196238 | | - }else{ |
| 196684 | + }else if( aCoord ){ |
| 196239 | 196685 | memset(aCoord, 0, sizeof(RtreeCoord)*4); |
| 196240 | 196686 | } |
| 196241 | 196687 | return pOut; |
| 196242 | 196688 | } |
| 196243 | 196689 | |
| | @@ -226018,10 +226464,11 @@ |
| 226018 | 226464 | ************************************************************************** |
| 226019 | 226465 | ** Below this point is the implementation of the fts5_decode() scalar |
| 226020 | 226466 | ** function only. |
| 226021 | 226467 | */ |
| 226022 | 226468 | |
| 226469 | +#ifdef SQLITE_TEST |
| 226023 | 226470 | /* |
| 226024 | 226471 | ** Decode a segment-data rowid from the %_data table. This function is |
| 226025 | 226472 | ** the opposite of macro FTS5_SEGMENT_ROWID(). |
| 226026 | 226473 | */ |
| 226027 | 226474 | static void fts5DecodeRowid( |
| | @@ -226040,11 +226487,13 @@ |
| 226040 | 226487 | *pbDlidx = (int)(iRowid & 0x0001); |
| 226041 | 226488 | iRowid >>= FTS5_DATA_DLI_B; |
| 226042 | 226489 | |
| 226043 | 226490 | *piSegid = (int)(iRowid & (((i64)1 << FTS5_DATA_ID_B) - 1)); |
| 226044 | 226491 | } |
| 226492 | +#endif /* SQLITE_TEST */ |
| 226045 | 226493 | |
| 226494 | +#ifdef SQLITE_TEST |
| 226046 | 226495 | static void fts5DebugRowid(int *pRc, Fts5Buffer *pBuf, i64 iKey){ |
| 226047 | 226496 | int iSegid, iHeight, iPgno, bDlidx; /* Rowid compenents */ |
| 226048 | 226497 | fts5DecodeRowid(iKey, &iSegid, &bDlidx, &iHeight, &iPgno); |
| 226049 | 226498 | |
| 226050 | 226499 | if( iSegid==0 ){ |
| | @@ -226058,11 +226507,13 @@ |
| 226058 | 226507 | sqlite3Fts5BufferAppendPrintf(pRc, pBuf, "{%ssegid=%d h=%d pgno=%d}", |
| 226059 | 226508 | bDlidx ? "dlidx " : "", iSegid, iHeight, iPgno |
| 226060 | 226509 | ); |
| 226061 | 226510 | } |
| 226062 | 226511 | } |
| 226512 | +#endif /* SQLITE_TEST */ |
| 226063 | 226513 | |
| 226514 | +#ifdef SQLITE_TEST |
| 226064 | 226515 | static void fts5DebugStructure( |
| 226065 | 226516 | int *pRc, /* IN/OUT: error code */ |
| 226066 | 226517 | Fts5Buffer *pBuf, |
| 226067 | 226518 | Fts5Structure *p |
| 226068 | 226519 | ){ |
| | @@ -226080,11 +226531,13 @@ |
| 226080 | 226531 | ); |
| 226081 | 226532 | } |
| 226082 | 226533 | sqlite3Fts5BufferAppendPrintf(pRc, pBuf, "}"); |
| 226083 | 226534 | } |
| 226084 | 226535 | } |
| 226536 | +#endif /* SQLITE_TEST */ |
| 226085 | 226537 | |
| 226538 | +#ifdef SQLITE_TEST |
| 226086 | 226539 | /* |
| 226087 | 226540 | ** This is part of the fts5_decode() debugging aid. |
| 226088 | 226541 | ** |
| 226089 | 226542 | ** Arguments pBlob/nBlob contain a serialized Fts5Structure object. This |
| 226090 | 226543 | ** function appends a human-readable representation of the same object |
| | @@ -226105,11 +226558,13 @@ |
| 226105 | 226558 | } |
| 226106 | 226559 | |
| 226107 | 226560 | fts5DebugStructure(pRc, pBuf, p); |
| 226108 | 226561 | fts5StructureRelease(p); |
| 226109 | 226562 | } |
| 226563 | +#endif /* SQLITE_TEST */ |
| 226110 | 226564 | |
| 226565 | +#ifdef SQLITE_TEST |
| 226111 | 226566 | /* |
| 226112 | 226567 | ** This is part of the fts5_decode() debugging aid. |
| 226113 | 226568 | ** |
| 226114 | 226569 | ** Arguments pBlob/nBlob contain an "averages" record. This function |
| 226115 | 226570 | ** appends a human-readable representation of record to the buffer passed |
| | @@ -226128,11 +226583,13 @@ |
| 226128 | 226583 | i += sqlite3Fts5GetVarint(&pBlob[i], &iVal); |
| 226129 | 226584 | sqlite3Fts5BufferAppendPrintf(pRc, pBuf, "%s%d", zSpace, (int)iVal); |
| 226130 | 226585 | zSpace = " "; |
| 226131 | 226586 | } |
| 226132 | 226587 | } |
| 226588 | +#endif /* SQLITE_TEST */ |
| 226133 | 226589 | |
| 226590 | +#ifdef SQLITE_TEST |
| 226134 | 226591 | /* |
| 226135 | 226592 | ** Buffer (a/n) is assumed to contain a list of serialized varints. Read |
| 226136 | 226593 | ** each varint and append its string representation to buffer pBuf. Return |
| 226137 | 226594 | ** after either the input buffer is exhausted or a 0 value is read. |
| 226138 | 226595 | ** |
| | @@ -226145,11 +226602,13 @@ |
| 226145 | 226602 | iOff += fts5GetVarint32(&a[iOff], iVal); |
| 226146 | 226603 | sqlite3Fts5BufferAppendPrintf(pRc, pBuf, " %d", iVal); |
| 226147 | 226604 | } |
| 226148 | 226605 | return iOff; |
| 226149 | 226606 | } |
| 226607 | +#endif /* SQLITE_TEST */ |
| 226150 | 226608 | |
| 226609 | +#ifdef SQLITE_TEST |
| 226151 | 226610 | /* |
| 226152 | 226611 | ** The start of buffer (a/n) contains the start of a doclist. The doclist |
| 226153 | 226612 | ** may or may not finish within the buffer. This function appends a text |
| 226154 | 226613 | ** representation of the part of the doclist that is present to buffer |
| 226155 | 226614 | ** pBuf. |
| | @@ -226178,11 +226637,13 @@ |
| 226178 | 226637 | } |
| 226179 | 226638 | } |
| 226180 | 226639 | |
| 226181 | 226640 | return iOff; |
| 226182 | 226641 | } |
| 226642 | +#endif /* SQLITE_TEST */ |
| 226183 | 226643 | |
| 226644 | +#ifdef SQLITE_TEST |
| 226184 | 226645 | /* |
| 226185 | 226646 | ** This function is part of the fts5_decode() debugging function. It is |
| 226186 | 226647 | ** only ever used with detail=none tables. |
| 226187 | 226648 | ** |
| 226188 | 226649 | ** Buffer (pData/nData) contains a doclist in the format used by detail=none |
| | @@ -226219,11 +226680,13 @@ |
| 226219 | 226680 | } |
| 226220 | 226681 | |
| 226221 | 226682 | sqlite3Fts5BufferAppendPrintf(pRc, pBuf, " %lld%s", iRowid, zApp); |
| 226222 | 226683 | } |
| 226223 | 226684 | } |
| 226685 | +#endif /* SQLITE_TEST */ |
| 226224 | 226686 | |
| 226687 | +#ifdef SQLITE_TEST |
| 226225 | 226688 | /* |
| 226226 | 226689 | ** The implementation of user-defined scalar function fts5_decode(). |
| 226227 | 226690 | */ |
| 226228 | 226691 | static void fts5DecodeFunction( |
| 226229 | 226692 | sqlite3_context *pCtx, /* Function call context */ |
| | @@ -226428,11 +226891,13 @@ |
| 226428 | 226891 | }else{ |
| 226429 | 226892 | sqlite3_result_error_code(pCtx, rc); |
| 226430 | 226893 | } |
| 226431 | 226894 | fts5BufferFree(&s); |
| 226432 | 226895 | } |
| 226896 | +#endif /* SQLITE_TEST */ |
| 226433 | 226897 | |
| 226898 | +#ifdef SQLITE_TEST |
| 226434 | 226899 | /* |
| 226435 | 226900 | ** The implementation of user-defined scalar function fts5_rowid(). |
| 226436 | 226901 | */ |
| 226437 | 226902 | static void fts5RowidFunction( |
| 226438 | 226903 | sqlite3_context *pCtx, /* Function call context */ |
| | @@ -226462,10 +226927,11 @@ |
| 226462 | 226927 | "first arg to fts5_rowid() must be 'segment'" , -1 |
| 226463 | 226928 | ); |
| 226464 | 226929 | } |
| 226465 | 226930 | } |
| 226466 | 226931 | } |
| 226932 | +#endif /* SQLITE_TEST */ |
| 226467 | 226933 | |
| 226468 | 226934 | /* |
| 226469 | 226935 | ** This is called as part of registering the FTS5 module with database |
| 226470 | 226936 | ** connection db. It registers several user-defined scalar functions useful |
| 226471 | 226937 | ** with FTS5. |
| | @@ -226472,10 +226938,11 @@ |
| 226472 | 226938 | ** |
| 226473 | 226939 | ** If successful, SQLITE_OK is returned. If an error occurs, some other |
| 226474 | 226940 | ** SQLite error code is returned instead. |
| 226475 | 226941 | */ |
| 226476 | 226942 | static int sqlite3Fts5IndexInit(sqlite3 *db){ |
| 226943 | +#ifdef SQLITE_TEST |
| 226477 | 226944 | int rc = sqlite3_create_function( |
| 226478 | 226945 | db, "fts5_decode", 2, SQLITE_UTF8, 0, fts5DecodeFunction, 0, 0 |
| 226479 | 226946 | ); |
| 226480 | 226947 | |
| 226481 | 226948 | if( rc==SQLITE_OK ){ |
| | @@ -226489,10 +226956,13 @@ |
| 226489 | 226956 | rc = sqlite3_create_function( |
| 226490 | 226957 | db, "fts5_rowid", -1, SQLITE_UTF8, 0, fts5RowidFunction, 0, 0 |
| 226491 | 226958 | ); |
| 226492 | 226959 | } |
| 226493 | 226960 | return rc; |
| 226961 | +#else |
| 226962 | + return SQLITE_OK; |
| 226963 | +#endif |
| 226494 | 226964 | } |
| 226495 | 226965 | |
| 226496 | 226966 | |
| 226497 | 226967 | static int sqlite3Fts5IndexReset(Fts5Index *p){ |
| 226498 | 226968 | assert( p->pStruct==0 || p->iStructVersion!=0 ); |
| | @@ -226524,11 +226994,13 @@ |
| 226524 | 226994 | ** This variable is set to false when running tests for which the on disk |
| 226525 | 226995 | ** structures should not be corrupt. Otherwise, true. If it is false, extra |
| 226526 | 226996 | ** assert() conditions in the fts5 code are activated - conditions that are |
| 226527 | 226997 | ** only true if it is guaranteed that the fts5 database is not corrupt. |
| 226528 | 226998 | */ |
| 226999 | +#ifdef SQLITE_DEBUG |
| 226529 | 227000 | SQLITE_API int sqlite3_fts5_may_be_corrupt = 1; |
| 227001 | +#endif |
| 226530 | 227002 | |
| 226531 | 227003 | |
| 226532 | 227004 | typedef struct Fts5Auxdata Fts5Auxdata; |
| 226533 | 227005 | typedef struct Fts5Auxiliary Fts5Auxiliary; |
| 226534 | 227006 | typedef struct Fts5Cursor Fts5Cursor; |
| | @@ -229290,11 +229762,11 @@ |
| 229290 | 229762 | int nArg, /* Number of args */ |
| 229291 | 229763 | sqlite3_value **apUnused /* Function arguments */ |
| 229292 | 229764 | ){ |
| 229293 | 229765 | assert( nArg==0 ); |
| 229294 | 229766 | UNUSED_PARAM2(nArg, apUnused); |
| 229295 | | - sqlite3_result_text(pCtx, "fts5: 2021-03-31 17:49:52 3b916924cef383f3d395e1f10aed6584d22d39a26f3b3c9919bd1afc0db635aa", -1, SQLITE_TRANSIENT); |
| 229767 | + sqlite3_result_text(pCtx, "fts5: 2021-04-07 13:20:34 c22e47c77a35ebcd1fdfc0caea9119dd5e24e76d5fdd0f2ffbb58205a7242297", -1, SQLITE_TRANSIENT); |
| 229296 | 229768 | } |
| 229297 | 229769 | |
| 229298 | 229770 | /* |
| 229299 | 229771 | ** Return true if zName is the extension on one of the shadow tables used |
| 229300 | 229772 | ** by this module. |
| | @@ -234216,12 +234688,12 @@ |
| 234216 | 234688 | } |
| 234217 | 234689 | #endif /* SQLITE_CORE */ |
| 234218 | 234690 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 234219 | 234691 | |
| 234220 | 234692 | /************** End of stmt.c ************************************************/ |
| 234221 | | -#if __LINE__!=234221 |
| 234693 | +#if __LINE__!=234693 |
| 234222 | 234694 | #undef SQLITE_SOURCE_ID |
| 234223 | | -#define SQLITE_SOURCE_ID "2021-03-31 17:49:52 3b916924cef383f3d395e1f10aed6584d22d39a26f3b3c9919bd1afc0db6alt2" |
| 234695 | +#define SQLITE_SOURCE_ID "2021-04-07 18:17:53 a2ddb89b206c13876d34c5f9e3db41cda72d6eb3fea31ffa8cc6daa1e158alt2" |
| 234224 | 234696 | #endif |
| 234225 | 234697 | /* Return the source-id for this library */ |
| 234226 | 234698 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 234227 | 234699 | /************************** End of sqlite3.c ******************************/ |
| 234228 | 234700 | |