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 | */ |
| 27 | static TreeView *sqlite3TreeViewPush(TreeView *p, u8 moreToFollow){ |
| 28 | if( p==0 ){ |
| 29 | p = sqlite3_malloc64( sizeof(*p) ); |
| 30 | if( p==0 ) return 0; |
| 31 | memset(p, 0, sizeof(*p)); |
| 32 | }else{ |
| 33 | p->iLevel++; |
| 34 | } |
| 35 | assert( moreToFollow==0 || moreToFollow==1 ); |
| 36 | if( p->iLevel<sizeof(p->bLine) ) p->bLine[p->iLevel] = moreToFollow; |
| 37 | return p; |
| 38 | } |
| 39 | |
| 40 | /* |
| 41 | ** Finished with one layer of the tree |
| 42 | */ |
| 43 | static void sqlite3TreeViewPop(TreeView *p){ |
| 44 | if( p==0 ) return; |
| 45 | p->iLevel--; |
| 46 | if( p->iLevel<0 ) sqlite3_free(p); |
| 47 | } |
| 48 | |
| 49 | /* |
| 50 | ** Generate a single line of output for the tree, with a prefix that contains |
| 51 | ** all the appropriate tree lines |
| 52 | */ |
| 53 | static void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){ |
| 54 | va_list ap; |
| 55 | int i; |
| 56 | StrAccum acc; |
| 57 | char zBuf[500]; |
| 58 | sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); |
| 59 | if( p ){ |
| 60 | for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){ |
drh | 0cdbe1a | 2018-05-09 13:46:26 +0000 | [diff] [blame] | 61 | sqlite3_str_append(&acc, p->bLine[i] ? "| " : " ", 4); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 62 | } |
drh | 0cdbe1a | 2018-05-09 13:46:26 +0000 | [diff] [blame] | 63 | sqlite3_str_append(&acc, p->bLine[i] ? "|-- " : "'-- ", 4); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 64 | } |
drh | fbe0753 | 2018-04-23 20:04:38 +0000 | [diff] [blame] | 65 | if( zFormat!=0 ){ |
| 66 | va_start(ap, zFormat); |
drh | 0cdbe1a | 2018-05-09 13:46:26 +0000 | [diff] [blame] | 67 | sqlite3_str_vappendf(&acc, zFormat, ap); |
drh | fbe0753 | 2018-04-23 20:04:38 +0000 | [diff] [blame] | 68 | va_end(ap); |
drh | 10c0e71 | 2019-04-25 18:15:38 +0000 | [diff] [blame] | 69 | assert( acc.nChar>0 || acc.accError ); |
drh | 0cdbe1a | 2018-05-09 13:46:26 +0000 | [diff] [blame] | 70 | sqlite3_str_append(&acc, "\n", 1); |
drh | fbe0753 | 2018-04-23 20:04:38 +0000 | [diff] [blame] | 71 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 72 | sqlite3StrAccumFinish(&acc); |
| 73 | fprintf(stdout,"%s", zBuf); |
| 74 | fflush(stdout); |
| 75 | } |
| 76 | |
| 77 | /* |
| 78 | ** Shorthand for starting a new tree item that consists of a single label |
| 79 | */ |
| 80 | static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){ |
| 81 | p = sqlite3TreeViewPush(p, moreFollows); |
| 82 | sqlite3TreeViewLine(p, "%s", zLabel); |
| 83 | } |
| 84 | |
drh | 2476a6f | 2015-11-07 15:19:59 +0000 | [diff] [blame] | 85 | /* |
| 86 | ** Generate a human-readable description of a WITH clause. |
| 87 | */ |
| 88 | void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){ |
| 89 | int i; |
| 90 | if( pWith==0 ) return; |
| 91 | if( pWith->nCte==0 ) return; |
| 92 | if( pWith->pOuter ){ |
| 93 | sqlite3TreeViewLine(pView, "WITH (0x%p, pOuter=0x%p)",pWith,pWith->pOuter); |
| 94 | }else{ |
| 95 | sqlite3TreeViewLine(pView, "WITH (0x%p)", pWith); |
| 96 | } |
| 97 | if( pWith->nCte>0 ){ |
| 98 | pView = sqlite3TreeViewPush(pView, 1); |
| 99 | for(i=0; i<pWith->nCte; i++){ |
| 100 | StrAccum x; |
| 101 | char zLine[1000]; |
| 102 | const struct Cte *pCte = &pWith->a[i]; |
| 103 | sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); |
drh | 0cdbe1a | 2018-05-09 13:46:26 +0000 | [diff] [blame] | 104 | sqlite3_str_appendf(&x, "%s", pCte->zName); |
drh | 2476a6f | 2015-11-07 15:19:59 +0000 | [diff] [blame] | 105 | if( pCte->pCols && pCte->pCols->nExpr>0 ){ |
| 106 | char cSep = '('; |
| 107 | int j; |
| 108 | for(j=0; j<pCte->pCols->nExpr; j++){ |
drh | 41cee66 | 2019-12-12 20:22:34 +0000 | [diff] [blame] | 109 | sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zEName); |
drh | 2476a6f | 2015-11-07 15:19:59 +0000 | [diff] [blame] | 110 | cSep = ','; |
| 111 | } |
drh | 0cdbe1a | 2018-05-09 13:46:26 +0000 | [diff] [blame] | 112 | sqlite3_str_appendf(&x, ")"); |
drh | 2476a6f | 2015-11-07 15:19:59 +0000 | [diff] [blame] | 113 | } |
drh | 0cdbe1a | 2018-05-09 13:46:26 +0000 | [diff] [blame] | 114 | sqlite3_str_appendf(&x, " AS"); |
drh | 2476a6f | 2015-11-07 15:19:59 +0000 | [diff] [blame] | 115 | sqlite3StrAccumFinish(&x); |
| 116 | sqlite3TreeViewItem(pView, zLine, i<pWith->nCte-1); |
| 117 | sqlite3TreeViewSelect(pView, pCte->pSelect, 0); |
| 118 | sqlite3TreeViewPop(pView); |
| 119 | } |
| 120 | sqlite3TreeViewPop(pView); |
| 121 | } |
| 122 | } |
| 123 | |
drh | 145d0a3 | 2018-11-08 22:53:06 +0000 | [diff] [blame] | 124 | /* |
| 125 | ** Generate a human-readable description of a SrcList object. |
| 126 | */ |
| 127 | void sqlite3TreeViewSrcList(TreeView *pView, const SrcList *pSrc){ |
| 128 | int i; |
| 129 | for(i=0; i<pSrc->nSrc; i++){ |
| 130 | const struct SrcList_item *pItem = &pSrc->a[i]; |
| 131 | StrAccum x; |
| 132 | char zLine[100]; |
| 133 | sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); |
drh | dbf1c4b | 2019-11-13 16:50:06 +0000 | [diff] [blame] | 134 | sqlite3_str_appendf(&x, "{%d:*}", pItem->iCursor); |
drh | 145d0a3 | 2018-11-08 22:53:06 +0000 | [diff] [blame] | 135 | if( pItem->zDatabase ){ |
| 136 | sqlite3_str_appendf(&x, " %s.%s", pItem->zDatabase, pItem->zName); |
| 137 | }else if( pItem->zName ){ |
| 138 | sqlite3_str_appendf(&x, " %s", pItem->zName); |
| 139 | } |
| 140 | if( pItem->pTab ){ |
drh | f7f6dbf | 2020-03-21 22:03:32 +0000 | [diff] [blame] | 141 | sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx", |
| 142 | pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, pItem->colUsed); |
drh | 145d0a3 | 2018-11-08 22:53:06 +0000 | [diff] [blame] | 143 | } |
| 144 | if( pItem->zAlias ){ |
| 145 | sqlite3_str_appendf(&x, " (AS %s)", pItem->zAlias); |
| 146 | } |
| 147 | if( pItem->fg.jointype & JT_LEFT ){ |
| 148 | sqlite3_str_appendf(&x, " LEFT-JOIN"); |
| 149 | } |
drh | b7e5199 | 2020-01-08 14:39:57 +0000 | [diff] [blame] | 150 | if( pItem->fg.fromDDL ){ |
| 151 | sqlite3_str_appendf(&x, " DDL"); |
| 152 | } |
drh | 145d0a3 | 2018-11-08 22:53:06 +0000 | [diff] [blame] | 153 | sqlite3StrAccumFinish(&x); |
| 154 | sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1); |
| 155 | if( pItem->pSelect ){ |
| 156 | sqlite3TreeViewSelect(pView, pItem->pSelect, 0); |
| 157 | } |
| 158 | if( pItem->fg.isTabFunc ){ |
| 159 | sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:"); |
| 160 | } |
| 161 | sqlite3TreeViewPop(pView); |
| 162 | } |
| 163 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 164 | |
| 165 | /* |
drh | 2e5c505 | 2016-08-27 20:21:51 +0000 | [diff] [blame] | 166 | ** Generate a human-readable description of a Select object. |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 167 | */ |
| 168 | void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){ |
| 169 | int n = 0; |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 170 | int cnt = 0; |
drh | 510b7ff | 2017-03-13 17:37:13 +0000 | [diff] [blame] | 171 | if( p==0 ){ |
| 172 | sqlite3TreeViewLine(pView, "nil-SELECT"); |
| 173 | return; |
| 174 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 175 | pView = sqlite3TreeViewPush(pView, moreToFollow); |
drh | 2476a6f | 2015-11-07 15:19:59 +0000 | [diff] [blame] | 176 | if( p->pWith ){ |
| 177 | sqlite3TreeViewWith(pView, p->pWith, 1); |
| 178 | cnt = 1; |
| 179 | sqlite3TreeViewPush(pView, 1); |
| 180 | } |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 181 | do{ |
drh | 55b4c82 | 2019-08-03 16:17:46 +0000 | [diff] [blame] | 182 | if( p->selFlags & SF_WhereBegin ){ |
| 183 | sqlite3TreeViewLine(pView, "sqlite3WhereBegin()"); |
| 184 | }else{ |
| 185 | sqlite3TreeViewLine(pView, |
| 186 | "SELECT%s%s (%u/%p) selFlags=0x%x nSelectRow=%d", |
| 187 | ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""), |
| 188 | ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), |
| 189 | p->selId, p, p->selFlags, |
| 190 | (int)p->nSelectRow |
| 191 | ); |
| 192 | } |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 193 | if( cnt++ ) sqlite3TreeViewPop(pView); |
| 194 | if( p->pPrior ){ |
| 195 | n = 1000; |
| 196 | }else{ |
| 197 | n = 0; |
| 198 | if( p->pSrc && p->pSrc->nSrc ) n++; |
| 199 | if( p->pWhere ) n++; |
| 200 | if( p->pGroupBy ) n++; |
| 201 | if( p->pHaving ) n++; |
| 202 | if( p->pOrderBy ) n++; |
| 203 | if( p->pLimit ) n++; |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 204 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 205 | if( p->pWin ) n++; |
| 206 | if( p->pWinDefn ) n++; |
| 207 | #endif |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 208 | } |
drh | 55b4c82 | 2019-08-03 16:17:46 +0000 | [diff] [blame] | 209 | if( p->pEList ){ |
| 210 | sqlite3TreeViewExprList(pView, p->pEList, n>0, "result-set"); |
| 211 | } |
| 212 | n--; |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 213 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 214 | if( p->pWin ){ |
| 215 | Window *pX; |
| 216 | pView = sqlite3TreeViewPush(pView, (n--)>0); |
| 217 | sqlite3TreeViewLine(pView, "window-functions"); |
| 218 | for(pX=p->pWin; pX; pX=pX->pNextWin){ |
| 219 | sqlite3TreeViewWinFunc(pView, pX, pX->pNextWin!=0); |
| 220 | } |
| 221 | sqlite3TreeViewPop(pView); |
| 222 | } |
| 223 | #endif |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 224 | if( p->pSrc && p->pSrc->nSrc ){ |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 225 | pView = sqlite3TreeViewPush(pView, (n--)>0); |
| 226 | sqlite3TreeViewLine(pView, "FROM"); |
drh | 145d0a3 | 2018-11-08 22:53:06 +0000 | [diff] [blame] | 227 | sqlite3TreeViewSrcList(pView, p->pSrc); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 228 | sqlite3TreeViewPop(pView); |
| 229 | } |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 230 | if( p->pWhere ){ |
| 231 | sqlite3TreeViewItem(pView, "WHERE", (n--)>0); |
| 232 | sqlite3TreeViewExpr(pView, p->pWhere, 0); |
| 233 | sqlite3TreeViewPop(pView); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 234 | } |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 235 | if( p->pGroupBy ){ |
| 236 | sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY"); |
| 237 | } |
| 238 | if( p->pHaving ){ |
| 239 | sqlite3TreeViewItem(pView, "HAVING", (n--)>0); |
| 240 | sqlite3TreeViewExpr(pView, p->pHaving, 0); |
| 241 | sqlite3TreeViewPop(pView); |
| 242 | } |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 243 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 244 | if( p->pWinDefn ){ |
| 245 | Window *pX; |
| 246 | sqlite3TreeViewItem(pView, "WINDOW", (n--)>0); |
| 247 | for(pX=p->pWinDefn; pX; pX=pX->pNextWin){ |
| 248 | sqlite3TreeViewWindow(pView, pX, pX->pNextWin!=0); |
| 249 | } |
| 250 | sqlite3TreeViewPop(pView); |
| 251 | } |
| 252 | #endif |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 253 | if( p->pOrderBy ){ |
| 254 | sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY"); |
| 255 | } |
| 256 | if( p->pLimit ){ |
| 257 | sqlite3TreeViewItem(pView, "LIMIT", (n--)>0); |
drh | 8c0833f | 2017-11-14 23:48:23 +0000 | [diff] [blame] | 258 | sqlite3TreeViewExpr(pView, p->pLimit->pLeft, p->pLimit->pRight!=0); |
| 259 | if( p->pLimit->pRight ){ |
| 260 | sqlite3TreeViewItem(pView, "OFFSET", (n--)>0); |
| 261 | sqlite3TreeViewExpr(pView, p->pLimit->pRight, 0); |
| 262 | sqlite3TreeViewPop(pView); |
| 263 | } |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 264 | sqlite3TreeViewPop(pView); |
| 265 | } |
| 266 | if( p->pPrior ){ |
| 267 | const char *zOp = "UNION"; |
| 268 | switch( p->op ){ |
| 269 | case TK_ALL: zOp = "UNION ALL"; break; |
| 270 | case TK_INTERSECT: zOp = "INTERSECT"; break; |
| 271 | case TK_EXCEPT: zOp = "EXCEPT"; break; |
| 272 | } |
| 273 | sqlite3TreeViewItem(pView, zOp, 1); |
| 274 | } |
| 275 | p = p->pPrior; |
| 276 | }while( p!=0 ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 277 | sqlite3TreeViewPop(pView); |
| 278 | } |
| 279 | |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 280 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 281 | /* |
| 282 | ** Generate a description of starting or stopping bounds |
| 283 | */ |
| 284 | void sqlite3TreeViewBound( |
| 285 | TreeView *pView, /* View context */ |
| 286 | u8 eBound, /* UNBOUNDED, CURRENT, PRECEDING, FOLLOWING */ |
| 287 | Expr *pExpr, /* Value for PRECEDING or FOLLOWING */ |
| 288 | u8 moreToFollow /* True if more to follow */ |
| 289 | ){ |
| 290 | switch( eBound ){ |
| 291 | case TK_UNBOUNDED: { |
| 292 | sqlite3TreeViewItem(pView, "UNBOUNDED", moreToFollow); |
| 293 | sqlite3TreeViewPop(pView); |
| 294 | break; |
| 295 | } |
| 296 | case TK_CURRENT: { |
| 297 | sqlite3TreeViewItem(pView, "CURRENT", moreToFollow); |
| 298 | sqlite3TreeViewPop(pView); |
| 299 | break; |
| 300 | } |
| 301 | case TK_PRECEDING: { |
| 302 | sqlite3TreeViewItem(pView, "PRECEDING", moreToFollow); |
| 303 | sqlite3TreeViewExpr(pView, pExpr, 0); |
| 304 | sqlite3TreeViewPop(pView); |
| 305 | break; |
| 306 | } |
| 307 | case TK_FOLLOWING: { |
| 308 | sqlite3TreeViewItem(pView, "FOLLOWING", moreToFollow); |
| 309 | sqlite3TreeViewExpr(pView, pExpr, 0); |
| 310 | sqlite3TreeViewPop(pView); |
| 311 | break; |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 316 | |
| 317 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 318 | /* |
| 319 | ** Generate a human-readable explanation for a Window object |
| 320 | */ |
| 321 | void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){ |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 322 | int nElement = 0; |
drh | 0dc0e9c | 2019-03-28 13:35:28 +0000 | [diff] [blame] | 323 | if( pWin->pFilter ){ |
| 324 | sqlite3TreeViewItem(pView, "FILTER", 1); |
| 325 | sqlite3TreeViewExpr(pView, pWin->pFilter, 0); |
| 326 | sqlite3TreeViewPop(pView); |
| 327 | } |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 328 | pView = sqlite3TreeViewPush(pView, more); |
| 329 | if( pWin->zName ){ |
drh | 6f1644c | 2019-03-28 13:53:12 +0000 | [diff] [blame] | 330 | sqlite3TreeViewLine(pView, "OVER %s (%p)", pWin->zName, pWin); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 331 | }else{ |
drh | 6f1644c | 2019-03-28 13:53:12 +0000 | [diff] [blame] | 332 | sqlite3TreeViewLine(pView, "OVER (%p)", pWin); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 333 | } |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 334 | if( pWin->zBase ) nElement++; |
| 335 | if( pWin->pOrderBy ) nElement++; |
| 336 | if( pWin->eFrmType ) nElement++; |
| 337 | if( pWin->eExclude ) nElement++; |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 338 | if( pWin->zBase ){ |
| 339 | sqlite3TreeViewPush(pView, (--nElement)>0); |
| 340 | sqlite3TreeViewLine(pView, "window: %s", pWin->zBase); |
| 341 | sqlite3TreeViewPop(pView); |
| 342 | } |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 343 | if( pWin->pPartition ){ |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 344 | sqlite3TreeViewExprList(pView, pWin->pPartition, nElement>0,"PARTITION-BY"); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 345 | } |
| 346 | if( pWin->pOrderBy ){ |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 347 | sqlite3TreeViewExprList(pView, pWin->pOrderBy, (--nElement)>0, "ORDER-BY"); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 348 | } |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 349 | if( pWin->eFrmType ){ |
drh | 0dc0e9c | 2019-03-28 13:35:28 +0000 | [diff] [blame] | 350 | char zBuf[30]; |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 351 | const char *zFrmType = "ROWS"; |
| 352 | if( pWin->eFrmType==TK_RANGE ) zFrmType = "RANGE"; |
| 353 | if( pWin->eFrmType==TK_GROUPS ) zFrmType = "GROUPS"; |
drh | 0dc0e9c | 2019-03-28 13:35:28 +0000 | [diff] [blame] | 354 | sqlite3_snprintf(sizeof(zBuf),zBuf,"%s%s",zFrmType, |
| 355 | pWin->bImplicitFrame ? " (implied)" : ""); |
| 356 | sqlite3TreeViewItem(pView, zBuf, (--nElement)>0); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 357 | sqlite3TreeViewBound(pView, pWin->eStart, pWin->pStart, 1); |
| 358 | sqlite3TreeViewBound(pView, pWin->eEnd, pWin->pEnd, 0); |
| 359 | sqlite3TreeViewPop(pView); |
| 360 | } |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 361 | if( pWin->eExclude ){ |
| 362 | char zBuf[30]; |
| 363 | const char *zExclude; |
| 364 | switch( pWin->eExclude ){ |
| 365 | case TK_NO: zExclude = "NO OTHERS"; break; |
| 366 | case TK_CURRENT: zExclude = "CURRENT ROW"; break; |
| 367 | case TK_GROUP: zExclude = "GROUP"; break; |
| 368 | case TK_TIES: zExclude = "TIES"; break; |
| 369 | default: |
| 370 | sqlite3_snprintf(sizeof(zBuf),zBuf,"invalid(%d)", pWin->eExclude); |
| 371 | zExclude = zBuf; |
| 372 | break; |
| 373 | } |
| 374 | sqlite3TreeViewPush(pView, 0); |
| 375 | sqlite3TreeViewLine(pView, "EXCLUDE %s", zExclude); |
| 376 | sqlite3TreeViewPop(pView); |
| 377 | } |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 378 | sqlite3TreeViewPop(pView); |
| 379 | } |
| 380 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 381 | |
| 382 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 383 | /* |
| 384 | ** Generate a human-readable explanation for a Window Function object |
| 385 | */ |
| 386 | void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){ |
| 387 | pView = sqlite3TreeViewPush(pView, more); |
| 388 | sqlite3TreeViewLine(pView, "WINFUNC %s(%d)", |
| 389 | pWin->pFunc->zName, pWin->pFunc->nArg); |
| 390 | sqlite3TreeViewWindow(pView, pWin, 0); |
| 391 | sqlite3TreeViewPop(pView); |
| 392 | } |
| 393 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 394 | |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 395 | /* |
| 396 | ** Generate a human-readable explanation of an expression tree. |
| 397 | */ |
| 398 | void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){ |
| 399 | const char *zBinOp = 0; /* Binary operator */ |
| 400 | const char *zUniOp = 0; /* Unary operator */ |
drh | e7375bf | 2020-03-10 19:24:38 +0000 | [diff] [blame] | 401 | char zFlgs[200]; |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 402 | pView = sqlite3TreeViewPush(pView, moreToFollow); |
| 403 | if( pExpr==0 ){ |
| 404 | sqlite3TreeViewLine(pView, "nil"); |
| 405 | sqlite3TreeViewPop(pView); |
| 406 | return; |
| 407 | } |
drh | e7375bf | 2020-03-10 19:24:38 +0000 | [diff] [blame] | 408 | if( pExpr->flags || pExpr->affExpr || pExpr->vvaFlags ){ |
drh | b7e5199 | 2020-01-08 14:39:57 +0000 | [diff] [blame] | 409 | StrAccum x; |
| 410 | sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0); |
| 411 | sqlite3_str_appendf(&x, " fg.af=%x.%c", |
| 412 | pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n'); |
drh | d97cda4 | 2017-04-14 14:02:14 +0000 | [diff] [blame] | 413 | if( ExprHasProperty(pExpr, EP_FromJoin) ){ |
drh | b7e5199 | 2020-01-08 14:39:57 +0000 | [diff] [blame] | 414 | sqlite3_str_appendf(&x, " iRJT=%d", pExpr->iRightJoinTable); |
drh | d97cda4 | 2017-04-14 14:02:14 +0000 | [diff] [blame] | 415 | } |
drh | b7e5199 | 2020-01-08 14:39:57 +0000 | [diff] [blame] | 416 | if( ExprHasProperty(pExpr, EP_FromDDL) ){ |
| 417 | sqlite3_str_appendf(&x, " DDL"); |
| 418 | } |
drh | e7375bf | 2020-03-10 19:24:38 +0000 | [diff] [blame] | 419 | if( ExprHasVVAProperty(pExpr, EP_Immutable) ){ |
| 420 | sqlite3_str_appendf(&x, " IMMUTABLE"); |
| 421 | } |
drh | b7e5199 | 2020-01-08 14:39:57 +0000 | [diff] [blame] | 422 | sqlite3StrAccumFinish(&x); |
drh | b3d903e | 2015-06-18 14:09:13 +0000 | [diff] [blame] | 423 | }else{ |
| 424 | zFlgs[0] = 0; |
| 425 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 426 | switch( pExpr->op ){ |
| 427 | case TK_AGG_COLUMN: { |
drh | b3d903e | 2015-06-18 14:09:13 +0000 | [diff] [blame] | 428 | sqlite3TreeViewLine(pView, "AGG{%d:%d}%s", |
| 429 | pExpr->iTable, pExpr->iColumn, zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 430 | break; |
| 431 | } |
| 432 | case TK_COLUMN: { |
| 433 | if( pExpr->iTable<0 ){ |
| 434 | /* This only happens when coding check constraints */ |
drh | d493353 | 2019-10-31 12:30:38 +0000 | [diff] [blame] | 435 | char zOp2[16]; |
| 436 | if( pExpr->op2 ){ |
| 437 | sqlite3_snprintf(sizeof(zOp2),zOp2," op2=0x%02x",pExpr->op2); |
| 438 | }else{ |
| 439 | zOp2[0] = 0; |
| 440 | } |
| 441 | sqlite3TreeViewLine(pView, "COLUMN(%d)%s%s", |
| 442 | pExpr->iColumn, zFlgs, zOp2); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 443 | }else{ |
drh | a513e59 | 2019-12-20 20:08:56 +0000 | [diff] [blame] | 444 | sqlite3TreeViewLine(pView, "{%d:%d} pTab=%p%s", |
| 445 | pExpr->iTable, pExpr->iColumn, |
| 446 | pExpr->y.pTab, zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 447 | } |
drh | efad2e2 | 2018-07-27 16:57:11 +0000 | [diff] [blame] | 448 | if( ExprHasProperty(pExpr, EP_FixedCol) ){ |
| 449 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 450 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 451 | break; |
| 452 | } |
| 453 | case TK_INTEGER: { |
| 454 | if( pExpr->flags & EP_IntValue ){ |
| 455 | sqlite3TreeViewLine(pView, "%d", pExpr->u.iValue); |
| 456 | }else{ |
| 457 | sqlite3TreeViewLine(pView, "%s", pExpr->u.zToken); |
| 458 | } |
| 459 | break; |
| 460 | } |
| 461 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 462 | case TK_FLOAT: { |
| 463 | sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken); |
| 464 | break; |
| 465 | } |
| 466 | #endif |
| 467 | case TK_STRING: { |
| 468 | sqlite3TreeViewLine(pView,"%Q", pExpr->u.zToken); |
| 469 | break; |
| 470 | } |
| 471 | case TK_NULL: { |
| 472 | sqlite3TreeViewLine(pView,"NULL"); |
| 473 | break; |
| 474 | } |
drh | 3432821 | 2018-02-26 19:03:25 +0000 | [diff] [blame] | 475 | case TK_TRUEFALSE: { |
drh | 43c4ac8 | 2018-02-26 21:26:27 +0000 | [diff] [blame] | 476 | sqlite3TreeViewLine(pView, |
drh | 96acafb | 2018-02-27 14:49:25 +0000 | [diff] [blame] | 477 | sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE"); |
drh | 3432821 | 2018-02-26 19:03:25 +0000 | [diff] [blame] | 478 | break; |
| 479 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 480 | #ifndef SQLITE_OMIT_BLOB_LITERAL |
| 481 | case TK_BLOB: { |
| 482 | sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken); |
| 483 | break; |
| 484 | } |
| 485 | #endif |
| 486 | case TK_VARIABLE: { |
| 487 | sqlite3TreeViewLine(pView,"VARIABLE(%s,%d)", |
| 488 | pExpr->u.zToken, pExpr->iColumn); |
| 489 | break; |
| 490 | } |
| 491 | case TK_REGISTER: { |
| 492 | sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable); |
| 493 | break; |
| 494 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 495 | case TK_ID: { |
| 496 | sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken); |
| 497 | break; |
| 498 | } |
| 499 | #ifndef SQLITE_OMIT_CAST |
| 500 | case TK_CAST: { |
| 501 | /* Expressions of the form: CAST(pLeft AS token) */ |
| 502 | sqlite3TreeViewLine(pView,"CAST %Q", pExpr->u.zToken); |
| 503 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 504 | break; |
| 505 | } |
| 506 | #endif /* SQLITE_OMIT_CAST */ |
| 507 | case TK_LT: zBinOp = "LT"; break; |
| 508 | case TK_LE: zBinOp = "LE"; break; |
| 509 | case TK_GT: zBinOp = "GT"; break; |
| 510 | case TK_GE: zBinOp = "GE"; break; |
| 511 | case TK_NE: zBinOp = "NE"; break; |
| 512 | case TK_EQ: zBinOp = "EQ"; break; |
| 513 | case TK_IS: zBinOp = "IS"; break; |
| 514 | case TK_ISNOT: zBinOp = "ISNOT"; break; |
| 515 | case TK_AND: zBinOp = "AND"; break; |
| 516 | case TK_OR: zBinOp = "OR"; break; |
| 517 | case TK_PLUS: zBinOp = "ADD"; break; |
| 518 | case TK_STAR: zBinOp = "MUL"; break; |
| 519 | case TK_MINUS: zBinOp = "SUB"; break; |
| 520 | case TK_REM: zBinOp = "REM"; break; |
| 521 | case TK_BITAND: zBinOp = "BITAND"; break; |
| 522 | case TK_BITOR: zBinOp = "BITOR"; break; |
| 523 | case TK_SLASH: zBinOp = "DIV"; break; |
| 524 | case TK_LSHIFT: zBinOp = "LSHIFT"; break; |
| 525 | case TK_RSHIFT: zBinOp = "RSHIFT"; break; |
| 526 | case TK_CONCAT: zBinOp = "CONCAT"; break; |
| 527 | case TK_DOT: zBinOp = "DOT"; break; |
drh | e7375bf | 2020-03-10 19:24:38 +0000 | [diff] [blame] | 528 | case TK_LIMIT: zBinOp = "LIMIT"; break; |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 529 | |
| 530 | case TK_UMINUS: zUniOp = "UMINUS"; break; |
| 531 | case TK_UPLUS: zUniOp = "UPLUS"; break; |
| 532 | case TK_BITNOT: zUniOp = "BITNOT"; break; |
| 533 | case TK_NOT: zUniOp = "NOT"; break; |
| 534 | case TK_ISNULL: zUniOp = "ISNULL"; break; |
| 535 | case TK_NOTNULL: zUniOp = "NOTNULL"; break; |
| 536 | |
drh | 3432821 | 2018-02-26 19:03:25 +0000 | [diff] [blame] | 537 | case TK_TRUTH: { |
drh | 43c4ac8 | 2018-02-26 21:26:27 +0000 | [diff] [blame] | 538 | int x; |
| 539 | const char *azOp[] = { |
| 540 | "IS-FALSE", "IS-TRUE", "IS-NOT-FALSE", "IS-NOT-TRUE" |
| 541 | }; |
drh | 3432821 | 2018-02-26 19:03:25 +0000 | [diff] [blame] | 542 | assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT ); |
| 543 | assert( pExpr->pRight ); |
dan | 6ece353 | 2019-06-12 13:49:32 +0000 | [diff] [blame] | 544 | assert( sqlite3ExprSkipCollate(pExpr->pRight)->op==TK_TRUEFALSE ); |
drh | 96acafb | 2018-02-27 14:49:25 +0000 | [diff] [blame] | 545 | x = (pExpr->op2==TK_ISNOT)*2 + sqlite3ExprTruthValue(pExpr->pRight); |
drh | 43c4ac8 | 2018-02-26 21:26:27 +0000 | [diff] [blame] | 546 | zUniOp = azOp[x]; |
drh | 3432821 | 2018-02-26 19:03:25 +0000 | [diff] [blame] | 547 | break; |
| 548 | } |
| 549 | |
drh | 94fa9c4 | 2016-02-27 21:16:04 +0000 | [diff] [blame] | 550 | case TK_SPAN: { |
| 551 | sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken); |
| 552 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 553 | break; |
| 554 | } |
| 555 | |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 556 | case TK_COLLATE: { |
drh | c204d81 | 2019-09-10 17:51:27 +0000 | [diff] [blame] | 557 | /* COLLATE operators without the EP_Collate flag are intended to |
drh | 018dbb1 | 2019-09-28 16:14:55 +0000 | [diff] [blame] | 558 | ** emulate collation associated with a table column. These show |
| 559 | ** up in the treeview output as "SOFT-COLLATE". Explicit COLLATE |
| 560 | ** operators that appear in the original SQL always have the |
| 561 | ** EP_Collate bit set and appear in treeview output as just "COLLATE" */ |
drh | c204d81 | 2019-09-10 17:51:27 +0000 | [diff] [blame] | 562 | sqlite3TreeViewLine(pView, "%sCOLLATE %Q%s", |
| 563 | !ExprHasProperty(pExpr, EP_Collate) ? "SOFT-" : "", |
| 564 | pExpr->u.zToken, zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 565 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 566 | break; |
| 567 | } |
| 568 | |
| 569 | case TK_AGG_FUNCTION: |
| 570 | case TK_FUNCTION: { |
| 571 | ExprList *pFarg; /* List of function arguments */ |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 572 | Window *pWin; |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 573 | if( ExprHasProperty(pExpr, EP_TokenOnly) ){ |
| 574 | pFarg = 0; |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 575 | pWin = 0; |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 576 | }else{ |
| 577 | pFarg = pExpr->x.pList; |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 578 | #ifndef SQLITE_OMIT_WINDOWFUNC |
drh | 014fff2 | 2020-01-08 22:22:36 +0000 | [diff] [blame] | 579 | pWin = ExprHasProperty(pExpr, EP_WinFunc) ? pExpr->y.pWin : 0; |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 580 | #else |
| 581 | pWin = 0; |
| 582 | #endif |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 583 | } |
| 584 | if( pExpr->op==TK_AGG_FUNCTION ){ |
drh | ca74fbf | 2020-05-24 02:05:04 +0000 | [diff] [blame^] | 585 | sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s iAgg=%d agg=%p", |
| 586 | pExpr->op2, pExpr->u.zToken, zFlgs, |
| 587 | pExpr->iAgg, pExpr->pAggInfo); |
drh | d493353 | 2019-10-31 12:30:38 +0000 | [diff] [blame] | 588 | }else if( pExpr->op2!=0 ){ |
| 589 | const char *zOp2; |
| 590 | char zBuf[8]; |
| 591 | sqlite3_snprintf(sizeof(zBuf),zBuf,"0x%02x",pExpr->op2); |
| 592 | zOp2 = zBuf; |
| 593 | if( pExpr->op2==NC_IsCheck ) zOp2 = "NC_IsCheck"; |
| 594 | if( pExpr->op2==NC_IdxExpr ) zOp2 = "NC_IdxExpr"; |
| 595 | if( pExpr->op2==NC_PartIdx ) zOp2 = "NC_PartIdx"; |
| 596 | if( pExpr->op2==NC_GenCol ) zOp2 = "NC_GenCol"; |
| 597 | sqlite3TreeViewLine(pView, "FUNCTION %Q%s op2=%s", |
| 598 | pExpr->u.zToken, zFlgs, zOp2); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 599 | }else{ |
drh | 42d2fce | 2019-08-15 20:04:09 +0000 | [diff] [blame] | 600 | sqlite3TreeViewLine(pView, "FUNCTION %Q%s", pExpr->u.zToken, zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 601 | } |
| 602 | if( pFarg ){ |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 603 | sqlite3TreeViewExprList(pView, pFarg, pWin!=0, 0); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 604 | } |
mistachkin | 1489785 | 2018-07-23 18:53:49 +0000 | [diff] [blame] | 605 | #ifndef SQLITE_OMIT_WINDOWFUNC |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 606 | if( pWin ){ |
| 607 | sqlite3TreeViewWindow(pView, pWin, 0); |
| 608 | } |
| 609 | #endif |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 610 | break; |
| 611 | } |
| 612 | #ifndef SQLITE_OMIT_SUBQUERY |
| 613 | case TK_EXISTS: { |
drh | 9f6e14c | 2017-07-10 13:24:58 +0000 | [diff] [blame] | 614 | sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 615 | sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); |
| 616 | break; |
| 617 | } |
| 618 | case TK_SELECT: { |
drh | 9f6e14c | 2017-07-10 13:24:58 +0000 | [diff] [blame] | 619 | sqlite3TreeViewLine(pView, "SELECT-expr flags=0x%x", pExpr->flags); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 620 | sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); |
| 621 | break; |
| 622 | } |
| 623 | case TK_IN: { |
drh | 9f6e14c | 2017-07-10 13:24:58 +0000 | [diff] [blame] | 624 | sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 625 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); |
| 626 | if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 627 | sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); |
| 628 | }else{ |
| 629 | sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0); |
| 630 | } |
| 631 | break; |
| 632 | } |
| 633 | #endif /* SQLITE_OMIT_SUBQUERY */ |
| 634 | |
| 635 | /* |
| 636 | ** x BETWEEN y AND z |
| 637 | ** |
| 638 | ** This is equivalent to |
| 639 | ** |
| 640 | ** x>=y AND x<=z |
| 641 | ** |
| 642 | ** X is stored in pExpr->pLeft. |
| 643 | ** Y is stored in pExpr->pList->a[0].pExpr. |
| 644 | ** Z is stored in pExpr->pList->a[1].pExpr. |
| 645 | */ |
| 646 | case TK_BETWEEN: { |
| 647 | Expr *pX = pExpr->pLeft; |
| 648 | Expr *pY = pExpr->x.pList->a[0].pExpr; |
| 649 | Expr *pZ = pExpr->x.pList->a[1].pExpr; |
| 650 | sqlite3TreeViewLine(pView, "BETWEEN"); |
| 651 | sqlite3TreeViewExpr(pView, pX, 1); |
| 652 | sqlite3TreeViewExpr(pView, pY, 1); |
| 653 | sqlite3TreeViewExpr(pView, pZ, 0); |
| 654 | break; |
| 655 | } |
| 656 | case TK_TRIGGER: { |
| 657 | /* If the opcode is TK_TRIGGER, then the expression is a reference |
| 658 | ** to a column in the new.* or old.* pseudo-tables available to |
| 659 | ** trigger programs. In this case Expr.iTable is set to 1 for the |
| 660 | ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn |
| 661 | ** is set to the column of the pseudo-table to read, or to -1 to |
| 662 | ** read the rowid field. |
| 663 | */ |
| 664 | sqlite3TreeViewLine(pView, "%s(%d)", |
| 665 | pExpr->iTable ? "NEW" : "OLD", pExpr->iColumn); |
| 666 | break; |
| 667 | } |
| 668 | case TK_CASE: { |
| 669 | sqlite3TreeViewLine(pView, "CASE"); |
| 670 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); |
| 671 | sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0); |
| 672 | break; |
| 673 | } |
| 674 | #ifndef SQLITE_OMIT_TRIGGER |
| 675 | case TK_RAISE: { |
| 676 | const char *zType = "unk"; |
drh | 1194904 | 2019-08-05 18:01:42 +0000 | [diff] [blame] | 677 | switch( pExpr->affExpr ){ |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 678 | case OE_Rollback: zType = "rollback"; break; |
| 679 | case OE_Abort: zType = "abort"; break; |
| 680 | case OE_Fail: zType = "fail"; break; |
| 681 | case OE_Ignore: zType = "ignore"; break; |
| 682 | } |
| 683 | sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken); |
| 684 | break; |
| 685 | } |
| 686 | #endif |
drh | c84a402 | 2016-05-27 12:30:20 +0000 | [diff] [blame] | 687 | case TK_MATCH: { |
| 688 | sqlite3TreeViewLine(pView, "MATCH {%d:%d}%s", |
| 689 | pExpr->iTable, pExpr->iColumn, zFlgs); |
| 690 | sqlite3TreeViewExpr(pView, pExpr->pRight, 0); |
| 691 | break; |
| 692 | } |
drh | db97e56 | 2016-08-18 17:55:57 +0000 | [diff] [blame] | 693 | case TK_VECTOR: { |
drh | 269d322 | 2019-10-23 18:09:39 +0000 | [diff] [blame] | 694 | char *z = sqlite3_mprintf("VECTOR%s",zFlgs); |
| 695 | sqlite3TreeViewBareExprList(pView, pExpr->x.pList, z); |
| 696 | sqlite3_free(z); |
drh | db97e56 | 2016-08-18 17:55:57 +0000 | [diff] [blame] | 697 | break; |
| 698 | } |
drh | 48cb3a7 | 2016-08-18 18:09:10 +0000 | [diff] [blame] | 699 | case TK_SELECT_COLUMN: { |
| 700 | sqlite3TreeViewLine(pView, "SELECT-COLUMN %d", pExpr->iColumn); |
| 701 | sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0); |
| 702 | break; |
| 703 | } |
drh | 31d6fd5 | 2017-04-14 19:03:10 +0000 | [diff] [blame] | 704 | case TK_IF_NULL_ROW: { |
| 705 | sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable); |
| 706 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 707 | break; |
| 708 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 709 | default: { |
| 710 | sqlite3TreeViewLine(pView, "op=%d", pExpr->op); |
| 711 | break; |
| 712 | } |
| 713 | } |
| 714 | if( zBinOp ){ |
drh | b3d903e | 2015-06-18 14:09:13 +0000 | [diff] [blame] | 715 | sqlite3TreeViewLine(pView, "%s%s", zBinOp, zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 716 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); |
| 717 | sqlite3TreeViewExpr(pView, pExpr->pRight, 0); |
| 718 | }else if( zUniOp ){ |
drh | b3d903e | 2015-06-18 14:09:13 +0000 | [diff] [blame] | 719 | sqlite3TreeViewLine(pView, "%s%s", zUniOp, zFlgs); |
drh | 1194904 | 2019-08-05 18:01:42 +0000 | [diff] [blame] | 720 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 721 | } |
| 722 | sqlite3TreeViewPop(pView); |
| 723 | } |
| 724 | |
drh | db97e56 | 2016-08-18 17:55:57 +0000 | [diff] [blame] | 725 | |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 726 | /* |
| 727 | ** Generate a human-readable explanation of an expression list. |
| 728 | */ |
drh | db97e56 | 2016-08-18 17:55:57 +0000 | [diff] [blame] | 729 | void sqlite3TreeViewBareExprList( |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 730 | TreeView *pView, |
| 731 | const ExprList *pList, |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 732 | const char *zLabel |
| 733 | ){ |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 734 | if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST"; |
| 735 | if( pList==0 ){ |
| 736 | sqlite3TreeViewLine(pView, "%s (empty)", zLabel); |
| 737 | }else{ |
drh | db97e56 | 2016-08-18 17:55:57 +0000 | [diff] [blame] | 738 | int i; |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 739 | sqlite3TreeViewLine(pView, "%s", zLabel); |
| 740 | for(i=0; i<pList->nExpr; i++){ |
drh | 5579d59 | 2015-08-26 14:01:41 +0000 | [diff] [blame] | 741 | int j = pList->a[i].u.x.iOrderByCol; |
drh | 41cee66 | 2019-12-12 20:22:34 +0000 | [diff] [blame] | 742 | char *zName = pList->a[i].zEName; |
drh | fbe0753 | 2018-04-23 20:04:38 +0000 | [diff] [blame] | 743 | int moreToFollow = i<pList->nExpr - 1; |
drh | e1f49b8 | 2020-01-03 00:28:14 +0000 | [diff] [blame] | 744 | if( pList->a[i].eEName!=ENAME_NAME ) zName = 0; |
drh | 5a699a0 | 2017-12-22 19:53:02 +0000 | [diff] [blame] | 745 | if( j || zName ){ |
drh | fbe0753 | 2018-04-23 20:04:38 +0000 | [diff] [blame] | 746 | sqlite3TreeViewPush(pView, moreToFollow); |
| 747 | moreToFollow = 0; |
| 748 | sqlite3TreeViewLine(pView, 0); |
| 749 | if( zName ){ |
| 750 | fprintf(stdout, "AS %s ", zName); |
| 751 | } |
| 752 | if( j ){ |
| 753 | fprintf(stdout, "iOrderByCol=%d", j); |
| 754 | } |
| 755 | fprintf(stdout, "\n"); |
| 756 | fflush(stdout); |
drh | 5a699a0 | 2017-12-22 19:53:02 +0000 | [diff] [blame] | 757 | } |
drh | fbe0753 | 2018-04-23 20:04:38 +0000 | [diff] [blame] | 758 | sqlite3TreeViewExpr(pView, pList->a[i].pExpr, moreToFollow); |
drh | 5a699a0 | 2017-12-22 19:53:02 +0000 | [diff] [blame] | 759 | if( j || zName ){ |
| 760 | sqlite3TreeViewPop(pView); |
| 761 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 762 | } |
| 763 | } |
drh | db97e56 | 2016-08-18 17:55:57 +0000 | [diff] [blame] | 764 | } |
| 765 | void sqlite3TreeViewExprList( |
| 766 | TreeView *pView, |
| 767 | const ExprList *pList, |
| 768 | u8 moreToFollow, |
| 769 | const char *zLabel |
| 770 | ){ |
| 771 | pView = sqlite3TreeViewPush(pView, moreToFollow); |
| 772 | sqlite3TreeViewBareExprList(pView, pList, zLabel); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 773 | sqlite3TreeViewPop(pView); |
| 774 | } |
| 775 | |
| 776 | #endif /* SQLITE_DEBUG */ |