aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2023-11-03 11:35:33 +0000
committerdrh <>2023-11-03 11:35:33 +0000
commit24f7f5923d9f630339a17afba82060f946d3bbae (patch)
tree6418865e330d1b51b69dae96f35057c6910b6a1f /src
parent215886458556aec979dd7228ab0095bf901a2d38 (diff)
parentd706adba48766b93197e5dea7ba64c0ce7776e3d (diff)
downloadsqlite-24f7f5923d9f630339a17afba82060f946d3bbae.tar.gz
sqlite-24f7f5923d9f630339a17afba82060f946d3bbae.zip
Merge all the latest trunk fixes and enhancements into the jsonb branch.
FossilOrigin-Name: b089bf46374b374d02d7654c65eb3e75d1777638b398061e47644af0dab48c9b
Diffstat (limited to 'src')
-rw-r--r--src/resolve.c7
-rw-r--r--src/select.c2
-rw-r--r--src/shell.c.in5
-rw-r--r--src/sqliteInt.h1
-rw-r--r--src/vdbeapi.c10
5 files changed, 19 insertions, 6 deletions
diff --git a/src/resolve.c b/src/resolve.c
index 0072f6b6a..5f675c1d2 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -1249,11 +1249,12 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
while( pNC2
&& sqlite3ReferencesSrcList(pParse, pExpr, pNC2->pSrcList)==0
){
- pExpr->op2++;
+ pExpr->op2 += (1 + pNC2->nNestedSelect);
pNC2 = pNC2->pNext;
}
assert( pDef!=0 || IN_RENAME_OBJECT );
if( pNC2 && pDef ){
+ pExpr->op2 += pNC2->nNestedSelect;
assert( SQLITE_FUNC_MINMAX==NC_MinMaxAgg );
assert( SQLITE_FUNC_ANYORDER==NC_OrderAgg );
testcase( (pDef->funcFlags & SQLITE_FUNC_MINMAX)!=0 );
@@ -1812,6 +1813,7 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
/* Recursively resolve names in all subqueries in the FROM clause
*/
+ if( pOuterNC ) pOuterNC->nNestedSelect++;
for(i=0; i<p->pSrc->nSrc; i++){
SrcItem *pItem = &p->pSrc->a[i];
if( pItem->pSelect && (pItem->pSelect->selFlags & SF_Resolved)==0 ){
@@ -1836,6 +1838,9 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
}
}
}
+ if( pOuterNC && ALWAYS(pOuterNC->nNestedSelect>0) ){
+ pOuterNC->nNestedSelect--;
+ }
/* Set up the local name-context to pass to sqlite3ResolveExprNames() to
** resolve the result-set expression list.
diff --git a/src/select.c b/src/select.c
index 7a79385e0..e97a5afb7 100644
--- a/src/select.c
+++ b/src/select.c
@@ -8472,7 +8472,7 @@ int sqlite3Select(
updateAccumulator(pParse, regAcc, pAggInfo, eDist);
if( eDist!=WHERE_DISTINCT_NOOP ){
struct AggInfo_func *pF = pAggInfo->aFunc;
- if( pF ){
+ if( ALWAYS(pF) ){
fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr);
}
}
diff --git a/src/shell.c.in b/src/shell.c.in
index ad16d7204..3cfe1a94a 100644
--- a/src/shell.c.in
+++ b/src/shell.c.in
@@ -704,9 +704,8 @@ static void console_prepare_utf8(void){
conState.outCodePage = GetConsoleOutputCP();
if( in_console ){
SetConsoleCP(CP_UTF8);
- DWORD newConsoleMode = conState.consoleMode
- | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
- SetConsoleMode(conState.hConsole, newConsoleMode);
+ SetConsoleMode(conState.hConsole, conState.consoleMode
+ | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT);
conState.infsMode = _setmode(_fileno(stdin), _O_U16TEXT);
console_utf8_in = 1;
}
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index dbf01dd13..23beb48de 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -3397,6 +3397,7 @@ struct NameContext {
int nRef; /* Number of names resolved by this context */
int nNcErr; /* Number of errors encountered while resolving names */
int ncFlags; /* Zero or more NC_* flags defined below */
+ u32 nNestedSelect; /* Number of nested selects using this NC */
Select *pWinSelect; /* SELECT statement for any window functions */
};
diff --git a/src/vdbeapi.c b/src/vdbeapi.c
index 22952ba1a..5ebd27383 100644
--- a/src/vdbeapi.c
+++ b/src/vdbeapi.c
@@ -152,7 +152,15 @@ int sqlite3_clear_bindings(sqlite3_stmt *pStmt){
int rc = SQLITE_OK;
Vdbe *p = (Vdbe*)pStmt;
#if SQLITE_THREADSAFE
- sqlite3_mutex *mutex = ((Vdbe*)pStmt)->db->mutex;
+ sqlite3_mutex *mutex;
+#endif
+#ifdef SQLITE_ENABLE_API_ARMOR
+ if( pStmt==0 ){
+ return SQLITE_MISUSE_BKPT;
+ }
+#endif
+#if SQLITE_THREADSAFE
+ mutex = p->db->mutex;
#endif
sqlite3_mutex_enter(mutex);
for(i=0; i<p->nVar; i++){