From 5d73872ca7a492da8f0d67a696b4414b04162426 Mon Sep 17 00:00:00 2001 From: Mark Raasveldt Date: Thu, 4 Jan 2024 18:14:56 +0100 Subject: [PATCH 1/2] Fix #10008 - disallow parameters in DEFAULT clause, and fix the way that the shell handles parameters --- src/main/prepared_statement_data.cpp | 4 ++- .../binder/statement/bind_create_table.cpp | 3 ++ tools/shell/shell.c | 32 +------------------ 3 files changed, 7 insertions(+), 32 deletions(-) diff --git a/src/main/prepared_statement_data.cpp b/src/main/prepared_statement_data.cpp index 4bc356ce822..4ff72354683 100644 --- a/src/main/prepared_statement_data.cpp +++ b/src/main/prepared_statement_data.cpp @@ -36,7 +36,9 @@ bool PreparedStatementData::RequireRebind(ClientContext &context, optional_ptrfind(identifier); - D_ASSERT(lookup != values->end()); + if (lookup == values->end()) { + break; + } if (lookup->second.type() != it.second->return_type) { return true; } diff --git a/src/planner/binder/statement/bind_create_table.cpp b/src/planner/binder/statement/bind_create_table.cpp index 56672a22e6a..6016273f1b8 100644 --- a/src/planner/binder/statement/bind_create_table.cpp +++ b/src/planner/binder/statement/bind_create_table.cpp @@ -216,6 +216,9 @@ void Binder::BindDefaultValues(const ColumnList &columns, vectorHasParameter()) { + throw BinderException("DEFAULT values cannot contain parameters"); + } ConstantBinder default_binder(*this, context, "DEFAULT value"); default_binder.target_type = column.Type(); bound_default = default_binder.Bind(default_copy); diff --git a/tools/shell/shell.c b/tools/shell/shell.c index 74e199375f5..16032d3d560 100644 --- a/tools/shell/shell.c +++ b/tools/shell/shell.c @@ -12540,37 +12540,7 @@ static void bind_table_init(ShellState *p){ ** tables. The table must be in the TEMP schema. */ static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){ - int nVar; - int i; - int rc; - sqlite3_stmt *pQ = 0; - - nVar = sqlite3_bind_parameter_count(pStmt); - if( nVar==0 ) return; /* Nothing to do */ - if( sqlite3_table_column_metadata(pArg->db, "TEMP", "sqlite_parameters", - "key", 0, 0, 0, 0, 0)!=SQLITE_OK ){ - return; /* Parameter table does not exist */ - } - rc = sqlite3_prepare_v2(pArg->db, - "SELECT value FROM temp.sqlite_parameters" - " WHERE key=?1", -1, &pQ, 0); - if( rc || pQ==0 ) return; - for(i=1; i<=nVar; i++){ - char zNum[30]; - const char *zVar = sqlite3_bind_parameter_name(pStmt, i); - if( zVar==0 ){ - sqlite3_snprintf(sizeof(zNum),zNum,"?%d",i); - zVar = zNum; - } - sqlite3_bind_text(pQ, 1, zVar, -1, SQLITE_STATIC); - if( sqlite3_step(pQ)==SQLITE_ROW ){ - sqlite3_bind_value(pStmt, i, sqlite3_column_value(pQ, 0)); - }else{ - sqlite3_bind_null(pStmt, i); - } - sqlite3_reset(pQ); - } - sqlite3_finalize(pQ); + return; } /* From 879985428fb7e0a151dfcf54678a876b0ef96279 Mon Sep 17 00:00:00 2001 From: Mark Raasveldt Date: Thu, 4 Jan 2024 18:16:08 +0100 Subject: [PATCH 2/2] Add test --- test/sql/catalog/table/create_table_parameters.test | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/sql/catalog/table/create_table_parameters.test diff --git a/test/sql/catalog/table/create_table_parameters.test b/test/sql/catalog/table/create_table_parameters.test new file mode 100644 index 00000000000..01f15a9ad03 --- /dev/null +++ b/test/sql/catalog/table/create_table_parameters.test @@ -0,0 +1,12 @@ +# name: test/sql/catalog/table/create_table_parameters.test +# description: Issue #10008 - DuckDB SIGSEGV when creating table with DEFAULT ? +# group: [table] + +statement error +CREATE TABLE t0 ( c1 INT DEFAULT ? ); +---- +DEFAULT values cannot contain parameters + +statement error +CREATE TABLE t0 ( c1 INT CHECK (?) ); +----