1 /* 2 ** 2015-06-08 3 ** 4 ** The author disclaims copyright to this source code. In place of 5 ** a legal notice, here is a blessing: 6 ** 7 ** May you do good and not evil. 8 ** May you find forgiveness for yourself and forgive others. 9 ** May you share freely, never taking more than you give. 10 ** 11 ************************************************************************* 12 ** 13 ** This file contains C code to implement the TreeView debugging routines. 14 ** These routines print a parse tree to standard output for debugging and 15 ** analysis. 16 ** 17 ** The interfaces in this file is only available when compiling 18 ** with SQLITE_DEBUG. 19 */ 20 #include "sqliteInt.h" 21 #ifdef SQLITE_DEBUG 22 23 /* 24 ** Add a new subitem to the tree. The moreToFollow flag indicates that this 25 ** is not the last item in the tree. 26 */ 27 static 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++; 35 } 36 assert( moreToFollow==0 || moreToFollow==1 ); 37 if( p->iLevel<(int)sizeof(p->bLine) ) p->bLine[p->iLevel] = moreToFollow; 38 } 39 40 /* 41 ** Finished with one layer of the tree 42 */ 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; 50 } 51 } 52 53 /* 54 ** Generate a single line of output for the tree, with a prefix that contains 55 ** all the appropriate tree lines 56 */ 57 void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){ 58 va_list ap; 59 int i; 60 StrAccum acc; 61 char zBuf[500]; 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); 66 } 67 sqlite3_str_append(&acc, p->bLine[i] ? "|-- " : "'-- ", 4); 68 } 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); 75 } 76 sqlite3StrAccumFinish(&acc); 77 fprintf(stdout,"%s", zBuf); 78 fflush(stdout); 79 } 80 81 /* 82 ** Shorthand for starting a new tree item that consists of a single label 83 */ 84 static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){ 85 sqlite3TreeViewPush(&p, moreFollows); 86 sqlite3TreeViewLine(p, "%s", zLabel); 87 } 88 89 /* 90 ** Show a list of Column objects in tree format. 91 */ 92 void sqlite3TreeViewColumnList( 93 TreeView *pView, 94 const Column *aCol, 95 int nCol, 96 u8 moreToFollow 97 ){ 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 moreToFollow = i<(nCol - 1); 104 sqlite3TreeViewPush(&pView, moreToFollow); 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; 120 } 121 } 122 } 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); 132 } 133 sqlite3TreeViewPop(&pView); 134 } 135 136 /* 137 ** Generate a human-readable description of a WITH clause. 138 */ 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); 147 } 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 = ','; 162 } 163 sqlite3_str_appendf(&x, ")"); 164 } 165 if( pCte->eM10d!=M10d_Any ){ 166 sqlite3_str_appendf(&x, " %sMATERIALIZED", 167 pCte->eM10d==M10d_No ? "NOT " : ""); 168 } 169 if( pCte->pUse ){ 170 sqlite3_str_appendf(&x, " (pUse=0x%p, nUse=%d)", pCte->pUse, 171 pCte->pUse->nUse); 172 } 173 sqlite3StrAccumFinish(&x); 174 sqlite3TreeViewItem(pView, zLine, i<pWith->nCte-1); 175 sqlite3TreeViewSelect(pView, pCte->pSelect, 0); 176 sqlite3TreeViewPop(&pView); 177 } 178 sqlite3TreeViewPop(&pView); 179 } 180 } 181 182 /* 183 ** Generate a human-readable description of a SrcList object. 184 */ 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[100]; 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); 199 } 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"); 208 } 209 if( pItem->fg.jointype & JT_LTORJ ){ 210 sqlite3_str_appendf(&x, " LTORJ"); 211 } 212 if( pItem->fg.fromDDL ){ 213 sqlite3_str_appendf(&x, " DDL"); 214 } 215 if( pItem->fg.isCte ){ 216 sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse); 217 } 218 sqlite3StrAccumFinish(&x); 219 sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1); 220 n = 0; 221 if( pItem->pSelect ) n++; 222 if( pItem->fg.isTabFunc ) n++; 223 if( pItem->fg.isUsing ) n++; 224 if( pItem->fg.isUsing ){ 225 sqlite3TreeViewIdList(pView, pItem->u3.pUsing, (--n)>0, "USING"); 226 } 227 if( pItem->pSelect ){ 228 if( pItem->pTab ){ 229 Table *pTab = pItem->pTab; 230 sqlite3TreeViewColumnList(pView, pTab->aCol, pTab->nCol, 1); 231 } 232 assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) ); 233 sqlite3TreeViewSelect(pView, pItem->pSelect, (--n)>0); 234 } 235 if( pItem->fg.isTabFunc ){ 236 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:"); 237 } 238 sqlite3TreeViewPop(&pView); 239 } 240 } 241 242 /* 243 ** Generate a human-readable description of a Select object. 244 */ 245 void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){ 246 int n = 0; 247 int cnt = 0; 248 if( p==0 ){ 249 sqlite3TreeViewLine(pView, "nil-SELECT"); 250 return; 251 } 252 sqlite3TreeViewPush(&pView, moreToFollow); 253 if( p->pWith ){ 254 sqlite3TreeViewWith(pView, p->pWith, 1); 255 cnt = 1; 256 sqlite3TreeViewPush(&pView, 1); 257 } 258 do{ 259 if( p->selFlags & SF_WhereBegin ){ 260 sqlite3TreeViewLine(pView, "sqlite3WhereBegin()"); 261 }else{ 262 sqlite3TreeViewLine(pView, 263 "SELECT%s%s (%u/%p) selFlags=0x%x nSelectRow=%d", 264 ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""), 265 ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), 266 p->selId, p, p->selFlags, 267 (int)p->nSelectRow 268 ); 269 } 270 if( cnt++ ) sqlite3TreeViewPop(&pView); 271 if( p->pPrior ){ 272 n = 1000; 273 }else{ 274 n = 0; 275 if( p->pSrc && p->pSrc->nSrc ) n++; 276 if( p->pWhere ) n++; 277 if( p->pGroupBy ) n++; 278 if( p->pHaving ) n++; 279 if( p->pOrderBy ) n++; 280 if( p->pLimit ) n++; 281 #ifndef SQLITE_OMIT_WINDOWFUNC 282 if( p->pWin ) n++; 283 if( p->pWinDefn ) n++; 284 #endif 285 } 286 if( p->pEList ){ 287 sqlite3TreeViewExprList(pView, p->pEList, n>0, "result-set"); 288 } 289 n--; 290 #ifndef SQLITE_OMIT_WINDOWFUNC 291 if( p->pWin ){ 292 Window *pX; 293 sqlite3TreeViewPush(&pView, (n--)>0); 294 sqlite3TreeViewLine(pView, "window-functions"); 295 for(pX=p->pWin; pX; pX=pX->pNextWin){ 296 sqlite3TreeViewWinFunc(pView, pX, pX->pNextWin!=0); 297 } 298 sqlite3TreeViewPop(&pView); 299 } 300 #endif 301 if( p->pSrc && p->pSrc->nSrc ){ 302 sqlite3TreeViewPush(&pView, (n--)>0); 303 sqlite3TreeViewLine(pView, "FROM"); 304 sqlite3TreeViewSrcList(pView, p->pSrc); 305 sqlite3TreeViewPop(&pView); 306 } 307 if( p->pWhere ){ 308 sqlite3TreeViewItem(pView, "WHERE", (n--)>0); 309 sqlite3TreeViewExpr(pView, p->pWhere, 0); 310 sqlite3TreeViewPop(&pView); 311 } 312 if( p->pGroupBy ){ 313 sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY"); 314 } 315 if( p->pHaving ){ 316 sqlite3TreeViewItem(pView, "HAVING", (n--)>0); 317 sqlite3TreeViewExpr(pView, p->pHaving, 0); 318 sqlite3TreeViewPop(&pView); 319 } 320 #ifndef SQLITE_OMIT_WINDOWFUNC 321 if( p->pWinDefn ){ 322 Window *pX; 323 sqlite3TreeViewItem(pView, "WINDOW", (n--)>0); 324 for(pX=p->pWinDefn; pX; pX=pX->pNextWin){ 325 sqlite3TreeViewWindow(pView, pX, pX->pNextWin!=0); 326 } 327 sqlite3TreeViewPop(&pView); 328 } 329 #endif 330 if( p->pOrderBy ){ 331 sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY"); 332 } 333 if( p->pLimit ){ 334 sqlite3TreeViewItem(pView, "LIMIT", (n--)>0); 335 sqlite3TreeViewExpr(pView, p->pLimit->pLeft, p->pLimit->pRight!=0); 336 if( p->pLimit->pRight ){ 337 sqlite3TreeViewItem(pView, "OFFSET", (n--)>0); 338 sqlite3TreeViewExpr(pView, p->pLimit->pRight, 0); 339 sqlite3TreeViewPop(&pView); 340 } 341 sqlite3TreeViewPop(&pView); 342 } 343 if( p->pPrior ){ 344 const char *zOp = "UNION"; 345 switch( p->op ){ 346 case TK_ALL: zOp = "UNION ALL"; break; 347 case TK_INTERSECT: zOp = "INTERSECT"; break; 348 case TK_EXCEPT: zOp = "EXCEPT"; break; 349 } 350 sqlite3TreeViewItem(pView, zOp, 1); 351 } 352 p = p->pPrior; 353 }while( p!=0 ); 354 sqlite3TreeViewPop(&pView); 355 } 356 357 #ifndef SQLITE_OMIT_WINDOWFUNC 358 /* 359 ** Generate a description of starting or stopping bounds 360 */ 361 void sqlite3TreeViewBound( 362 TreeView *pView, /* View context */ 363 u8 eBound, /* UNBOUNDED, CURRENT, PRECEDING, FOLLOWING */ 364 Expr *pExpr, /* Value for PRECEDING or FOLLOWING */ 365 u8 moreToFollow /* True if more to follow */ 366 ){ 367 switch( eBound ){ 368 case TK_UNBOUNDED: { 369 sqlite3TreeViewItem(pView, "UNBOUNDED", moreToFollow); 370 sqlite3TreeViewPop(&pView); 371 break; 372 } 373 case TK_CURRENT: { 374 sqlite3TreeViewItem(pView, "CURRENT", moreToFollow); 375 sqlite3TreeViewPop(&pView); 376 break; 377 } 378 case TK_PRECEDING: { 379 sqlite3TreeViewItem(pView, "PRECEDING", moreToFollow); 380 sqlite3TreeViewExpr(pView, pExpr, 0); 381 sqlite3TreeViewPop(&pView); 382 break; 383 } 384 case TK_FOLLOWING: { 385 sqlite3TreeViewItem(pView, "FOLLOWING", moreToFollow); 386 sqlite3TreeViewExpr(pView, pExpr, 0); 387 sqlite3TreeViewPop(&pView); 388 break; 389 } 390 } 391 } 392 #endif /* SQLITE_OMIT_WINDOWFUNC */ 393 394 #ifndef SQLITE_OMIT_WINDOWFUNC 395 /* 396 ** Generate a human-readable explanation for a Window object 397 */ 398 void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){ 399 int nElement = 0; 400 if( pWin->pFilter ){ 401 sqlite3TreeViewItem(pView, "FILTER", 1); 402 sqlite3TreeViewExpr(pView, pWin->pFilter, 0); 403 sqlite3TreeViewPop(&pView); 404 } 405 sqlite3TreeViewPush(&pView, more); 406 if( pWin->zName ){ 407 sqlite3TreeViewLine(pView, "OVER %s (%p)", pWin->zName, pWin); 408 }else{ 409 sqlite3TreeViewLine(pView, "OVER (%p)", pWin); 410 } 411 if( pWin->zBase ) nElement++; 412 if( pWin->pOrderBy ) nElement++; 413 if( pWin->eFrmType ) nElement++; 414 if( pWin->eExclude ) nElement++; 415 if( pWin->zBase ){ 416 sqlite3TreeViewPush(&pView, (--nElement)>0); 417 sqlite3TreeViewLine(pView, "window: %s", pWin->zBase); 418 sqlite3TreeViewPop(&pView); 419 } 420 if( pWin->pPartition ){ 421 sqlite3TreeViewExprList(pView, pWin->pPartition, nElement>0,"PARTITION-BY"); 422 } 423 if( pWin->pOrderBy ){ 424 sqlite3TreeViewExprList(pView, pWin->pOrderBy, (--nElement)>0, "ORDER-BY"); 425 } 426 if( pWin->eFrmType ){ 427 char zBuf[30]; 428 const char *zFrmType = "ROWS"; 429 if( pWin->eFrmType==TK_RANGE ) zFrmType = "RANGE"; 430 if( pWin->eFrmType==TK_GROUPS ) zFrmType = "GROUPS"; 431 sqlite3_snprintf(sizeof(zBuf),zBuf,"%s%s",zFrmType, 432 pWin->bImplicitFrame ? " (implied)" : ""); 433 sqlite3TreeViewItem(pView, zBuf, (--nElement)>0); 434 sqlite3TreeViewBound(pView, pWin->eStart, pWin->pStart, 1); 435 sqlite3TreeViewBound(pView, pWin->eEnd, pWin->pEnd, 0); 436 sqlite3TreeViewPop(&pView); 437 } 438 if( pWin->eExclude ){ 439 char zBuf[30]; 440 const char *zExclude; 441 switch( pWin->eExclude ){ 442 case TK_NO: zExclude = "NO OTHERS"; break; 443 case TK_CURRENT: zExclude = "CURRENT ROW"; break; 444 case TK_GROUP: zExclude = "GROUP"; break; 445 case TK_TIES: zExclude = "TIES"; break; 446 default: 447 sqlite3_snprintf(sizeof(zBuf),zBuf,"invalid(%d)", pWin->eExclude); 448 zExclude = zBuf; 449 break; 450 } 451 sqlite3TreeViewPush(&pView, 0); 452 sqlite3TreeViewLine(pView, "EXCLUDE %s", zExclude); 453 sqlite3TreeViewPop(&pView); 454 } 455 sqlite3TreeViewPop(&pView); 456 } 457 #endif /* SQLITE_OMIT_WINDOWFUNC */ 458 459 #ifndef SQLITE_OMIT_WINDOWFUNC 460 /* 461 ** Generate a human-readable explanation for a Window Function object 462 */ 463 void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){ 464 sqlite3TreeViewPush(&pView, more); 465 sqlite3TreeViewLine(pView, "WINFUNC %s(%d)", 466 pWin->pWFunc->zName, pWin->pWFunc->nArg); 467 sqlite3TreeViewWindow(pView, pWin, 0); 468 sqlite3TreeViewPop(&pView); 469 } 470 #endif /* SQLITE_OMIT_WINDOWFUNC */ 471 472 /* 473 ** Generate a human-readable explanation of an expression tree. 474 */ 475 void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){ 476 const char *zBinOp = 0; /* Binary operator */ 477 const char *zUniOp = 0; /* Unary operator */ 478 char zFlgs[200]; 479 sqlite3TreeViewPush(&pView, moreToFollow); 480 if( pExpr==0 ){ 481 sqlite3TreeViewLine(pView, "nil"); 482 sqlite3TreeViewPop(&pView); 483 return; 484 } 485 if( pExpr->flags || pExpr->affExpr || pExpr->vvaFlags ){ 486 StrAccum x; 487 sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0); 488 sqlite3_str_appendf(&x, " fg.af=%x.%c", 489 pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n'); 490 if( ExprHasProperty(pExpr, EP_FromJoin) ){ 491 sqlite3_str_appendf(&x, " iJoin=%d", pExpr->w.iJoin); 492 } 493 if( ExprHasProperty(pExpr, EP_FromDDL) ){ 494 sqlite3_str_appendf(&x, " DDL"); 495 } 496 if( ExprHasVVAProperty(pExpr, EP_Immutable) ){ 497 sqlite3_str_appendf(&x, " IMMUTABLE"); 498 } 499 sqlite3StrAccumFinish(&x); 500 }else{ 501 zFlgs[0] = 0; 502 } 503 switch( pExpr->op ){ 504 case TK_AGG_COLUMN: { 505 sqlite3TreeViewLine(pView, "AGG{%d:%d}%s", 506 pExpr->iTable, pExpr->iColumn, zFlgs); 507 break; 508 } 509 case TK_COLUMN: { 510 if( pExpr->iTable<0 ){ 511 /* This only happens when coding check constraints */ 512 char zOp2[16]; 513 if( pExpr->op2 ){ 514 sqlite3_snprintf(sizeof(zOp2),zOp2," op2=0x%02x",pExpr->op2); 515 }else{ 516 zOp2[0] = 0; 517 } 518 sqlite3TreeViewLine(pView, "COLUMN(%d)%s%s", 519 pExpr->iColumn, zFlgs, zOp2); 520 }else{ 521 assert( ExprUseYTab(pExpr) ); 522 sqlite3TreeViewLine(pView, "{%d:%d} pTab=%p%s", 523 pExpr->iTable, pExpr->iColumn, 524 pExpr->y.pTab, zFlgs); 525 } 526 if( ExprHasProperty(pExpr, EP_FixedCol) ){ 527 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); 528 } 529 break; 530 } 531 case TK_INTEGER: { 532 if( pExpr->flags & EP_IntValue ){ 533 sqlite3TreeViewLine(pView, "%d", pExpr->u.iValue); 534 }else{ 535 sqlite3TreeViewLine(pView, "%s", pExpr->u.zToken); 536 } 537 break; 538 } 539 #ifndef SQLITE_OMIT_FLOATING_POINT 540 case TK_FLOAT: { 541 assert( !ExprHasProperty(pExpr, EP_IntValue) ); 542 sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken); 543 break; 544 } 545 #endif 546 case TK_STRING: { 547 assert( !ExprHasProperty(pExpr, EP_IntValue) ); 548 sqlite3TreeViewLine(pView,"%Q", pExpr->u.zToken); 549 break; 550 } 551 case TK_NULL: { 552 sqlite3TreeViewLine(pView,"NULL"); 553 break; 554 } 555 case TK_TRUEFALSE: { 556 sqlite3TreeViewLine(pView,"%s%s", 557 sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE", zFlgs); 558 break; 559 } 560 #ifndef SQLITE_OMIT_BLOB_LITERAL 561 case TK_BLOB: { 562 assert( !ExprHasProperty(pExpr, EP_IntValue) ); 563 sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken); 564 break; 565 } 566 #endif 567 case TK_VARIABLE: { 568 assert( !ExprHasProperty(pExpr, EP_IntValue) ); 569 sqlite3TreeViewLine(pView,"VARIABLE(%s,%d)", 570 pExpr->u.zToken, pExpr->iColumn); 571 break; 572 } 573 case TK_REGISTER: { 574 sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable); 575 break; 576 } 577 case TK_ID: { 578 assert( !ExprHasProperty(pExpr, EP_IntValue) ); 579 sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken); 580 break; 581 } 582 #ifndef SQLITE_OMIT_CAST 583 case TK_CAST: { 584 /* Expressions of the form: CAST(pLeft AS token) */ 585 assert( !ExprHasProperty(pExpr, EP_IntValue) ); 586 sqlite3TreeViewLine(pView,"CAST %Q", pExpr->u.zToken); 587 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); 588 break; 589 } 590 #endif /* SQLITE_OMIT_CAST */ 591 case TK_LT: zBinOp = "LT"; break; 592 case TK_LE: zBinOp = "LE"; break; 593 case TK_GT: zBinOp = "GT"; break; 594 case TK_GE: zBinOp = "GE"; break; 595 case TK_NE: zBinOp = "NE"; break; 596 case TK_EQ: zBinOp = "EQ"; break; 597 case TK_IS: zBinOp = "IS"; break; 598 case TK_ISNOT: zBinOp = "ISNOT"; break; 599 case TK_AND: zBinOp = "AND"; break; 600 case TK_OR: zBinOp = "OR"; break; 601 case TK_PLUS: zBinOp = "ADD"; break; 602 case TK_STAR: zBinOp = "MUL"; break; 603 case TK_MINUS: zBinOp = "SUB"; break; 604 case TK_REM: zBinOp = "REM"; break; 605 case TK_BITAND: zBinOp = "BITAND"; break; 606 case TK_BITOR: zBinOp = "BITOR"; break; 607 case TK_SLASH: zBinOp = "DIV"; break; 608 case TK_LSHIFT: zBinOp = "LSHIFT"; break; 609 case TK_RSHIFT: zBinOp = "RSHIFT"; break; 610 case TK_CONCAT: zBinOp = "CONCAT"; break; 611 case TK_DOT: zBinOp = "DOT"; break; 612 case TK_LIMIT: zBinOp = "LIMIT"; break; 613 614 case TK_UMINUS: zUniOp = "UMINUS"; break; 615 case TK_UPLUS: zUniOp = "UPLUS"; break; 616 case TK_BITNOT: zUniOp = "BITNOT"; break; 617 case TK_NOT: zUniOp = "NOT"; break; 618 case TK_ISNULL: zUniOp = "ISNULL"; break; 619 case TK_NOTNULL: zUniOp = "NOTNULL"; break; 620 621 case TK_TRUTH: { 622 int x; 623 const char *azOp[] = { 624 "IS-FALSE", "IS-TRUE", "IS-NOT-FALSE", "IS-NOT-TRUE" 625 }; 626 assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT ); 627 assert( pExpr->pRight ); 628 assert( sqlite3ExprSkipCollate(pExpr->pRight)->op==TK_TRUEFALSE ); 629 x = (pExpr->op2==TK_ISNOT)*2 + sqlite3ExprTruthValue(pExpr->pRight); 630 zUniOp = azOp[x]; 631 break; 632 } 633 634 case TK_SPAN: { 635 assert( !ExprHasProperty(pExpr, EP_IntValue) ); 636 sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken); 637 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); 638 break; 639 } 640 641 case TK_COLLATE: { 642 /* COLLATE operators without the EP_Collate flag are intended to 643 ** emulate collation associated with a table column. These show 644 ** up in the treeview output as "SOFT-COLLATE". Explicit COLLATE 645 ** operators that appear in the original SQL always have the 646 ** EP_Collate bit set and appear in treeview output as just "COLLATE" */ 647 assert( !ExprHasProperty(pExpr, EP_IntValue) ); 648 sqlite3TreeViewLine(pView, "%sCOLLATE %Q%s", 649 !ExprHasProperty(pExpr, EP_Collate) ? "SOFT-" : "", 650 pExpr->u.zToken, zFlgs); 651 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); 652 break; 653 } 654 655 case TK_AGG_FUNCTION: 656 case TK_FUNCTION: { 657 ExprList *pFarg; /* List of function arguments */ 658 Window *pWin; 659 if( ExprHasProperty(pExpr, EP_TokenOnly) ){ 660 pFarg = 0; 661 pWin = 0; 662 }else{ 663 assert( ExprUseXList(pExpr) ); 664 pFarg = pExpr->x.pList; 665 #ifndef SQLITE_OMIT_WINDOWFUNC 666 pWin = ExprHasProperty(pExpr, EP_WinFunc) ? pExpr->y.pWin : 0; 667 #else 668 pWin = 0; 669 #endif 670 } 671 assert( !ExprHasProperty(pExpr, EP_IntValue) ); 672 if( pExpr->op==TK_AGG_FUNCTION ){ 673 sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s agg=%d[%d]/%p", 674 pExpr->op2, pExpr->u.zToken, zFlgs, 675 pExpr->pAggInfo ? pExpr->pAggInfo->selId : 0, 676 pExpr->iAgg, pExpr->pAggInfo); 677 }else if( pExpr->op2!=0 ){ 678 const char *zOp2; 679 char zBuf[8]; 680 sqlite3_snprintf(sizeof(zBuf),zBuf,"0x%02x",pExpr->op2); 681 zOp2 = zBuf; 682 if( pExpr->op2==NC_IsCheck ) zOp2 = "NC_IsCheck"; 683 if( pExpr->op2==NC_IdxExpr ) zOp2 = "NC_IdxExpr"; 684 if( pExpr->op2==NC_PartIdx ) zOp2 = "NC_PartIdx"; 685 if( pExpr->op2==NC_GenCol ) zOp2 = "NC_GenCol"; 686 sqlite3TreeViewLine(pView, "FUNCTION %Q%s op2=%s", 687 pExpr->u.zToken, zFlgs, zOp2); 688 }else{ 689 sqlite3TreeViewLine(pView, "FUNCTION %Q%s", pExpr->u.zToken, zFlgs); 690 } 691 if( pFarg ){ 692 sqlite3TreeViewExprList(pView, pFarg, pWin!=0, 0); 693 } 694 #ifndef SQLITE_OMIT_WINDOWFUNC 695 if( pWin ){ 696 sqlite3TreeViewWindow(pView, pWin, 0); 697 } 698 #endif 699 break; 700 } 701 #ifndef SQLITE_OMIT_SUBQUERY 702 case TK_EXISTS: { 703 assert( ExprUseXSelect(pExpr) ); 704 sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags); 705 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); 706 break; 707 } 708 case TK_SELECT: { 709 assert( ExprUseXSelect(pExpr) ); 710 sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags); 711 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); 712 break; 713 } 714 case TK_IN: { 715 sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags); 716 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); 717 if( ExprUseXSelect(pExpr) ){ 718 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); 719 }else{ 720 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0); 721 } 722 break; 723 } 724 #endif /* SQLITE_OMIT_SUBQUERY */ 725 726 /* 727 ** x BETWEEN y AND z 728 ** 729 ** This is equivalent to 730 ** 731 ** x>=y AND x<=z 732 ** 733 ** X is stored in pExpr->pLeft. 734 ** Y is stored in pExpr->pList->a[0].pExpr. 735 ** Z is stored in pExpr->pList->a[1].pExpr. 736 */ 737 case TK_BETWEEN: { 738 const Expr *pX, *pY, *pZ; 739 pX = pExpr->pLeft; 740 assert( ExprUseXList(pExpr) ); 741 assert( pExpr->x.pList->nExpr==2 ); 742 pY = pExpr->x.pList->a[0].pExpr; 743 pZ = pExpr->x.pList->a[1].pExpr; 744 sqlite3TreeViewLine(pView, "BETWEEN"); 745 sqlite3TreeViewExpr(pView, pX, 1); 746 sqlite3TreeViewExpr(pView, pY, 1); 747 sqlite3TreeViewExpr(pView, pZ, 0); 748 break; 749 } 750 case TK_TRIGGER: { 751 /* If the opcode is TK_TRIGGER, then the expression is a reference 752 ** to a column in the new.* or old.* pseudo-tables available to 753 ** trigger programs. In this case Expr.iTable is set to 1 for the 754 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn 755 ** is set to the column of the pseudo-table to read, or to -1 to 756 ** read the rowid field. 757 */ 758 sqlite3TreeViewLine(pView, "%s(%d)", 759 pExpr->iTable ? "NEW" : "OLD", pExpr->iColumn); 760 break; 761 } 762 case TK_CASE: { 763 sqlite3TreeViewLine(pView, "CASE"); 764 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); 765 assert( ExprUseXList(pExpr) ); 766 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0); 767 break; 768 } 769 #ifndef SQLITE_OMIT_TRIGGER 770 case TK_RAISE: { 771 const char *zType = "unk"; 772 switch( pExpr->affExpr ){ 773 case OE_Rollback: zType = "rollback"; break; 774 case OE_Abort: zType = "abort"; break; 775 case OE_Fail: zType = "fail"; break; 776 case OE_Ignore: zType = "ignore"; break; 777 } 778 assert( !ExprHasProperty(pExpr, EP_IntValue) ); 779 sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken); 780 break; 781 } 782 #endif 783 case TK_MATCH: { 784 sqlite3TreeViewLine(pView, "MATCH {%d:%d}%s", 785 pExpr->iTable, pExpr->iColumn, zFlgs); 786 sqlite3TreeViewExpr(pView, pExpr->pRight, 0); 787 break; 788 } 789 case TK_VECTOR: { 790 char *z = sqlite3_mprintf("VECTOR%s",zFlgs); 791 assert( ExprUseXList(pExpr) ); 792 sqlite3TreeViewBareExprList(pView, pExpr->x.pList, z); 793 sqlite3_free(z); 794 break; 795 } 796 case TK_SELECT_COLUMN: { 797 sqlite3TreeViewLine(pView, "SELECT-COLUMN %d of [0..%d]%s", 798 pExpr->iColumn, pExpr->iTable-1, 799 pExpr->pRight==pExpr->pLeft ? " (SELECT-owner)" : ""); 800 assert( ExprUseXSelect(pExpr->pLeft) ); 801 sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0); 802 break; 803 } 804 case TK_IF_NULL_ROW: { 805 sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable); 806 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); 807 break; 808 } 809 case TK_ERROR: { 810 Expr tmp; 811 sqlite3TreeViewLine(pView, "ERROR"); 812 tmp = *pExpr; 813 tmp.op = pExpr->op2; 814 sqlite3TreeViewExpr(pView, &tmp, 0); 815 break; 816 } 817 case TK_ROW: { 818 if( pExpr->iColumn<=0 ){ 819 sqlite3TreeViewLine(pView, "First FROM table rowid"); 820 }else{ 821 sqlite3TreeViewLine(pView, "First FROM table column %d", 822 pExpr->iColumn-1); 823 } 824 break; 825 } 826 default: { 827 sqlite3TreeViewLine(pView, "op=%d", pExpr->op); 828 break; 829 } 830 } 831 if( zBinOp ){ 832 sqlite3TreeViewLine(pView, "%s%s", zBinOp, zFlgs); 833 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); 834 sqlite3TreeViewExpr(pView, pExpr->pRight, 0); 835 }else if( zUniOp ){ 836 sqlite3TreeViewLine(pView, "%s%s", zUniOp, zFlgs); 837 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); 838 } 839 sqlite3TreeViewPop(&pView); 840 } 841 842 843 /* 844 ** Generate a human-readable explanation of an expression list. 845 */ 846 void sqlite3TreeViewBareExprList( 847 TreeView *pView, 848 const ExprList *pList, 849 const char *zLabel 850 ){ 851 if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST"; 852 if( pList==0 ){ 853 sqlite3TreeViewLine(pView, "%s (empty)", zLabel); 854 }else{ 855 int i; 856 sqlite3TreeViewLine(pView, "%s", zLabel); 857 for(i=0; i<pList->nExpr; i++){ 858 int j = pList->a[i].u.x.iOrderByCol; 859 char *zName = pList->a[i].zEName; 860 int moreToFollow = i<pList->nExpr - 1; 861 if( j || zName ){ 862 sqlite3TreeViewPush(&pView, moreToFollow); 863 moreToFollow = 0; 864 sqlite3TreeViewLine(pView, 0); 865 if( zName ){ 866 switch( pList->a[i].eEName ){ 867 default: 868 fprintf(stdout, "AS %s ", zName); 869 break; 870 case ENAME_TAB: 871 fprintf(stdout, "TABLE-ALIAS-NAME(\"%s\") ", zName); 872 if( pList->a[i].bUsed==0 ) fprintf(stdout, "(unused) "); 873 break; 874 case ENAME_SPAN: 875 fprintf(stdout, "SPAN(\"%s\") ", zName); 876 break; 877 } 878 } 879 if( j ){ 880 fprintf(stdout, "iOrderByCol=%d", j); 881 } 882 fprintf(stdout, "\n"); 883 fflush(stdout); 884 } 885 sqlite3TreeViewExpr(pView, pList->a[i].pExpr, moreToFollow); 886 if( j || zName ){ 887 sqlite3TreeViewPop(&pView); 888 } 889 } 890 } 891 } 892 void sqlite3TreeViewExprList( 893 TreeView *pView, 894 const ExprList *pList, 895 u8 moreToFollow, 896 const char *zLabel 897 ){ 898 sqlite3TreeViewPush(&pView, moreToFollow); 899 sqlite3TreeViewBareExprList(pView, pList, zLabel); 900 sqlite3TreeViewPop(&pView); 901 } 902 903 /* 904 ** Generate a human-readable explanation of an id-list. 905 */ 906 void sqlite3TreeViewBareIdList( 907 TreeView *pView, 908 const IdList *pList, 909 const char *zLabel 910 ){ 911 if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST"; 912 if( pList==0 ){ 913 sqlite3TreeViewLine(pView, "%s (empty)", zLabel); 914 }else{ 915 int i; 916 sqlite3TreeViewLine(pView, "%s", zLabel); 917 for(i=0; i<pList->nId; i++){ 918 char *zName = pList->a[i].zName; 919 int moreToFollow = i<pList->nId - 1; 920 if( zName==0 ) zName = "(null)"; 921 sqlite3TreeViewPush(&pView, moreToFollow); 922 sqlite3TreeViewLine(pView, 0); 923 if( pList->eU4==EU4_NONE ){ 924 fprintf(stdout, "%s\n", zName); 925 }else if( pList->eU4==EU4_IDX ){ 926 fprintf(stdout, "%s (%d)\n", zName, pList->a[i].u4.idx); 927 }else{ 928 assert( pList->eU4==EU4_EXPR ); 929 if( pList->a[i].u4.pExpr==0 ){ 930 fprintf(stdout, "%s (pExpr=NULL)\n", zName); 931 }else{ 932 fprintf(stdout, "%s\n", zName); 933 sqlite3TreeViewPush(&pView, i<pList->nId-1); 934 sqlite3TreeViewExpr(pView, pList->a[i].u4.pExpr, 0); 935 sqlite3TreeViewPop(&pView); 936 } 937 } 938 sqlite3TreeViewPop(&pView); 939 } 940 } 941 } 942 void sqlite3TreeViewIdList( 943 TreeView *pView, 944 const IdList *pList, 945 u8 moreToFollow, 946 const char *zLabel 947 ){ 948 sqlite3TreeViewPush(&pView, moreToFollow); 949 sqlite3TreeViewBareIdList(pView, pList, zLabel); 950 sqlite3TreeViewPop(&pView); 951 } 952 953 /* 954 ** Generate a human-readable explanation of a list of Upsert objects 955 */ 956 void sqlite3TreeViewUpsert( 957 TreeView *pView, 958 const Upsert *pUpsert, 959 u8 moreToFollow 960 ){ 961 if( pUpsert==0 ) return; 962 sqlite3TreeViewPush(&pView, moreToFollow); 963 while( pUpsert ){ 964 int n; 965 sqlite3TreeViewPush(&pView, pUpsert->pNextUpsert!=0 || moreToFollow); 966 sqlite3TreeViewLine(pView, "ON CONFLICT DO %s", 967 pUpsert->isDoUpdate ? "UPDATE" : "NOTHING"); 968 n = (pUpsert->pUpsertSet!=0) + (pUpsert->pUpsertWhere!=0); 969 sqlite3TreeViewExprList(pView, pUpsert->pUpsertTarget, (n--)>0, "TARGET"); 970 sqlite3TreeViewExprList(pView, pUpsert->pUpsertSet, (n--)>0, "SET"); 971 if( pUpsert->pUpsertWhere ){ 972 sqlite3TreeViewItem(pView, "WHERE", (n--)>0); 973 sqlite3TreeViewExpr(pView, pUpsert->pUpsertWhere, 0); 974 sqlite3TreeViewPop(&pView); 975 } 976 sqlite3TreeViewPop(&pView); 977 pUpsert = pUpsert->pNextUpsert; 978 } 979 sqlite3TreeViewPop(&pView); 980 } 981 982 /* 983 ** Generate a human-readable diagram of the data structure that go 984 ** into generating an DELETE statement. 985 */ 986 void sqlite3TreeViewDelete( 987 const With *pWith, 988 const SrcList *pTabList, 989 const Expr *pWhere, 990 const ExprList *pOrderBy, 991 const Expr *pLimit, 992 const Trigger *pTrigger 993 ){ 994 int n = 0; 995 TreeView *pView = 0; 996 sqlite3TreeViewPush(&pView, 0); 997 sqlite3TreeViewLine(pView, "DELETE"); 998 if( pWith ) n++; 999 if( pTabList ) n++; 1000 if( pWhere ) n++; 1001 if( pOrderBy ) n++; 1002 if( pLimit ) n++; 1003 if( pTrigger ) n++; 1004 if( pWith ){ 1005 sqlite3TreeViewPush(&pView, (--n)>0); 1006 sqlite3TreeViewWith(pView, pWith, 0); 1007 sqlite3TreeViewPop(&pView); 1008 } 1009 if( pTabList ){ 1010 sqlite3TreeViewPush(&pView, (--n)>0); 1011 sqlite3TreeViewLine(pView, "FROM"); 1012 sqlite3TreeViewSrcList(pView, pTabList); 1013 sqlite3TreeViewPop(&pView); 1014 } 1015 if( pWhere ){ 1016 sqlite3TreeViewPush(&pView, (--n)>0); 1017 sqlite3TreeViewLine(pView, "WHERE"); 1018 sqlite3TreeViewExpr(pView, pWhere, 0); 1019 sqlite3TreeViewPop(&pView); 1020 } 1021 if( pOrderBy ){ 1022 sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY"); 1023 } 1024 if( pLimit ){ 1025 sqlite3TreeViewPush(&pView, (--n)>0); 1026 sqlite3TreeViewLine(pView, "LIMIT"); 1027 sqlite3TreeViewExpr(pView, pLimit, 0); 1028 sqlite3TreeViewPop(&pView); 1029 } 1030 if( pTrigger ){ 1031 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); 1032 } 1033 sqlite3TreeViewPop(&pView); 1034 } 1035 1036 /* 1037 ** Generate a human-readable diagram of the data structure that go 1038 ** into generating an INSERT statement. 1039 */ 1040 void sqlite3TreeViewInsert( 1041 const With *pWith, 1042 const SrcList *pTabList, 1043 const IdList *pColumnList, 1044 const Select *pSelect, 1045 const ExprList *pExprList, 1046 int onError, 1047 const Upsert *pUpsert, 1048 const Trigger *pTrigger 1049 ){ 1050 TreeView *pView = 0; 1051 int n = 0; 1052 const char *zLabel = "INSERT"; 1053 switch( onError ){ 1054 case OE_Replace: zLabel = "REPLACE"; break; 1055 case OE_Ignore: zLabel = "INSERT OR IGNORE"; break; 1056 case OE_Rollback: zLabel = "INSERT OR ROLLBACK"; break; 1057 case OE_Abort: zLabel = "INSERT OR ABORT"; break; 1058 case OE_Fail: zLabel = "INSERT OR FAIL"; break; 1059 } 1060 sqlite3TreeViewPush(&pView, 0); 1061 sqlite3TreeViewLine(pView, zLabel); 1062 if( pWith ) n++; 1063 if( pTabList ) n++; 1064 if( pColumnList ) n++; 1065 if( pSelect ) n++; 1066 if( pExprList ) n++; 1067 if( pUpsert ) n++; 1068 if( pTrigger ) n++; 1069 if( pWith ){ 1070 sqlite3TreeViewPush(&pView, (--n)>0); 1071 sqlite3TreeViewWith(pView, pWith, 0); 1072 sqlite3TreeViewPop(&pView); 1073 } 1074 if( pTabList ){ 1075 sqlite3TreeViewPush(&pView, (--n)>0); 1076 sqlite3TreeViewLine(pView, "INTO"); 1077 sqlite3TreeViewSrcList(pView, pTabList); 1078 sqlite3TreeViewPop(&pView); 1079 } 1080 if( pColumnList ){ 1081 sqlite3TreeViewIdList(pView, pColumnList, (--n)>0, "COLUMNS"); 1082 } 1083 if( pSelect ){ 1084 sqlite3TreeViewPush(&pView, (--n)>0); 1085 sqlite3TreeViewLine(pView, "DATA-SOURCE"); 1086 sqlite3TreeViewSelect(pView, pSelect, 0); 1087 sqlite3TreeViewPop(&pView); 1088 } 1089 if( pExprList ){ 1090 sqlite3TreeViewExprList(pView, pExprList, (--n)>0, "VALUES"); 1091 } 1092 if( pUpsert ){ 1093 sqlite3TreeViewPush(&pView, (--n)>0); 1094 sqlite3TreeViewLine(pView, "UPSERT"); 1095 sqlite3TreeViewUpsert(pView, pUpsert, 0); 1096 sqlite3TreeViewPop(&pView); 1097 } 1098 if( pTrigger ){ 1099 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); 1100 } 1101 sqlite3TreeViewPop(&pView); 1102 } 1103 1104 /* 1105 ** Generate a human-readable diagram of the data structure that go 1106 ** into generating an UPDATE statement. 1107 */ 1108 void sqlite3TreeViewUpdate( 1109 const With *pWith, 1110 const SrcList *pTabList, 1111 const ExprList *pChanges, 1112 const Expr *pWhere, 1113 int onError, 1114 const ExprList *pOrderBy, 1115 const Expr *pLimit, 1116 const Upsert *pUpsert, 1117 const Trigger *pTrigger 1118 ){ 1119 int n = 0; 1120 TreeView *pView = 0; 1121 const char *zLabel = "UPDATE"; 1122 switch( onError ){ 1123 case OE_Replace: zLabel = "UPDATE OR REPLACE"; break; 1124 case OE_Ignore: zLabel = "UPDATE OR IGNORE"; break; 1125 case OE_Rollback: zLabel = "UPDATE OR ROLLBACK"; break; 1126 case OE_Abort: zLabel = "UPDATE OR ABORT"; break; 1127 case OE_Fail: zLabel = "UPDATE OR FAIL"; break; 1128 } 1129 sqlite3TreeViewPush(&pView, 0); 1130 sqlite3TreeViewLine(pView, zLabel); 1131 if( pWith ) n++; 1132 if( pTabList ) n++; 1133 if( pChanges ) n++; 1134 if( pWhere ) n++; 1135 if( pOrderBy ) n++; 1136 if( pLimit ) n++; 1137 if( pUpsert ) n++; 1138 if( pTrigger ) n++; 1139 if( pWith ){ 1140 sqlite3TreeViewPush(&pView, (--n)>0); 1141 sqlite3TreeViewWith(pView, pWith, 0); 1142 sqlite3TreeViewPop(&pView); 1143 } 1144 if( pTabList ){ 1145 sqlite3TreeViewPush(&pView, (--n)>0); 1146 sqlite3TreeViewLine(pView, "FROM"); 1147 sqlite3TreeViewSrcList(pView, pTabList); 1148 sqlite3TreeViewPop(&pView); 1149 } 1150 if( pChanges ){ 1151 sqlite3TreeViewExprList(pView, pChanges, (--n)>0, "SET"); 1152 } 1153 if( pWhere ){ 1154 sqlite3TreeViewPush(&pView, (--n)>0); 1155 sqlite3TreeViewLine(pView, "WHERE"); 1156 sqlite3TreeViewExpr(pView, pWhere, 0); 1157 sqlite3TreeViewPop(&pView); 1158 } 1159 if( pOrderBy ){ 1160 sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY"); 1161 } 1162 if( pLimit ){ 1163 sqlite3TreeViewPush(&pView, (--n)>0); 1164 sqlite3TreeViewLine(pView, "LIMIT"); 1165 sqlite3TreeViewExpr(pView, pLimit, 0); 1166 sqlite3TreeViewPop(&pView); 1167 } 1168 if( pUpsert ){ 1169 sqlite3TreeViewPush(&pView, (--n)>0); 1170 sqlite3TreeViewLine(pView, "UPSERT"); 1171 sqlite3TreeViewUpsert(pView, pUpsert, 0); 1172 sqlite3TreeViewPop(&pView); 1173 } 1174 if( pTrigger ){ 1175 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); 1176 } 1177 sqlite3TreeViewPop(&pView); 1178 } 1179 1180 #ifndef SQLITE_OMIT_TRIGGER 1181 /* 1182 ** Show a human-readable graph of a TriggerStep 1183 */ 1184 void sqlite3TreeViewTriggerStep( 1185 TreeView *pView, 1186 const TriggerStep *pStep, 1187 u8 moreToFollow, 1188 u8 showFullList 1189 ){ 1190 int cnt = 0; 1191 if( pStep==0 ) return; 1192 sqlite3TreeViewPush(&pView, 1193 moreToFollow || (showFullList && pStep->pNext!=0)); 1194 do{ 1195 if( cnt++ && pStep->pNext==0 ){ 1196 sqlite3TreeViewPop(&pView); 1197 sqlite3TreeViewPush(&pView, 0); 1198 } 1199 sqlite3TreeViewLine(pView, "%s", pStep->zSpan ? pStep->zSpan : "RETURNING"); 1200 }while( showFullList && (pStep = pStep->pNext)!=0 ); 1201 sqlite3TreeViewPop(&pView); 1202 } 1203 1204 /* 1205 ** Show a human-readable graph of a Trigger 1206 */ 1207 void sqlite3TreeViewTrigger( 1208 TreeView *pView, 1209 const Trigger *pTrigger, 1210 u8 moreToFollow, 1211 u8 showFullList 1212 ){ 1213 int cnt = 0; 1214 if( pTrigger==0 ) return; 1215 sqlite3TreeViewPush(&pView, 1216 moreToFollow || (showFullList && pTrigger->pNext!=0)); 1217 do{ 1218 if( cnt++ && pTrigger->pNext==0 ){ 1219 sqlite3TreeViewPop(&pView); 1220 sqlite3TreeViewPush(&pView, 0); 1221 } 1222 sqlite3TreeViewLine(pView, "TRIGGER %s", pTrigger->zName); 1223 sqlite3TreeViewPush(&pView, 0); 1224 sqlite3TreeViewTriggerStep(pView, pTrigger->step_list, 0, 1); 1225 sqlite3TreeViewPop(&pView); 1226 }while( showFullList && (pTrigger = pTrigger->pNext)!=0 ); 1227 sqlite3TreeViewPop(&pView); 1228 } 1229 #endif /* SQLITE_OMIT_TRIGGER */ 1230 1231 1232 /* 1233 ** These simplified versions of the tree-view routines omit unnecessary 1234 ** parameters. These variants are intended to be used from a symbolic 1235 ** debugger, such as "gdb", during interactive debugging sessions. 1236 ** 1237 ** This routines are given external linkage so that they will always be 1238 ** accessible to the debugging, and to avoid warnings about unused 1239 ** functions. But these routines only exist in debugging builds, so they 1240 ** do not contaminate the interface. 1241 */ 1242 void sqlite3ShowExpr(const Expr *p){ sqlite3TreeViewExpr(0,p,0); } 1243 void sqlite3ShowExprList(const ExprList *p){ sqlite3TreeViewExprList(0,p,0,0);} 1244 void sqlite3ShowIdList(const IdList *p){ sqlite3TreeViewIdList(0,p,0,0); } 1245 void sqlite3ShowSrcList(const SrcList *p){ sqlite3TreeViewSrcList(0,p); } 1246 void sqlite3ShowSelect(const Select *p){ sqlite3TreeViewSelect(0,p,0); } 1247 void sqlite3ShowWith(const With *p){ sqlite3TreeViewWith(0,p,0); } 1248 void sqlite3ShowUpsert(const Upsert *p){ sqlite3TreeViewUpsert(0,p,0); } 1249 #ifndef SQLITE_OMIT_TRIGGER 1250 void sqlite3ShowTriggerStep(const TriggerStep *p){ 1251 sqlite3TreeViewTriggerStep(0,p,0,0); 1252 } 1253 void sqlite3ShowTriggerStepList(const TriggerStep *p){ 1254 sqlite3TreeViewTriggerStep(0,p,0,1); 1255 } 1256 void sqlite3ShowTrigger(const Trigger *p){ sqlite3TreeViewTrigger(0,p,0,0); } 1257 void sqlite3ShowTriggerList(const Trigger *p){ sqlite3TreeViewTrigger(0,p,0,1);} 1258 #endif 1259 #ifndef SQLITE_OMIT_WINDOWFUNC 1260 void sqlite3ShowWindow(const Window *p){ sqlite3TreeViewWindow(0,p,0); } 1261 void sqlite3ShowWinFunc(const Window *p){ sqlite3TreeViewWinFunc(0,p,0); } 1262 #endif 1263 1264 #endif /* SQLITE_DEBUG */ 1265