[libgda] Fixed Gda.MetaStore.extract_v annotations
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Fixed Gda.MetaStore.extract_v annotations
- Date: Sun, 8 Jan 2012 04:19:54 +0000 (UTC)
commit 5951b788aa33683ce014651a75aa058e9e59f0a8
Author: Daniel Espinosa <despinosa src gnome org>
Date: Thu Jan 5 18:16:40 2012 -0600
Fixed Gda.MetaStore.extract_v annotations
libgda/Gda-5.0.gir | 2 +-
libgda/data/IdField.vala | 30 ------
libgda/data/Record.vala | 187 +++++++++++++++++++++++++++++++++++++++
libgda/data/RecordSingleId.vala | 142 -----------------------------
libgda/gda-meta-store.c | 2 +-
libgda/libgda-5.0.vapi | 2 +-
6 files changed, 190 insertions(+), 175 deletions(-)
---
diff --git a/libgda/Gda-5.0.gir b/libgda/Gda-5.0.gir
index d767bff..b1de661 100644
--- a/libgda/Gda-5.0.gir
+++ b/libgda/Gda-5.0.gir
@@ -10524,7 +10524,7 @@ SQL identifiers are represented in @store, see the
<parameter name="vars" transfer-ownership="none" allow-none="1">
<doc xml:whitespace="preserve">a hash table with all variables names as keys and GValue* as value, representing values for all the variables mentioned in @select_sql. If there is no variable then this part can be omitted.</doc>
<type name="GLib.HashTable" c:type="GHashTable*">
- <type name="gchar"/>
+ <type name="utf8"/>
<type name="GObject.Value"/>
</type>
</parameter>
diff --git a/libgda/data/Record.vala b/libgda/data/Record.vala
new file mode 100644
index 0000000..ee79c2e
--- /dev/null
+++ b/libgda/data/Record.vala
@@ -0,0 +1,187 @@
+/* -*- Mode: Vala; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * libgdavala
+ * Copyright (C) Daniel Espinosa Ortiz 2011 <esodan gmail com>
+ *
+ * libgda is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * libgda is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gda;
+using Gee;
+
+namespace GdaData {
+
+ public abstract class Record<G> : Object {
+
+ protected HashMap<string,DbField<G>> _model = new HashMap<string,DbField<G>> ();
+ protected HashMap<string,DbField<G>> _keys = new HashMap<string,DbField<G>> ();
+ /**
+ * Derived classes must implement this property to set the table used to get data from.
+ */
+ public DbTable table { get; set construct; }
+ /**
+ * Returns a Gee.Collection with the data stored by this object.
+ */
+ public Collection<DbField<G>> fields { owned get { return _model.values; } }
+ public Collection<DbField<G>> keys { owned get { return _keys.values; } }
+ /**
+ * Set the connection to be used to get/set data.
+ */
+ public Connection connection { get; set; }
+ /**
+ * Returns a GLib.Value containing the value stored in the given field.
+ */
+ public G get_value (string field)
+ throws Error
+ {
+ var f = this._model.get (field);
+ return f.value;
+ }
+ /**
+ * Set the value to a field with the given @name.
+ */
+ public void set_value (string field, G v)
+ throws Error
+ {
+ if (_model.has_key (field)) {
+ var f = this._model.get (field);
+ f.value = v;
+ this._model.set (field, f);
+ }
+ else {
+ // FIXME: Get default attributes from table
+ var n = new Field<G> (field, DbField.Attribute.NONE);
+ n.value = v;
+ this._model.set (field, n);
+ }
+
+ }
+
+ public void set_key (string field, G v)
+ {
+ if (keys.has_key (field)) {
+ var f = keys.get (field);
+ f.value = v;
+ keys.set (field, f);
+ }
+ else {
+ // FIXME: Get default attributes from table
+ var n = new Field<G> (field, DbField.Attribute.NONE);
+ n.value = v;
+ keys.set (field, n);
+ }
+ }
+ /**
+ * Saves any modficiation made to in memory representation of the data directly to
+ * the database.
+ */
+ public void save () throws Error
+ {
+ var q = new SqlBuilder (SqlStatementType.UPDATE);
+ q.set_table (table.name);
+ foreach (DbField<G> f in fields) {
+ Value v = f.value;
+ q.add_field_value_as_gvalue (f.column_name, v);
+ }
+ SqlBuilderId cond = -1;
+ foreach (DbField<G> f in fields) {
+ var f_id = q.add_id (f.name);
+ Value v = f.value;
+ var e_id = q.add_expr_value (null, v);
+ var c_id = q.add_cond (SqlOperatorType.EQ, f_id, e_id, 0);
+ if (cond < 0)
+ cond = c_id;
+ else
+ cond = sql.add_cond (SqlOperatorType.AND, cond, c_id, 0);
+ }
+ q.set_where (cond);
+// stdout.printf ("DEBUG: UPDATE statement to execute: \n"+
+// (q.get_statement()).to_sql_extended (this.connection, null,
+// StatementSqlFlag.PRETTY, null)
+// + "\n");
+ var i = this.connection.statement_execute_non_select (q.get_statement (), null, null);
+ if (i != 1) {
+ throw new DbObjectError.APPEND ("Have been saved more or less rows than expected");
+ }
+ }
+ /**
+ * Updates values stored in database.
+ */
+ public void update () throws Error
+ {
+ var q = new SqlBuilder (SqlStatementType.SELECT);
+ q.select_add_target (table.name, null);
+ SqlBuilderId cond = -1;
+ foreach (DbField<G> f in fields) {
+ var f_id = sql.add_id (f.name);
+ Value v = f.value;
+ var e_id = sql.add_expr_value (null, v);
+ var c_id = sql.add_cond (SqlOperatorType.EQ, f_id, e_id, 0);
+ if (cond < 0)
+ cond = c_id;
+ else
+ cond = sql.add_cond (SqlOperatorType.AND, cond, c_id, 0);
+ }
+ q.set_where (cond);
+ q.select_add_field ("*", null, null);
+// stdout.printf ("DEBUG: UPDATE statement to execute: \n"+
+// (q.get_statement()).to_sql_extended (this.connection, null,
+// StatementSqlFlag.PRETTY, null)
+// + "\n");
+ var i = this.connection.statement_execute_non_select (sql.get_statement (), null, null);
+ if (i != 1) {
+ throw new DbObjectError.UPDATE ("Have been updated more or less rows than expected");
+ }
+ }
+ /**
+ * Append a new row to the defined table and returns its ID. If defaults is set to true,
+ * default value for each field is set.
+ */
+ public bool append () throws Error
+ {
+ var sql = new SqlBuilder (SqlStatementType.INSERT);
+ sql.set_table (this.table);
+ // FIXME: MetaData is required
+ foreach (Field<G> f in _model.values) {
+ Value v = f.value;
+ sql.add_field_value_as_gvalue (f.column_name, v);
+ }
+// stdout.printf ("DEBUG: INSERT statement to execute: \n"+
+// (sql.get_statement()).to_sql_extended (this.connection, null,
+// StatementSqlFlag.PRETTY, null)
+// + "\n");
+ Set last_inserted;
+ var i = this.connection.statement_execute_non_select (sql.get_statement (), null, null);
+ if (i != 1) {
+ throw new DbObjectError.UPDATE ("Have been added more or less rows than expected");
+ }
+ return true;
+ }
+
+ public string to_string ()
+ {
+ string r = "";
+ foreach (Field<G> f in this.fields) {
+ r += "|" + f.name;
+ }
+ r+="\n";
+ foreach (Field<Value?> f in this.fields) {
+ Value v = f.value;
+ r += "|" + Gda.value_stringify (v);
+ }
+ r+="\n";
+ return r;
+ }
+ }
+}
diff --git a/libgda/gda-meta-store.c b/libgda/gda-meta-store.c
index 12a228d..eee1dfc 100644
--- a/libgda/gda-meta-store.c
+++ b/libgda/gda-meta-store.c
@@ -2454,7 +2454,7 @@ gda_meta_store_extract (GdaMetaStore *store, const gchar *select_sql, GError **e
* gda_meta_store_extract_v:
* @store: a #GdaMetaStore object
* @select_sql: a SELECT statement
- * @vars: (element-type gchar GObject.Value) (allow-none): a hash table with all variables names as keys and GValue* as
+ * @vars: (element-type utf8 GObject.Value) (allow-none): a hash table with all variables names as keys and GValue* as
* value, representing values for all the variables mentioned in @select_sql. If there is no variable then this part can be
* omitted.
* @error: a place to store errors, or %NULL
diff --git a/libgda/libgda-5.0.vapi b/libgda/libgda-5.0.vapi
index 19c3442..82d47ac 100644
--- a/libgda/libgda-5.0.vapi
+++ b/libgda/libgda-5.0.vapi
@@ -571,7 +571,7 @@ namespace Gda {
public Gda.DataModel create_modify_data_model (string table_name);
public bool declare_foreign_key (Gda.MetaStruct? mstruct, string fk_name, string? catalog, string? schema, string table, string? ref_catalog, string? ref_schema, string ref_table, [CCode (array_length_cname = "nb_cols", array_length_pos = 8.5, array_length_type = "guint")] string[] colnames, [CCode (array_length_cname = "nb_cols", array_length_pos = 8.5, array_length_type = "guint")] string[] ref_colnames) throws GLib.Error;
public static GLib.Quark error_quark ();
- public Gda.DataModel extract_v (string select_sql, GLib.HashTable<char,GLib.Value>? vars) throws GLib.Error;
+ public Gda.DataModel extract_v (string select_sql, GLib.HashTable<string,GLib.Value>? vars) throws GLib.Error;
public bool get_attribute_value (string att_name, out string att_value) throws GLib.Error;
public unowned Gda.Connection get_internal_connection ();
public int get_version ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]