expose: idempotent store Open, pg cleanup on failed connect + fallback proof
This commit is contained in:
@@ -96,6 +96,7 @@ class SqliteStore : public StatsStore {
|
||||
if (db_) sqlite3_close(db_);
|
||||
}
|
||||
bool Open(std::string& err) override {
|
||||
if (db_) return true; // idempotent: :memory: DBs must survive re-Open
|
||||
if (sqlite3_open(path_.c_str(), &db_) != SQLITE_OK) {
|
||||
err = sqlite3_errmsg(db_);
|
||||
return false;
|
||||
@@ -197,9 +198,11 @@ class PgStore : public StatsStore {
|
||||
if (db_) PQfinish(db_);
|
||||
}
|
||||
bool Open(std::string& err) override {
|
||||
if (db_) return true;
|
||||
db_ = PQconnectdb(url_.c_str());
|
||||
if (!db_ || PQstatus(db_) != CONNECTION_OK) {
|
||||
err = db_ ? PQerrorMessage(db_) : "pg connect failed";
|
||||
if (db_) { PQfinish(db_); db_ = nullptr; }
|
||||
return false;
|
||||
}
|
||||
PGresult* r = PQexec(db_, kSchemaPg);
|
||||
|
||||
Reference in New Issue
Block a user