MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / openSQLiteDB

Function openSQLiteDB

src/Databases/SQLite/SQLiteUtils.cpp:44–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44SQLitePtr openSQLiteDB(const String & path, ContextPtr context, bool throw_on_error)
45{
46 // If run in Local mode, no need for path checking.
47 bool need_check = context->getApplicationType() != Context::ApplicationType::LOCAL;
48
49 auto user_files_path = context->getUserFilesPath();
50 auto database_path = validateSQLiteDatabasePath(path, user_files_path, need_check, throw_on_error);
51
52 /// For attach database there is no throw mode.
53 if (database_path.empty())
54 return nullptr;
55
56 if (!fs::exists(database_path))
57 LOG_DEBUG(getLogger("SQLite"), "SQLite database path {} does not exist, will create an empty SQLite database", database_path);
58
59 sqlite3 * tmp_sqlite_db = nullptr;
60 int status = 0;
61 {
62 std::lock_guard lock(init_sqlite_db_mutex);
63 status = sqlite3_open(database_path.c_str(), &tmp_sqlite_db);
64 }
65
66 if (status != SQLITE_OK)
67 {
68 processSQLiteError(fmt::format("Cannot access sqlite database. Error status: {}. Message: {}",
69 status, sqlite3_errstr(status)), throw_on_error);
70 return nullptr;
71 }
72
73 return std::shared_ptr<sqlite3>(tmp_sqlite_db, sqlite3_close);
74}
75
76}
77

Callers 8

readMethod · 0.85
writeMethod · 0.85
registerStorageSQLiteFunction · 0.85
DatabaseSQLiteMethod · 0.85
fetchTablesListMethod · 0.85
checkSQLiteTableMethod · 0.85
fetchTableMethod · 0.85
parseArgumentsMethod · 0.85

Calls 8

processSQLiteErrorFunction · 0.85
getApplicationTypeMethod · 0.80
getUserFilesPathMethod · 0.80
existsFunction · 0.50
getLoggerFunction · 0.50
formatFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected