[libgda] Implementations for DbCollection, DbSchema, DbTable, DbField, IdField, DbObject



commit 73cd0a33f0ecccbb0d7430198d5234c1b9778fd0
Author: Daniel Espinosa <despinosa src gnome org>
Date:   Wed Jan 4 22:08:44 2012 -0600

    Implementations for DbCollection, DbSchema, DbTable, DbField, IdField, DbObject

 libgda/data/DataBase.vala       |   49 +++++++++++++
 libgda/data/DbCollection.vala   |    4 +-
 libgda/data/DbField.vala        |    8 +-
 libgda/data/DbFieldInfo.vala    |   29 ++++++++
 libgda/data/DbObject.vala       |    2 +-
 libgda/data/DbSchema.vala       |    3 +-
 libgda/data/DbTable.vala        |    5 +-
 libgda/data/Field.vala          |   15 ++---
 libgda/data/FieldInfo.vala      |   46 +++++++++++++
 libgda/data/GdaData-5.0.gir     |   36 ++--------
 libgda/data/IdField.vala        |   30 ++++++++
 libgda/data/Makefile.am         |    6 ++
 libgda/data/RecordSingleId.vala |  142 +++++++++++++++++++++++++++++++++++++++
 libgda/data/Schema.vala         |   51 ++++++++++++++
 libgda/data/Table.vala          |   44 ++++++++++++
 15 files changed, 419 insertions(+), 51 deletions(-)
