gint xmms_medialib_session_property_set (xmms_medialib_session_t *session, xmms_medialib_entry_t entry, const gchar *key, const s4_val_t *value, const gchar *source) { const gchar *sources[2] = { source, NULL }; const s4_result_t *res; s4_condition_t *cond; s4_fetchspec_t *spec; s4_resultset_t *set; s4_sourcepref_t *sp; s4_val_t *song_id; gint result; GHashTable *events; song_id = s4_val_new_int (entry); sp = s4_sourcepref_create (sources); cond = s4_cond_new_filter (S4_FILTER_EQUAL, "song_id", song_id, sp, S4_CMP_CASELESS, S4_COND_PARENT); spec = s4_fetchspec_create (); s4_fetchspec_add (spec, key, sp, S4_FETCH_DATA); set = s4_query (session->trans, spec, cond); s4_cond_free (cond); s4_fetchspec_free (spec); res = s4_resultset_get_result (set, 0, 0); if (res != NULL) { const s4_val_t *old_value = s4_result_get_val (res); s4_del (session->trans, "song_id", song_id, key, old_value, source); } s4_resultset_free (set); s4_sourcepref_unref (sp); result = s4_add (session->trans, "song_id", song_id, key, value, source); s4_val_free (song_id); if (strcmp (key, XMMS_MEDIALIB_ENTRY_PROPERTY_URL) == 0) { events = xmms_medialib_session_get_table (&session->added); } else { events = xmms_medialib_session_get_table (&session->updated); } g_hash_table_insert (events, GINT_TO_POINTER (entry), GINT_TO_POINTER (entry)); return result; }
static s4_resultset_t * not_resolved_set (xmms_medialib_session_t *session) { s4_condition_t *cond1, *cond2, *cond; s4_sourcepref_t *sourcepref; s4_fetchspec_t *spec; s4_resultset_t *ret; s4_val_t *v1, *v2; sourcepref = xmms_medialib_session_get_source_preferences (session); v1 = s4_val_new_int (XMMS_MEDIALIB_ENTRY_STATUS_NEW); v2 = s4_val_new_int (XMMS_MEDIALIB_ENTRY_STATUS_REHASH); cond1 = s4_cond_new_filter (S4_FILTER_EQUAL, XMMS_MEDIALIB_ENTRY_PROPERTY_STATUS, v1, sourcepref, S4_CMP_CASELESS, 0); cond2 = s4_cond_new_filter (S4_FILTER_EQUAL, XMMS_MEDIALIB_ENTRY_PROPERTY_STATUS, v2, sourcepref, S4_CMP_CASELESS, 0); cond = s4_cond_new_combiner (S4_COMBINE_OR); s4_cond_add_operand (cond, cond1); s4_cond_add_operand (cond, cond2); spec = s4_fetchspec_create (); s4_fetchspec_add (spec, "song_id", sourcepref, S4_FETCH_PARENT); ret = xmms_medialib_session_query (session, spec, cond); s4_sourcepref_unref (sourcepref); s4_fetchspec_free (spec); s4_cond_free (cond); s4_cond_free (cond1); s4_cond_free (cond2); s4_val_free (v1); s4_val_free (v2); return ret; }
static void check_db (struct db_struct *db) { int i, j; s4_fetchspec_t *fs = s4_fetchspec_create (); s4_fetchspec_add (fs, NULL, NULL, S4_FETCH_DATA); for (i = 0; db[i].name != NULL; i++) { s4_val_t *name_val = s4_val_new_string (db[i].name); s4_condition_t *cond = s4_cond_new_filter (S4_FILTER_EQUAL, "entry", name_val, NULL, S4_CMP_CASELESS, S4_COND_PARENT); s4_transaction_t *trans = s4_begin (s4, 0); s4_resultset_t *set = s4_query (trans, fs, cond); s4_commit (trans); const s4_result_t *res = s4_resultset_get_result (set, 0, 0); int found[ARG_SIZE] = {0}; for (; res != NULL; res = s4_result_next (res)) { for (j = 0; db[i].args[j] != NULL; j++) { const char *str; if (s4_val_get_str (s4_result_get_val (res), &str) && !strcmp (str, db[i].args[j]) && !strcmp (s4_result_get_key (res), "property") && !strcmp (s4_result_get_src (res), db[i].src)) { found[j] = 1; break; } } } for (j = 0; db[i].args[j] != NULL; j++) { CU_ASSERT_EQUAL (found[j], 1); } s4_resultset_free (set); s4_cond_free (cond); s4_val_free (name_val); } s4_fetchspec_free (fs); }
static s4_resultset_t * xmms_medialib_filter (xmms_medialib_session_t *session, const gchar *filter_key, const s4_val_t *filter_val, gint filter_flags, s4_sourcepref_t *sourcepref, const gchar *fetch_key, gint fetch_flags) { s4_condition_t *cond; s4_fetchspec_t *spec; s4_resultset_t *ret; cond = s4_cond_new_filter (S4_FILTER_EQUAL, filter_key, filter_val, sourcepref, S4_CMP_CASELESS, filter_flags); spec = s4_fetchspec_create (); s4_fetchspec_add (spec, fetch_key, sourcepref, fetch_flags); ret = xmms_medialib_session_query (session, spec, cond); s4_cond_free (cond); s4_fetchspec_free (spec); return ret; }