+void zpm_db_run(struct zpm *zpm, char *query, ...) {
+ sqlite3_stmt *st;
+ va_list args;
+ int rv;
+
+ va_start(args, query);
+ st = zpm_dbqueryv(zpm, query, args);
+ va_end(args);
+
+ rv = sqlite3_step(st);
+
+ if (rv != SQLITE_DONE) {
+ zpm->error = 1;
+ zpm_seterror(zpm, "db error: %s", sqlite3_errstr(rv));
+ }
+
+ sqlite3_finalize(st);
+ return ;
+}
+
+int zpm_findhash(struct zpm *zpm, char *find, char *dest) {
+ int count;
+ char *found;
+
+ count = zpm_db_int(zpm, "select count(*) from files where hash like '%q%%';", find);
+ if (count != 1) {
+ return count;
+ }
+ if (dest) {
+ found = zpm_db_string(zpm, "select hash from files where hash like '%s%%' limit 1;", find);
+ if (find) {
+ strcpy(dest, found);
+ free(found);
+ } else {
+ count = 0;
+ }
+ }
+ return count;
+
+}
+