distroquery: correctly finalize sqlite3 prepared statements

This commit is contained in:
Silvan Calarco 2013-10-14 18:18:31 +02:00
parent ec0c093578
commit 868ec46738

View File

@ -315,15 +315,14 @@ void printQueryData() {
if (sqlite3_prepare_v2((sqlite3*)query_repositories[i]->db[ARCHS_MAX], sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) { if (sqlite3_prepare_v2((sqlite3*)query_repositories[i]->db[ARCHS_MAX], sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) {
sqlite3_step(stmt1); sqlite3_step(stmt1);
get_favicon_from_url(sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "url")),buffer,PATH_MAX); get_favicon_from_url(sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "url")),buffer,PATH_MAX);
} else buffer[0]='\0'; printf("<div style='position:relative'><hr><br>");
printTagsLine(query_repositories[i]->arch[a],
printf("<div style='position:relative'><hr><br>"); query_repositories[i]->tag,
printTagsLine(query_repositories[i]->arch[a], sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "groupdescr")),
query_repositories[i]->tag, sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "license")));
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "groupdescr")), printf("<br><img src=\"%s\" width\"16\" height=\"16\">&nbsp;", buffer);
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "license"))); sqlite3_finalize(stmt1);
printf("<br><img src=\"%s\" width\"16\" height=\"16\">&nbsp;", buffer); }
printf("<b>%s</b> %s-%s<br>%s", printf("<b>%s</b> %s-%s<br>%s",
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")), sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")),
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "version")), sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "version")),
@ -364,6 +363,7 @@ void printQueryData() {
printf("</div></div><br>"); printf("</div></div><br>");
} }
} }
sqlite3_finalize(statement);
localprovidesresults = 0; localprovidesresults = 0;
snprintf(sql, PATH_MAX, snprintf(sql, PATH_MAX,
"SELECT * FROM packages,provides,provided WHERE " "SELECT * FROM packages,provides,provided WHERE "
@ -394,6 +394,7 @@ void printQueryData() {
} }
if (localprovidesresults > 0) printf("</div>"); if (localprovidesresults > 0) printf("</div>");
} }
sqlite3_finalize(statement);
} }
} }
} }
@ -442,6 +443,7 @@ void printQueryData() {
query_repositories[i]->tag, query_repositories[i]->tag,
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name"))); sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")));
} }
sqlite3_finalize(statement);
} else { } else {
fprintf(stderr, "ERROR: SQLite: %s (%s)\n", sqlite3_errmsg(query_repositories[i]->db[ARCHS_MAX]), sql); fprintf(stderr, "ERROR: SQLite: %s (%s)\n", sqlite3_errmsg(query_repositories[i]->db[ARCHS_MAX]), sql);
} }
@ -493,15 +495,21 @@ void printPackageData() {
if (db && if (db &&
(sqlite3_prepare_v2(db, sql, strlen(sql), &statement, NULL) == SQLITE_OK)) { (sqlite3_prepare_v2(db, sql, strlen(sql), &statement, NULL) == SQLITE_OK)) {
if (sqlite3_step(statement) == SQLITE_ROW) { if (sqlite3_step(statement) == SQLITE_ROW) {
snprintf(dbname, PATH_MAX, "%s%s-sources.db", ct->repository_dir, ct->tag); snprintf(dbname, PATH_MAX, "%s%s-sources.db", ct->repository_dir, ct->tag);
if (!sqlite3_open_v2(dbname, &dbs, SQLITE_OPEN_READONLY, NULL)) { if (sqlite3_open_v2(dbname, &dbs, SQLITE_OPEN_READONLY, NULL)) {
if (dbs) sqlite3_close(dbs);
snprintf(sql, PATH_MAX, dbs = NULL;
"SELECT * FROM sources,packagers WHERE sources.id=%d AND sources.id_packager=packagers.id", fprintf(stderr, "ERROR: unable to open sqlite3 db %s; aborting.\n", dbname);
sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id_source"))); return;
if (sqlite3_prepare_v2(dbs, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) sqlite3_step(stmt1);
} }
snprintf(sql, PATH_MAX,
"SELECT * FROM sources,packagers WHERE sources.id=%d AND sources.id_packager=packagers.id",
sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id_source")));
if (!sqlite3_prepare_v2(dbs, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) {
fprintf(stderr, "ERROR: unable to prepare statement for %s; aborting.\n", sql);
return;
}
sqlite3_step(stmt1);
printf("<hr><br>"); printf("<hr><br>");
printTagsLine(query_arch, printTagsLine(query_arch,
@ -529,7 +537,7 @@ void printPackageData() {
snprintf(sql, PATH_MAX, "SELECT * FROM packages WHERE id_source=%d AND NOT id=%d", snprintf(sql, PATH_MAX, "SELECT * FROM packages WHERE id_source=%d AND NOT id=%d",
sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id_source")), sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id_source")),
sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id")));
if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt2, NULL) == SQLITE_OK) if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt2, NULL) == SQLITE_OK) {
while (sqlite3_step(stmt2) == SQLITE_ROW) while (sqlite3_step(stmt2) == SQLITE_ROW)
printf(" <a href='javascript:distroquery_request(\"repository=%s&package=%s&arch=%s\")'>%s(%s)</a>", printf(" <a href='javascript:distroquery_request(\"repository=%s&package=%s&arch=%s\")'>%s(%s)</a>",
ct->tag, ct->tag,
@ -537,7 +545,8 @@ void printPackageData() {
query_arch, query_arch,
sqlite3_column_text(stmt2,sqlite3_find_column_id(stmt2, NULL, "name")), sqlite3_column_text(stmt2,sqlite3_find_column_id(stmt2, NULL, "name")),
query_arch); query_arch);
sqlite3_finalize(stmt2);
}
printf("<br><br><div style='text-align:justify;text-justify:inter-word;font-style:italic'>%s</div><br>", printf("<br><br><div style='text-align:justify;text-justify:inter-word;font-style:italic'>%s</div><br>",
htmlclean(sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "description")),buffer,PATH_MAX)); htmlclean(sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "description")),buffer,PATH_MAX));
@ -568,7 +577,8 @@ void printPackageData() {
printf("<br><br>%s:", _("Obsoletes")); printf("<br><br>%s:", _("Obsoletes"));
snprintf(sql, PATH_MAX, "SELECT * FROM obsoletes WHERE id_package=%d", snprintf(sql, PATH_MAX, "SELECT * FROM obsoletes WHERE id_package=%d",
sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id")));
if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) sqlite3_finalize(stmt1);
if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) {
while (sqlite3_step(stmt1) == SQLITE_ROW) { while (sqlite3_step(stmt1) == SQLITE_ROW) {
printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "obsoletename"))); printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "obsoletename")));
if (sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "obsoleteversion"))) { if (sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "obsoleteversion"))) {
@ -576,13 +586,14 @@ void printPackageData() {
printf("%s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "obsoleteversion"))); printf("%s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "obsoleteversion")));
} }
} }
sqlite3_finalize(stmt1);
}
printf("<br><br>%s:",_("Provides")); printf("<br><br>%s:",_("Provides"));
snprintf(sql, PATH_MAX, "SELECT * FROM provides,provided " snprintf(sql, PATH_MAX, "SELECT * FROM provides,provided "
"WHERE provides.id_package=%d AND provided.id=provides.id_provided " "WHERE provides.id_package=%d AND provided.id=provides.id_provided "
"ORDER BY provided.name", "ORDER BY provided.name",
sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id")));
if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) {
while (sqlite3_step(stmt1) == SQLITE_ROW) { while (sqlite3_step(stmt1) == SQLITE_ROW) {
printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name"))); printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name")));
if (sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "provideversion"))) { if (sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "provideversion"))) {
@ -590,13 +601,14 @@ void printPackageData() {
printf("%s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "provideversion"))); printf("%s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "provideversion")));
} }
} }
sqlite3_finalize(stmt1);
}
printf("<br><br>%s:", _("Requires")); printf("<br><br>%s:", _("Requires"));
snprintf(sql, PATH_MAX, "SELECT * FROM requires,provided " snprintf(sql, PATH_MAX, "SELECT * FROM requires,provided "
"WHERE requires.id_package=%d AND provided.id=requires.id_provided " "WHERE requires.id_package=%d AND provided.id=requires.id_provided "
"ORDER BY provided.name", "ORDER BY provided.name",
sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id")));
if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) {
while (sqlite3_step(stmt1) == SQLITE_ROW) { while (sqlite3_step(stmt1) == SQLITE_ROW) {
printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name"))); printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name")));
if (sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "requireversion"))) { if (sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "requireversion"))) {
@ -604,14 +616,18 @@ void printPackageData() {
printf("%s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "requireversion"))); printf("%s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "requireversion")));
} }
} }
sqlite3_finalize(stmt1);
}
sqlite3_close(dbs); sqlite3_close(dbs);
} }
snprintf(buffer, PATH_MAX, "%s - %s",
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")),
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")));
sqlite3_finalize(statement);
} }
printf("]]></queryreply>"); printf("]]></queryreply>");
printf("<title><![CDATA[%s - %s :: %s]]></title>", printf("<title><![CDATA[%s :: %s]]></title>",
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")), buffer,
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")),
firstconfigtag->configdefaults->distribution_name); firstconfigtag->configdefaults->distribution_name);
sqlite3_close(db); sqlite3_close(db);
@ -673,7 +689,7 @@ void printSourcePackageData() {
if (!sqlite3_open_v2(dbname, &dba, SQLITE_OPEN_READONLY, NULL)) { if (!sqlite3_open_v2(dbname, &dba, SQLITE_OPEN_READONLY, NULL)) {
snprintf(sql, PATH_MAX, "SELECT * FROM packages WHERE id_source=%d", snprintf(sql, PATH_MAX, "SELECT * FROM packages WHERE id_source=%d",
sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id")));
if (sqlite3_prepare_v2(dba, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) if (sqlite3_prepare_v2(dba, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) {
while (sqlite3_step(stmt1) == SQLITE_ROW) while (sqlite3_step(stmt1) == SQLITE_ROW)
printf(" <a href='javascript:distroquery_request(\"repository=%s&package=%s&arch=%s\")'>%s(%s)</a>", printf(" <a href='javascript:distroquery_request(\"repository=%s&package=%s&arch=%s\")'>%s(%s)</a>",
ct->tag, ct->tag,
@ -681,6 +697,8 @@ void printSourcePackageData() {
ct->arch[a], ct->arch[a],
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name")), sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name")),
ct->arch[a]); ct->arch[a]);
sqlite3_finalize(stmt1);
}
sqlite3_close(dba); sqlite3_close(dba);
} }
} }
@ -707,25 +725,27 @@ void printSourcePackageData() {
snprintf(sql, PATH_MAX, snprintf(sql, PATH_MAX,
"SELECT * FROM sources_source WHERE id_source=%d", "SELECT * FROM sources_source WHERE id_source=%d",
sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id")));
if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) {
while (sqlite3_step(stmt1) == SQLITE_ROW) { while (sqlite3_step(stmt1) == SQLITE_ROW) {
printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "source"))); printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "source")));
} }
sqlite3_finalize(stmt1);
}
printf("<br><br>%s:", _("Patches")); printf("<br><br>%s:", _("Patches"));
snprintf(sql, PATH_MAX, snprintf(sql, PATH_MAX,
"SELECT * FROM sources_patch WHERE id_source=%d", "SELECT * FROM sources_patch WHERE id_source=%d",
sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id")));
if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) {
while (sqlite3_step(stmt1) == SQLITE_ROW) { while (sqlite3_step(stmt1) == SQLITE_ROW) {
printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "patch"))); printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "patch")));
} }
sqlite3_finalize(stmt1);
}
printf("<br><br>%s:", _("Build requirements")); printf("<br><br>%s:", _("Build requirements"));
snprintf(sql, PATH_MAX, "SELECT * FROM buildrequires WHERE id_source=%d", snprintf(sql, PATH_MAX, "SELECT * FROM buildrequires WHERE id_source=%d",
sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id")));
if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) {
while (sqlite3_step(stmt1) == SQLITE_ROW) { while (sqlite3_step(stmt1) == SQLITE_ROW) {
printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "buildrequirename"))); printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "buildrequirename")));
if (strcmp("", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "buildrequireversion")))) { if (strcmp("", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "buildrequireversion")))) {
@ -733,12 +753,14 @@ void printSourcePackageData() {
printf("%s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "buildrequireversion"))); printf("%s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "buildrequireversion")));
} }
} }
sqlite3_finalize(stmt1);
}
printf("<br><br>%s:<br>", _("Changelog")); printf("<br><br>%s:<br>", _("Changelog"));
snprintf(sql, PATH_MAX, snprintf(sql, PATH_MAX,
"SELECT * FROM changelog,packagers WHERE id_source=%d AND changelog.id_packager=packagers.id", "SELECT * FROM changelog,packagers WHERE id_source=%d AND changelog.id_packager=packagers.id",
sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id")));
if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) {
while (sqlite3_step(stmt1) == SQLITE_ROW) { while (sqlite3_step(stmt1) == SQLITE_ROW) {
printf("%s - %s (%s)<br><pre>%s</pre>", printf("%s - %s (%s)<br><pre>%s</pre>",
simpleTimeToHuman(sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "time")), (humanDate *) & strdate), simpleTimeToHuman(sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "time")), (humanDate *) & strdate),
@ -746,14 +768,17 @@ void printSourcePackageData() {
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "release")), sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "release")),
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "text"))); sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "text")));
} }
sqlite3_finalize(stmt1);
}
} }
snprintf(buffer, PATH_MAX, "%s - %s",
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")),
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")));
sqlite3_finalize(statement);
} }
printf("]]></queryreply>"); printf("]]></queryreply>");
printf("<title><![CDATA[%s - %s :: %s]]></title>", printf("<title><![CDATA[%s :: %s]]></title>",
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")), buffer,
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")),
firstconfigtag->configdefaults->distribution_name); firstconfigtag->configdefaults->distribution_name);
sqlite3_close(db); sqlite3_close(db);