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