diff --git a/duckdb b/duckdb index a966898..d8f3435 160000 --- a/duckdb +++ b/duckdb @@ -1 +1 @@ -Subproject commit a966898d86b58ce31dc4955897f8d3f99db1bd83 +Subproject commit d8f343577c04ab84c32c19f201e1082ea6fa8ade diff --git a/extension-ci-tools b/extension-ci-tools index a4373c6..a00c74e 160000 --- a/extension-ci-tools +++ b/extension-ci-tools @@ -1 +1 @@ -Subproject commit a4373c6ec5bfcf4e0ec2f89b50248eefd0d8f2c7 +Subproject commit a00c74e02aefbfa3fd31a4c74c4b6bc260af0de7 diff --git a/src/include/storage/sqlite_index_entry.hpp b/src/include/storage/sqlite_index_entry.hpp index 5f09b0b..516b9d8 100644 --- a/src/include/storage/sqlite_index_entry.hpp +++ b/src/include/storage/sqlite_index_entry.hpp @@ -19,8 +19,8 @@ class SQLiteIndexEntry : public IndexCatalogEntry { string table_name; public: - string GetSchemaName() const override; - string GetTableName() const override; + Identifier GetSchemaName() const override; + Identifier GetTableName() const override; }; } // namespace duckdb diff --git a/src/sqlite_db.cpp b/src/sqlite_db.cpp index 27eaf27..8603c14 100644 --- a/src/sqlite_db.cpp +++ b/src/sqlite_db.cpp @@ -174,7 +174,7 @@ void SQLiteDB::GetTableInfo(const string &table_name, ColumnList &columns, vecto SQLiteStatement stmt; idx_t primary_key_index = idx_t(-1); - vector primary_keys; + vector primary_keys; bool found = false; @@ -191,9 +191,9 @@ void SQLiteDB::GetTableInfo(const string &table_name, ColumnList &columns, vecto if (pk) { primary_key_index = cid; - primary_keys.push_back(sqlite_colname); + primary_keys.emplace_back(sqlite_colname); } - ColumnDefinition column(std::move(sqlite_colname), std::move(column_type)); + ColumnDefinition column(Identifier(std::move(sqlite_colname)), std::move(column_type)); if (!default_value.empty() && default_value != "\"\"") { auto expressions = Parser::ParseExpressionList(default_value); if (expressions.empty()) { diff --git a/src/sqlite_scanner.cpp b/src/sqlite_scanner.cpp index 4268928..d060a99 100644 --- a/src/sqlite_scanner.cpp +++ b/src/sqlite_scanner.cpp @@ -68,7 +68,7 @@ static unique_ptr SqliteBind(ClientContext &context, TableFunction } db.GetTableInfo(result->table_name, columns, constraints, result->all_varchar); for (auto &column : columns.Logical()) { - names.push_back(column.GetName()); + names.emplace_back(column.GetName().GetIdentifierName()); return_types.push_back(column.GetType()); } @@ -427,7 +427,7 @@ static void AttachFunction(ClientContext &context, TableFunctionInput &data_p, D auto tables = db.GetTables(); for (auto &table_name : tables) { dconn.TableFunction("sqlite_scan", {Value(data.file_name), Value(table_name)}) - ->CreateView(table_name, data.overwrite, false); + ->CreateView(Identifier(table_name), data.overwrite, false); } } { diff --git a/src/storage/sqlite_delete.cpp b/src/storage/sqlite_delete.cpp index 09c3dba..4e239f8 100644 --- a/src/storage/sqlite_delete.cpp +++ b/src/storage/sqlite_delete.cpp @@ -68,7 +68,7 @@ SourceResultType SQLiteDelete::GetDataInternal(ExecutionContext &context, DataCh if (!insert_gstate.delete_done) { if (!insert_gstate.statement.IsOpen()) { auto &transaction = SQLiteTransaction::Get(context.client, insert_gstate.table.catalog); - insert_gstate.statement = transaction.GetDB().Prepare(GetDeleteSQL(insert_gstate.table.name)); + insert_gstate.statement = transaction.GetDB().Prepare(GetDeleteSQL(insert_gstate.table.name.GetIdentifierName())); } for (auto row_id : insert_gstate.rowids) { insert_gstate.statement.Bind(0, row_id); @@ -94,7 +94,7 @@ string SQLiteDelete::GetName() const { InsertionOrderPreservingMap SQLiteDelete::ParamsToString() const { InsertionOrderPreservingMap result; - result["Table Name"] = table.name; + result["Table Name"] = table.name.GetIdentifierName(); return result; } @@ -107,7 +107,7 @@ PhysicalOperator &SQLiteCatalog::PlanDelete(ClientContext &context, PhysicalPlan throw BinderException("RETURNING clause not yet supported for deletion of a SQLite table"); } auto &bound_ref = op.expressions[0]->Cast(); - auto &delete_op = planner.Make(op, op.table, bound_ref.index); + auto &delete_op = planner.Make(op, op.table, bound_ref.Index()); delete_op.children.push_back(plan); return delete_op; } diff --git a/src/storage/sqlite_index_entry.cpp b/src/storage/sqlite_index_entry.cpp index 8f92089..9443ae9 100644 --- a/src/storage/sqlite_index_entry.cpp +++ b/src/storage/sqlite_index_entry.cpp @@ -8,12 +8,12 @@ SQLiteIndexEntry::SQLiteIndexEntry(Catalog &catalog, SchemaCatalogEntry &schema, : IndexCatalogEntry(catalog, schema, info), table_name(std::move(table_name_p)) { } -string SQLiteIndexEntry::GetSchemaName() const { +Identifier SQLiteIndexEntry::GetSchemaName() const { return schema.name; } -string SQLiteIndexEntry::GetTableName() const { - return table_name; +Identifier SQLiteIndexEntry::GetTableName() const { + return Identifier(table_name); } } // namespace duckdb diff --git a/src/storage/sqlite_insert.cpp b/src/storage/sqlite_insert.cpp index 44502ef..b12c42f 100644 --- a/src/storage/sqlite_insert.cpp +++ b/src/storage/sqlite_insert.cpp @@ -40,7 +40,7 @@ class SQLiteInsertGlobalState : public GlobalSinkState { string GetInsertSQL(const SQLiteInsert &insert, SQLiteTableEntry *entry) { string result; - result = "INSERT INTO " + KeywordHelper::WriteOptionallyQuoted(entry->name); + result = "INSERT INTO " + KeywordHelper::WriteOptionallyQuoted(entry->name.GetIdentifierName()); auto &columns = entry->GetColumns(); idx_t column_count; if (!insert.column_index_map.empty()) { @@ -63,7 +63,7 @@ string GetInsertSQL(const SQLiteInsert &insert, SQLiteTableEntry *entry) { result += ", "; } auto &col = columns.GetColumn(column_indexes[c]); - result += KeywordHelper::WriteOptionallyQuoted(col.GetName()); + result += KeywordHelper::WriteOptionallyQuoted(col.GetName().GetIdentifierName()); } result += ")"; } else { @@ -136,7 +136,7 @@ string SQLiteInsert::GetName() const { InsertionOrderPreservingMap SQLiteInsert::ParamsToString() const { InsertionOrderPreservingMap result; - result["Table Name"] = table ? table->name : info->Base().table; + result["Table Name"] = table ? table->name.GetIdentifierName() : info->Base().table.GetIdentifierName(); return result; } diff --git a/src/storage/sqlite_query.cpp b/src/storage/sqlite_query.cpp index e776f5c..81d063d 100644 --- a/src/storage/sqlite_query.cpp +++ b/src/storage/sqlite_query.cpp @@ -24,7 +24,7 @@ static unique_ptr SQLiteQueryBind(ClientContext &context, TableFun // look up the database to query auto db_name = input.inputs[0].GetValue(); auto &db_manager = DatabaseManager::Get(context); - auto db = db_manager.GetDatabase(context, db_name); + auto db = db_manager.GetDatabase(context, Identifier(db_name)); if (!db) { throw BinderException("Failed to find attached database \"%s\" referenced in sqlite_query", db_name); } diff --git a/src/storage/sqlite_schema_entry.cpp b/src/storage/sqlite_schema_entry.cpp index e43f0f9..5693fdd 100644 --- a/src/storage/sqlite_schema_entry.cpp +++ b/src/storage/sqlite_schema_entry.cpp @@ -37,7 +37,7 @@ string GetCreateTableSQL(CreateTableInfo &info) { if (info.on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT) { ss << "IF NOT EXISTS "; } - ss << KeywordHelper::WriteOptionallyQuoted(info.table); + ss << KeywordHelper::WriteOptionallyQuoted(info.table.GetIdentifierName()); ss << TableCatalogEntry::ColumnsToSQL(info.columns, info.constraints); ss << ";"; return ss.str(); @@ -46,7 +46,7 @@ string GetCreateTableSQL(CreateTableInfo &info) { void SQLiteSchemaEntry::TryDropEntry(ClientContext &context, CatalogType catalog_type, const string &name) { DropInfo info; info.type = catalog_type; - info.name = name; + info.name = Identifier(name); info.cascade = false; info.if_not_found = OnEntryNotFound::RETURN_NULL; DropEntry(context, info); @@ -58,7 +58,7 @@ optional_ptr SQLiteSchemaEntry::CreateTable(CatalogTransaction tra auto table_name = base_info.table; if (base_info.on_conflict == OnCreateConflict::REPLACE_ON_CONFLICT) { // CREATE OR REPLACE - drop any existing entries first (if any) - TryDropEntry(transaction.GetContext(), CatalogType::TABLE_ENTRY, table_name); + TryDropEntry(transaction.GetContext(), CatalogType::TABLE_ENTRY, table_name.GetIdentifierName()); } sqlite_transaction.GetDB().Execute(GetCreateTableSQL(base_info)); @@ -89,9 +89,9 @@ string GetCreateIndexSQL(CreateIndexInfo &info, TableCatalogEntry &tbl) { if (info.on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT) { sql += " IF NOT EXISTS "; } - sql += KeywordHelper::WriteOptionallyQuoted(info.index_name); + sql += KeywordHelper::WriteOptionallyQuoted(info.index_name.GetIdentifierName()); sql += " ON "; - sql += KeywordHelper::WriteOptionallyQuoted(tbl.name); + sql += KeywordHelper::WriteOptionallyQuoted(tbl.name.GetIdentifierName()); sql += "("; for (idx_t i = 0; i < info.parsed_expressions.size(); i++) { if (i > 0) { @@ -117,7 +117,7 @@ string GetCreateViewSQL(CreateViewInfo &info) { if (info.on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT) { sql += "IF NOT EXISTS "; } - sql += KeywordHelper::WriteOptionallyQuoted(info.view_name); + sql += KeywordHelper::WriteOptionallyQuoted(info.view_name.GetIdentifierName()); sql += " "; if (!info.aliases.empty()) { sql += "("; @@ -126,7 +126,7 @@ string GetCreateViewSQL(CreateViewInfo &info) { sql += ", "; } auto &alias = info.aliases[i]; - sql += KeywordHelper::WriteOptionallyQuoted(alias); + sql += KeywordHelper::WriteOptionallyQuoted(alias.GetIdentifierName()); } sql += ") "; } @@ -142,7 +142,7 @@ optional_ptr SQLiteSchemaEntry::CreateView(CatalogTransaction tran } if (info.on_conflict == OnCreateConflict::REPLACE_ON_CONFLICT) { // CREATE OR REPLACE - drop any existing entries first (if any) - TryDropEntry(transaction.GetContext(), CatalogType::VIEW_ENTRY, info.view_name); + TryDropEntry(transaction.GetContext(), CatalogType::VIEW_ENTRY, info.view_name.GetIdentifierName()); } auto &sqlite_transaction = GetSQLiteTransaction(transaction); sqlite_transaction.GetDB().Execute(GetCreateViewSQL(info)); @@ -179,32 +179,32 @@ optional_ptr SQLiteSchemaEntry::CreateType(CatalogTransaction tran void SQLiteSchemaEntry::AlterTable(SQLiteTransaction &sqlite_transaction, RenameTableInfo &info) { string sql = "ALTER TABLE "; - sql += KeywordHelper::WriteOptionallyQuoted(info.name); + sql += KeywordHelper::WriteOptionallyQuoted(info.name.GetIdentifierName()); sql += " RENAME TO "; - sql += KeywordHelper::WriteOptionallyQuoted(info.new_table_name); + sql += KeywordHelper::WriteOptionallyQuoted(info.new_table_name.GetIdentifierName()); sqlite_transaction.GetDB().Execute(sql); } void SQLiteSchemaEntry::AlterTable(SQLiteTransaction &sqlite_transaction, RenameColumnInfo &info) { string sql = "ALTER TABLE "; - sql += KeywordHelper::WriteOptionallyQuoted(info.name); + sql += KeywordHelper::WriteOptionallyQuoted(info.name.GetIdentifierName()); sql += " RENAME COLUMN "; - sql += KeywordHelper::WriteOptionallyQuoted(info.old_name); + sql += KeywordHelper::WriteOptionallyQuoted(info.old_name.GetIdentifierName()); sql += " TO "; - sql += KeywordHelper::WriteOptionallyQuoted(info.new_name); + sql += KeywordHelper::WriteOptionallyQuoted(info.new_name.GetIdentifierName()); sqlite_transaction.GetDB().Execute(sql); } void SQLiteSchemaEntry::AlterTable(SQLiteTransaction &sqlite_transaction, AddColumnInfo &info) { if (info.if_column_not_exists) { - if (sqlite_transaction.GetDB().ColumnExists(info.name, info.new_column.GetName())) { + if (sqlite_transaction.GetDB().ColumnExists(info.name.GetIdentifierName(), info.new_column.GetName().GetIdentifierName())) { return; } } string sql = "ALTER TABLE "; - sql += KeywordHelper::WriteOptionallyQuoted(info.name); + sql += KeywordHelper::WriteOptionallyQuoted(info.name.GetIdentifierName()); sql += " ADD COLUMN "; - sql += KeywordHelper::WriteOptionallyQuoted(info.new_column.Name()); + sql += KeywordHelper::WriteOptionallyQuoted(info.new_column.Name().GetIdentifierName()); sql += " "; sql += info.new_column.Type().ToString(); sqlite_transaction.GetDB().Execute(sql); @@ -212,14 +212,14 @@ void SQLiteSchemaEntry::AlterTable(SQLiteTransaction &sqlite_transaction, AddCol void SQLiteSchemaEntry::AlterTable(SQLiteTransaction &sqlite_transaction, RemoveColumnInfo &info) { if (info.if_column_exists) { - if (!sqlite_transaction.GetDB().ColumnExists(info.name, info.removed_column)) { + if (!sqlite_transaction.GetDB().ColumnExists(info.name.GetIdentifierName(), info.removed_column.GetIdentifierName())) { return; } } string sql = "ALTER TABLE "; - sql += KeywordHelper::WriteOptionallyQuoted(info.name); + sql += KeywordHelper::WriteOptionallyQuoted(info.name.GetIdentifierName()); sql += " DROP COLUMN "; - sql += KeywordHelper::WriteOptionallyQuoted(info.removed_column); + sql += KeywordHelper::WriteOptionallyQuoted(info.removed_column.GetIdentifierName()); sqlite_transaction.GetDB().Execute(sql); } @@ -247,7 +247,7 @@ void SQLiteSchemaEntry::Alter(CatalogTransaction catalog_transaction, AlterInfo "support RENAME TABLE, RENAME COLUMN, " "ADD COLUMN and DROP COLUMN"); } - transaction.ClearTableEntry(info.name); + transaction.ClearTableEntry(info.name.GetIdentifierName()); } void SQLiteSchemaEntry::Scan(ClientContext &context, CatalogType type, @@ -269,7 +269,7 @@ void SQLiteSchemaEntry::Scan(ClientContext &context, CatalogType type, return; } for (auto &entry_name : entries) { - callback(*GetEntry(GetCatalogTransaction(context), type, entry_name)); + callback(*GetEntry(GetCatalogTransaction(context), type, Identifier(entry_name))); } } void SQLiteSchemaEntry::Scan(CatalogType type, const std::function &callback) { @@ -294,7 +294,7 @@ void SQLiteSchemaEntry::DropEntry(ClientContext &context, DropInfo &info) { throw InternalException("Failed to drop entry \"%s\" - could not find entry", info.name); } auto &transaction = SQLiteTransaction::Get(context, catalog); - transaction.DropEntry(info.type, info.name, info.cascade); + transaction.DropEntry(info.type, info.name.GetIdentifierName(), info.cascade); } optional_ptr SQLiteSchemaEntry::LookupEntry(CatalogTransaction transaction, diff --git a/src/storage/sqlite_table_entry.cpp b/src/storage/sqlite_table_entry.cpp index f7c0316..e19aa7d 100644 --- a/src/storage/sqlite_table_entry.cpp +++ b/src/storage/sqlite_table_entry.cpp @@ -23,18 +23,18 @@ void SQLiteTableEntry::BindUpdateConstraints(Binder &, LogicalGet &, LogicalProj TableFunction SQLiteTableEntry::GetScanFunction(ClientContext &context, unique_ptr &bind_data) { auto result = make_uniq(); for (auto &col : columns.Logical()) { - result->names.push_back(col.GetName()); + result->names.emplace_back(col.GetName().GetIdentifierName()); result->types.push_back(col.GetType()); } auto &sqlite_catalog = catalog.Cast(); result->file_name = sqlite_catalog.path; - result->table_name = name; + result->table_name = name.GetIdentifierName(); result->all_varchar = all_varchar; auto &transaction = Transaction::Get(context, catalog).Cast(); auto &db = transaction.GetDB(); - if (!db.GetRowIdInfo(name, result->row_id_info)) { + if (!db.GetRowIdInfo(name.GetIdentifierName(), result->row_id_info)) { result->rows_per_group = optional_idx(); } @@ -71,14 +71,14 @@ TableStorageInfo SQLiteTableEntry::GetStorageInfo(ClientContext &context) { TableStorageInfo result; RowIdInfo info; - if (!db.GetRowIdInfo(name, info)) { + if (!db.GetRowIdInfo(name.GetIdentifierName(), info)) { // probably result.cardinality = 10000; } else { result.cardinality = info.max_rowid.GetIndex() - info.min_rowid.GetIndex(); } - result.index_info = db.GetIndexInfo(name); + result.index_info = db.GetIndexInfo(name.GetIdentifierName()); return result; } diff --git a/src/storage/sqlite_transaction.cpp b/src/storage/sqlite_transaction.cpp index 08ea220..34b115c 100644 --- a/src/storage/sqlite_transaction.cpp +++ b/src/storage/sqlite_transaction.cpp @@ -108,7 +108,7 @@ void ExtractColumnIds(const ParsedExpression &expr, TableCatalogEntry &table, Cr if (expr.GetExpressionType() == ExpressionType::COLUMN_REF) { auto &colref = expr.Cast(); auto &colname = colref.GetColumnName(); - auto &column_def = table.GetColumn(colname); + auto &column_def = table.GetColumn(Identifier(colname)); auto index = column_def.Oid(); if (std::find(info.column_ids.begin(), info.column_ids.end(), index) == info.column_ids.end()) { info.column_ids.push_back(index); @@ -156,7 +156,7 @@ optional_ptr SQLiteTransaction::GetCatalogEntry(const string &entr unique_ptr result; switch (type) { case CatalogType::TABLE_ENTRY: { - CreateTableInfo info(sqlite_catalog.GetMainSchema(), entry_name); + CreateTableInfo info(sqlite_catalog.GetMainSchema(), Identifier(entry_name)); bool all_varchar = false; Value sqlite_all_varchar; if (context.lock()->TryGetCurrentSetting("sqlite_all_varchar", sqlite_all_varchar)) { @@ -177,7 +177,7 @@ optional_ptr SQLiteTransaction::GetCatalogEntry(const string &entr view_info = CreateViewInfo::FromCreateView(*context.lock(), sqlite_catalog.GetMainSchema(), sql); } catch (std::exception &ex) { auto view_sql = ExtractSelectStatement(sql); - auto catalog_name = StringUtil::Replace(sqlite_catalog.GetName(), "\"", "\"\""); + auto catalog_name = StringUtil::Replace(sqlite_catalog.GetName().GetIdentifierName(), "\"", "\"\""); auto escaped_view_sql = StringUtil::Replace(view_sql, "'", "''"); auto view_def = StringUtil::Format("CREATE VIEW %s AS FROM sqlite_query(\"%s\", '%s')", entry_name, catalog_name, escaped_view_sql); diff --git a/src/storage/sqlite_update.cpp b/src/storage/sqlite_update.cpp index 29ab390..cc6e095 100644 --- a/src/storage/sqlite_update.cpp +++ b/src/storage/sqlite_update.cpp @@ -29,14 +29,14 @@ class SQLiteUpdateGlobalState : public GlobalSinkState { string GetUpdateSQL(SQLiteTableEntry &table, const vector &index) { string result; - result = "UPDATE " + KeywordHelper::WriteOptionallyQuoted(table.name); + result = "UPDATE " + KeywordHelper::WriteOptionallyQuoted(table.name.GetIdentifierName()); result += " SET "; for (idx_t i = 0; i < index.size(); i++) { if (i > 0) { result += ", "; } auto &col = table.GetColumn(LogicalIndex(index[i].index)); - result += KeywordHelper::WriteOptionallyQuoted(col.GetName()); + result += KeywordHelper::WriteOptionallyQuoted(col.GetName().GetIdentifierName()); result += " = ?"; } result += " WHERE rowid = ?"; @@ -99,7 +99,7 @@ string SQLiteUpdate::GetName() const { InsertionOrderPreservingMap SQLiteUpdate::ParamsToString() const { InsertionOrderPreservingMap result; - result["Table Name"] = table.name; + result["Table Name"] = table.name.GetIdentifierName(); return result; }