blob: 8d171a4733c4d610ea60c76ca5d731720e56fa4b [file] [log] [blame]
drh38b41492015-06-08 15:08:15 +00001/*
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*/
27static 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*/
43static 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*/
53static 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++){
61 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "| " : " ", 4);
62 }
63 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
64 }
65 va_start(ap, zFormat);
drh5f4a6862016-01-30 12:50:25 +000066 sqlite3VXPrintf(&acc, zFormat, ap);
drh38b41492015-06-08 15:08:15 +000067 va_end(ap);
drh54fc5cc2016-11-04 11:23:30 +000068 assert( acc.nChar>0 );
drh38b41492015-06-08 15:08:15 +000069 if( zBuf[acc.nChar-1]!='\n' ) sqlite3StrAccumAppend(&acc, "\n", 1);
70 sqlite3StrAccumFinish(&acc);
71 fprintf(stdout,"%s", zBuf);
72 fflush(stdout);
73}
74
75/*
76** Shorthand for starting a new tree item that consists of a single label
77*/
78static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){
79 p = sqlite3TreeViewPush(p, moreFollows);
80 sqlite3TreeViewLine(p, "%s", zLabel);
81}
82
drh2476a6f2015-11-07 15:19:59 +000083/*
84** Generate a human-readable description of a WITH clause.
85*/
86void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){
87 int i;
88 if( pWith==0 ) return;
89 if( pWith->nCte==0 ) return;
90 if( pWith->pOuter ){
91 sqlite3TreeViewLine(pView, "WITH (0x%p, pOuter=0x%p)",pWith,pWith->pOuter);
92 }else{
93 sqlite3TreeViewLine(pView, "WITH (0x%p)", pWith);
94 }
95 if( pWith->nCte>0 ){
96 pView = sqlite3TreeViewPush(pView, 1);
97 for(i=0; i<pWith->nCte; i++){
98 StrAccum x;
99 char zLine[1000];
100 const struct Cte *pCte = &pWith->a[i];
101 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
drh5f4a6862016-01-30 12:50:25 +0000102 sqlite3XPrintf(&x, "%s", pCte->zName);
drh2476a6f2015-11-07 15:19:59 +0000103 if( pCte->pCols && pCte->pCols->nExpr>0 ){
104 char cSep = '(';
105 int j;
106 for(j=0; j<pCte->pCols->nExpr; j++){
drh5f4a6862016-01-30 12:50:25 +0000107 sqlite3XPrintf(&x, "%c%s", cSep, pCte->pCols->a[j].zName);
drh2476a6f2015-11-07 15:19:59 +0000108 cSep = ',';
109 }
drh5f4a6862016-01-30 12:50:25 +0000110 sqlite3XPrintf(&x, ")");
drh2476a6f2015-11-07 15:19:59 +0000111 }
drh5f4a6862016-01-30 12:50:25 +0000112 sqlite3XPrintf(&x, " AS");
drh2476a6f2015-11-07 15:19:59 +0000113 sqlite3StrAccumFinish(&x);
114 sqlite3TreeViewItem(pView, zLine, i<pWith->nCte-1);
115 sqlite3TreeViewSelect(pView, pCte->pSelect, 0);
116 sqlite3TreeViewPop(pView);
117 }
118 sqlite3TreeViewPop(pView);
119 }
120}
121
drh38b41492015-06-08 15:08:15 +0000122
123/*
drh2e5c5052016-08-27 20:21:51 +0000124** Generate a human-readable description of a Select object.
drh38b41492015-06-08 15:08:15 +0000125*/
126void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
127 int n = 0;
drh1c4505d2015-08-26 11:34:31 +0000128 int cnt = 0;
drh510b7ff2017-03-13 17:37:13 +0000129 if( p==0 ){
130 sqlite3TreeViewLine(pView, "nil-SELECT");
131 return;
132 }
drh38b41492015-06-08 15:08:15 +0000133 pView = sqlite3TreeViewPush(pView, moreToFollow);
drh2476a6f2015-11-07 15:19:59 +0000134 if( p->pWith ){
135 sqlite3TreeViewWith(pView, p->pWith, 1);
136 cnt = 1;
137 sqlite3TreeViewPush(pView, 1);
138 }
drh1c4505d2015-08-26 11:34:31 +0000139 do{
drhc3489bb2016-02-25 16:04:59 +0000140 sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x nSelectRow=%d",
drh1c4505d2015-08-26 11:34:31 +0000141 ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
drhc3489bb2016-02-25 16:04:59 +0000142 ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p, p->selFlags,
143 (int)p->nSelectRow
drh1c4505d2015-08-26 11:34:31 +0000144 );
145 if( cnt++ ) sqlite3TreeViewPop(pView);
146 if( p->pPrior ){
147 n = 1000;
148 }else{
149 n = 0;
150 if( p->pSrc && p->pSrc->nSrc ) n++;
151 if( p->pWhere ) n++;
152 if( p->pGroupBy ) n++;
153 if( p->pHaving ) n++;
154 if( p->pOrderBy ) n++;
155 if( p->pLimit ) n++;
drh1c4505d2015-08-26 11:34:31 +0000156 }
157 sqlite3TreeViewExprList(pView, p->pEList, (n--)>0, "result-set");
158 if( p->pSrc && p->pSrc->nSrc ){
159 int i;
160 pView = sqlite3TreeViewPush(pView, (n--)>0);
161 sqlite3TreeViewLine(pView, "FROM");
162 for(i=0; i<p->pSrc->nSrc; i++){
163 struct SrcList_item *pItem = &p->pSrc->a[i];
164 StrAccum x;
165 char zLine[100];
166 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
drh5f4a6862016-01-30 12:50:25 +0000167 sqlite3XPrintf(&x, "{%d,*}", pItem->iCursor);
drh1c4505d2015-08-26 11:34:31 +0000168 if( pItem->zDatabase ){
drh5f4a6862016-01-30 12:50:25 +0000169 sqlite3XPrintf(&x, " %s.%s", pItem->zDatabase, pItem->zName);
drh1c4505d2015-08-26 11:34:31 +0000170 }else if( pItem->zName ){
drh5f4a6862016-01-30 12:50:25 +0000171 sqlite3XPrintf(&x, " %s", pItem->zName);
drh1c4505d2015-08-26 11:34:31 +0000172 }
173 if( pItem->pTab ){
drh5f4a6862016-01-30 12:50:25 +0000174 sqlite3XPrintf(&x, " tabname=%Q", pItem->pTab->zName);
drh1c4505d2015-08-26 11:34:31 +0000175 }
176 if( pItem->zAlias ){
drh5f4a6862016-01-30 12:50:25 +0000177 sqlite3XPrintf(&x, " (AS %s)", pItem->zAlias);
drh1c4505d2015-08-26 11:34:31 +0000178 }
179 if( pItem->fg.jointype & JT_LEFT ){
drh5f4a6862016-01-30 12:50:25 +0000180 sqlite3XPrintf(&x, " LEFT-JOIN");
drh1c4505d2015-08-26 11:34:31 +0000181 }
182 sqlite3StrAccumFinish(&x);
183 sqlite3TreeViewItem(pView, zLine, i<p->pSrc->nSrc-1);
184 if( pItem->pSelect ){
185 sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
186 }
187 if( pItem->fg.isTabFunc ){
188 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
189 }
190 sqlite3TreeViewPop(pView);
drh01d230c2015-08-19 17:11:37 +0000191 }
drh38b41492015-06-08 15:08:15 +0000192 sqlite3TreeViewPop(pView);
193 }
drh1c4505d2015-08-26 11:34:31 +0000194 if( p->pWhere ){
195 sqlite3TreeViewItem(pView, "WHERE", (n--)>0);
196 sqlite3TreeViewExpr(pView, p->pWhere, 0);
197 sqlite3TreeViewPop(pView);
drh38b41492015-06-08 15:08:15 +0000198 }
drh1c4505d2015-08-26 11:34:31 +0000199 if( p->pGroupBy ){
200 sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY");
201 }
202 if( p->pHaving ){
203 sqlite3TreeViewItem(pView, "HAVING", (n--)>0);
204 sqlite3TreeViewExpr(pView, p->pHaving, 0);
205 sqlite3TreeViewPop(pView);
206 }
207 if( p->pOrderBy ){
208 sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY");
209 }
210 if( p->pLimit ){
211 sqlite3TreeViewItem(pView, "LIMIT", (n--)>0);
drh8c0833f2017-11-14 23:48:23 +0000212 sqlite3TreeViewExpr(pView, p->pLimit->pLeft, p->pLimit->pRight!=0);
213 if( p->pLimit->pRight ){
214 sqlite3TreeViewItem(pView, "OFFSET", (n--)>0);
215 sqlite3TreeViewExpr(pView, p->pLimit->pRight, 0);
216 sqlite3TreeViewPop(pView);
217 }
drh1c4505d2015-08-26 11:34:31 +0000218 sqlite3TreeViewPop(pView);
219 }
220 if( p->pPrior ){
221 const char *zOp = "UNION";
222 switch( p->op ){
223 case TK_ALL: zOp = "UNION ALL"; break;
224 case TK_INTERSECT: zOp = "INTERSECT"; break;
225 case TK_EXCEPT: zOp = "EXCEPT"; break;
226 }
227 sqlite3TreeViewItem(pView, zOp, 1);
228 }
229 p = p->pPrior;
230 }while( p!=0 );
drh38b41492015-06-08 15:08:15 +0000231 sqlite3TreeViewPop(pView);
232}
233
234/*
235** Generate a human-readable explanation of an expression tree.
236*/
237void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
238 const char *zBinOp = 0; /* Binary operator */
239 const char *zUniOp = 0; /* Unary operator */
drhd97cda42017-04-14 14:02:14 +0000240 char zFlgs[60];
drh38b41492015-06-08 15:08:15 +0000241 pView = sqlite3TreeViewPush(pView, moreToFollow);
242 if( pExpr==0 ){
243 sqlite3TreeViewLine(pView, "nil");
244 sqlite3TreeViewPop(pView);
245 return;
246 }
drhb3d903e2015-06-18 14:09:13 +0000247 if( pExpr->flags ){
drhd97cda42017-04-14 14:02:14 +0000248 if( ExprHasProperty(pExpr, EP_FromJoin) ){
249 sqlite3_snprintf(sizeof(zFlgs),zFlgs," flags=0x%x iRJT=%d",
250 pExpr->flags, pExpr->iRightJoinTable);
251 }else{
252 sqlite3_snprintf(sizeof(zFlgs),zFlgs," flags=0x%x",pExpr->flags);
253 }
drhb3d903e2015-06-18 14:09:13 +0000254 }else{
255 zFlgs[0] = 0;
256 }
drh38b41492015-06-08 15:08:15 +0000257 switch( pExpr->op ){
258 case TK_AGG_COLUMN: {
drhb3d903e2015-06-18 14:09:13 +0000259 sqlite3TreeViewLine(pView, "AGG{%d:%d}%s",
260 pExpr->iTable, pExpr->iColumn, zFlgs);
drh38b41492015-06-08 15:08:15 +0000261 break;
262 }
263 case TK_COLUMN: {
264 if( pExpr->iTable<0 ){
265 /* This only happens when coding check constraints */
drhb3d903e2015-06-18 14:09:13 +0000266 sqlite3TreeViewLine(pView, "COLUMN(%d)%s", pExpr->iColumn, zFlgs);
drh38b41492015-06-08 15:08:15 +0000267 }else{
drhb3d903e2015-06-18 14:09:13 +0000268 sqlite3TreeViewLine(pView, "{%d:%d}%s",
269 pExpr->iTable, pExpr->iColumn, zFlgs);
drh38b41492015-06-08 15:08:15 +0000270 }
271 break;
272 }
273 case TK_INTEGER: {
274 if( pExpr->flags & EP_IntValue ){
275 sqlite3TreeViewLine(pView, "%d", pExpr->u.iValue);
276 }else{
277 sqlite3TreeViewLine(pView, "%s", pExpr->u.zToken);
278 }
279 break;
280 }
281#ifndef SQLITE_OMIT_FLOATING_POINT
282 case TK_FLOAT: {
283 sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
284 break;
285 }
286#endif
287 case TK_STRING: {
288 sqlite3TreeViewLine(pView,"%Q", pExpr->u.zToken);
289 break;
290 }
291 case TK_NULL: {
292 sqlite3TreeViewLine(pView,"NULL");
293 break;
294 }
295#ifndef SQLITE_OMIT_BLOB_LITERAL
296 case TK_BLOB: {
297 sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
298 break;
299 }
300#endif
301 case TK_VARIABLE: {
302 sqlite3TreeViewLine(pView,"VARIABLE(%s,%d)",
303 pExpr->u.zToken, pExpr->iColumn);
304 break;
305 }
306 case TK_REGISTER: {
307 sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable);
308 break;
309 }
drh38b41492015-06-08 15:08:15 +0000310 case TK_ID: {
311 sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken);
312 break;
313 }
314#ifndef SQLITE_OMIT_CAST
315 case TK_CAST: {
316 /* Expressions of the form: CAST(pLeft AS token) */
317 sqlite3TreeViewLine(pView,"CAST %Q", pExpr->u.zToken);
318 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
319 break;
320 }
321#endif /* SQLITE_OMIT_CAST */
322 case TK_LT: zBinOp = "LT"; break;
323 case TK_LE: zBinOp = "LE"; break;
324 case TK_GT: zBinOp = "GT"; break;
325 case TK_GE: zBinOp = "GE"; break;
326 case TK_NE: zBinOp = "NE"; break;
327 case TK_EQ: zBinOp = "EQ"; break;
328 case TK_IS: zBinOp = "IS"; break;
329 case TK_ISNOT: zBinOp = "ISNOT"; break;
330 case TK_AND: zBinOp = "AND"; break;
331 case TK_OR: zBinOp = "OR"; break;
332 case TK_PLUS: zBinOp = "ADD"; break;
333 case TK_STAR: zBinOp = "MUL"; break;
334 case TK_MINUS: zBinOp = "SUB"; break;
335 case TK_REM: zBinOp = "REM"; break;
336 case TK_BITAND: zBinOp = "BITAND"; break;
337 case TK_BITOR: zBinOp = "BITOR"; break;
338 case TK_SLASH: zBinOp = "DIV"; break;
339 case TK_LSHIFT: zBinOp = "LSHIFT"; break;
340 case TK_RSHIFT: zBinOp = "RSHIFT"; break;
341 case TK_CONCAT: zBinOp = "CONCAT"; break;
342 case TK_DOT: zBinOp = "DOT"; break;
343
344 case TK_UMINUS: zUniOp = "UMINUS"; break;
345 case TK_UPLUS: zUniOp = "UPLUS"; break;
346 case TK_BITNOT: zUniOp = "BITNOT"; break;
347 case TK_NOT: zUniOp = "NOT"; break;
348 case TK_ISNULL: zUniOp = "ISNULL"; break;
349 case TK_NOTNULL: zUniOp = "NOTNULL"; break;
350
drh94fa9c42016-02-27 21:16:04 +0000351 case TK_SPAN: {
352 sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken);
353 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
354 break;
355 }
356
drh38b41492015-06-08 15:08:15 +0000357 case TK_COLLATE: {
358 sqlite3TreeViewLine(pView, "COLLATE %Q", pExpr->u.zToken);
359 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
360 break;
361 }
362
363 case TK_AGG_FUNCTION:
364 case TK_FUNCTION: {
365 ExprList *pFarg; /* List of function arguments */
366 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
367 pFarg = 0;
368 }else{
369 pFarg = pExpr->x.pList;
370 }
371 if( pExpr->op==TK_AGG_FUNCTION ){
372 sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q",
373 pExpr->op2, pExpr->u.zToken);
374 }else{
375 sqlite3TreeViewLine(pView, "FUNCTION %Q", pExpr->u.zToken);
376 }
377 if( pFarg ){
378 sqlite3TreeViewExprList(pView, pFarg, 0, 0);
379 }
380 break;
381 }
382#ifndef SQLITE_OMIT_SUBQUERY
383 case TK_EXISTS: {
drh9f6e14c2017-07-10 13:24:58 +0000384 sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags);
drh38b41492015-06-08 15:08:15 +0000385 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
386 break;
387 }
388 case TK_SELECT: {
drh9f6e14c2017-07-10 13:24:58 +0000389 sqlite3TreeViewLine(pView, "SELECT-expr flags=0x%x", pExpr->flags);
drh38b41492015-06-08 15:08:15 +0000390 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
391 break;
392 }
393 case TK_IN: {
drh9f6e14c2017-07-10 13:24:58 +0000394 sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags);
drh38b41492015-06-08 15:08:15 +0000395 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
396 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
397 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
398 }else{
399 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
400 }
401 break;
402 }
403#endif /* SQLITE_OMIT_SUBQUERY */
404
405 /*
406 ** x BETWEEN y AND z
407 **
408 ** This is equivalent to
409 **
410 ** x>=y AND x<=z
411 **
412 ** X is stored in pExpr->pLeft.
413 ** Y is stored in pExpr->pList->a[0].pExpr.
414 ** Z is stored in pExpr->pList->a[1].pExpr.
415 */
416 case TK_BETWEEN: {
417 Expr *pX = pExpr->pLeft;
418 Expr *pY = pExpr->x.pList->a[0].pExpr;
419 Expr *pZ = pExpr->x.pList->a[1].pExpr;
420 sqlite3TreeViewLine(pView, "BETWEEN");
421 sqlite3TreeViewExpr(pView, pX, 1);
422 sqlite3TreeViewExpr(pView, pY, 1);
423 sqlite3TreeViewExpr(pView, pZ, 0);
424 break;
425 }
426 case TK_TRIGGER: {
427 /* If the opcode is TK_TRIGGER, then the expression is a reference
428 ** to a column in the new.* or old.* pseudo-tables available to
429 ** trigger programs. In this case Expr.iTable is set to 1 for the
430 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn
431 ** is set to the column of the pseudo-table to read, or to -1 to
432 ** read the rowid field.
433 */
434 sqlite3TreeViewLine(pView, "%s(%d)",
435 pExpr->iTable ? "NEW" : "OLD", pExpr->iColumn);
436 break;
437 }
438 case TK_CASE: {
439 sqlite3TreeViewLine(pView, "CASE");
440 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
441 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
442 break;
443 }
444#ifndef SQLITE_OMIT_TRIGGER
445 case TK_RAISE: {
446 const char *zType = "unk";
447 switch( pExpr->affinity ){
448 case OE_Rollback: zType = "rollback"; break;
449 case OE_Abort: zType = "abort"; break;
450 case OE_Fail: zType = "fail"; break;
451 case OE_Ignore: zType = "ignore"; break;
452 }
453 sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken);
454 break;
455 }
456#endif
drhc84a4022016-05-27 12:30:20 +0000457 case TK_MATCH: {
458 sqlite3TreeViewLine(pView, "MATCH {%d:%d}%s",
459 pExpr->iTable, pExpr->iColumn, zFlgs);
460 sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
461 break;
462 }
drhdb97e562016-08-18 17:55:57 +0000463 case TK_VECTOR: {
464 sqlite3TreeViewBareExprList(pView, pExpr->x.pList, "VECTOR");
465 break;
466 }
drh48cb3a72016-08-18 18:09:10 +0000467 case TK_SELECT_COLUMN: {
468 sqlite3TreeViewLine(pView, "SELECT-COLUMN %d", pExpr->iColumn);
469 sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
470 break;
471 }
drh31d6fd52017-04-14 19:03:10 +0000472 case TK_IF_NULL_ROW: {
473 sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable);
474 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
475 break;
476 }
drh38b41492015-06-08 15:08:15 +0000477 default: {
478 sqlite3TreeViewLine(pView, "op=%d", pExpr->op);
479 break;
480 }
481 }
482 if( zBinOp ){
drhb3d903e2015-06-18 14:09:13 +0000483 sqlite3TreeViewLine(pView, "%s%s", zBinOp, zFlgs);
drh38b41492015-06-08 15:08:15 +0000484 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
485 sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
486 }else if( zUniOp ){
drhb3d903e2015-06-18 14:09:13 +0000487 sqlite3TreeViewLine(pView, "%s%s", zUniOp, zFlgs);
drh38b41492015-06-08 15:08:15 +0000488 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
489 }
490 sqlite3TreeViewPop(pView);
491}
492
drhdb97e562016-08-18 17:55:57 +0000493
drh38b41492015-06-08 15:08:15 +0000494/*
495** Generate a human-readable explanation of an expression list.
496*/
drhdb97e562016-08-18 17:55:57 +0000497void sqlite3TreeViewBareExprList(
drh38b41492015-06-08 15:08:15 +0000498 TreeView *pView,
499 const ExprList *pList,
drh38b41492015-06-08 15:08:15 +0000500 const char *zLabel
501){
drh38b41492015-06-08 15:08:15 +0000502 if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST";
503 if( pList==0 ){
504 sqlite3TreeViewLine(pView, "%s (empty)", zLabel);
505 }else{
drhdb97e562016-08-18 17:55:57 +0000506 int i;
drh38b41492015-06-08 15:08:15 +0000507 sqlite3TreeViewLine(pView, "%s", zLabel);
508 for(i=0; i<pList->nExpr; i++){
drh5579d592015-08-26 14:01:41 +0000509 int j = pList->a[i].u.x.iOrderByCol;
510 if( j ){
511 sqlite3TreeViewPush(pView, 0);
512 sqlite3TreeViewLine(pView, "iOrderByCol=%d", j);
513 }
drh38b41492015-06-08 15:08:15 +0000514 sqlite3TreeViewExpr(pView, pList->a[i].pExpr, i<pList->nExpr-1);
drh5579d592015-08-26 14:01:41 +0000515 if( j ) sqlite3TreeViewPop(pView);
drh38b41492015-06-08 15:08:15 +0000516 }
517 }
drhdb97e562016-08-18 17:55:57 +0000518}
519void sqlite3TreeViewExprList(
520 TreeView *pView,
521 const ExprList *pList,
522 u8 moreToFollow,
523 const char *zLabel
524){
525 pView = sqlite3TreeViewPush(pView, moreToFollow);
526 sqlite3TreeViewBareExprList(pView, pList, zLabel);
drh38b41492015-06-08 15:08:15 +0000527 sqlite3TreeViewPop(pView);
528}
529
530#endif /* SQLITE_DEBUG */