blob: 3ba8a63cd7763a93b982d2f331f6e8e85d7423ce [file] [log] [blame]
drh38b41492015-06-08 15:08:15 +00001/*
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*/
drh2a7dcbf2022-04-06 15:41:53 +000027static void sqlite3TreeViewPush(TreeView **pp, u8 moreToFollow){
28 TreeView *p = *pp;
drh38b41492015-06-08 15:08:15 +000029 if( p==0 ){
drh2a7dcbf2022-04-06 15:41:53 +000030 *pp = p = sqlite3_malloc64( sizeof(*p) );
31 if( p==0 ) return;
drh38b41492015-06-08 15:08:15 +000032 memset(p, 0, sizeof(*p));
33 }else{
34 p->iLevel++;
35 }
36 assert( moreToFollow==0 || moreToFollow==1 );
drhe684ac62022-03-08 13:59:46 +000037 if( p->iLevel<(int)sizeof(p->bLine) ) p->bLine[p->iLevel] = moreToFollow;
drh38b41492015-06-08 15:08:15 +000038}
39
40/*
41** Finished with one layer of the tree
42*/
drh2a7dcbf2022-04-06 15:41:53 +000043static void sqlite3TreeViewPop(TreeView **pp){
44 TreeView *p = *pp;
drh38b41492015-06-08 15:08:15 +000045 if( p==0 ) return;
46 p->iLevel--;
drh2a7dcbf2022-04-06 15:41:53 +000047 if( p->iLevel<0 ){
48 sqlite3_free(p);
49 *pp = 0;
50 }
drh38b41492015-06-08 15:08:15 +000051}
52
53/*
54** Generate a single line of output for the tree, with a prefix that contains
55** all the appropriate tree lines
56*/
drh2a7dcbf2022-04-06 15:41:53 +000057void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){
drh38b41492015-06-08 15:08:15 +000058 va_list ap;
59 int i;
60 StrAccum acc;
61 char zBuf[500];
62 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
63 if( p ){
drhe684ac62022-03-08 13:59:46 +000064 for(i=0; i<p->iLevel && i<(int)sizeof(p->bLine)-1; i++){
drh0cdbe1a2018-05-09 13:46:26 +000065 sqlite3_str_append(&acc, p->bLine[i] ? "| " : " ", 4);
drh38b41492015-06-08 15:08:15 +000066 }
drh0cdbe1a2018-05-09 13:46:26 +000067 sqlite3_str_append(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
drh38b41492015-06-08 15:08:15 +000068 }
drhfbe07532018-04-23 20:04:38 +000069 if( zFormat!=0 ){
70 va_start(ap, zFormat);
drh0cdbe1a2018-05-09 13:46:26 +000071 sqlite3_str_vappendf(&acc, zFormat, ap);
drhfbe07532018-04-23 20:04:38 +000072 va_end(ap);
drh10c0e712019-04-25 18:15:38 +000073 assert( acc.nChar>0 || acc.accError );
drh0cdbe1a2018-05-09 13:46:26 +000074 sqlite3_str_append(&acc, "\n", 1);
drhfbe07532018-04-23 20:04:38 +000075 }
drh38b41492015-06-08 15:08:15 +000076 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*/
84static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){
drh2a7dcbf2022-04-06 15:41:53 +000085 sqlite3TreeViewPush(&p, moreFollows);
drh38b41492015-06-08 15:08:15 +000086 sqlite3TreeViewLine(p, "%s", zLabel);
87}
88
drh2476a6f2015-11-07 15:19:59 +000089/*
90** Generate a human-readable description of a WITH clause.
91*/
92void 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 ){
drh2a7dcbf2022-04-06 15:41:53 +0000102 sqlite3TreeViewPush(&pView, moreToFollow);
drh2476a6f2015-11-07 15:19:59 +0000103 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);
drh0cdbe1a2018-05-09 13:46:26 +0000108 sqlite3_str_appendf(&x, "%s", pCte->zName);
drh2476a6f2015-11-07 15:19:59 +0000109 if( pCte->pCols && pCte->pCols->nExpr>0 ){
110 char cSep = '(';
111 int j;
112 for(j=0; j<pCte->pCols->nExpr; j++){
drh41cee662019-12-12 20:22:34 +0000113 sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zEName);
drh2476a6f2015-11-07 15:19:59 +0000114 cSep = ',';
115 }
drh0cdbe1a2018-05-09 13:46:26 +0000116 sqlite3_str_appendf(&x, ")");
drh2476a6f2015-11-07 15:19:59 +0000117 }
drha79e2a22021-02-21 23:44:14 +0000118 if( pCte->pUse ){
119 sqlite3_str_appendf(&x, " (pUse=0x%p, nUse=%d)", pCte->pUse,
120 pCte->pUse->nUse);
121 }
drh2476a6f2015-11-07 15:19:59 +0000122 sqlite3StrAccumFinish(&x);
123 sqlite3TreeViewItem(pView, zLine, i<pWith->nCte-1);
124 sqlite3TreeViewSelect(pView, pCte->pSelect, 0);
drh2a7dcbf2022-04-06 15:41:53 +0000125 sqlite3TreeViewPop(&pView);
drh2476a6f2015-11-07 15:19:59 +0000126 }
drh2a7dcbf2022-04-06 15:41:53 +0000127 sqlite3TreeViewPop(&pView);
drh2476a6f2015-11-07 15:19:59 +0000128 }
129}
130
drh145d0a32018-11-08 22:53:06 +0000131/*
132** Generate a human-readable description of a SrcList object.
133*/
134void sqlite3TreeViewSrcList(TreeView *pView, const SrcList *pSrc){
135 int i;
drhb60d1fb2022-04-13 18:32:04 +0000136 if( pSrc==0 ) return;
drh145d0a32018-11-08 22:53:06 +0000137 for(i=0; i<pSrc->nSrc; i++){
drh76012942021-02-21 21:04:54 +0000138 const SrcItem *pItem = &pSrc->a[i];
drh145d0a32018-11-08 22:53:06 +0000139 StrAccum x;
140 char zLine[100];
141 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
drhff374912021-04-12 12:58:55 +0000142 x.printfFlags |= SQLITE_PRINTF_INTERNAL;
drh6610e6a2021-03-19 19:44:56 +0000143 sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem);
drh145d0a32018-11-08 22:53:06 +0000144 if( pItem->pTab ){
drhf7f6dbf2020-03-21 22:03:32 +0000145 sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx",
146 pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, pItem->colUsed);
drh145d0a32018-11-08 22:53:06 +0000147 }
drha76ac882022-04-08 19:20:12 +0000148 if( (pItem->fg.jointype & (JT_LEFT|JT_RIGHT))==(JT_LEFT|JT_RIGHT) ){
149 sqlite3_str_appendf(&x, " FULL-OUTER-JOIN");
150 }else if( pItem->fg.jointype & JT_LEFT ){
drh145d0a32018-11-08 22:53:06 +0000151 sqlite3_str_appendf(&x, " LEFT-JOIN");
drha76ac882022-04-08 19:20:12 +0000152 }else if( pItem->fg.jointype & JT_RIGHT ){
153 sqlite3_str_appendf(&x, " RIGHT-JOIN");
drh9b9f2352021-06-23 11:39:00 +0000154 }else if( pItem->fg.jointype & JT_CROSS ){
155 sqlite3_str_appendf(&x, " CROSS-JOIN");
drh145d0a32018-11-08 22:53:06 +0000156 }
drh8a28ce72022-04-11 00:54:30 +0000157 if( pItem->fg.jointype & JT_LTORJ ){
158 sqlite3_str_appendf(&x, " LTORJ");
159 }
drhb7e51992020-01-08 14:39:57 +0000160 if( pItem->fg.fromDDL ){
161 sqlite3_str_appendf(&x, " DDL");
162 }
drha79e2a22021-02-21 23:44:14 +0000163 if( pItem->fg.isCte ){
164 sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse);
165 }
drh145d0a32018-11-08 22:53:06 +0000166 sqlite3StrAccumFinish(&x);
167 sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
168 if( pItem->pSelect ){
drh825a6bf2022-04-21 14:08:29 +0000169 assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
drh145d0a32018-11-08 22:53:06 +0000170 sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
171 }
172 if( pItem->fg.isTabFunc ){
173 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
174 }
drh2a7dcbf2022-04-06 15:41:53 +0000175 sqlite3TreeViewPop(&pView);
drh145d0a32018-11-08 22:53:06 +0000176 }
177}
drh38b41492015-06-08 15:08:15 +0000178
179/*
drh2e5c5052016-08-27 20:21:51 +0000180** Generate a human-readable description of a Select object.
drh38b41492015-06-08 15:08:15 +0000181*/
182void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
183 int n = 0;
drh1c4505d2015-08-26 11:34:31 +0000184 int cnt = 0;
drh510b7ff2017-03-13 17:37:13 +0000185 if( p==0 ){
186 sqlite3TreeViewLine(pView, "nil-SELECT");
187 return;
188 }
drh2a7dcbf2022-04-06 15:41:53 +0000189 sqlite3TreeViewPush(&pView, moreToFollow);
drh2476a6f2015-11-07 15:19:59 +0000190 if( p->pWith ){
191 sqlite3TreeViewWith(pView, p->pWith, 1);
192 cnt = 1;
drh2a7dcbf2022-04-06 15:41:53 +0000193 sqlite3TreeViewPush(&pView, 1);
drh2476a6f2015-11-07 15:19:59 +0000194 }
drh1c4505d2015-08-26 11:34:31 +0000195 do{
drh55b4c822019-08-03 16:17:46 +0000196 if( p->selFlags & SF_WhereBegin ){
197 sqlite3TreeViewLine(pView, "sqlite3WhereBegin()");
198 }else{
199 sqlite3TreeViewLine(pView,
200 "SELECT%s%s (%u/%p) selFlags=0x%x nSelectRow=%d",
201 ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
202 ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""),
203 p->selId, p, p->selFlags,
204 (int)p->nSelectRow
205 );
206 }
drh2a7dcbf2022-04-06 15:41:53 +0000207 if( cnt++ ) sqlite3TreeViewPop(&pView);
drh1c4505d2015-08-26 11:34:31 +0000208 if( p->pPrior ){
209 n = 1000;
210 }else{
211 n = 0;
212 if( p->pSrc && p->pSrc->nSrc ) n++;
213 if( p->pWhere ) n++;
214 if( p->pGroupBy ) n++;
215 if( p->pHaving ) n++;
216 if( p->pOrderBy ) n++;
217 if( p->pLimit ) n++;
drha1fd4b52018-07-10 06:32:53 +0000218#ifndef SQLITE_OMIT_WINDOWFUNC
219 if( p->pWin ) n++;
220 if( p->pWinDefn ) n++;
221#endif
drh1c4505d2015-08-26 11:34:31 +0000222 }
drh55b4c822019-08-03 16:17:46 +0000223 if( p->pEList ){
224 sqlite3TreeViewExprList(pView, p->pEList, n>0, "result-set");
225 }
226 n--;
drha1fd4b52018-07-10 06:32:53 +0000227#ifndef SQLITE_OMIT_WINDOWFUNC
228 if( p->pWin ){
229 Window *pX;
drh2a7dcbf2022-04-06 15:41:53 +0000230 sqlite3TreeViewPush(&pView, (n--)>0);
drha1fd4b52018-07-10 06:32:53 +0000231 sqlite3TreeViewLine(pView, "window-functions");
232 for(pX=p->pWin; pX; pX=pX->pNextWin){
233 sqlite3TreeViewWinFunc(pView, pX, pX->pNextWin!=0);
234 }
drh2a7dcbf2022-04-06 15:41:53 +0000235 sqlite3TreeViewPop(&pView);
drha1fd4b52018-07-10 06:32:53 +0000236 }
237#endif
drh1c4505d2015-08-26 11:34:31 +0000238 if( p->pSrc && p->pSrc->nSrc ){
drh2a7dcbf2022-04-06 15:41:53 +0000239 sqlite3TreeViewPush(&pView, (n--)>0);
drh1c4505d2015-08-26 11:34:31 +0000240 sqlite3TreeViewLine(pView, "FROM");
drh145d0a32018-11-08 22:53:06 +0000241 sqlite3TreeViewSrcList(pView, p->pSrc);
drh2a7dcbf2022-04-06 15:41:53 +0000242 sqlite3TreeViewPop(&pView);
drh38b41492015-06-08 15:08:15 +0000243 }
drh1c4505d2015-08-26 11:34:31 +0000244 if( p->pWhere ){
245 sqlite3TreeViewItem(pView, "WHERE", (n--)>0);
246 sqlite3TreeViewExpr(pView, p->pWhere, 0);
drh2a7dcbf2022-04-06 15:41:53 +0000247 sqlite3TreeViewPop(&pView);
drh38b41492015-06-08 15:08:15 +0000248 }
drh1c4505d2015-08-26 11:34:31 +0000249 if( p->pGroupBy ){
250 sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY");
251 }
252 if( p->pHaving ){
253 sqlite3TreeViewItem(pView, "HAVING", (n--)>0);
254 sqlite3TreeViewExpr(pView, p->pHaving, 0);
drh2a7dcbf2022-04-06 15:41:53 +0000255 sqlite3TreeViewPop(&pView);
drh1c4505d2015-08-26 11:34:31 +0000256 }
drha1fd4b52018-07-10 06:32:53 +0000257#ifndef SQLITE_OMIT_WINDOWFUNC
258 if( p->pWinDefn ){
259 Window *pX;
260 sqlite3TreeViewItem(pView, "WINDOW", (n--)>0);
261 for(pX=p->pWinDefn; pX; pX=pX->pNextWin){
262 sqlite3TreeViewWindow(pView, pX, pX->pNextWin!=0);
263 }
drh2a7dcbf2022-04-06 15:41:53 +0000264 sqlite3TreeViewPop(&pView);
drha1fd4b52018-07-10 06:32:53 +0000265 }
266#endif
drh1c4505d2015-08-26 11:34:31 +0000267 if( p->pOrderBy ){
268 sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY");
269 }
270 if( p->pLimit ){
271 sqlite3TreeViewItem(pView, "LIMIT", (n--)>0);
drh8c0833f2017-11-14 23:48:23 +0000272 sqlite3TreeViewExpr(pView, p->pLimit->pLeft, p->pLimit->pRight!=0);
273 if( p->pLimit->pRight ){
274 sqlite3TreeViewItem(pView, "OFFSET", (n--)>0);
275 sqlite3TreeViewExpr(pView, p->pLimit->pRight, 0);
drh2a7dcbf2022-04-06 15:41:53 +0000276 sqlite3TreeViewPop(&pView);
drh8c0833f2017-11-14 23:48:23 +0000277 }
drh2a7dcbf2022-04-06 15:41:53 +0000278 sqlite3TreeViewPop(&pView);
drh1c4505d2015-08-26 11:34:31 +0000279 }
280 if( p->pPrior ){
281 const char *zOp = "UNION";
282 switch( p->op ){
283 case TK_ALL: zOp = "UNION ALL"; break;
284 case TK_INTERSECT: zOp = "INTERSECT"; break;
285 case TK_EXCEPT: zOp = "EXCEPT"; break;
286 }
287 sqlite3TreeViewItem(pView, zOp, 1);
288 }
289 p = p->pPrior;
290 }while( p!=0 );
drh2a7dcbf2022-04-06 15:41:53 +0000291 sqlite3TreeViewPop(&pView);
drh38b41492015-06-08 15:08:15 +0000292}
293
drha1fd4b52018-07-10 06:32:53 +0000294#ifndef SQLITE_OMIT_WINDOWFUNC
295/*
296** Generate a description of starting or stopping bounds
297*/
298void sqlite3TreeViewBound(
299 TreeView *pView, /* View context */
300 u8 eBound, /* UNBOUNDED, CURRENT, PRECEDING, FOLLOWING */
301 Expr *pExpr, /* Value for PRECEDING or FOLLOWING */
302 u8 moreToFollow /* True if more to follow */
303){
304 switch( eBound ){
305 case TK_UNBOUNDED: {
306 sqlite3TreeViewItem(pView, "UNBOUNDED", moreToFollow);
drh2a7dcbf2022-04-06 15:41:53 +0000307 sqlite3TreeViewPop(&pView);
drha1fd4b52018-07-10 06:32:53 +0000308 break;
309 }
310 case TK_CURRENT: {
311 sqlite3TreeViewItem(pView, "CURRENT", moreToFollow);
drh2a7dcbf2022-04-06 15:41:53 +0000312 sqlite3TreeViewPop(&pView);
drha1fd4b52018-07-10 06:32:53 +0000313 break;
314 }
315 case TK_PRECEDING: {
316 sqlite3TreeViewItem(pView, "PRECEDING", moreToFollow);
317 sqlite3TreeViewExpr(pView, pExpr, 0);
drh2a7dcbf2022-04-06 15:41:53 +0000318 sqlite3TreeViewPop(&pView);
drha1fd4b52018-07-10 06:32:53 +0000319 break;
320 }
321 case TK_FOLLOWING: {
322 sqlite3TreeViewItem(pView, "FOLLOWING", moreToFollow);
323 sqlite3TreeViewExpr(pView, pExpr, 0);
drh2a7dcbf2022-04-06 15:41:53 +0000324 sqlite3TreeViewPop(&pView);
drha1fd4b52018-07-10 06:32:53 +0000325 break;
326 }
327 }
328}
329#endif /* SQLITE_OMIT_WINDOWFUNC */
330
331#ifndef SQLITE_OMIT_WINDOWFUNC
332/*
333** Generate a human-readable explanation for a Window object
334*/
335void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){
drhfc15f4c2019-03-28 13:03:41 +0000336 int nElement = 0;
drh0dc0e9c2019-03-28 13:35:28 +0000337 if( pWin->pFilter ){
338 sqlite3TreeViewItem(pView, "FILTER", 1);
339 sqlite3TreeViewExpr(pView, pWin->pFilter, 0);
drh2a7dcbf2022-04-06 15:41:53 +0000340 sqlite3TreeViewPop(&pView);
drh0dc0e9c2019-03-28 13:35:28 +0000341 }
drh2a7dcbf2022-04-06 15:41:53 +0000342 sqlite3TreeViewPush(&pView, more);
drha1fd4b52018-07-10 06:32:53 +0000343 if( pWin->zName ){
drh6f1644c2019-03-28 13:53:12 +0000344 sqlite3TreeViewLine(pView, "OVER %s (%p)", pWin->zName, pWin);
drha1fd4b52018-07-10 06:32:53 +0000345 }else{
drh6f1644c2019-03-28 13:53:12 +0000346 sqlite3TreeViewLine(pView, "OVER (%p)", pWin);
drha1fd4b52018-07-10 06:32:53 +0000347 }
drhfc15f4c2019-03-28 13:03:41 +0000348 if( pWin->zBase ) nElement++;
349 if( pWin->pOrderBy ) nElement++;
350 if( pWin->eFrmType ) nElement++;
351 if( pWin->eExclude ) nElement++;
drhfc15f4c2019-03-28 13:03:41 +0000352 if( pWin->zBase ){
drh2a7dcbf2022-04-06 15:41:53 +0000353 sqlite3TreeViewPush(&pView, (--nElement)>0);
drhfc15f4c2019-03-28 13:03:41 +0000354 sqlite3TreeViewLine(pView, "window: %s", pWin->zBase);
drh2a7dcbf2022-04-06 15:41:53 +0000355 sqlite3TreeViewPop(&pView);
drhfc15f4c2019-03-28 13:03:41 +0000356 }
drha1fd4b52018-07-10 06:32:53 +0000357 if( pWin->pPartition ){
drhfc15f4c2019-03-28 13:03:41 +0000358 sqlite3TreeViewExprList(pView, pWin->pPartition, nElement>0,"PARTITION-BY");
drha1fd4b52018-07-10 06:32:53 +0000359 }
360 if( pWin->pOrderBy ){
drhfc15f4c2019-03-28 13:03:41 +0000361 sqlite3TreeViewExprList(pView, pWin->pOrderBy, (--nElement)>0, "ORDER-BY");
drha1fd4b52018-07-10 06:32:53 +0000362 }
drhfc15f4c2019-03-28 13:03:41 +0000363 if( pWin->eFrmType ){
drh0dc0e9c2019-03-28 13:35:28 +0000364 char zBuf[30];
drhfc15f4c2019-03-28 13:03:41 +0000365 const char *zFrmType = "ROWS";
366 if( pWin->eFrmType==TK_RANGE ) zFrmType = "RANGE";
367 if( pWin->eFrmType==TK_GROUPS ) zFrmType = "GROUPS";
drh0dc0e9c2019-03-28 13:35:28 +0000368 sqlite3_snprintf(sizeof(zBuf),zBuf,"%s%s",zFrmType,
369 pWin->bImplicitFrame ? " (implied)" : "");
370 sqlite3TreeViewItem(pView, zBuf, (--nElement)>0);
drha1fd4b52018-07-10 06:32:53 +0000371 sqlite3TreeViewBound(pView, pWin->eStart, pWin->pStart, 1);
372 sqlite3TreeViewBound(pView, pWin->eEnd, pWin->pEnd, 0);
drh2a7dcbf2022-04-06 15:41:53 +0000373 sqlite3TreeViewPop(&pView);
drha1fd4b52018-07-10 06:32:53 +0000374 }
drhfc15f4c2019-03-28 13:03:41 +0000375 if( pWin->eExclude ){
376 char zBuf[30];
377 const char *zExclude;
378 switch( pWin->eExclude ){
379 case TK_NO: zExclude = "NO OTHERS"; break;
380 case TK_CURRENT: zExclude = "CURRENT ROW"; break;
381 case TK_GROUP: zExclude = "GROUP"; break;
382 case TK_TIES: zExclude = "TIES"; break;
383 default:
384 sqlite3_snprintf(sizeof(zBuf),zBuf,"invalid(%d)", pWin->eExclude);
385 zExclude = zBuf;
386 break;
387 }
drh2a7dcbf2022-04-06 15:41:53 +0000388 sqlite3TreeViewPush(&pView, 0);
drhfc15f4c2019-03-28 13:03:41 +0000389 sqlite3TreeViewLine(pView, "EXCLUDE %s", zExclude);
drh2a7dcbf2022-04-06 15:41:53 +0000390 sqlite3TreeViewPop(&pView);
drhfc15f4c2019-03-28 13:03:41 +0000391 }
drh2a7dcbf2022-04-06 15:41:53 +0000392 sqlite3TreeViewPop(&pView);
drha1fd4b52018-07-10 06:32:53 +0000393}
394#endif /* SQLITE_OMIT_WINDOWFUNC */
395
396#ifndef SQLITE_OMIT_WINDOWFUNC
397/*
398** Generate a human-readable explanation for a Window Function object
399*/
400void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){
drh2a7dcbf2022-04-06 15:41:53 +0000401 sqlite3TreeViewPush(&pView, more);
drha1fd4b52018-07-10 06:32:53 +0000402 sqlite3TreeViewLine(pView, "WINFUNC %s(%d)",
drh105dcaa2022-03-10 16:01:14 +0000403 pWin->pWFunc->zName, pWin->pWFunc->nArg);
drha1fd4b52018-07-10 06:32:53 +0000404 sqlite3TreeViewWindow(pView, pWin, 0);
drh2a7dcbf2022-04-06 15:41:53 +0000405 sqlite3TreeViewPop(&pView);
drha1fd4b52018-07-10 06:32:53 +0000406}
407#endif /* SQLITE_OMIT_WINDOWFUNC */
408
drh38b41492015-06-08 15:08:15 +0000409/*
410** Generate a human-readable explanation of an expression tree.
411*/
412void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
413 const char *zBinOp = 0; /* Binary operator */
414 const char *zUniOp = 0; /* Unary operator */
drhe7375bf2020-03-10 19:24:38 +0000415 char zFlgs[200];
drh2a7dcbf2022-04-06 15:41:53 +0000416 sqlite3TreeViewPush(&pView, moreToFollow);
drh38b41492015-06-08 15:08:15 +0000417 if( pExpr==0 ){
418 sqlite3TreeViewLine(pView, "nil");
drh2a7dcbf2022-04-06 15:41:53 +0000419 sqlite3TreeViewPop(&pView);
drh38b41492015-06-08 15:08:15 +0000420 return;
421 }
drhe7375bf2020-03-10 19:24:38 +0000422 if( pExpr->flags || pExpr->affExpr || pExpr->vvaFlags ){
drhb7e51992020-01-08 14:39:57 +0000423 StrAccum x;
424 sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0);
425 sqlite3_str_appendf(&x, " fg.af=%x.%c",
426 pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n');
drhd97cda42017-04-14 14:02:14 +0000427 if( ExprHasProperty(pExpr, EP_FromJoin) ){
drhd1985262022-04-11 11:25:28 +0000428 sqlite3_str_appendf(&x, " iJoin=%d", pExpr->w.iJoin);
drhd97cda42017-04-14 14:02:14 +0000429 }
drhb7e51992020-01-08 14:39:57 +0000430 if( ExprHasProperty(pExpr, EP_FromDDL) ){
431 sqlite3_str_appendf(&x, " DDL");
432 }
drhe7375bf2020-03-10 19:24:38 +0000433 if( ExprHasVVAProperty(pExpr, EP_Immutable) ){
434 sqlite3_str_appendf(&x, " IMMUTABLE");
435 }
drhb7e51992020-01-08 14:39:57 +0000436 sqlite3StrAccumFinish(&x);
drhb3d903e2015-06-18 14:09:13 +0000437 }else{
438 zFlgs[0] = 0;
439 }
drh38b41492015-06-08 15:08:15 +0000440 switch( pExpr->op ){
441 case TK_AGG_COLUMN: {
drhb3d903e2015-06-18 14:09:13 +0000442 sqlite3TreeViewLine(pView, "AGG{%d:%d}%s",
443 pExpr->iTable, pExpr->iColumn, zFlgs);
drh38b41492015-06-08 15:08:15 +0000444 break;
445 }
446 case TK_COLUMN: {
447 if( pExpr->iTable<0 ){
448 /* This only happens when coding check constraints */
drhd4933532019-10-31 12:30:38 +0000449 char zOp2[16];
450 if( pExpr->op2 ){
451 sqlite3_snprintf(sizeof(zOp2),zOp2," op2=0x%02x",pExpr->op2);
452 }else{
453 zOp2[0] = 0;
454 }
455 sqlite3TreeViewLine(pView, "COLUMN(%d)%s%s",
456 pExpr->iColumn, zFlgs, zOp2);
drh38b41492015-06-08 15:08:15 +0000457 }else{
drh477572b2021-10-07 20:46:29 +0000458 assert( ExprUseYTab(pExpr) );
drha513e592019-12-20 20:08:56 +0000459 sqlite3TreeViewLine(pView, "{%d:%d} pTab=%p%s",
460 pExpr->iTable, pExpr->iColumn,
461 pExpr->y.pTab, zFlgs);
drh38b41492015-06-08 15:08:15 +0000462 }
drhefad2e22018-07-27 16:57:11 +0000463 if( ExprHasProperty(pExpr, EP_FixedCol) ){
464 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
465 }
drh38b41492015-06-08 15:08:15 +0000466 break;
467 }
468 case TK_INTEGER: {
469 if( pExpr->flags & EP_IntValue ){
470 sqlite3TreeViewLine(pView, "%d", pExpr->u.iValue);
471 }else{
472 sqlite3TreeViewLine(pView, "%s", pExpr->u.zToken);
473 }
474 break;
475 }
476#ifndef SQLITE_OMIT_FLOATING_POINT
477 case TK_FLOAT: {
drhf9751072021-10-07 13:40:29 +0000478 assert( !ExprHasProperty(pExpr, EP_IntValue) );
drh38b41492015-06-08 15:08:15 +0000479 sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
480 break;
481 }
482#endif
483 case TK_STRING: {
drhf9751072021-10-07 13:40:29 +0000484 assert( !ExprHasProperty(pExpr, EP_IntValue) );
drh38b41492015-06-08 15:08:15 +0000485 sqlite3TreeViewLine(pView,"%Q", pExpr->u.zToken);
486 break;
487 }
488 case TK_NULL: {
489 sqlite3TreeViewLine(pView,"NULL");
490 break;
491 }
drh34328212018-02-26 19:03:25 +0000492 case TK_TRUEFALSE: {
drh348e0022021-07-22 16:07:01 +0000493 sqlite3TreeViewLine(pView,"%s%s",
494 sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE", zFlgs);
drh34328212018-02-26 19:03:25 +0000495 break;
496 }
drh38b41492015-06-08 15:08:15 +0000497#ifndef SQLITE_OMIT_BLOB_LITERAL
498 case TK_BLOB: {
drhf9751072021-10-07 13:40:29 +0000499 assert( !ExprHasProperty(pExpr, EP_IntValue) );
drh38b41492015-06-08 15:08:15 +0000500 sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
501 break;
502 }
503#endif
504 case TK_VARIABLE: {
drhf9751072021-10-07 13:40:29 +0000505 assert( !ExprHasProperty(pExpr, EP_IntValue) );
drh38b41492015-06-08 15:08:15 +0000506 sqlite3TreeViewLine(pView,"VARIABLE(%s,%d)",
507 pExpr->u.zToken, pExpr->iColumn);
508 break;
509 }
510 case TK_REGISTER: {
511 sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable);
512 break;
513 }
drh38b41492015-06-08 15:08:15 +0000514 case TK_ID: {
drhf9751072021-10-07 13:40:29 +0000515 assert( !ExprHasProperty(pExpr, EP_IntValue) );
drh38b41492015-06-08 15:08:15 +0000516 sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken);
517 break;
518 }
519#ifndef SQLITE_OMIT_CAST
520 case TK_CAST: {
521 /* Expressions of the form: CAST(pLeft AS token) */
drhf9751072021-10-07 13:40:29 +0000522 assert( !ExprHasProperty(pExpr, EP_IntValue) );
drh38b41492015-06-08 15:08:15 +0000523 sqlite3TreeViewLine(pView,"CAST %Q", pExpr->u.zToken);
524 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
525 break;
526 }
527#endif /* SQLITE_OMIT_CAST */
528 case TK_LT: zBinOp = "LT"; break;
529 case TK_LE: zBinOp = "LE"; break;
530 case TK_GT: zBinOp = "GT"; break;
531 case TK_GE: zBinOp = "GE"; break;
532 case TK_NE: zBinOp = "NE"; break;
533 case TK_EQ: zBinOp = "EQ"; break;
534 case TK_IS: zBinOp = "IS"; break;
535 case TK_ISNOT: zBinOp = "ISNOT"; break;
536 case TK_AND: zBinOp = "AND"; break;
537 case TK_OR: zBinOp = "OR"; break;
538 case TK_PLUS: zBinOp = "ADD"; break;
539 case TK_STAR: zBinOp = "MUL"; break;
540 case TK_MINUS: zBinOp = "SUB"; break;
541 case TK_REM: zBinOp = "REM"; break;
542 case TK_BITAND: zBinOp = "BITAND"; break;
543 case TK_BITOR: zBinOp = "BITOR"; break;
544 case TK_SLASH: zBinOp = "DIV"; break;
545 case TK_LSHIFT: zBinOp = "LSHIFT"; break;
546 case TK_RSHIFT: zBinOp = "RSHIFT"; break;
547 case TK_CONCAT: zBinOp = "CONCAT"; break;
548 case TK_DOT: zBinOp = "DOT"; break;
drhe7375bf2020-03-10 19:24:38 +0000549 case TK_LIMIT: zBinOp = "LIMIT"; break;
drh38b41492015-06-08 15:08:15 +0000550
551 case TK_UMINUS: zUniOp = "UMINUS"; break;
552 case TK_UPLUS: zUniOp = "UPLUS"; break;
553 case TK_BITNOT: zUniOp = "BITNOT"; break;
554 case TK_NOT: zUniOp = "NOT"; break;
555 case TK_ISNULL: zUniOp = "ISNULL"; break;
556 case TK_NOTNULL: zUniOp = "NOTNULL"; break;
557
drh34328212018-02-26 19:03:25 +0000558 case TK_TRUTH: {
drh43c4ac82018-02-26 21:26:27 +0000559 int x;
560 const char *azOp[] = {
561 "IS-FALSE", "IS-TRUE", "IS-NOT-FALSE", "IS-NOT-TRUE"
562 };
drh34328212018-02-26 19:03:25 +0000563 assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT );
564 assert( pExpr->pRight );
dan6ece3532019-06-12 13:49:32 +0000565 assert( sqlite3ExprSkipCollate(pExpr->pRight)->op==TK_TRUEFALSE );
drh96acafb2018-02-27 14:49:25 +0000566 x = (pExpr->op2==TK_ISNOT)*2 + sqlite3ExprTruthValue(pExpr->pRight);
drh43c4ac82018-02-26 21:26:27 +0000567 zUniOp = azOp[x];
drh34328212018-02-26 19:03:25 +0000568 break;
569 }
570
drh94fa9c42016-02-27 21:16:04 +0000571 case TK_SPAN: {
drhf9751072021-10-07 13:40:29 +0000572 assert( !ExprHasProperty(pExpr, EP_IntValue) );
drh94fa9c42016-02-27 21:16:04 +0000573 sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken);
574 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
575 break;
576 }
577
drh38b41492015-06-08 15:08:15 +0000578 case TK_COLLATE: {
drhc204d812019-09-10 17:51:27 +0000579 /* COLLATE operators without the EP_Collate flag are intended to
drh018dbb12019-09-28 16:14:55 +0000580 ** emulate collation associated with a table column. These show
581 ** up in the treeview output as "SOFT-COLLATE". Explicit COLLATE
582 ** operators that appear in the original SQL always have the
583 ** EP_Collate bit set and appear in treeview output as just "COLLATE" */
drhf9751072021-10-07 13:40:29 +0000584 assert( !ExprHasProperty(pExpr, EP_IntValue) );
drhc204d812019-09-10 17:51:27 +0000585 sqlite3TreeViewLine(pView, "%sCOLLATE %Q%s",
586 !ExprHasProperty(pExpr, EP_Collate) ? "SOFT-" : "",
587 pExpr->u.zToken, zFlgs);
drh38b41492015-06-08 15:08:15 +0000588 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
589 break;
590 }
591
592 case TK_AGG_FUNCTION:
593 case TK_FUNCTION: {
594 ExprList *pFarg; /* List of function arguments */
drha1fd4b52018-07-10 06:32:53 +0000595 Window *pWin;
drh38b41492015-06-08 15:08:15 +0000596 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
597 pFarg = 0;
drha1fd4b52018-07-10 06:32:53 +0000598 pWin = 0;
drh38b41492015-06-08 15:08:15 +0000599 }else{
drha4eeccd2021-10-07 17:43:30 +0000600 assert( ExprUseXList(pExpr) );
drh38b41492015-06-08 15:08:15 +0000601 pFarg = pExpr->x.pList;
drha1fd4b52018-07-10 06:32:53 +0000602#ifndef SQLITE_OMIT_WINDOWFUNC
drh014fff22020-01-08 22:22:36 +0000603 pWin = ExprHasProperty(pExpr, EP_WinFunc) ? pExpr->y.pWin : 0;
drha1fd4b52018-07-10 06:32:53 +0000604#else
605 pWin = 0;
606#endif
drh38b41492015-06-08 15:08:15 +0000607 }
drhf9751072021-10-07 13:40:29 +0000608 assert( !ExprHasProperty(pExpr, EP_IntValue) );
drh38b41492015-06-08 15:08:15 +0000609 if( pExpr->op==TK_AGG_FUNCTION ){
drhe26d4282020-06-09 11:59:15 +0000610 sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s agg=%d[%d]/%p",
drhca74fbf2020-05-24 02:05:04 +0000611 pExpr->op2, pExpr->u.zToken, zFlgs,
drhe26d4282020-06-09 11:59:15 +0000612 pExpr->pAggInfo ? pExpr->pAggInfo->selId : 0,
drhca74fbf2020-05-24 02:05:04 +0000613 pExpr->iAgg, pExpr->pAggInfo);
drhd4933532019-10-31 12:30:38 +0000614 }else if( pExpr->op2!=0 ){
615 const char *zOp2;
616 char zBuf[8];
617 sqlite3_snprintf(sizeof(zBuf),zBuf,"0x%02x",pExpr->op2);
618 zOp2 = zBuf;
619 if( pExpr->op2==NC_IsCheck ) zOp2 = "NC_IsCheck";
620 if( pExpr->op2==NC_IdxExpr ) zOp2 = "NC_IdxExpr";
621 if( pExpr->op2==NC_PartIdx ) zOp2 = "NC_PartIdx";
622 if( pExpr->op2==NC_GenCol ) zOp2 = "NC_GenCol";
623 sqlite3TreeViewLine(pView, "FUNCTION %Q%s op2=%s",
624 pExpr->u.zToken, zFlgs, zOp2);
drh38b41492015-06-08 15:08:15 +0000625 }else{
drh42d2fce2019-08-15 20:04:09 +0000626 sqlite3TreeViewLine(pView, "FUNCTION %Q%s", pExpr->u.zToken, zFlgs);
drh38b41492015-06-08 15:08:15 +0000627 }
628 if( pFarg ){
drha1fd4b52018-07-10 06:32:53 +0000629 sqlite3TreeViewExprList(pView, pFarg, pWin!=0, 0);
drh38b41492015-06-08 15:08:15 +0000630 }
mistachkin14897852018-07-23 18:53:49 +0000631#ifndef SQLITE_OMIT_WINDOWFUNC
drha1fd4b52018-07-10 06:32:53 +0000632 if( pWin ){
633 sqlite3TreeViewWindow(pView, pWin, 0);
634 }
635#endif
drh38b41492015-06-08 15:08:15 +0000636 break;
637 }
638#ifndef SQLITE_OMIT_SUBQUERY
639 case TK_EXISTS: {
drha4eeccd2021-10-07 17:43:30 +0000640 assert( ExprUseXSelect(pExpr) );
drh9f6e14c2017-07-10 13:24:58 +0000641 sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags);
drh38b41492015-06-08 15:08:15 +0000642 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
643 break;
644 }
645 case TK_SELECT: {
drha4eeccd2021-10-07 17:43:30 +0000646 assert( ExprUseXSelect(pExpr) );
drha0365c42020-06-05 04:01:50 +0000647 sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags);
drh38b41492015-06-08 15:08:15 +0000648 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
649 break;
650 }
651 case TK_IN: {
drh9f6e14c2017-07-10 13:24:58 +0000652 sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags);
drh38b41492015-06-08 15:08:15 +0000653 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
drha4eeccd2021-10-07 17:43:30 +0000654 if( ExprUseXSelect(pExpr) ){
drh38b41492015-06-08 15:08:15 +0000655 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
656 }else{
657 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
658 }
659 break;
660 }
661#endif /* SQLITE_OMIT_SUBQUERY */
662
663 /*
664 ** x BETWEEN y AND z
665 **
666 ** This is equivalent to
667 **
668 ** x>=y AND x<=z
669 **
670 ** X is stored in pExpr->pLeft.
671 ** Y is stored in pExpr->pList->a[0].pExpr.
672 ** Z is stored in pExpr->pList->a[1].pExpr.
673 */
674 case TK_BETWEEN: {
drha4eeccd2021-10-07 17:43:30 +0000675 const Expr *pX, *pY, *pZ;
676 pX = pExpr->pLeft;
677 assert( ExprUseXList(pExpr) );
678 assert( pExpr->x.pList->nExpr==2 );
679 pY = pExpr->x.pList->a[0].pExpr;
680 pZ = pExpr->x.pList->a[1].pExpr;
drh38b41492015-06-08 15:08:15 +0000681 sqlite3TreeViewLine(pView, "BETWEEN");
682 sqlite3TreeViewExpr(pView, pX, 1);
683 sqlite3TreeViewExpr(pView, pY, 1);
684 sqlite3TreeViewExpr(pView, pZ, 0);
685 break;
686 }
687 case TK_TRIGGER: {
688 /* If the opcode is TK_TRIGGER, then the expression is a reference
689 ** to a column in the new.* or old.* pseudo-tables available to
690 ** trigger programs. In this case Expr.iTable is set to 1 for the
691 ** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn
692 ** is set to the column of the pseudo-table to read, or to -1 to
693 ** read the rowid field.
694 */
695 sqlite3TreeViewLine(pView, "%s(%d)",
696 pExpr->iTable ? "NEW" : "OLD", pExpr->iColumn);
697 break;
698 }
699 case TK_CASE: {
700 sqlite3TreeViewLine(pView, "CASE");
701 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
drha4eeccd2021-10-07 17:43:30 +0000702 assert( ExprUseXList(pExpr) );
drh38b41492015-06-08 15:08:15 +0000703 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
704 break;
705 }
706#ifndef SQLITE_OMIT_TRIGGER
707 case TK_RAISE: {
708 const char *zType = "unk";
drh11949042019-08-05 18:01:42 +0000709 switch( pExpr->affExpr ){
drh38b41492015-06-08 15:08:15 +0000710 case OE_Rollback: zType = "rollback"; break;
711 case OE_Abort: zType = "abort"; break;
712 case OE_Fail: zType = "fail"; break;
713 case OE_Ignore: zType = "ignore"; break;
714 }
drhf9751072021-10-07 13:40:29 +0000715 assert( !ExprHasProperty(pExpr, EP_IntValue) );
drh38b41492015-06-08 15:08:15 +0000716 sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken);
717 break;
718 }
719#endif
drhc84a4022016-05-27 12:30:20 +0000720 case TK_MATCH: {
721 sqlite3TreeViewLine(pView, "MATCH {%d:%d}%s",
722 pExpr->iTable, pExpr->iColumn, zFlgs);
723 sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
724 break;
725 }
drhdb97e562016-08-18 17:55:57 +0000726 case TK_VECTOR: {
drh269d3222019-10-23 18:09:39 +0000727 char *z = sqlite3_mprintf("VECTOR%s",zFlgs);
drha4eeccd2021-10-07 17:43:30 +0000728 assert( ExprUseXList(pExpr) );
drh269d3222019-10-23 18:09:39 +0000729 sqlite3TreeViewBareExprList(pView, pExpr->x.pList, z);
730 sqlite3_free(z);
drhdb97e562016-08-18 17:55:57 +0000731 break;
732 }
drh48cb3a72016-08-18 18:09:10 +0000733 case TK_SELECT_COLUMN: {
drhe46292a2021-07-05 02:40:29 +0000734 sqlite3TreeViewLine(pView, "SELECT-COLUMN %d of [0..%d]%s",
735 pExpr->iColumn, pExpr->iTable-1,
736 pExpr->pRight==pExpr->pLeft ? " (SELECT-owner)" : "");
drha4eeccd2021-10-07 17:43:30 +0000737 assert( ExprUseXSelect(pExpr->pLeft) );
drh48cb3a72016-08-18 18:09:10 +0000738 sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
739 break;
740 }
drh31d6fd52017-04-14 19:03:10 +0000741 case TK_IF_NULL_ROW: {
742 sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable);
743 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
744 break;
745 }
drhbf7f3a02021-05-24 11:35:16 +0000746 case TK_ERROR: {
747 Expr tmp;
748 sqlite3TreeViewLine(pView, "ERROR");
749 tmp = *pExpr;
750 tmp.op = pExpr->op2;
751 sqlite3TreeViewExpr(pView, &tmp, 0);
752 break;
753 }
drh4a4e02b2021-07-04 22:33:08 +0000754 case TK_ROW: {
755 if( pExpr->iColumn<=0 ){
756 sqlite3TreeViewLine(pView, "First FROM table rowid");
757 }else{
758 sqlite3TreeViewLine(pView, "First FROM table column %d",
759 pExpr->iColumn-1);
760 }
761 break;
762 }
drh38b41492015-06-08 15:08:15 +0000763 default: {
764 sqlite3TreeViewLine(pView, "op=%d", pExpr->op);
765 break;
766 }
767 }
768 if( zBinOp ){
drhb3d903e2015-06-18 14:09:13 +0000769 sqlite3TreeViewLine(pView, "%s%s", zBinOp, zFlgs);
drh38b41492015-06-08 15:08:15 +0000770 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
771 sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
772 }else if( zUniOp ){
drhb3d903e2015-06-18 14:09:13 +0000773 sqlite3TreeViewLine(pView, "%s%s", zUniOp, zFlgs);
drh11949042019-08-05 18:01:42 +0000774 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
drh38b41492015-06-08 15:08:15 +0000775 }
drh2a7dcbf2022-04-06 15:41:53 +0000776 sqlite3TreeViewPop(&pView);
drh38b41492015-06-08 15:08:15 +0000777}
778
drhdb97e562016-08-18 17:55:57 +0000779
drh38b41492015-06-08 15:08:15 +0000780/*
781** Generate a human-readable explanation of an expression list.
782*/
drhdb97e562016-08-18 17:55:57 +0000783void sqlite3TreeViewBareExprList(
drh38b41492015-06-08 15:08:15 +0000784 TreeView *pView,
785 const ExprList *pList,
drh38b41492015-06-08 15:08:15 +0000786 const char *zLabel
787){
drh38b41492015-06-08 15:08:15 +0000788 if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST";
789 if( pList==0 ){
790 sqlite3TreeViewLine(pView, "%s (empty)", zLabel);
791 }else{
drhdb97e562016-08-18 17:55:57 +0000792 int i;
drh38b41492015-06-08 15:08:15 +0000793 sqlite3TreeViewLine(pView, "%s", zLabel);
794 for(i=0; i<pList->nExpr; i++){
drh5579d592015-08-26 14:01:41 +0000795 int j = pList->a[i].u.x.iOrderByCol;
drh41cee662019-12-12 20:22:34 +0000796 char *zName = pList->a[i].zEName;
drhfbe07532018-04-23 20:04:38 +0000797 int moreToFollow = i<pList->nExpr - 1;
drh5a699a02017-12-22 19:53:02 +0000798 if( j || zName ){
drh2a7dcbf2022-04-06 15:41:53 +0000799 sqlite3TreeViewPush(&pView, moreToFollow);
drhfbe07532018-04-23 20:04:38 +0000800 moreToFollow = 0;
801 sqlite3TreeViewLine(pView, 0);
802 if( zName ){
drhd4e9caf2022-04-20 12:14:20 +0000803 switch( pList->a[i].eEName ){
804 default:
805 fprintf(stdout, "AS %s ", zName);
806 break;
807 case ENAME_TAB:
808 fprintf(stdout, "TABLE-ALIAS-NAME(\"%s\") ", zName);
drh815b7822022-04-20 15:07:39 +0000809 if( pList->a[i].bUsed==0 ) fprintf(stdout, "(unused) ");
drhd4e9caf2022-04-20 12:14:20 +0000810 break;
811 case ENAME_SPAN:
812 fprintf(stdout, "SPAN(\"%s\") ", zName);
813 break;
814 }
drhfbe07532018-04-23 20:04:38 +0000815 }
816 if( j ){
817 fprintf(stdout, "iOrderByCol=%d", j);
818 }
819 fprintf(stdout, "\n");
820 fflush(stdout);
drh5a699a02017-12-22 19:53:02 +0000821 }
drhfbe07532018-04-23 20:04:38 +0000822 sqlite3TreeViewExpr(pView, pList->a[i].pExpr, moreToFollow);
drh5a699a02017-12-22 19:53:02 +0000823 if( j || zName ){
drh2a7dcbf2022-04-06 15:41:53 +0000824 sqlite3TreeViewPop(&pView);
drh5a699a02017-12-22 19:53:02 +0000825 }
drh38b41492015-06-08 15:08:15 +0000826 }
827 }
drhdb97e562016-08-18 17:55:57 +0000828}
829void sqlite3TreeViewExprList(
830 TreeView *pView,
831 const ExprList *pList,
832 u8 moreToFollow,
833 const char *zLabel
834){
drh2a7dcbf2022-04-06 15:41:53 +0000835 sqlite3TreeViewPush(&pView, moreToFollow);
drhdb97e562016-08-18 17:55:57 +0000836 sqlite3TreeViewBareExprList(pView, pList, zLabel);
drh2a7dcbf2022-04-06 15:41:53 +0000837 sqlite3TreeViewPop(&pView);
drh38b41492015-06-08 15:08:15 +0000838}
839
drh7d2c1d22022-04-06 00:29:21 +0000840/*
841** Generate a human-readable explanation of an id-list.
842*/
843void sqlite3TreeViewBareIdList(
844 TreeView *pView,
845 const IdList *pList,
846 const char *zLabel
847){
848 if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST";
849 if( pList==0 ){
850 sqlite3TreeViewLine(pView, "%s (empty)", zLabel);
851 }else{
852 int i;
853 sqlite3TreeViewLine(pView, "%s", zLabel);
854 for(i=0; i<pList->nId; i++){
855 char *zName = pList->a[i].zName;
856 int moreToFollow = i<pList->nId - 1;
857 if( zName==0 ) zName = "(null)";
drh2a7dcbf2022-04-06 15:41:53 +0000858 sqlite3TreeViewPush(&pView, moreToFollow);
drh7d2c1d22022-04-06 00:29:21 +0000859 sqlite3TreeViewLine(pView, 0);
drha99e3252022-04-15 15:47:14 +0000860 if( pList->eU4==EU4_NONE ){
861 fprintf(stdout, "%s\n", zName);
862 }else if( pList->eU4==EU4_IDX ){
863 fprintf(stdout, "%s (%d)\n", zName, pList->a[i].u4.idx);
864 }else{
865 assert( pList->eU4==EU4_EXPR );
866 if( pList->a[i].u4.pExpr==0 ){
867 fprintf(stdout, "%s (pExpr=NULL)\n", zName);
868 }else{
869 fprintf(stdout, "%s\n", zName);
870 sqlite3TreeViewPush(&pView, i<pList->nId-1);
871 sqlite3TreeViewExpr(pView, pList->a[i].u4.pExpr, 0);
872 sqlite3TreeViewPop(&pView);
873 }
874 }
drh2a7dcbf2022-04-06 15:41:53 +0000875 sqlite3TreeViewPop(&pView);
drh7d2c1d22022-04-06 00:29:21 +0000876 }
877 }
878}
879void sqlite3TreeViewIdList(
880 TreeView *pView,
881 const IdList *pList,
882 u8 moreToFollow,
883 const char *zLabel
884){
drh2a7dcbf2022-04-06 15:41:53 +0000885 sqlite3TreeViewPush(&pView, moreToFollow);
drh7d2c1d22022-04-06 00:29:21 +0000886 sqlite3TreeViewBareIdList(pView, pList, zLabel);
drh2a7dcbf2022-04-06 15:41:53 +0000887 sqlite3TreeViewPop(&pView);
drh7d2c1d22022-04-06 00:29:21 +0000888}
889
890/*
891** Generate a human-readable explanation of a list of Upsert objects
892*/
893void sqlite3TreeViewUpsert(
894 TreeView *pView,
895 const Upsert *pUpsert,
896 u8 moreToFollow
897){
898 if( pUpsert==0 ) return;
drh2a7dcbf2022-04-06 15:41:53 +0000899 sqlite3TreeViewPush(&pView, moreToFollow);
drh7d2c1d22022-04-06 00:29:21 +0000900 while( pUpsert ){
901 int n;
drh2a7dcbf2022-04-06 15:41:53 +0000902 sqlite3TreeViewPush(&pView, pUpsert->pNextUpsert!=0 || moreToFollow);
drh7d2c1d22022-04-06 00:29:21 +0000903 sqlite3TreeViewLine(pView, "ON CONFLICT DO %s",
904 pUpsert->isDoUpdate ? "UPDATE" : "NOTHING");
905 n = (pUpsert->pUpsertSet!=0) + (pUpsert->pUpsertWhere!=0);
906 sqlite3TreeViewExprList(pView, pUpsert->pUpsertTarget, (n--)>0, "TARGET");
907 sqlite3TreeViewExprList(pView, pUpsert->pUpsertSet, (n--)>0, "SET");
908 if( pUpsert->pUpsertWhere ){
909 sqlite3TreeViewItem(pView, "WHERE", (n--)>0);
910 sqlite3TreeViewExpr(pView, pUpsert->pUpsertWhere, 0);
drh2a7dcbf2022-04-06 15:41:53 +0000911 sqlite3TreeViewPop(&pView);
drh7d2c1d22022-04-06 00:29:21 +0000912 }
drh2a7dcbf2022-04-06 15:41:53 +0000913 sqlite3TreeViewPop(&pView);
drh7d2c1d22022-04-06 00:29:21 +0000914 pUpsert = pUpsert->pNextUpsert;
915 }
drh2a7dcbf2022-04-06 15:41:53 +0000916 sqlite3TreeViewPop(&pView);
drh7d2c1d22022-04-06 00:29:21 +0000917}
918
919/*
920** Generate a human-readable diagram of the data structure that go
drhf8ef2db2022-04-06 10:37:44 +0000921** into generating an DELETE statement.
922*/
923void sqlite3TreeViewDelete(
drhf8ef2db2022-04-06 10:37:44 +0000924 const With *pWith,
925 const SrcList *pTabList,
926 const Expr *pWhere,
927 const ExprList *pOrderBy,
drh2a7dcbf2022-04-06 15:41:53 +0000928 const Expr *pLimit,
929 const Trigger *pTrigger
drhf8ef2db2022-04-06 10:37:44 +0000930){
931 int n = 0;
drh2a7dcbf2022-04-06 15:41:53 +0000932 TreeView *pView = 0;
933 sqlite3TreeViewPush(&pView, 0);
drhf8ef2db2022-04-06 10:37:44 +0000934 sqlite3TreeViewLine(pView, "DELETE");
drhf8ef2db2022-04-06 10:37:44 +0000935 if( pWith ) n++;
936 if( pTabList ) n++;
937 if( pWhere ) n++;
938 if( pOrderBy ) n++;
939 if( pLimit ) n++;
drh2a7dcbf2022-04-06 15:41:53 +0000940 if( pTrigger ) n++;
drhf8ef2db2022-04-06 10:37:44 +0000941 if( pWith ){
drh2a7dcbf2022-04-06 15:41:53 +0000942 sqlite3TreeViewPush(&pView, (--n)>0);
drhf8ef2db2022-04-06 10:37:44 +0000943 sqlite3TreeViewWith(pView, pWith, 0);
drh2a7dcbf2022-04-06 15:41:53 +0000944 sqlite3TreeViewPop(&pView);
drhf8ef2db2022-04-06 10:37:44 +0000945 }
946 if( pTabList ){
drh2a7dcbf2022-04-06 15:41:53 +0000947 sqlite3TreeViewPush(&pView, (--n)>0);
drhf8ef2db2022-04-06 10:37:44 +0000948 sqlite3TreeViewLine(pView, "FROM");
949 sqlite3TreeViewSrcList(pView, pTabList);
drh2a7dcbf2022-04-06 15:41:53 +0000950 sqlite3TreeViewPop(&pView);
drhf8ef2db2022-04-06 10:37:44 +0000951 }
952 if( pWhere ){
drh2a7dcbf2022-04-06 15:41:53 +0000953 sqlite3TreeViewPush(&pView, (--n)>0);
drhf8ef2db2022-04-06 10:37:44 +0000954 sqlite3TreeViewLine(pView, "WHERE");
955 sqlite3TreeViewExpr(pView, pWhere, 0);
drh2a7dcbf2022-04-06 15:41:53 +0000956 sqlite3TreeViewPop(&pView);
drhf8ef2db2022-04-06 10:37:44 +0000957 }
958 if( pOrderBy ){
959 sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY");
960 }
961 if( pLimit ){
drh2a7dcbf2022-04-06 15:41:53 +0000962 sqlite3TreeViewPush(&pView, (--n)>0);
drhf8ef2db2022-04-06 10:37:44 +0000963 sqlite3TreeViewLine(pView, "LIMIT");
964 sqlite3TreeViewExpr(pView, pLimit, 0);
drh2a7dcbf2022-04-06 15:41:53 +0000965 sqlite3TreeViewPop(&pView);
drhf8ef2db2022-04-06 10:37:44 +0000966 }
drh2a7dcbf2022-04-06 15:41:53 +0000967 if( pTrigger ){
968 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
969 }
970 sqlite3TreeViewPop(&pView);
drhf8ef2db2022-04-06 10:37:44 +0000971}
972
973/*
974** Generate a human-readable diagram of the data structure that go
drh7d2c1d22022-04-06 00:29:21 +0000975** into generating an INSERT statement.
976*/
977void sqlite3TreeViewInsert(
drh7d2c1d22022-04-06 00:29:21 +0000978 const With *pWith,
979 const SrcList *pTabList,
980 const IdList *pColumnList,
981 const Select *pSelect,
drhc2d0df92022-04-06 18:30:17 +0000982 const ExprList *pExprList,
drh7d2c1d22022-04-06 00:29:21 +0000983 int onError,
drh2a7dcbf2022-04-06 15:41:53 +0000984 const Upsert *pUpsert,
985 const Trigger *pTrigger
drh7d2c1d22022-04-06 00:29:21 +0000986){
drh2a7dcbf2022-04-06 15:41:53 +0000987 TreeView *pView = 0;
drh7d2c1d22022-04-06 00:29:21 +0000988 int n = 0;
989 const char *zLabel = "INSERT";
990 switch( onError ){
991 case OE_Replace: zLabel = "REPLACE"; break;
992 case OE_Ignore: zLabel = "INSERT OR IGNORE"; break;
993 case OE_Rollback: zLabel = "INSERT OR ROLLBACK"; break;
994 case OE_Abort: zLabel = "INSERT OR ABORT"; break;
995 case OE_Fail: zLabel = "INSERT OR FAIL"; break;
996 }
drh2a7dcbf2022-04-06 15:41:53 +0000997 sqlite3TreeViewPush(&pView, 0);
drh7d2c1d22022-04-06 00:29:21 +0000998 sqlite3TreeViewLine(pView, zLabel);
drh7d2c1d22022-04-06 00:29:21 +0000999 if( pWith ) n++;
1000 if( pTabList ) n++;
1001 if( pColumnList ) n++;
1002 if( pSelect ) n++;
drhc2d0df92022-04-06 18:30:17 +00001003 if( pExprList ) n++;
drh7d2c1d22022-04-06 00:29:21 +00001004 if( pUpsert ) n++;
drh2a7dcbf2022-04-06 15:41:53 +00001005 if( pTrigger ) n++;
drh7d2c1d22022-04-06 00:29:21 +00001006 if( pWith ){
drh2a7dcbf2022-04-06 15:41:53 +00001007 sqlite3TreeViewPush(&pView, (--n)>0);
drh7d2c1d22022-04-06 00:29:21 +00001008 sqlite3TreeViewWith(pView, pWith, 0);
drh2a7dcbf2022-04-06 15:41:53 +00001009 sqlite3TreeViewPop(&pView);
drh7d2c1d22022-04-06 00:29:21 +00001010 }
1011 if( pTabList ){
drh2a7dcbf2022-04-06 15:41:53 +00001012 sqlite3TreeViewPush(&pView, (--n)>0);
drh7d2c1d22022-04-06 00:29:21 +00001013 sqlite3TreeViewLine(pView, "INTO");
1014 sqlite3TreeViewSrcList(pView, pTabList);
drh2a7dcbf2022-04-06 15:41:53 +00001015 sqlite3TreeViewPop(&pView);
drh7d2c1d22022-04-06 00:29:21 +00001016 }
1017 if( pColumnList ){
1018 sqlite3TreeViewIdList(pView, pColumnList, (--n)>0, "COLUMNS");
1019 }
1020 if( pSelect ){
drh2a7dcbf2022-04-06 15:41:53 +00001021 sqlite3TreeViewPush(&pView, (--n)>0);
drh7d2c1d22022-04-06 00:29:21 +00001022 sqlite3TreeViewLine(pView, "DATA-SOURCE");
1023 sqlite3TreeViewSelect(pView, pSelect, 0);
drh2a7dcbf2022-04-06 15:41:53 +00001024 sqlite3TreeViewPop(&pView);
drh7d2c1d22022-04-06 00:29:21 +00001025 }
drhc2d0df92022-04-06 18:30:17 +00001026 if( pExprList ){
1027 sqlite3TreeViewExprList(pView, pExprList, (--n)>0, "VALUES");
1028 }
drh7d2c1d22022-04-06 00:29:21 +00001029 if( pUpsert ){
drh2a7dcbf2022-04-06 15:41:53 +00001030 sqlite3TreeViewPush(&pView, (--n)>0);
drh7d2c1d22022-04-06 00:29:21 +00001031 sqlite3TreeViewLine(pView, "UPSERT");
1032 sqlite3TreeViewUpsert(pView, pUpsert, 0);
drh2a7dcbf2022-04-06 15:41:53 +00001033 sqlite3TreeViewPop(&pView);
drh7d2c1d22022-04-06 00:29:21 +00001034 }
drh2a7dcbf2022-04-06 15:41:53 +00001035 if( pTrigger ){
1036 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
1037 }
1038 sqlite3TreeViewPop(&pView);
drh7d2c1d22022-04-06 00:29:21 +00001039}
1040
drhf8ef2db2022-04-06 10:37:44 +00001041/*
1042** Generate a human-readable diagram of the data structure that go
1043** into generating an UPDATE statement.
1044*/
1045void sqlite3TreeViewUpdate(
drhf8ef2db2022-04-06 10:37:44 +00001046 const With *pWith,
1047 const SrcList *pTabList,
1048 const ExprList *pChanges,
1049 const Expr *pWhere,
1050 int onError,
1051 const ExprList *pOrderBy,
1052 const Expr *pLimit,
drh2a7dcbf2022-04-06 15:41:53 +00001053 const Upsert *pUpsert,
1054 const Trigger *pTrigger
drhf8ef2db2022-04-06 10:37:44 +00001055){
1056 int n = 0;
drh2a7dcbf2022-04-06 15:41:53 +00001057 TreeView *pView = 0;
drhf8ef2db2022-04-06 10:37:44 +00001058 const char *zLabel = "UPDATE";
1059 switch( onError ){
1060 case OE_Replace: zLabel = "UPDATE OR REPLACE"; break;
1061 case OE_Ignore: zLabel = "UPDATE OR IGNORE"; break;
1062 case OE_Rollback: zLabel = "UPDATE OR ROLLBACK"; break;
1063 case OE_Abort: zLabel = "UPDATE OR ABORT"; break;
1064 case OE_Fail: zLabel = "UPDATE OR FAIL"; break;
1065 }
drh2a7dcbf2022-04-06 15:41:53 +00001066 sqlite3TreeViewPush(&pView, 0);
drhf8ef2db2022-04-06 10:37:44 +00001067 sqlite3TreeViewLine(pView, zLabel);
drhf8ef2db2022-04-06 10:37:44 +00001068 if( pWith ) n++;
1069 if( pTabList ) n++;
1070 if( pChanges ) n++;
1071 if( pWhere ) n++;
1072 if( pOrderBy ) n++;
1073 if( pLimit ) n++;
1074 if( pUpsert ) n++;
drh2a7dcbf2022-04-06 15:41:53 +00001075 if( pTrigger ) n++;
drhf8ef2db2022-04-06 10:37:44 +00001076 if( pWith ){
drh2a7dcbf2022-04-06 15:41:53 +00001077 sqlite3TreeViewPush(&pView, (--n)>0);
drhf8ef2db2022-04-06 10:37:44 +00001078 sqlite3TreeViewWith(pView, pWith, 0);
drh2a7dcbf2022-04-06 15:41:53 +00001079 sqlite3TreeViewPop(&pView);
drhf8ef2db2022-04-06 10:37:44 +00001080 }
1081 if( pTabList ){
drh2a7dcbf2022-04-06 15:41:53 +00001082 sqlite3TreeViewPush(&pView, (--n)>0);
drhf8ef2db2022-04-06 10:37:44 +00001083 sqlite3TreeViewLine(pView, "FROM");
1084 sqlite3TreeViewSrcList(pView, pTabList);
drh2a7dcbf2022-04-06 15:41:53 +00001085 sqlite3TreeViewPop(&pView);
drhf8ef2db2022-04-06 10:37:44 +00001086 }
1087 if( pChanges ){
1088 sqlite3TreeViewExprList(pView, pChanges, (--n)>0, "SET");
1089 }
1090 if( pWhere ){
drh2a7dcbf2022-04-06 15:41:53 +00001091 sqlite3TreeViewPush(&pView, (--n)>0);
drhf8ef2db2022-04-06 10:37:44 +00001092 sqlite3TreeViewLine(pView, "WHERE");
1093 sqlite3TreeViewExpr(pView, pWhere, 0);
drh2a7dcbf2022-04-06 15:41:53 +00001094 sqlite3TreeViewPop(&pView);
drhf8ef2db2022-04-06 10:37:44 +00001095 }
1096 if( pOrderBy ){
1097 sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY");
1098 }
1099 if( pLimit ){
drh2a7dcbf2022-04-06 15:41:53 +00001100 sqlite3TreeViewPush(&pView, (--n)>0);
drhf8ef2db2022-04-06 10:37:44 +00001101 sqlite3TreeViewLine(pView, "LIMIT");
1102 sqlite3TreeViewExpr(pView, pLimit, 0);
drh2a7dcbf2022-04-06 15:41:53 +00001103 sqlite3TreeViewPop(&pView);
drhf8ef2db2022-04-06 10:37:44 +00001104 }
1105 if( pUpsert ){
drh2a7dcbf2022-04-06 15:41:53 +00001106 sqlite3TreeViewPush(&pView, (--n)>0);
drhf8ef2db2022-04-06 10:37:44 +00001107 sqlite3TreeViewLine(pView, "UPSERT");
1108 sqlite3TreeViewUpsert(pView, pUpsert, 0);
drh2a7dcbf2022-04-06 15:41:53 +00001109 sqlite3TreeViewPop(&pView);
drhf8ef2db2022-04-06 10:37:44 +00001110 }
drh2a7dcbf2022-04-06 15:41:53 +00001111 if( pTrigger ){
1112 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
1113 }
1114 sqlite3TreeViewPop(&pView);
drhf8ef2db2022-04-06 10:37:44 +00001115}
1116
drh2a7dcbf2022-04-06 15:41:53 +00001117#ifndef SQLITE_OMIT_TRIGGER
1118/*
1119** Show a human-readable graph of a TriggerStep
1120*/
1121void sqlite3TreeViewTriggerStep(
1122 TreeView *pView,
1123 const TriggerStep *pStep,
1124 u8 moreToFollow,
1125 u8 showFullList
1126){
1127 int cnt = 0;
1128 if( pStep==0 ) return;
1129 sqlite3TreeViewPush(&pView,
1130 moreToFollow || (showFullList && pStep->pNext!=0));
1131 do{
1132 if( cnt++ && pStep->pNext==0 ){
1133 sqlite3TreeViewPop(&pView);
1134 sqlite3TreeViewPush(&pView, 0);
1135 }
1136 sqlite3TreeViewLine(pView, "%s", pStep->zSpan ? pStep->zSpan : "RETURNING");
1137 }while( showFullList && (pStep = pStep->pNext)!=0 );
1138 sqlite3TreeViewPop(&pView);
1139}
1140
1141/*
1142** Show a human-readable graph of a Trigger
1143*/
1144void sqlite3TreeViewTrigger(
1145 TreeView *pView,
1146 const Trigger *pTrigger,
1147 u8 moreToFollow,
1148 u8 showFullList
1149){
1150 int cnt = 0;
1151 if( pTrigger==0 ) return;
1152 sqlite3TreeViewPush(&pView,
1153 moreToFollow || (showFullList && pTrigger->pNext!=0));
1154 do{
1155 if( cnt++ && pTrigger->pNext==0 ){
1156 sqlite3TreeViewPop(&pView);
1157 sqlite3TreeViewPush(&pView, 0);
1158 }
1159 sqlite3TreeViewLine(pView, "TRIGGER %s", pTrigger->zName);
1160 sqlite3TreeViewPush(&pView, 0);
1161 sqlite3TreeViewTriggerStep(pView, pTrigger->step_list, 0, 1);
1162 sqlite3TreeViewPop(&pView);
1163 }while( showFullList && (pTrigger = pTrigger->pNext)!=0 );
1164 sqlite3TreeViewPop(&pView);
1165}
1166#endif /* SQLITE_OMIT_TRIGGER */
1167
1168
drh8f1eb6f2022-04-06 12:25:04 +00001169/*
1170** These simplified versions of the tree-view routines omit unnecessary
1171** parameters. These variants are intended to be used from a symbolic
1172** debugger, such as "gdb", during interactive debugging sessions.
1173**
1174** This routines are given external linkage so that they will always be
1175** accessible to the debugging, and to avoid warnings about unused
1176** functions. But these routines only exist in debugging builds, so they
1177** do not contaminate the interface.
1178*/
1179void sqlite3ShowExpr(const Expr *p){ sqlite3TreeViewExpr(0,p,0); }
1180void sqlite3ShowExprList(const ExprList *p){ sqlite3TreeViewExprList(0,p,0,0);}
1181void sqlite3ShowIdList(const IdList *p){ sqlite3TreeViewIdList(0,p,0,0); }
1182void sqlite3ShowSrcList(const SrcList *p){ sqlite3TreeViewSrcList(0,p); }
1183void sqlite3ShowSelect(const Select *p){ sqlite3TreeViewSelect(0,p,0); }
1184void sqlite3ShowWith(const With *p){ sqlite3TreeViewWith(0,p,0); }
1185void sqlite3ShowUpsert(const Upsert *p){ sqlite3TreeViewUpsert(0,p,0); }
drh2a7dcbf2022-04-06 15:41:53 +00001186#ifndef SQLITE_OMIT_TRIGGER
1187void sqlite3ShowTriggerStep(const TriggerStep *p){
1188 sqlite3TreeViewTriggerStep(0,p,0,0);
1189}
1190void sqlite3ShowTriggerStepList(const TriggerStep *p){
1191 sqlite3TreeViewTriggerStep(0,p,0,1);
1192}
1193void sqlite3ShowTrigger(const Trigger *p){ sqlite3TreeViewTrigger(0,p,0,0); }
1194void sqlite3ShowTriggerList(const Trigger *p){ sqlite3TreeViewTrigger(0,p,0,1);}
1195#endif
drh8f1eb6f2022-04-06 12:25:04 +00001196#ifndef SQLITE_OMIT_WINDOWFUNC
1197void sqlite3ShowWindow(const Window *p){ sqlite3TreeViewWindow(0,p,0); }
1198void sqlite3ShowWinFunc(const Window *p){ sqlite3TreeViewWinFunc(0,p,0); }
1199#endif
1200
drh38b41492015-06-08 15:08:15 +00001201#endif /* SQLITE_DEBUG */