1 #define _POSIX_C_SOURCE 200809L
11 void zpm_note_ack(struct zpm *zpm, int64_t note) {
12 char *in = "update notes set ack = 1 where id = %" PRId64;
13 zpm_db_run(zpm, in, note);
16 void zpm_note_unack(struct zpm *zpm, int64_t note) {
17 char *in = "update notes set ack = 0 where id = %" PRId64;
18 zpm_db_run(zpm, in, note);
21 void zpm_note_del(struct zpm *zpm, int64_t note) {
22 char *in = "delete from notes where id = %" PRId64;
23 zpm_db_run(zpm, in, note);
26 static char *colstring(sqlite3_stmt *s, int col) {
30 val = (const char *)sqlite3_column_text(s, col);
37 /* normally unacked only */
40 * 0x4 = suppress unack, implies 0x2
42 /* TODO filter on pkgid/path/hash if not null */
43 int64_t zpm_note(struct zpm *zpm, struct zpm_note *n, unsigned int flags) {
44 char *op = "=", *ack = " and ack = 0";
55 } else if (flags & 0x2) {
59 st = zpm_dbquery(zpm, "select id,ts,note,pkgid,path,file,ack "
60 "from notes where id %s %" PRId64 "%s %s",
63 switch (sqlite3_step(st)) {
64 case SQLITE_DONE: /* not found */
67 n->note = colstring(st, 2);
68 n->pkgid = colstring(st, 3);
69 n->path = colstring(st, 4);
70 n->file = colstring(st, 5);
71 n->ack = sqlite3_column_int(st, 6);
72 n->ts = sqlite3_column_int(st, 1);
73 n->id = sqlite3_column_int64(st, 0);
76 default: zpm->error = 1;
77 zpm->errmsg = strdup(sqlite3_errmsg(zpm->db));
85 void zpm_note_free(struct zpm_note *n) {
92 int zpm_notes_available(struct zpm *zpm, int flags) {
97 sql = "select count(*) from notes where ack = 0";
99 sql = "select count(*) from notes";
102 total = zpm_db_int(zpm, sql);
106 /* get up to n notes following. return total number of notes found */
107 /* set the first note id to the id before the first one you want
108 * or to 0 to start at the beginning. This can then
109 * be iterated up to n notes at a time by setting the id of the
110 * first one to the id found in the last one.
112 int zpm_notes(struct zpm *zpm, int n, struct zpm_note *note) {
116 for (i = 0; i < n; i++) {
117 id = zpm_note(zpm, note, 1);
130 int64_t zpm_note_next(struct zpm *zpm, struct zpm_note *n) {
131 return zpm_note(zpm, n, 1);
134 int64_t zpm_note_add(struct zpm *zpm, char *pkgid, char *path, char *filehash,
135 char *notefmt, ...) {
140 char *in = "insert into notes (note,pkgid,path,file) values (?,?,?,?);";
146 st = zpm_dbquery(zpm, in);
150 zpm->errmsg = strdup(sqlite3_errmsg(zpm->db));
154 va_start(ap, notefmt);
155 note = sqlite3_vmprintf(notefmt, ap);
160 zpm_seterror(zpm, "can't alloc");
163 sqlite3_bind_text(st, 1, note, -1, SQLITE_STATIC);
164 sqlite3_bind_text(st, 2, pkgid, -1, SQLITE_STATIC);
165 sqlite3_bind_text(st, 3, path, -1, SQLITE_STATIC);
166 sqlite3_bind_text(st, 4, filehash, -1, SQLITE_STATIC);
168 switch (sqlite3_step(st)) {
170 id = sqlite3_last_insert_rowid(zpm->db);
172 default: zpm->error = 1;
173 zpm->errmsg = strdup(sqlite3_errmsg(zpm->db));
177 sqlite3_finalize(st);