4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
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.
11 *************************************************************************
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
17 ** The interfaces in this file is only available when compiling
20 #include "sqliteInt.h"
24 ** Add a new subitem to the tree. The moreToFollow flag indicates that this
25 ** is not the last item in the tree.
27 static TreeView
*sqlite3TreeViewPush(TreeView
*p
, u8 moreToFollow
){
29 p
= sqlite3_malloc64( sizeof(*p
) );
31 memset(p
, 0, sizeof(*p
));
35 assert( moreToFollow
==0 || moreToFollow
==1 );
36 if( p
->iLevel
<sizeof(p
->bLine
) ) p
->bLine
[p
->iLevel
] = moreToFollow
;
41 ** Finished with one layer of the tree
43 static void sqlite3TreeViewPop(TreeView
*p
){
46 if( p
->iLevel
<0 ) sqlite3_free(p
);
50 ** Generate a single line of output for the tree, with a prefix that contains
51 ** all the appropriate tree lines
53 static void sqlite3TreeViewLine(TreeView
*p
, const char *zFormat
, ...){
58 sqlite3StrAccumInit(&acc
, 0, zBuf
, sizeof(zBuf
), 0);
60 for(i
=0; i
<p
->iLevel
&& i
<sizeof(p
->bLine
)-1; i
++){
61 sqlite3_str_append(&acc
, p
->bLine
[i
] ? "| " : " ", 4);
63 sqlite3_str_append(&acc
, p
->bLine
[i
] ? "|-- " : "'-- ", 4);
66 va_start(ap
, zFormat
);
67 sqlite3_str_vappendf(&acc
, zFormat
, ap
);
69 assert( acc
.nChar
>0 || acc
.accError
);
70 sqlite3_str_append(&acc
, "\n", 1);
72 sqlite3StrAccumFinish(&acc
);
73 fprintf(stdout
,"%s", zBuf
);
78 ** Shorthand for starting a new tree item that consists of a single label
80 static void sqlite3TreeViewItem(TreeView
*p
, const char *zLabel
,u8 moreFollows
){
81 p
= sqlite3TreeViewPush(p
, moreFollows
);
82 sqlite3TreeViewLine(p
, "%s", zLabel
);
86 ** Generate a human-readable description of a WITH clause.
88 void sqlite3TreeViewWith(TreeView
*pView
, const With
*pWith
, u8 moreToFollow
){
90 if( pWith
==0 ) return;
91 if( pWith
->nCte
==0 ) return;
93 sqlite3TreeViewLine(pView
, "WITH (0x%p, pOuter=0x%p)",pWith
,pWith
->pOuter
);
95 sqlite3TreeViewLine(pView
, "WITH (0x%p)", pWith
);
98 pView
= sqlite3TreeViewPush(pView
, 1);
99 for(i
=0; i
<pWith
->nCte
; i
++){
102 const struct Cte
*pCte
= &pWith
->a
[i
];
103 sqlite3StrAccumInit(&x
, 0, zLine
, sizeof(zLine
), 0);
104 sqlite3_str_appendf(&x
, "%s", pCte
->zName
);
105 if( pCte
->pCols
&& pCte
->pCols
->nExpr
>0 ){
108 for(j
=0; j
<pCte
->pCols
->nExpr
; j
++){
109 sqlite3_str_appendf(&x
, "%c%s", cSep
, pCte
->pCols
->a
[j
].zEName
);
112 sqlite3_str_appendf(&x
, ")");
114 sqlite3_str_appendf(&x
, " AS");
115 sqlite3StrAccumFinish(&x
);
116 sqlite3TreeViewItem(pView
, zLine
, i
<pWith
->nCte
-1);
117 sqlite3TreeViewSelect(pView
, pCte
->pSelect
, 0);
118 sqlite3TreeViewPop(pView
);
120 sqlite3TreeViewPop(pView
);
125 ** Generate a human-readable description of a SrcList object.
127 void sqlite3TreeViewSrcList(TreeView
*pView
, const SrcList
*pSrc
){
129 for(i
=0; i
<pSrc
->nSrc
; i
++){
130 const struct SrcList_item
*pItem
= &pSrc
->a
[i
];
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
);
141 sqlite3_str_appendf(&x
, " tab=%Q nCol=%d ptr=%p used=%llx",
142 pItem
->pTab
->zName
, pItem
->pTab
->nCol
, pItem
->pTab
, pItem
->colUsed
);
145 sqlite3_str_appendf(&x
, " (AS %s)", pItem
->zAlias
);
147 if( pItem
->fg
.jointype
& JT_LEFT
){
148 sqlite3_str_appendf(&x
, " LEFT-JOIN");
150 if( pItem
->fg
.fromDDL
){
151 sqlite3_str_appendf(&x
, " DDL");
153 sqlite3StrAccumFinish(&x
);
154 sqlite3TreeViewItem(pView
, zLine
, i
<pSrc
->nSrc
-1);
155 if( pItem
->pSelect
){
156 sqlite3TreeViewSelect(pView
, pItem
->pSelect
, 0);
158 if( pItem
->fg
.isTabFunc
){
159 sqlite3TreeViewExprList(pView
, pItem
->u1
.pFuncArg
, 0, "func-args:");
161 sqlite3TreeViewPop(pView
);
166 ** Generate a human-readable description of a Select object.
168 void sqlite3TreeViewSelect(TreeView
*pView
, const Select
*p
, u8 moreToFollow
){
172 sqlite3TreeViewLine(pView
, "nil-SELECT");
175 pView
= sqlite3TreeViewPush(pView
, moreToFollow
);
177 sqlite3TreeViewWith(pView
, p
->pWith
, 1);
179 sqlite3TreeViewPush(pView
, 1);
182 if( p
->selFlags
& SF_WhereBegin
){
183 sqlite3TreeViewLine(pView
, "sqlite3WhereBegin()");
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
,
193 if( cnt
++ ) sqlite3TreeViewPop(pView
);
198 if( p
->pSrc
&& p
->pSrc
->nSrc
) n
++;
200 if( p
->pGroupBy
) n
++;
201 if( p
->pHaving
) n
++;
202 if( p
->pOrderBy
) n
++;
204 #ifndef SQLITE_OMIT_WINDOWFUNC
206 if( p
->pWinDefn
) n
++;
210 sqlite3TreeViewExprList(pView
, p
->pEList
, n
>0, "result-set");
213 #ifndef SQLITE_OMIT_WINDOWFUNC
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);
221 sqlite3TreeViewPop(pView
);
224 if( p
->pSrc
&& p
->pSrc
->nSrc
){
225 pView
= sqlite3TreeViewPush(pView
, (n
--)>0);
226 sqlite3TreeViewLine(pView
, "FROM");
227 sqlite3TreeViewSrcList(pView
, p
->pSrc
);
228 sqlite3TreeViewPop(pView
);
231 sqlite3TreeViewItem(pView
, "WHERE", (n
--)>0);
232 sqlite3TreeViewExpr(pView
, p
->pWhere
, 0);
233 sqlite3TreeViewPop(pView
);
236 sqlite3TreeViewExprList(pView
, p
->pGroupBy
, (n
--)>0, "GROUPBY");
239 sqlite3TreeViewItem(pView
, "HAVING", (n
--)>0);
240 sqlite3TreeViewExpr(pView
, p
->pHaving
, 0);
241 sqlite3TreeViewPop(pView
);
243 #ifndef SQLITE_OMIT_WINDOWFUNC
246 sqlite3TreeViewItem(pView
, "WINDOW", (n
--)>0);
247 for(pX
=p
->pWinDefn
; pX
; pX
=pX
->pNextWin
){
248 sqlite3TreeViewWindow(pView
, pX
, pX
->pNextWin
!=0);
250 sqlite3TreeViewPop(pView
);
254 sqlite3TreeViewExprList(pView
, p
->pOrderBy
, (n
--)>0, "ORDERBY");
257 sqlite3TreeViewItem(pView
, "LIMIT", (n
--)>0);
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
);
264 sqlite3TreeViewPop(pView
);
267 const char *zOp
= "UNION";
269 case TK_ALL
: zOp
= "UNION ALL"; break;
270 case TK_INTERSECT
: zOp
= "INTERSECT"; break;
271 case TK_EXCEPT
: zOp
= "EXCEPT"; break;
273 sqlite3TreeViewItem(pView
, zOp
, 1);
277 sqlite3TreeViewPop(pView
);
280 #ifndef SQLITE_OMIT_WINDOWFUNC
282 ** Generate a description of starting or stopping bounds
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 */
292 sqlite3TreeViewItem(pView
, "UNBOUNDED", moreToFollow
);
293 sqlite3TreeViewPop(pView
);
297 sqlite3TreeViewItem(pView
, "CURRENT", moreToFollow
);
298 sqlite3TreeViewPop(pView
);
302 sqlite3TreeViewItem(pView
, "PRECEDING", moreToFollow
);
303 sqlite3TreeViewExpr(pView
, pExpr
, 0);
304 sqlite3TreeViewPop(pView
);
308 sqlite3TreeViewItem(pView
, "FOLLOWING", moreToFollow
);
309 sqlite3TreeViewExpr(pView
, pExpr
, 0);
310 sqlite3TreeViewPop(pView
);
315 #endif /* SQLITE_OMIT_WINDOWFUNC */
317 #ifndef SQLITE_OMIT_WINDOWFUNC
319 ** Generate a human-readable explanation for a Window object
321 void sqlite3TreeViewWindow(TreeView
*pView
, const Window
*pWin
, u8 more
){
324 sqlite3TreeViewItem(pView
, "FILTER", 1);
325 sqlite3TreeViewExpr(pView
, pWin
->pFilter
, 0);
326 sqlite3TreeViewPop(pView
);
328 pView
= sqlite3TreeViewPush(pView
, more
);
330 sqlite3TreeViewLine(pView
, "OVER %s (%p)", pWin
->zName
, pWin
);
332 sqlite3TreeViewLine(pView
, "OVER (%p)", pWin
);
334 if( pWin
->zBase
) nElement
++;
335 if( pWin
->pOrderBy
) nElement
++;
336 if( pWin
->eFrmType
) nElement
++;
337 if( pWin
->eExclude
) nElement
++;
339 sqlite3TreeViewPush(pView
, (--nElement
)>0);
340 sqlite3TreeViewLine(pView
, "window: %s", pWin
->zBase
);
341 sqlite3TreeViewPop(pView
);
343 if( pWin
->pPartition
){
344 sqlite3TreeViewExprList(pView
, pWin
->pPartition
, nElement
>0,"PARTITION-BY");
346 if( pWin
->pOrderBy
){
347 sqlite3TreeViewExprList(pView
, pWin
->pOrderBy
, (--nElement
)>0, "ORDER-BY");
349 if( pWin
->eFrmType
){
351 const char *zFrmType
= "ROWS";
352 if( pWin
->eFrmType
==TK_RANGE
) zFrmType
= "RANGE";
353 if( pWin
->eFrmType
==TK_GROUPS
) zFrmType
= "GROUPS";
354 sqlite3_snprintf(sizeof(zBuf
),zBuf
,"%s%s",zFrmType
,
355 pWin
->bImplicitFrame
? " (implied)" : "");
356 sqlite3TreeViewItem(pView
, zBuf
, (--nElement
)>0);
357 sqlite3TreeViewBound(pView
, pWin
->eStart
, pWin
->pStart
, 1);
358 sqlite3TreeViewBound(pView
, pWin
->eEnd
, pWin
->pEnd
, 0);
359 sqlite3TreeViewPop(pView
);
361 if( pWin
->eExclude
){
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;
370 sqlite3_snprintf(sizeof(zBuf
),zBuf
,"invalid(%d)", pWin
->eExclude
);
374 sqlite3TreeViewPush(pView
, 0);
375 sqlite3TreeViewLine(pView
, "EXCLUDE %s", zExclude
);
376 sqlite3TreeViewPop(pView
);
378 sqlite3TreeViewPop(pView
);
380 #endif /* SQLITE_OMIT_WINDOWFUNC */
382 #ifndef SQLITE_OMIT_WINDOWFUNC
384 ** Generate a human-readable explanation for a Window Function object
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
);
393 #endif /* SQLITE_OMIT_WINDOWFUNC */
396 ** Generate a human-readable explanation of an expression tree.
398 void sqlite3TreeViewExpr(TreeView
*pView
, const Expr
*pExpr
, u8 moreToFollow
){
399 const char *zBinOp
= 0; /* Binary operator */
400 const char *zUniOp
= 0; /* Unary operator */
402 pView
= sqlite3TreeViewPush(pView
, moreToFollow
);
404 sqlite3TreeViewLine(pView
, "nil");
405 sqlite3TreeViewPop(pView
);
408 if( pExpr
->flags
|| pExpr
->affExpr
|| pExpr
->vvaFlags
){
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');
413 if( ExprHasProperty(pExpr
, EP_FromJoin
) ){
414 sqlite3_str_appendf(&x
, " iRJT=%d", pExpr
->iRightJoinTable
);
416 if( ExprHasProperty(pExpr
, EP_FromDDL
) ){
417 sqlite3_str_appendf(&x
, " DDL");
419 if( ExprHasVVAProperty(pExpr
, EP_Immutable
) ){
420 sqlite3_str_appendf(&x
, " IMMUTABLE");
422 sqlite3StrAccumFinish(&x
);
427 case TK_AGG_COLUMN
: {
428 sqlite3TreeViewLine(pView
, "AGG{%d:%d}%s",
429 pExpr
->iTable
, pExpr
->iColumn
, zFlgs
);
433 if( pExpr
->iTable
<0 ){
434 /* This only happens when coding check constraints */
437 sqlite3_snprintf(sizeof(zOp2
),zOp2
," op2=0x%02x",pExpr
->op2
);
441 sqlite3TreeViewLine(pView
, "COLUMN(%d)%s%s",
442 pExpr
->iColumn
, zFlgs
, zOp2
);
444 sqlite3TreeViewLine(pView
, "{%d:%d} pTab=%p%s",
445 pExpr
->iTable
, pExpr
->iColumn
,
446 pExpr
->y
.pTab
, zFlgs
);
448 if( ExprHasProperty(pExpr
, EP_FixedCol
) ){
449 sqlite3TreeViewExpr(pView
, pExpr
->pLeft
, 0);
454 if( pExpr
->flags
& EP_IntValue
){
455 sqlite3TreeViewLine(pView
, "%d", pExpr
->u
.iValue
);
457 sqlite3TreeViewLine(pView
, "%s", pExpr
->u
.zToken
);
461 #ifndef SQLITE_OMIT_FLOATING_POINT
463 sqlite3TreeViewLine(pView
,"%s", pExpr
->u
.zToken
);
468 sqlite3TreeViewLine(pView
,"%Q", pExpr
->u
.zToken
);
472 sqlite3TreeViewLine(pView
,"NULL");
476 sqlite3TreeViewLine(pView
,
477 sqlite3ExprTruthValue(pExpr
) ? "TRUE" : "FALSE");
480 #ifndef SQLITE_OMIT_BLOB_LITERAL
482 sqlite3TreeViewLine(pView
,"%s", pExpr
->u
.zToken
);
487 sqlite3TreeViewLine(pView
,"VARIABLE(%s,%d)",
488 pExpr
->u
.zToken
, pExpr
->iColumn
);
492 sqlite3TreeViewLine(pView
,"REGISTER(%d)", pExpr
->iTable
);
496 sqlite3TreeViewLine(pView
,"ID \"%w\"", pExpr
->u
.zToken
);
499 #ifndef SQLITE_OMIT_CAST
501 /* Expressions of the form: CAST(pLeft AS token) */
502 sqlite3TreeViewLine(pView
,"CAST %Q", pExpr
->u
.zToken
);
503 sqlite3TreeViewExpr(pView
, pExpr
->pLeft
, 0);
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;
528 case TK_LIMIT
: zBinOp
= "LIMIT"; break;
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;
539 const char *azOp
[] = {
540 "IS-FALSE", "IS-TRUE", "IS-NOT-FALSE", "IS-NOT-TRUE"
542 assert( pExpr
->op2
==TK_IS
|| pExpr
->op2
==TK_ISNOT
);
543 assert( pExpr
->pRight
);
544 assert( sqlite3ExprSkipCollate(pExpr
->pRight
)->op
==TK_TRUEFALSE
);
545 x
= (pExpr
->op2
==TK_ISNOT
)*2 + sqlite3ExprTruthValue(pExpr
->pRight
);
551 sqlite3TreeViewLine(pView
, "SPAN %Q", pExpr
->u
.zToken
);
552 sqlite3TreeViewExpr(pView
, pExpr
->pLeft
, 0);
557 /* COLLATE operators without the EP_Collate flag are intended to
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" */
562 sqlite3TreeViewLine(pView
, "%sCOLLATE %Q%s",
563 !ExprHasProperty(pExpr
, EP_Collate
) ? "SOFT-" : "",
564 pExpr
->u
.zToken
, zFlgs
);
565 sqlite3TreeViewExpr(pView
, pExpr
->pLeft
, 0);
569 case TK_AGG_FUNCTION
:
571 ExprList
*pFarg
; /* List of function arguments */
573 if( ExprHasProperty(pExpr
, EP_TokenOnly
) ){
577 pFarg
= pExpr
->x
.pList
;
578 #ifndef SQLITE_OMIT_WINDOWFUNC
579 pWin
= ExprHasProperty(pExpr
, EP_WinFunc
) ? pExpr
->y
.pWin
: 0;
584 if( pExpr
->op
==TK_AGG_FUNCTION
){
585 sqlite3TreeViewLine(pView
, "AGG_FUNCTION%d %Q%s agg=%d[%d]/%p",
586 pExpr
->op2
, pExpr
->u
.zToken
, zFlgs
,
587 pExpr
->pAggInfo
? pExpr
->pAggInfo
->selId
: 0,
588 pExpr
->iAgg
, pExpr
->pAggInfo
);
589 }else if( pExpr
->op2
!=0 ){
592 sqlite3_snprintf(sizeof(zBuf
),zBuf
,"0x%02x",pExpr
->op2
);
594 if( pExpr
->op2
==NC_IsCheck
) zOp2
= "NC_IsCheck";
595 if( pExpr
->op2
==NC_IdxExpr
) zOp2
= "NC_IdxExpr";
596 if( pExpr
->op2
==NC_PartIdx
) zOp2
= "NC_PartIdx";
597 if( pExpr
->op2
==NC_GenCol
) zOp2
= "NC_GenCol";
598 sqlite3TreeViewLine(pView
, "FUNCTION %Q%s op2=%s",
599 pExpr
->u
.zToken
, zFlgs
, zOp2
);
601 sqlite3TreeViewLine(pView
, "FUNCTION %Q%s", pExpr
->u
.zToken
, zFlgs
);
604 sqlite3TreeViewExprList(pView
, pFarg
, pWin
!=0, 0);
606 #ifndef SQLITE_OMIT_WINDOWFUNC
608 sqlite3TreeViewWindow(pView
, pWin
, 0);
613 #ifndef SQLITE_OMIT_SUBQUERY
615 sqlite3TreeViewLine(pView
, "EXISTS-expr flags=0x%x", pExpr
->flags
);
616 sqlite3TreeViewSelect(pView
, pExpr
->x
.pSelect
, 0);
620 sqlite3TreeViewLine(pView
, "subquery-expr flags=0x%x", pExpr
->flags
);
621 sqlite3TreeViewSelect(pView
, pExpr
->x
.pSelect
, 0);
625 sqlite3TreeViewLine(pView
, "IN flags=0x%x", pExpr
->flags
);
626 sqlite3TreeViewExpr(pView
, pExpr
->pLeft
, 1);
627 if( ExprHasProperty(pExpr
, EP_xIsSelect
) ){
628 sqlite3TreeViewSelect(pView
, pExpr
->x
.pSelect
, 0);
630 sqlite3TreeViewExprList(pView
, pExpr
->x
.pList
, 0, 0);
634 #endif /* SQLITE_OMIT_SUBQUERY */
639 ** This is equivalent to
643 ** X is stored in pExpr->pLeft.
644 ** Y is stored in pExpr->pList->a[0].pExpr.
645 ** Z is stored in pExpr->pList->a[1].pExpr.
648 Expr
*pX
= pExpr
->pLeft
;
649 Expr
*pY
= pExpr
->x
.pList
->a
[0].pExpr
;
650 Expr
*pZ
= pExpr
->x
.pList
->a
[1].pExpr
;
651 sqlite3TreeViewLine(pView
, "BETWEEN");
652 sqlite3TreeViewExpr(pView
, pX
, 1);
653 sqlite3TreeViewExpr(pView
, pY
, 1);
654 sqlite3TreeViewExpr(pView
, pZ
, 0);
658 /* If the opcode is TK_TRIGGER, then the expression is a reference
659 ** to a column in the new.* or old.* pseudo-tables available to
660 ** trigger programs. In this case Expr.iTable is set to 1 for the
661 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn
662 ** is set to the column of the pseudo-table to read, or to -1 to
663 ** read the rowid field.
665 sqlite3TreeViewLine(pView
, "%s(%d)",
666 pExpr
->iTable
? "NEW" : "OLD", pExpr
->iColumn
);
670 sqlite3TreeViewLine(pView
, "CASE");
671 sqlite3TreeViewExpr(pView
, pExpr
->pLeft
, 1);
672 sqlite3TreeViewExprList(pView
, pExpr
->x
.pList
, 0, 0);
675 #ifndef SQLITE_OMIT_TRIGGER
677 const char *zType
= "unk";
678 switch( pExpr
->affExpr
){
679 case OE_Rollback
: zType
= "rollback"; break;
680 case OE_Abort
: zType
= "abort"; break;
681 case OE_Fail
: zType
= "fail"; break;
682 case OE_Ignore
: zType
= "ignore"; break;
684 sqlite3TreeViewLine(pView
, "RAISE %s(%Q)", zType
, pExpr
->u
.zToken
);
689 sqlite3TreeViewLine(pView
, "MATCH {%d:%d}%s",
690 pExpr
->iTable
, pExpr
->iColumn
, zFlgs
);
691 sqlite3TreeViewExpr(pView
, pExpr
->pRight
, 0);
695 char *z
= sqlite3_mprintf("VECTOR%s",zFlgs
);
696 sqlite3TreeViewBareExprList(pView
, pExpr
->x
.pList
, z
);
700 case TK_SELECT_COLUMN
: {
701 sqlite3TreeViewLine(pView
, "SELECT-COLUMN %d", pExpr
->iColumn
);
702 sqlite3TreeViewSelect(pView
, pExpr
->pLeft
->x
.pSelect
, 0);
705 case TK_IF_NULL_ROW
: {
706 sqlite3TreeViewLine(pView
, "IF-NULL-ROW %d", pExpr
->iTable
);
707 sqlite3TreeViewExpr(pView
, pExpr
->pLeft
, 0);
711 sqlite3TreeViewLine(pView
, "op=%d", pExpr
->op
);
716 sqlite3TreeViewLine(pView
, "%s%s", zBinOp
, zFlgs
);
717 sqlite3TreeViewExpr(pView
, pExpr
->pLeft
, 1);
718 sqlite3TreeViewExpr(pView
, pExpr
->pRight
, 0);
720 sqlite3TreeViewLine(pView
, "%s%s", zUniOp
, zFlgs
);
721 sqlite3TreeViewExpr(pView
, pExpr
->pLeft
, 0);
723 sqlite3TreeViewPop(pView
);
728 ** Generate a human-readable explanation of an expression list.
730 void sqlite3TreeViewBareExprList(
732 const ExprList
*pList
,
735 if( zLabel
==0 || zLabel
[0]==0 ) zLabel
= "LIST";
737 sqlite3TreeViewLine(pView
, "%s (empty)", zLabel
);
740 sqlite3TreeViewLine(pView
, "%s", zLabel
);
741 for(i
=0; i
<pList
->nExpr
; i
++){
742 int j
= pList
->a
[i
].u
.x
.iOrderByCol
;
743 char *zName
= pList
->a
[i
].zEName
;
744 int moreToFollow
= i
<pList
->nExpr
- 1;
745 if( pList
->a
[i
].eEName
!=ENAME_NAME
) zName
= 0;
747 sqlite3TreeViewPush(pView
, moreToFollow
);
749 sqlite3TreeViewLine(pView
, 0);
751 fprintf(stdout
, "AS %s ", zName
);
754 fprintf(stdout
, "iOrderByCol=%d", j
);
756 fprintf(stdout
, "\n");
759 sqlite3TreeViewExpr(pView
, pList
->a
[i
].pExpr
, moreToFollow
);
761 sqlite3TreeViewPop(pView
);
766 void sqlite3TreeViewExprList(
768 const ExprList
*pList
,
772 pView
= sqlite3TreeViewPush(pView
, moreToFollow
);
773 sqlite3TreeViewBareExprList(pView
, pList
, zLabel
);
774 sqlite3TreeViewPop(pView
);
777 #endif /* SQLITE_DEBUG */