blob: 51fa7f06ca9ba9f3f2c63694033cd9aef64b8411 [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 }
drhfbe07532018-04-23 20:04:38 +000065 if( zFormat!=0 ){
66 va_start(ap, zFormat);
67 sqlite3VXPrintf(&acc, zFormat, ap);
68 va_end(ap);
69 assert( acc.nChar>0 );
70 sqlite3StrAccumAppend(&acc, "\n", 1);
71 }
drh38b41492015-06-08 15:08:15 +000072 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*/
80static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){
81 p = sqlite3TreeViewPush(p, moreFollows);
82 sqlite3TreeViewLine(p, "%s", zLabel);
83}
84
drh2476a6f2015-11-07 15:19:59 +000085/*
86** Generate a human-readable description of a WITH clause.
87*/
88void 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);
drh5f4a6862016-01-30 12:50:25 +0000104 sqlite3XPrintf(&x, "%s", pCte->zName);
drh2476a6f2015-11-07 15:19:59 +0000105 if( pCte->pCols && pCte->pCols->nExpr>0 ){
106 char cSep = '(';
107 int j;
108 for(j=0; j<pCte->pCols->nExpr; j++){
drh5f4a6862016-01-30 12:50:25 +0000109 sqlite3XPrintf(&x, "%c%s", cSep, pCte->pCols->a[j].zName);
drh2476a6f2015-11-07 15:19:59 +0000110 cSep = ',';
111 }
drh5f4a6862016-01-30 12:50:25 +0000112 sqlite3XPrintf(&x, ")");
drh2476a6f2015-11-07 15:19:59 +0000113 }
drh5f4a6862016-01-30 12:50:25 +0000114 sqlite3XPrintf(&x, " AS");
drh2476a6f2015-11-07 15:19:59 +0000115 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
drh38b41492015-06-08 15:08:15 +0000124
125/*
drh2e5c5052016-08-27 20:21:51 +0000126** Generate a human-readable description of a Select object.
drh38b41492015-06-08 15:08:15 +0000127*/
128void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
129 int n = 0;
drh1c4505d2015-08-26 11:34:31 +0000130 int cnt = 0;
drh510b7ff2017-03-13 17:37:13 +0000131 if( p==0 ){
132 sqlite3TreeViewLine(pView, "nil-SELECT");
133 return;
134 }
drh38b41492015-06-08 15:08:15 +0000135 pView = sqlite3TreeViewPush(pView, moreToFollow);
drh2476a6f2015-11-07 15:19:59 +0000136 if( p->pWith ){
137 sqlite3TreeViewWith(pView, p->pWith, 1);
138 cnt = 1;
139 sqlite3TreeViewPush(pView, 1);
140 }
drh1c4505d2015-08-26 11:34:31 +0000141 do{
drh926961d2018-03-19 16:06:11 +0000142#if SELECTTRACE_ENABLED
143 sqlite3TreeViewLine(pView,
drhf20609d2018-04-23 17:43:35 +0000144 "SELECT%s%s (%s/%d/%p) selFlags=0x%x nSelectRow=%d",
drh926961d2018-03-19 16:06:11 +0000145 ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
146 ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""),
drhf20609d2018-04-23 17:43:35 +0000147 p->zSelName, p->iSelectId, p, p->selFlags,
drh926961d2018-03-19 16:06:11 +0000148 (int)p->nSelectRow
149 );
150#else
drhc3489bb2016-02-25 16:04:59 +0000151 sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x nSelectRow=%d",
drh1c4505d2015-08-26 11:34:31 +0000152 ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
drhc3489bb2016-02-25 16:04:59 +0000153 ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p, p->selFlags,
154 (int)p->nSelectRow
drh1c4505d2015-08-26 11:34:31 +0000155 );
drh926961d2018-03-19 16:06:11 +0000156#endif
drh1c4505d2015-08-26 11:34:31 +0000157 if( cnt++ ) sqlite3TreeViewPop(pView);
158 if( p->pPrior ){
159 n = 1000;
160 }else{
161 n = 0;
162 if( p->pSrc && p->pSrc->nSrc ) n++;
163 if( p->pWhere ) n++;
164 if( p->pGroupBy ) n++;
165 if( p->pHaving ) n++;
166 if( p->pOrderBy ) n++;
167 if( p->pLimit ) n++;
drh1c4505d2015-08-26 11:34:31 +0000168 }
169 sqlite3TreeViewExprList(pView, p->pEList, (n--)>0, "result-set");
170 if( p->pSrc && p->pSrc->nSrc ){
171 int i;
172 pView = sqlite3TreeViewPush(pView, (n--)>0);
173 sqlite3TreeViewLine(pView, "FROM");
174 for(i=0; i<p->pSrc->nSrc; i++){
175 struct SrcList_item *pItem = &p->pSrc->a[i];
176 StrAccum x;
177 char zLine[100];
178 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
drh5f4a6862016-01-30 12:50:25 +0000179 sqlite3XPrintf(&x, "{%d,*}", pItem->iCursor);
drh1c4505d2015-08-26 11:34:31 +0000180 if( pItem->zDatabase ){
drh5f4a6862016-01-30 12:50:25 +0000181 sqlite3XPrintf(&x, " %s.%s", pItem->zDatabase, pItem->zName);
drh1c4505d2015-08-26 11:34:31 +0000182 }else if( pItem->zName ){
drh5f4a6862016-01-30 12:50:25 +0000183 sqlite3XPrintf(&x, " %s", pItem->zName);
drh1c4505d2015-08-26 11:34:31 +0000184 }
185 if( pItem->pTab ){
drh5f4a6862016-01-30 12:50:25 +0000186 sqlite3XPrintf(&x, " tabname=%Q", pItem->pTab->zName);
drh1c4505d2015-08-26 11:34:31 +0000187 }
188 if( pItem->zAlias ){
drh5f4a6862016-01-30 12:50:25 +0000189 sqlite3XPrintf(&x, " (AS %s)", pItem->zAlias);
drh1c4505d2015-08-26 11:34:31 +0000190 }
191 if( pItem->fg.jointype & JT_LEFT ){
drh5f4a6862016-01-30 12:50:25 +0000192 sqlite3XPrintf(&x, " LEFT-JOIN");
drh1c4505d2015-08-26 11:34:31 +0000193 }
194 sqlite3StrAccumFinish(&x);
195 sqlite3TreeViewItem(pView, zLine, i<p->pSrc->nSrc-1);
196 if( pItem->pSelect ){
197 sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
198 }
199 if( pItem->fg.isTabFunc ){
200 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
201 }
202 sqlite3TreeViewPop(pView);
drh01d230c2015-08-19 17:11:37 +0000203 }
drh38b41492015-06-08 15:08:15 +0000204 sqlite3TreeViewPop(pView);
205 }
drh1c4505d2015-08-26 11:34:31 +0000206 if( p->pWhere ){
207 sqlite3TreeViewItem(pView, "WHERE", (n--)>0);
208 sqlite3TreeViewExpr(pView, p->pWhere, 0);
209 sqlite3TreeViewPop(pView);
drh38b41492015-06-08 15:08:15 +0000210 }
drh1c4505d2015-08-26 11:34:31 +0000211 if( p->pGroupBy ){
212 sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY");
213 }
214 if( p->pHaving ){
215 sqlite3TreeViewItem(pView, "HAVING", (n--)>0);
216 sqlite3TreeViewExpr(pView, p->pHaving, 0);
217 sqlite3TreeViewPop(pView);
218 }
219 if( p->pOrderBy ){
220 sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY");
221 }
222 if( p->pLimit ){
223 sqlite3TreeViewItem(pView, "LIMIT", (n--)>0);
drh8c0833f2017-11-14 23:48:23 +0000224 sqlite3TreeViewExpr(pView, p->pLimit->pLeft, p->pLimit->pRight!=0);
225 if( p->pLimit->pRight ){
226 sqlite3TreeViewItem(pView, "OFFSET", (n--)>0);
227 sqlite3TreeViewExpr(pView, p->pLimit->pRight, 0);
228 sqlite3TreeViewPop(pView);
229 }
drh1c4505d2015-08-26 11:34:31 +0000230 sqlite3TreeViewPop(pView);
231 }
232 if( p->pPrior ){
233 const char *zOp = "UNION";
234 switch( p->op ){
235 case TK_ALL: zOp = "UNION ALL"; break;
236 case TK_INTERSECT: zOp = "INTERSECT"; break;
237 case TK_EXCEPT: zOp = "EXCEPT"; break;
238 }
239 sqlite3TreeViewItem(pView, zOp, 1);
240 }
241 p = p->pPrior;
242 }while( p!=0 );
drh38b41492015-06-08 15:08:15 +0000243 sqlite3TreeViewPop(pView);
244}
245
246/*
247** Generate a human-readable explanation of an expression tree.
248*/
249void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
250 const char *zBinOp = 0; /* Binary operator */
251 const char *zUniOp = 0; /* Unary operator */
drhd97cda42017-04-14 14:02:14 +0000252 char zFlgs[60];
drh38b41492015-06-08 15:08:15 +0000253 pView = sqlite3TreeViewPush(pView, moreToFollow);
254 if( pExpr==0 ){
255 sqlite3TreeViewLine(pView, "nil");
256 sqlite3TreeViewPop(pView);
257 return;
258 }
drhb3d903e2015-06-18 14:09:13 +0000259 if( pExpr->flags ){
drhd97cda42017-04-14 14:02:14 +0000260 if( ExprHasProperty(pExpr, EP_FromJoin) ){
261 sqlite3_snprintf(sizeof(zFlgs),zFlgs," flags=0x%x iRJT=%d",
262 pExpr->flags, pExpr->iRightJoinTable);
263 }else{
264 sqlite3_snprintf(sizeof(zFlgs),zFlgs," flags=0x%x",pExpr->flags);
265 }
drhb3d903e2015-06-18 14:09:13 +0000266 }else{
267 zFlgs[0] = 0;
268 }
drh38b41492015-06-08 15:08:15 +0000269 switch( pExpr->op ){
270 case TK_AGG_COLUMN: {
drhb3d903e2015-06-18 14:09:13 +0000271 sqlite3TreeViewLine(pView, "AGG{%d:%d}%s",
272 pExpr->iTable, pExpr->iColumn, zFlgs);
drh38b41492015-06-08 15:08:15 +0000273 break;
274 }
275 case TK_COLUMN: {
276 if( pExpr->iTable<0 ){
277 /* This only happens when coding check constraints */
drhb3d903e2015-06-18 14:09:13 +0000278 sqlite3TreeViewLine(pView, "COLUMN(%d)%s", pExpr->iColumn, zFlgs);
drh38b41492015-06-08 15:08:15 +0000279 }else{
drhb3d903e2015-06-18 14:09:13 +0000280 sqlite3TreeViewLine(pView, "{%d:%d}%s",
281 pExpr->iTable, pExpr->iColumn, zFlgs);
drh38b41492015-06-08 15:08:15 +0000282 }
283 break;
284 }
285 case TK_INTEGER: {
286 if( pExpr->flags & EP_IntValue ){
287 sqlite3TreeViewLine(pView, "%d", pExpr->u.iValue);
288 }else{
289 sqlite3TreeViewLine(pView, "%s", pExpr->u.zToken);
290 }
291 break;
292 }
293#ifndef SQLITE_OMIT_FLOATING_POINT
294 case TK_FLOAT: {
295 sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
296 break;
297 }
298#endif
299 case TK_STRING: {
300 sqlite3TreeViewLine(pView,"%Q", pExpr->u.zToken);
301 break;
302 }
303 case TK_NULL: {
304 sqlite3TreeViewLine(pView,"NULL");
305 break;
306 }
drh34328212018-02-26 19:03:25 +0000307 case TK_TRUEFALSE: {
drh43c4ac82018-02-26 21:26:27 +0000308 sqlite3TreeViewLine(pView,
drh96acafb2018-02-27 14:49:25 +0000309 sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE");
drh34328212018-02-26 19:03:25 +0000310 break;
311 }
drh38b41492015-06-08 15:08:15 +0000312#ifndef SQLITE_OMIT_BLOB_LITERAL
313 case TK_BLOB: {
314 sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
315 break;
316 }
317#endif
318 case TK_VARIABLE: {
319 sqlite3TreeViewLine(pView,"VARIABLE(%s,%d)",
320 pExpr->u.zToken, pExpr->iColumn);
321 break;
322 }
323 case TK_REGISTER: {
324 sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable);
325 break;
326 }
drh38b41492015-06-08 15:08:15 +0000327 case TK_ID: {
328 sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken);
329 break;
330 }
331#ifndef SQLITE_OMIT_CAST
332 case TK_CAST: {
333 /* Expressions of the form: CAST(pLeft AS token) */
334 sqlite3TreeViewLine(pView,"CAST %Q", pExpr->u.zToken);
335 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
336 break;
337 }
338#endif /* SQLITE_OMIT_CAST */
339 case TK_LT: zBinOp = "LT"; break;
340 case TK_LE: zBinOp = "LE"; break;
341 case TK_GT: zBinOp = "GT"; break;
342 case TK_GE: zBinOp = "GE"; break;
343 case TK_NE: zBinOp = "NE"; break;
344 case TK_EQ: zBinOp = "EQ"; break;
345 case TK_IS: zBinOp = "IS"; break;
346 case TK_ISNOT: zBinOp = "ISNOT"; break;
347 case TK_AND: zBinOp = "AND"; break;
348 case TK_OR: zBinOp = "OR"; break;
349 case TK_PLUS: zBinOp = "ADD"; break;
350 case TK_STAR: zBinOp = "MUL"; break;
351 case TK_MINUS: zBinOp = "SUB"; break;
352 case TK_REM: zBinOp = "REM"; break;
353 case TK_BITAND: zBinOp = "BITAND"; break;
354 case TK_BITOR: zBinOp = "BITOR"; break;
355 case TK_SLASH: zBinOp = "DIV"; break;
356 case TK_LSHIFT: zBinOp = "LSHIFT"; break;
357 case TK_RSHIFT: zBinOp = "RSHIFT"; break;
358 case TK_CONCAT: zBinOp = "CONCAT"; break;
359 case TK_DOT: zBinOp = "DOT"; break;
360
361 case TK_UMINUS: zUniOp = "UMINUS"; break;
362 case TK_UPLUS: zUniOp = "UPLUS"; break;
363 case TK_BITNOT: zUniOp = "BITNOT"; break;
364 case TK_NOT: zUniOp = "NOT"; break;
365 case TK_ISNULL: zUniOp = "ISNULL"; break;
366 case TK_NOTNULL: zUniOp = "NOTNULL"; break;
367
drh34328212018-02-26 19:03:25 +0000368 case TK_TRUTH: {
drh43c4ac82018-02-26 21:26:27 +0000369 int x;
370 const char *azOp[] = {
371 "IS-FALSE", "IS-TRUE", "IS-NOT-FALSE", "IS-NOT-TRUE"
372 };
drh34328212018-02-26 19:03:25 +0000373 assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT );
374 assert( pExpr->pRight );
375 assert( pExpr->pRight->op==TK_TRUEFALSE );
drh96acafb2018-02-27 14:49:25 +0000376 x = (pExpr->op2==TK_ISNOT)*2 + sqlite3ExprTruthValue(pExpr->pRight);
drh43c4ac82018-02-26 21:26:27 +0000377 zUniOp = azOp[x];
drh34328212018-02-26 19:03:25 +0000378 break;
379 }
380
drh94fa9c42016-02-27 21:16:04 +0000381 case TK_SPAN: {
382 sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken);
383 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
384 break;
385 }
386
drh38b41492015-06-08 15:08:15 +0000387 case TK_COLLATE: {
388 sqlite3TreeViewLine(pView, "COLLATE %Q", pExpr->u.zToken);
389 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
390 break;
391 }
392
393 case TK_AGG_FUNCTION:
394 case TK_FUNCTION: {
395 ExprList *pFarg; /* List of function arguments */
396 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
397 pFarg = 0;
398 }else{
399 pFarg = pExpr->x.pList;
400 }
401 if( pExpr->op==TK_AGG_FUNCTION ){
402 sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q",
403 pExpr->op2, pExpr->u.zToken);
404 }else{
405 sqlite3TreeViewLine(pView, "FUNCTION %Q", pExpr->u.zToken);
406 }
407 if( pFarg ){
408 sqlite3TreeViewExprList(pView, pFarg, 0, 0);
409 }
410 break;
411 }
412#ifndef SQLITE_OMIT_SUBQUERY
413 case TK_EXISTS: {
drh9f6e14c2017-07-10 13:24:58 +0000414 sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags);
drh38b41492015-06-08 15:08:15 +0000415 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
416 break;
417 }
418 case TK_SELECT: {
drh9f6e14c2017-07-10 13:24:58 +0000419 sqlite3TreeViewLine(pView, "SELECT-expr flags=0x%x", pExpr->flags);
drh38b41492015-06-08 15:08:15 +0000420 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
421 break;
422 }
423 case TK_IN: {
drh9f6e14c2017-07-10 13:24:58 +0000424 sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags);
drh38b41492015-06-08 15:08:15 +0000425 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
426 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
427 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
428 }else{
429 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
430 }
431 break;
432 }
433#endif /* SQLITE_OMIT_SUBQUERY */
434
435 /*
436 ** x BETWEEN y AND z
437 **
438 ** This is equivalent to
439 **
440 ** x>=y AND x<=z
441 **
442 ** X is stored in pExpr->pLeft.
443 ** Y is stored in pExpr->pList->a[0].pExpr.
444 ** Z is stored in pExpr->pList->a[1].pExpr.
445 */
446 case TK_BETWEEN: {
447 Expr *pX = pExpr->pLeft;
448 Expr *pY = pExpr->x.pList->a[0].pExpr;
449 Expr *pZ = pExpr->x.pList->a[1].pExpr;
450 sqlite3TreeViewLine(pView, "BETWEEN");
451 sqlite3TreeViewExpr(pView, pX, 1);
452 sqlite3TreeViewExpr(pView, pY, 1);
453 sqlite3TreeViewExpr(pView, pZ, 0);
454 break;
455 }
456 case TK_TRIGGER: {
457 /* If the opcode is TK_TRIGGER, then the expression is a reference
458 ** to a column in the new.* or old.* pseudo-tables available to
459 ** trigger programs. In this case Expr.iTable is set to 1 for the
460 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn
461 ** is set to the column of the pseudo-table to read, or to -1 to
462 ** read the rowid field.
463 */
464 sqlite3TreeViewLine(pView, "%s(%d)",
465 pExpr->iTable ? "NEW" : "OLD", pExpr->iColumn);
466 break;
467 }
468 case TK_CASE: {
469 sqlite3TreeViewLine(pView, "CASE");
470 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
471 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
472 break;
473 }
474#ifndef SQLITE_OMIT_TRIGGER
475 case TK_RAISE: {
476 const char *zType = "unk";
477 switch( pExpr->affinity ){
478 case OE_Rollback: zType = "rollback"; break;
479 case OE_Abort: zType = "abort"; break;
480 case OE_Fail: zType = "fail"; break;
481 case OE_Ignore: zType = "ignore"; break;
482 }
483 sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken);
484 break;
485 }
486#endif
drhc84a4022016-05-27 12:30:20 +0000487 case TK_MATCH: {
488 sqlite3TreeViewLine(pView, "MATCH {%d:%d}%s",
489 pExpr->iTable, pExpr->iColumn, zFlgs);
490 sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
491 break;
492 }
drhdb97e562016-08-18 17:55:57 +0000493 case TK_VECTOR: {
494 sqlite3TreeViewBareExprList(pView, pExpr->x.pList, "VECTOR");
495 break;
496 }
drh48cb3a72016-08-18 18:09:10 +0000497 case TK_SELECT_COLUMN: {
498 sqlite3TreeViewLine(pView, "SELECT-COLUMN %d", pExpr->iColumn);
499 sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
500 break;
501 }
drh31d6fd52017-04-14 19:03:10 +0000502 case TK_IF_NULL_ROW: {
503 sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable);
504 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
505 break;
506 }
drh38b41492015-06-08 15:08:15 +0000507 default: {
508 sqlite3TreeViewLine(pView, "op=%d", pExpr->op);
509 break;
510 }
511 }
512 if( zBinOp ){
drhb3d903e2015-06-18 14:09:13 +0000513 sqlite3TreeViewLine(pView, "%s%s", zBinOp, zFlgs);
drh38b41492015-06-08 15:08:15 +0000514 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
515 sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
516 }else if( zUniOp ){
drhb3d903e2015-06-18 14:09:13 +0000517 sqlite3TreeViewLine(pView, "%s%s", zUniOp, zFlgs);
drh38b41492015-06-08 15:08:15 +0000518 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
519 }
520 sqlite3TreeViewPop(pView);
521}
522
drhdb97e562016-08-18 17:55:57 +0000523
drh38b41492015-06-08 15:08:15 +0000524/*
525** Generate a human-readable explanation of an expression list.
526*/
drhdb97e562016-08-18 17:55:57 +0000527void sqlite3TreeViewBareExprList(
drh38b41492015-06-08 15:08:15 +0000528 TreeView *pView,
529 const ExprList *pList,
drh38b41492015-06-08 15:08:15 +0000530 const char *zLabel
531){
drh38b41492015-06-08 15:08:15 +0000532 if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST";
533 if( pList==0 ){
534 sqlite3TreeViewLine(pView, "%s (empty)", zLabel);
535 }else{
drhdb97e562016-08-18 17:55:57 +0000536 int i;
drh38b41492015-06-08 15:08:15 +0000537 sqlite3TreeViewLine(pView, "%s", zLabel);
538 for(i=0; i<pList->nExpr; i++){
drh5579d592015-08-26 14:01:41 +0000539 int j = pList->a[i].u.x.iOrderByCol;
drh5a699a02017-12-22 19:53:02 +0000540 char *zName = pList->a[i].zName;
drhfbe07532018-04-23 20:04:38 +0000541 int moreToFollow = i<pList->nExpr - 1;
drh5a699a02017-12-22 19:53:02 +0000542 if( j || zName ){
drhfbe07532018-04-23 20:04:38 +0000543 sqlite3TreeViewPush(pView, moreToFollow);
544 moreToFollow = 0;
545 sqlite3TreeViewLine(pView, 0);
546 if( zName ){
547 fprintf(stdout, "AS %s ", zName);
548 }
549 if( j ){
550 fprintf(stdout, "iOrderByCol=%d", j);
551 }
552 fprintf(stdout, "\n");
553 fflush(stdout);
drh5a699a02017-12-22 19:53:02 +0000554 }
drhfbe07532018-04-23 20:04:38 +0000555 sqlite3TreeViewExpr(pView, pList->a[i].pExpr, moreToFollow);
drh5a699a02017-12-22 19:53:02 +0000556 if( j || zName ){
557 sqlite3TreeViewPop(pView);
558 }
drh38b41492015-06-08 15:08:15 +0000559 }
560 }
drhdb97e562016-08-18 17:55:57 +0000561}
562void sqlite3TreeViewExprList(
563 TreeView *pView,
564 const ExprList *pList,
565 u8 moreToFollow,
566 const char *zLabel
567){
568 pView = sqlite3TreeViewPush(pView, moreToFollow);
569 sqlite3TreeViewBareExprList(pView, pList, zLabel);
drh38b41492015-06-08 15:08:15 +0000570 sqlite3TreeViewPop(pView);
571}
572
573#endif /* SQLITE_DEBUG */