Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/node_webstorage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,24 @@ Maybe<void> Storage::Open() {
""
"INSERT OR IGNORE INTO nodejs_webstorage_state (total_size) VALUES (0);";

sqlite3* db = db_.get();
if (db != nullptr) {
if (db_ != nullptr) {
return JustVoid();
}

sqlite3* db = nullptr;
int r = sqlite3_open(location_.c_str(), &db);
auto conn = conn_unique_ptr(db);
CHECK_ERROR_OR_THROW(env(), r, SQLITE_OK, Nothing<void>());
r = sqlite3_exec(db, init_sql_v0.data(), nullptr, nullptr, nullptr);
r = sqlite3_exec(conn.get(), init_sql_v0.data(), nullptr, nullptr, nullptr);
CHECK_ERROR_OR_THROW(env(), r, SQLITE_OK, Nothing<void>());

// Get the current schema version, used to determine schema migrations.
sqlite3_stmt* s = nullptr;
r = sqlite3_prepare_v2(db,
r = sqlite3_prepare_v2(conn.get(),
get_schema_version_sql.data(),
get_schema_version_sql.size(),
&s,
nullptr);
r = sqlite3_exec(db, init_sql_v0.data(), nullptr, nullptr, nullptr);
CHECK_ERROR_OR_THROW(env(), r, SQLITE_OK, Nothing<void>());
auto stmt = stmt_unique_ptr(s);
CHECK_ERROR_OR_THROW(
Expand All @@ -205,11 +205,11 @@ Maybe<void> Storage::Open() {
"UPDATE nodejs_webstorage_state SET schema_version = " +
std::to_string(kCurrentSchemaVersion) + ";";
r = sqlite3_exec(
db, set_user_version_sql.c_str(), nullptr, nullptr, nullptr);
conn.get(), set_user_version_sql.c_str(), nullptr, nullptr, nullptr);
CHECK_ERROR_OR_THROW(env(), r, SQLITE_OK, Nothing<void>());
}

db_ = conn_unique_ptr(db);
db_ = std::move(conn);
return JustVoid();
}

Expand Down
Loading