drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 1 | /* |
| 2 | ** 2015-06-08 |
| 3 | ** |
| 4 | ** The author disclaims copyright to this source code. In place of |
| 5 | ** a legal notice, here is a blessing: |
| 6 | ** |
| 7 | ** May you do good and not evil. |
| 8 | ** May you find forgiveness for yourself and forgive others. |
| 9 | ** May you share freely, never taking more than you give. |
| 10 | ** |
| 11 | ************************************************************************* |
| 12 | ** |
| 13 | ** This file contains C code to implement the TreeView debugging routines. |
| 14 | ** These routines print a parse tree to standard output for debugging and |
| 15 | ** analysis. |
| 16 | ** |
| 17 | ** The interfaces in this file is only available when compiling |
| 18 | ** with SQLITE_DEBUG. |
| 19 | */ |
| 20 | #include "sqliteInt.h" |
| 21 | #ifdef SQLITE_DEBUG |
| 22 | |
| 23 | /* |
| 24 | ** Add a new subitem to the tree. The moreToFollow flag indicates that this |
| 25 | ** is not the last item in the tree. |
| 26 | */ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 27 | static void sqlite3TreeViewPush(TreeView **pp, u8 moreToFollow){ |
| 28 | TreeView *p = *pp; |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 29 | if( p==0 ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 30 | *pp = p = sqlite3_malloc64( sizeof(*p) ); |
| 31 | if( p==0 ) return; |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 32 | memset(p, 0, sizeof(*p)); |
| 33 | }else{ |
| 34 | p->iLevel++; |
| 35 | } |
| 36 | assert( moreToFollow==0 || moreToFollow==1 ); |
drh | e684ac6 | 2022-03-08 13:59:46 | [diff] [blame] | 37 | if( p->iLevel<(int)sizeof(p->bLine) ) p->bLine[p->iLevel] = moreToFollow; |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | /* |
| 41 | ** Finished with one layer of the tree |
| 42 | */ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 43 | static void sqlite3TreeViewPop(TreeView **pp){ |
| 44 | TreeView *p = *pp; |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 45 | if( p==0 ) return; |
| 46 | p->iLevel--; |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 47 | if( p->iLevel<0 ){ |
| 48 | sqlite3_free(p); |
| 49 | *pp = 0; |
| 50 | } |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /* |
| 54 | ** Generate a single line of output for the tree, with a prefix that contains |
| 55 | ** all the appropriate tree lines |
| 56 | */ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 57 | void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){ |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 58 | va_list ap; |
| 59 | int i; |
| 60 | StrAccum acc; |
drh | 0751fc3 | 2022-06-22 14:43:52 | [diff] [blame] | 61 | char zBuf[1000]; |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 62 | sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); |
| 63 | if( p ){ |
drh | e684ac6 | 2022-03-08 13:59:46 | [diff] [blame] | 64 | for(i=0; i<p->iLevel && i<(int)sizeof(p->bLine)-1; i++){ |
drh | 0cdbe1a | 2018-05-09 13:46:26 | [diff] [blame] | 65 | sqlite3_str_append(&acc, p->bLine[i] ? "| " : " ", 4); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 66 | } |
drh | 0cdbe1a | 2018-05-09 13:46:26 | [diff] [blame] | 67 | sqlite3_str_append(&acc, p->bLine[i] ? "|-- " : "'-- ", 4); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 68 | } |
drh | fbe0753 | 2018-04-23 20:04:38 | [diff] [blame] | 69 | if( zFormat!=0 ){ |
| 70 | va_start(ap, zFormat); |
drh | 0cdbe1a | 2018-05-09 13:46:26 | [diff] [blame] | 71 | sqlite3_str_vappendf(&acc, zFormat, ap); |
drh | fbe0753 | 2018-04-23 20:04:38 | [diff] [blame] | 72 | va_end(ap); |
drh | 10c0e71 | 2019-04-25 18:15:38 | [diff] [blame] | 73 | assert( acc.nChar>0 || acc.accError ); |
drh | 0cdbe1a | 2018-05-09 13:46:26 | [diff] [blame] | 74 | sqlite3_str_append(&acc, "\n", 1); |
drh | fbe0753 | 2018-04-23 20:04:38 | [diff] [blame] | 75 | } |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 76 | sqlite3StrAccumFinish(&acc); |
| 77 | fprintf(stdout,"%s", zBuf); |
| 78 | fflush(stdout); |
| 79 | } |
| 80 | |
| 81 | /* |
| 82 | ** Shorthand for starting a new tree item that consists of a single label |
| 83 | */ |
| 84 | static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 85 | sqlite3TreeViewPush(&p, moreFollows); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 86 | sqlite3TreeViewLine(p, "%s", zLabel); |
| 87 | } |
| 88 | |
drh | 2476a6f | 2015-11-07 15:19:59 | [diff] [blame] | 89 | /* |
drh | a087eb8 | 2022-04-28 18:17:51 | [diff] [blame] | 90 | ** Show a list of Column objects in tree format. |
| 91 | */ |
| 92 | void sqlite3TreeViewColumnList( |
| 93 | TreeView *pView, |
| 94 | const Column *aCol, |
| 95 | int nCol, |
| 96 | u8 moreToFollow |
| 97 | ){ |
| 98 | int i; |
| 99 | sqlite3TreeViewPush(&pView, moreToFollow); |
| 100 | sqlite3TreeViewLine(pView, "COLUMNS"); |
| 101 | for(i=0; i<nCol; i++){ |
| 102 | u16 flg = aCol[i].colFlags; |
mistachkin | 07fae32 | 2022-07-06 23:50:01 | [diff] [blame] | 103 | int colMoreToFollow = i<(nCol - 1); |
| 104 | sqlite3TreeViewPush(&pView, colMoreToFollow); |
drh | a087eb8 | 2022-04-28 18:17:51 | [diff] [blame] | 105 | sqlite3TreeViewLine(pView, 0); |
| 106 | printf(" %s", aCol[i].zCnName); |
| 107 | switch( aCol[i].eCType ){ |
| 108 | case COLTYPE_ANY: printf(" ANY"); break; |
| 109 | case COLTYPE_BLOB: printf(" BLOB"); break; |
| 110 | case COLTYPE_INT: printf(" INT"); break; |
| 111 | case COLTYPE_INTEGER: printf(" INTEGER"); break; |
| 112 | case COLTYPE_REAL: printf(" REAL"); break; |
| 113 | case COLTYPE_TEXT: printf(" TEXT"); break; |
| 114 | case COLTYPE_CUSTOM: { |
| 115 | if( flg & COLFLAG_HASTYPE ){ |
| 116 | const char *z = aCol[i].zCnName; |
| 117 | z += strlen(z)+1; |
| 118 | printf(" X-%s", z); |
| 119 | break; |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | if( flg & COLFLAG_PRIMKEY ) printf(" PRIMARY KEY"); |
| 124 | if( flg & COLFLAG_HIDDEN ) printf(" HIDDEN"); |
drh | 0c0d052 | 2022-04-29 17:13:52 | [diff] [blame] | 125 | #ifdef COLFLAG_NOEXPAND |
drh | a087eb8 | 2022-04-28 18:17:51 | [diff] [blame] | 126 | if( flg & COLFLAG_NOEXPAND ) printf(" NO-EXPAND"); |
drh | 0c0d052 | 2022-04-29 17:13:52 | [diff] [blame] | 127 | #endif |
drh | a087eb8 | 2022-04-28 18:17:51 | [diff] [blame] | 128 | if( flg ) printf(" flags=%04x", flg); |
| 129 | printf("\n"); |
| 130 | fflush(stdout); |
| 131 | sqlite3TreeViewPop(&pView); |
| 132 | } |
| 133 | sqlite3TreeViewPop(&pView); |
| 134 | } |
| 135 | |
| 136 | /* |
drh | 2476a6f | 2015-11-07 15:19:59 | [diff] [blame] | 137 | ** Generate a human-readable description of a WITH clause. |
| 138 | */ |
| 139 | void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){ |
| 140 | int i; |
| 141 | if( pWith==0 ) return; |
| 142 | if( pWith->nCte==0 ) return; |
| 143 | if( pWith->pOuter ){ |
| 144 | sqlite3TreeViewLine(pView, "WITH (0x%p, pOuter=0x%p)",pWith,pWith->pOuter); |
| 145 | }else{ |
| 146 | sqlite3TreeViewLine(pView, "WITH (0x%p)", pWith); |
| 147 | } |
| 148 | if( pWith->nCte>0 ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 149 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | 2476a6f | 2015-11-07 15:19:59 | [diff] [blame] | 150 | for(i=0; i<pWith->nCte; i++){ |
| 151 | StrAccum x; |
| 152 | char zLine[1000]; |
| 153 | const struct Cte *pCte = &pWith->a[i]; |
| 154 | sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); |
drh | 0cdbe1a | 2018-05-09 13:46:26 | [diff] [blame] | 155 | sqlite3_str_appendf(&x, "%s", pCte->zName); |
drh | 2476a6f | 2015-11-07 15:19:59 | [diff] [blame] | 156 | if( pCte->pCols && pCte->pCols->nExpr>0 ){ |
| 157 | char cSep = '('; |
| 158 | int j; |
| 159 | for(j=0; j<pCte->pCols->nExpr; j++){ |
drh | 41cee66 | 2019-12-12 20:22:34 | [diff] [blame] | 160 | sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zEName); |
drh | 2476a6f | 2015-11-07 15:19:59 | [diff] [blame] | 161 | cSep = ','; |
| 162 | } |
drh | 0cdbe1a | 2018-05-09 13:46:26 | [diff] [blame] | 163 | sqlite3_str_appendf(&x, ")"); |
drh | 2476a6f | 2015-11-07 15:19:59 | [diff] [blame] | 164 | } |
drh | 67f70be | 2022-04-22 16:15:48 | [diff] [blame] | 165 | if( pCte->eM10d!=M10d_Any ){ |
| 166 | sqlite3_str_appendf(&x, " %sMATERIALIZED", |
| 167 | pCte->eM10d==M10d_No ? "NOT " : ""); |
| 168 | } |
drh | a79e2a2 | 2021-02-21 23:44:14 | [diff] [blame] | 169 | if( pCte->pUse ){ |
| 170 | sqlite3_str_appendf(&x, " (pUse=0x%p, nUse=%d)", pCte->pUse, |
| 171 | pCte->pUse->nUse); |
| 172 | } |
drh | 2476a6f | 2015-11-07 15:19:59 | [diff] [blame] | 173 | sqlite3StrAccumFinish(&x); |
| 174 | sqlite3TreeViewItem(pView, zLine, i<pWith->nCte-1); |
| 175 | sqlite3TreeViewSelect(pView, pCte->pSelect, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 176 | sqlite3TreeViewPop(&pView); |
drh | 2476a6f | 2015-11-07 15:19:59 | [diff] [blame] | 177 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 178 | sqlite3TreeViewPop(&pView); |
drh | 2476a6f | 2015-11-07 15:19:59 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | |
drh | 145d0a3 | 2018-11-08 22:53:06 | [diff] [blame] | 182 | /* |
| 183 | ** Generate a human-readable description of a SrcList object. |
| 184 | */ |
| 185 | void sqlite3TreeViewSrcList(TreeView *pView, const SrcList *pSrc){ |
| 186 | int i; |
drh | b60d1fb | 2022-04-13 18:32:04 | [diff] [blame] | 187 | if( pSrc==0 ) return; |
drh | 145d0a3 | 2018-11-08 22:53:06 | [diff] [blame] | 188 | for(i=0; i<pSrc->nSrc; i++){ |
drh | 7601294 | 2021-02-21 21:04:54 | [diff] [blame] | 189 | const SrcItem *pItem = &pSrc->a[i]; |
drh | 145d0a3 | 2018-11-08 22:53:06 | [diff] [blame] | 190 | StrAccum x; |
drh | 08e1a6a | 2022-04-29 17:03:25 | [diff] [blame] | 191 | int n = 0; |
drh | 0751fc3 | 2022-06-22 14:43:52 | [diff] [blame] | 192 | char zLine[1000]; |
drh | 145d0a3 | 2018-11-08 22:53:06 | [diff] [blame] | 193 | sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); |
drh | ff37491 | 2021-04-12 12:58:55 | [diff] [blame] | 194 | x.printfFlags |= SQLITE_PRINTF_INTERNAL; |
drh | 6610e6a | 2021-03-19 19:44:56 | [diff] [blame] | 195 | sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem); |
drh | b204b6a | 2024-08-17 23:23:23 | [diff] [blame] | 196 | if( pItem->pSTab ){ |
drh | 0462499 | 2024-05-18 20:00:08 | [diff] [blame] | 197 | sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx%s", |
drh | b204b6a | 2024-08-17 23:23:23 | [diff] [blame] | 198 | pItem->pSTab->zName, pItem->pSTab->nCol, pItem->pSTab, |
drh | 0462499 | 2024-05-18 20:00:08 | [diff] [blame] | 199 | pItem->colUsed, |
| 200 | pItem->fg.rowidUsed ? "+rowid" : ""); |
drh | 145d0a3 | 2018-11-08 22:53:06 | [diff] [blame] | 201 | } |
drh | a76ac88 | 2022-04-08 19:20:12 | [diff] [blame] | 202 | if( (pItem->fg.jointype & (JT_LEFT|JT_RIGHT))==(JT_LEFT|JT_RIGHT) ){ |
| 203 | sqlite3_str_appendf(&x, " FULL-OUTER-JOIN"); |
| 204 | }else if( pItem->fg.jointype & JT_LEFT ){ |
drh | 145d0a3 | 2018-11-08 22:53:06 | [diff] [blame] | 205 | sqlite3_str_appendf(&x, " LEFT-JOIN"); |
drh | a76ac88 | 2022-04-08 19:20:12 | [diff] [blame] | 206 | }else if( pItem->fg.jointype & JT_RIGHT ){ |
| 207 | sqlite3_str_appendf(&x, " RIGHT-JOIN"); |
drh | 9b9f235 | 2021-06-23 11:39:00 | [diff] [blame] | 208 | }else if( pItem->fg.jointype & JT_CROSS ){ |
| 209 | sqlite3_str_appendf(&x, " CROSS-JOIN"); |
drh | 145d0a3 | 2018-11-08 22:53:06 | [diff] [blame] | 210 | } |
drh | 8a28ce7 | 2022-04-11 00:54:30 | [diff] [blame] | 211 | if( pItem->fg.jointype & JT_LTORJ ){ |
| 212 | sqlite3_str_appendf(&x, " LTORJ"); |
| 213 | } |
drh | b7e5199 | 2020-01-08 14:39:57 | [diff] [blame] | 214 | if( pItem->fg.fromDDL ){ |
| 215 | sqlite3_str_appendf(&x, " DDL"); |
| 216 | } |
drh | a79e2a2 | 2021-02-21 23:44:14 | [diff] [blame] | 217 | if( pItem->fg.isCte ){ |
drh | 04364cb | 2025-01-02 21:23:25 | [diff] [blame] | 218 | static const char *aMat[] = {",MAT", "", ",NO-MAT"}; |
| 219 | sqlite3_str_appendf(&x, " CteUse=%d%s", |
| 220 | pItem->u2.pCteUse->nUse, |
| 221 | aMat[pItem->u2.pCteUse->eM10d]); |
drh | a79e2a2 | 2021-02-21 23:44:14 | [diff] [blame] | 222 | } |
drh | 5c118e3 | 2022-06-08 15:30:39 | [diff] [blame] | 223 | if( pItem->fg.isOn || (pItem->fg.isUsing==0 && pItem->u3.pOn!=0) ){ |
drh | 224e356 | 2024-12-02 13:29:29 | [diff] [blame] | 224 | sqlite3_str_appendf(&x, " isOn"); |
drh | 5c118e3 | 2022-06-08 15:30:39 | [diff] [blame] | 225 | } |
drh | 8cc8d36 | 2023-01-28 21:01:33 | [diff] [blame] | 226 | if( pItem->fg.isTabFunc ) sqlite3_str_appendf(&x, " isTabFunc"); |
| 227 | if( pItem->fg.isCorrelated ) sqlite3_str_appendf(&x, " isCorrelated"); |
| 228 | if( pItem->fg.isMaterialized ) sqlite3_str_appendf(&x, " isMaterialized"); |
| 229 | if( pItem->fg.viaCoroutine ) sqlite3_str_appendf(&x, " viaCoroutine"); |
| 230 | if( pItem->fg.notCte ) sqlite3_str_appendf(&x, " notCte"); |
| 231 | if( pItem->fg.isNestedFrom ) sqlite3_str_appendf(&x, " isNestedFrom"); |
drh | 01972f5 | 2024-08-21 10:32:00 | [diff] [blame] | 232 | if( pItem->fg.fixedSchema ) sqlite3_str_appendf(&x, " fixedSchema"); |
| 233 | if( pItem->fg.hadSchema ) sqlite3_str_appendf(&x, " hadSchema"); |
| 234 | if( pItem->fg.isSubquery ) sqlite3_str_appendf(&x, " isSubquery"); |
drh | 8cc8d36 | 2023-01-28 21:01:33 | [diff] [blame] | 235 | |
drh | 145d0a3 | 2018-11-08 22:53:06 | [diff] [blame] | 236 | sqlite3StrAccumFinish(&x); |
drh | a087eb8 | 2022-04-28 18:17:51 | [diff] [blame] | 237 | sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1); |
drh | 08e1a6a | 2022-04-29 17:03:25 | [diff] [blame] | 238 | n = 0; |
drh | 1521ca4 | 2024-08-19 22:48:30 | [diff] [blame] | 239 | if( pItem->fg.isSubquery ) n++; |
drh | 08e1a6a | 2022-04-29 17:03:25 | [diff] [blame] | 240 | if( pItem->fg.isTabFunc ) n++; |
| 241 | if( pItem->fg.isUsing ) n++; |
| 242 | if( pItem->fg.isUsing ){ |
| 243 | sqlite3TreeViewIdList(pView, pItem->u3.pUsing, (--n)>0, "USING"); |
| 244 | } |
drh | 1521ca4 | 2024-08-19 22:48:30 | [diff] [blame] | 245 | if( pItem->fg.isSubquery ){ |
drh | 01972f5 | 2024-08-21 10:32:00 | [diff] [blame] | 246 | assert( n==1 ); |
drh | b204b6a | 2024-08-17 23:23:23 | [diff] [blame] | 247 | if( pItem->pSTab ){ |
| 248 | Table *pTab = pItem->pSTab; |
drh | 8e8e9de | 2022-04-29 17:45:39 | [diff] [blame] | 249 | sqlite3TreeViewColumnList(pView, pTab->aCol, pTab->nCol, 1); |
| 250 | } |
drh | 1521ca4 | 2024-08-19 22:48:30 | [diff] [blame] | 251 | assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem) ); |
drh | 01972f5 | 2024-08-21 10:32:00 | [diff] [blame] | 252 | sqlite3TreeViewSelect(pView, pItem->u4.pSubq->pSelect, 0); |
drh | 145d0a3 | 2018-11-08 22:53:06 | [diff] [blame] | 253 | } |
| 254 | if( pItem->fg.isTabFunc ){ |
| 255 | sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:"); |
| 256 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 257 | sqlite3TreeViewPop(&pView); |
drh | 145d0a3 | 2018-11-08 22:53:06 | [diff] [blame] | 258 | } |
| 259 | } |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 260 | |
| 261 | /* |
drh | 2e5c505 | 2016-08-27 20:21:51 | [diff] [blame] | 262 | ** Generate a human-readable description of a Select object. |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 263 | */ |
| 264 | void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){ |
| 265 | int n = 0; |
drh | 1c4505d | 2015-08-26 11:34:31 | [diff] [blame] | 266 | int cnt = 0; |
drh | 510b7ff | 2017-03-13 17:37:13 | [diff] [blame] | 267 | if( p==0 ){ |
| 268 | sqlite3TreeViewLine(pView, "nil-SELECT"); |
| 269 | return; |
| 270 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 271 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | 2476a6f | 2015-11-07 15:19:59 | [diff] [blame] | 272 | if( p->pWith ){ |
| 273 | sqlite3TreeViewWith(pView, p->pWith, 1); |
| 274 | cnt = 1; |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 275 | sqlite3TreeViewPush(&pView, 1); |
drh | 2476a6f | 2015-11-07 15:19:59 | [diff] [blame] | 276 | } |
drh | 1c4505d | 2015-08-26 11:34:31 | [diff] [blame] | 277 | do{ |
drh | 55b4c82 | 2019-08-03 16:17:46 | [diff] [blame] | 278 | if( p->selFlags & SF_WhereBegin ){ |
| 279 | sqlite3TreeViewLine(pView, "sqlite3WhereBegin()"); |
| 280 | }else{ |
| 281 | sqlite3TreeViewLine(pView, |
| 282 | "SELECT%s%s (%u/%p) selFlags=0x%x nSelectRow=%d", |
| 283 | ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""), |
| 284 | ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), |
| 285 | p->selId, p, p->selFlags, |
| 286 | (int)p->nSelectRow |
| 287 | ); |
| 288 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 289 | if( cnt++ ) sqlite3TreeViewPop(&pView); |
drh | 1c4505d | 2015-08-26 11:34:31 | [diff] [blame] | 290 | if( p->pPrior ){ |
| 291 | n = 1000; |
| 292 | }else{ |
| 293 | n = 0; |
drh | 6326e30 | 2024-07-21 23:34:52 | [diff] [blame] | 294 | if( p->pSrc && p->pSrc->nSrc && p->pSrc->nAlloc ) n++; |
drh | 1c4505d | 2015-08-26 11:34:31 | [diff] [blame] | 295 | if( p->pWhere ) n++; |
| 296 | if( p->pGroupBy ) n++; |
| 297 | if( p->pHaving ) n++; |
| 298 | if( p->pOrderBy ) n++; |
| 299 | if( p->pLimit ) n++; |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 300 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 301 | if( p->pWin ) n++; |
| 302 | if( p->pWinDefn ) n++; |
| 303 | #endif |
drh | 1c4505d | 2015-08-26 11:34:31 | [diff] [blame] | 304 | } |
drh | 55b4c82 | 2019-08-03 16:17:46 | [diff] [blame] | 305 | if( p->pEList ){ |
| 306 | sqlite3TreeViewExprList(pView, p->pEList, n>0, "result-set"); |
| 307 | } |
| 308 | n--; |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 309 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 310 | if( p->pWin ){ |
| 311 | Window *pX; |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 312 | sqlite3TreeViewPush(&pView, (n--)>0); |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 313 | sqlite3TreeViewLine(pView, "window-functions"); |
| 314 | for(pX=p->pWin; pX; pX=pX->pNextWin){ |
| 315 | sqlite3TreeViewWinFunc(pView, pX, pX->pNextWin!=0); |
| 316 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 317 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 318 | } |
| 319 | #endif |
drh | 6326e30 | 2024-07-21 23:34:52 | [diff] [blame] | 320 | if( p->pSrc && p->pSrc->nSrc && p->pSrc->nAlloc ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 321 | sqlite3TreeViewPush(&pView, (n--)>0); |
drh | 1c4505d | 2015-08-26 11:34:31 | [diff] [blame] | 322 | sqlite3TreeViewLine(pView, "FROM"); |
drh | 145d0a3 | 2018-11-08 22:53:06 | [diff] [blame] | 323 | sqlite3TreeViewSrcList(pView, p->pSrc); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 324 | sqlite3TreeViewPop(&pView); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 325 | } |
drh | 1c4505d | 2015-08-26 11:34:31 | [diff] [blame] | 326 | if( p->pWhere ){ |
| 327 | sqlite3TreeViewItem(pView, "WHERE", (n--)>0); |
| 328 | sqlite3TreeViewExpr(pView, p->pWhere, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 329 | sqlite3TreeViewPop(&pView); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 330 | } |
drh | 1c4505d | 2015-08-26 11:34:31 | [diff] [blame] | 331 | if( p->pGroupBy ){ |
| 332 | sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY"); |
| 333 | } |
| 334 | if( p->pHaving ){ |
| 335 | sqlite3TreeViewItem(pView, "HAVING", (n--)>0); |
| 336 | sqlite3TreeViewExpr(pView, p->pHaving, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 337 | sqlite3TreeViewPop(&pView); |
drh | 1c4505d | 2015-08-26 11:34:31 | [diff] [blame] | 338 | } |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 339 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 340 | if( p->pWinDefn ){ |
| 341 | Window *pX; |
| 342 | sqlite3TreeViewItem(pView, "WINDOW", (n--)>0); |
| 343 | for(pX=p->pWinDefn; pX; pX=pX->pNextWin){ |
| 344 | sqlite3TreeViewWindow(pView, pX, pX->pNextWin!=0); |
| 345 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 346 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 347 | } |
| 348 | #endif |
drh | 1c4505d | 2015-08-26 11:34:31 | [diff] [blame] | 349 | if( p->pOrderBy ){ |
| 350 | sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY"); |
| 351 | } |
| 352 | if( p->pLimit ){ |
| 353 | sqlite3TreeViewItem(pView, "LIMIT", (n--)>0); |
drh | 8c0833f | 2017-11-14 23:48:23 | [diff] [blame] | 354 | sqlite3TreeViewExpr(pView, p->pLimit->pLeft, p->pLimit->pRight!=0); |
| 355 | if( p->pLimit->pRight ){ |
drh | fed13d5 | 2024-04-26 11:32:50 | [diff] [blame] | 356 | sqlite3TreeViewItem(pView, "OFFSET", 0); |
drh | 8c0833f | 2017-11-14 23:48:23 | [diff] [blame] | 357 | sqlite3TreeViewExpr(pView, p->pLimit->pRight, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 358 | sqlite3TreeViewPop(&pView); |
drh | 8c0833f | 2017-11-14 23:48:23 | [diff] [blame] | 359 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 360 | sqlite3TreeViewPop(&pView); |
drh | 1c4505d | 2015-08-26 11:34:31 | [diff] [blame] | 361 | } |
| 362 | if( p->pPrior ){ |
| 363 | const char *zOp = "UNION"; |
| 364 | switch( p->op ){ |
| 365 | case TK_ALL: zOp = "UNION ALL"; break; |
| 366 | case TK_INTERSECT: zOp = "INTERSECT"; break; |
| 367 | case TK_EXCEPT: zOp = "EXCEPT"; break; |
| 368 | } |
| 369 | sqlite3TreeViewItem(pView, zOp, 1); |
| 370 | } |
| 371 | p = p->pPrior; |
| 372 | }while( p!=0 ); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 373 | sqlite3TreeViewPop(&pView); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 374 | } |
| 375 | |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 376 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 377 | /* |
| 378 | ** Generate a description of starting or stopping bounds |
| 379 | */ |
| 380 | void sqlite3TreeViewBound( |
| 381 | TreeView *pView, /* View context */ |
| 382 | u8 eBound, /* UNBOUNDED, CURRENT, PRECEDING, FOLLOWING */ |
| 383 | Expr *pExpr, /* Value for PRECEDING or FOLLOWING */ |
| 384 | u8 moreToFollow /* True if more to follow */ |
| 385 | ){ |
| 386 | switch( eBound ){ |
| 387 | case TK_UNBOUNDED: { |
| 388 | sqlite3TreeViewItem(pView, "UNBOUNDED", moreToFollow); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 389 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 390 | break; |
| 391 | } |
| 392 | case TK_CURRENT: { |
| 393 | sqlite3TreeViewItem(pView, "CURRENT", moreToFollow); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 394 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 395 | break; |
| 396 | } |
| 397 | case TK_PRECEDING: { |
| 398 | sqlite3TreeViewItem(pView, "PRECEDING", moreToFollow); |
| 399 | sqlite3TreeViewExpr(pView, pExpr, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 400 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 401 | break; |
| 402 | } |
| 403 | case TK_FOLLOWING: { |
| 404 | sqlite3TreeViewItem(pView, "FOLLOWING", moreToFollow); |
| 405 | sqlite3TreeViewExpr(pView, pExpr, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 406 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 407 | break; |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 412 | |
| 413 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 414 | /* |
| 415 | ** Generate a human-readable explanation for a Window object |
| 416 | */ |
| 417 | void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){ |
drh | fc15f4c | 2019-03-28 13:03:41 | [diff] [blame] | 418 | int nElement = 0; |
drh | bae50d6 | 2022-04-30 19:55:28 | [diff] [blame] | 419 | if( pWin==0 ) return; |
drh | 0dc0e9c | 2019-03-28 13:35:28 | [diff] [blame] | 420 | if( pWin->pFilter ){ |
| 421 | sqlite3TreeViewItem(pView, "FILTER", 1); |
| 422 | sqlite3TreeViewExpr(pView, pWin->pFilter, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 423 | sqlite3TreeViewPop(&pView); |
drh | d8b840a | 2023-10-19 19:08:33 | [diff] [blame] | 424 | if( pWin->eFrmType==TK_FILTER ) return; |
drh | 0dc0e9c | 2019-03-28 13:35:28 | [diff] [blame] | 425 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 426 | sqlite3TreeViewPush(&pView, more); |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 427 | if( pWin->zName ){ |
drh | 6f1644c | 2019-03-28 13:53:12 | [diff] [blame] | 428 | sqlite3TreeViewLine(pView, "OVER %s (%p)", pWin->zName, pWin); |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 429 | }else{ |
drh | 6f1644c | 2019-03-28 13:53:12 | [diff] [blame] | 430 | sqlite3TreeViewLine(pView, "OVER (%p)", pWin); |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 431 | } |
drh | fc15f4c | 2019-03-28 13:03:41 | [diff] [blame] | 432 | if( pWin->zBase ) nElement++; |
| 433 | if( pWin->pOrderBy ) nElement++; |
drh | d8b840a | 2023-10-19 19:08:33 | [diff] [blame] | 434 | if( pWin->eFrmType!=0 && pWin->eFrmType!=TK_FILTER ) nElement++; |
drh | fc15f4c | 2019-03-28 13:03:41 | [diff] [blame] | 435 | if( pWin->eExclude ) nElement++; |
drh | fc15f4c | 2019-03-28 13:03:41 | [diff] [blame] | 436 | if( pWin->zBase ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 437 | sqlite3TreeViewPush(&pView, (--nElement)>0); |
drh | fc15f4c | 2019-03-28 13:03:41 | [diff] [blame] | 438 | sqlite3TreeViewLine(pView, "window: %s", pWin->zBase); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 439 | sqlite3TreeViewPop(&pView); |
drh | fc15f4c | 2019-03-28 13:03:41 | [diff] [blame] | 440 | } |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 441 | if( pWin->pPartition ){ |
drh | fc15f4c | 2019-03-28 13:03:41 | [diff] [blame] | 442 | sqlite3TreeViewExprList(pView, pWin->pPartition, nElement>0,"PARTITION-BY"); |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 443 | } |
| 444 | if( pWin->pOrderBy ){ |
drh | fc15f4c | 2019-03-28 13:03:41 | [diff] [blame] | 445 | sqlite3TreeViewExprList(pView, pWin->pOrderBy, (--nElement)>0, "ORDER-BY"); |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 446 | } |
drh | d8b840a | 2023-10-19 19:08:33 | [diff] [blame] | 447 | if( pWin->eFrmType!=0 && pWin->eFrmType!=TK_FILTER ){ |
drh | 0dc0e9c | 2019-03-28 13:35:28 | [diff] [blame] | 448 | char zBuf[30]; |
drh | fc15f4c | 2019-03-28 13:03:41 | [diff] [blame] | 449 | const char *zFrmType = "ROWS"; |
| 450 | if( pWin->eFrmType==TK_RANGE ) zFrmType = "RANGE"; |
| 451 | if( pWin->eFrmType==TK_GROUPS ) zFrmType = "GROUPS"; |
drh | 0dc0e9c | 2019-03-28 13:35:28 | [diff] [blame] | 452 | sqlite3_snprintf(sizeof(zBuf),zBuf,"%s%s",zFrmType, |
| 453 | pWin->bImplicitFrame ? " (implied)" : ""); |
| 454 | sqlite3TreeViewItem(pView, zBuf, (--nElement)>0); |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 455 | sqlite3TreeViewBound(pView, pWin->eStart, pWin->pStart, 1); |
| 456 | sqlite3TreeViewBound(pView, pWin->eEnd, pWin->pEnd, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 457 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 458 | } |
drh | fc15f4c | 2019-03-28 13:03:41 | [diff] [blame] | 459 | if( pWin->eExclude ){ |
| 460 | char zBuf[30]; |
| 461 | const char *zExclude; |
| 462 | switch( pWin->eExclude ){ |
| 463 | case TK_NO: zExclude = "NO OTHERS"; break; |
| 464 | case TK_CURRENT: zExclude = "CURRENT ROW"; break; |
| 465 | case TK_GROUP: zExclude = "GROUP"; break; |
| 466 | case TK_TIES: zExclude = "TIES"; break; |
| 467 | default: |
| 468 | sqlite3_snprintf(sizeof(zBuf),zBuf,"invalid(%d)", pWin->eExclude); |
| 469 | zExclude = zBuf; |
| 470 | break; |
| 471 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 472 | sqlite3TreeViewPush(&pView, 0); |
drh | fc15f4c | 2019-03-28 13:03:41 | [diff] [blame] | 473 | sqlite3TreeViewLine(pView, "EXCLUDE %s", zExclude); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 474 | sqlite3TreeViewPop(&pView); |
drh | fc15f4c | 2019-03-28 13:03:41 | [diff] [blame] | 475 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 476 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 477 | } |
| 478 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 479 | |
| 480 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 481 | /* |
| 482 | ** Generate a human-readable explanation for a Window Function object |
| 483 | */ |
| 484 | void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){ |
drh | 7a88099 | 2022-05-02 15:23:59 | [diff] [blame] | 485 | if( pWin==0 ) return; |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 486 | sqlite3TreeViewPush(&pView, more); |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 487 | sqlite3TreeViewLine(pView, "WINFUNC %s(%d)", |
drh | 105dcaa | 2022-03-10 16:01:14 | [diff] [blame] | 488 | pWin->pWFunc->zName, pWin->pWFunc->nArg); |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 489 | sqlite3TreeViewWindow(pView, pWin, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 490 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 491 | } |
| 492 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 493 | |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 494 | /* |
| 495 | ** Generate a human-readable explanation of an expression tree. |
| 496 | */ |
| 497 | void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){ |
| 498 | const char *zBinOp = 0; /* Binary operator */ |
| 499 | const char *zUniOp = 0; /* Unary operator */ |
drh | e7375bf | 2020-03-10 19:24:38 | [diff] [blame] | 500 | char zFlgs[200]; |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 501 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 502 | if( pExpr==0 ){ |
| 503 | sqlite3TreeViewLine(pView, "nil"); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 504 | sqlite3TreeViewPop(&pView); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 505 | return; |
| 506 | } |
drh | 217e77d | 2022-11-26 20:48:56 | [diff] [blame] | 507 | if( pExpr->flags || pExpr->affExpr || pExpr->vvaFlags || pExpr->pAggInfo ){ |
drh | b7e5199 | 2020-01-08 14:39:57 | [diff] [blame] | 508 | StrAccum x; |
| 509 | sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0); |
| 510 | sqlite3_str_appendf(&x, " fg.af=%x.%c", |
| 511 | pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n'); |
drh | 67a99db | 2022-05-13 14:52:04 | [diff] [blame] | 512 | if( ExprHasProperty(pExpr, EP_OuterON) ){ |
drh | a6e8ee1 | 2022-05-13 16:38:40 | [diff] [blame] | 513 | sqlite3_str_appendf(&x, " outer.iJoin=%d", pExpr->w.iJoin); |
drh | d97cda4 | 2017-04-14 14:02:14 | [diff] [blame] | 514 | } |
drh | 67a99db | 2022-05-13 14:52:04 | [diff] [blame] | 515 | if( ExprHasProperty(pExpr, EP_InnerON) ){ |
drh | a6e8ee1 | 2022-05-13 16:38:40 | [diff] [blame] | 516 | sqlite3_str_appendf(&x, " inner.iJoin=%d", pExpr->w.iJoin); |
drh | 67a99db | 2022-05-13 14:52:04 | [diff] [blame] | 517 | } |
drh | b7e5199 | 2020-01-08 14:39:57 | [diff] [blame] | 518 | if( ExprHasProperty(pExpr, EP_FromDDL) ){ |
| 519 | sqlite3_str_appendf(&x, " DDL"); |
| 520 | } |
drh | e7375bf | 2020-03-10 19:24:38 | [diff] [blame] | 521 | if( ExprHasVVAProperty(pExpr, EP_Immutable) ){ |
| 522 | sqlite3_str_appendf(&x, " IMMUTABLE"); |
| 523 | } |
drh | 217e77d | 2022-11-26 20:48:56 | [diff] [blame] | 524 | if( pExpr->pAggInfo!=0 ){ |
| 525 | sqlite3_str_appendf(&x, " agg-column[%d]", pExpr->iAgg); |
| 526 | } |
drh | b7e5199 | 2020-01-08 14:39:57 | [diff] [blame] | 527 | sqlite3StrAccumFinish(&x); |
drh | b3d903e | 2015-06-18 14:09:13 | [diff] [blame] | 528 | }else{ |
| 529 | zFlgs[0] = 0; |
| 530 | } |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 531 | switch( pExpr->op ){ |
| 532 | case TK_AGG_COLUMN: { |
drh | b3d903e | 2015-06-18 14:09:13 | [diff] [blame] | 533 | sqlite3TreeViewLine(pView, "AGG{%d:%d}%s", |
| 534 | pExpr->iTable, pExpr->iColumn, zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 535 | break; |
| 536 | } |
| 537 | case TK_COLUMN: { |
| 538 | if( pExpr->iTable<0 ){ |
| 539 | /* This only happens when coding check constraints */ |
drh | d493353 | 2019-10-31 12:30:38 | [diff] [blame] | 540 | char zOp2[16]; |
| 541 | if( pExpr->op2 ){ |
| 542 | sqlite3_snprintf(sizeof(zOp2),zOp2," op2=0x%02x",pExpr->op2); |
| 543 | }else{ |
| 544 | zOp2[0] = 0; |
| 545 | } |
| 546 | sqlite3TreeViewLine(pView, "COLUMN(%d)%s%s", |
| 547 | pExpr->iColumn, zFlgs, zOp2); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 548 | }else{ |
drh | 477572b | 2021-10-07 20:46:29 | [diff] [blame] | 549 | assert( ExprUseYTab(pExpr) ); |
drh | a513e59 | 2019-12-20 20:08:56 | [diff] [blame] | 550 | sqlite3TreeViewLine(pView, "{%d:%d} pTab=%p%s", |
| 551 | pExpr->iTable, pExpr->iColumn, |
| 552 | pExpr->y.pTab, zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 553 | } |
drh | efad2e2 | 2018-07-27 16:57:11 | [diff] [blame] | 554 | if( ExprHasProperty(pExpr, EP_FixedCol) ){ |
| 555 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 556 | } |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 557 | break; |
| 558 | } |
| 559 | case TK_INTEGER: { |
| 560 | if( pExpr->flags & EP_IntValue ){ |
| 561 | sqlite3TreeViewLine(pView, "%d", pExpr->u.iValue); |
| 562 | }else{ |
| 563 | sqlite3TreeViewLine(pView, "%s", pExpr->u.zToken); |
| 564 | } |
| 565 | break; |
| 566 | } |
| 567 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 568 | case TK_FLOAT: { |
drh | f975107 | 2021-10-07 13:40:29 | [diff] [blame] | 569 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 570 | sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken); |
| 571 | break; |
| 572 | } |
| 573 | #endif |
| 574 | case TK_STRING: { |
drh | f975107 | 2021-10-07 13:40:29 | [diff] [blame] | 575 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 576 | sqlite3TreeViewLine(pView,"%Q", pExpr->u.zToken); |
| 577 | break; |
| 578 | } |
| 579 | case TK_NULL: { |
| 580 | sqlite3TreeViewLine(pView,"NULL"); |
| 581 | break; |
| 582 | } |
drh | 3432821 | 2018-02-26 19:03:25 | [diff] [blame] | 583 | case TK_TRUEFALSE: { |
drh | 348e002 | 2021-07-22 16:07:01 | [diff] [blame] | 584 | sqlite3TreeViewLine(pView,"%s%s", |
| 585 | sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE", zFlgs); |
drh | 3432821 | 2018-02-26 19:03:25 | [diff] [blame] | 586 | break; |
| 587 | } |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 588 | #ifndef SQLITE_OMIT_BLOB_LITERAL |
| 589 | case TK_BLOB: { |
drh | f975107 | 2021-10-07 13:40:29 | [diff] [blame] | 590 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 591 | sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken); |
| 592 | break; |
| 593 | } |
| 594 | #endif |
| 595 | case TK_VARIABLE: { |
drh | f975107 | 2021-10-07 13:40:29 | [diff] [blame] | 596 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 597 | sqlite3TreeViewLine(pView,"VARIABLE(%s,%d)", |
| 598 | pExpr->u.zToken, pExpr->iColumn); |
| 599 | break; |
| 600 | } |
| 601 | case TK_REGISTER: { |
| 602 | sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable); |
| 603 | break; |
| 604 | } |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 605 | case TK_ID: { |
drh | f975107 | 2021-10-07 13:40:29 | [diff] [blame] | 606 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 607 | sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken); |
| 608 | break; |
| 609 | } |
| 610 | #ifndef SQLITE_OMIT_CAST |
| 611 | case TK_CAST: { |
| 612 | /* Expressions of the form: CAST(pLeft AS token) */ |
drh | f975107 | 2021-10-07 13:40:29 | [diff] [blame] | 613 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 614 | sqlite3TreeViewLine(pView,"CAST %Q", pExpr->u.zToken); |
| 615 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 616 | break; |
| 617 | } |
| 618 | #endif /* SQLITE_OMIT_CAST */ |
| 619 | case TK_LT: zBinOp = "LT"; break; |
| 620 | case TK_LE: zBinOp = "LE"; break; |
| 621 | case TK_GT: zBinOp = "GT"; break; |
| 622 | case TK_GE: zBinOp = "GE"; break; |
| 623 | case TK_NE: zBinOp = "NE"; break; |
| 624 | case TK_EQ: zBinOp = "EQ"; break; |
| 625 | case TK_IS: zBinOp = "IS"; break; |
| 626 | case TK_ISNOT: zBinOp = "ISNOT"; break; |
| 627 | case TK_AND: zBinOp = "AND"; break; |
| 628 | case TK_OR: zBinOp = "OR"; break; |
| 629 | case TK_PLUS: zBinOp = "ADD"; break; |
| 630 | case TK_STAR: zBinOp = "MUL"; break; |
| 631 | case TK_MINUS: zBinOp = "SUB"; break; |
| 632 | case TK_REM: zBinOp = "REM"; break; |
| 633 | case TK_BITAND: zBinOp = "BITAND"; break; |
| 634 | case TK_BITOR: zBinOp = "BITOR"; break; |
| 635 | case TK_SLASH: zBinOp = "DIV"; break; |
| 636 | case TK_LSHIFT: zBinOp = "LSHIFT"; break; |
| 637 | case TK_RSHIFT: zBinOp = "RSHIFT"; break; |
| 638 | case TK_CONCAT: zBinOp = "CONCAT"; break; |
| 639 | case TK_DOT: zBinOp = "DOT"; break; |
drh | e7375bf | 2020-03-10 19:24:38 | [diff] [blame] | 640 | case TK_LIMIT: zBinOp = "LIMIT"; break; |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 641 | |
| 642 | case TK_UMINUS: zUniOp = "UMINUS"; break; |
| 643 | case TK_UPLUS: zUniOp = "UPLUS"; break; |
| 644 | case TK_BITNOT: zUniOp = "BITNOT"; break; |
| 645 | case TK_NOT: zUniOp = "NOT"; break; |
| 646 | case TK_ISNULL: zUniOp = "ISNULL"; break; |
| 647 | case TK_NOTNULL: zUniOp = "NOTNULL"; break; |
| 648 | |
drh | 3432821 | 2018-02-26 19:03:25 | [diff] [blame] | 649 | case TK_TRUTH: { |
drh | 43c4ac8 | 2018-02-26 21:26:27 | [diff] [blame] | 650 | int x; |
| 651 | const char *azOp[] = { |
| 652 | "IS-FALSE", "IS-TRUE", "IS-NOT-FALSE", "IS-NOT-TRUE" |
| 653 | }; |
drh | 3432821 | 2018-02-26 19:03:25 | [diff] [blame] | 654 | assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT ); |
| 655 | assert( pExpr->pRight ); |
drh | 010bd47 | 2023-05-17 00:26:50 | [diff] [blame] | 656 | assert( sqlite3ExprSkipCollateAndLikely(pExpr->pRight)->op |
| 657 | == TK_TRUEFALSE ); |
drh | 96acafb | 2018-02-27 14:49:25 | [diff] [blame] | 658 | x = (pExpr->op2==TK_ISNOT)*2 + sqlite3ExprTruthValue(pExpr->pRight); |
drh | 43c4ac8 | 2018-02-26 21:26:27 | [diff] [blame] | 659 | zUniOp = azOp[x]; |
drh | 3432821 | 2018-02-26 19:03:25 | [diff] [blame] | 660 | break; |
| 661 | } |
| 662 | |
drh | 94fa9c4 | 2016-02-27 21:16:04 | [diff] [blame] | 663 | case TK_SPAN: { |
drh | f975107 | 2021-10-07 13:40:29 | [diff] [blame] | 664 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 94fa9c4 | 2016-02-27 21:16:04 | [diff] [blame] | 665 | sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken); |
| 666 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 667 | break; |
| 668 | } |
| 669 | |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 670 | case TK_COLLATE: { |
drh | c204d81 | 2019-09-10 17:51:27 | [diff] [blame] | 671 | /* COLLATE operators without the EP_Collate flag are intended to |
drh | 018dbb1 | 2019-09-28 16:14:55 | [diff] [blame] | 672 | ** emulate collation associated with a table column. These show |
| 673 | ** up in the treeview output as "SOFT-COLLATE". Explicit COLLATE |
| 674 | ** operators that appear in the original SQL always have the |
| 675 | ** EP_Collate bit set and appear in treeview output as just "COLLATE" */ |
drh | f975107 | 2021-10-07 13:40:29 | [diff] [blame] | 676 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | c204d81 | 2019-09-10 17:51:27 | [diff] [blame] | 677 | sqlite3TreeViewLine(pView, "%sCOLLATE %Q%s", |
| 678 | !ExprHasProperty(pExpr, EP_Collate) ? "SOFT-" : "", |
| 679 | pExpr->u.zToken, zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 680 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 681 | break; |
| 682 | } |
| 683 | |
| 684 | case TK_AGG_FUNCTION: |
| 685 | case TK_FUNCTION: { |
| 686 | ExprList *pFarg; /* List of function arguments */ |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 687 | Window *pWin; |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 688 | if( ExprHasProperty(pExpr, EP_TokenOnly) ){ |
| 689 | pFarg = 0; |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 690 | pWin = 0; |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 691 | }else{ |
drh | a4eeccd | 2021-10-07 17:43:30 | [diff] [blame] | 692 | assert( ExprUseXList(pExpr) ); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 693 | pFarg = pExpr->x.pList; |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 694 | #ifndef SQLITE_OMIT_WINDOWFUNC |
drh | d8b840a | 2023-10-19 19:08:33 | [diff] [blame] | 695 | pWin = IsWindowFunc(pExpr) ? pExpr->y.pWin : 0; |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 696 | #else |
| 697 | pWin = 0; |
| 698 | #endif |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 699 | } |
drh | f975107 | 2021-10-07 13:40:29 | [diff] [blame] | 700 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 701 | if( pExpr->op==TK_AGG_FUNCTION ){ |
drh | e26d428 | 2020-06-09 11:59:15 | [diff] [blame] | 702 | sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s agg=%d[%d]/%p", |
drh | ca74fbf | 2020-05-24 02:05:04 | [diff] [blame] | 703 | pExpr->op2, pExpr->u.zToken, zFlgs, |
drh | e26d428 | 2020-06-09 11:59:15 | [diff] [blame] | 704 | pExpr->pAggInfo ? pExpr->pAggInfo->selId : 0, |
drh | ca74fbf | 2020-05-24 02:05:04 | [diff] [blame] | 705 | pExpr->iAgg, pExpr->pAggInfo); |
drh | d493353 | 2019-10-31 12:30:38 | [diff] [blame] | 706 | }else if( pExpr->op2!=0 ){ |
| 707 | const char *zOp2; |
| 708 | char zBuf[8]; |
| 709 | sqlite3_snprintf(sizeof(zBuf),zBuf,"0x%02x",pExpr->op2); |
| 710 | zOp2 = zBuf; |
| 711 | if( pExpr->op2==NC_IsCheck ) zOp2 = "NC_IsCheck"; |
| 712 | if( pExpr->op2==NC_IdxExpr ) zOp2 = "NC_IdxExpr"; |
| 713 | if( pExpr->op2==NC_PartIdx ) zOp2 = "NC_PartIdx"; |
| 714 | if( pExpr->op2==NC_GenCol ) zOp2 = "NC_GenCol"; |
| 715 | sqlite3TreeViewLine(pView, "FUNCTION %Q%s op2=%s", |
| 716 | pExpr->u.zToken, zFlgs, zOp2); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 717 | }else{ |
drh | 42d2fce | 2019-08-15 20:04:09 | [diff] [blame] | 718 | sqlite3TreeViewLine(pView, "FUNCTION %Q%s", pExpr->u.zToken, zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 719 | } |
| 720 | if( pFarg ){ |
drh | d8b840a | 2023-10-19 19:08:33 | [diff] [blame] | 721 | sqlite3TreeViewExprList(pView, pFarg, pWin!=0 || pExpr->pLeft, 0); |
drh | f8202f1 | 2023-10-18 13:18:52 | [diff] [blame] | 722 | if( pExpr->pLeft ){ |
| 723 | Expr *pOB = pExpr->pLeft; |
| 724 | assert( pOB->op==TK_ORDER ); |
| 725 | assert( ExprUseXList(pOB) ); |
| 726 | sqlite3TreeViewExprList(pView, pOB->x.pList, pWin!=0, "ORDERBY"); |
| 727 | } |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 728 | } |
mistachkin | 1489785 | 2018-07-23 18:53:49 | [diff] [blame] | 729 | #ifndef SQLITE_OMIT_WINDOWFUNC |
drh | a1fd4b5 | 2018-07-10 06:32:53 | [diff] [blame] | 730 | if( pWin ){ |
| 731 | sqlite3TreeViewWindow(pView, pWin, 0); |
| 732 | } |
| 733 | #endif |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 734 | break; |
| 735 | } |
drh | 90e4a3b | 2023-10-20 15:47:30 | [diff] [blame] | 736 | case TK_ORDER: { |
| 737 | sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, "ORDERBY"); |
| 738 | break; |
| 739 | } |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 740 | #ifndef SQLITE_OMIT_SUBQUERY |
| 741 | case TK_EXISTS: { |
drh | a4eeccd | 2021-10-07 17:43:30 | [diff] [blame] | 742 | assert( ExprUseXSelect(pExpr) ); |
drh | 9f6e14c | 2017-07-10 13:24:58 | [diff] [blame] | 743 | sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 744 | sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); |
| 745 | break; |
| 746 | } |
| 747 | case TK_SELECT: { |
drh | a4eeccd | 2021-10-07 17:43:30 | [diff] [blame] | 748 | assert( ExprUseXSelect(pExpr) ); |
drh | a0365c4 | 2020-06-05 04:01:50 | [diff] [blame] | 749 | sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 750 | sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); |
| 751 | break; |
| 752 | } |
| 753 | case TK_IN: { |
drh | c64f0e7 | 2022-04-30 00:05:37 | [diff] [blame] | 754 | sqlite3_str *pStr = sqlite3_str_new(0); |
| 755 | char *z; |
| 756 | sqlite3_str_appendf(pStr, "IN flags=0x%x", pExpr->flags); |
| 757 | if( pExpr->iTable ) sqlite3_str_appendf(pStr, " iTable=%d",pExpr->iTable); |
| 758 | if( ExprHasProperty(pExpr, EP_Subrtn) ){ |
| 759 | sqlite3_str_appendf(pStr, " subrtn(%d,%d)", |
| 760 | pExpr->y.sub.regReturn, pExpr->y.sub.iAddr); |
| 761 | } |
| 762 | z = sqlite3_str_finish(pStr); |
| 763 | sqlite3TreeViewLine(pView, z); |
| 764 | sqlite3_free(z); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 765 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); |
drh | a4eeccd | 2021-10-07 17:43:30 | [diff] [blame] | 766 | if( ExprUseXSelect(pExpr) ){ |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 767 | sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); |
| 768 | }else{ |
| 769 | sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0); |
| 770 | } |
| 771 | break; |
| 772 | } |
| 773 | #endif /* SQLITE_OMIT_SUBQUERY */ |
| 774 | |
| 775 | /* |
| 776 | ** x BETWEEN y AND z |
| 777 | ** |
| 778 | ** This is equivalent to |
| 779 | ** |
| 780 | ** x>=y AND x<=z |
| 781 | ** |
| 782 | ** X is stored in pExpr->pLeft. |
| 783 | ** Y is stored in pExpr->pList->a[0].pExpr. |
| 784 | ** Z is stored in pExpr->pList->a[1].pExpr. |
| 785 | */ |
| 786 | case TK_BETWEEN: { |
drh | a4eeccd | 2021-10-07 17:43:30 | [diff] [blame] | 787 | const Expr *pX, *pY, *pZ; |
| 788 | pX = pExpr->pLeft; |
| 789 | assert( ExprUseXList(pExpr) ); |
| 790 | assert( pExpr->x.pList->nExpr==2 ); |
| 791 | pY = pExpr->x.pList->a[0].pExpr; |
| 792 | pZ = pExpr->x.pList->a[1].pExpr; |
drh | 88dcfe5 | 2023-11-10 20:46:58 | [diff] [blame] | 793 | sqlite3TreeViewLine(pView, "BETWEEN%s", zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 794 | sqlite3TreeViewExpr(pView, pX, 1); |
| 795 | sqlite3TreeViewExpr(pView, pY, 1); |
| 796 | sqlite3TreeViewExpr(pView, pZ, 0); |
| 797 | break; |
| 798 | } |
| 799 | case TK_TRIGGER: { |
| 800 | /* If the opcode is TK_TRIGGER, then the expression is a reference |
| 801 | ** to a column in the new.* or old.* pseudo-tables available to |
| 802 | ** trigger programs. In this case Expr.iTable is set to 1 for the |
| 803 | ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn |
| 804 | ** is set to the column of the pseudo-table to read, or to -1 to |
| 805 | ** read the rowid field. |
| 806 | */ |
| 807 | sqlite3TreeViewLine(pView, "%s(%d)", |
| 808 | pExpr->iTable ? "NEW" : "OLD", pExpr->iColumn); |
| 809 | break; |
| 810 | } |
| 811 | case TK_CASE: { |
| 812 | sqlite3TreeViewLine(pView, "CASE"); |
| 813 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); |
drh | a4eeccd | 2021-10-07 17:43:30 | [diff] [blame] | 814 | assert( ExprUseXList(pExpr) ); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 815 | sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0); |
| 816 | break; |
| 817 | } |
| 818 | #ifndef SQLITE_OMIT_TRIGGER |
| 819 | case TK_RAISE: { |
| 820 | const char *zType = "unk"; |
drh | 1194904 | 2019-08-05 18:01:42 | [diff] [blame] | 821 | switch( pExpr->affExpr ){ |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 822 | case OE_Rollback: zType = "rollback"; break; |
| 823 | case OE_Abort: zType = "abort"; break; |
| 824 | case OE_Fail: zType = "fail"; break; |
| 825 | case OE_Ignore: zType = "ignore"; break; |
| 826 | } |
drh | f975107 | 2021-10-07 13:40:29 | [diff] [blame] | 827 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 788ade3 | 2024-05-08 17:42:13 | [diff] [blame] | 828 | sqlite3TreeViewLine(pView, "RAISE %s", zType); |
| 829 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 830 | break; |
| 831 | } |
| 832 | #endif |
drh | c84a402 | 2016-05-27 12:30:20 | [diff] [blame] | 833 | case TK_MATCH: { |
| 834 | sqlite3TreeViewLine(pView, "MATCH {%d:%d}%s", |
| 835 | pExpr->iTable, pExpr->iColumn, zFlgs); |
| 836 | sqlite3TreeViewExpr(pView, pExpr->pRight, 0); |
| 837 | break; |
| 838 | } |
drh | db97e56 | 2016-08-18 17:55:57 | [diff] [blame] | 839 | case TK_VECTOR: { |
drh | 269d322 | 2019-10-23 18:09:39 | [diff] [blame] | 840 | char *z = sqlite3_mprintf("VECTOR%s",zFlgs); |
drh | a4eeccd | 2021-10-07 17:43:30 | [diff] [blame] | 841 | assert( ExprUseXList(pExpr) ); |
drh | 269d322 | 2019-10-23 18:09:39 | [diff] [blame] | 842 | sqlite3TreeViewBareExprList(pView, pExpr->x.pList, z); |
| 843 | sqlite3_free(z); |
drh | db97e56 | 2016-08-18 17:55:57 | [diff] [blame] | 844 | break; |
| 845 | } |
drh | 48cb3a7 | 2016-08-18 18:09:10 | [diff] [blame] | 846 | case TK_SELECT_COLUMN: { |
drh | e46292a | 2021-07-05 02:40:29 | [diff] [blame] | 847 | sqlite3TreeViewLine(pView, "SELECT-COLUMN %d of [0..%d]%s", |
| 848 | pExpr->iColumn, pExpr->iTable-1, |
| 849 | pExpr->pRight==pExpr->pLeft ? " (SELECT-owner)" : ""); |
drh | a4eeccd | 2021-10-07 17:43:30 | [diff] [blame] | 850 | assert( ExprUseXSelect(pExpr->pLeft) ); |
drh | 48cb3a7 | 2016-08-18 18:09:10 | [diff] [blame] | 851 | sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0); |
| 852 | break; |
| 853 | } |
drh | 31d6fd5 | 2017-04-14 19:03:10 | [diff] [blame] | 854 | case TK_IF_NULL_ROW: { |
| 855 | sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable); |
| 856 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 857 | break; |
| 858 | } |
drh | bf7f3a0 | 2021-05-24 11:35:16 | [diff] [blame] | 859 | case TK_ERROR: { |
| 860 | Expr tmp; |
| 861 | sqlite3TreeViewLine(pView, "ERROR"); |
| 862 | tmp = *pExpr; |
| 863 | tmp.op = pExpr->op2; |
| 864 | sqlite3TreeViewExpr(pView, &tmp, 0); |
| 865 | break; |
| 866 | } |
drh | 4a4e02b | 2021-07-04 22:33:08 | [diff] [blame] | 867 | case TK_ROW: { |
| 868 | if( pExpr->iColumn<=0 ){ |
| 869 | sqlite3TreeViewLine(pView, "First FROM table rowid"); |
| 870 | }else{ |
| 871 | sqlite3TreeViewLine(pView, "First FROM table column %d", |
| 872 | pExpr->iColumn-1); |
| 873 | } |
| 874 | break; |
| 875 | } |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 876 | default: { |
| 877 | sqlite3TreeViewLine(pView, "op=%d", pExpr->op); |
| 878 | break; |
| 879 | } |
| 880 | } |
| 881 | if( zBinOp ){ |
drh | b3d903e | 2015-06-18 14:09:13 | [diff] [blame] | 882 | sqlite3TreeViewLine(pView, "%s%s", zBinOp, zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 883 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); |
| 884 | sqlite3TreeViewExpr(pView, pExpr->pRight, 0); |
| 885 | }else if( zUniOp ){ |
drh | b3d903e | 2015-06-18 14:09:13 | [diff] [blame] | 886 | sqlite3TreeViewLine(pView, "%s%s", zUniOp, zFlgs); |
drh | 1194904 | 2019-08-05 18:01:42 | [diff] [blame] | 887 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 888 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 889 | sqlite3TreeViewPop(&pView); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 890 | } |
| 891 | |
drh | db97e56 | 2016-08-18 17:55:57 | [diff] [blame] | 892 | |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 893 | /* |
| 894 | ** Generate a human-readable explanation of an expression list. |
| 895 | */ |
drh | db97e56 | 2016-08-18 17:55:57 | [diff] [blame] | 896 | void sqlite3TreeViewBareExprList( |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 897 | TreeView *pView, |
| 898 | const ExprList *pList, |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 899 | const char *zLabel |
| 900 | ){ |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 901 | if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST"; |
| 902 | if( pList==0 ){ |
| 903 | sqlite3TreeViewLine(pView, "%s (empty)", zLabel); |
| 904 | }else{ |
drh | db97e56 | 2016-08-18 17:55:57 | [diff] [blame] | 905 | int i; |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 906 | sqlite3TreeViewLine(pView, "%s", zLabel); |
| 907 | for(i=0; i<pList->nExpr; i++){ |
drh | 5579d59 | 2015-08-26 14:01:41 | [diff] [blame] | 908 | int j = pList->a[i].u.x.iOrderByCol; |
drh | 9175b18 | 2024-06-14 23:13:54 | [diff] [blame] | 909 | u8 sortFlags = pList->a[i].fg.sortFlags; |
drh | 41cee66 | 2019-12-12 20:22:34 | [diff] [blame] | 910 | char *zName = pList->a[i].zEName; |
drh | fbe0753 | 2018-04-23 20:04:38 | [diff] [blame] | 911 | int moreToFollow = i<pList->nExpr - 1; |
drh | 9175b18 | 2024-06-14 23:13:54 | [diff] [blame] | 912 | if( j || zName || sortFlags ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 913 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | fbe0753 | 2018-04-23 20:04:38 | [diff] [blame] | 914 | moreToFollow = 0; |
| 915 | sqlite3TreeViewLine(pView, 0); |
| 916 | if( zName ){ |
drh | d88fd53 | 2022-05-02 20:49:30 | [diff] [blame] | 917 | switch( pList->a[i].fg.eEName ){ |
drh | d4e9caf | 2022-04-20 12:14:20 | [diff] [blame] | 918 | default: |
| 919 | fprintf(stdout, "AS %s ", zName); |
| 920 | break; |
| 921 | case ENAME_TAB: |
| 922 | fprintf(stdout, "TABLE-ALIAS-NAME(\"%s\") ", zName); |
drh | d88fd53 | 2022-05-02 20:49:30 | [diff] [blame] | 923 | if( pList->a[i].fg.bUsed ) fprintf(stdout, "(used) "); |
| 924 | if( pList->a[i].fg.bUsingTerm ) fprintf(stdout, "(USING-term) "); |
| 925 | if( pList->a[i].fg.bNoExpand ) fprintf(stdout, "(NoExpand) "); |
drh | d4e9caf | 2022-04-20 12:14:20 | [diff] [blame] | 926 | break; |
| 927 | case ENAME_SPAN: |
| 928 | fprintf(stdout, "SPAN(\"%s\") ", zName); |
| 929 | break; |
| 930 | } |
drh | fbe0753 | 2018-04-23 20:04:38 | [diff] [blame] | 931 | } |
| 932 | if( j ){ |
drh | 9175b18 | 2024-06-14 23:13:54 | [diff] [blame] | 933 | fprintf(stdout, "iOrderByCol=%d ", j); |
| 934 | } |
| 935 | if( sortFlags & KEYINFO_ORDER_DESC ){ |
| 936 | fprintf(stdout, "DESC "); |
| 937 | }else if( sortFlags & KEYINFO_ORDER_BIGNULL ){ |
| 938 | fprintf(stdout, "NULLS-LAST"); |
drh | fbe0753 | 2018-04-23 20:04:38 | [diff] [blame] | 939 | } |
| 940 | fprintf(stdout, "\n"); |
| 941 | fflush(stdout); |
drh | 5a699a0 | 2017-12-22 19:53:02 | [diff] [blame] | 942 | } |
drh | fbe0753 | 2018-04-23 20:04:38 | [diff] [blame] | 943 | sqlite3TreeViewExpr(pView, pList->a[i].pExpr, moreToFollow); |
drh | 9175b18 | 2024-06-14 23:13:54 | [diff] [blame] | 944 | if( j || zName || sortFlags ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 945 | sqlite3TreeViewPop(&pView); |
drh | 5a699a0 | 2017-12-22 19:53:02 | [diff] [blame] | 946 | } |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 947 | } |
| 948 | } |
drh | db97e56 | 2016-08-18 17:55:57 | [diff] [blame] | 949 | } |
| 950 | void sqlite3TreeViewExprList( |
| 951 | TreeView *pView, |
| 952 | const ExprList *pList, |
| 953 | u8 moreToFollow, |
| 954 | const char *zLabel |
| 955 | ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 956 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | db97e56 | 2016-08-18 17:55:57 | [diff] [blame] | 957 | sqlite3TreeViewBareExprList(pView, pList, zLabel); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 958 | sqlite3TreeViewPop(&pView); |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 959 | } |
| 960 | |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 961 | /* |
| 962 | ** Generate a human-readable explanation of an id-list. |
| 963 | */ |
| 964 | void sqlite3TreeViewBareIdList( |
| 965 | TreeView *pView, |
| 966 | const IdList *pList, |
| 967 | const char *zLabel |
| 968 | ){ |
| 969 | if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST"; |
| 970 | if( pList==0 ){ |
| 971 | sqlite3TreeViewLine(pView, "%s (empty)", zLabel); |
| 972 | }else{ |
| 973 | int i; |
| 974 | sqlite3TreeViewLine(pView, "%s", zLabel); |
| 975 | for(i=0; i<pList->nId; i++){ |
| 976 | char *zName = pList->a[i].zName; |
| 977 | int moreToFollow = i<pList->nId - 1; |
| 978 | if( zName==0 ) zName = "(null)"; |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 979 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 980 | sqlite3TreeViewLine(pView, 0); |
drh | 8b62a82 | 2025-01-28 12:50:17 | [diff] [blame] | 981 | fprintf(stdout, "%s\n", zName); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 982 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | } |
| 986 | void sqlite3TreeViewIdList( |
| 987 | TreeView *pView, |
| 988 | const IdList *pList, |
| 989 | u8 moreToFollow, |
| 990 | const char *zLabel |
| 991 | ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 992 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 993 | sqlite3TreeViewBareIdList(pView, pList, zLabel); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 994 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | /* |
| 998 | ** Generate a human-readable explanation of a list of Upsert objects |
| 999 | */ |
| 1000 | void sqlite3TreeViewUpsert( |
| 1001 | TreeView *pView, |
| 1002 | const Upsert *pUpsert, |
| 1003 | u8 moreToFollow |
| 1004 | ){ |
| 1005 | if( pUpsert==0 ) return; |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1006 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1007 | while( pUpsert ){ |
| 1008 | int n; |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1009 | sqlite3TreeViewPush(&pView, pUpsert->pNextUpsert!=0 || moreToFollow); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1010 | sqlite3TreeViewLine(pView, "ON CONFLICT DO %s", |
| 1011 | pUpsert->isDoUpdate ? "UPDATE" : "NOTHING"); |
| 1012 | n = (pUpsert->pUpsertSet!=0) + (pUpsert->pUpsertWhere!=0); |
| 1013 | sqlite3TreeViewExprList(pView, pUpsert->pUpsertTarget, (n--)>0, "TARGET"); |
| 1014 | sqlite3TreeViewExprList(pView, pUpsert->pUpsertSet, (n--)>0, "SET"); |
| 1015 | if( pUpsert->pUpsertWhere ){ |
| 1016 | sqlite3TreeViewItem(pView, "WHERE", (n--)>0); |
| 1017 | sqlite3TreeViewExpr(pView, pUpsert->pUpsertWhere, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1018 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1019 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1020 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1021 | pUpsert = pUpsert->pNextUpsert; |
| 1022 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1023 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1024 | } |
| 1025 | |
drh | f1ab642 | 2022-07-11 18:26:14 | [diff] [blame] | 1026 | #if TREETRACE_ENABLED |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1027 | /* |
| 1028 | ** Generate a human-readable diagram of the data structure that go |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1029 | ** into generating an DELETE statement. |
| 1030 | */ |
| 1031 | void sqlite3TreeViewDelete( |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1032 | const With *pWith, |
| 1033 | const SrcList *pTabList, |
| 1034 | const Expr *pWhere, |
| 1035 | const ExprList *pOrderBy, |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1036 | const Expr *pLimit, |
| 1037 | const Trigger *pTrigger |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1038 | ){ |
| 1039 | int n = 0; |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1040 | TreeView *pView = 0; |
| 1041 | sqlite3TreeViewPush(&pView, 0); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1042 | sqlite3TreeViewLine(pView, "DELETE"); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1043 | if( pWith ) n++; |
| 1044 | if( pTabList ) n++; |
| 1045 | if( pWhere ) n++; |
| 1046 | if( pOrderBy ) n++; |
| 1047 | if( pLimit ) n++; |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1048 | if( pTrigger ) n++; |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1049 | if( pWith ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1050 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1051 | sqlite3TreeViewWith(pView, pWith, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1052 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1053 | } |
| 1054 | if( pTabList ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1055 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1056 | sqlite3TreeViewLine(pView, "FROM"); |
| 1057 | sqlite3TreeViewSrcList(pView, pTabList); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1058 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1059 | } |
| 1060 | if( pWhere ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1061 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1062 | sqlite3TreeViewLine(pView, "WHERE"); |
| 1063 | sqlite3TreeViewExpr(pView, pWhere, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1064 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1065 | } |
| 1066 | if( pOrderBy ){ |
| 1067 | sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY"); |
| 1068 | } |
| 1069 | if( pLimit ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1070 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1071 | sqlite3TreeViewLine(pView, "LIMIT"); |
| 1072 | sqlite3TreeViewExpr(pView, pLimit, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1073 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1074 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1075 | if( pTrigger ){ |
| 1076 | sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); |
| 1077 | } |
| 1078 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1079 | } |
drh | f1ab642 | 2022-07-11 18:26:14 | [diff] [blame] | 1080 | #endif /* TREETRACE_ENABLED */ |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1081 | |
drh | f1ab642 | 2022-07-11 18:26:14 | [diff] [blame] | 1082 | #if TREETRACE_ENABLED |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1083 | /* |
| 1084 | ** Generate a human-readable diagram of the data structure that go |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1085 | ** into generating an INSERT statement. |
| 1086 | */ |
| 1087 | void sqlite3TreeViewInsert( |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1088 | const With *pWith, |
| 1089 | const SrcList *pTabList, |
| 1090 | const IdList *pColumnList, |
| 1091 | const Select *pSelect, |
drh | c2d0df9 | 2022-04-06 18:30:17 | [diff] [blame] | 1092 | const ExprList *pExprList, |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1093 | int onError, |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1094 | const Upsert *pUpsert, |
| 1095 | const Trigger *pTrigger |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1096 | ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1097 | TreeView *pView = 0; |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1098 | int n = 0; |
| 1099 | const char *zLabel = "INSERT"; |
| 1100 | switch( onError ){ |
| 1101 | case OE_Replace: zLabel = "REPLACE"; break; |
| 1102 | case OE_Ignore: zLabel = "INSERT OR IGNORE"; break; |
| 1103 | case OE_Rollback: zLabel = "INSERT OR ROLLBACK"; break; |
| 1104 | case OE_Abort: zLabel = "INSERT OR ABORT"; break; |
| 1105 | case OE_Fail: zLabel = "INSERT OR FAIL"; break; |
| 1106 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1107 | sqlite3TreeViewPush(&pView, 0); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1108 | sqlite3TreeViewLine(pView, zLabel); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1109 | if( pWith ) n++; |
| 1110 | if( pTabList ) n++; |
| 1111 | if( pColumnList ) n++; |
| 1112 | if( pSelect ) n++; |
drh | c2d0df9 | 2022-04-06 18:30:17 | [diff] [blame] | 1113 | if( pExprList ) n++; |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1114 | if( pUpsert ) n++; |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1115 | if( pTrigger ) n++; |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1116 | if( pWith ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1117 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1118 | sqlite3TreeViewWith(pView, pWith, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1119 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1120 | } |
| 1121 | if( pTabList ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1122 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1123 | sqlite3TreeViewLine(pView, "INTO"); |
| 1124 | sqlite3TreeViewSrcList(pView, pTabList); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1125 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1126 | } |
| 1127 | if( pColumnList ){ |
| 1128 | sqlite3TreeViewIdList(pView, pColumnList, (--n)>0, "COLUMNS"); |
| 1129 | } |
| 1130 | if( pSelect ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1131 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1132 | sqlite3TreeViewLine(pView, "DATA-SOURCE"); |
| 1133 | sqlite3TreeViewSelect(pView, pSelect, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1134 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1135 | } |
drh | c2d0df9 | 2022-04-06 18:30:17 | [diff] [blame] | 1136 | if( pExprList ){ |
| 1137 | sqlite3TreeViewExprList(pView, pExprList, (--n)>0, "VALUES"); |
| 1138 | } |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1139 | if( pUpsert ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1140 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1141 | sqlite3TreeViewLine(pView, "UPSERT"); |
| 1142 | sqlite3TreeViewUpsert(pView, pUpsert, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1143 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1144 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1145 | if( pTrigger ){ |
| 1146 | sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); |
| 1147 | } |
| 1148 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1149 | } |
drh | f1ab642 | 2022-07-11 18:26:14 | [diff] [blame] | 1150 | #endif /* TREETRACE_ENABLED */ |
drh | 7d2c1d2 | 2022-04-06 00:29:21 | [diff] [blame] | 1151 | |
drh | f1ab642 | 2022-07-11 18:26:14 | [diff] [blame] | 1152 | #if TREETRACE_ENABLED |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1153 | /* |
| 1154 | ** Generate a human-readable diagram of the data structure that go |
| 1155 | ** into generating an UPDATE statement. |
| 1156 | */ |
| 1157 | void sqlite3TreeViewUpdate( |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1158 | const With *pWith, |
| 1159 | const SrcList *pTabList, |
| 1160 | const ExprList *pChanges, |
| 1161 | const Expr *pWhere, |
| 1162 | int onError, |
| 1163 | const ExprList *pOrderBy, |
| 1164 | const Expr *pLimit, |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1165 | const Upsert *pUpsert, |
| 1166 | const Trigger *pTrigger |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1167 | ){ |
| 1168 | int n = 0; |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1169 | TreeView *pView = 0; |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1170 | const char *zLabel = "UPDATE"; |
| 1171 | switch( onError ){ |
| 1172 | case OE_Replace: zLabel = "UPDATE OR REPLACE"; break; |
| 1173 | case OE_Ignore: zLabel = "UPDATE OR IGNORE"; break; |
| 1174 | case OE_Rollback: zLabel = "UPDATE OR ROLLBACK"; break; |
| 1175 | case OE_Abort: zLabel = "UPDATE OR ABORT"; break; |
| 1176 | case OE_Fail: zLabel = "UPDATE OR FAIL"; break; |
| 1177 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1178 | sqlite3TreeViewPush(&pView, 0); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1179 | sqlite3TreeViewLine(pView, zLabel); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1180 | if( pWith ) n++; |
| 1181 | if( pTabList ) n++; |
| 1182 | if( pChanges ) n++; |
| 1183 | if( pWhere ) n++; |
| 1184 | if( pOrderBy ) n++; |
| 1185 | if( pLimit ) n++; |
| 1186 | if( pUpsert ) n++; |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1187 | if( pTrigger ) n++; |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1188 | if( pWith ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1189 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1190 | sqlite3TreeViewWith(pView, pWith, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1191 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1192 | } |
| 1193 | if( pTabList ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1194 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1195 | sqlite3TreeViewLine(pView, "FROM"); |
| 1196 | sqlite3TreeViewSrcList(pView, pTabList); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1197 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1198 | } |
| 1199 | if( pChanges ){ |
| 1200 | sqlite3TreeViewExprList(pView, pChanges, (--n)>0, "SET"); |
| 1201 | } |
| 1202 | if( pWhere ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1203 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1204 | sqlite3TreeViewLine(pView, "WHERE"); |
| 1205 | sqlite3TreeViewExpr(pView, pWhere, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1206 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1207 | } |
| 1208 | if( pOrderBy ){ |
| 1209 | sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY"); |
| 1210 | } |
| 1211 | if( pLimit ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1212 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1213 | sqlite3TreeViewLine(pView, "LIMIT"); |
| 1214 | sqlite3TreeViewExpr(pView, pLimit, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1215 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1216 | } |
| 1217 | if( pUpsert ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1218 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1219 | sqlite3TreeViewLine(pView, "UPSERT"); |
| 1220 | sqlite3TreeViewUpsert(pView, pUpsert, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1221 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1222 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1223 | if( pTrigger ){ |
| 1224 | sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); |
| 1225 | } |
| 1226 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1227 | } |
drh | f1ab642 | 2022-07-11 18:26:14 | [diff] [blame] | 1228 | #endif /* TREETRACE_ENABLED */ |
drh | f8ef2db | 2022-04-06 10:37:44 | [diff] [blame] | 1229 | |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1230 | #ifndef SQLITE_OMIT_TRIGGER |
| 1231 | /* |
| 1232 | ** Show a human-readable graph of a TriggerStep |
| 1233 | */ |
| 1234 | void sqlite3TreeViewTriggerStep( |
| 1235 | TreeView *pView, |
| 1236 | const TriggerStep *pStep, |
| 1237 | u8 moreToFollow, |
| 1238 | u8 showFullList |
| 1239 | ){ |
| 1240 | int cnt = 0; |
| 1241 | if( pStep==0 ) return; |
| 1242 | sqlite3TreeViewPush(&pView, |
| 1243 | moreToFollow || (showFullList && pStep->pNext!=0)); |
| 1244 | do{ |
| 1245 | if( cnt++ && pStep->pNext==0 ){ |
| 1246 | sqlite3TreeViewPop(&pView); |
| 1247 | sqlite3TreeViewPush(&pView, 0); |
| 1248 | } |
| 1249 | sqlite3TreeViewLine(pView, "%s", pStep->zSpan ? pStep->zSpan : "RETURNING"); |
| 1250 | }while( showFullList && (pStep = pStep->pNext)!=0 ); |
| 1251 | sqlite3TreeViewPop(&pView); |
| 1252 | } |
| 1253 | |
| 1254 | /* |
| 1255 | ** Show a human-readable graph of a Trigger |
| 1256 | */ |
| 1257 | void sqlite3TreeViewTrigger( |
| 1258 | TreeView *pView, |
| 1259 | const Trigger *pTrigger, |
| 1260 | u8 moreToFollow, |
| 1261 | u8 showFullList |
| 1262 | ){ |
| 1263 | int cnt = 0; |
| 1264 | if( pTrigger==0 ) return; |
| 1265 | sqlite3TreeViewPush(&pView, |
| 1266 | moreToFollow || (showFullList && pTrigger->pNext!=0)); |
| 1267 | do{ |
| 1268 | if( cnt++ && pTrigger->pNext==0 ){ |
| 1269 | sqlite3TreeViewPop(&pView); |
| 1270 | sqlite3TreeViewPush(&pView, 0); |
| 1271 | } |
| 1272 | sqlite3TreeViewLine(pView, "TRIGGER %s", pTrigger->zName); |
| 1273 | sqlite3TreeViewPush(&pView, 0); |
| 1274 | sqlite3TreeViewTriggerStep(pView, pTrigger->step_list, 0, 1); |
| 1275 | sqlite3TreeViewPop(&pView); |
| 1276 | }while( showFullList && (pTrigger = pTrigger->pNext)!=0 ); |
| 1277 | sqlite3TreeViewPop(&pView); |
| 1278 | } |
| 1279 | #endif /* SQLITE_OMIT_TRIGGER */ |
| 1280 | |
| 1281 | |
drh | 8f1eb6f | 2022-04-06 12:25:04 | [diff] [blame] | 1282 | /* |
| 1283 | ** These simplified versions of the tree-view routines omit unnecessary |
| 1284 | ** parameters. These variants are intended to be used from a symbolic |
| 1285 | ** debugger, such as "gdb", during interactive debugging sessions. |
| 1286 | ** |
| 1287 | ** This routines are given external linkage so that they will always be |
| 1288 | ** accessible to the debugging, and to avoid warnings about unused |
| 1289 | ** functions. But these routines only exist in debugging builds, so they |
| 1290 | ** do not contaminate the interface. |
drh | d4a65cf | 2024-11-20 14:19:44 | [diff] [blame] | 1291 | ** |
| 1292 | ** See Also: |
| 1293 | ** |
| 1294 | ** sqlite3ShowWhereTerm() in where.c |
drh | 8f1eb6f | 2022-04-06 12:25:04 | [diff] [blame] | 1295 | */ |
| 1296 | void sqlite3ShowExpr(const Expr *p){ sqlite3TreeViewExpr(0,p,0); } |
| 1297 | void sqlite3ShowExprList(const ExprList *p){ sqlite3TreeViewExprList(0,p,0,0);} |
| 1298 | void sqlite3ShowIdList(const IdList *p){ sqlite3TreeViewIdList(0,p,0,0); } |
| 1299 | void sqlite3ShowSrcList(const SrcList *p){ sqlite3TreeViewSrcList(0,p); } |
| 1300 | void sqlite3ShowSelect(const Select *p){ sqlite3TreeViewSelect(0,p,0); } |
| 1301 | void sqlite3ShowWith(const With *p){ sqlite3TreeViewWith(0,p,0); } |
| 1302 | void sqlite3ShowUpsert(const Upsert *p){ sqlite3TreeViewUpsert(0,p,0); } |
drh | 2a7dcbf | 2022-04-06 15:41:53 | [diff] [blame] | 1303 | #ifndef SQLITE_OMIT_TRIGGER |
| 1304 | void sqlite3ShowTriggerStep(const TriggerStep *p){ |
| 1305 | sqlite3TreeViewTriggerStep(0,p,0,0); |
| 1306 | } |
| 1307 | void sqlite3ShowTriggerStepList(const TriggerStep *p){ |
| 1308 | sqlite3TreeViewTriggerStep(0,p,0,1); |
| 1309 | } |
| 1310 | void sqlite3ShowTrigger(const Trigger *p){ sqlite3TreeViewTrigger(0,p,0,0); } |
| 1311 | void sqlite3ShowTriggerList(const Trigger *p){ sqlite3TreeViewTrigger(0,p,0,1);} |
| 1312 | #endif |
drh | 8f1eb6f | 2022-04-06 12:25:04 | [diff] [blame] | 1313 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 1314 | void sqlite3ShowWindow(const Window *p){ sqlite3TreeViewWindow(0,p,0); } |
| 1315 | void sqlite3ShowWinFunc(const Window *p){ sqlite3TreeViewWinFunc(0,p,0); } |
| 1316 | #endif |
| 1317 | |
drh | 38b4149 | 2015-06-08 15:08:15 | [diff] [blame] | 1318 | #endif /* SQLITE_DEBUG */ |