+static gint
+query_read_events (RTComEl *el, const gchar *service)
+{
+ sqlite3 *db;
+ sqlite3_stmt *stmt;
+ int ret;
+ gint count = -1;
+
+ g_object_get (el, "db", &db, NULL);
+
+ if (sqlite3_prepare_v2 (db,
+ "SELECT SUM(total_events) FROM GroupCache, Services "
+ "WHERE GroupCache.service_id=Services.id AND Services.name=?;",
+ -1,
+ &stmt,
+ NULL) != SQLITE_OK) {
+ g_error ("%s: can't compile SQL", G_STRFUNC);
+ return -1;
+ }
+ if (sqlite3_bind_text (stmt, 1, service, -1, SQLITE_STATIC) != SQLITE_OK) {
+ g_error ("Failed to bind %s to SQL stmt", service);
+ goto DONE;
+ }
+
+ while (SQLITE_BUSY == (ret = sqlite3_step (stmt)));
+
+ if (ret == SQLITE_ROW) {
+ count = sqlite3_column_int (stmt, 0);
+ }
+ else {
+ g_error ("%s: error while executing SQL", G_STRFUNC);
+ }
+
+ DONE:
+ sqlite3_finalize (stmt);
+
+ return count;
+}
+