Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/sqlite/src/src/treeview.c

Issue 2751253002: [sql] Import SQLite 3.17.0. (Closed)
Patch Set: also clang on Linux i386 Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/sqlite/src/src/tokenize.c ('k') | third_party/sqlite/src/src/trigger.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 ** 2015-06-08 2 ** 2015-06-08
3 ** 3 **
4 ** The author disclaims copyright to this source code. In place of 4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing: 5 ** a legal notice, here is a blessing:
6 ** 6 **
7 ** May you do good and not evil. 7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others. 8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give. 9 ** May you share freely, never taking more than you give.
10 ** 10 **
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 StrAccum acc; 56 StrAccum acc;
57 char zBuf[500]; 57 char zBuf[500];
58 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); 58 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
59 if( p ){ 59 if( p ){
60 for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){ 60 for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){
61 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "| " : " ", 4); 61 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "| " : " ", 4);
62 } 62 }
63 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4); 63 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
64 } 64 }
65 va_start(ap, zFormat); 65 va_start(ap, zFormat);
66 sqlite3VXPrintf(&acc, 0, zFormat, ap); 66 sqlite3VXPrintf(&acc, zFormat, ap);
67 va_end(ap); 67 va_end(ap);
68 assert( acc.nChar>0 );
68 if( zBuf[acc.nChar-1]!='\n' ) sqlite3StrAccumAppend(&acc, "\n", 1); 69 if( zBuf[acc.nChar-1]!='\n' ) sqlite3StrAccumAppend(&acc, "\n", 1);
69 sqlite3StrAccumFinish(&acc); 70 sqlite3StrAccumFinish(&acc);
70 fprintf(stdout,"%s", zBuf); 71 fprintf(stdout,"%s", zBuf);
71 fflush(stdout); 72 fflush(stdout);
72 } 73 }
73 74
74 /* 75 /*
75 ** Shorthand for starting a new tree item that consists of a single label 76 ** Shorthand for starting a new tree item that consists of a single label
76 */ 77 */
77 static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){ 78 static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){
(...skipping 13 matching lines...) Expand all
91 }else{ 92 }else{
92 sqlite3TreeViewLine(pView, "WITH (0x%p)", pWith); 93 sqlite3TreeViewLine(pView, "WITH (0x%p)", pWith);
93 } 94 }
94 if( pWith->nCte>0 ){ 95 if( pWith->nCte>0 ){
95 pView = sqlite3TreeViewPush(pView, 1); 96 pView = sqlite3TreeViewPush(pView, 1);
96 for(i=0; i<pWith->nCte; i++){ 97 for(i=0; i<pWith->nCte; i++){
97 StrAccum x; 98 StrAccum x;
98 char zLine[1000]; 99 char zLine[1000];
99 const struct Cte *pCte = &pWith->a[i]; 100 const struct Cte *pCte = &pWith->a[i];
100 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); 101 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
101 sqlite3XPrintf(&x, 0, "%s", pCte->zName); 102 sqlite3XPrintf(&x, "%s", pCte->zName);
102 if( pCte->pCols && pCte->pCols->nExpr>0 ){ 103 if( pCte->pCols && pCte->pCols->nExpr>0 ){
103 char cSep = '('; 104 char cSep = '(';
104 int j; 105 int j;
105 for(j=0; j<pCte->pCols->nExpr; j++){ 106 for(j=0; j<pCte->pCols->nExpr; j++){
106 sqlite3XPrintf(&x, 0, "%c%s", cSep, pCte->pCols->a[j].zName); 107 sqlite3XPrintf(&x, "%c%s", cSep, pCte->pCols->a[j].zName);
107 cSep = ','; 108 cSep = ',';
108 } 109 }
109 sqlite3XPrintf(&x, 0, ")"); 110 sqlite3XPrintf(&x, ")");
110 } 111 }
111 sqlite3XPrintf(&x, 0, " AS"); 112 sqlite3XPrintf(&x, " AS");
112 sqlite3StrAccumFinish(&x); 113 sqlite3StrAccumFinish(&x);
113 sqlite3TreeViewItem(pView, zLine, i<pWith->nCte-1); 114 sqlite3TreeViewItem(pView, zLine, i<pWith->nCte-1);
114 sqlite3TreeViewSelect(pView, pCte->pSelect, 0); 115 sqlite3TreeViewSelect(pView, pCte->pSelect, 0);
115 sqlite3TreeViewPop(pView); 116 sqlite3TreeViewPop(pView);
116 } 117 }
117 sqlite3TreeViewPop(pView); 118 sqlite3TreeViewPop(pView);
118 } 119 }
119 } 120 }
120 121
121 122
122 /* 123 /*
123 ** Generate a human-readable description of a the Select object. 124 ** Generate a human-readable description of a Select object.
124 */ 125 */
125 void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){ 126 void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
126 int n = 0; 127 int n = 0;
127 int cnt = 0; 128 int cnt = 0;
128 pView = sqlite3TreeViewPush(pView, moreToFollow); 129 pView = sqlite3TreeViewPush(pView, moreToFollow);
129 if( p->pWith ){ 130 if( p->pWith ){
130 sqlite3TreeViewWith(pView, p->pWith, 1); 131 sqlite3TreeViewWith(pView, p->pWith, 1);
131 cnt = 1; 132 cnt = 1;
132 sqlite3TreeViewPush(pView, 1); 133 sqlite3TreeViewPush(pView, 1);
133 } 134 }
134 do{ 135 do{
135 sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x", 136 sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x nSelectRow=%d",
136 ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""), 137 ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
137 ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p, p->selFlags 138 ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p, p->selFlags,
139 (int)p->nSelectRow
138 ); 140 );
139 if( cnt++ ) sqlite3TreeViewPop(pView); 141 if( cnt++ ) sqlite3TreeViewPop(pView);
140 if( p->pPrior ){ 142 if( p->pPrior ){
141 n = 1000; 143 n = 1000;
142 }else{ 144 }else{
143 n = 0; 145 n = 0;
144 if( p->pSrc && p->pSrc->nSrc ) n++; 146 if( p->pSrc && p->pSrc->nSrc ) n++;
145 if( p->pWhere ) n++; 147 if( p->pWhere ) n++;
146 if( p->pGroupBy ) n++; 148 if( p->pGroupBy ) n++;
147 if( p->pHaving ) n++; 149 if( p->pHaving ) n++;
148 if( p->pOrderBy ) n++; 150 if( p->pOrderBy ) n++;
149 if( p->pLimit ) n++; 151 if( p->pLimit ) n++;
150 if( p->pOffset ) n++; 152 if( p->pOffset ) n++;
151 } 153 }
152 sqlite3TreeViewExprList(pView, p->pEList, (n--)>0, "result-set"); 154 sqlite3TreeViewExprList(pView, p->pEList, (n--)>0, "result-set");
153 if( p->pSrc && p->pSrc->nSrc ){ 155 if( p->pSrc && p->pSrc->nSrc ){
154 int i; 156 int i;
155 pView = sqlite3TreeViewPush(pView, (n--)>0); 157 pView = sqlite3TreeViewPush(pView, (n--)>0);
156 sqlite3TreeViewLine(pView, "FROM"); 158 sqlite3TreeViewLine(pView, "FROM");
157 for(i=0; i<p->pSrc->nSrc; i++){ 159 for(i=0; i<p->pSrc->nSrc; i++){
158 struct SrcList_item *pItem = &p->pSrc->a[i]; 160 struct SrcList_item *pItem = &p->pSrc->a[i];
159 StrAccum x; 161 StrAccum x;
160 char zLine[100]; 162 char zLine[100];
161 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); 163 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
162 sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor); 164 sqlite3XPrintf(&x, "{%d,*}", pItem->iCursor);
163 if( pItem->zDatabase ){ 165 if( pItem->zDatabase ){
164 sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName); 166 sqlite3XPrintf(&x, " %s.%s", pItem->zDatabase, pItem->zName);
165 }else if( pItem->zName ){ 167 }else if( pItem->zName ){
166 sqlite3XPrintf(&x, 0, " %s", pItem->zName); 168 sqlite3XPrintf(&x, " %s", pItem->zName);
167 } 169 }
168 if( pItem->pTab ){ 170 if( pItem->pTab ){
169 sqlite3XPrintf(&x, 0, " tabname=%Q", pItem->pTab->zName); 171 sqlite3XPrintf(&x, " tabname=%Q", pItem->pTab->zName);
170 } 172 }
171 if( pItem->zAlias ){ 173 if( pItem->zAlias ){
172 sqlite3XPrintf(&x, 0, " (AS %s)", pItem->zAlias); 174 sqlite3XPrintf(&x, " (AS %s)", pItem->zAlias);
173 } 175 }
174 if( pItem->fg.jointype & JT_LEFT ){ 176 if( pItem->fg.jointype & JT_LEFT ){
175 sqlite3XPrintf(&x, 0, " LEFT-JOIN"); 177 sqlite3XPrintf(&x, " LEFT-JOIN");
176 } 178 }
177 sqlite3StrAccumFinish(&x); 179 sqlite3StrAccumFinish(&x);
178 sqlite3TreeViewItem(pView, zLine, i<p->pSrc->nSrc-1); 180 sqlite3TreeViewItem(pView, zLine, i<p->pSrc->nSrc-1);
179 if( pItem->pSelect ){ 181 if( pItem->pSelect ){
180 sqlite3TreeViewSelect(pView, pItem->pSelect, 0); 182 sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
181 } 183 }
182 if( pItem->fg.isTabFunc ){ 184 if( pItem->fg.isTabFunc ){
183 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:"); 185 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
184 } 186 }
185 sqlite3TreeViewPop(pView); 187 sqlite3TreeViewPop(pView);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 case TK_CONCAT: zBinOp = "CONCAT"; break; 333 case TK_CONCAT: zBinOp = "CONCAT"; break;
332 case TK_DOT: zBinOp = "DOT"; break; 334 case TK_DOT: zBinOp = "DOT"; break;
333 335
334 case TK_UMINUS: zUniOp = "UMINUS"; break; 336 case TK_UMINUS: zUniOp = "UMINUS"; break;
335 case TK_UPLUS: zUniOp = "UPLUS"; break; 337 case TK_UPLUS: zUniOp = "UPLUS"; break;
336 case TK_BITNOT: zUniOp = "BITNOT"; break; 338 case TK_BITNOT: zUniOp = "BITNOT"; break;
337 case TK_NOT: zUniOp = "NOT"; break; 339 case TK_NOT: zUniOp = "NOT"; break;
338 case TK_ISNULL: zUniOp = "ISNULL"; break; 340 case TK_ISNULL: zUniOp = "ISNULL"; break;
339 case TK_NOTNULL: zUniOp = "NOTNULL"; break; 341 case TK_NOTNULL: zUniOp = "NOTNULL"; break;
340 342
343 case TK_SPAN: {
344 sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken);
345 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
346 break;
347 }
348
341 case TK_COLLATE: { 349 case TK_COLLATE: {
342 sqlite3TreeViewLine(pView, "COLLATE %Q", pExpr->u.zToken); 350 sqlite3TreeViewLine(pView, "COLLATE %Q", pExpr->u.zToken);
343 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); 351 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
344 break; 352 break;
345 } 353 }
346 354
347 case TK_AGG_FUNCTION: 355 case TK_AGG_FUNCTION:
348 case TK_FUNCTION: { 356 case TK_FUNCTION: {
349 ExprList *pFarg; /* List of function arguments */ 357 ExprList *pFarg; /* List of function arguments */
350 if( ExprHasProperty(pExpr, EP_TokenOnly) ){ 358 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 switch( pExpr->affinity ){ 439 switch( pExpr->affinity ){
432 case OE_Rollback: zType = "rollback"; break; 440 case OE_Rollback: zType = "rollback"; break;
433 case OE_Abort: zType = "abort"; break; 441 case OE_Abort: zType = "abort"; break;
434 case OE_Fail: zType = "fail"; break; 442 case OE_Fail: zType = "fail"; break;
435 case OE_Ignore: zType = "ignore"; break; 443 case OE_Ignore: zType = "ignore"; break;
436 } 444 }
437 sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken); 445 sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken);
438 break; 446 break;
439 } 447 }
440 #endif 448 #endif
449 case TK_MATCH: {
450 sqlite3TreeViewLine(pView, "MATCH {%d:%d}%s",
451 pExpr->iTable, pExpr->iColumn, zFlgs);
452 sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
453 break;
454 }
455 case TK_VECTOR: {
456 sqlite3TreeViewBareExprList(pView, pExpr->x.pList, "VECTOR");
457 break;
458 }
459 case TK_SELECT_COLUMN: {
460 sqlite3TreeViewLine(pView, "SELECT-COLUMN %d", pExpr->iColumn);
461 sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
462 break;
463 }
441 default: { 464 default: {
442 sqlite3TreeViewLine(pView, "op=%d", pExpr->op); 465 sqlite3TreeViewLine(pView, "op=%d", pExpr->op);
443 break; 466 break;
444 } 467 }
445 } 468 }
446 if( zBinOp ){ 469 if( zBinOp ){
447 sqlite3TreeViewLine(pView, "%s%s", zBinOp, zFlgs); 470 sqlite3TreeViewLine(pView, "%s%s", zBinOp, zFlgs);
448 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); 471 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
449 sqlite3TreeViewExpr(pView, pExpr->pRight, 0); 472 sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
450 }else if( zUniOp ){ 473 }else if( zUniOp ){
451 sqlite3TreeViewLine(pView, "%s%s", zUniOp, zFlgs); 474 sqlite3TreeViewLine(pView, "%s%s", zUniOp, zFlgs);
452 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); 475 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
453 } 476 }
454 sqlite3TreeViewPop(pView); 477 sqlite3TreeViewPop(pView);
455 } 478 }
456 479
480
457 /* 481 /*
458 ** Generate a human-readable explanation of an expression list. 482 ** Generate a human-readable explanation of an expression list.
459 */ 483 */
460 void sqlite3TreeViewExprList( 484 void sqlite3TreeViewBareExprList(
461 TreeView *pView, 485 TreeView *pView,
462 const ExprList *pList, 486 const ExprList *pList,
463 u8 moreToFollow,
464 const char *zLabel 487 const char *zLabel
465 ){ 488 ){
466 int i;
467 pView = sqlite3TreeViewPush(pView, moreToFollow);
468 if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST"; 489 if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST";
469 if( pList==0 ){ 490 if( pList==0 ){
470 sqlite3TreeViewLine(pView, "%s (empty)", zLabel); 491 sqlite3TreeViewLine(pView, "%s (empty)", zLabel);
471 }else{ 492 }else{
493 int i;
472 sqlite3TreeViewLine(pView, "%s", zLabel); 494 sqlite3TreeViewLine(pView, "%s", zLabel);
473 for(i=0; i<pList->nExpr; i++){ 495 for(i=0; i<pList->nExpr; i++){
474 int j = pList->a[i].u.x.iOrderByCol; 496 int j = pList->a[i].u.x.iOrderByCol;
475 if( j ){ 497 if( j ){
476 sqlite3TreeViewPush(pView, 0); 498 sqlite3TreeViewPush(pView, 0);
477 sqlite3TreeViewLine(pView, "iOrderByCol=%d", j); 499 sqlite3TreeViewLine(pView, "iOrderByCol=%d", j);
478 } 500 }
479 sqlite3TreeViewExpr(pView, pList->a[i].pExpr, i<pList->nExpr-1); 501 sqlite3TreeViewExpr(pView, pList->a[i].pExpr, i<pList->nExpr-1);
480 if( j ) sqlite3TreeViewPop(pView); 502 if( j ) sqlite3TreeViewPop(pView);
481 } 503 }
482 } 504 }
505 }
506 void sqlite3TreeViewExprList(
507 TreeView *pView,
508 const ExprList *pList,
509 u8 moreToFollow,
510 const char *zLabel
511 ){
512 pView = sqlite3TreeViewPush(pView, moreToFollow);
513 sqlite3TreeViewBareExprList(pView, pList, zLabel);
483 sqlite3TreeViewPop(pView); 514 sqlite3TreeViewPop(pView);
484 } 515 }
485 516
486 #endif /* SQLITE_DEBUG */ 517 #endif /* SQLITE_DEBUG */
OLDNEW
« no previous file with comments | « third_party/sqlite/src/src/tokenize.c ('k') | third_party/sqlite/src/src/trigger.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698