39 static void dbwrite_operator (
void *key,
void *value,
void *udata);
40 static void dbwrite_coll_attributes (
const char *key,
xmmsv_t *value,
void *udata);
41 static void dbwrite_strip_tmpprops (
void *key,
void *value,
void *udata);
43 static gint value_get_dict_int (
xmmsv_t *val,
const gchar *key);
44 static const gchar *value_get_dict_string (
xmmsv_t *val,
const gchar *key);
68 coll_dbwrite_t dbinfos = { session, 1, 0 };
75 dbwrite_strip_tmpprops, NULL);
97 query =
"SELECT op.id AS id, lbl.name AS label, " 98 " lbl.namespace AS nsid, op.type AS type " 99 "FROM CollectionOperators AS op, CollectionLabels as lbl " 100 "WHERE op.id=lbl.collid " 111 id = value_get_dict_int (cmdval,
"id");
112 type = value_get_dict_int (cmdval,
"type");
113 nsid = value_get_dict_int (cmdval,
"nsid");
114 label = value_get_dict_string (cmdval,
"label");
117 if (previd < 0 ||
id != previd) {
118 coll = xmms_collection_dbread_operator (session,
id, type);
128 res = g_list_delete_link (res, res);
161 g_snprintf (query,
sizeof (query),
162 "SELECT attr.key AS key, attr.value AS value " 163 "FROM CollectionOperators AS op, CollectionAttributes AS attr " 164 "WHERE op.id=%d AND attr.collid=op.id",
id);
167 for (n = res; n; n = n->next) {
168 const gchar *key, *value;
171 key = value_get_dict_string (cmdval,
"key");
172 value = value_get_dict_string (cmdval,
"value");
180 g_snprintf (query,
sizeof (query),
181 "SELECT idl.mid AS mid " 182 "FROM CollectionOperators AS op, CollectionIdlists AS idl " 183 "WHERE op.id=%d AND idl.collid=op.id " 184 "ORDER BY idl.position",
id);
187 for (n = res; n; n = n->next) {
197 g_snprintf (query,
sizeof (query),
198 "SELECT op.id AS id, op.type AS type " 199 "FROM CollectionOperators AS op, CollectionConnections AS conn " 200 "WHERE conn.to_id=%d AND conn.from_id=op.id",
id);
203 for (n = res; n; n = n->next) {
208 _id = value_get_dict_int (cmdval,
"id");
209 type = value_get_dict_int (cmdval,
"type");
211 op = xmms_collection_dbread_operator (session, _id, type);
240 coll_dbwrite_t dbwrite_infos = { session, collid, 0 };
243 g_snprintf (query,
sizeof (query),
244 "INSERT INTO CollectionOperators VALUES(%d, %d)",
261 g_snprintf (query,
sizeof (query),
262 "INSERT INTO CollectionIdlists VALUES(%d, %d, %d)",
284 nextid = xmms_collection_dbwrite_operator (session, newid, op);
285 g_snprintf (query,
sizeof (query),
286 "INSERT INTO CollectionConnections VALUES(%d, %d)",
301 dbwrite_operator (
void *key,
void *value,
void *udata)
306 coll_dbwrite_t *dbinfos = udata;
312 serial_id = dbinfos->collid;
313 dbinfos->collid = xmms_collection_dbwrite_operator (dbinfos->session,
314 dbinfos->collid, coll);
319 query = g_strdup_printf (
"INSERT INTO CollectionLabels VALUES(%d, %d, %s)",
320 serial_id, dbinfos->nsid, esc_label);
329 dbwrite_coll_attributes (
const char *key,
xmmsv_t *value,
void *udata)
332 coll_dbwrite_t *dbwrite_infos = udata;
339 g_return_if_fail (r);
343 query = g_strdup_printf (
"INSERT INTO CollectionAttributes VALUES(%d, %s, %s)",
344 dbwrite_infos->collid, esc_key, esc_val);
354 dbwrite_strip_tmpprops (
void *key,
void *value,
void *udata)
363 value_get_dict_int (
xmmsv_t *val,
const gchar *key)
372 value_get_dict_string (
xmmsv_t *val,
const gchar *key)
void xmmsv_list_iter_first(xmmsv_list_iter_t *it)
Rewind the iterator to the start of the list.
struct xmmsv_list_iter_St xmmsv_list_iter_t
void xmmsv_unref(xmmsv_t *val)
Decreases the references for the xmmsv_t When the number of references reaches 0 it will be freed...
void bind_all_references(xmms_coll_dag_t *dag, xmmsv_coll_t *coll, xmmsv_coll_t *parent, void *udata)
If a reference, add the operator of the pointed collection as an operand.
int xmmsv_coll_idlist_append(xmmsv_coll_t *coll, int id)
Append a value to the idlist.
void xmmsv_coll_attribute_set(xmmsv_coll_t *coll, const char *key, const char *value)
Set an attribute in the given collection.
xmmsv_coll_t * xmmsv_coll_ref(xmmsv_coll_t *coll)
Increases the references for the xmmsv_coll_t.
int xmmsv_coll_attribute_remove(xmmsv_coll_t *coll, const char *key)
Remove an attribute from the given collection.
int xmmsv_get_list_iter(const xmmsv_t *val, xmmsv_list_iter_t **it)
Retrieves a list iterator from a list xmmsv_t.
struct xmmsv_St * xmmsv_coll_operands_get(xmmsv_coll_t *coll)
gboolean xmms_collection_get_int_attr(xmmsv_coll_t *coll, const gchar *attrname, gint *val)
Extract an attribute from a collection as an integer.
int xmmsv_dict_foreach(xmmsv_t *dictv, xmmsv_dict_foreach_func func, void *user_data)
Apply a function to each key-element pair in the list.
struct xmmsv_St * xmmsv_coll_idlist_get(xmmsv_coll_t *coll)
Return the list of ids stored in the collection.
xmms_collection_namespace_id_t
void xmmsv_list_iter_next(xmmsv_list_iter_t *it)
Advance the iterator to the next element in the list.
int xmmsv_dict_entry_get_int(xmmsv_t *val, const char *key, int32_t *r)
void xmmsv_list_iter_explicit_destroy(xmmsv_list_iter_t *it)
Explicitly free list iterator.
struct xmmsv_coll_St xmmsv_coll_t
void xmms_collection_apply_to_all_collections(xmms_coll_dag_t *dag, FuncApplyToColl f, void *udata)
Apply a function of type FuncApplyToColl to all the collections in all namespaces.
void xmms_collection_dag_save(xmms_coll_dag_t *dag)
Save the collection DAG in the database.
int xmmsv_dict_entry_get_string(xmmsv_t *val, const char *key, const char **r)
#define XMMS_COLLSERIAL_ATTR_ID
gchar * sqlite_prepare_string(const gchar *input)
xmmsv_coll_t * xmmsv_coll_new(xmmsv_coll_type_t type)
Allocate a new collection of the given type.
struct xmmsv_St * xmmsv_coll_attributes_get(xmmsv_coll_t *coll)
gboolean xmms_collection_set_int_attr(xmmsv_coll_t *coll, const gchar *attrname, gint newval)
Set the attribute of a collection as an integer.
void xmmsv_coll_add_operand(xmmsv_coll_t *coll, xmmsv_coll_t *op)
Add the operand to the given collection.
void xmms_collection_dag_replace(xmms_coll_dag_t *dag, xmms_collection_namespace_id_t nsid, gchar *key, xmmsv_coll_t *newcoll)
Update the DAG to update the value of the pair with the given key.
#define XMMS_COLLECTION_NUM_NAMESPACES
void xmms_collection_dag_restore(xmms_coll_dag_t *dag)
Restore the collection DAG from the database.
int xmmsv_list_iter_valid(xmmsv_list_iter_t *it)
Check whether the iterator is valid and points to a valid element.
int xmmsv_get_string(const xmmsv_t *val, const char **r)
Retrieves a string from the value.
void xmms_collection_foreach_in_namespace(xmms_coll_dag_t *dag, guint nsid, GHFunc f, void *udata)
Apply a function to all the collections in a given namespace.
int xmmsv_list_iter_entry(xmmsv_list_iter_t *it, xmmsv_t **val)
Get the element currently pointed at by the iterator.
int xmmsv_list_iter_entry_int(xmmsv_list_iter_t *it, int32_t *val)
xmmsv_coll_type_t xmmsv_coll_get_type(xmmsv_coll_t *coll)
Return the type of the collection.
int xmmsv_get_coll(const xmmsv_t *val, xmmsv_coll_t **coll)
Retrieves a collection from the value.
struct xmms_coll_dag_St xmms_coll_dag_t
void xmmsv_coll_unref(xmmsv_coll_t *coll)
Decreases the references for the xmmsv_coll_t When the number of references reaches 0 it will be free...