return value;
}
+static int get_many_ids(sqlite3 *db, char *query, size_t qlen, int *ids,
+ size_t len)
+{
+ sqlite3_stmt *stmt;
+ int r;
+ int i = 0;
+ if (!qlen)
+ qlen = strlen(query);
+ r = sqlite3_prepare_v2(db, query, qlen, &stmt, NULL);
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ if (i < len)
+ ids[i++] = sqlite3_column_int(stmt, 0);
+ }
+ sqlite3_finalize(stmt);
+ return i;
+}
+
char * get_talker_email(sqlite3 *db, int id)
{
return get_oneliner_field_by_id(db, talker_user_query, "email", id);
id);
}
+static char * talk_title_query = "select %s from events_talk where id = %d;";
+char * get_talk_title(sqlite3 *db, int id)
+{
+ return get_oneliner_field_by_id(db, talk_title_query, "title", id);
+}
+static char *talk_talkers_query = "select speaker_id from "
+ "events_talk_speakers where talk_id = %d;";
+int get_talk_talkers(sqlite3 *db, int id, int *ids, int len)
+{
+ int r;
+ char *query;
+ size_t qlen;
+ qlen = asprintf(&query, talk_talkers_query, id);
+ r = get_many_ids(db, query, qlen, ids, len);
+ free(query);
+ return r;
+}
char * get_talker_email(sqlite3 *db, int id);
char * get_talker_name(sqlite3 *db, int id);
+char * get_talk_title(sqlite3 *db, int id);
+int get_talk_talkers(sqlite3 *db, int id, int *ids, int len);
#endif
--- /dev/null
+/*
+ * Copyright (C) 2009 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+#include "helper.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char **argv)
+{
+ sqlite3 *db;
+ char *dbname;
+ char *title;
+ char *email;
+ int talk_id;
+ int ids[16];
+ int nids;
+ int i;
+ if (argc < 3) {
+ fprintf(stderr, "<program> <db> <id>\n");
+ return 1;
+ }
+ dbname = argv[1];
+ talk_id = atoi(argv[2]);
+ sqlite3_open(dbname, &db);
+ title = get_talk_title(db, talk_id);
+ if (title) {
+ printf("Talk title is %s\n", title);
+ free(title);
+ } else {
+ fprintf(stderr, "Could not find talk\n");
+ }
+ nids = get_talk_talkers(db, talk_id, ids, 16);
+ for (i = 0; i < nids; i++) {
+ email = get_talker_email(db, ids[i]);
+ if (email) {
+ printf("Talker email is %s\n", email);
+ free(email);
+ } else {
+ fprintf(stderr, "Could not find talker\n");
+ }
+ }
+ sqlite3_close(db);
+ return 0;
+}