+/*
+ * 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.
+ */
+
+/*
+ * Somer helper functions to get some fields from the sqlite database.
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sqlite3.h>
+
+static char * talker_email_query = "select email from auth_user,"
+ "events_speaker where auth_user.id = events_speaker.user_id "
+ "and events_speaker.id = %d;";
+static char * talker_name_query = "select first_name from auth_user,"
+ "events_speaker where auth_user.id = events_speaker.user_id "
+ "and events_speaker.id = %d;";
+
+static char * get_talker_userfield(sqlite3 *db, char *query, int id)
+{
+ sqlite3_stmt *stmt;
+ char * s;
+ int r;
+ char *email = NULL;
+ r = asprintf(&s, query, id);
+ r = sqlite3_prepare_v2(db, s, r, &stmt, NULL);
+ free(s);
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ if (email)
+ free(email);
+ email = strdup(sqlite3_column_text(stmt, 0));
+ }
+ sqlite3_finalize(stmt);
+ return email;
+}
+
+char * get_talker_email(sqlite3 *db, int id)
+{
+ return get_talker_userfield(db, talker_email_query, id);
+}
+
+char * get_talker_name(sqlite3 *db, int id)
+{
+ return get_talker_userfield(db, talker_name_query, id);
+}
+
+