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; |
drh | 0c0d052 | 2022-04-29 17:13:52 +0000 | [diff] [blame] | 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 | } |
drh | 145d0a3 | 2018-11-08 22:53:06 +0000 | [diff] [blame] | 227 | if( pItem->pSelect ){ |
drh | 8e8e9de | 2022-04-29 17:45:39 +0000 | [diff] [blame^] | 228 | if( pItem->pTab ){ |
| 229 | Table *pTab = pItem->pTab; |
| 230 | sqlite3TreeViewColumnList(pView, pTab->aCol, pTab->nCol, 1); |
| 231 | } |
drh | 825a6bf | 2022-04-21 14:08:29 +0000 | [diff] [blame] | 232 | assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) ); |
drh | 0c0d052 | 2022-04-29 17:13:52 +0000 | [diff] [blame] | 233 | sqlite3TreeViewSelect(pView, pItem->pSelect, (--n)>0); |
drh | 145d0a3 | 2018-11-08 22:53:06 +0000 | [diff] [blame] | 234 | } |
| 235 | if( pItem->fg.isTabFunc ){ |
| 236 | sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:"); |
| 237 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 238 | sqlite3TreeViewPop(&pView); |
drh | 145d0a3 | 2018-11-08 22:53:06 +0000 | [diff] [blame] | 239 | } |
| 240 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 241 | |
| 242 | /* |
drh | 2e5c505 | 2016-08-27 20:21:51 +0000 | [diff] [blame] | 243 | ** Generate a human-readable description of a Select object. |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 244 | */ |
| 245 | void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){ |
| 246 | int n = 0; |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 247 | int cnt = 0; |
drh | 510b7ff | 2017-03-13 17:37:13 +0000 | [diff] [blame] | 248 | if( p==0 ){ |
| 249 | sqlite3TreeViewLine(pView, "nil-SELECT"); |
| 250 | return; |
| 251 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 252 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | 2476a6f | 2015-11-07 15:19:59 +0000 | [diff] [blame] | 253 | if( p->pWith ){ |
| 254 | sqlite3TreeViewWith(pView, p->pWith, 1); |
| 255 | cnt = 1; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 256 | sqlite3TreeViewPush(&pView, 1); |
drh | 2476a6f | 2015-11-07 15:19:59 +0000 | [diff] [blame] | 257 | } |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 258 | do{ |
drh | 55b4c82 | 2019-08-03 16:17:46 +0000 | [diff] [blame] | 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 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 270 | if( cnt++ ) sqlite3TreeViewPop(&pView); |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 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++; |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 281 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 282 | if( p->pWin ) n++; |
| 283 | if( p->pWinDefn ) n++; |
| 284 | #endif |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 285 | } |
drh | 55b4c82 | 2019-08-03 16:17:46 +0000 | [diff] [blame] | 286 | if( p->pEList ){ |
| 287 | sqlite3TreeViewExprList(pView, p->pEList, n>0, "result-set"); |
| 288 | } |
| 289 | n--; |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 290 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 291 | if( p->pWin ){ |
| 292 | Window *pX; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 293 | sqlite3TreeViewPush(&pView, (n--)>0); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 294 | sqlite3TreeViewLine(pView, "window-functions"); |
| 295 | for(pX=p->pWin; pX; pX=pX->pNextWin){ |
| 296 | sqlite3TreeViewWinFunc(pView, pX, pX->pNextWin!=0); |
| 297 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 298 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 299 | } |
| 300 | #endif |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 301 | if( p->pSrc && p->pSrc->nSrc ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 302 | sqlite3TreeViewPush(&pView, (n--)>0); |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 303 | sqlite3TreeViewLine(pView, "FROM"); |
drh | 145d0a3 | 2018-11-08 22:53:06 +0000 | [diff] [blame] | 304 | sqlite3TreeViewSrcList(pView, p->pSrc); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 305 | sqlite3TreeViewPop(&pView); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 306 | } |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 307 | if( p->pWhere ){ |
| 308 | sqlite3TreeViewItem(pView, "WHERE", (n--)>0); |
| 309 | sqlite3TreeViewExpr(pView, p->pWhere, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 310 | sqlite3TreeViewPop(&pView); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 311 | } |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 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); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 318 | sqlite3TreeViewPop(&pView); |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 319 | } |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 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 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 327 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 328 | } |
| 329 | #endif |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 330 | if( p->pOrderBy ){ |
| 331 | sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY"); |
| 332 | } |
| 333 | if( p->pLimit ){ |
| 334 | sqlite3TreeViewItem(pView, "LIMIT", (n--)>0); |
drh | 8c0833f | 2017-11-14 23:48:23 +0000 | [diff] [blame] | 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); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 339 | sqlite3TreeViewPop(&pView); |
drh | 8c0833f | 2017-11-14 23:48:23 +0000 | [diff] [blame] | 340 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 341 | sqlite3TreeViewPop(&pView); |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 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 ); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 354 | sqlite3TreeViewPop(&pView); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 355 | } |
| 356 | |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 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); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 370 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 371 | break; |
| 372 | } |
| 373 | case TK_CURRENT: { |
| 374 | sqlite3TreeViewItem(pView, "CURRENT", moreToFollow); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 375 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 376 | break; |
| 377 | } |
| 378 | case TK_PRECEDING: { |
| 379 | sqlite3TreeViewItem(pView, "PRECEDING", moreToFollow); |
| 380 | sqlite3TreeViewExpr(pView, pExpr, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 381 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 382 | break; |
| 383 | } |
| 384 | case TK_FOLLOWING: { |
| 385 | sqlite3TreeViewItem(pView, "FOLLOWING", moreToFollow); |
| 386 | sqlite3TreeViewExpr(pView, pExpr, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 387 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 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){ |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 399 | int nElement = 0; |
drh | 0dc0e9c | 2019-03-28 13:35:28 +0000 | [diff] [blame] | 400 | if( pWin->pFilter ){ |
| 401 | sqlite3TreeViewItem(pView, "FILTER", 1); |
| 402 | sqlite3TreeViewExpr(pView, pWin->pFilter, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 403 | sqlite3TreeViewPop(&pView); |
drh | 0dc0e9c | 2019-03-28 13:35:28 +0000 | [diff] [blame] | 404 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 405 | sqlite3TreeViewPush(&pView, more); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 406 | if( pWin->zName ){ |
drh | 6f1644c | 2019-03-28 13:53:12 +0000 | [diff] [blame] | 407 | sqlite3TreeViewLine(pView, "OVER %s (%p)", pWin->zName, pWin); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 408 | }else{ |
drh | 6f1644c | 2019-03-28 13:53:12 +0000 | [diff] [blame] | 409 | sqlite3TreeViewLine(pView, "OVER (%p)", pWin); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 410 | } |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 411 | if( pWin->zBase ) nElement++; |
| 412 | if( pWin->pOrderBy ) nElement++; |
| 413 | if( pWin->eFrmType ) nElement++; |
| 414 | if( pWin->eExclude ) nElement++; |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 415 | if( pWin->zBase ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 416 | sqlite3TreeViewPush(&pView, (--nElement)>0); |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 417 | sqlite3TreeViewLine(pView, "window: %s", pWin->zBase); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 418 | sqlite3TreeViewPop(&pView); |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 419 | } |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 420 | if( pWin->pPartition ){ |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 421 | sqlite3TreeViewExprList(pView, pWin->pPartition, nElement>0,"PARTITION-BY"); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 422 | } |
| 423 | if( pWin->pOrderBy ){ |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 424 | sqlite3TreeViewExprList(pView, pWin->pOrderBy, (--nElement)>0, "ORDER-BY"); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 425 | } |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 426 | if( pWin->eFrmType ){ |
drh | 0dc0e9c | 2019-03-28 13:35:28 +0000 | [diff] [blame] | 427 | char zBuf[30]; |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 428 | const char *zFrmType = "ROWS"; |
| 429 | if( pWin->eFrmType==TK_RANGE ) zFrmType = "RANGE"; |
| 430 | if( pWin->eFrmType==TK_GROUPS ) zFrmType = "GROUPS"; |
drh | 0dc0e9c | 2019-03-28 13:35:28 +0000 | [diff] [blame] | 431 | sqlite3_snprintf(sizeof(zBuf),zBuf,"%s%s",zFrmType, |
| 432 | pWin->bImplicitFrame ? " (implied)" : ""); |
| 433 | sqlite3TreeViewItem(pView, zBuf, (--nElement)>0); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 434 | sqlite3TreeViewBound(pView, pWin->eStart, pWin->pStart, 1); |
| 435 | sqlite3TreeViewBound(pView, pWin->eEnd, pWin->pEnd, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 436 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 437 | } |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 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 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 451 | sqlite3TreeViewPush(&pView, 0); |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 452 | sqlite3TreeViewLine(pView, "EXCLUDE %s", zExclude); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 453 | sqlite3TreeViewPop(&pView); |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 454 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 455 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 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){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 464 | sqlite3TreeViewPush(&pView, more); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 465 | sqlite3TreeViewLine(pView, "WINFUNC %s(%d)", |
drh | 105dcaa | 2022-03-10 16:01:14 +0000 | [diff] [blame] | 466 | pWin->pWFunc->zName, pWin->pWFunc->nArg); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 467 | sqlite3TreeViewWindow(pView, pWin, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 468 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 469 | } |
| 470 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 471 | |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 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 */ |
drh | e7375bf | 2020-03-10 19:24:38 +0000 | [diff] [blame] | 478 | char zFlgs[200]; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 479 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 480 | if( pExpr==0 ){ |
| 481 | sqlite3TreeViewLine(pView, "nil"); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 482 | sqlite3TreeViewPop(&pView); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 483 | return; |
| 484 | } |
drh | e7375bf | 2020-03-10 19:24:38 +0000 | [diff] [blame] | 485 | if( pExpr->flags || pExpr->affExpr || pExpr->vvaFlags ){ |
drh | b7e5199 | 2020-01-08 14:39:57 +0000 | [diff] [blame] | 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'); |
drh | d97cda4 | 2017-04-14 14:02:14 +0000 | [diff] [blame] | 490 | if( ExprHasProperty(pExpr, EP_FromJoin) ){ |
drh | d198526 | 2022-04-11 11:25:28 +0000 | [diff] [blame] | 491 | sqlite3_str_appendf(&x, " iJoin=%d", pExpr->w.iJoin); |
drh | d97cda4 | 2017-04-14 14:02:14 +0000 | [diff] [blame] | 492 | } |
drh | b7e5199 | 2020-01-08 14:39:57 +0000 | [diff] [blame] | 493 | if( ExprHasProperty(pExpr, EP_FromDDL) ){ |
| 494 | sqlite3_str_appendf(&x, " DDL"); |
| 495 | } |
drh | e7375bf | 2020-03-10 19:24:38 +0000 | [diff] [blame] | 496 | if( ExprHasVVAProperty(pExpr, EP_Immutable) ){ |
| 497 | sqlite3_str_appendf(&x, " IMMUTABLE"); |
| 498 | } |
drh | b7e5199 | 2020-01-08 14:39:57 +0000 | [diff] [blame] | 499 | sqlite3StrAccumFinish(&x); |
drh | b3d903e | 2015-06-18 14:09:13 +0000 | [diff] [blame] | 500 | }else{ |
| 501 | zFlgs[0] = 0; |
| 502 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 503 | switch( pExpr->op ){ |
| 504 | case TK_AGG_COLUMN: { |
drh | b3d903e | 2015-06-18 14:09:13 +0000 | [diff] [blame] | 505 | sqlite3TreeViewLine(pView, "AGG{%d:%d}%s", |
| 506 | pExpr->iTable, pExpr->iColumn, zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 507 | break; |
| 508 | } |
| 509 | case TK_COLUMN: { |
| 510 | if( pExpr->iTable<0 ){ |
| 511 | /* This only happens when coding check constraints */ |
drh | d493353 | 2019-10-31 12:30:38 +0000 | [diff] [blame] | 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); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 520 | }else{ |
drh | 477572b | 2021-10-07 20:46:29 +0000 | [diff] [blame] | 521 | assert( ExprUseYTab(pExpr) ); |
drh | a513e59 | 2019-12-20 20:08:56 +0000 | [diff] [blame] | 522 | sqlite3TreeViewLine(pView, "{%d:%d} pTab=%p%s", |
| 523 | pExpr->iTable, pExpr->iColumn, |
| 524 | pExpr->y.pTab, zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 525 | } |
drh | efad2e2 | 2018-07-27 16:57:11 +0000 | [diff] [blame] | 526 | if( ExprHasProperty(pExpr, EP_FixedCol) ){ |
| 527 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 528 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 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: { |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 541 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 542 | sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken); |
| 543 | break; |
| 544 | } |
| 545 | #endif |
| 546 | case TK_STRING: { |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 547 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 548 | sqlite3TreeViewLine(pView,"%Q", pExpr->u.zToken); |
| 549 | break; |
| 550 | } |
| 551 | case TK_NULL: { |
| 552 | sqlite3TreeViewLine(pView,"NULL"); |
| 553 | break; |
| 554 | } |
drh | 3432821 | 2018-02-26 19:03:25 +0000 | [diff] [blame] | 555 | case TK_TRUEFALSE: { |
drh | 348e002 | 2021-07-22 16:07:01 +0000 | [diff] [blame] | 556 | sqlite3TreeViewLine(pView,"%s%s", |
| 557 | sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE", zFlgs); |
drh | 3432821 | 2018-02-26 19:03:25 +0000 | [diff] [blame] | 558 | break; |
| 559 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 560 | #ifndef SQLITE_OMIT_BLOB_LITERAL |
| 561 | case TK_BLOB: { |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 562 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 563 | sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken); |
| 564 | break; |
| 565 | } |
| 566 | #endif |
| 567 | case TK_VARIABLE: { |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 568 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 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 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 577 | case TK_ID: { |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 578 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 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) */ |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 585 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 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; |
drh | e7375bf | 2020-03-10 19:24:38 +0000 | [diff] [blame] | 612 | case TK_LIMIT: zBinOp = "LIMIT"; break; |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 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 | |
drh | 3432821 | 2018-02-26 19:03:25 +0000 | [diff] [blame] | 621 | case TK_TRUTH: { |
drh | 43c4ac8 | 2018-02-26 21:26:27 +0000 | [diff] [blame] | 622 | int x; |
| 623 | const char *azOp[] = { |
| 624 | "IS-FALSE", "IS-TRUE", "IS-NOT-FALSE", "IS-NOT-TRUE" |
| 625 | }; |
drh | 3432821 | 2018-02-26 19:03:25 +0000 | [diff] [blame] | 626 | assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT ); |
| 627 | assert( pExpr->pRight ); |
dan | 6ece353 | 2019-06-12 13:49:32 +0000 | [diff] [blame] | 628 | assert( sqlite3ExprSkipCollate(pExpr->pRight)->op==TK_TRUEFALSE ); |
drh | 96acafb | 2018-02-27 14:49:25 +0000 | [diff] [blame] | 629 | x = (pExpr->op2==TK_ISNOT)*2 + sqlite3ExprTruthValue(pExpr->pRight); |
drh | 43c4ac8 | 2018-02-26 21:26:27 +0000 | [diff] [blame] | 630 | zUniOp = azOp[x]; |
drh | 3432821 | 2018-02-26 19:03:25 +0000 | [diff] [blame] | 631 | break; |
| 632 | } |
| 633 | |
drh | 94fa9c4 | 2016-02-27 21:16:04 +0000 | [diff] [blame] | 634 | case TK_SPAN: { |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 635 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 94fa9c4 | 2016-02-27 21:16:04 +0000 | [diff] [blame] | 636 | sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken); |
| 637 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 638 | break; |
| 639 | } |
| 640 | |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 641 | case TK_COLLATE: { |
drh | c204d81 | 2019-09-10 17:51:27 +0000 | [diff] [blame] | 642 | /* COLLATE operators without the EP_Collate flag are intended to |
drh | 018dbb1 | 2019-09-28 16:14:55 +0000 | [diff] [blame] | 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" */ |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 647 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | c204d81 | 2019-09-10 17:51:27 +0000 | [diff] [blame] | 648 | sqlite3TreeViewLine(pView, "%sCOLLATE %Q%s", |
| 649 | !ExprHasProperty(pExpr, EP_Collate) ? "SOFT-" : "", |
| 650 | pExpr->u.zToken, zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 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 */ |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 658 | Window *pWin; |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 659 | if( ExprHasProperty(pExpr, EP_TokenOnly) ){ |
| 660 | pFarg = 0; |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 661 | pWin = 0; |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 662 | }else{ |
drh | a4eeccd | 2021-10-07 17:43:30 +0000 | [diff] [blame] | 663 | assert( ExprUseXList(pExpr) ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 664 | pFarg = pExpr->x.pList; |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 665 | #ifndef SQLITE_OMIT_WINDOWFUNC |
drh | 014fff2 | 2020-01-08 22:22:36 +0000 | [diff] [blame] | 666 | pWin = ExprHasProperty(pExpr, EP_WinFunc) ? pExpr->y.pWin : 0; |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 667 | #else |
| 668 | pWin = 0; |
| 669 | #endif |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 670 | } |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 671 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 672 | if( pExpr->op==TK_AGG_FUNCTION ){ |
drh | e26d428 | 2020-06-09 11:59:15 +0000 | [diff] [blame] | 673 | sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s agg=%d[%d]/%p", |
drh | ca74fbf | 2020-05-24 02:05:04 +0000 | [diff] [blame] | 674 | pExpr->op2, pExpr->u.zToken, zFlgs, |
drh | e26d428 | 2020-06-09 11:59:15 +0000 | [diff] [blame] | 675 | pExpr->pAggInfo ? pExpr->pAggInfo->selId : 0, |
drh | ca74fbf | 2020-05-24 02:05:04 +0000 | [diff] [blame] | 676 | pExpr->iAgg, pExpr->pAggInfo); |
drh | d493353 | 2019-10-31 12:30:38 +0000 | [diff] [blame] | 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); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 688 | }else{ |
drh | 42d2fce | 2019-08-15 20:04:09 +0000 | [diff] [blame] | 689 | sqlite3TreeViewLine(pView, "FUNCTION %Q%s", pExpr->u.zToken, zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 690 | } |
| 691 | if( pFarg ){ |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 692 | sqlite3TreeViewExprList(pView, pFarg, pWin!=0, 0); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 693 | } |
mistachkin | 1489785 | 2018-07-23 18:53:49 +0000 | [diff] [blame] | 694 | #ifndef SQLITE_OMIT_WINDOWFUNC |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 695 | if( pWin ){ |
| 696 | sqlite3TreeViewWindow(pView, pWin, 0); |
| 697 | } |
| 698 | #endif |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 699 | break; |
| 700 | } |
| 701 | #ifndef SQLITE_OMIT_SUBQUERY |
| 702 | case TK_EXISTS: { |
drh | a4eeccd | 2021-10-07 17:43:30 +0000 | [diff] [blame] | 703 | assert( ExprUseXSelect(pExpr) ); |
drh | 9f6e14c | 2017-07-10 13:24:58 +0000 | [diff] [blame] | 704 | sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 705 | sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); |
| 706 | break; |
| 707 | } |
| 708 | case TK_SELECT: { |
drh | a4eeccd | 2021-10-07 17:43:30 +0000 | [diff] [blame] | 709 | assert( ExprUseXSelect(pExpr) ); |
drh | a0365c4 | 2020-06-05 04:01:50 +0000 | [diff] [blame] | 710 | sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 711 | sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); |
| 712 | break; |
| 713 | } |
| 714 | case TK_IN: { |
drh | 9f6e14c | 2017-07-10 13:24:58 +0000 | [diff] [blame] | 715 | sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 716 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); |
drh | a4eeccd | 2021-10-07 17:43:30 +0000 | [diff] [blame] | 717 | if( ExprUseXSelect(pExpr) ){ |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 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: { |
drh | a4eeccd | 2021-10-07 17:43:30 +0000 | [diff] [blame] | 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; |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 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); |
drh | a4eeccd | 2021-10-07 17:43:30 +0000 | [diff] [blame] | 765 | assert( ExprUseXList(pExpr) ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 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"; |
drh | 1194904 | 2019-08-05 18:01:42 +0000 | [diff] [blame] | 772 | switch( pExpr->affExpr ){ |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 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 | } |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 778 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 779 | sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken); |
| 780 | break; |
| 781 | } |
| 782 | #endif |
drh | c84a402 | 2016-05-27 12:30:20 +0000 | [diff] [blame] | 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 | } |
drh | db97e56 | 2016-08-18 17:55:57 +0000 | [diff] [blame] | 789 | case TK_VECTOR: { |
drh | 269d322 | 2019-10-23 18:09:39 +0000 | [diff] [blame] | 790 | char *z = sqlite3_mprintf("VECTOR%s",zFlgs); |
drh | a4eeccd | 2021-10-07 17:43:30 +0000 | [diff] [blame] | 791 | assert( ExprUseXList(pExpr) ); |
drh | 269d322 | 2019-10-23 18:09:39 +0000 | [diff] [blame] | 792 | sqlite3TreeViewBareExprList(pView, pExpr->x.pList, z); |
| 793 | sqlite3_free(z); |
drh | db97e56 | 2016-08-18 17:55:57 +0000 | [diff] [blame] | 794 | break; |
| 795 | } |
drh | 48cb3a7 | 2016-08-18 18:09:10 +0000 | [diff] [blame] | 796 | case TK_SELECT_COLUMN: { |
drh | e46292a | 2021-07-05 02:40:29 +0000 | [diff] [blame] | 797 | sqlite3TreeViewLine(pView, "SELECT-COLUMN %d of [0..%d]%s", |
| 798 | pExpr->iColumn, pExpr->iTable-1, |
| 799 | pExpr->pRight==pExpr->pLeft ? " (SELECT-owner)" : ""); |
drh | a4eeccd | 2021-10-07 17:43:30 +0000 | [diff] [blame] | 800 | assert( ExprUseXSelect(pExpr->pLeft) ); |
drh | 48cb3a7 | 2016-08-18 18:09:10 +0000 | [diff] [blame] | 801 | sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0); |
| 802 | break; |
| 803 | } |
drh | 31d6fd5 | 2017-04-14 19:03:10 +0000 | [diff] [blame] | 804 | case TK_IF_NULL_ROW: { |
| 805 | sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable); |
| 806 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 807 | break; |
| 808 | } |
drh | bf7f3a0 | 2021-05-24 11:35:16 +0000 | [diff] [blame] | 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 | } |
drh | 4a4e02b | 2021-07-04 22:33:08 +0000 | [diff] [blame] | 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 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 826 | default: { |
| 827 | sqlite3TreeViewLine(pView, "op=%d", pExpr->op); |
| 828 | break; |
| 829 | } |
| 830 | } |
| 831 | if( zBinOp ){ |
drh | b3d903e | 2015-06-18 14:09:13 +0000 | [diff] [blame] | 832 | sqlite3TreeViewLine(pView, "%s%s", zBinOp, zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 833 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); |
| 834 | sqlite3TreeViewExpr(pView, pExpr->pRight, 0); |
| 835 | }else if( zUniOp ){ |
drh | b3d903e | 2015-06-18 14:09:13 +0000 | [diff] [blame] | 836 | sqlite3TreeViewLine(pView, "%s%s", zUniOp, zFlgs); |
drh | 1194904 | 2019-08-05 18:01:42 +0000 | [diff] [blame] | 837 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 838 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 839 | sqlite3TreeViewPop(&pView); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 840 | } |
| 841 | |
drh | db97e56 | 2016-08-18 17:55:57 +0000 | [diff] [blame] | 842 | |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 843 | /* |
| 844 | ** Generate a human-readable explanation of an expression list. |
| 845 | */ |
drh | db97e56 | 2016-08-18 17:55:57 +0000 | [diff] [blame] | 846 | void sqlite3TreeViewBareExprList( |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 847 | TreeView *pView, |
| 848 | const ExprList *pList, |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 849 | const char *zLabel |
| 850 | ){ |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 851 | if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST"; |
| 852 | if( pList==0 ){ |
| 853 | sqlite3TreeViewLine(pView, "%s (empty)", zLabel); |
| 854 | }else{ |
drh | db97e56 | 2016-08-18 17:55:57 +0000 | [diff] [blame] | 855 | int i; |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 856 | sqlite3TreeViewLine(pView, "%s", zLabel); |
| 857 | for(i=0; i<pList->nExpr; i++){ |
drh | 5579d59 | 2015-08-26 14:01:41 +0000 | [diff] [blame] | 858 | int j = pList->a[i].u.x.iOrderByCol; |
drh | 41cee66 | 2019-12-12 20:22:34 +0000 | [diff] [blame] | 859 | char *zName = pList->a[i].zEName; |
drh | fbe0753 | 2018-04-23 20:04:38 +0000 | [diff] [blame] | 860 | int moreToFollow = i<pList->nExpr - 1; |
drh | 5a699a0 | 2017-12-22 19:53:02 +0000 | [diff] [blame] | 861 | if( j || zName ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 862 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | fbe0753 | 2018-04-23 20:04:38 +0000 | [diff] [blame] | 863 | moreToFollow = 0; |
| 864 | sqlite3TreeViewLine(pView, 0); |
| 865 | if( zName ){ |
drh | d4e9caf | 2022-04-20 12:14:20 +0000 | [diff] [blame] | 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); |
drh | 815b782 | 2022-04-20 15:07:39 +0000 | [diff] [blame] | 872 | if( pList->a[i].bUsed==0 ) fprintf(stdout, "(unused) "); |
drh | d4e9caf | 2022-04-20 12:14:20 +0000 | [diff] [blame] | 873 | break; |
| 874 | case ENAME_SPAN: |
| 875 | fprintf(stdout, "SPAN(\"%s\") ", zName); |
| 876 | break; |
| 877 | } |
drh | fbe0753 | 2018-04-23 20:04:38 +0000 | [diff] [blame] | 878 | } |
| 879 | if( j ){ |
| 880 | fprintf(stdout, "iOrderByCol=%d", j); |
| 881 | } |
| 882 | fprintf(stdout, "\n"); |
| 883 | fflush(stdout); |
drh | 5a699a0 | 2017-12-22 19:53:02 +0000 | [diff] [blame] | 884 | } |
drh | fbe0753 | 2018-04-23 20:04:38 +0000 | [diff] [blame] | 885 | sqlite3TreeViewExpr(pView, pList->a[i].pExpr, moreToFollow); |
drh | 5a699a0 | 2017-12-22 19:53:02 +0000 | [diff] [blame] | 886 | if( j || zName ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 887 | sqlite3TreeViewPop(&pView); |
drh | 5a699a0 | 2017-12-22 19:53:02 +0000 | [diff] [blame] | 888 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 889 | } |
| 890 | } |
drh | db97e56 | 2016-08-18 17:55:57 +0000 | [diff] [blame] | 891 | } |
| 892 | void sqlite3TreeViewExprList( |
| 893 | TreeView *pView, |
| 894 | const ExprList *pList, |
| 895 | u8 moreToFollow, |
| 896 | const char *zLabel |
| 897 | ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 898 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | db97e56 | 2016-08-18 17:55:57 +0000 | [diff] [blame] | 899 | sqlite3TreeViewBareExprList(pView, pList, zLabel); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 900 | sqlite3TreeViewPop(&pView); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 901 | } |
| 902 | |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 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)"; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 921 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 922 | sqlite3TreeViewLine(pView, 0); |
drh | a99e325 | 2022-04-15 15:47:14 +0000 | [diff] [blame] | 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 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 938 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 939 | } |
| 940 | } |
| 941 | } |
| 942 | void sqlite3TreeViewIdList( |
| 943 | TreeView *pView, |
| 944 | const IdList *pList, |
| 945 | u8 moreToFollow, |
| 946 | const char *zLabel |
| 947 | ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 948 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 949 | sqlite3TreeViewBareIdList(pView, pList, zLabel); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 950 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 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; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 962 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 963 | while( pUpsert ){ |
| 964 | int n; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 965 | sqlite3TreeViewPush(&pView, pUpsert->pNextUpsert!=0 || moreToFollow); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 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); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 974 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 975 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 976 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 977 | pUpsert = pUpsert->pNextUpsert; |
| 978 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 979 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | /* |
| 983 | ** Generate a human-readable diagram of the data structure that go |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 984 | ** into generating an DELETE statement. |
| 985 | */ |
| 986 | void sqlite3TreeViewDelete( |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 987 | const With *pWith, |
| 988 | const SrcList *pTabList, |
| 989 | const Expr *pWhere, |
| 990 | const ExprList *pOrderBy, |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 991 | const Expr *pLimit, |
| 992 | const Trigger *pTrigger |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 993 | ){ |
| 994 | int n = 0; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 995 | TreeView *pView = 0; |
| 996 | sqlite3TreeViewPush(&pView, 0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 997 | sqlite3TreeViewLine(pView, "DELETE"); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 998 | if( pWith ) n++; |
| 999 | if( pTabList ) n++; |
| 1000 | if( pWhere ) n++; |
| 1001 | if( pOrderBy ) n++; |
| 1002 | if( pLimit ) n++; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1003 | if( pTrigger ) n++; |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1004 | if( pWith ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1005 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1006 | sqlite3TreeViewWith(pView, pWith, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1007 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1008 | } |
| 1009 | if( pTabList ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1010 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1011 | sqlite3TreeViewLine(pView, "FROM"); |
| 1012 | sqlite3TreeViewSrcList(pView, pTabList); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1013 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1014 | } |
| 1015 | if( pWhere ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1016 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1017 | sqlite3TreeViewLine(pView, "WHERE"); |
| 1018 | sqlite3TreeViewExpr(pView, pWhere, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1019 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1020 | } |
| 1021 | if( pOrderBy ){ |
| 1022 | sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY"); |
| 1023 | } |
| 1024 | if( pLimit ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1025 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1026 | sqlite3TreeViewLine(pView, "LIMIT"); |
| 1027 | sqlite3TreeViewExpr(pView, pLimit, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1028 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1029 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1030 | if( pTrigger ){ |
| 1031 | sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); |
| 1032 | } |
| 1033 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | /* |
| 1037 | ** Generate a human-readable diagram of the data structure that go |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1038 | ** into generating an INSERT statement. |
| 1039 | */ |
| 1040 | void sqlite3TreeViewInsert( |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1041 | const With *pWith, |
| 1042 | const SrcList *pTabList, |
| 1043 | const IdList *pColumnList, |
| 1044 | const Select *pSelect, |
drh | c2d0df9 | 2022-04-06 18:30:17 +0000 | [diff] [blame] | 1045 | const ExprList *pExprList, |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1046 | int onError, |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1047 | const Upsert *pUpsert, |
| 1048 | const Trigger *pTrigger |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1049 | ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1050 | TreeView *pView = 0; |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 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 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1060 | sqlite3TreeViewPush(&pView, 0); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1061 | sqlite3TreeViewLine(pView, zLabel); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1062 | if( pWith ) n++; |
| 1063 | if( pTabList ) n++; |
| 1064 | if( pColumnList ) n++; |
| 1065 | if( pSelect ) n++; |
drh | c2d0df9 | 2022-04-06 18:30:17 +0000 | [diff] [blame] | 1066 | if( pExprList ) n++; |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1067 | if( pUpsert ) n++; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1068 | if( pTrigger ) n++; |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1069 | if( pWith ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1070 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1071 | sqlite3TreeViewWith(pView, pWith, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1072 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1073 | } |
| 1074 | if( pTabList ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1075 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1076 | sqlite3TreeViewLine(pView, "INTO"); |
| 1077 | sqlite3TreeViewSrcList(pView, pTabList); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1078 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1079 | } |
| 1080 | if( pColumnList ){ |
| 1081 | sqlite3TreeViewIdList(pView, pColumnList, (--n)>0, "COLUMNS"); |
| 1082 | } |
| 1083 | if( pSelect ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1084 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1085 | sqlite3TreeViewLine(pView, "DATA-SOURCE"); |
| 1086 | sqlite3TreeViewSelect(pView, pSelect, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1087 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1088 | } |
drh | c2d0df9 | 2022-04-06 18:30:17 +0000 | [diff] [blame] | 1089 | if( pExprList ){ |
| 1090 | sqlite3TreeViewExprList(pView, pExprList, (--n)>0, "VALUES"); |
| 1091 | } |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1092 | if( pUpsert ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1093 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1094 | sqlite3TreeViewLine(pView, "UPSERT"); |
| 1095 | sqlite3TreeViewUpsert(pView, pUpsert, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1096 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1097 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1098 | if( pTrigger ){ |
| 1099 | sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); |
| 1100 | } |
| 1101 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1104 | /* |
| 1105 | ** Generate a human-readable diagram of the data structure that go |
| 1106 | ** into generating an UPDATE statement. |
| 1107 | */ |
| 1108 | void sqlite3TreeViewUpdate( |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 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, |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1116 | const Upsert *pUpsert, |
| 1117 | const Trigger *pTrigger |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1118 | ){ |
| 1119 | int n = 0; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1120 | TreeView *pView = 0; |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 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 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1129 | sqlite3TreeViewPush(&pView, 0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1130 | sqlite3TreeViewLine(pView, zLabel); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 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++; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1138 | if( pTrigger ) n++; |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1139 | if( pWith ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1140 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1141 | sqlite3TreeViewWith(pView, pWith, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1142 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1143 | } |
| 1144 | if( pTabList ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1145 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1146 | sqlite3TreeViewLine(pView, "FROM"); |
| 1147 | sqlite3TreeViewSrcList(pView, pTabList); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1148 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1149 | } |
| 1150 | if( pChanges ){ |
| 1151 | sqlite3TreeViewExprList(pView, pChanges, (--n)>0, "SET"); |
| 1152 | } |
| 1153 | if( pWhere ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1154 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1155 | sqlite3TreeViewLine(pView, "WHERE"); |
| 1156 | sqlite3TreeViewExpr(pView, pWhere, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1157 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1158 | } |
| 1159 | if( pOrderBy ){ |
| 1160 | sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY"); |
| 1161 | } |
| 1162 | if( pLimit ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1163 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1164 | sqlite3TreeViewLine(pView, "LIMIT"); |
| 1165 | sqlite3TreeViewExpr(pView, pLimit, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1166 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1167 | } |
| 1168 | if( pUpsert ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1169 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1170 | sqlite3TreeViewLine(pView, "UPSERT"); |
| 1171 | sqlite3TreeViewUpsert(pView, pUpsert, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1172 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1173 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1174 | if( pTrigger ){ |
| 1175 | sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); |
| 1176 | } |
| 1177 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1178 | } |
| 1179 | |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 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 | |
drh | 8f1eb6f | 2022-04-06 12:25:04 +0000 | [diff] [blame] | 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); } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 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 |
drh | 8f1eb6f | 2022-04-06 12:25:04 +0000 | [diff] [blame] | 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 | |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 1264 | #endif /* SQLITE_DEBUG */ |