MCPcopy Create free account
hub / github.com/duckdb/duckdb / OpenDB

Method OpenDB

tools/shell/shell.cpp:1173–1211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1171}
1172
1173void ShellState::OpenDB(ShellOpenFlags flags) {
1174 // log storage to stdout
1175 auto std_out_log_storage = duckdb::make_shared_ptr<ShellLogStorage>(*this);
1176 duckdb::shared_ptr<duckdb::LogStorage> storage_ptr = std_out_log_storage;
1177
1178 if (!db) {
1179 try {
1180 db = make_uniq<duckdb::DuckDB>(zDbFilename.c_str(), &config);
1181 RegisterShellLogger(*db, storage_ptr);
1182 conn = make_uniq<duckdb::Connection>(*db);
1183 } catch (std::exception &ex) {
1184 duckdb::ErrorData error(ex);
1185 PrintDatabaseError(error.Message());
1186 if (flags == ShellOpenFlags::KEEP_ALIVE_ON_FAILURE) {
1187 db = make_uniq<duckdb::DuckDB>(":memory:", &config);
1188 RegisterShellLogger(*db, storage_ptr);
1189 conn = make_uniq<duckdb::Connection>(*db);
1190 } else {
1191 ShellState::Exit(1);
1192 }
1193 }
1194 auto &client_config = duckdb::ClientConfig::GetConfig(*conn->context);
1195 if (stdout_is_console) {
1196 client_config.display_create_func = CreateProgressBar;
1197 }
1198#ifdef SHELL_INLINE_AUTOCOMPLETE
1199 db->LoadStaticExtension<duckdb::AutocompleteExtension>();
1200#endif
1201 db->LoadStaticExtension<duckdb::ShellExtension>();
1202 if (safe_mode) {
1203 ExecuteQuery("SET enable_external_access=false");
1204 ExecuteQuery("SET lock_configuration=true");
1205 }
1206 if (stdout_is_console) {
1207 ExecuteQuery("PRAGMA enable_progress_bar");
1208 ExecuteQuery("PRAGMA enable_print_progress_bar");
1209 }
1210 }
1211}
1212
1213/*
1214** Do C-language style dequoting.

Callers 1

RunShellFunction · 0.80

Calls 3

RegisterShellLoggerFunction · 0.85
ExecuteQueryFunction · 0.85
c_strMethod · 0.80

Tested by

no test coverage detected