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