[rhythmbox] python: fix type conversion for query parameters



commit 8f88ee707578061d1122dddc4c40952fde8e9a6f
Author: Jonathan Matthew <jonathan d14n org>
Date:   Tue Jun 1 13:06:32 2010 +1000

    python: fix type conversion for query parameters
    
    Convert query parameter values to the type required for the property,
    rather than the closest GType for the python value we get.  This makes
    it possible to query on numeric parameters.  Also add binding for
    rhythmdb_query_to_string, which I used to check this was working.

 bindings/python/rhythmdb.defs     |    9 +++++++++
 bindings/python/rhythmdb.override |   16 +++++-----------
 2 files changed, 14 insertions(+), 11 deletions(-)
---
diff --git a/bindings/python/rhythmdb.defs b/bindings/python/rhythmdb.defs
index cdb7f46..27b5dfd 100644
--- a/bindings/python/rhythmdb.defs
+++ b/bindings/python/rhythmdb.defs
@@ -313,6 +313,15 @@
   )
 )
 
+(define-method query_to_string
+  (of-object "RhythmDB")
+  (c-name "rhythmdb_query_to_string")
+  (return-type "char*")
+  (parameters
+    '("RhythmDBQuery*" "query")
+  )
+)
+
 (define-method entry_get
   (of-object "RhythmDB")
   (c-name "rhythmdb_entry_get")
diff --git a/bindings/python/rhythmdb.override b/bindings/python/rhythmdb.override
index d0e624b..c4c8130 100644
--- a/bindings/python/rhythmdb.override
+++ b/bindings/python/rhythmdb.override
@@ -1057,7 +1057,7 @@ _wrap_rhythmdb_query_append (PyGObject *self, PyObject *args, PyObject *kwargs)
 				return NULL;
 			}
 			Py_DECREF (py_type);
-	
+
 			/* Check that there are enough elements left. */
 			switch (type) {
 			case RHYTHMDB_QUERY_END:
@@ -1100,8 +1100,9 @@ _wrap_rhythmdb_query_append (PyGObject *self, PyObject *args, PyObject *kwargs)
 					return NULL;
 				}
 				Py_DECREF (obj);
-	
+
 				obj = PySequence_GetItem (criteria, index+2);
+				g_value_init (&value, rhythmdb_get_property_type (RHYTHMDB_RHYTHMDB(self->obj), propid));
 				if (propid == RHYTHMDB_PROP_TYPE) {
 					RhythmDBEntryType et;
 					if (pyg_boxed_check(obj, RHYTHMDB_TYPE_ENTRY_TYPE)) {
@@ -1113,15 +1114,8 @@ _wrap_rhythmdb_query_append (PyGObject *self, PyObject *args, PyObject *kwargs)
 						g_free (s);
 						return NULL;
 					}
-					g_value_init (&value, rhythmdb_get_property_type (RHYTHMDB_RHYTHMDB(self->obj), propid));
 					g_value_set_pointer (&value, et);
 				} else {
-					gtype = pyg_type_from_object ((PyObject *)obj->ob_type);
-					if (!gtype) {
-						PyErr_SetString (PyExc_TypeError, "can't map metadata to GType system");
-						return NULL;
-					}
-					g_value_init (&value, gtype);
 					if (pyg_value_from_pyobject  (&value, obj) < 0) {
 						Py_XDECREF (obj);
 						g_value_unset (&value);
@@ -1132,7 +1126,7 @@ _wrap_rhythmdb_query_append (PyGObject *self, PyObject *args, PyObject *kwargs)
 				Py_DECREF (obj);
 				break;
 			}
-	
+
 			rhythmdb_query_append_params (RHYTHMDB_RHYTHMDB (self->obj), query, type, propid, &value);
 			if (G_IS_VALUE (&value))
 				g_value_unset (&value);
@@ -1141,7 +1135,7 @@ _wrap_rhythmdb_query_append (PyGObject *self, PyObject *args, PyObject *kwargs)
 			remaining = remaining - increment;
 		} /* End criteria loop */
 	} /* End args loop */
-	
+
 	Py_RETURN_NONE;
 }
 %%



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]