X-Git-Url: https://pd.if.org/git/?p=zpackage;a=blobdiff_plain;f=lib%2Fdbquery.c;h=d0edecc5bff6d34014fdbd98237b411839cd68c9;hp=11131645d9b4d388c7229665515b588492a4164e;hb=06ea9ccb6a8d36c63d5f1dac4fd2430819b75a95;hpb=47b298c6557161ff7e46a778de693268cf9230cc diff --git a/lib/dbquery.c b/lib/dbquery.c index 1113164..d0edecc 100644 --- a/lib/dbquery.c +++ b/lib/dbquery.c @@ -2,6 +2,7 @@ #include #include +#include #include "sqlite3.h" #include "zpm.h" @@ -83,6 +84,27 @@ void zpm_db_run(struct zpm *zpm, char *query, ...) { 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; + +} + char *zpm_db_string(struct zpm *zpm, char *query, ...) { sqlite3_stmt *st; va_list args;