[libgda] Hinding GDA's GValue API to Vala bindings * Including a gda_value_new_from_string version for Vala b
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Hinding GDA's GValue API to Vala bindings * Including a gda_value_new_from_string version for Vala b
- Date: Thu, 2 Feb 2012 22:43:36 +0000 (UTC)
commit 91898cf4fce5332ba1570b3583e0db56ccf55341
Author: Daniel Espinosa <despinosa src gnome org>
Date: Thu Feb 2 16:39:59 2012 -0600
Hinding GDA's GValue API to Vala bindings
* Including a gda_value_new_from_string version for Vala bindings as
GdaData.DbField.value_from_string
libgda/Gda-5.0.metadata | 13 +++++++++-
libgda/data/DbField.vala | 38 +++++++++++++++++++++++++++++
libgda/data/GdaData-5.0.gir | 13 ++++++++++
libgda/data/Table.vala | 2 +-
libgda/libgda-5.0.vapi | 20 ---------------
samples/vala/SampleDataModelIterable.vala | 2 -
6 files changed, 64 insertions(+), 24 deletions(-)
---
diff --git a/libgda/Gda-5.0.metadata b/libgda/Gda-5.0.metadata
index d46ad56..1ab4b2d 100644
--- a/libgda/Gda-5.0.metadata
+++ b/libgda/Gda-5.0.metadata
@@ -6,7 +6,6 @@ Set.new_from_spec_node.xml_spec type="Xml.Node*"
DataModel.add_data_from_xml_node.node type="Xml.Node*"
utility_data_model_dump_data_to_xml.parent type="Xml.Node*"
utility_holder_load_attributes.node type="Xml.Node*"
-value_new_from_xml.node type="Xml.Node*"
DataModelImport.new_xml_node.node type="Xml.Node*"
ServerOperation.load_data_from_xml.node type="Xml.Node*"
// type overrides for GIR not well detected
@@ -44,3 +43,15 @@ Holder.get_value nullable=true
Row.get_value nullable=true
Numeric.get_string nullable=true
//Numeric.number hidden=true
+//value_new_from_string skip=true
+value_copy skip=true
+value_new skip=true
+value_new_null skip=true
+value_new_default skip=true
+value_new_binary skip=true
+value_new_blob skip=true
+value_new_blob_from_file skip=true
+value_new_timestamp_from_timet skip=true
+value_new_from_string skip=true
+value_new_from_xml skip=true
+//value_new_from_xml.node type="Xml.Node*"
diff --git a/libgda/data/DbField.vala b/libgda/data/DbField.vala
index 7d0f390..2d018e8 100644
--- a/libgda/data/DbField.vala
+++ b/libgda/data/DbField.vala
@@ -45,5 +45,43 @@ namespace GdaData
NO_MODIF,
UNUSED
}
+
+ public static Value? value_from_string (string as_string, Type type)
+ {
+ // FIXME: No all basic types have support to parse from string se bug 669278
+
+ if (type == typeof (bool)) {
+ if ((as_string[0] == 't') || (as_string[0] == 'T') || as_string == "true")
+ return true;
+ if ((as_string[0] == 'f') || (as_string[0] == 'F') || as_string == "false")
+ return false;
+ int i = int.parse(as_string);
+ return i==0 ? false : true;
+ }
+ if (type == typeof (int64))
+ return int64.parse (as_string);
+ if (type == typeof (uint64))
+ return uint64.parse (as_string);
+ if (type == typeof (int))
+ return int.parse (as_string);
+// if (type == typeof (short))
+// return short.parse (as_string);
+// if (type == typeof (ushort))
+// return ushort.parse (as_string);
+ if (type == typeof (long))
+ return long.parse (as_string);
+// if (type == typeof (float))
+// return float.parse (as_string);
+// if (type == typeof (double))
+// return double.parse (as_string);
+ if (type == typeof (Gda.Numeric))
+ {
+ var n = new Gda.Numeric ();
+ n.set_from_string (as_string);
+ return n;
+ }
+
+ return as_string;
+ }
}
}
diff --git a/libgda/data/GdaData-5.0.gir b/libgda/data/GdaData-5.0.gir
index a26a01f..60f8795 100644
--- a/libgda/data/GdaData-5.0.gir
+++ b/libgda/data/GdaData-5.0.gir
@@ -794,6 +794,19 @@
<type name="utf8" c:type="gchar*"/>
</return-value>
</virtual-method>
+ <function name="value_from_string" c:identifier="gda_data_db_field_value_from_string">
+ <parameters>
+ <parameter name="as_string" transfer-ownership="none">
+ <type name="utf8" c:type="const gchar*"/>
+ </parameter>
+ <parameter name="type" transfer-ownership="none">
+ <type name="GObject.Type" c:type="GType"/>
+ </parameter>
+ </parameters>
+ <return-value transfer-ownership="full" allow-none="1">
+ <type name="GObject.Value" c:type="GValue*"/>
+ </return-value>
+ </function>
<property name="value" writable="1">
<type name="GObject.Value" c:type="GValue*"/>
</property>
diff --git a/libgda/data/Table.vala b/libgda/data/Table.vala
index b92da4a..7d02f1c 100644
--- a/libgda/data/Table.vala
+++ b/libgda/data/Table.vala
@@ -59,7 +59,7 @@ namespace GdaData
string fdv = (string) mt.get_value_at (mt.get_column_index ("column_default"), r);
if (fdv != null) {
attr = attr & DbField.Attribute.CAN_BE_DEFAULT;
- //Value? dv = Gda.value_new_from_string (fdv, ft);
+ var dv = DbField.value_from_string (fdv, ft);
}
string fai = (string) mt.get_value_at (mt.get_column_index ("extras"), r);
bool fai_b = false;
diff --git a/libgda/libgda-5.0.vapi b/libgda/libgda-5.0.vapi
index d3fd7b4..7a0bbbf 100644
--- a/libgda/libgda-5.0.vapi
+++ b/libgda/libgda-5.0.vapi
@@ -2071,8 +2071,6 @@ namespace Gda {
[CCode (cheader_filename = "libgda/libgda.h")]
public static int value_compare (GLib.Value value1, GLib.Value value2);
[CCode (cheader_filename = "libgda/libgda.h")]
- public static GLib.Value value_copy (GLib.Value value);
- [CCode (cheader_filename = "libgda/libgda.h")]
public static int value_differ (GLib.Value value1, GLib.Value value2);
[CCode (cheader_filename = "libgda/libgda.h")]
public static void value_free (owned GLib.Value? value);
@@ -2097,24 +2095,6 @@ namespace Gda {
[CCode (cheader_filename = "libgda/libgda.h")]
public static bool value_is_number (GLib.Value value);
[CCode (cheader_filename = "libgda/libgda.h")]
- public static GLib.Value value_new (GLib.Type type);
- [CCode (cheader_filename = "libgda/libgda.h")]
- public static GLib.Value value_new_binary (uint8 val, long size);
- [CCode (cheader_filename = "libgda/libgda.h")]
- public static GLib.Value value_new_blob (uint8 val, long size);
- [CCode (cheader_filename = "libgda/libgda.h")]
- public static GLib.Value value_new_blob_from_file (string filename);
- [CCode (cheader_filename = "libgda/libgda.h")]
- public static GLib.Value value_new_default (string? default_val);
- [CCode (cheader_filename = "libgda/libgda.h")]
- public static GLib.Value value_new_from_string (string as_string, GLib.Type type);
- [CCode (cheader_filename = "libgda/libgda.h")]
- public static GLib.Value value_new_from_xml ([CCode (type = "xmlNodePtr")] Xml.Node* node);
- [CCode (cheader_filename = "libgda/libgda.h")]
- public static GLib.Value value_new_null ();
- [CCode (cheader_filename = "libgda/libgda.h")]
- public static GLib.Value value_new_timestamp_from_timet (long val);
- [CCode (cheader_filename = "libgda/libgda.h")]
public static void value_reset_with_type (GLib.Value value, GLib.Type type);
[CCode (cheader_filename = "libgda/libgda.h")]
public static void value_set_binary (GLib.Value value, Gda.Binary binary);
diff --git a/samples/vala/SampleDataModelIterable.vala b/samples/vala/SampleDataModelIterable.vala
index 3ddfc34..49b4344 100644
--- a/samples/vala/SampleDataModelIterable.vala
+++ b/samples/vala/SampleDataModelIterable.vala
@@ -52,8 +52,6 @@ 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 ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]