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; |
drh | b60d1fb | 2022-04-13 18:32:04 +0000 | [diff] [blame] | 136 | if( pSrc==0 ) return; |
drh | 145d0a3 | 2018-11-08 22:53:06 +0000 | [diff] [blame] | 137 | for(i=0; i<pSrc->nSrc; i++){ |
drh | 7601294 | 2021-02-21 21:04:54 +0000 | [diff] [blame] | 138 | const SrcItem *pItem = &pSrc->a[i]; |
drh | 145d0a3 | 2018-11-08 22:53:06 +0000 | [diff] [blame] | 139 | StrAccum x; |
| 140 | char zLine[100]; |
| 141 | sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); |
drh | ff37491 | 2021-04-12 12:58:55 +0000 | [diff] [blame] | 142 | x.printfFlags |= SQLITE_PRINTF_INTERNAL; |
drh | 6610e6a | 2021-03-19 19:44:56 +0000 | [diff] [blame] | 143 | sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem); |
drh | 145d0a3 | 2018-11-08 22:53:06 +0000 | [diff] [blame] | 144 | if( pItem->pTab ){ |
drh | f7f6dbf | 2020-03-21 22:03:32 +0000 | [diff] [blame] | 145 | sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx", |
| 146 | pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, pItem->colUsed); |
drh | 145d0a3 | 2018-11-08 22:53:06 +0000 | [diff] [blame] | 147 | } |
drh | a76ac88 | 2022-04-08 19:20:12 +0000 | [diff] [blame] | 148 | 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 ){ |
drh | 145d0a3 | 2018-11-08 22:53:06 +0000 | [diff] [blame] | 151 | sqlite3_str_appendf(&x, " LEFT-JOIN"); |
drh | a76ac88 | 2022-04-08 19:20:12 +0000 | [diff] [blame] | 152 | }else if( pItem->fg.jointype & JT_RIGHT ){ |
| 153 | sqlite3_str_appendf(&x, " RIGHT-JOIN"); |
drh | 9b9f235 | 2021-06-23 11:39:00 +0000 | [diff] [blame] | 154 | }else if( pItem->fg.jointype & JT_CROSS ){ |
| 155 | sqlite3_str_appendf(&x, " CROSS-JOIN"); |
drh | 145d0a3 | 2018-11-08 22:53:06 +0000 | [diff] [blame] | 156 | } |
drh | 8a28ce7 | 2022-04-11 00:54:30 +0000 | [diff] [blame] | 157 | if( pItem->fg.jointype & JT_LTORJ ){ |
| 158 | sqlite3_str_appendf(&x, " LTORJ"); |
| 159 | } |
drh | b7e5199 | 2020-01-08 14:39:57 +0000 | [diff] [blame] | 160 | if( pItem->fg.fromDDL ){ |
| 161 | sqlite3_str_appendf(&x, " DDL"); |
| 162 | } |
drh | a79e2a2 | 2021-02-21 23:44:14 +0000 | [diff] [blame] | 163 | if( pItem->fg.isCte ){ |
| 164 | sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse); |
| 165 | } |
drh | 145d0a3 | 2018-11-08 22:53:06 +0000 | [diff] [blame] | 166 | sqlite3StrAccumFinish(&x); |
| 167 | sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1); |
| 168 | if( pItem->pSelect ){ |
drh | 825a6bf | 2022-04-21 14:08:29 +0000 | [diff] [blame^] | 169 | assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) ); |
drh | 145d0a3 | 2018-11-08 22:53:06 +0000 | [diff] [blame] | 170 | sqlite3TreeViewSelect(pView, pItem->pSelect, 0); |
| 171 | } |
| 172 | if( pItem->fg.isTabFunc ){ |
| 173 | sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:"); |
| 174 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 175 | sqlite3TreeViewPop(&pView); |
drh | 145d0a3 | 2018-11-08 22:53:06 +0000 | [diff] [blame] | 176 | } |
| 177 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 178 | |
| 179 | /* |
drh | 2e5c505 | 2016-08-27 20:21:51 +0000 | [diff] [blame] | 180 | ** Generate a human-readable description of a Select object. |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 181 | */ |
| 182 | void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){ |
| 183 | int n = 0; |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 184 | int cnt = 0; |
drh | 510b7ff | 2017-03-13 17:37:13 +0000 | [diff] [blame] | 185 | if( p==0 ){ |
| 186 | sqlite3TreeViewLine(pView, "nil-SELECT"); |
| 187 | return; |
| 188 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 189 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | 2476a6f | 2015-11-07 15:19:59 +0000 | [diff] [blame] | 190 | if( p->pWith ){ |
| 191 | sqlite3TreeViewWith(pView, p->pWith, 1); |
| 192 | cnt = 1; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 193 | sqlite3TreeViewPush(&pView, 1); |
drh | 2476a6f | 2015-11-07 15:19:59 +0000 | [diff] [blame] | 194 | } |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 195 | do{ |
drh | 55b4c82 | 2019-08-03 16:17:46 +0000 | [diff] [blame] | 196 | 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 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 207 | if( cnt++ ) sqlite3TreeViewPop(&pView); |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 208 | 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++; |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 218 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 219 | if( p->pWin ) n++; |
| 220 | if( p->pWinDefn ) n++; |
| 221 | #endif |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 222 | } |
drh | 55b4c82 | 2019-08-03 16:17:46 +0000 | [diff] [blame] | 223 | if( p->pEList ){ |
| 224 | sqlite3TreeViewExprList(pView, p->pEList, n>0, "result-set"); |
| 225 | } |
| 226 | n--; |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 227 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 228 | if( p->pWin ){ |
| 229 | Window *pX; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 230 | sqlite3TreeViewPush(&pView, (n--)>0); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 231 | sqlite3TreeViewLine(pView, "window-functions"); |
| 232 | for(pX=p->pWin; pX; pX=pX->pNextWin){ |
| 233 | sqlite3TreeViewWinFunc(pView, pX, pX->pNextWin!=0); |
| 234 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 235 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 236 | } |
| 237 | #endif |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 238 | if( p->pSrc && p->pSrc->nSrc ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 239 | sqlite3TreeViewPush(&pView, (n--)>0); |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 240 | sqlite3TreeViewLine(pView, "FROM"); |
drh | 145d0a3 | 2018-11-08 22:53:06 +0000 | [diff] [blame] | 241 | sqlite3TreeViewSrcList(pView, p->pSrc); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 242 | sqlite3TreeViewPop(&pView); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 243 | } |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 244 | if( p->pWhere ){ |
| 245 | sqlite3TreeViewItem(pView, "WHERE", (n--)>0); |
| 246 | sqlite3TreeViewExpr(pView, p->pWhere, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 247 | sqlite3TreeViewPop(&pView); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 248 | } |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 249 | 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); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 255 | sqlite3TreeViewPop(&pView); |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 256 | } |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 257 | #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 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 264 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 265 | } |
| 266 | #endif |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 267 | if( p->pOrderBy ){ |
| 268 | sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY"); |
| 269 | } |
| 270 | if( p->pLimit ){ |
| 271 | sqlite3TreeViewItem(pView, "LIMIT", (n--)>0); |
drh | 8c0833f | 2017-11-14 23:48:23 +0000 | [diff] [blame] | 272 | 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); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 276 | sqlite3TreeViewPop(&pView); |
drh | 8c0833f | 2017-11-14 23:48:23 +0000 | [diff] [blame] | 277 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 278 | sqlite3TreeViewPop(&pView); |
drh | 1c4505d | 2015-08-26 11:34:31 +0000 | [diff] [blame] | 279 | } |
| 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 ); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 291 | sqlite3TreeViewPop(&pView); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 292 | } |
| 293 | |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 294 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 295 | /* |
| 296 | ** Generate a description of starting or stopping bounds |
| 297 | */ |
| 298 | void 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); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 307 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 308 | break; |
| 309 | } |
| 310 | case TK_CURRENT: { |
| 311 | sqlite3TreeViewItem(pView, "CURRENT", moreToFollow); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 312 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 313 | break; |
| 314 | } |
| 315 | case TK_PRECEDING: { |
| 316 | sqlite3TreeViewItem(pView, "PRECEDING", moreToFollow); |
| 317 | sqlite3TreeViewExpr(pView, pExpr, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 318 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 319 | break; |
| 320 | } |
| 321 | case TK_FOLLOWING: { |
| 322 | sqlite3TreeViewItem(pView, "FOLLOWING", moreToFollow); |
| 323 | sqlite3TreeViewExpr(pView, pExpr, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 324 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 325 | 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 | */ |
| 335 | void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){ |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 336 | int nElement = 0; |
drh | 0dc0e9c | 2019-03-28 13:35:28 +0000 | [diff] [blame] | 337 | if( pWin->pFilter ){ |
| 338 | sqlite3TreeViewItem(pView, "FILTER", 1); |
| 339 | sqlite3TreeViewExpr(pView, pWin->pFilter, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 340 | sqlite3TreeViewPop(&pView); |
drh | 0dc0e9c | 2019-03-28 13:35:28 +0000 | [diff] [blame] | 341 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 342 | sqlite3TreeViewPush(&pView, more); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 343 | if( pWin->zName ){ |
drh | 6f1644c | 2019-03-28 13:53:12 +0000 | [diff] [blame] | 344 | sqlite3TreeViewLine(pView, "OVER %s (%p)", pWin->zName, pWin); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 345 | }else{ |
drh | 6f1644c | 2019-03-28 13:53:12 +0000 | [diff] [blame] | 346 | sqlite3TreeViewLine(pView, "OVER (%p)", pWin); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 347 | } |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 348 | if( pWin->zBase ) nElement++; |
| 349 | if( pWin->pOrderBy ) nElement++; |
| 350 | if( pWin->eFrmType ) nElement++; |
| 351 | if( pWin->eExclude ) nElement++; |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 352 | if( pWin->zBase ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 353 | sqlite3TreeViewPush(&pView, (--nElement)>0); |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 354 | sqlite3TreeViewLine(pView, "window: %s", pWin->zBase); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 355 | sqlite3TreeViewPop(&pView); |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 356 | } |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 357 | if( pWin->pPartition ){ |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 358 | sqlite3TreeViewExprList(pView, pWin->pPartition, nElement>0,"PARTITION-BY"); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 359 | } |
| 360 | if( pWin->pOrderBy ){ |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 361 | sqlite3TreeViewExprList(pView, pWin->pOrderBy, (--nElement)>0, "ORDER-BY"); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 362 | } |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 363 | if( pWin->eFrmType ){ |
drh | 0dc0e9c | 2019-03-28 13:35:28 +0000 | [diff] [blame] | 364 | char zBuf[30]; |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 365 | const char *zFrmType = "ROWS"; |
| 366 | if( pWin->eFrmType==TK_RANGE ) zFrmType = "RANGE"; |
| 367 | if( pWin->eFrmType==TK_GROUPS ) zFrmType = "GROUPS"; |
drh | 0dc0e9c | 2019-03-28 13:35:28 +0000 | [diff] [blame] | 368 | sqlite3_snprintf(sizeof(zBuf),zBuf,"%s%s",zFrmType, |
| 369 | pWin->bImplicitFrame ? " (implied)" : ""); |
| 370 | sqlite3TreeViewItem(pView, zBuf, (--nElement)>0); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 371 | sqlite3TreeViewBound(pView, pWin->eStart, pWin->pStart, 1); |
| 372 | sqlite3TreeViewBound(pView, pWin->eEnd, pWin->pEnd, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 373 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 374 | } |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 375 | 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 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 388 | sqlite3TreeViewPush(&pView, 0); |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 389 | sqlite3TreeViewLine(pView, "EXCLUDE %s", zExclude); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 390 | sqlite3TreeViewPop(&pView); |
drh | fc15f4c | 2019-03-28 13:03:41 +0000 | [diff] [blame] | 391 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 392 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 393 | } |
| 394 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 395 | |
| 396 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 397 | /* |
| 398 | ** Generate a human-readable explanation for a Window Function object |
| 399 | */ |
| 400 | void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 401 | sqlite3TreeViewPush(&pView, more); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 402 | sqlite3TreeViewLine(pView, "WINFUNC %s(%d)", |
drh | 105dcaa | 2022-03-10 16:01:14 +0000 | [diff] [blame] | 403 | pWin->pWFunc->zName, pWin->pWFunc->nArg); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 404 | sqlite3TreeViewWindow(pView, pWin, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 405 | sqlite3TreeViewPop(&pView); |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 406 | } |
| 407 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 408 | |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 409 | /* |
| 410 | ** Generate a human-readable explanation of an expression tree. |
| 411 | */ |
| 412 | void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){ |
| 413 | const char *zBinOp = 0; /* Binary operator */ |
| 414 | const char *zUniOp = 0; /* Unary operator */ |
drh | e7375bf | 2020-03-10 19:24:38 +0000 | [diff] [blame] | 415 | char zFlgs[200]; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 416 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 417 | if( pExpr==0 ){ |
| 418 | sqlite3TreeViewLine(pView, "nil"); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 419 | sqlite3TreeViewPop(&pView); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 420 | return; |
| 421 | } |
drh | e7375bf | 2020-03-10 19:24:38 +0000 | [diff] [blame] | 422 | if( pExpr->flags || pExpr->affExpr || pExpr->vvaFlags ){ |
drh | b7e5199 | 2020-01-08 14:39:57 +0000 | [diff] [blame] | 423 | 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'); |
drh | d97cda4 | 2017-04-14 14:02:14 +0000 | [diff] [blame] | 427 | if( ExprHasProperty(pExpr, EP_FromJoin) ){ |
drh | d198526 | 2022-04-11 11:25:28 +0000 | [diff] [blame] | 428 | sqlite3_str_appendf(&x, " iJoin=%d", pExpr->w.iJoin); |
drh | d97cda4 | 2017-04-14 14:02:14 +0000 | [diff] [blame] | 429 | } |
drh | b7e5199 | 2020-01-08 14:39:57 +0000 | [diff] [blame] | 430 | if( ExprHasProperty(pExpr, EP_FromDDL) ){ |
| 431 | sqlite3_str_appendf(&x, " DDL"); |
| 432 | } |
drh | e7375bf | 2020-03-10 19:24:38 +0000 | [diff] [blame] | 433 | if( ExprHasVVAProperty(pExpr, EP_Immutable) ){ |
| 434 | sqlite3_str_appendf(&x, " IMMUTABLE"); |
| 435 | } |
drh | b7e5199 | 2020-01-08 14:39:57 +0000 | [diff] [blame] | 436 | sqlite3StrAccumFinish(&x); |
drh | b3d903e | 2015-06-18 14:09:13 +0000 | [diff] [blame] | 437 | }else{ |
| 438 | zFlgs[0] = 0; |
| 439 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 440 | switch( pExpr->op ){ |
| 441 | case TK_AGG_COLUMN: { |
drh | b3d903e | 2015-06-18 14:09:13 +0000 | [diff] [blame] | 442 | sqlite3TreeViewLine(pView, "AGG{%d:%d}%s", |
| 443 | pExpr->iTable, pExpr->iColumn, zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 444 | break; |
| 445 | } |
| 446 | case TK_COLUMN: { |
| 447 | if( pExpr->iTable<0 ){ |
| 448 | /* This only happens when coding check constraints */ |
drh | d493353 | 2019-10-31 12:30:38 +0000 | [diff] [blame] | 449 | 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); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 457 | }else{ |
drh | 477572b | 2021-10-07 20:46:29 +0000 | [diff] [blame] | 458 | assert( ExprUseYTab(pExpr) ); |
drh | a513e59 | 2019-12-20 20:08:56 +0000 | [diff] [blame] | 459 | sqlite3TreeViewLine(pView, "{%d:%d} pTab=%p%s", |
| 460 | pExpr->iTable, pExpr->iColumn, |
| 461 | pExpr->y.pTab, zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 462 | } |
drh | efad2e2 | 2018-07-27 16:57:11 +0000 | [diff] [blame] | 463 | if( ExprHasProperty(pExpr, EP_FixedCol) ){ |
| 464 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 465 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 466 | 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: { |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 478 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 479 | sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken); |
| 480 | break; |
| 481 | } |
| 482 | #endif |
| 483 | case TK_STRING: { |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 484 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 485 | sqlite3TreeViewLine(pView,"%Q", pExpr->u.zToken); |
| 486 | break; |
| 487 | } |
| 488 | case TK_NULL: { |
| 489 | sqlite3TreeViewLine(pView,"NULL"); |
| 490 | break; |
| 491 | } |
drh | 3432821 | 2018-02-26 19:03:25 +0000 | [diff] [blame] | 492 | case TK_TRUEFALSE: { |
drh | 348e002 | 2021-07-22 16:07:01 +0000 | [diff] [blame] | 493 | sqlite3TreeViewLine(pView,"%s%s", |
| 494 | sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE", zFlgs); |
drh | 3432821 | 2018-02-26 19:03:25 +0000 | [diff] [blame] | 495 | break; |
| 496 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 497 | #ifndef SQLITE_OMIT_BLOB_LITERAL |
| 498 | case TK_BLOB: { |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 499 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 500 | sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken); |
| 501 | break; |
| 502 | } |
| 503 | #endif |
| 504 | case TK_VARIABLE: { |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 505 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 506 | 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 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 514 | case TK_ID: { |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 515 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 516 | 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) */ |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 522 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 523 | 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; |
drh | e7375bf | 2020-03-10 19:24:38 +0000 | [diff] [blame] | 549 | case TK_LIMIT: zBinOp = "LIMIT"; break; |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 550 | |
| 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 | |
drh | 3432821 | 2018-02-26 19:03:25 +0000 | [diff] [blame] | 558 | case TK_TRUTH: { |
drh | 43c4ac8 | 2018-02-26 21:26:27 +0000 | [diff] [blame] | 559 | int x; |
| 560 | const char *azOp[] = { |
| 561 | "IS-FALSE", "IS-TRUE", "IS-NOT-FALSE", "IS-NOT-TRUE" |
| 562 | }; |
drh | 3432821 | 2018-02-26 19:03:25 +0000 | [diff] [blame] | 563 | assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT ); |
| 564 | assert( pExpr->pRight ); |
dan | 6ece353 | 2019-06-12 13:49:32 +0000 | [diff] [blame] | 565 | assert( sqlite3ExprSkipCollate(pExpr->pRight)->op==TK_TRUEFALSE ); |
drh | 96acafb | 2018-02-27 14:49:25 +0000 | [diff] [blame] | 566 | x = (pExpr->op2==TK_ISNOT)*2 + sqlite3ExprTruthValue(pExpr->pRight); |
drh | 43c4ac8 | 2018-02-26 21:26:27 +0000 | [diff] [blame] | 567 | zUniOp = azOp[x]; |
drh | 3432821 | 2018-02-26 19:03:25 +0000 | [diff] [blame] | 568 | break; |
| 569 | } |
| 570 | |
drh | 94fa9c4 | 2016-02-27 21:16:04 +0000 | [diff] [blame] | 571 | case TK_SPAN: { |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 572 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 94fa9c4 | 2016-02-27 21:16:04 +0000 | [diff] [blame] | 573 | sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken); |
| 574 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 575 | break; |
| 576 | } |
| 577 | |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 578 | case TK_COLLATE: { |
drh | c204d81 | 2019-09-10 17:51:27 +0000 | [diff] [blame] | 579 | /* COLLATE operators without the EP_Collate flag are intended to |
drh | 018dbb1 | 2019-09-28 16:14:55 +0000 | [diff] [blame] | 580 | ** 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" */ |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 584 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | c204d81 | 2019-09-10 17:51:27 +0000 | [diff] [blame] | 585 | sqlite3TreeViewLine(pView, "%sCOLLATE %Q%s", |
| 586 | !ExprHasProperty(pExpr, EP_Collate) ? "SOFT-" : "", |
| 587 | pExpr->u.zToken, zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 588 | 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 */ |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 595 | Window *pWin; |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 596 | if( ExprHasProperty(pExpr, EP_TokenOnly) ){ |
| 597 | pFarg = 0; |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 598 | pWin = 0; |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 599 | }else{ |
drh | a4eeccd | 2021-10-07 17:43:30 +0000 | [diff] [blame] | 600 | assert( ExprUseXList(pExpr) ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 601 | pFarg = pExpr->x.pList; |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 602 | #ifndef SQLITE_OMIT_WINDOWFUNC |
drh | 014fff2 | 2020-01-08 22:22:36 +0000 | [diff] [blame] | 603 | pWin = ExprHasProperty(pExpr, EP_WinFunc) ? pExpr->y.pWin : 0; |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 604 | #else |
| 605 | pWin = 0; |
| 606 | #endif |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 607 | } |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 608 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 609 | if( pExpr->op==TK_AGG_FUNCTION ){ |
drh | e26d428 | 2020-06-09 11:59:15 +0000 | [diff] [blame] | 610 | sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s agg=%d[%d]/%p", |
drh | ca74fbf | 2020-05-24 02:05:04 +0000 | [diff] [blame] | 611 | pExpr->op2, pExpr->u.zToken, zFlgs, |
drh | e26d428 | 2020-06-09 11:59:15 +0000 | [diff] [blame] | 612 | pExpr->pAggInfo ? pExpr->pAggInfo->selId : 0, |
drh | ca74fbf | 2020-05-24 02:05:04 +0000 | [diff] [blame] | 613 | pExpr->iAgg, pExpr->pAggInfo); |
drh | d493353 | 2019-10-31 12:30:38 +0000 | [diff] [blame] | 614 | }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); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 625 | }else{ |
drh | 42d2fce | 2019-08-15 20:04:09 +0000 | [diff] [blame] | 626 | sqlite3TreeViewLine(pView, "FUNCTION %Q%s", pExpr->u.zToken, zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 627 | } |
| 628 | if( pFarg ){ |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 629 | sqlite3TreeViewExprList(pView, pFarg, pWin!=0, 0); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 630 | } |
mistachkin | 1489785 | 2018-07-23 18:53:49 +0000 | [diff] [blame] | 631 | #ifndef SQLITE_OMIT_WINDOWFUNC |
drh | a1fd4b5 | 2018-07-10 06:32:53 +0000 | [diff] [blame] | 632 | if( pWin ){ |
| 633 | sqlite3TreeViewWindow(pView, pWin, 0); |
| 634 | } |
| 635 | #endif |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 636 | break; |
| 637 | } |
| 638 | #ifndef SQLITE_OMIT_SUBQUERY |
| 639 | case TK_EXISTS: { |
drh | a4eeccd | 2021-10-07 17:43:30 +0000 | [diff] [blame] | 640 | assert( ExprUseXSelect(pExpr) ); |
drh | 9f6e14c | 2017-07-10 13:24:58 +0000 | [diff] [blame] | 641 | sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 642 | sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); |
| 643 | break; |
| 644 | } |
| 645 | case TK_SELECT: { |
drh | a4eeccd | 2021-10-07 17:43:30 +0000 | [diff] [blame] | 646 | assert( ExprUseXSelect(pExpr) ); |
drh | a0365c4 | 2020-06-05 04:01:50 +0000 | [diff] [blame] | 647 | sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 648 | sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); |
| 649 | break; |
| 650 | } |
| 651 | case TK_IN: { |
drh | 9f6e14c | 2017-07-10 13:24:58 +0000 | [diff] [blame] | 652 | sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 653 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); |
drh | a4eeccd | 2021-10-07 17:43:30 +0000 | [diff] [blame] | 654 | if( ExprUseXSelect(pExpr) ){ |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 655 | 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: { |
drh | a4eeccd | 2021-10-07 17:43:30 +0000 | [diff] [blame] | 675 | 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; |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 681 | 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); |
drh | a4eeccd | 2021-10-07 17:43:30 +0000 | [diff] [blame] | 702 | assert( ExprUseXList(pExpr) ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 703 | sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0); |
| 704 | break; |
| 705 | } |
| 706 | #ifndef SQLITE_OMIT_TRIGGER |
| 707 | case TK_RAISE: { |
| 708 | const char *zType = "unk"; |
drh | 1194904 | 2019-08-05 18:01:42 +0000 | [diff] [blame] | 709 | switch( pExpr->affExpr ){ |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 710 | 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 | } |
drh | f975107 | 2021-10-07 13:40:29 +0000 | [diff] [blame] | 715 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 716 | sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken); |
| 717 | break; |
| 718 | } |
| 719 | #endif |
drh | c84a402 | 2016-05-27 12:30:20 +0000 | [diff] [blame] | 720 | 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 | } |
drh | db97e56 | 2016-08-18 17:55:57 +0000 | [diff] [blame] | 726 | case TK_VECTOR: { |
drh | 269d322 | 2019-10-23 18:09:39 +0000 | [diff] [blame] | 727 | char *z = sqlite3_mprintf("VECTOR%s",zFlgs); |
drh | a4eeccd | 2021-10-07 17:43:30 +0000 | [diff] [blame] | 728 | assert( ExprUseXList(pExpr) ); |
drh | 269d322 | 2019-10-23 18:09:39 +0000 | [diff] [blame] | 729 | sqlite3TreeViewBareExprList(pView, pExpr->x.pList, z); |
| 730 | sqlite3_free(z); |
drh | db97e56 | 2016-08-18 17:55:57 +0000 | [diff] [blame] | 731 | break; |
| 732 | } |
drh | 48cb3a7 | 2016-08-18 18:09:10 +0000 | [diff] [blame] | 733 | case TK_SELECT_COLUMN: { |
drh | e46292a | 2021-07-05 02:40:29 +0000 | [diff] [blame] | 734 | sqlite3TreeViewLine(pView, "SELECT-COLUMN %d of [0..%d]%s", |
| 735 | pExpr->iColumn, pExpr->iTable-1, |
| 736 | pExpr->pRight==pExpr->pLeft ? " (SELECT-owner)" : ""); |
drh | a4eeccd | 2021-10-07 17:43:30 +0000 | [diff] [blame] | 737 | assert( ExprUseXSelect(pExpr->pLeft) ); |
drh | 48cb3a7 | 2016-08-18 18:09:10 +0000 | [diff] [blame] | 738 | sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0); |
| 739 | break; |
| 740 | } |
drh | 31d6fd5 | 2017-04-14 19:03:10 +0000 | [diff] [blame] | 741 | case TK_IF_NULL_ROW: { |
| 742 | sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable); |
| 743 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 744 | break; |
| 745 | } |
drh | bf7f3a0 | 2021-05-24 11:35:16 +0000 | [diff] [blame] | 746 | 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 | } |
drh | 4a4e02b | 2021-07-04 22:33:08 +0000 | [diff] [blame] | 754 | 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 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 763 | default: { |
| 764 | sqlite3TreeViewLine(pView, "op=%d", pExpr->op); |
| 765 | break; |
| 766 | } |
| 767 | } |
| 768 | if( zBinOp ){ |
drh | b3d903e | 2015-06-18 14:09:13 +0000 | [diff] [blame] | 769 | sqlite3TreeViewLine(pView, "%s%s", zBinOp, zFlgs); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 770 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); |
| 771 | sqlite3TreeViewExpr(pView, pExpr->pRight, 0); |
| 772 | }else if( zUniOp ){ |
drh | b3d903e | 2015-06-18 14:09:13 +0000 | [diff] [blame] | 773 | sqlite3TreeViewLine(pView, "%s%s", zUniOp, zFlgs); |
drh | 1194904 | 2019-08-05 18:01:42 +0000 | [diff] [blame] | 774 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 775 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 776 | sqlite3TreeViewPop(&pView); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 777 | } |
| 778 | |
drh | db97e56 | 2016-08-18 17:55:57 +0000 | [diff] [blame] | 779 | |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 780 | /* |
| 781 | ** Generate a human-readable explanation of an expression list. |
| 782 | */ |
drh | db97e56 | 2016-08-18 17:55:57 +0000 | [diff] [blame] | 783 | void sqlite3TreeViewBareExprList( |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 784 | TreeView *pView, |
| 785 | const ExprList *pList, |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 786 | const char *zLabel |
| 787 | ){ |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 788 | if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST"; |
| 789 | if( pList==0 ){ |
| 790 | sqlite3TreeViewLine(pView, "%s (empty)", zLabel); |
| 791 | }else{ |
drh | db97e56 | 2016-08-18 17:55:57 +0000 | [diff] [blame] | 792 | int i; |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 793 | sqlite3TreeViewLine(pView, "%s", zLabel); |
| 794 | for(i=0; i<pList->nExpr; i++){ |
drh | 5579d59 | 2015-08-26 14:01:41 +0000 | [diff] [blame] | 795 | int j = pList->a[i].u.x.iOrderByCol; |
drh | 41cee66 | 2019-12-12 20:22:34 +0000 | [diff] [blame] | 796 | char *zName = pList->a[i].zEName; |
drh | fbe0753 | 2018-04-23 20:04:38 +0000 | [diff] [blame] | 797 | int moreToFollow = i<pList->nExpr - 1; |
drh | 5a699a0 | 2017-12-22 19:53:02 +0000 | [diff] [blame] | 798 | if( j || zName ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 799 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | fbe0753 | 2018-04-23 20:04:38 +0000 | [diff] [blame] | 800 | moreToFollow = 0; |
| 801 | sqlite3TreeViewLine(pView, 0); |
| 802 | if( zName ){ |
drh | d4e9caf | 2022-04-20 12:14:20 +0000 | [diff] [blame] | 803 | 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); |
drh | 815b782 | 2022-04-20 15:07:39 +0000 | [diff] [blame] | 809 | if( pList->a[i].bUsed==0 ) fprintf(stdout, "(unused) "); |
drh | d4e9caf | 2022-04-20 12:14:20 +0000 | [diff] [blame] | 810 | break; |
| 811 | case ENAME_SPAN: |
| 812 | fprintf(stdout, "SPAN(\"%s\") ", zName); |
| 813 | break; |
| 814 | } |
drh | fbe0753 | 2018-04-23 20:04:38 +0000 | [diff] [blame] | 815 | } |
| 816 | if( j ){ |
| 817 | fprintf(stdout, "iOrderByCol=%d", j); |
| 818 | } |
| 819 | fprintf(stdout, "\n"); |
| 820 | fflush(stdout); |
drh | 5a699a0 | 2017-12-22 19:53:02 +0000 | [diff] [blame] | 821 | } |
drh | fbe0753 | 2018-04-23 20:04:38 +0000 | [diff] [blame] | 822 | sqlite3TreeViewExpr(pView, pList->a[i].pExpr, moreToFollow); |
drh | 5a699a0 | 2017-12-22 19:53:02 +0000 | [diff] [blame] | 823 | if( j || zName ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 824 | sqlite3TreeViewPop(&pView); |
drh | 5a699a0 | 2017-12-22 19:53:02 +0000 | [diff] [blame] | 825 | } |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 826 | } |
| 827 | } |
drh | db97e56 | 2016-08-18 17:55:57 +0000 | [diff] [blame] | 828 | } |
| 829 | void sqlite3TreeViewExprList( |
| 830 | TreeView *pView, |
| 831 | const ExprList *pList, |
| 832 | u8 moreToFollow, |
| 833 | const char *zLabel |
| 834 | ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 835 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | db97e56 | 2016-08-18 17:55:57 +0000 | [diff] [blame] | 836 | sqlite3TreeViewBareExprList(pView, pList, zLabel); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 837 | sqlite3TreeViewPop(&pView); |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 838 | } |
| 839 | |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 840 | /* |
| 841 | ** Generate a human-readable explanation of an id-list. |
| 842 | */ |
| 843 | void 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)"; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 858 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 859 | sqlite3TreeViewLine(pView, 0); |
drh | a99e325 | 2022-04-15 15:47:14 +0000 | [diff] [blame] | 860 | 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 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 875 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 876 | } |
| 877 | } |
| 878 | } |
| 879 | void sqlite3TreeViewIdList( |
| 880 | TreeView *pView, |
| 881 | const IdList *pList, |
| 882 | u8 moreToFollow, |
| 883 | const char *zLabel |
| 884 | ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 885 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 886 | sqlite3TreeViewBareIdList(pView, pList, zLabel); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 887 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | /* |
| 891 | ** Generate a human-readable explanation of a list of Upsert objects |
| 892 | */ |
| 893 | void sqlite3TreeViewUpsert( |
| 894 | TreeView *pView, |
| 895 | const Upsert *pUpsert, |
| 896 | u8 moreToFollow |
| 897 | ){ |
| 898 | if( pUpsert==0 ) return; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 899 | sqlite3TreeViewPush(&pView, moreToFollow); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 900 | while( pUpsert ){ |
| 901 | int n; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 902 | sqlite3TreeViewPush(&pView, pUpsert->pNextUpsert!=0 || moreToFollow); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 903 | 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); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 911 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 912 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 913 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 914 | pUpsert = pUpsert->pNextUpsert; |
| 915 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 916 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | /* |
| 920 | ** Generate a human-readable diagram of the data structure that go |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 921 | ** into generating an DELETE statement. |
| 922 | */ |
| 923 | void sqlite3TreeViewDelete( |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 924 | const With *pWith, |
| 925 | const SrcList *pTabList, |
| 926 | const Expr *pWhere, |
| 927 | const ExprList *pOrderBy, |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 928 | const Expr *pLimit, |
| 929 | const Trigger *pTrigger |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 930 | ){ |
| 931 | int n = 0; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 932 | TreeView *pView = 0; |
| 933 | sqlite3TreeViewPush(&pView, 0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 934 | sqlite3TreeViewLine(pView, "DELETE"); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 935 | if( pWith ) n++; |
| 936 | if( pTabList ) n++; |
| 937 | if( pWhere ) n++; |
| 938 | if( pOrderBy ) n++; |
| 939 | if( pLimit ) n++; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 940 | if( pTrigger ) n++; |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 941 | if( pWith ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 942 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 943 | sqlite3TreeViewWith(pView, pWith, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 944 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 945 | } |
| 946 | if( pTabList ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 947 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 948 | sqlite3TreeViewLine(pView, "FROM"); |
| 949 | sqlite3TreeViewSrcList(pView, pTabList); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 950 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 951 | } |
| 952 | if( pWhere ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 953 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 954 | sqlite3TreeViewLine(pView, "WHERE"); |
| 955 | sqlite3TreeViewExpr(pView, pWhere, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 956 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 957 | } |
| 958 | if( pOrderBy ){ |
| 959 | sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY"); |
| 960 | } |
| 961 | if( pLimit ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 962 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 963 | sqlite3TreeViewLine(pView, "LIMIT"); |
| 964 | sqlite3TreeViewExpr(pView, pLimit, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 965 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 966 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 967 | if( pTrigger ){ |
| 968 | sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); |
| 969 | } |
| 970 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | /* |
| 974 | ** Generate a human-readable diagram of the data structure that go |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 975 | ** into generating an INSERT statement. |
| 976 | */ |
| 977 | void sqlite3TreeViewInsert( |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 978 | const With *pWith, |
| 979 | const SrcList *pTabList, |
| 980 | const IdList *pColumnList, |
| 981 | const Select *pSelect, |
drh | c2d0df9 | 2022-04-06 18:30:17 +0000 | [diff] [blame] | 982 | const ExprList *pExprList, |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 983 | int onError, |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 984 | const Upsert *pUpsert, |
| 985 | const Trigger *pTrigger |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 986 | ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 987 | TreeView *pView = 0; |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 988 | 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 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 997 | sqlite3TreeViewPush(&pView, 0); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 998 | sqlite3TreeViewLine(pView, zLabel); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 999 | if( pWith ) n++; |
| 1000 | if( pTabList ) n++; |
| 1001 | if( pColumnList ) n++; |
| 1002 | if( pSelect ) n++; |
drh | c2d0df9 | 2022-04-06 18:30:17 +0000 | [diff] [blame] | 1003 | if( pExprList ) n++; |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1004 | if( pUpsert ) n++; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1005 | if( pTrigger ) n++; |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1006 | if( pWith ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1007 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1008 | sqlite3TreeViewWith(pView, pWith, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1009 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1010 | } |
| 1011 | if( pTabList ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1012 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1013 | sqlite3TreeViewLine(pView, "INTO"); |
| 1014 | sqlite3TreeViewSrcList(pView, pTabList); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1015 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1016 | } |
| 1017 | if( pColumnList ){ |
| 1018 | sqlite3TreeViewIdList(pView, pColumnList, (--n)>0, "COLUMNS"); |
| 1019 | } |
| 1020 | if( pSelect ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1021 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1022 | sqlite3TreeViewLine(pView, "DATA-SOURCE"); |
| 1023 | sqlite3TreeViewSelect(pView, pSelect, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1024 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1025 | } |
drh | c2d0df9 | 2022-04-06 18:30:17 +0000 | [diff] [blame] | 1026 | if( pExprList ){ |
| 1027 | sqlite3TreeViewExprList(pView, pExprList, (--n)>0, "VALUES"); |
| 1028 | } |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1029 | if( pUpsert ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1030 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1031 | sqlite3TreeViewLine(pView, "UPSERT"); |
| 1032 | sqlite3TreeViewUpsert(pView, pUpsert, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1033 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1034 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1035 | if( pTrigger ){ |
| 1036 | sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); |
| 1037 | } |
| 1038 | sqlite3TreeViewPop(&pView); |
drh | 7d2c1d2 | 2022-04-06 00:29:21 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1041 | /* |
| 1042 | ** Generate a human-readable diagram of the data structure that go |
| 1043 | ** into generating an UPDATE statement. |
| 1044 | */ |
| 1045 | void sqlite3TreeViewUpdate( |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1046 | 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, |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1053 | const Upsert *pUpsert, |
| 1054 | const Trigger *pTrigger |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1055 | ){ |
| 1056 | int n = 0; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1057 | TreeView *pView = 0; |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1058 | 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 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1066 | sqlite3TreeViewPush(&pView, 0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1067 | sqlite3TreeViewLine(pView, zLabel); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1068 | 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++; |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1075 | if( pTrigger ) n++; |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1076 | if( pWith ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1077 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1078 | sqlite3TreeViewWith(pView, pWith, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1079 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1080 | } |
| 1081 | if( pTabList ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1082 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1083 | sqlite3TreeViewLine(pView, "FROM"); |
| 1084 | sqlite3TreeViewSrcList(pView, pTabList); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1085 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1086 | } |
| 1087 | if( pChanges ){ |
| 1088 | sqlite3TreeViewExprList(pView, pChanges, (--n)>0, "SET"); |
| 1089 | } |
| 1090 | if( pWhere ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1091 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1092 | sqlite3TreeViewLine(pView, "WHERE"); |
| 1093 | sqlite3TreeViewExpr(pView, pWhere, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1094 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1095 | } |
| 1096 | if( pOrderBy ){ |
| 1097 | sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY"); |
| 1098 | } |
| 1099 | if( pLimit ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1100 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1101 | sqlite3TreeViewLine(pView, "LIMIT"); |
| 1102 | sqlite3TreeViewExpr(pView, pLimit, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1103 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1104 | } |
| 1105 | if( pUpsert ){ |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1106 | sqlite3TreeViewPush(&pView, (--n)>0); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1107 | sqlite3TreeViewLine(pView, "UPSERT"); |
| 1108 | sqlite3TreeViewUpsert(pView, pUpsert, 0); |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1109 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1110 | } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1111 | if( pTrigger ){ |
| 1112 | sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1); |
| 1113 | } |
| 1114 | sqlite3TreeViewPop(&pView); |
drh | f8ef2db | 2022-04-06 10:37:44 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1117 | #ifndef SQLITE_OMIT_TRIGGER |
| 1118 | /* |
| 1119 | ** Show a human-readable graph of a TriggerStep |
| 1120 | */ |
| 1121 | void 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 | */ |
| 1144 | void 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 | |
drh | 8f1eb6f | 2022-04-06 12:25:04 +0000 | [diff] [blame] | 1169 | /* |
| 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 | */ |
| 1179 | void sqlite3ShowExpr(const Expr *p){ sqlite3TreeViewExpr(0,p,0); } |
| 1180 | void sqlite3ShowExprList(const ExprList *p){ sqlite3TreeViewExprList(0,p,0,0);} |
| 1181 | void sqlite3ShowIdList(const IdList *p){ sqlite3TreeViewIdList(0,p,0,0); } |
| 1182 | void sqlite3ShowSrcList(const SrcList *p){ sqlite3TreeViewSrcList(0,p); } |
| 1183 | void sqlite3ShowSelect(const Select *p){ sqlite3TreeViewSelect(0,p,0); } |
| 1184 | void sqlite3ShowWith(const With *p){ sqlite3TreeViewWith(0,p,0); } |
| 1185 | void sqlite3ShowUpsert(const Upsert *p){ sqlite3TreeViewUpsert(0,p,0); } |
drh | 2a7dcbf | 2022-04-06 15:41:53 +0000 | [diff] [blame] | 1186 | #ifndef SQLITE_OMIT_TRIGGER |
| 1187 | void sqlite3ShowTriggerStep(const TriggerStep *p){ |
| 1188 | sqlite3TreeViewTriggerStep(0,p,0,0); |
| 1189 | } |
| 1190 | void sqlite3ShowTriggerStepList(const TriggerStep *p){ |
| 1191 | sqlite3TreeViewTriggerStep(0,p,0,1); |
| 1192 | } |
| 1193 | void sqlite3ShowTrigger(const Trigger *p){ sqlite3TreeViewTrigger(0,p,0,0); } |
| 1194 | void sqlite3ShowTriggerList(const Trigger *p){ sqlite3TreeViewTrigger(0,p,0,1);} |
| 1195 | #endif |
drh | 8f1eb6f | 2022-04-06 12:25:04 +0000 | [diff] [blame] | 1196 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 1197 | void sqlite3ShowWindow(const Window *p){ sqlite3TreeViewWindow(0,p,0); } |
| 1198 | void sqlite3ShowWinFunc(const Window *p){ sqlite3TreeViewWinFunc(0,p,0); } |
| 1199 | #endif |
| 1200 | |
drh | 38b4149 | 2015-06-08 15:08:15 +0000 | [diff] [blame] | 1201 | #endif /* SQLITE_DEBUG */ |