backend-sqlite3: correctly finalize sqlite3 prepared statements

This commit is contained in:
Silvan Calarco 2013-10-14 18:19:10 +02:00
parent 868ec46738
commit 406de2b323

View File

@ -77,10 +77,11 @@ int SQLite_print_contents_subtree(sqlite3 *db,
ft->numproviders); ft->numproviders);
sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL); sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL);
sqlite3_bind_text(stmt, 1, ft->name, -1, SQLITE_STATIC); sqlite3_bind_text(stmt, 1, ft->name, -1, SQLITE_STATIC);
if (sqlite3_step(stmt) != SQLITE_DONE) { 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); sqlite3_transaction_size += strlen(sqlite3_query);
if (sqlite3_transaction_size >= sqlite3_transaction_maxsize) { if (sqlite3_transaction_size >= sqlite3_transaction_maxsize) {
@ -128,13 +129,13 @@ int generateSQLite_files(struct configTag* ct, sqlite3 *db, int arch) {
currpackage->id, currpackage->id,
currpackage->file[i]->id); currpackage->file[i]->id);
if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { 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, 1, currpackage->name, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 2, currpackage->version, -1, SQLITE_STATIC); sqlite3_bind_text(stmt, 2, currpackage->version, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 3, currpackage->release, -1, SQLITE_STATIC); sqlite3_bind_text(stmt, 3, currpackage->release, -1, SQLITE_STATIC);
if (sqlite3_step(stmt) != SQLITE_DONE) { 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; return 3;
} }
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
@ -159,7 +160,6 @@ int generateSQLite_provided(struct configTag* ct, sqlite3 *db, int arch) {
int i; int i;
struct providedList* provided; struct providedList* provided;
// for (i = 0; i < ARCHS_MAX && ct->arch[i]; i++) {
snprintf(sqlite3_query, PATH_MAX, "provided"); snprintf(sqlite3_query, PATH_MAX, "provided");
SQLite_init_table(db, sqlite3_query, SQLITE_TABLE_provided); SQLite_init_table(db, sqlite3_query, SQLITE_TABLE_provided);
SQLite_begin_transaction(db); SQLite_begin_transaction(db);
@ -170,23 +170,17 @@ int generateSQLite_provided(struct configTag* ct, sqlite3 *db, int arch) {
provided->id, provided->id,
provided->flags, provided->flags,
provided->numproviders); provided->numproviders);
sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL); sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL);
sqlite3_bind_text(stmt, 1, provided->name, -1, SQLITE_STATIC); sqlite3_bind_text(stmt, 1, provided->name, -1, SQLITE_STATIC);
if (sqlite3_step(stmt) != SQLITE_DONE) { if (sqlite3_step(stmt) != SQLITE_DONE) {
fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
} }
sqlite3_finalize(stmt);
provided = provided->next; provided = provided->next;
} }
SQLite_commit_transaction(db); SQLite_commit_transaction(db);
/* if (sqlite3_finalize(stmt)) {
fprintf(stderr, "ERROR: SQLite: (%s) %s", sqlite3_query, sqlite3_errmsg(db));
}*/
// }
return 0; return 0;
} }
@ -522,12 +516,12 @@ generateSQLiteFiles(struct configTag *ct)
unlink(dbname); unlink(dbname);
if (sqlite3_open_v2(dbname, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL)) { 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); if (db) sqlite3_close(db);
return 1; return 1;
} }
generateSQLite_files(ct, db, i); if (generateSQLite_files(ct, db, i)) return 1;
sqlite3_close(db); if (db) sqlite3_close(db);
} }
return 0; return 0;
} }