---
diff --git a/libgda/data/DataBase.vala b/libgda/data/DataBase.vala
new file mode 100644
index 0000000..b173de4
--- /dev/null
+++ b/libgda/data/DataBase.vala
@@ -0,0 +1,49 @@
+/* -*- Mode: Vala; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * libgdadata
+ * 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 Gee;
+using Gda;
+
+namespace GdaData
+{
+	public class DataBase : Object 
+	{
+		public HashMap<string,DbSchema> schemas_container;
+		// DbObject Interface
+		public Connection connection { get; set; }
+		public void update () throws Error
+		{
+			connection.update_meta_store (null);
+			var store = connection.get_meta_store ();
+			var mstruct = Gda.MetaStruct.new (store, Gda.MetaStructFeature.ALL);
+			var msch =  store.extract ("SELECT * FROM _schemata");
+			int c, r;
+			for ( r = 0; r < msch.get_n_rows (); r++) {
+				var schema = new Schema ();
+				schema.connection = this.connection;
+				schema.name = (string) msch.get_value_at (msch.get_column_index ("schema_name"),r);
+				_schemas.set (schema.name, (DbSchema) schema);
+			}
+		}
+		public void save () {}
+		public void append () {}
+		// DbCollection Interface
+		public abstract Collection<DbSchema> schemas { get { _schemas.values; }}
+	}
+}
diff --git a/libgda/data/DbCollection.vala b/libgda/data/DbCollection.vala
index 1461d39..5850351 100644
--- a/libgda/data/DbCollection.vala
+++ b/libgda/data/DbCollection.vala
@@ -22,10 +22,8 @@ using Gda;
 
 namespace GdaData
 {
-	public interface DbCollection : GLib.Object 
+	public interface DbCollection : DbNamedObject 
 	{
 		public abstract Collection<DbSchema> schemas { get; }
-		
-		public abstract Collection<DbTable> get_tables (string schema);
 	}
 }
diff --git a/libgda/data/DbField.vala b/libgda/data/DbField.vala
index d2557f1..b5a2171 100644
--- a/libgda/data/DbField.vala
+++ b/libgda/data/DbField.vala
@@ -22,12 +22,12 @@ using Gda;
 
 namespace GdaData
 {
-	public interface DbField<G> : GLib.Object
+	public interface DbField<G> : Object
 	{
-		public abstract G value { get; set; }
+		public abstract G @value { get; set; }
 		public abstract string name { get; set; }
-		public abstract string column_name { get; construct; }
-		public abstract DbField.Attribute attributes { get; construct; }
+		public abstract string column_name { get; }
+		public abstract DbField.Attribute attributes { get; }
 		
 		public abstract string to_string ();
 		
diff --git a/libgda/data/DbFieldInfo.vala b/libgda/data/DbFieldInfo.vala
new file mode 100644
index 0000000..ca9da87
--- /dev/null
+++ b/libgda/data/DbFieldInfo.vala
@@ -0,0 +1,29 @@
+/* -*- 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;
+
+namespace GdaData {
+	public interface DbFieldInfo<G> : Object
+	{
+		public abstract DbField.Attribute  attributes { get; }
+		public abstract G                  default_value { get; }
+		public abstract string             name { get; }
+	}
+}
diff --git a/libgda/data/DbObject.vala b/libgda/data/DbObject.vala
index 71e2d2c..c1309e2 100644
--- a/libgda/data/DbObject.vala
+++ b/libgda/data/DbObject.vala
@@ -21,7 +21,7 @@ using Gee;
 using Gda;
 
 namespace GdaData {
-	public interface DbObject : GLib.Object {
+	public interface DbObject : Object {
 		public abstract Connection   connection { get; set; }
 		public abstract DbObject     append ();
 		public abstract void         update ();
diff --git a/libgda/data/DbSchema.vala b/libgda/data/DbSchema.vala
index 93fba36..3fbd50a 100644
--- a/libgda/data/DbSchema.vala
+++ b/libgda/data/DbSchema.vala
@@ -22,9 +22,8 @@ using Gda;
 
 namespace GdaData
 {
-	public interface DbSchema : GLib.Object
+	public interface DbSchema : DbNamedObject
 	{
-		public abstract string name { get; set; }
 		public abstract Collection<DbTable> tables { get; }
 	}
 }
diff --git a/libgda/data/DbTable.vala b/libgda/data/DbTable.vala
index 5f2c9c3..048be2d 100644
--- a/libgda/data/DbTable.vala
+++ b/libgda/data/DbTable.vala
@@ -22,11 +22,10 @@ using Gda;
 
 namespace GdaData
 {
-	public interface DbTable : GLib.Object
+	public interface DbTable : DbNamedObject
 	{
 		public abstract DbSchema schema { get; set construct; }
-		public abstract string name { get; set; }
-		public abstract Collection<DbRecord> tables { get; }
+		public abstract Collection<DbRecord> records { get; }
 		public abstract Collection<DbTable> fk_depends { get; }
 		public abstract Collection<DbTable> fk { get; }
 		public abstract Iterator<DbRecord> iterator ();
diff --git a/libgda/data/Field.vala b/libgda/data/Field.vala
index f1b3b0c..b31e864 100644
--- a/libgda/data/Field.vala
+++ b/libgda/data/Field.vala
@@ -22,14 +22,14 @@ using Gda;
 
 namespace GdaData
 {
-	public class Field<G> : GLib.Object
+	public class Field<G> : Object, DbField<G>
 	{
 		private G                 val;
 		private string            _name;
 		private string            _column_name;
 		private DbField.Attribute _attributes;
 		
-		public G value { 
+		public G @value { 
 			get { return val; } 
 			set { val = value; }
 		}
@@ -38,19 +38,16 @@ namespace GdaData
 			set { _name = value; }
 		}
 		public string column_name { 
-			get { return _column_name; } 
-			construct { _column_name = value; }
+			get { return _column_name; }
 		}
 		public DbField.Attribute attributes { 
-			get { return _attributes; } 
-			construct {
-				_attributes = value;
-			}
+			get { return _attributes; }
 		}
 		public string to_string () { return (string) val; }
 		public Field (string col_name, DbField.Attribute attr) 
 		{
-			GLib.Object (column_name: col_name, attributes: attr);
+			_column_name = col_name;
+			_attributes = attr;
 			_name = col_name;
 		}
 	}
diff --git a/libgda/data/FieldInfo.vala b/libgda/data/FieldInfo.vala
new file mode 100644
index 0000000..4381b24
--- /dev/null
+++ b/libgda/data/FieldInfo.vala
@@ -0,0 +1,46 @@
+/* -*- 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;
+
+namespace GdaData {
+	public class FieldInfo<G> : Object, DbFieldInfo
+	{
+		private DbField.Attribute _attr;
+		private G _default_value;
+		private string _name;
+		
+		public override DbField.Attribute  attributes {
+			get { return _attr; }
+		}
+		
+		public override G default_value { 
+			get { return _default_value; }
+		}
+		public override string name { 
+			get { return _name; }
+		}
+		FieldInfo (string name, DbField.Attribute attr, G default_val)
+		{
+			_name = name;
+			_attr = attr;
+			_default_value = default_val;
+		}
+	}
+}
diff --git a/libgda/data/GdaData-5.0.gir b/libgda/data/GdaData-5.0.gir
index 75661d4..53ae5d3 100644
--- a/libgda/data/GdaData-5.0.gir
+++ b/libgda/data/GdaData-5.0.gir
@@ -208,17 +208,13 @@
 	</record>
 	<record name="RecordSingleIdPrivate" c:type="GdaDataRecordSingleIdPrivate" disguised="1"/>
 	<class name="Field" c:type="GdaDataField" glib:type-name="GdaDataField" glib:get-type="gda_data_field_get_type" glib:type-struct="FieldClass" parent="GObject.Object">
+		<implements name="GdaData.DbField"/>
 		<field name="parent_instance">
 			<type name="GObject.Object" c:type="GObject"/>
 		</field>
 		<field name="priv">
 			<type name="FieldPrivate" c:type="GdaDataFieldPrivate*"/>
 		</field>
-		<method name="to_string" c:identifier="gda_data_field_to_string">
-			<return-value transfer-ownership="full">
-				<type name="utf8" c:type="gchar*"/>
-			</return-value>
-		</method>
 		<constructor name="new" c:identifier="gda_data_field_new">
 			<parameters>
 				<parameter name="col_name" transfer-ownership="none">
@@ -232,18 +228,6 @@
 				<type name="GdaData.Field" c:type="GdaDataField*"/>
 			</return-value>
 		</constructor>
-		<property name="value" writable="1">
-			<type name="gpointer" c:type="gpointer"/>
-		</property>
-		<property name="name" writable="1">
-			<type name="utf8" c:type="gchar*"/>
-		</property>
-		<property name="column-name" writable="1" construct-only="1">
-			<type name="utf8" c:type="gchar*"/>
-		</property>
-		<property name="attributes" writable="1" construct-only="1">
-			<type name="GdaData.DbFieldAttribute" c:type="GdaDataDbFieldAttribute"/>
-		</property>
 	</class>
 	<record name="FieldClass" c:type="GdaDataFieldClass" glib:is-gtype-struct-for="Field">
 		<field name="parent_class">
@@ -413,7 +397,7 @@
 		</field>
 	</record>
 	<interface name="DbCollection" c:type="GdaDataDbCollection" glib:type-name="GdaDataDbCollection" glib:get-type="gda_data_db_collection_get_type" glib:type-struct="DbCollectionIface">
-		<prerequisite name="GObject.Object"/>
+		<prerequisite name="GdaData.DbNamedObject"/>
 		<method name="get_tables" c:identifier="gda_data_db_collection_get_tables">
 			<parameters>
 				<parameter name="schema" transfer-ownership="none">
@@ -467,7 +451,7 @@
 		</field>
 	</record>
 	<interface name="DbTable" c:type="GdaDataDbTable" glib:type-name="GdaDataDbTable" glib:get-type="gda_data_db_table_get_type" glib:type-struct="DbTableIface">
-		<prerequisite name="GObject.Object"/>
+		<prerequisite name="GdaData.DbNamedObject"/>
 		<method name="iterator" c:identifier="gda_data_db_table_iterator">
 			<return-value transfer-ownership="full">
 				<type name="Gee.Iterator" c:type="GeeIterator*">
@@ -485,10 +469,7 @@
 		<property name="schema" writable="1" construct="1">
 			<type name="GdaData.DbSchema" c:type="GdaDataDbSchema*"/>
 		</property>
-		<property name="name" writable="1">
-			<type name="utf8" c:type="gchar*"/>
-		</property>
-		<property name="tables">
+		<property name="records">
 			<type name="Gee.Collection" c:type="GeeCollection*">
 				<type name="GdaData.DbRecord" c:type="GdaDataDbRecord*"/>
 			</type>
@@ -557,10 +538,10 @@
 		<property name="name" writable="1">
 			<type name="utf8" c:type="gchar*"/>
 		</property>
-		<property name="column-name" writable="1" construct-only="1">
+		<property name="column-name">
 			<type name="utf8" c:type="gchar*"/>
 		</property>
-		<property name="attributes" writable="1" construct-only="1">
+		<property name="attributes">
 			<type name="GdaData.DbFieldAttribute" c:type="GdaDataDbFieldAttribute"/>
 		</property>
 	</interface>
@@ -595,10 +576,7 @@
 		<member name="unused" c:identifier="GDA_DATA_DB_FIELD_ATTRIBUTE_UNUSED" value="1024"/>
 	</bitfield>
 	<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"/>
-		<property name="name" writable="1">
-			<type name="utf8" c:type="gchar*"/>
-		</property>
+		<prerequisite name="GdaData.DbNamedObject"/>
 		<property name="tables">
 			<type name="Gee.Collection" c:type="GeeCollection*">
 				<type name="GdaData.DbTable" c:type="GdaDataDbTable*"/>
diff --git a/libgda/data/IdField.vala b/libgda/data/IdField.vala
new file mode 100644
index 0000000..aaed39e
--- /dev/null
+++ b/libgda/data/IdField.vala
@@ -0,0 +1,30 @@
+/* -*- 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;
+
+namespace GdaData 
+{
+	public class IdField : Object
+	{
+		public string name { get; set; }
+		public G value { get; set; }
+		public G next (Gda.Connection cnn, DbTable table) {}
+	}
+}
diff --git a/libgda/data/Makefile.am b/libgda/data/Makefile.am
index 01c3a6b..587509c 100644
--- a/libgda/data/Makefile.am
+++ b/libgda/data/Makefile.am
@@ -32,6 +32,9 @@ VALAFLAGS = \
     $(NULL)
 
 object_persistance_sources = \
+	DataBase.vala \
+	Schema.vala \
+	Table.vala \
 	Record.vala \
 	RecordSingleId.vala \
 	SelectQuery.vala \
@@ -43,8 +46,11 @@ db_collection_sources = \
 	DbTable.vala \
 	DbRecord.vala \
 	DbField.vala \
+	DbFieldInfo.vala \
 	DbSchema.vala \
 	Field.vala \
+	FieldInfo.vala \
+	IdField.vala \
 	$(NULL)
 
 selectable_sources = \
diff --git a/libgda/data/RecordSingleId.vala b/libgda/data/RecordSingleId.vala
new file mode 100644
index 0000000..2261e48
--- /dev/null
+++ b/libgda/data/RecordSingleId.vala
@@ -0,0 +1,142 @@
+/* -*- 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;
+
+namespace GdaData {
+
+	public abstract class RecordSingleId : Record<Value?> 
+	{
+		private Value? _id_value;
+        
+        /**
+         * Field's name used as ID in the row
+         */
+        public abstract string field_id { get; }
+        /* 
+         * ID Field's default index, returned when an INSERT statement is used.
+         */
+        public abstract int field_id_index { get; }
+        
+        public Value get_id ()
+        {
+        	return this._id_value;
+        }
+        
+        /* 
+         * Set a condition to get only one row data from the table in the database.
+         */
+        public void set_id (Value v)
+        	throws Error
+        	requires (this.table != "")
+        {
+        	this._id_value = v;
+        	var q = this.sql ();
+        	var s = q.get_statement ();
+        	var m = this.connection.statement_execute_select (s, null);
+        	for (int r = 0; r < m.get_n_rows (); r++) {
+        		for (int c = 0; c < m.get_n_columns (); c++) {
+        			Gda.ValueAttribute attr = m.get_attributes_at (c, r);
+        			string col_name = m.get_column_name (c);
+        			var f = new Field<Value?> (col_name, (DbField.Attribute) attr);
+        			f.value = m.get_value_at (c, r);
+        			this._model.set (f.name, f);
+        		}
+        	}
+        }
+        
+        /**
+         * Returns a #SqlBuilder object with the query used to select the data in the used
+         * that points this object to.
+         */
+        public SqlBuilder sql ()
+        	requires (this.table != null || this.table != "")
+        	requires (this.field_id != null || this.field_id != "")
+        	requires (this._id_value != null)
+        {
+        	var q = new SqlBuilder (SqlStatementType.SELECT);
+        	q.select_add_target (this.table, null);
+        	var f_id = q.add_id (this.field_id);
+			var e_id = q.add_expr_value (null, this._id_value);
+			var c_id = q.add_cond (SqlOperatorType.EQ, f_id, e_id, 0);
+			q.set_where (c_id);
+			q.select_add_field ("*", null, null);
+			return q;			
+        }
+        
+        public override void save () throws Error
+        {
+        	var sql = new SqlBuilder (SqlStatementType.UPDATE);
+			sql.set_table (this.table);
+			foreach (Field<Value?> f in _model.values) {
+				sql.add_field_value_as_gvalue (f.column_name, f.value);
+			}
+			var f_id = sql.add_id (this.field_id);
+			var e_id = sql.add_expr_value (null, this._id_value);
+			var c_id = sql.add_cond (SqlOperatorType.EQ, f_id, e_id, 0);
+			sql.set_where (c_id);
+//			stdout.printf ("DEBUG: UPDATE statement to execute: \n"+ 
+//							(sql.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.APPEND ("Have been saved more or less rows than expected");
+			}
+        }
+        public override bool append () throws Error
+        {
+        	var sql = new SqlBuilder (SqlStatementType.INSERT);
+			sql.set_table (this.table);
+			// FIXME: MetaData is required
+			foreach (Field<Value?> f in _model.values) {
+				sql.add_field_value_as_gvalue (f.column_name, f.value);
+			}
+//			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.APPEND ("Have been added more or less rows than expected");
+			}
+			return true;
+        }
+		public override void update ()
+        	throws Error
+        	requires (this.table != "")
+        {
+        	set_id (this._id_value);
+        }
+        public override string to_string () 
+        {
+        	string r = "";
+			foreach (Field<Value?> f in this.fields) {
+				r += "|" + f.name;
+			}
+			r+="\n";
+			foreach (Field<Value?> f in this.fields) {
+				r += "|" + Gda.value_stringify (f.value);
+			}
+			r+="\n";
+			return r;
+        }
+	}
+}
diff --git a/libgda/data/Schema.vala b/libgda/data/Schema.vala
new file mode 100644
index 0000000..affa8c6
--- /dev/null
+++ b/libgda/data/Schema.vala
@@ -0,0 +1,51 @@
+/* -*- Mode: Vala; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * libgdadata
+ * 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 Gee;
+using Gda;
+
+namespace GdaData
+{
+	public class Schema : Object
+	{
+		public HashMap<string,DbTable> tables = new HashMap<string,DbTable> ();
+		// DbObject Interface
+		public Connection connection { get; set; }
+		public update () 
+		{
+			connection.update_meta_store (null); // FIXME: just update schemas
+			var store = connection.get_meta_store ();
+			tables.clear ();
+			var mt = store.extract (@"SELECT * FROM _tables WHERE schema_name = $name");
+			for (int r = 0; r < mt.get_n_rows (); r++) {
+				var t = new Table ();
+				t.connection = connection;
+				t.name = (string) mt.get_value_at (mt.get_column_index ("table_name"), r);
+				t.schema = (DbSchema) this;
+				tables.set (t.name, (DbTable) t);
+			}
+		}
+		public void save () {}
+		public void append () {}
+		// DbNamedObject Interface
+		public string name { get; set; }
+		// DbSchema Interface
+		public Collection<DbTable> tables { get { return tables.values; } }
+	}
+}
diff --git a/libgda/data/Table.vala b/libgda/data/Table.vala
new file mode 100644
index 0000000..bb76069
--- /dev/null
+++ b/libgda/data/Table.vala
@@ -0,0 +1,44 @@
+/* -*- Mode: Vala; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * libgdadata
+ * 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 Gee;
+using Gda;
+
+namespace GdaData
+{
+	public interface Table : Object
+	{
+		// DbObject Interface
+		public Connection connection { get; set; }
+		public void update ()
+		{
+			
+		}
+		// DbNamedObject Interface
+		public string name { get; set; }
+		
+		// DbTable Interface
+		public Collection<FieldInfo<G>> info_fields {}
+		public DbSchema schema { get; set; }
+//		public Collection<DbRecord> records { get; }
+//		public Collection<DbTable> fk_depends { get; }
+//		public Collection<DbTable> fk { get; }
+//		public Iterator<DbRecord> iterator ();
+	}
+}



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