[libgda] Added new constructor for GdaDataProxy. Build fixes and test on python.



commit c0b59f9bb48fb8cba3675f1b932c5ef10c702411
Author: Daniel Espinosa <despinosa src gnome org>
Date:   Wed Feb 1 16:59:16 2012 -0600

    Added new constructor for GdaDataProxy. Build fixes and test on python.
    
    * Added symbol gda_data_proxy_new_with_data_model to be used by bindins instead
    gda_data_proxy_new not detected properly in GI before 1.31
    * Added a simple sample for dataproxy API test (new and old constructor)
    * Some build fixes for vala-extensions samples

 libgda/Gda-5.0.gir                        |   18 +++++++++++++++++-
 libgda/gda-data-proxy.c                   |   25 ++++++++++++++++++++++++-
 libgda/gda-data-proxy.h                   |    1 +
 libgda/libgda-5.0.vapi                    |    2 ++
 libgda/libgda.symbols                     |    1 +
 samples/Gir/dataproxy.py                  |   15 +++++++++++++++
 samples/vala/SampleDataModelIterable.vala |    7 ++++---
 7 files changed, 64 insertions(+), 5 deletions(-)
---
diff --git a/libgda/Gda-5.0.gir b/libgda/Gda-5.0.gir
index 47f6fdc..e71debd 100644
--- a/libgda/Gda-5.0.gir
+++ b/libgda/Gda-5.0.gir
@@ -7648,13 +7648,29 @@ still forming a valid SQL syntax).</doc>
            glib:get-type="gda_data_proxy_get_type"
            glib:type-struct="DataProxyClass">
       <implements name="DataModel"/>
+      <constructor name="new_with_data_model"
+                   c:identifier="gda_data_proxy_new_with_data_model"
+                   version="5.2.0">
+        <doc xml:whitespace="preserve">Creates a new proxy for @model. This is the preferred method to create 
+#GdaDataProxy objects by bindings.</doc>
+        <return-value transfer-ownership="full">
+          <doc xml:whitespace="preserve">a new #GdaDataProxy object</doc>
+          <type name="DataProxy" c:type="GdaDataProxy*"/>
+        </return-value>
+        <parameters>
+          <parameter name="model" transfer-ownership="none">
+            <doc xml:whitespace="preserve">Data model to be proxied</doc>
+            <type name="DataModel" c:type="GdaDataModel*"/>
+          </parameter>
+        </parameters>
+      </constructor>
       <function name="error_quark" c:identifier="gda_data_proxy_error_quark">
         <return-value transfer-ownership="none">
           <type name="GLib.Quark" c:type="GQuark"/>
         </return-value>
       </function>
       <function name="new" c:identifier="gda_data_proxy_new">
-        <doc xml:whitespace="preserve">Creates a new proxy for @model</doc>
+        <doc xml:whitespace="preserve">Creates a new proxy for @model. For bindings use @gda_data_proxy_new_with_data_model.</doc>
         <return-value transfer-ownership="full">
           <doc xml:whitespace="preserve">a new #GdaDataProxy object</doc>
           <type name="GObject.Object" c:type="GObject*"/>
diff --git a/libgda/gda-data-proxy.c b/libgda/gda-data-proxy.c
index 459b144..1ba946a 100644
--- a/libgda/gda-data-proxy.c
+++ b/libgda/gda-data-proxy.c
@@ -767,7 +767,7 @@ static void proxied_model_access_changed_cb (GdaDataModel *model, GdaDataProxy *
  * gda_data_proxy_new:
  * @model: (transfer none): Data model to be proxied
  *
- * Creates a new proxy for @model
+ * Creates a new proxy for @model. For bindings use @gda_data_proxy_new_with_data_model. 
  *
  * Returns: (transfer full): a new #GdaDataProxy object
  */
@@ -783,6 +783,29 @@ gda_data_proxy_new (GdaDataModel *model)
 	return obj;
 }
 
