コード例 #1
0
ファイル: medialib_session.c プロジェクト: chrippa/xmms2
s4_resultset_t *
xmms_medialib_session_query (xmms_medialib_session_t *session,
                             s4_fetchspec_t *specification,
                             s4_condition_t *condition)
{
	return s4_query (session->trans, specification, condition);
}
コード例 #2
0
ファイル: medialib_session.c プロジェクト: chrippa/xmms2
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;
}
コード例 #3
0
ファイル: t_s4.c プロジェクト: xmms2/s4
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);
}