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