backend-sqlite3: correctly finalize sqlite3 prepared statements
This commit is contained in:
parent
868ec46738
commit
406de2b323
@ -77,10 +77,11 @@ int SQLite_print_contents_subtree(sqlite3 *db,
|
||||
ft->numproviders);
|
||||
sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL);
|
||||
sqlite3_bind_text(stmt, 1, ft->name, -1, SQLITE_STATIC);
|
||||
|
||||
if (sqlite3_step(stmt) != SQLITE_DONE) {
|
||||
fprintf(stderr, "ERROR: SQLite: %s (%s)\n", sqlite3_errmsg(db), sqlite3_query);
|
||||
fprintf(stderr, "ERROR: sqlite3_step: %s (%s)\n", sqlite3_errmsg(db), sqlite3_query);
|
||||
return 1;
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
sqlite3_transaction_size += strlen(sqlite3_query);
|
||||
if (sqlite3_transaction_size >= sqlite3_transaction_maxsize) {
|
||||
@ -128,13 +129,13 @@ int generateSQLite_files(struct configTag* ct, sqlite3 *db, int arch) {
|
||||
currpackage->id,
|
||||
currpackage->file[i]->id);
|
||||
if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) {
|
||||
fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
|
||||
fprintf(stderr, "ERROR: sqlite3_prepare_v2: %s (%s)\n", sqlite3_errmsg(db), sqlite3_query);
|
||||
}
|
||||
sqlite3_bind_text(stmt, 1, currpackage->name, -1, SQLITE_STATIC);
|
||||
sqlite3_bind_text(stmt, 2, currpackage->version, -1, SQLITE_STATIC);
|
||||
sqlite3_bind_text(stmt, 3, currpackage->release, -1, SQLITE_STATIC);
|
||||
if (sqlite3_step(stmt) != SQLITE_DONE) {
|
||||
fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
|
||||
fprintf(stderr, "ERROR: sqlite3_step: %s (%s)\n", sqlite3_query, sqlite3_errmsg(db));
|
||||
return 3;
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
@ -159,33 +160,26 @@ int generateSQLite_provided(struct configTag* ct, sqlite3 *db, int arch) {
|
||||
int i;
|
||||
struct providedList* provided;
|
||||
|
||||
// for (i = 0; i < ARCHS_MAX && ct->arch[i]; i++) {
|
||||
snprintf(sqlite3_query, PATH_MAX, "provided");
|
||||
SQLite_init_table(db, sqlite3_query, SQLITE_TABLE_provided);
|
||||
SQLite_begin_transaction(db);
|
||||
snprintf(sqlite3_query, PATH_MAX, "provided");
|
||||
SQLite_init_table(db, sqlite3_query, SQLITE_TABLE_provided);
|
||||
SQLite_begin_transaction(db);
|
||||
|
||||
provided = ct->providedlist_idx[arch][0];
|
||||
while (provided) {
|
||||
snprintf(sqlite3_query, PATH_MAX, "INSERT INTO provided VALUES(%d,?,%d,%d);",
|
||||
provided->id,
|
||||
provided->flags,
|
||||
provided->numproviders);
|
||||
|
||||
sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL);
|
||||
sqlite3_bind_text(stmt, 1, provided->name, -1, SQLITE_STATIC);
|
||||
|
||||
if (sqlite3_step(stmt) != SQLITE_DONE) {
|
||||
fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
|
||||
}
|
||||
provided = provided->next;
|
||||
provided = ct->providedlist_idx[arch][0];
|
||||
while (provided) {
|
||||
snprintf(sqlite3_query, PATH_MAX, "INSERT INTO provided VALUES(%d,?,%d,%d);",
|
||||
provided->id,
|
||||
provided->flags,
|
||||
provided->numproviders);
|
||||
sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL);
|
||||
sqlite3_bind_text(stmt, 1, provided->name, -1, SQLITE_STATIC);
|
||||
if (sqlite3_step(stmt) != SQLITE_DONE) {
|
||||
fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
provided = provided->next;
|
||||
}
|
||||
|
||||
SQLite_commit_transaction(db);
|
||||
|
||||
/* if (sqlite3_finalize(stmt)) {
|
||||
fprintf(stderr, "ERROR: SQLite: (%s) %s", sqlite3_query, sqlite3_errmsg(db));
|
||||
}*/
|
||||
// }
|
||||
SQLite_commit_transaction(db);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -522,12 +516,12 @@ generateSQLiteFiles(struct configTag *ct)
|
||||
unlink(dbname);
|
||||
|
||||
if (sqlite3_open_v2(dbname, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL)) {
|
||||
logmsg(LOG_ERROR, "sqlite3_open_v2: %s %s", sqlite3_errmsg(db), dbname);
|
||||
logmsg(LOG_ERROR, "sqlite3_open_v2: %s (%s)", dbname, sqlite3_errmsg(db));
|
||||
if (db) sqlite3_close(db);
|
||||
return 1;
|
||||
}
|
||||
generateSQLite_files(ct, db, i);
|
||||
sqlite3_close(db);
|
||||
if (generateSQLite_files(ct, db, i)) return 1;
|
||||
if (db) sqlite3_close(db);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user