gboolean journal_store_scan(JournalStore *js, JournalStoreScanCallback scan_cb, const gpointer scan_data, JournalStoreSummaryCallback cb_func, const gpointer cb_data) { int ret; sqlite3_stmt *stmt = NULL; int matchcount = 0; SQLCHECK(sqlite3_prepare(js->db, "SELECT itemid, timestamp, subject, event, security " "FROM entry ORDER BY itemid ASC", -1, &stmt, NULL)); ret = sqlite3_step(stmt); while (ret == SQLITE_ROW) { int itemid = sqlite3_column_int(stmt, 0); time_t timestamp = sqlite3_column_int(stmt, 1); const char *subject = (char*)sqlite3_column_text(stmt, 2); const char *event = (char*)sqlite3_column_text(stmt, 3); LJSecurity sec = {0}; if (sqlite3_column_type(stmt, 4) != SQLITE_NULL) security_from_int(&sec, sqlite3_column_int(stmt, 4)); if (scan_cb(subject, scan_data) || scan_cb(event, scan_data)) { const char *summary = lj_get_summary(subject, event); cb_func(itemid, timestamp, summary, &sec, cb_data); if (++matchcount == MAX_MATCHES) break; } ret = sqlite3_step(stmt); } if (ret != SQLITE_ROW && ret != SQLITE_DONE) { SQLCHECK(ret); SQLCHECK(sqlite3_finalize(stmt)); return FALSE; } SQLCHECK(sqlite3_finalize(stmt)); return TRUE; }
gboolean journal_store_get_day_entries(JournalStore *js, int year, int mon, int day, JournalStoreSummaryCallback cb_func, gpointer cb_data) { int ret; sqlite3_stmt *stmt = NULL; const char *subject; const char *event; LJSecurity sec = {0}; SQLCHECK(sqlite3_prepare(js->db, "SELECT itemid, timestamp, subject, event " "FROM entry WHERE year=?1 AND month=?2 AND day=?3", -1, &stmt, NULL)); SQLCHECK(sqlite3_bind_int(stmt, 1, year)); SQLCHECK(sqlite3_bind_int(stmt, 2, mon)); SQLCHECK(sqlite3_bind_int(stmt, 3, day)); ret = sqlite3_step(stmt); while (ret == SQLITE_ROW) { int itemid = sqlite3_column_int(stmt, 0); time_t timestamp = sqlite3_column_int(stmt, 1); subject = (char*)sqlite3_column_text(stmt, 2); event = (char*)sqlite3_column_text(stmt, 3); cb_func(itemid, timestamp, lj_get_summary(subject, event), &sec /* XXX */, cb_data); ret = sqlite3_step(stmt); } if (ret != SQLITE_DONE) { SQLCHECK(ret); SQLCHECK(sqlite3_finalize(stmt)); return FALSE; } SQLCHECK(sqlite3_finalize(stmt)); return TRUE; }
const char* lj_entry_make_summary(LJEntry *entry) { return lj_get_summary(entry->subject, entry->event); }