Commit 08b5add9 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[326] initial cpp version

parent a176724d
......@@ -668,13 +668,26 @@ checkAndSetupSchema(Sqlite3Initializer* initializer) {
if (prepared != NULL) {
sqlite3_finalize(prepared);
}
for (int i = 0; SCHEMA_LIST[i] != NULL; ++i) {
if (sqlite3_exec(db, SCHEMA_LIST[i], NULL, NULL, NULL) !=
SQLITE_OK) {
isc_throw(Sqlite3Error,
"Failed to set up schema " << SCHEMA_LIST[i]);
// We need to create the database. However, there is a potential
// race condition with another process that wants to do the same
// So we acquire an exclusive lock, and then check whether the
// tables have been created again. If not, we create them.
sqlite3_exec(db, "BEGIN EXCLUSIVE TRANSACTION", NULL, NULL, NULL);
if (sqlite3_prepare_v2(db, "SELECT version FROM schema_version", -1,
&prepared, NULL) == SQLITE_OK &&
sqlite3_step(prepared) == SQLITE_ROW) {
initializer->params_.version_ = sqlite3_column_int(prepared, 0);
sqlite3_finalize(prepared);
} else {
for (int i = 0; SCHEMA_LIST[i] != NULL; ++i) {
if (sqlite3_exec(db, SCHEMA_LIST[i], NULL, NULL, NULL) !=
SQLITE_OK) {
isc_throw(Sqlite3Error,
"Failed to set up schema " << SCHEMA_LIST[i]);
}
}
}
sqlite3_exec(db, "COMMIT TRANSACTION", NULL, NULL, NULL);
}
initializer->params_.q_zone_ = prepare(db, q_zone_str);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment