[libgda] Implemented GdaData.Record.drop(). Updated GIR/VAPI files. * GdaData.Record.drop() implemented and p



commit 86078134646f894191aebc6794c937b93c544d13
Author: Daniel Espinosa <despinosa src gnome org>
Date:   Wed Feb 29 21:07:43 2012 -0600

    Implemented GdaData.Record.drop(). Updated GIR/VAPI files.
    * GdaData.Record.drop() implemented and pass Unit Tests
    * Updated VAPI for improvements in Vala 0.15.2

 configure.ac                    |    2 +-
 libgda/Gda-5.0.gir              |    3 --
 libgda/data/DbObject.vala       |    3 +-
 libgda/data/DbTable.vala        |    3 +-
 libgda/data/GdaData-5.0.gir     |    1 +
 libgda/data/Record.vala         |   46 +++++++++++++++++++++++++++++++++-
 libgda/libgda-5.0.vapi          |   52 ++++++++++++++++++--------------------
 tests/vala/CheckDataObject.vala |   25 ++++++++++++++++--
 8 files changed, 96 insertions(+), 39 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0effa14..6ff1d1b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -481,7 +481,7 @@ AC_ARG_ENABLE([vala-extensions],
 have_vala=no
 if test "x$found_introspection" = "xyes"
 then
-    VALA_MODULES="libvala-0.16 >= 0.15.1".
+    VALA_MODULES="libvala-0.16 >= 0.15.1"
     PKG_CHECK_MODULES(VALA, $VALA_MODULES,
     if test "$enable_vala" = "yes" -o "$enable_vala" = "auto"
 	then
diff --git a/libgda/Gda-5.0.gir b/libgda/Gda-5.0.gir
index 19fde7d..52a11af 100644
--- a/libgda/Gda-5.0.gir
+++ b/libgda/Gda-5.0.gir
@@ -7666,9 +7666,6 @@ gda_data_model_iter_get_value_at() will return %NULL when using an iterator.</do
                 transfer-ownership="none">
         <type name="gint"/>
       </property>
-      <property name="use-rdn" writable="1" transfer-ownership="none">
-        <type name="gboolean"/>
-      </property>
       <field name="object">
         <type name="GObject.Object" c:type="GObject"/>
       </field>
diff --git a/libgda/data/DbObject.vala b/libgda/data/DbObject.vala
index dc9f763..edbb223 100644
--- a/libgda/data/DbObject.vala
+++ b/libgda/data/DbObject.vala
@@ -38,7 +38,8 @@ namespace GdaData {
 	public errordomain DbObjectError {
     	APPEND,
     	UPDATE,
-    	SAVE
+    	SAVE,
+    	DROP
     }
 
 }
diff --git a/libgda/data/DbTable.vala b/libgda/data/DbTable.vala
index b21f648..a2f7153 100644
--- a/libgda/data/DbTable.vala
+++ b/libgda/data/DbTable.vala
@@ -67,7 +67,6 @@ namespace GdaData
 	
 	errordomain DbTableError {
 		READ_ONLY,
-		FIELD,
-		UPDATE
+		FIELD
 	}
 }
diff --git a/libgda/data/GdaData-5.0.gir b/libgda/data/GdaData-5.0.gir
index 52e747b..f2b07b9 100644
--- a/libgda/data/GdaData-5.0.gir
+++ b/libgda/data/GdaData-5.0.gir
@@ -15,6 +15,7 @@
 		<member name="append" c:identifier="GDA_DATA_DB_OBJECT_ERROR_APPEND" value="0"/>
 		<member name="update" c:identifier="GDA_DATA_DB_OBJECT_ERROR_UPDATE" value="1"/>
 		<member name="save" c:identifier="GDA_DATA_DB_OBJECT_ERROR_SAVE" value="2"/>
+		<member name="drop" c:identifier="GDA_DATA_DB_OBJECT_ERROR_DROP" value="3"/>
 	</enumeration>
 	<class name="DataBase" c:type="GdaDataDataBase" glib:type-name="GdaDataDataBase" glib:get-type="gda_data_data_base_get_type" glib:type-struct="DataBaseClass" parent="GObject.Object">
 		<implements name="GdaData.DbObject"/>
diff --git a/libgda/data/Record.vala b/libgda/data/Record.vala
index b1db7a5..a793ca1 100644
--- a/libgda/data/Record.vala
+++ b/libgda/data/Record.vala
@@ -1,7 +1,7 @@
 /* -*- Mode: Vala; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
 /*
  * libgdavala
- * Copyright (C) Daniel Espinosa Ortiz 2011 <esodan gmail com>
+ * Copyright (C) Daniel Espinosa Ortiz 2012 <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
@@ -30,15 +30,19 @@ namespace GdaData {
          * 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> fields { owned get { return _fields.values; } }
+        
         public Collection<DbField> 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.
          */
@@ -48,6 +52,7 @@ namespace GdaData {
         	var f = this._fields.get (field);
         	return f.value;
         }
+        
 		/**
          * Set the value to a field with the given @name.
          */
@@ -66,16 +71,19 @@ namespace GdaData {
         	}
         	
         }
+        
         public void set_field_value (string field, Value? val) throws Error
         {
         	var n = new Field (field, DbField.Attribute.NONE); 
     		n.value = val;
     		this.set_field (n);
         }
+        
         public DbField get_field (string name) throws Error
         {
         	return _fields.get (name);
         }
+        
         public void set_key (DbField field)
         {
         	if (_keys.has_key (field.name)) {
@@ -90,16 +98,19 @@ namespace GdaData {
         		_keys.set (field.name, n);
         	}
         }
+        
         public void set_key_value (string key, Value? val) throws Error
         {
         	var n = new Field (key, DbField.Attribute.NONE); 
     		n.value = val;
     		this.set_key (n);
         }
+        
         public DbField get_key (string name) throws Error
         {
         	return _keys.get (name);
         }
+        
         /**
          * Saves any modficiation made to in memory representation of the data directly to
          * the database.
@@ -135,6 +146,7 @@ namespace GdaData {
 				throw new DbObjectError.SAVE ("Have been saved more or less rows than expected");
 			}
         }
+        
         /**
          * Updates values stored in database.
          */
@@ -174,6 +186,7 @@ namespace GdaData {
 				this.set_field (f);
 			}
         }
+        
         /**
          * 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.
@@ -197,7 +210,36 @@ namespace GdaData {
 				throw new DbObjectError.UPDATE ("Have been updated more or less rows than expected");
 			}
 		}
-		public void drop (bool cascade) throws Error {}
+		
+		public void drop (bool cascade) throws Error 
+		{
+			if (keys.size <= 0)
+        		throw new DbObjectError.DROP ("No keys has been set");
+			var sql = new SqlBuilder (SqlStatementType.DELETE);
+			sql.set_table (table.name);
+			SqlBuilderId cond = -1;
+			int pn = 0;
+        	foreach (DbField f in keys) {
+				var fid = sql.add_id (f.column_name);
+				var vid = sql.add_expr_value (null, f.value);
+				var c_id = sql.add_cond (SqlOperatorType.EQ, fid, vid, 0);
+				if (cond == -1) {
+					cond = c_id;
+				}
+				else {
+					cond = sql.add_cond (SqlOperatorType.AND, cond, c_id, 0);
+				}
+			}
+			sql.set_where (cond);
+			stdout.printf ("DEBUG: DELETE 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.DROP ("Have been dropped more or less rows than expected");
+			}
+		}
         // 
         public string to_string ()
         {
diff --git a/libgda/libgda-5.0.vapi b/libgda/libgda-5.0.vapi
index 97bfad9..c4cb918 100644
--- a/libgda/libgda-5.0.vapi
+++ b/libgda/libgda-5.0.vapi
@@ -149,7 +149,7 @@ namespace Gda {
 		public unowned Gda.ServerProvider get_provider ();
 		public unowned string get_provider_name ();
 		public unowned Gda.TransactionStatus get_transaction_status ();
-		public bool insert_row_into_table_v (string table, GLib.SList<string> col_names, GLib.SList<GLib.Value> values) throws GLib.Error;
+		public bool insert_row_into_table_v (string table, GLib.SList<string> col_names, GLib.SList<GLib.Value?> values) throws GLib.Error;
 		public bool is_opened ();
 		public bool open () throws GLib.Error;
 		public static Gda.Connection open_from_dsn (string dsn, string? auth_string, Gda.ConnectionOptions options) throws GLib.Error;
@@ -171,7 +171,7 @@ namespace Gda {
 		public static void string_split (string string, string out_cnc_params, string out_provider, string out_username, string out_password);
 		public bool supports_feature (Gda.ConnectionFeature feature);
 		public bool update_meta_store (Gda.MetaContext? context) throws GLib.Error;
-		public bool update_row_in_table_v (string table, string condition_column_name, GLib.Value condition_value, GLib.SList<string> col_names, GLib.SList<GLib.Value> values) throws GLib.Error;
+		public bool update_row_in_table_v (string table, string condition_column_name, GLib.Value condition_value, GLib.SList<string> col_names, GLib.SList<GLib.Value?> values) throws GLib.Error;
 		public string value_to_sql_string (GLib.Value from);
 		[NoAccessorMethod]
 		public string auth_string { owned get; set; }
@@ -335,8 +335,6 @@ namespace Gda {
 		public string filter { owned get; construct; }
 		[NoAccessorMethod]
 		public int scope { get; construct; }
-		[NoAccessorMethod]
-		public bool use_rdn { get; set; }
 	}
 	[CCode (cheader_filename = "libgda/libgda.h", type_id = "gda_data_pivot_get_type ()")]
 	public class DataPivot : GLib.Object, Gda.DataModel {
@@ -373,7 +371,7 @@ namespace Gda {
 		public int get_sample_size ();
 		public int get_sample_start ();
 		public Gda.ValueAttribute get_value_attributes (int proxy_row, int col);
-		public GLib.SList<weak GLib.Value> get_values (int proxy_row, [CCode (array_length = false)] int[] cols_index, int n_cols);
+		public GLib.SList<weak GLib.Value?> get_values (int proxy_row, [CCode (array_length = false)] int[] cols_index, int n_cols);
 		public bool has_changed ();
 		public bool is_read_only ();
 		public bool row_has_changed (int proxy_row);
@@ -609,7 +607,7 @@ namespace Gda {
 		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 ();
 		[CCode (cname = "gda_meta_store_extract_v")]
-		public Gda.DataModel extract (string select_sql, GLib.HashTable<string,GLib.Value>? vars) throws GLib.Error;
+		public Gda.DataModel extract (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 ();
@@ -1286,22 +1284,22 @@ namespace Gda {
 		public bool trylock ();
 		public void unlock ();
 	}
-	[CCode (cheader_filename = "libgda/libgda.h")]
+	[CCode (cheader_filename = "libgda/libgda.h", has_type_id = false)]
 	public struct DataMetaWrapper {
 		public weak GLib.Object object;
 	}
-	[CCode (cheader_filename = "libgda/libgda.h")]
+	[CCode (cheader_filename = "libgda/libgda.h", has_type_id = false)]
 	public struct DataMetaWrapperClass {
 		public weak GLib.ObjectClass parent_class;
 	}
-	[CCode (cheader_filename = "libgda/libgda.h")]
+	[CCode (cheader_filename = "libgda/libgda.h", has_type_id = false)]
 	public struct Diff {
 		public Gda.DiffType type;
 		public int old_row;
 		public int new_row;
 		public weak GLib.HashTable<void*,void*> values;
 	}
-	[CCode (cheader_filename = "libgda/libgda.h")]
+	[CCode (cheader_filename = "libgda/libgda.h", has_type_id = false)]
 	public struct DsnInfo {
 		public weak string name;
 		public weak string provider;
@@ -1310,7 +1308,7 @@ namespace Gda {
 		public weak string auth_string;
 		public bool is_system;
 	}
-	[CCode (cheader_filename = "libgda/libgda.h")]
+	[CCode (cheader_filename = "libgda/libgda.h", has_type_id = false)]
 	public struct MetaDbObject {
 		public Gda.MetaDbObjectType obj_type;
 		public bool outdated;
@@ -1326,12 +1324,12 @@ namespace Gda {
 		[CCode (cname = "extra.meta_view")]
 		public Gda.MetaView extra_meta_view;
 	}
-	[CCode (cheader_filename = "libgda/libgda.h")]
+	[CCode (cheader_filename = "libgda/libgda.h", has_type_id = false)]
 	public struct MetaStoreChange {
 		public Gda.MetaStoreChangeType c_type;
 		public weak string table_name;
 	}
-	[CCode (cheader_filename = "libgda/libgda.h")]
+	[CCode (cheader_filename = "libgda/libgda.h", has_type_id = false)]
 	public struct MetaTable {
 		public GLib.List<Gda.MetaTableColumn> columns;
 		public int pk_cols_array;
@@ -1339,7 +1337,7 @@ namespace Gda {
 		public GLib.List<Gda.MetaTableForeignKey> reverse_fk_list;
 		public GLib.List<Gda.MetaTableForeignKey> fk_list;
 	}
-	[CCode (cheader_filename = "libgda/libgda.h")]
+	[CCode (cheader_filename = "libgda/libgda.h", has_type_id = false)]
 	public struct MetaTableColumn {
 		public weak string column_name;
 		public weak string column_type;
@@ -1351,7 +1349,7 @@ namespace Gda {
 		public GLib.Value get_attribute (string attribute);
 		public void set_attribute (string attribute, GLib.Value? value, GLib.DestroyNotify? destroy);
 	}
-	[CCode (cheader_filename = "libgda/libgda.h")]
+	[CCode (cheader_filename = "libgda/libgda.h", has_type_id = false)]
 	public struct MetaTableForeignKey {
 		public Gda.MetaDbObject meta_table;
 		public Gda.MetaDbObject depend_on;
@@ -1362,13 +1360,13 @@ namespace Gda {
 		public weak string ref_pk_names_array;
 		public weak string fk_name;
 	}
-	[CCode (cheader_filename = "libgda/libgda.h")]
+	[CCode (cheader_filename = "libgda/libgda.h", has_type_id = false)]
 	public struct MetaView {
 		public Gda.MetaTable table;
 		public weak string view_def;
 		public bool is_updatable;
 	}
-	[CCode (cheader_filename = "libgda/libgda.h")]
+	[CCode (cheader_filename = "libgda/libgda.h", has_type_id = false)]
 	public struct ProviderInfo {
 		public weak string id;
 		public weak string location;
@@ -1376,24 +1374,24 @@ namespace Gda {
 		public weak Gda.Set dsn_params;
 		public weak Gda.Set auth_params;
 	}
-	[CCode (cheader_filename = "libgda/libgda.h")]
+	[CCode (cheader_filename = "libgda/libgda.h", has_type_id = false)]
 	public struct ServerProviderHandlerInfo {
 		public weak Gda.Connection cnc;
 		public GLib.Type g_type;
 		public weak string dbms_type;
 	}
-	[CCode (cheader_filename = "libgda/libgda.h")]
+	[CCode (cheader_filename = "libgda/libgda.h", has_type_id = false)]
 	public struct SetGroup {
 		public GLib.List<Gda.SetNode> nodes;
 		public Gda.SetSource nodes_source;
 	}
-	[CCode (cheader_filename = "libgda/libgda.h")]
+	[CCode (cheader_filename = "libgda/libgda.h", has_type_id = false)]
 	public struct SetNode {
 		public weak Gda.Holder holder;
 		public weak Gda.DataModel source_model;
 		public int source_column;
 	}
-	[CCode (cheader_filename = "libgda/libgda.h")]
+	[CCode (cheader_filename = "libgda/libgda.h", has_type_id = false)]
 	public struct SetSource {
 		public weak Gda.DataModel data_model;
 		public GLib.List<Gda.SetNode> nodes;
@@ -1402,7 +1400,7 @@ namespace Gda {
 	[SimpleType]
 	public struct SqlBuilderId : uint {
 	}
-	[CCode (cheader_filename = "libgda/libgda.h")]
+	[CCode (cheader_filename = "libgda/libgda.h", has_type_id = false)]
 	public struct SqlRenderingContext {
 		public Gda.StatementSqlFlag flags;
 		public weak Gda.Set @params;
@@ -1411,12 +1409,12 @@ namespace Gda {
 		public weak Gda.Connection cnc;
 		public weak Gda.SqlRenderingValue render_value;
 	}
-	[CCode (cheader_filename = "libgda/libgda.h")]
+	[CCode (cheader_filename = "libgda/libgda.h", has_type_id = false)]
 	public struct ThreadNotification {
 		public Gda.ThreadNotificationType type;
 		public uint job_id;
 	}
-	[CCode (cheader_filename = "libgda/libgda.h")]
+	[CCode (cheader_filename = "libgda/libgda.h", has_type_id = false)]
 	public struct TransactionStatusEvent {
 		public weak Gda.TransactionStatus trans;
 		public Gda.TransactionStatusEventType type;
@@ -1428,7 +1426,7 @@ namespace Gda {
 		[CCode (cname = "pl.sub_trans")]
 		public weak Gda.TransactionStatus pl_sub_trans;
 	}
-	[CCode (cheader_filename = "libgda/libgda.h")]
+	[CCode (cheader_filename = "libgda/libgda.h", has_type_id = false)]
 	public struct XaTransactionId {
 		public uint32 format;
 		public ushort gtrid_length;
@@ -1437,7 +1435,7 @@ namespace Gda {
 		public weak char[] data;
 		public string to_string ();
 	}
-	[CCode (cheader_filename = "libgda/libgda.h", cname = "_GdaServerOperationNode")]
+	[CCode (cheader_filename = "libgda/libgda.h", cname = "_GdaServerOperationNode", has_type_id = false)]
 	public struct _ServerOperationNode {
 		public Gda.ServerOperationNodeType type;
 		public Gda.ServerOperationNodeStatus status;
@@ -1446,7 +1444,7 @@ namespace Gda {
 		public weak Gda.Column column;
 		public weak Gda.Holder param;
 	}
-	[CCode (cheader_filename = "libgda/libgda.h", cname = "_GdaSqlParserIface")]
+	[CCode (cheader_filename = "libgda/libgda.h", cname = "_GdaSqlParserIface", has_type_id = false)]
 	public struct _SqlParserIface {
 		public weak Gda.SqlParser parser;
 		public weak Gda.SqlStatement parsed_statement;
diff --git a/tests/vala/CheckDataObject.vala b/tests/vala/CheckDataObject.vala
index aa81858..6fee176 100644
--- a/tests/vala/CheckDataObject.vala
+++ b/tests/vala/CheckDataObject.vala
@@ -200,7 +200,7 @@ namespace Check {
 		public int t2()
 			throws Error
 		{
-			stdout.printf(">>> NEW TEST: Gda.DbRecord - Adding new objects to DB...\n");
+			stdout.printf(">>> NEW TEST: Gda.DbRecord - Adding/Deleting objects to DB...\n");
 			int fails = 0;
 			try {
 				var n = new Check.Record ();
@@ -220,9 +220,28 @@ namespace Check {
 				stdout.printf("%s\n", n.to_string());
 				n.append ();
 				var m = n.connection.execute_select_command ("SELECT * FROM user");
-				if (m.get_n_rows () != 3) fails++;
 				stdout.printf ("All records:\n" + m.dump_as_string () + "\n");
-				stdout.printf("PASS\n");
+				if (m.get_n_rows () != 3) {
+					fails++;
+					stdout.printf("FAIL\n");
+				}
+				else
+					stdout.printf("PASS\n");
+				// Delete an object from database
+				var r = new Check.Record ();
+				r.connection = this.connection;
+				r.table = t;
+				r.set_key_value ("id", 3);
+				r.drop (false);
+				var m2 = n.connection.execute_select_command ("SELECT * FROM user");
+				stdout.printf ("All records:\n" + m2.dump_as_string () + "\n");
+				if (m2.get_n_rows () != 2) {
+					fails++;
+					stdout.printf("FAIL\n");
+				}
+				else
+					stdout.printf("PASS\n");
+				
 			}
 			catch (Error e) {
 				fails++;



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