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