]> pd.if.org Git - zpackage/blob - lib/script_hash.c
remove foreign key from elf tables
[zpackage] / lib / script_hash.c
1 #define _POSIX_C_SOURCE 200809L
2
3 #include <stdarg.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 #include "sqlite3.h"
8 #include "zpm.h"
9
10 int zpm_script_hash(struct zpm *zpm, char *pkgstr, char *phase, char *hash) {
11         char *pkgid = 0;
12         char *template = "select hash from scripts_pkgid where pkgid = %Q and stage = %Q";
13         sqlite3_stmt *st;
14
15         pkgid = zpm_findpkg(zpm, pkgstr);
16
17         st = zpm_dbquery(zpm, template, pkgid, phase);
18
19         free(pkgid);
20
21         if (!st) {
22                 zpm->error = 1;
23                 zpm->errmsg = strdup(sqlite3_errmsg(zpm->db));
24                 return 0;
25         }
26
27         switch (sqlite3_step(st)) {
28                 case SQLITE_ROW:
29                         strncpy(hash, (const char *) sqlite3_column_text(st, 0),
30                                         ZPM_HASH_STRLEN);
31                         hash[ZPM_HASH_STRLEN] = 0;
32                         break;
33                 default: zpm->error = 1; /* fall through */
34                          zpm->errmsg = strdup(sqlite3_errmsg(zpm->db));
35                 case SQLITE_DONE:
36                         sqlite3_finalize(st);
37                         return 0; break; /* not found */
38         }
39
40         sqlite3_finalize(st);
41         return 1;
42 }