2 * Copyright (C) 2009 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * Somer helper functions to get some fields from the sqlite database.
29 static char * talker_user_query = "select %s from auth_user,"
30 "events_speaker where auth_user.id = events_speaker.user_id "
31 "and events_speaker.id = %d;";
33 static char * get_oneliner(sqlite3 *db, char *query, size_t qlen)
40 r = sqlite3_prepare_v2(db, query, qlen, &stmt, NULL);
41 while (sqlite3_step(stmt) == SQLITE_ROW) {
44 value = strdup(sqlite3_column_text(stmt, 0));
46 sqlite3_finalize(stmt);
50 static char * get_oneliner_field_by_id(sqlite3 *db, char *query,
56 r = asprintf(&s, query, field, id);
57 value = get_oneliner(db, s, r);
62 static int get_many_ids(sqlite3 *db, char *query, size_t qlen, int *ids,
70 r = sqlite3_prepare_v2(db, query, qlen, &stmt, NULL);
71 while (sqlite3_step(stmt) == SQLITE_ROW) {
73 ids[i++] = sqlite3_column_int(stmt, 0);
75 sqlite3_finalize(stmt);
79 char * get_talker_email(sqlite3 *db, int id)
81 return get_oneliner_field_by_id(db, talker_user_query, "email", id);
84 char * get_talker_name(sqlite3 *db, int id)
86 return get_oneliner_field_by_id(db, talker_user_query, "first_name",
90 static char * talk_title_query = "select %s from events_talk where id = %d;";
91 char * get_talk_title(sqlite3 *db, int id)
93 return get_oneliner_field_by_id(db, talk_title_query, "title", id);
96 static char *talk_talkers_query = "select speaker_id from "
97 "events_talk_speakers where talk_id = %d;";
98 int get_talk_talkers(sqlite3 *db, int id, int *ids, int len)
103 qlen = asprintf(&query, talk_talkers_query, id);
104 r = get_many_ids(db, query, qlen, ids, len);