[libgda/libgda-vala: 602/602] GdaData: Added to_string() functons and items() to enums
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda/libgda-vala: 602/602] GdaData: Added to_string() functons and items() to enums
- Date: Fri, 3 May 2013 18:40:12 +0000 (UTC)
commit 8f5a4b5bf1977b3a4daa83adb6f39c7585a3aa2d
Author: Daniel Espinosa <esodan gmail com>
Date: Fri May 3 09:45:10 2013 -0500
GdaData: Added to_string() functons and items() to enums
libgda-ui/libgdaui-5.0.vapi | 1 -
libgda/data/DbFieldInfo.vala | 254 ++++++++++++++++++++++++++++++------------
libgda/data/GdaData-5.0.gir | 144 ++++++++++++++++++------
libgda/data/Table.vala | 12 +-
4 files changed, 297 insertions(+), 114 deletions(-)
---
diff --git a/libgda-ui/libgdaui-5.0.vapi b/libgda-ui/libgdaui-5.0.vapi
index 4308733..fe4f180 100644
--- a/libgda-ui/libgdaui-5.0.vapi
+++ b/libgda-ui/libgdaui-5.0.vapi
@@ -626,7 +626,6 @@ namespace Gdaui {
public interface DataSelector : GLib.Object {
public abstract unowned Gda.DataModelIter get_data_set ();
public abstract unowned Gda.DataModel get_model ();
- public abstract GLib.Array<void*> get_selected_rows ();
public abstract bool select_row (int row);
public abstract void set_column_visible (int column, bool visible);
public abstract void set_model (Gda.DataModel model);
diff --git a/libgda/data/DbFieldInfo.vala b/libgda/data/DbFieldInfo.vala
index 0fe44b3..d7d0952 100644
--- a/libgda/data/DbFieldInfo.vala
+++ b/libgda/data/DbFieldInfo.vala
@@ -39,32 +39,16 @@ namespace GdaData {
// Constrains
public abstract ForeignKey fkey { get; set; }
-
- public static Attribute attribute_from_string (string str)
- {
- if (str == "NONE")
- return Attribute.NONE;
- if (str == "PRIMARY_KEY")
- return Attribute.PRIMARY_KEY;
- if (str == "PRIMARY KEY")
- return Attribute.PRIMARY_KEY;
- if (str == "UNIQUE")
- return Attribute.UNIQUE;
- if (str == "FOREIGN_KEY")
- return Attribute.FOREIGN_KEY;
- if (str == "FOREIGN KEY")
- return Attribute.FOREIGN_KEY;
- if (str == "CHECK")
- return Attribute.CHECK;
- if (str == "HAVE_DEFAULT")
- return Attribute.HAVE_DEFAULT;
- if (str == "CAN_BE_NULL")
- return Attribute.CAN_BE_NULL;
- if (str == "AUTO_INCREMENT")
- return Attribute.AUTO_INCREMENT;
-
- return Attribute.NONE;
+
+ public virtual string to_string () {
+ string fk = "";
+ if (fkey != null)
+ fk = fkey.to_string ();
+ return @"([$ordinal],[$name],[$(value_type.name ())],[%s],[$(attributes)],[%s],[$fk])"
+ .printf (default_value == null ? "" :
Gda.value_stringify (default_value),
+ desc == null ? "" : desc);
}
+
[Flags]
public enum Attribute {
NONE,
@@ -74,7 +58,68 @@ namespace GdaData {
CHECK,
HAVE_DEFAULT,
CAN_BE_NULL,
- AUTO_INCREMENT
+ AUTO_INCREMENT;
+
+ public static Attribute[] items () {
+ return {
+ NONE,
+ PRIMARY_KEY,
+ UNIQUE,
+ FOREIGN_KEY,
+ CHECK,
+ HAVE_DEFAULT,
+ CAN_BE_NULL,
+ AUTO_INCREMENT
+ };
+ }
+
+ public string to_string () {
+ string str = "";
+ if (NONE in this)
+ str += "NONE ";
+ if (PRIMARY_KEY in this)
+ str += "PRIMARY_KEY ";
+ if (UNIQUE in this)
+ str += "UNIQUE ";
+ if (FOREIGN_KEY in this)
+ str += "FOREIGN_KEY ";
+ if (CHECK in this)
+ str += "CHECK ";
+ if (HAVE_DEFAULT in this)
+ str += "HAVE_DEFAULT ";
+ if (CAN_BE_NULL in this)
+ str += "CAN_BE_NULL ";
+ if (AUTO_INCREMENT in this)
+ str += "AUTO_INCREMENT ";
+ if (str == "")
+ return "NONE";
+ return str;
+ }
+
+ public static Attribute from_string (string str)
+ {
+ if (str == "NONE")
+ return NONE;
+ if (str == "PRIMARY_KEY")
+ return PRIMARY_KEY;
+ if (str == "PRIMARY KEY")
+ return PRIMARY_KEY;
+ if (str == "UNIQUE")
+ return UNIQUE;
+ if (str == "FOREIGN_KEY")
+ return FOREIGN_KEY;
+ if (str == "FOREIGN KEY")
+ return FOREIGN_KEY;
+ if (str == "CHECK")
+ return CHECK;
+ if (str == "HAVE_DEFAULT")
+ return HAVE_DEFAULT;
+ if (str == "CAN_BE_NULL")
+ return CAN_BE_NULL;
+ if (str == "AUTO_INCREMENT")
+ return AUTO_INCREMENT;
+ return Attribute.NONE;
+ }
}
@@ -92,59 +137,70 @@ namespace GdaData {
{
refcol = new ArrayList<string> ();
}
-
- public static Match match_from_string (string str)
- {
- if (str == "FULL")
- return Match.FULL;
- if (str == "PARTIAL")
- return Match.PARTIAL;
-
- return Match.NONE;
- }
-
- public static Rule rule_from_string (string? str)
+
+ public bool equal (ForeignKey fkey)
{
- if (str == "CASCADE")
- return Rule.CASCADE;
- if (str == "SET_NULL")
- return Rule.SET_NULL;
- if (str == "SET NULL")
- return Rule.SET_NULL;
- if (str == "SET_DEFAULT")
- return Rule.SET_DEFAULT;
- if (str == "SET DEFAULT")
- return Rule.SET_DEFAULT;
- if (str == "RESTRICT")
- return Rule.RESTRICT;
- if (str == "NO_ACTION")
- return Rule.NO_ACTION;
- if (str == "NO ACTION")
- return Rule.NO_ACTION;
-
- return Rule.NONE;
+ if (fkey.name != name)
+ return false;
+ if (fkey.refname != refname)
+ return false;
+ if (fkey.reftable != reftable)
+ return false;
+ if (fkey.match != match)
+ return false;
+ if (fkey.update_rule != update_rule)
+ return false;
+ if (fkey.delete_rule != delete_rule)
+ return false;
+ foreach (string rc in fkey.refcol) {
+ if (!refcol.contains (rc))
+ return false;
+ }
+ return true;
}
-
- public static string rule_to_string (Rule r)
+
+ public string to_string ()
{
- if (r == Rule.CASCADE)
- return "CASCADE";
- if (r == Rule.SET_NULL)
- return "SET NULL";
- if (r == Rule.SET_DEFAULT)
- return "SET DEFAULT";
- if (r == Rule.RESTRICT)
- return "RESTRICT";
- if (r == Rule.NO_ACTION)
- return "NO ACTION";
-
- return "NONE";
+ string s = "";
+ foreach (string str in refcol) {
+ s += str + ",";
+ }
+ return
@"{[$(name)],[$(refname)],[$(reftable.name)],[$s],[$(match)],[$(update_rule)],[$(delete_rule)]}";
}
-
+
public enum Match {
+ NONE,
FULL,
- PARTIAL,
- NONE
+ PARTIAL;
+
+ public static Match[] items () {
+ return {
+ NONE,
+ FULL,
+ PARTIAL
+ };
+ }
+
+ public string to_string ()
+ {
+ switch (this) {
+ case FULL:
+ return "FULL";
+ case PARTIAL:
+ return "PARTIAL";
+ }
+ return "NONE";
+ }
+
+ public static Match from_string (string str)
+ {
+ if (str == "FULL")
+ return FULL;
+ if (str == "PARTIAL")
+ return PARTIAL;
+
+ return Match.NONE;
+ }
}
public enum Rule {
NONE,
@@ -152,7 +208,57 @@ namespace GdaData {
SET_NULL,
SET_DEFAULT,
RESTRICT,
- NO_ACTION
+ NO_ACTION;
+
+ public static Rule[] items () {
+ return {
+ NONE,
+ CASCADE,
+ SET_NULL,
+ SET_DEFAULT,
+ RESTRICT,
+ NO_ACTION
+ };
+ }
+
+ public string to_string ()
+ {
+ switch (this) {
+ case CASCADE:
+ return "CASCADE";
+ case SET_NULL:
+ return "SET_NULL";
+ case SET_DEFAULT:
+ return "SET_DEFAULT";
+ case RESTRICT:
+ return "RESTRICT";
+ case NO_ACTION:
+ return "NO_ACTION";
+ }
+ return "NONE";
+ }
+
+ public static Rule from_string (string? str)
+ {
+ if (str == "CASCADE")
+ return Rule.CASCADE;
+ if (str == "SET_NULL")
+ return Rule.SET_NULL;
+ if (str == "SET NULL")
+ return Rule.SET_NULL;
+ if (str == "SET_DEFAULT")
+ return Rule.SET_DEFAULT;
+ if (str == "SET DEFAULT")
+ return Rule.SET_DEFAULT;
+ if (str == "RESTRICT")
+ return Rule.RESTRICT;
+ if (str == "NO_ACTION")
+ return Rule.NO_ACTION;
+ if (str == "NO ACTION")
+ return Rule.NO_ACTION;
+
+ return Rule.NONE;
+ }
}
}
}
diff --git a/libgda/data/GdaData-5.0.gir b/libgda/data/GdaData-5.0.gir
index c61cf0d..9c10d53 100644
--- a/libgda/data/GdaData-5.0.gir
+++ b/libgda/data/GdaData-5.0.gir
@@ -1092,16 +1092,16 @@
</function>
<interface name="DbFieldInfo" c:type="GdaDataDbFieldInfo" glib:type-name="GdaDataDbFieldInfo"
glib:get-type="gda_data_db_field_info_get_type" glib:type-struct="DbFieldInfoIface">
<prerequisite name="GObject.Object"/>
- <function name="attribute_from_string"
c:identifier="gda_data_db_field_info_attribute_from_string">
+ <method name="to_string" c:identifier="gda_data_db_field_info_to_string">
<return-value transfer-ownership="full">
- <type name="GdaData.DbFieldInfoAttribute"
c:type="GdaDataDbFieldInfoAttribute"/>
+ <type name="utf8" c:type="gchar*"/>
</return-value>
- <parameters>
- <parameter name="str" transfer-ownership="none">
- <type name="utf8" c:type="const gchar*"/>
- </parameter>
- </parameters>
- </function>
+ </method>
+ <virtual-method name="to_string" invoker="to_string">
+ <return-value transfer-ownership="full">
+ <type name="utf8" c:type="gchar*"/>
+ </return-value>
+ </virtual-method>
<property name="ordinal" writable="1">
<type name="gint" c:type="gint"/>
</property>
@@ -1134,6 +1134,18 @@
<field name="parent_iface">
<type name="GObject.TypeInterface" c:type="GTypeInterface"/>
</field>
+ <field name="to_string">
+ <callback name="to_string" c:type="to_string">
+ <return-value transfer-ownership="full">
+ <type name="utf8" c:type="gchar*"/>
+ </return-value>
+ <parameters>
+ <parameter name="self" transfer-ownership="none">
+ <type name="GdaData.DbFieldInfo"
c:type="GdaDataDbFieldInfo*"/>
+ </parameter>
+ </parameters>
+ </callback>
+ </field>
</record>
<bitfield name="DbFieldInfoAttribute" c:type="GdaDataDbFieldInfoAttribute"
glib:type-name="GdaDataDbFieldInfoAttribute" glib:get-type="gda_data_db_field_info_attribute_get_type">
<member name="none" c:identifier="GDA_DATA_DB_FIELD_INFO_ATTRIBUTE_NONE" value="1"/>
@@ -1145,42 +1157,54 @@
<member name="can_be_null" c:identifier="GDA_DATA_DB_FIELD_INFO_ATTRIBUTE_CAN_BE_NULL"
value="64"/>
<member name="auto_increment" c:identifier="GDA_DATA_DB_FIELD_INFO_ATTRIBUTE_AUTO_INCREMENT"
value="128"/>
</bitfield>
+ <function name="db_field_info_attribute_items" c:identifier="gda_data_db_field_info_attribute_items">
+ <return-value transfer-ownership="full">
+ <array length="0">
+ <type name="GdaData.DbFieldInfoAttribute"
c:type="GdaDataDbFieldInfoAttribute"/>
+ </array>
+ </return-value>
+ <parameters>
+ <parameter name="result_length1" direction="out" transfer-ownership="none">
+ <type name="gint" c:type="gint"/>
+ </parameter>
+ </parameters>
+ </function>
+ <function name="db_field_info_attribute_to_string"
c:identifier="gda_data_db_field_info_attribute_to_string">
+ <return-value transfer-ownership="full">
+ <type name="utf8" c:type="gchar*"/>
+ </return-value>
+ </function>
+ <function name="db_field_info_attribute_from_string"
c:identifier="gda_data_db_field_info_attribute_from_string">
+ <return-value transfer-ownership="full">
+ <type name="GdaData.DbFieldInfoAttribute" c:type="GdaDataDbFieldInfoAttribute"/>
+ </return-value>
+ <parameters>
+ <parameter name="str" transfer-ownership="none">
+ <type name="utf8" c:type="const gchar*"/>
+ </parameter>
+ </parameters>
+ </function>
<record name="DbFieldInfoForeignKey">
<constructor name="new" c:identifier="gda_data_db_field_info_foreign_key_new">
<return-value transfer-ownership="full">
<type name="GdaData.DbFieldInfoForeignKey"
c:type="GdaDataDbFieldInfoForeignKey*"/>
</return-value>
</constructor>
- <function name="match_from_string"
c:identifier="gda_data_db_field_info_foreign_key_match_from_string">
+ <method name="equal" c:identifier="gda_data_db_field_info_foreign_key_equal">
<return-value transfer-ownership="full">
- <type name="GdaData.DbFieldInfoForeignKeyMatch"
c:type="GdaDataDbFieldInfoForeignKeyMatch"/>
- </return-value>
- <parameters>
- <parameter name="str" transfer-ownership="none">
- <type name="utf8" c:type="const gchar*"/>
- </parameter>
- </parameters>
- </function>
- <function name="rule_from_string"
c:identifier="gda_data_db_field_info_foreign_key_rule_from_string">
- <return-value transfer-ownership="full">
- <type name="GdaData.DbFieldInfoForeignKeyRule"
c:type="GdaDataDbFieldInfoForeignKeyRule"/>
+ <type name="gboolean" c:type="gboolean"/>
</return-value>
<parameters>
- <parameter name="str" transfer-ownership="none" allow-none="1">
- <type name="utf8" c:type="const gchar*"/>
+ <parameter name="fkey" transfer-ownership="none">
+ <type name="GdaData.DbFieldInfoForeignKey"
c:type="GdaDataDbFieldInfoForeignKey*"/>
</parameter>
</parameters>
- </function>
- <function name="rule_to_string"
c:identifier="gda_data_db_field_info_foreign_key_rule_to_string">
+ </method>
+ <method name="to_string" c:identifier="gda_data_db_field_info_foreign_key_to_string">
<return-value transfer-ownership="full">
<type name="utf8" c:type="gchar*"/>
</return-value>
- <parameters>
- <parameter name="r" transfer-ownership="none">
- <type name="GdaData.DbFieldInfoForeignKeyRule"
c:type="GdaDataDbFieldInfoForeignKeyRule"/>
- </parameter>
- </parameters>
- </function>
+ </method>
<property name="name" writable="1">
<type name="utf8" c:type="gchar*"/>
</property>
@@ -1206,10 +1230,37 @@
</property>
</record>
<enumeration name="DbFieldInfoForeignKeyMatch" c:type="GdaDataDbFieldInfoForeignKeyMatch"
glib:type-name="GdaDataDbFieldInfoForeignKeyMatch"
glib:get-type="gda_data_db_field_info_foreign_key_match_get_type">
- <member name="full" c:identifier="GDA_DATA_DB_FIELD_INFO_FOREIGN_KEY_MATCH_FULL" value="0"/>
- <member name="partial" c:identifier="GDA_DATA_DB_FIELD_INFO_FOREIGN_KEY_MATCH_PARTIAL"
value="1"/>
- <member name="none" c:identifier="GDA_DATA_DB_FIELD_INFO_FOREIGN_KEY_MATCH_NONE" value="2"/>
+ <member name="none" c:identifier="GDA_DATA_DB_FIELD_INFO_FOREIGN_KEY_MATCH_NONE" value="0"/>
+ <member name="full" c:identifier="GDA_DATA_DB_FIELD_INFO_FOREIGN_KEY_MATCH_FULL" value="1"/>
+ <member name="partial" c:identifier="GDA_DATA_DB_FIELD_INFO_FOREIGN_KEY_MATCH_PARTIAL"
value="2"/>
</enumeration>
+ <function name="db_field_info_foreign_key_match_items"
c:identifier="gda_data_db_field_info_foreign_key_match_items">
+ <return-value transfer-ownership="full">
+ <array length="0">
+ <type name="GdaData.DbFieldInfoForeignKeyMatch"
c:type="GdaDataDbFieldInfoForeignKeyMatch"/>
+ </array>
+ </return-value>
+ <parameters>
+ <parameter name="result_length1" direction="out" transfer-ownership="none">
+ <type name="gint" c:type="gint"/>
+ </parameter>
+ </parameters>
+ </function>
+ <function name="db_field_info_foreign_key_match_to_string"
c:identifier="gda_data_db_field_info_foreign_key_match_to_string">
+ <return-value transfer-ownership="full">
+ <type name="utf8" c:type="gchar*"/>
+ </return-value>
+ </function>
+ <function name="db_field_info_foreign_key_match_from_string"
c:identifier="gda_data_db_field_info_foreign_key_match_from_string">
+ <return-value transfer-ownership="full">
+ <type name="GdaData.DbFieldInfoForeignKeyMatch"
c:type="GdaDataDbFieldInfoForeignKeyMatch"/>
+ </return-value>
+ <parameters>
+ <parameter name="str" transfer-ownership="none">
+ <type name="utf8" c:type="const gchar*"/>
+ </parameter>
+ </parameters>
+ </function>
<enumeration name="DbFieldInfoForeignKeyRule" c:type="GdaDataDbFieldInfoForeignKeyRule"
glib:type-name="GdaDataDbFieldInfoForeignKeyRule"
glib:get-type="gda_data_db_field_info_foreign_key_rule_get_type">
<member name="none" c:identifier="GDA_DATA_DB_FIELD_INFO_FOREIGN_KEY_RULE_NONE" value="0"/>
<member name="cascade" c:identifier="GDA_DATA_DB_FIELD_INFO_FOREIGN_KEY_RULE_CASCADE"
value="1"/>
@@ -1218,6 +1269,33 @@
<member name="restrict" c:identifier="GDA_DATA_DB_FIELD_INFO_FOREIGN_KEY_RULE_RESTRICT"
value="4"/>
<member name="no_action" c:identifier="GDA_DATA_DB_FIELD_INFO_FOREIGN_KEY_RULE_NO_ACTION"
value="5"/>
</enumeration>
+ <function name="db_field_info_foreign_key_rule_items"
c:identifier="gda_data_db_field_info_foreign_key_rule_items">
+ <return-value transfer-ownership="full">
+ <array length="0">
+ <type name="GdaData.DbFieldInfoForeignKeyRule"
c:type="GdaDataDbFieldInfoForeignKeyRule"/>
+ </array>
+ </return-value>
+ <parameters>
+ <parameter name="result_length1" direction="out" transfer-ownership="none">
+ <type name="gint" c:type="gint"/>
+ </parameter>
+ </parameters>
+ </function>
+ <function name="db_field_info_foreign_key_rule_to_string"
c:identifier="gda_data_db_field_info_foreign_key_rule_to_string">
+ <return-value transfer-ownership="full">
+ <type name="utf8" c:type="gchar*"/>
+ </return-value>
+ </function>
+ <function name="db_field_info_foreign_key_rule_from_string"
c:identifier="gda_data_db_field_info_foreign_key_rule_from_string">
+ <return-value transfer-ownership="full">
+ <type name="GdaData.DbFieldInfoForeignKeyRule"
c:type="GdaDataDbFieldInfoForeignKeyRule"/>
+ </return-value>
+ <parameters>
+ <parameter name="str" transfer-ownership="none" allow-none="1">
+ <type name="utf8" c:type="const gchar*"/>
+ </parameter>
+ </parameters>
+ </function>
<interface name="DbSchema" c:type="GdaDataDbSchema" glib:type-name="GdaDataDbSchema"
glib:get-type="gda_data_db_schema_get_type" glib:type-struct="DbSchemaIface">
<prerequisite name="GObject.Object"/>
<prerequisite name="GdaData.DbObject"/>
diff --git a/libgda/data/Table.vala b/libgda/data/Table.vala
index 82c3699..39ca079 100644
--- a/libgda/data/Table.vala
+++ b/libgda/data/Table.vala
@@ -228,7 +228,7 @@ namespace GdaData
}
var colname = (string) mpk.get_value_at (mpk.get_column_index
("column_name"), 0);
var f = _fields.get (colname);
- f.attributes = f.attributes | DbFieldInfo.attribute_from_string (ct);
+ f.attributes = f.attributes | DbFieldInfo.Attribute.from_string (ct);
if (DbFieldInfo.Attribute.FOREIGN_KEY in f.attributes)
{
@@ -268,14 +268,14 @@ namespace GdaData
_depends.set (f.fkey.reftable.name, f.fkey.reftable);
var match = (string) mfk.get_value_at (
mfk.get_column_index ("match_option"), 0);
- f.fkey.match = DbFieldInfo.ForeignKey.match_from_string (match);
+ f.fkey.match = DbFieldInfo.ForeignKey.Match.from_string (match);
var update_rule = (string) mfk.get_value_at (
mfk.get_column_index ("update_rule"), 0);
- f.fkey.update_rule = DbFieldInfo.ForeignKey.rule_from_string
(update_rule);
+ f.fkey.update_rule = DbFieldInfo.ForeignKey.Rule.from_string
(update_rule);
var delete_rule = (string) mfk.get_value_at (
mfk.get_column_index ("delete_rule"), 0);
- f.fkey.delete_rule = DbFieldInfo.ForeignKey.rule_from_string
(delete_rule);
+ f.fkey.delete_rule = DbFieldInfo.ForeignKey.Rule.from_string
(delete_rule);
var mfkr = store.extract ("SELECT * FROM _detailed_fk " +
" WHERE fk_table_name
= ##name::string"+
@@ -380,9 +380,9 @@ namespace GdaData
rc++;
}
- op.set_value_at (DbFieldInfo.ForeignKey.rule_to_string
(f.fkey.update_rule),
+ op.set_value_at (f.fkey.update_rule.to_string (),
"/FKEY_S/" + refs.to_string
() + "/FKEY_ONUPDATE");
- op.set_value_at (DbFieldInfo.ForeignKey.rule_to_string
(f.fkey.delete_rule),
+ op.set_value_at (f.fkey.delete_rule.to_string (),
"/FKEY_S/" + refs.to_string
() + "/FKEY_ONDELETE");
refs++;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]