1 #define _POSIX_C_SOURCE 200809L
10 int zpm_foreach_script(struct zpm *zpm, char *pkgstr, char *stage, void *cbd,
11 int (*cb)(void *ud, const char *pkg, const char *stage, const char *hash)) {
17 char *find = "select printf('%%s-%%s-%%d', package, version, release) as pkgid, stage, hash from scripts where true";
18 char *pkgidwhere = " and printf('%%%%s-%%%%s-%%%%d', package, version, release) = %Q";
19 char *stagewhere = " and stage = %Q";
29 pkgid = zpm_findpkg(zpm, pkgstr, 0);
35 s = sqlite3_str_new(zpm->db);
36 sqlite3_str_appendall(s, find);
39 sqlite3_str_appendf(s, pkgidwhere, pkgid);
43 sqlite3_str_appendf(s, stagewhere, stage);
46 sql = sqlite3_str_finish(s);
55 st = zpm_dbquery(zpm, sql);
64 while ((rv = sqlite3_step(st)) == SQLITE_ROW) {
66 const char *sstage, *spkgid, *shash;
69 spkgid = (const char *)sqlite3_column_text(st, 0);
70 sstage = (const char *)sqlite3_column_text(st, 1);
71 shash = (const char *)sqlite3_column_text(st, 2);
73 cbrv = cb(cbd, spkgid, sstage, shash);
80 if (rv != SQLITE_DONE) {
93 int zpm_script_set(struct zpm *zpm, char *pkgstr, char *phase, char *hash) {
97 char *insert = "insert into scripts (package,version,release,stage,hash) values (%Q,%Q,%d,%Q,%Q) on conflict (package,version,release,stage) do update set hash = excluded.hash ";
98 char *delete = "delete from scripts where package = ? and version = ? and release = ? and stage = ?";
100 if (!zpm || !zpm->db || !phase) {
104 if (zpm_parse_package(pkgstr, package, version, &release)) {
106 zpm_db_run(zpm, insert, package, version, release, phase, hash);
108 zpm_db_run(zpm, delete, package, version, release, phase);
116 int zpm_script_hash(struct zpm *zpm, char *pkgstr, char *phase, char *hash) {
118 char *template = "select hash from scripts_pkgid where pkgid = %Q and stage = %Q";
121 pkgid = zpm_findpkg(zpm, pkgstr, NULL);
123 st = zpm_dbquery(zpm, template, pkgid, phase);
129 zpm->errmsg = strdup(sqlite3_errmsg(zpm->db));
133 switch (sqlite3_step(st)) {
135 strncpy(hash, (const char *) sqlite3_column_text(st, 0),
137 hash[ZPM_HASH_STRLEN] = 0;
139 default: zpm->error = 1; /* fall through */
140 zpm->errmsg = strdup(sqlite3_errmsg(zpm->db));
142 sqlite3_finalize(st);
143 return 0; break; /* not found */
146 sqlite3_finalize(st);