Snapshot of upstream SQLite 3.43.1
[sqlcipher.git] / src / treeview.c
blobd55adab384d5ac916daa24ae1834f5f92c1fb07c
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.
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
15 ** analysis.
17 ** The interfaces in this file is only available when compiling
18 ** with SQLITE_DEBUG.
20 #include "sqliteInt.h"
21 #ifdef SQLITE_DEBUG
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 void sqlite3TreeViewPush(TreeView **pp, u8 moreToFollow){
28 TreeView *p = *pp;
29 if( p==0 ){
30 *pp = p = sqlite3_malloc64( sizeof(*p) );
31 if( p==0 ) return;
32 memset(p, 0, sizeof(*p));
33 }else{
34 p->iLevel++;
36 assert( moreToFollow==0 || moreToFollow==1 );
37 if( p->iLevel<(int)sizeof(p->bLine) ) p->bLine[p->iLevel] = moreToFollow;
41 ** Finished with one layer of the tree
43 static void sqlite3TreeViewPop(TreeView **pp){
44 TreeView *p = *pp;
45 if( p==0 ) return;
46 p->iLevel--;
47 if( p->iLevel<0 ){
48 sqlite3_free(p);
49 *pp = 0;
54 ** Generate a single line of output for the tree, with a prefix that contains
55 ** all the appropriate tree lines
57 void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){
58 va_list ap;
59 int i;
60 StrAccum acc;
61 char zBuf[1000];
62 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
63 if( p ){
64 for(i=0; i<p->iLevel && i<(int)sizeof(p->bLine)-1; i++){
65 sqlite3_str_append(&acc, p->bLine[i] ? "| " : " ", 4);
67 sqlite3_str_append(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
69 if( zFormat!=0 ){
70 va_start(ap, zFormat);
71 sqlite3_str_vappendf(&acc, zFormat, ap);
72 va_end(ap);
73 assert( acc.nChar>0 || acc.accError );
74 sqlite3_str_append(&acc, "\n", 1);
76 sqlite3StrAccumFinish(&acc);
77 fprintf(stdout,"%s", zBuf);
78 fflush(stdout);
82 ** Shorthand for starting a new tree item that consists of a single label
84 static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){
85 sqlite3TreeViewPush(&p, moreFollows);
86 sqlite3TreeViewLine(p, "%s", zLabel);
90 ** Show a list of Column objects in tree format.
92 void sqlite3TreeViewColumnList(
93 TreeView *pView,
94 const Column *aCol,
95 int nCol,
96 u8 moreToFollow
98 int i;
99 sqlite3TreeViewPush(&pView, moreToFollow);
100 sqlite3TreeViewLine(pView, "COLUMNS");
101 for(i=0; i<nCol; i++){
102 u16 flg = aCol[i].colFlags;
103 int colMoreToFollow = i<(nCol - 1);
104 sqlite3TreeViewPush(&pView, colMoreToFollow);
105 sqlite3TreeViewLine(pView, 0);
106 printf(" %s", aCol[i].zCnName);
107 switch( aCol[i].eCType ){
108 case COLTYPE_ANY: printf(" ANY"); break;
109 case COLTYPE_BLOB: printf(" BLOB"); break;
110 case COLTYPE_INT: printf(" INT"); break;
111 case COLTYPE_INTEGER: printf(" INTEGER"); break;
112 case COLTYPE_REAL: printf(" REAL"); break;
113 case COLTYPE_TEXT: printf(" TEXT"); break;
114 case COLTYPE_CUSTOM: {
115 if( flg & COLFLAG_HASTYPE ){
116 const char *z = aCol[i].zCnName;
117 z += strlen(z)+1;
118 printf(" X-%s", z);
119 break;
123 if( flg & COLFLAG_PRIMKEY ) printf(" PRIMARY KEY");
124 if( flg & COLFLAG_HIDDEN ) printf(" HIDDEN");
125 #ifdef COLFLAG_NOEXPAND
126 if( flg & COLFLAG_NOEXPAND ) printf(" NO-EXPAND");
127 #endif
128 if( flg ) printf(" flags=%04x", flg);
129 printf("\n");
130 fflush(stdout);
131 sqlite3TreeViewPop(&pView);
133 sqlite3TreeViewPop(&pView);
137 ** Generate a human-readable description of a WITH clause.
139 void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){
140 int i;
141 if( pWith==0 ) return;
142 if( pWith->nCte==0 ) return;
143 if( pWith->pOuter ){
144 sqlite3TreeViewLine(pView, "WITH (0x%p, pOuter=0x%p)",pWith,pWith->pOuter);
145 }else{
146 sqlite3TreeViewLine(pView, "WITH (0x%p)", pWith);
148 if( pWith->nCte>0 ){
149 sqlite3TreeViewPush(&pView, moreToFollow);
150 for(i=0; i<pWith->nCte; i++){
151 StrAccum x;
152 char zLine[1000];
153 const struct Cte *pCte = &pWith->a[i];
154 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
155 sqlite3_str_appendf(&x, "%s", pCte->zName);
156 if( pCte->pCols && pCte->pCols->nExpr>0 ){
157 char cSep = '(';
158 int j;
159 for(j=0; j<pCte->pCols->nExpr; j++){
160 sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zEName);
161 cSep = ',';
163 sqlite3_str_appendf(&x, ")");
165 if( pCte->eM10d!=M10d_Any ){
166 sqlite3_str_appendf(&x, " %sMATERIALIZED",
167 pCte->eM10d==M10d_No ? "NOT " : "");
169 if( pCte->pUse ){
170 sqlite3_str_appendf(&x, " (pUse=0x%p, nUse=%d)", pCte->pUse,
171 pCte->pUse->nUse);
173 sqlite3StrAccumFinish(&x);
174 sqlite3TreeViewItem(pView, zLine, i<pWith->nCte-1);
175 sqlite3TreeViewSelect(pView, pCte->pSelect, 0);
176 sqlite3TreeViewPop(&pView);
178 sqlite3TreeViewPop(&pView);
183 ** Generate a human-readable description of a SrcList object.
185 void sqlite3TreeViewSrcList(TreeView *pView, const SrcList *pSrc){
186 int i;
187 if( pSrc==0 ) return;
188 for(i=0; i<pSrc->nSrc; i++){
189 const SrcItem *pItem = &pSrc->a[i];
190 StrAccum x;
191 int n = 0;
192 char zLine[1000];
193 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
194 x.printfFlags |= SQLITE_PRINTF_INTERNAL;
195 sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem);
196 if( pItem->pTab ){
197 sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx",
198 pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, pItem->colUsed);
200 if( (pItem->fg.jointype & (JT_LEFT|JT_RIGHT))==(JT_LEFT|JT_RIGHT) ){
201 sqlite3_str_appendf(&x, " FULL-OUTER-JOIN");
202 }else if( pItem->fg.jointype & JT_LEFT ){
203 sqlite3_str_appendf(&x, " LEFT-JOIN");
204 }else if( pItem->fg.jointype & JT_RIGHT ){
205 sqlite3_str_appendf(&x, " RIGHT-JOIN");
206 }else if( pItem->fg.jointype & JT_CROSS ){
207 sqlite3_str_appendf(&x, " CROSS-JOIN");
209 if( pItem->fg.jointype & JT_LTORJ ){
210 sqlite3_str_appendf(&x, " LTORJ");
212 if( pItem->fg.fromDDL ){
213 sqlite3_str_appendf(&x, " DDL");
215 if( pItem->fg.isCte ){
216 sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse);
218 if( pItem->fg.isOn || (pItem->fg.isUsing==0 && pItem->u3.pOn!=0) ){
219 sqlite3_str_appendf(&x, " ON");
221 if( pItem->fg.isTabFunc ) sqlite3_str_appendf(&x, " isTabFunc");
222 if( pItem->fg.isCorrelated ) sqlite3_str_appendf(&x, " isCorrelated");
223 if( pItem->fg.isMaterialized ) sqlite3_str_appendf(&x, " isMaterialized");
224 if( pItem->fg.viaCoroutine ) sqlite3_str_appendf(&x, " viaCoroutine");
225 if( pItem->fg.notCte ) sqlite3_str_appendf(&x, " notCte");
226 if( pItem->fg.isNestedFrom ) sqlite3_str_appendf(&x, " isNestedFrom");
228 sqlite3StrAccumFinish(&x);
229 sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
230 n = 0;
231 if( pItem->pSelect ) n++;
232 if( pItem->fg.isTabFunc ) n++;
233 if( pItem->fg.isUsing ) n++;
234 if( pItem->fg.isUsing ){
235 sqlite3TreeViewIdList(pView, pItem->u3.pUsing, (--n)>0, "USING");
237 if( pItem->pSelect ){
238 if( pItem->pTab ){
239 Table *pTab = pItem->pTab;
240 sqlite3TreeViewColumnList(pView, pTab->aCol, pTab->nCol, 1);
242 assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
243 sqlite3TreeViewSelect(pView, pItem->pSelect, (--n)>0);
245 if( pItem->fg.isTabFunc ){
246 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
248 sqlite3TreeViewPop(&pView);
253 ** Generate a human-readable description of a Select object.
255 void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
256 int n = 0;
257 int cnt = 0;
258 if( p==0 ){
259 sqlite3TreeViewLine(pView, "nil-SELECT");
260 return;
262 sqlite3TreeViewPush(&pView, moreToFollow);
263 if( p->pWith ){
264 sqlite3TreeViewWith(pView, p->pWith, 1);
265 cnt = 1;
266 sqlite3TreeViewPush(&pView, 1);
269 if( p->selFlags & SF_WhereBegin ){
270 sqlite3TreeViewLine(pView, "sqlite3WhereBegin()");
271 }else{
272 sqlite3TreeViewLine(pView,
273 "SELECT%s%s (%u/%p) selFlags=0x%x nSelectRow=%d",
274 ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
275 ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""),
276 p->selId, p, p->selFlags,
277 (int)p->nSelectRow
280 if( cnt++ ) sqlite3TreeViewPop(&pView);
281 if( p->pPrior ){
282 n = 1000;
283 }else{
284 n = 0;
285 if( p->pSrc && p->pSrc->nSrc ) n++;
286 if( p->pWhere ) n++;
287 if( p->pGroupBy ) n++;
288 if( p->pHaving ) n++;
289 if( p->pOrderBy ) n++;
290 if( p->pLimit ) n++;
291 #ifndef SQLITE_OMIT_WINDOWFUNC
292 if( p->pWin ) n++;
293 if( p->pWinDefn ) n++;
294 #endif
296 if( p->pEList ){
297 sqlite3TreeViewExprList(pView, p->pEList, n>0, "result-set");
299 n--;
300 #ifndef SQLITE_OMIT_WINDOWFUNC
301 if( p->pWin ){
302 Window *pX;
303 sqlite3TreeViewPush(&pView, (n--)>0);
304 sqlite3TreeViewLine(pView, "window-functions");
305 for(pX=p->pWin; pX; pX=pX->pNextWin){
306 sqlite3TreeViewWinFunc(pView, pX, pX->pNextWin!=0);
308 sqlite3TreeViewPop(&pView);
310 #endif
311 if( p->pSrc && p->pSrc->nSrc ){
312 sqlite3TreeViewPush(&pView, (n--)>0);
313 sqlite3TreeViewLine(pView, "FROM");
314 sqlite3TreeViewSrcList(pView, p->pSrc);
315 sqlite3TreeViewPop(&pView);
317 if( p->pWhere ){
318 sqlite3TreeViewItem(pView, "WHERE", (n--)>0);
319 sqlite3TreeViewExpr(pView, p->pWhere, 0);
320 sqlite3TreeViewPop(&pView);
322 if( p->pGroupBy ){
323 sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY");
325 if( p->pHaving ){
326 sqlite3TreeViewItem(pView, "HAVING", (n--)>0);
327 sqlite3TreeViewExpr(pView, p->pHaving, 0);
328 sqlite3TreeViewPop(&pView);
330 #ifndef SQLITE_OMIT_WINDOWFUNC
331 if( p->pWinDefn ){
332 Window *pX;
333 sqlite3TreeViewItem(pView, "WINDOW", (n--)>0);
334 for(pX=p->pWinDefn; pX; pX=pX->pNextWin){
335 sqlite3TreeViewWindow(pView, pX, pX->pNextWin!=0);
337 sqlite3TreeViewPop(&pView);
339 #endif
340 if( p->pOrderBy ){
341 sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY");
343 if( p->pLimit ){
344 sqlite3TreeViewItem(pView, "LIMIT", (n--)>0);
345 sqlite3TreeViewExpr(pView, p->pLimit->pLeft, p->pLimit->pRight!=0);
346 if( p->pLimit->pRight ){
347 sqlite3TreeViewItem(pView, "OFFSET", (n--)>0);
348 sqlite3TreeViewExpr(pView, p->pLimit->pRight, 0);
349 sqlite3TreeViewPop(&pView);
351 sqlite3TreeViewPop(&pView);
353 if( p->pPrior ){
354 const char *zOp = "UNION";
355 switch( p->op ){
356 case TK_ALL: zOp = "UNION ALL"; break;
357 case TK_INTERSECT: zOp = "INTERSECT"; break;
358 case TK_EXCEPT: zOp = "EXCEPT"; break;
360 sqlite3TreeViewItem(pView, zOp, 1);
362 p = p->pPrior;
363 }while( p!=0 );
364 sqlite3TreeViewPop(&pView);
367 #ifndef SQLITE_OMIT_WINDOWFUNC
369 ** Generate a description of starting or stopping bounds
371 void sqlite3TreeViewBound(
372 TreeView *pView, /* View context */
373 u8 eBound, /* UNBOUNDED, CURRENT, PRECEDING, FOLLOWING */
374 Expr *pExpr, /* Value for PRECEDING or FOLLOWING */
375 u8 moreToFollow /* True if more to follow */
377 switch( eBound ){
378 case TK_UNBOUNDED: {
379 sqlite3TreeViewItem(pView, "UNBOUNDED", moreToFollow);
380 sqlite3TreeViewPop(&pView);
381 break;
383 case TK_CURRENT: {
384 sqlite3TreeViewItem(pView, "CURRENT", moreToFollow);
385 sqlite3TreeViewPop(&pView);
386 break;
388 case TK_PRECEDING: {
389 sqlite3TreeViewItem(pView, "PRECEDING", moreToFollow);
390 sqlite3TreeViewExpr(pView, pExpr, 0);
391 sqlite3TreeViewPop(&pView);
392 break;
394 case TK_FOLLOWING: {
395 sqlite3TreeViewItem(pView, "FOLLOWING", moreToFollow);
396 sqlite3TreeViewExpr(pView, pExpr, 0);
397 sqlite3TreeViewPop(&pView);
398 break;
402 #endif /* SQLITE_OMIT_WINDOWFUNC */
404 #ifndef SQLITE_OMIT_WINDOWFUNC
406 ** Generate a human-readable explanation for a Window object
408 void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){
409 int nElement = 0;
410 if( pWin==0 ) return;
411 if( pWin->pFilter ){
412 sqlite3TreeViewItem(pView, "FILTER", 1);
413 sqlite3TreeViewExpr(pView, pWin->pFilter, 0);
414 sqlite3TreeViewPop(&pView);
416 sqlite3TreeViewPush(&pView, more);
417 if( pWin->zName ){
418 sqlite3TreeViewLine(pView, "OVER %s (%p)", pWin->zName, pWin);
419 }else{
420 sqlite3TreeViewLine(pView, "OVER (%p)", pWin);
422 if( pWin->zBase ) nElement++;
423 if( pWin->pOrderBy ) nElement++;
424 if( pWin->eFrmType ) nElement++;
425 if( pWin->eExclude ) nElement++;
426 if( pWin->zBase ){
427 sqlite3TreeViewPush(&pView, (--nElement)>0);
428 sqlite3TreeViewLine(pView, "window: %s", pWin->zBase);
429 sqlite3TreeViewPop(&pView);
431 if( pWin->pPartition ){
432 sqlite3TreeViewExprList(pView, pWin->pPartition, nElement>0,"PARTITION-BY");
434 if( pWin->pOrderBy ){
435 sqlite3TreeViewExprList(pView, pWin->pOrderBy, (--nElement)>0, "ORDER-BY");
437 if( pWin->eFrmType ){
438 char zBuf[30];
439 const char *zFrmType = "ROWS";
440 if( pWin->eFrmType==TK_RANGE ) zFrmType = "RANGE";
441 if( pWin->eFrmType==TK_GROUPS ) zFrmType = "GROUPS";
442 sqlite3_snprintf(sizeof(zBuf),zBuf,"%s%s",zFrmType,
443 pWin->bImplicitFrame ? " (implied)" : "");
444 sqlite3TreeViewItem(pView, zBuf, (--nElement)>0);
445 sqlite3TreeViewBound(pView, pWin->eStart, pWin->pStart, 1);
446 sqlite3TreeViewBound(pView, pWin->eEnd, pWin->pEnd, 0);
447 sqlite3TreeViewPop(&pView);
449 if( pWin->eExclude ){
450 char zBuf[30];
451 const char *zExclude;
452 switch( pWin->eExclude ){
453 case TK_NO: zExclude = "NO OTHERS"; break;
454 case TK_CURRENT: zExclude = "CURRENT ROW"; break;
455 case TK_GROUP: zExclude = "GROUP"; break;
456 case TK_TIES: zExclude = "TIES"; break;
457 default:
458 sqlite3_snprintf(sizeof(zBuf),zBuf,"invalid(%d)", pWin->eExclude);
459 zExclude = zBuf;
460 break;
462 sqlite3TreeViewPush(&pView, 0);
463 sqlite3TreeViewLine(pView, "EXCLUDE %s", zExclude);
464 sqlite3TreeViewPop(&pView);
466 sqlite3TreeViewPop(&pView);
468 #endif /* SQLITE_OMIT_WINDOWFUNC */
470 #ifndef SQLITE_OMIT_WINDOWFUNC
472 ** Generate a human-readable explanation for a Window Function object
474 void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){
475 if( pWin==0 ) return;
476 sqlite3TreeViewPush(&pView, more);
477 sqlite3TreeViewLine(pView, "WINFUNC %s(%d)",
478 pWin->pWFunc->zName, pWin->pWFunc->nArg);
479 sqlite3TreeViewWindow(pView, pWin, 0);
480 sqlite3TreeViewPop(&pView);
482 #endif /* SQLITE_OMIT_WINDOWFUNC */
485 ** Generate a human-readable explanation of an expression tree.
487 void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
488 const char *zBinOp = 0; /* Binary operator */
489 const char *zUniOp = 0; /* Unary operator */
490 char zFlgs[200];
491 sqlite3TreeViewPush(&pView, moreToFollow);
492 if( pExpr==0 ){
493 sqlite3TreeViewLine(pView, "nil");
494 sqlite3TreeViewPop(&pView);
495 return;
497 if( pExpr->flags || pExpr->affExpr || pExpr->vvaFlags || pExpr->pAggInfo ){
498 StrAccum x;
499 sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0);
500 sqlite3_str_appendf(&x, " fg.af=%x.%c",
501 pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n');
502 if( ExprHasProperty(pExpr, EP_OuterON) ){
503 sqlite3_str_appendf(&x, " outer.iJoin=%d", pExpr->w.iJoin);
505 if( ExprHasProperty(pExpr, EP_InnerON) ){
506 sqlite3_str_appendf(&x, " inner.iJoin=%d", pExpr->w.iJoin);
508 if( ExprHasProperty(pExpr, EP_FromDDL) ){
509 sqlite3_str_appendf(&x, " DDL");
511 if( ExprHasVVAProperty(pExpr, EP_Immutable) ){
512 sqlite3_str_appendf(&x, " IMMUTABLE");
514 if( pExpr->pAggInfo!=0 ){
515 sqlite3_str_appendf(&x, " agg-column[%d]", pExpr->iAgg);
517 sqlite3StrAccumFinish(&x);
518 }else{
519 zFlgs[0] = 0;
521 switch( pExpr->op ){
522 case TK_AGG_COLUMN: {
523 sqlite3TreeViewLine(pView, "AGG{%d:%d}%s",
524 pExpr->iTable, pExpr->iColumn, zFlgs);
525 break;
527 case TK_COLUMN: {
528 if( pExpr->iTable<0 ){
529 /* This only happens when coding check constraints */
530 char zOp2[16];
531 if( pExpr->op2 ){
532 sqlite3_snprintf(sizeof(zOp2),zOp2," op2=0x%02x",pExpr->op2);
533 }else{
534 zOp2[0] = 0;
536 sqlite3TreeViewLine(pView, "COLUMN(%d)%s%s",
537 pExpr->iColumn, zFlgs, zOp2);
538 }else{
539 assert( ExprUseYTab(pExpr) );
540 sqlite3TreeViewLine(pView, "{%d:%d} pTab=%p%s",
541 pExpr->iTable, pExpr->iColumn,
542 pExpr->y.pTab, zFlgs);
544 if( ExprHasProperty(pExpr, EP_FixedCol) ){
545 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
547 break;
549 case TK_INTEGER: {
550 if( pExpr->flags & EP_IntValue ){
551 sqlite3TreeViewLine(pView, "%d", pExpr->u.iValue);
552 }else{
553 sqlite3TreeViewLine(pView, "%s", pExpr->u.zToken);
555 break;
557 #ifndef SQLITE_OMIT_FLOATING_POINT
558 case TK_FLOAT: {
559 assert( !ExprHasProperty(pExpr, EP_IntValue) );
560 sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
561 break;
563 #endif
564 case TK_STRING: {
565 assert( !ExprHasProperty(pExpr, EP_IntValue) );
566 sqlite3TreeViewLine(pView,"%Q", pExpr->u.zToken);
567 break;
569 case TK_NULL: {
570 sqlite3TreeViewLine(pView,"NULL");
571 break;
573 case TK_TRUEFALSE: {
574 sqlite3TreeViewLine(pView,"%s%s",
575 sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE", zFlgs);
576 break;
578 #ifndef SQLITE_OMIT_BLOB_LITERAL
579 case TK_BLOB: {
580 assert( !ExprHasProperty(pExpr, EP_IntValue) );
581 sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
582 break;
584 #endif
585 case TK_VARIABLE: {
586 assert( !ExprHasProperty(pExpr, EP_IntValue) );
587 sqlite3TreeViewLine(pView,"VARIABLE(%s,%d)",
588 pExpr->u.zToken, pExpr->iColumn);
589 break;
591 case TK_REGISTER: {
592 sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable);
593 break;
595 case TK_ID: {
596 assert( !ExprHasProperty(pExpr, EP_IntValue) );
597 sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken);
598 break;
600 #ifndef SQLITE_OMIT_CAST
601 case TK_CAST: {
602 /* Expressions of the form: CAST(pLeft AS token) */
603 assert( !ExprHasProperty(pExpr, EP_IntValue) );
604 sqlite3TreeViewLine(pView,"CAST %Q", pExpr->u.zToken);
605 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
606 break;
608 #endif /* SQLITE_OMIT_CAST */
609 case TK_LT: zBinOp = "LT"; break;
610 case TK_LE: zBinOp = "LE"; break;
611 case TK_GT: zBinOp = "GT"; break;
612 case TK_GE: zBinOp = "GE"; break;
613 case TK_NE: zBinOp = "NE"; break;
614 case TK_EQ: zBinOp = "EQ"; break;
615 case TK_IS: zBinOp = "IS"; break;
616 case TK_ISNOT: zBinOp = "ISNOT"; break;
617 case TK_AND: zBinOp = "AND"; break;
618 case TK_OR: zBinOp = "OR"; break;
619 case TK_PLUS: zBinOp = "ADD"; break;
620 case TK_STAR: zBinOp = "MUL"; break;
621 case TK_MINUS: zBinOp = "SUB"; break;
622 case TK_REM: zBinOp = "REM"; break;
623 case TK_BITAND: zBinOp = "BITAND"; break;
624 case TK_BITOR: zBinOp = "BITOR"; break;
625 case TK_SLASH: zBinOp = "DIV"; break;
626 case TK_LSHIFT: zBinOp = "LSHIFT"; break;
627 case TK_RSHIFT: zBinOp = "RSHIFT"; break;
628 case TK_CONCAT: zBinOp = "CONCAT"; break;
629 case TK_DOT: zBinOp = "DOT"; break;
630 case TK_LIMIT: zBinOp = "LIMIT"; break;
632 case TK_UMINUS: zUniOp = "UMINUS"; break;
633 case TK_UPLUS: zUniOp = "UPLUS"; break;
634 case TK_BITNOT: zUniOp = "BITNOT"; break;
635 case TK_NOT: zUniOp = "NOT"; break;
636 case TK_ISNULL: zUniOp = "ISNULL"; break;
637 case TK_NOTNULL: zUniOp = "NOTNULL"; break;
639 case TK_TRUTH: {
640 int x;
641 const char *azOp[] = {
642 "IS-FALSE", "IS-TRUE", "IS-NOT-FALSE", "IS-NOT-TRUE"
644 assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT );
645 assert( pExpr->pRight );
646 assert( sqlite3ExprSkipCollateAndLikely(pExpr->pRight)->op
647 == TK_TRUEFALSE );
648 x = (pExpr->op2==TK_ISNOT)*2 + sqlite3ExprTruthValue(pExpr->pRight);
649 zUniOp = azOp[x];
650 break;
653 case TK_SPAN: {
654 assert( !ExprHasProperty(pExpr, EP_IntValue) );
655 sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken);
656 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
657 break;
660 case TK_COLLATE: {
661 /* COLLATE operators without the EP_Collate flag are intended to
662 ** emulate collation associated with a table column. These show
663 ** up in the treeview output as "SOFT-COLLATE". Explicit COLLATE
664 ** operators that appear in the original SQL always have the
665 ** EP_Collate bit set and appear in treeview output as just "COLLATE" */
666 assert( !ExprHasProperty(pExpr, EP_IntValue) );
667 sqlite3TreeViewLine(pView, "%sCOLLATE %Q%s",
668 !ExprHasProperty(pExpr, EP_Collate) ? "SOFT-" : "",
669 pExpr->u.zToken, zFlgs);
670 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
671 break;
674 case TK_AGG_FUNCTION:
675 case TK_FUNCTION: {
676 ExprList *pFarg; /* List of function arguments */
677 Window *pWin;
678 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
679 pFarg = 0;
680 pWin = 0;
681 }else{
682 assert( ExprUseXList(pExpr) );
683 pFarg = pExpr->x.pList;
684 #ifndef SQLITE_OMIT_WINDOWFUNC
685 pWin = ExprHasProperty(pExpr, EP_WinFunc) ? pExpr->y.pWin : 0;
686 #else
687 pWin = 0;
688 #endif
690 assert( !ExprHasProperty(pExpr, EP_IntValue) );
691 if( pExpr->op==TK_AGG_FUNCTION ){
692 sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s agg=%d[%d]/%p",
693 pExpr->op2, pExpr->u.zToken, zFlgs,
694 pExpr->pAggInfo ? pExpr->pAggInfo->selId : 0,
695 pExpr->iAgg, pExpr->pAggInfo);
696 }else if( pExpr->op2!=0 ){
697 const char *zOp2;
698 char zBuf[8];
699 sqlite3_snprintf(sizeof(zBuf),zBuf,"0x%02x",pExpr->op2);
700 zOp2 = zBuf;
701 if( pExpr->op2==NC_IsCheck ) zOp2 = "NC_IsCheck";
702 if( pExpr->op2==NC_IdxExpr ) zOp2 = "NC_IdxExpr";
703 if( pExpr->op2==NC_PartIdx ) zOp2 = "NC_PartIdx";
704 if( pExpr->op2==NC_GenCol ) zOp2 = "NC_GenCol";
705 sqlite3TreeViewLine(pView, "FUNCTION %Q%s op2=%s",
706 pExpr->u.zToken, zFlgs, zOp2);
707 }else{
708 sqlite3TreeViewLine(pView, "FUNCTION %Q%s", pExpr->u.zToken, zFlgs);
710 if( pFarg ){
711 sqlite3TreeViewExprList(pView, pFarg, pWin!=0, 0);
713 #ifndef SQLITE_OMIT_WINDOWFUNC
714 if( pWin ){
715 sqlite3TreeViewWindow(pView, pWin, 0);
717 #endif
718 break;
720 #ifndef SQLITE_OMIT_SUBQUERY
721 case TK_EXISTS: {
722 assert( ExprUseXSelect(pExpr) );
723 sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags);
724 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
725 break;
727 case TK_SELECT: {
728 assert( ExprUseXSelect(pExpr) );
729 sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags);
730 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
731 break;
733 case TK_IN: {
734 sqlite3_str *pStr = sqlite3_str_new(0);
735 char *z;
736 sqlite3_str_appendf(pStr, "IN flags=0x%x", pExpr->flags);
737 if( pExpr->iTable ) sqlite3_str_appendf(pStr, " iTable=%d",pExpr->iTable);
738 if( ExprHasProperty(pExpr, EP_Subrtn) ){
739 sqlite3_str_appendf(pStr, " subrtn(%d,%d)",
740 pExpr->y.sub.regReturn, pExpr->y.sub.iAddr);
742 z = sqlite3_str_finish(pStr);
743 sqlite3TreeViewLine(pView, z);
744 sqlite3_free(z);
745 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
746 if( ExprUseXSelect(pExpr) ){
747 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
748 }else{
749 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
751 break;
753 #endif /* SQLITE_OMIT_SUBQUERY */
756 ** x BETWEEN y AND z
758 ** This is equivalent to
760 ** x>=y AND x<=z
762 ** X is stored in pExpr->pLeft.
763 ** Y is stored in pExpr->pList->a[0].pExpr.
764 ** Z is stored in pExpr->pList->a[1].pExpr.
766 case TK_BETWEEN: {
767 const Expr *pX, *pY, *pZ;
768 pX = pExpr->pLeft;
769 assert( ExprUseXList(pExpr) );
770 assert( pExpr->x.pList->nExpr==2 );
771 pY = pExpr->x.pList->a[0].pExpr;
772 pZ = pExpr->x.pList->a[1].pExpr;
773 sqlite3TreeViewLine(pView, "BETWEEN");
774 sqlite3TreeViewExpr(pView, pX, 1);
775 sqlite3TreeViewExpr(pView, pY, 1);
776 sqlite3TreeViewExpr(pView, pZ, 0);
777 break;
779 case TK_TRIGGER: {
780 /* If the opcode is TK_TRIGGER, then the expression is a reference
781 ** to a column in the new.* or old.* pseudo-tables available to
782 ** trigger programs. In this case Expr.iTable is set to 1 for the
783 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn
784 ** is set to the column of the pseudo-table to read, or to -1 to
785 ** read the rowid field.
787 sqlite3TreeViewLine(pView, "%s(%d)",
788 pExpr->iTable ? "NEW" : "OLD", pExpr->iColumn);
789 break;
791 case TK_CASE: {
792 sqlite3TreeViewLine(pView, "CASE");
793 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
794 assert( ExprUseXList(pExpr) );
795 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
796 break;
798 #ifndef SQLITE_OMIT_TRIGGER
799 case TK_RAISE: {
800 const char *zType = "unk";
801 switch( pExpr->affExpr ){
802 case OE_Rollback: zType = "rollback"; break;
803 case OE_Abort: zType = "abort"; break;
804 case OE_Fail: zType = "fail"; break;
805 case OE_Ignore: zType = "ignore"; break;
807 assert( !ExprHasProperty(pExpr, EP_IntValue) );
808 sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken);
809 break;
811 #endif
812 case TK_MATCH: {
813 sqlite3TreeViewLine(pView, "MATCH {%d:%d}%s",
814 pExpr->iTable, pExpr->iColumn, zFlgs);
815 sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
816 break;
818 case TK_VECTOR: {
819 char *z = sqlite3_mprintf("VECTOR%s",zFlgs);
820 assert( ExprUseXList(pExpr) );
821 sqlite3TreeViewBareExprList(pView, pExpr->x.pList, z);
822 sqlite3_free(z);
823 break;
825 case TK_SELECT_COLUMN: {
826 sqlite3TreeViewLine(pView, "SELECT-COLUMN %d of [0..%d]%s",
827 pExpr->iColumn, pExpr->iTable-1,
828 pExpr->pRight==pExpr->pLeft ? " (SELECT-owner)" : "");
829 assert( ExprUseXSelect(pExpr->pLeft) );
830 sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
831 break;
833 case TK_IF_NULL_ROW: {
834 sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable);
835 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
836 break;
838 case TK_ERROR: {
839 Expr tmp;
840 sqlite3TreeViewLine(pView, "ERROR");
841 tmp = *pExpr;
842 tmp.op = pExpr->op2;
843 sqlite3TreeViewExpr(pView, &tmp, 0);
844 break;
846 case TK_ROW: {
847 if( pExpr->iColumn<=0 ){
848 sqlite3TreeViewLine(pView, "First FROM table rowid");
849 }else{
850 sqlite3TreeViewLine(pView, "First FROM table column %d",
851 pExpr->iColumn-1);
853 break;
855 default: {
856 sqlite3TreeViewLine(pView, "op=%d", pExpr->op);
857 break;
860 if( zBinOp ){
861 sqlite3TreeViewLine(pView, "%s%s", zBinOp, zFlgs);
862 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
863 sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
864 }else if( zUniOp ){
865 sqlite3TreeViewLine(pView, "%s%s", zUniOp, zFlgs);
866 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
868 sqlite3TreeViewPop(&pView);
873 ** Generate a human-readable explanation of an expression list.
875 void sqlite3TreeViewBareExprList(
876 TreeView *pView,
877 const ExprList *pList,
878 const char *zLabel
880 if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST";
881 if( pList==0 ){
882 sqlite3TreeViewLine(pView, "%s (empty)", zLabel);
883 }else{
884 int i;
885 sqlite3TreeViewLine(pView, "%s", zLabel);
886 for(i=0; i<pList->nExpr; i++){
887 int j = pList->a[i].u.x.iOrderByCol;
888 char *zName = pList->a[i].zEName;
889 int moreToFollow = i<pList->nExpr - 1;
890 if( j || zName ){
891 sqlite3TreeViewPush(&pView, moreToFollow);
892 moreToFollow = 0;
893 sqlite3TreeViewLine(pView, 0);
894 if( zName ){
895 switch( pList->a[i].fg.eEName ){
896 default:
897 fprintf(stdout, "AS %s ", zName);
898 break;
899 case ENAME_TAB:
900 fprintf(stdout, "TABLE-ALIAS-NAME(\"%s\") ", zName);
901 if( pList->a[i].fg.bUsed ) fprintf(stdout, "(used) ");
902 if( pList->a[i].fg.bUsingTerm ) fprintf(stdout, "(USING-term) ");
903 if( pList->a[i].fg.bNoExpand ) fprintf(stdout, "(NoExpand) ");
904 break;
905 case ENAME_SPAN:
906 fprintf(stdout, "SPAN(\"%s\") ", zName);
907 break;
910 if( j ){
911 fprintf(stdout, "iOrderByCol=%d", j);
913 fprintf(stdout, "\n");
914 fflush(stdout);
916 sqlite3TreeViewExpr(pView, pList->a[i].pExpr, moreToFollow);
917 if( j || zName ){
918 sqlite3TreeViewPop(&pView);
923 void sqlite3TreeViewExprList(
924 TreeView *pView,
925 const ExprList *pList,
926 u8 moreToFollow,
927 const char *zLabel
929 sqlite3TreeViewPush(&pView, moreToFollow);
930 sqlite3TreeViewBareExprList(pView, pList, zLabel);
931 sqlite3TreeViewPop(&pView);
935 ** Generate a human-readable explanation of an id-list.
937 void sqlite3TreeViewBareIdList(
938 TreeView *pView,
939 const IdList *pList,
940 const char *zLabel
942 if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST";
943 if( pList==0 ){
944 sqlite3TreeViewLine(pView, "%s (empty)", zLabel);
945 }else{
946 int i;
947 sqlite3TreeViewLine(pView, "%s", zLabel);
948 for(i=0; i<pList->nId; i++){
949 char *zName = pList->a[i].zName;
950 int moreToFollow = i<pList->nId - 1;
951 if( zName==0 ) zName = "(null)";
952 sqlite3TreeViewPush(&pView, moreToFollow);
953 sqlite3TreeViewLine(pView, 0);
954 if( pList->eU4==EU4_NONE ){
955 fprintf(stdout, "%s\n", zName);
956 }else if( pList->eU4==EU4_IDX ){
957 fprintf(stdout, "%s (%d)\n", zName, pList->a[i].u4.idx);
958 }else{
959 assert( pList->eU4==EU4_EXPR );
960 if( pList->a[i].u4.pExpr==0 ){
961 fprintf(stdout, "%s (pExpr=NULL)\n", zName);
962 }else{
963 fprintf(stdout, "%s\n", zName);
964 sqlite3TreeViewPush(&pView, i<pList->nId-1);
965 sqlite3TreeViewExpr(pView, pList->a[i].u4.pExpr, 0);
966 sqlite3TreeViewPop(&pView);
969 sqlite3TreeViewPop(&pView);
973 void sqlite3TreeViewIdList(
974 TreeView *pView,
975 const IdList *pList,
976 u8 moreToFollow,
977 const char *zLabel
979 sqlite3TreeViewPush(&pView, moreToFollow);
980 sqlite3TreeViewBareIdList(pView, pList, zLabel);
981 sqlite3TreeViewPop(&pView);
985 ** Generate a human-readable explanation of a list of Upsert objects
987 void sqlite3TreeViewUpsert(
988 TreeView *pView,
989 const Upsert *pUpsert,
990 u8 moreToFollow
992 if( pUpsert==0 ) return;
993 sqlite3TreeViewPush(&pView, moreToFollow);
994 while( pUpsert ){
995 int n;
996 sqlite3TreeViewPush(&pView, pUpsert->pNextUpsert!=0 || moreToFollow);
997 sqlite3TreeViewLine(pView, "ON CONFLICT DO %s",
998 pUpsert->isDoUpdate ? "UPDATE" : "NOTHING");
999 n = (pUpsert->pUpsertSet!=0) + (pUpsert->pUpsertWhere!=0);
1000 sqlite3TreeViewExprList(pView, pUpsert->pUpsertTarget, (n--)>0, "TARGET");
1001 sqlite3TreeViewExprList(pView, pUpsert->pUpsertSet, (n--)>0, "SET");
1002 if( pUpsert->pUpsertWhere ){
1003 sqlite3TreeViewItem(pView, "WHERE", (n--)>0);
1004 sqlite3TreeViewExpr(pView, pUpsert->pUpsertWhere, 0);
1005 sqlite3TreeViewPop(&pView);
1007 sqlite3TreeViewPop(&pView);
1008 pUpsert = pUpsert->pNextUpsert;
1010 sqlite3TreeViewPop(&pView);
1013 #if TREETRACE_ENABLED
1015 ** Generate a human-readable diagram of the data structure that go
1016 ** into generating an DELETE statement.
1018 void sqlite3TreeViewDelete(
1019 const With *pWith,
1020 const SrcList *pTabList,
1021 const Expr *pWhere,
1022 const ExprList *pOrderBy,
1023 const Expr *pLimit,
1024 const Trigger *pTrigger
1026 int n = 0;
1027 TreeView *pView = 0;
1028 sqlite3TreeViewPush(&pView, 0);
1029 sqlite3TreeViewLine(pView, "DELETE");
1030 if( pWith ) n++;
1031 if( pTabList ) n++;
1032 if( pWhere ) n++;
1033 if( pOrderBy ) n++;
1034 if( pLimit ) n++;
1035 if( pTrigger ) n++;
1036 if( pWith ){
1037 sqlite3TreeViewPush(&pView, (--n)>0);
1038 sqlite3TreeViewWith(pView, pWith, 0);
1039 sqlite3TreeViewPop(&pView);
1041 if( pTabList ){
1042 sqlite3TreeViewPush(&pView, (--n)>0);
1043 sqlite3TreeViewLine(pView, "FROM");
1044 sqlite3TreeViewSrcList(pView, pTabList);
1045 sqlite3TreeViewPop(&pView);
1047 if( pWhere ){
1048 sqlite3TreeViewPush(&pView, (--n)>0);
1049 sqlite3TreeViewLine(pView, "WHERE");
1050 sqlite3TreeViewExpr(pView, pWhere, 0);
1051 sqlite3TreeViewPop(&pView);
1053 if( pOrderBy ){
1054 sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY");
1056 if( pLimit ){
1057 sqlite3TreeViewPush(&pView, (--n)>0);
1058 sqlite3TreeViewLine(pView, "LIMIT");
1059 sqlite3TreeViewExpr(pView, pLimit, 0);
1060 sqlite3TreeViewPop(&pView);
1062 if( pTrigger ){
1063 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
1065 sqlite3TreeViewPop(&pView);
1067 #endif /* TREETRACE_ENABLED */
1069 #if TREETRACE_ENABLED
1071 ** Generate a human-readable diagram of the data structure that go
1072 ** into generating an INSERT statement.
1074 void sqlite3TreeViewInsert(
1075 const With *pWith,
1076 const SrcList *pTabList,
1077 const IdList *pColumnList,
1078 const Select *pSelect,
1079 const ExprList *pExprList,
1080 int onError,
1081 const Upsert *pUpsert,
1082 const Trigger *pTrigger
1084 TreeView *pView = 0;
1085 int n = 0;
1086 const char *zLabel = "INSERT";
1087 switch( onError ){
1088 case OE_Replace: zLabel = "REPLACE"; break;
1089 case OE_Ignore: zLabel = "INSERT OR IGNORE"; break;
1090 case OE_Rollback: zLabel = "INSERT OR ROLLBACK"; break;
1091 case OE_Abort: zLabel = "INSERT OR ABORT"; break;
1092 case OE_Fail: zLabel = "INSERT OR FAIL"; break;
1094 sqlite3TreeViewPush(&pView, 0);
1095 sqlite3TreeViewLine(pView, zLabel);
1096 if( pWith ) n++;
1097 if( pTabList ) n++;
1098 if( pColumnList ) n++;
1099 if( pSelect ) n++;
1100 if( pExprList ) n++;
1101 if( pUpsert ) n++;
1102 if( pTrigger ) n++;
1103 if( pWith ){
1104 sqlite3TreeViewPush(&pView, (--n)>0);
1105 sqlite3TreeViewWith(pView, pWith, 0);
1106 sqlite3TreeViewPop(&pView);
1108 if( pTabList ){
1109 sqlite3TreeViewPush(&pView, (--n)>0);
1110 sqlite3TreeViewLine(pView, "INTO");
1111 sqlite3TreeViewSrcList(pView, pTabList);
1112 sqlite3TreeViewPop(&pView);
1114 if( pColumnList ){
1115 sqlite3TreeViewIdList(pView, pColumnList, (--n)>0, "COLUMNS");
1117 if( pSelect ){
1118 sqlite3TreeViewPush(&pView, (--n)>0);
1119 sqlite3TreeViewLine(pView, "DATA-SOURCE");
1120 sqlite3TreeViewSelect(pView, pSelect, 0);
1121 sqlite3TreeViewPop(&pView);
1123 if( pExprList ){
1124 sqlite3TreeViewExprList(pView, pExprList, (--n)>0, "VALUES");
1126 if( pUpsert ){
1127 sqlite3TreeViewPush(&pView, (--n)>0);
1128 sqlite3TreeViewLine(pView, "UPSERT");
1129 sqlite3TreeViewUpsert(pView, pUpsert, 0);
1130 sqlite3TreeViewPop(&pView);
1132 if( pTrigger ){
1133 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
1135 sqlite3TreeViewPop(&pView);
1137 #endif /* TREETRACE_ENABLED */
1139 #if TREETRACE_ENABLED
1141 ** Generate a human-readable diagram of the data structure that go
1142 ** into generating an UPDATE statement.
1144 void sqlite3TreeViewUpdate(
1145 const With *pWith,
1146 const SrcList *pTabList,
1147 const ExprList *pChanges,
1148 const Expr *pWhere,
1149 int onError,
1150 const ExprList *pOrderBy,
1151 const Expr *pLimit,
1152 const Upsert *pUpsert,
1153 const Trigger *pTrigger
1155 int n = 0;
1156 TreeView *pView = 0;
1157 const char *zLabel = "UPDATE";
1158 switch( onError ){
1159 case OE_Replace: zLabel = "UPDATE OR REPLACE"; break;
1160 case OE_Ignore: zLabel = "UPDATE OR IGNORE"; break;
1161 case OE_Rollback: zLabel = "UPDATE OR ROLLBACK"; break;
1162 case OE_Abort: zLabel = "UPDATE OR ABORT"; break;
1163 case OE_Fail: zLabel = "UPDATE OR FAIL"; break;
1165 sqlite3TreeViewPush(&pView, 0);
1166 sqlite3TreeViewLine(pView, zLabel);
1167 if( pWith ) n++;
1168 if( pTabList ) n++;
1169 if( pChanges ) n++;
1170 if( pWhere ) n++;
1171 if( pOrderBy ) n++;
1172 if( pLimit ) n++;
1173 if( pUpsert ) n++;
1174 if( pTrigger ) n++;
1175 if( pWith ){
1176 sqlite3TreeViewPush(&pView, (--n)>0);
1177 sqlite3TreeViewWith(pView, pWith, 0);
1178 sqlite3TreeViewPop(&pView);
1180 if( pTabList ){
1181 sqlite3TreeViewPush(&pView, (--n)>0);
1182 sqlite3TreeViewLine(pView, "FROM");
1183 sqlite3TreeViewSrcList(pView, pTabList);
1184 sqlite3TreeViewPop(&pView);
1186 if( pChanges ){
1187 sqlite3TreeViewExprList(pView, pChanges, (--n)>0, "SET");
1189 if( pWhere ){
1190 sqlite3TreeViewPush(&pView, (--n)>0);
1191 sqlite3TreeViewLine(pView, "WHERE");
1192 sqlite3TreeViewExpr(pView, pWhere, 0);
1193 sqlite3TreeViewPop(&pView);
1195 if( pOrderBy ){
1196 sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY");
1198 if( pLimit ){
1199 sqlite3TreeViewPush(&pView, (--n)>0);
1200 sqlite3TreeViewLine(pView, "LIMIT");
1201 sqlite3TreeViewExpr(pView, pLimit, 0);
1202 sqlite3TreeViewPop(&pView);
1204 if( pUpsert ){
1205 sqlite3TreeViewPush(&pView, (--n)>0);
1206 sqlite3TreeViewLine(pView, "UPSERT");
1207 sqlite3TreeViewUpsert(pView, pUpsert, 0);
1208 sqlite3TreeViewPop(&pView);
1210 if( pTrigger ){
1211 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
1213 sqlite3TreeViewPop(&pView);
1215 #endif /* TREETRACE_ENABLED */
1217 #ifndef SQLITE_OMIT_TRIGGER
1219 ** Show a human-readable graph of a TriggerStep
1221 void sqlite3TreeViewTriggerStep(
1222 TreeView *pView,
1223 const TriggerStep *pStep,
1224 u8 moreToFollow,
1225 u8 showFullList
1227 int cnt = 0;
1228 if( pStep==0 ) return;
1229 sqlite3TreeViewPush(&pView,
1230 moreToFollow || (showFullList && pStep->pNext!=0));
1232 if( cnt++ && pStep->pNext==0 ){
1233 sqlite3TreeViewPop(&pView);
1234 sqlite3TreeViewPush(&pView, 0);
1236 sqlite3TreeViewLine(pView, "%s", pStep->zSpan ? pStep->zSpan : "RETURNING");
1237 }while( showFullList && (pStep = pStep->pNext)!=0 );
1238 sqlite3TreeViewPop(&pView);
1242 ** Show a human-readable graph of a Trigger
1244 void sqlite3TreeViewTrigger(
1245 TreeView *pView,
1246 const Trigger *pTrigger,
1247 u8 moreToFollow,
1248 u8 showFullList
1250 int cnt = 0;
1251 if( pTrigger==0 ) return;
1252 sqlite3TreeViewPush(&pView,
1253 moreToFollow || (showFullList && pTrigger->pNext!=0));
1255 if( cnt++ && pTrigger->pNext==0 ){
1256 sqlite3TreeViewPop(&pView);
1257 sqlite3TreeViewPush(&pView, 0);
1259 sqlite3TreeViewLine(pView, "TRIGGER %s", pTrigger->zName);
1260 sqlite3TreeViewPush(&pView, 0);
1261 sqlite3TreeViewTriggerStep(pView, pTrigger->step_list, 0, 1);
1262 sqlite3TreeViewPop(&pView);
1263 }while( showFullList && (pTrigger = pTrigger->pNext)!=0 );
1264 sqlite3TreeViewPop(&pView);
1266 #endif /* SQLITE_OMIT_TRIGGER */
1270 ** These simplified versions of the tree-view routines omit unnecessary
1271 ** parameters. These variants are intended to be used from a symbolic
1272 ** debugger, such as "gdb", during interactive debugging sessions.
1274 ** This routines are given external linkage so that they will always be
1275 ** accessible to the debugging, and to avoid warnings about unused
1276 ** functions. But these routines only exist in debugging builds, so they
1277 ** do not contaminate the interface.
1279 void sqlite3ShowExpr(const Expr *p){ sqlite3TreeViewExpr(0,p,0); }
1280 void sqlite3ShowExprList(const ExprList *p){ sqlite3TreeViewExprList(0,p,0,0);}
1281 void sqlite3ShowIdList(const IdList *p){ sqlite3TreeViewIdList(0,p,0,0); }
1282 void sqlite3ShowSrcList(const SrcList *p){ sqlite3TreeViewSrcList(0,p); }
1283 void sqlite3ShowSelect(const Select *p){ sqlite3TreeViewSelect(0,p,0); }
1284 void sqlite3ShowWith(const With *p){ sqlite3TreeViewWith(0,p,0); }
1285 void sqlite3ShowUpsert(const Upsert *p){ sqlite3TreeViewUpsert(0,p,0); }
1286 #ifndef SQLITE_OMIT_TRIGGER
1287 void sqlite3ShowTriggerStep(const TriggerStep *p){
1288 sqlite3TreeViewTriggerStep(0,p,0,0);
1290 void sqlite3ShowTriggerStepList(const TriggerStep *p){
1291 sqlite3TreeViewTriggerStep(0,p,0,1);
1293 void sqlite3ShowTrigger(const Trigger *p){ sqlite3TreeViewTrigger(0,p,0,0); }
1294 void sqlite3ShowTriggerList(const Trigger *p){ sqlite3TreeViewTrigger(0,p,0,1);}
1295 #endif
1296 #ifndef SQLITE_OMIT_WINDOWFUNC
1297 void sqlite3ShowWindow(const Window *p){ sqlite3TreeViewWindow(0,p,0); }
1298 void sqlite3ShowWinFunc(const Window *p){ sqlite3TreeViewWinFunc(0,p,0); }
1299 #endif
1301 #endif /* SQLITE_DEBUG */