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 = colstring(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) {
91 n->note = n->ts = n->pkgid = n->path = n->file = 0;
94 int zpm_notes_available(struct zpm *zpm, int flags) {
99 sql = "select count(*) from notes where ack = 0";
101 sql = "select count(*) from notes";
104 total = zpm_db_int(zpm, sql);
108 /* get up to n notes following. return total number of notes found */
109 /* set the first note id to the id before the first one you want
110 * or to 0 to start at the beginning. This can then
111 * be iterated up to n notes at a time by setting the id of the
112 * first one to the id found in the last one.
114 int zpm_notes(struct zpm *zpm, int n, struct zpm_note *note) {
118 for (i = 0; i < n; i++) {
119 id = zpm_note(zpm, note, 1);
132 int64_t zpm_note_next(struct zpm *zpm, struct zpm_note *n) {
133 return zpm_note(zpm, n, 1);
136 int64_t zpm_note_add(struct zpm *zpm, char *pkgid, char *path, char *filehash,
137 char *notefmt, ...) {
142 char *in = "insert into notes (note,pkgid,path,file) values (?,?,?,?);";
148 st = zpm_dbquery(zpm, in);
152 zpm->errmsg = strdup(sqlite3_errmsg(zpm->db));
156 va_start(ap, notefmt);
157 note = sqlite3_vmprintf(notefmt, ap);
162 zpm_seterror(zpm, "can't alloc");
165 sqlite3_bind_text(st, 1, note, -1, SQLITE_STATIC);
166 sqlite3_bind_text(st, 2, pkgid, -1, SQLITE_STATIC);
167 sqlite3_bind_text(st, 3, path, -1, SQLITE_STATIC);
168 sqlite3_bind_text(st, 4, filehash, -1, SQLITE_STATIC);
170 switch (sqlite3_step(st)) {
172 id = sqlite3_last_insert_rowid(zpm->db);
174 default: zpm->error = 1;
175 zpm->errmsg = strdup(sqlite3_errmsg(zpm->db));
179 sqlite3_finalize(st);