1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 12:17:44 +00:00

SQLServer: Store LibSQL database files in the standard data directory

This also allows for overriding the path. Ladybird will want to store
the database files in a subdirectory of the standard data directory that
contains the Ladybird application name.

Fixes #16000.
This commit is contained in:
Timothy Flynn 2022-12-05 12:50:45 -05:00 committed by Andreas Kling
parent 49d74ee288
commit b3e287342f
5 changed files with 23 additions and 12 deletions

View file

@ -21,12 +21,14 @@ RefPtr<DatabaseConnection> DatabaseConnection::connection_for(u64 connection_id)
return nullptr;
}
ErrorOr<NonnullRefPtr<DatabaseConnection>> DatabaseConnection::create(DeprecatedString database_name, int client_id)
ErrorOr<NonnullRefPtr<DatabaseConnection>> DatabaseConnection::create(StringView database_path, DeprecatedString database_name, int client_id)
{
if (LexicalPath path(database_name); (path.title() != database_name) || (path.dirname() != "."))
return Error::from_string_view("Invalid database name"sv);
auto database = SQL::Database::construct(DeprecatedString::formatted("/home/anon/sql/{}.db", database_name));
auto database_file = DeprecatedString::formatted("{}/{}.db", database_path, database_name);
auto database = SQL::Database::construct(move(database_file));
if (auto result = database->open(); result.is_error()) {
warnln("Could not open database: {}", result.error().error_string());
return Error::from_string_view("Could not open database"sv);