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