+/**
+ * gda_data_proxy_new_with_data_model:
+ * @model: (transfer none): Data model to be proxied
+ *
+ * Creates a new proxy for @model. This is the preferred method to create 
+ * #GdaDataProxy objects by bindings.
+ *
+ * Returns: (transfer full): a new #GdaDataProxy object
+ *
+ * Since: 5.2.0
+ */
+GdaDataProxy*
+gda_data_proxy_new_with_data_model (GdaDataModel *model)
+{
+	GObject *obj;
+
+	g_return_val_if_fail (model && GDA_IS_DATA_MODEL (model), NULL);
+
+	obj = g_object_new (GDA_TYPE_DATA_PROXY, "model", model, NULL);
+
+	return (GdaDataProxy*) obj;
+}
+
 static void
 clean_proxy (GdaDataProxy *proxy)
 {
diff --git a/libgda/gda-data-proxy.h b/libgda/gda-data-proxy.h
index de7ffd6..eff0d2e 100644
--- a/libgda/gda-data-proxy.h
+++ b/libgda/gda-data-proxy.h
@@ -182,6 +182,7 @@ struct _GdaDataProxyClass
 
 GType             gda_data_proxy_get_type                 (void) G_GNUC_CONST;
 GObject          *gda_data_proxy_new                      (GdaDataModel *model);
+GdaDataProxy     *gda_data_proxy_new_with_data_model      (GdaDataModel *model);
 
 GdaDataModel     *gda_data_proxy_get_proxied_model        (GdaDataProxy *proxy);
 gint              gda_data_proxy_get_proxied_model_n_cols (GdaDataProxy *proxy);
diff --git a/libgda/libgda-5.0.vapi b/libgda/libgda-5.0.vapi
index fc60ff8..d3fd7b4 100644
--- a/libgda/libgda-5.0.vapi
+++ b/libgda/libgda-5.0.vapi
@@ -365,6 +365,8 @@ namespace Gda {
 		public void set_sample_size (int sample_size);
 		public void set_sample_start (int sample_start);
 		public void undelete (int proxy_row);
+		[CCode (has_construct_function = false)]
+		public DataProxy.with_data_model (Gda.DataModel model);
 		[NoAccessorMethod]
 		public bool defer_sync { get; set; }
 		[NoAccessorMethod]
diff --git a/libgda/libgda.symbols b/libgda/libgda.symbols
index ef8a696..0b4b2eb 100644
--- a/libgda/libgda.symbols
+++ b/libgda/libgda.symbols
@@ -317,6 +317,7 @@
 	gda_data_proxy_has_changed
 	gda_data_proxy_is_read_only
 	gda_data_proxy_new
+	gda_data_proxy_new_with_data_model
 	gda_data_proxy_row_has_changed
 	gda_data_proxy_row_is_deleted
 	gda_data_proxy_row_is_inserted
diff --git a/samples/Gir/dataproxy.py b/samples/Gir/dataproxy.py
new file mode 100644
index 0000000..1d6e187
--- /dev/null
+++ b/samples/Gir/dataproxy.py
@@ -0,0 +1,15 @@
+#! python
+from gi.repository import GLib, Gda
+GLib.unlink ("dataproxy.db")
+c = Gda.Connection.open_from_string("SQLite", "DB_DIR=.;DB_NAME=dataproxy", None, Gda.ConnectionOptions.NONE)
+c.execute_non_select_command("CREATE TABLE user (name string PRIMARY KEY, functions string, security_number integer)")
+c.execute_non_select_command("INSERT INTO user (name, functions, security_number) VALUES ( \"Martin Stewart\", \"Programmer, QA\", 2334556)")
+m = c.execute_select_command ("SELECT * FROM user")
+print m.dump_as_string()
+print "Tesing old API for Gda.DataProxy"
+pxy1 = Gda.DataProxy.new (m)
+print pxy1.dump_as_string ()
+print "Tesing new (5.2) API for Gda.DataProxy"
+pxy2 = Gda.DataProxy.new_with_data_model (m)
+print pxy2.dump_as_string ()
+
diff --git a/samples/vala/SampleDataModelIterable.vala b/samples/vala/SampleDataModelIterable.vala
index 5bb508e..3ddfc34 100644
--- a/samples/vala/SampleDataModelIterable.vala
+++ b/samples/vala/SampleDataModelIterable.vala
@@ -52,14 +52,15 @@ namespace Sample {
 			t.connection = connection;
 			t.name = "user";
 			this.itermodel = new RecordCollection (model, t);
-
+			var pxy = new DataProxy.with_data_model (model);
+			stdout.printf(pxy.dump_as_string ());
 		}
 		
 		public void iterating ()
 			throws Error
 		{
 			stdout.printf ("Iterating over all Records in DataModel using foreach\n");
-			foreach (DbRecord<Value?> r in itermodel) {
+			foreach (DbRecord r in itermodel) {
 				stdout.printf (r.to_string ());
 			}
 			stdout.printf ("\nIterating over all Records in DataModel using a Gee.Iterator\n");
@@ -94,7 +95,7 @@ namespace Sample {
 			var iter = itermodel.filter (
 			(g) => {
 				bool ret = false;
-				foreach (DbField<Value?> fl in g.fields) {
+				foreach (DbField fl in g.fields) {
 					string t = Gda.value_stringify (fl.value);
 					stdout.printf ("Value to check: " + t);
 					if (t.contains ("x")) {



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