#include "sqlite3.h"
#include "zpm.h"
-int zpm_foreach_path(struct zpm *zpm, char *pkgid,
+int zpm_foreach_path(struct zpm *zpm, char *pkgid, char *where,
int (*callback)(void *f, int ncols, char **vals, char **cols),
void *data, char **errmsg) {
+ char *sql;
+ sqlite3_str *s;
- char *files = "select * from packagefiles where"
- " printf('%%s-%%s-%%s', package, version, release) = %Q"
- " order by path"
- ;
+ if (!zpm || zpm->error || !callback) return 0;
- char *sql;
+ s = sqlite3_str_new(zpm->db);
+ sqlite3_str_appendall(s, "select * from packagefiles_pkgid where ");
+
+ if (where) {
+ sqlite3_str_appendf(s, "%s", where);
+ } else {
+ sqlite3_str_appendall(s, "true");
+ }
+
+ if (pkgid) {
+ sqlite3_str_appendf(s, " and printf('%%s-%%s-%%s', package, version, release) = %Q", pkgid);
+ }
- if (!zpm || zpm->error || !pkgid || !callback) return 0;
- sql = sqlite3_mprintf(files, pkgid);
+ sql = sqlite3_str_value(s);
if (!sql) {
- return 0;
+ sqlite3_str_finish(s);
zpm->error = 1;
+ return 0;
}
zpm_exec(zpm, sql, callback, data, errmsg);
- if (errmsg) {
+ sqlite3_str_finish(s);
+ if (*errmsg) {
+ fprintf(stderr, "errmsg: %s\n", *errmsg);
zpm->error = 2;
return 0;
}
- sqlite3_free(sql);
return 1;
}
/* install a collation function */
// zpm_addvercmp(&pkg);
- if (!zpm_foreach_path(&pkg, conf.pkgid, conf.callback, &conf, &errmsg)) {
+ if (!zpm_foreach_path(&pkg, conf.pkgid, 0, conf.callback, &conf, &errmsg)) {
if (errmsg) {
fprintf(stderr, "database error: %s\n", errmsg);
exit(EXIT_FAILURE);
int zpm_exec(struct zpm *z, const char *sql, int(*callback)(void *, int, char **, char**), void *arg, char **errmsg);
-int zpm_foreach_path(struct zpm *zpm, char *pkgid,
+int zpm_foreach_path(struct zpm *zpm, char *pkgid, char *where,
int (*callback)(void *f, int ncols, char **vals, char **cols),
void *data, char **errmsg);