[libgda/LIBGDA_4.0] Gda-SQL: fixed a bug when saving statements



commit 4c4c4f186dcc377563ee69638be36894a6379033
Author: Vivien Malerba <malerba gnome-db org>
Date:   Fri Jun 5 22:19:30 2009 +0200

    Gda-SQL: fixed a bug when saving statements
    
    Saving SQL statements using the ".qs" internal command
    did not check if there was already one saved statement of the same
    name, resulting in errors; now any previous saved statement with
    the same name is first deleted.
---
 ChangeLog       |    5 +++++
 tools/gda-sql.c |   22 +++++++++++++++++++---
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index beb461f..7a0cbce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-06-05  Vivien Malerba <malerba gnome-db org>
+
+	* tools/gda-sql.c: overwrite any existing definition of a saved statement with
+	the same name when saving a new statement
+
 2009-06-04  Vivien Malerba <malerba gnome-db org>
 
 	* libgda/sqlite/gda-sqlite-provider.c:
diff --git a/tools/gda-sql.c b/tools/gda-sql.c
index bf7aa3b..ba80235 100644
--- a/tools/gda-sql.c
+++ b/tools/gda-sql.c
@@ -3622,13 +3622,17 @@ extra_command_query_buffer_to_dict (SqlConsole *console, GdaConnection *cnc, con
 		}
 		
 		/* actual store of the statement */
-		static GdaStatement *ins_stmt = NULL;
+		static GdaStatement *ins_stmt = NULL, *del_stmt;
 		static GdaSet *ins_params = NULL;
 		if (!ins_stmt) {
 			ins_stmt = gda_sql_parser_parse_string (main_data->current->parser, 
 								QUERY_BUFFERS_TABLE_INSERT, NULL, NULL);
 			g_assert (ins_stmt);
 			g_assert (gda_statement_get_parameters (ins_stmt, &ins_params, NULL));
+
+			del_stmt = gda_sql_parser_parse_string (main_data->current->parser, 
+								QUERY_BUFFERS_TABLE_DELETE, NULL, NULL);
+			g_assert (del_stmt);
 		}
 
 		if (! gda_set_set_holder_value (ins_params, error, "name", qname) ||
@@ -3639,10 +3643,22 @@ extra_command_query_buffer_to_dict (SqlConsole *console, GdaConnection *cnc, con
 		g_free (qname);
 		
 		GdaConnection *store_cnc;
+		gboolean intrans;
 		store_cnc = gda_meta_store_get_internal_connection (mstore);
-		if (gda_connection_statement_execute_non_select (store_cnc, ins_stmt, ins_params,
-								 NULL, error) == -1)
+		intrans = gda_connection_begin_transaction (store_cnc, NULL,
+							    GDA_TRANSACTION_ISOLATION_UNKNOWN, NULL);
+
+		if ((gda_connection_statement_execute_non_select (store_cnc, del_stmt, ins_params,
+								  NULL, error) == -1) ||
+		    (gda_connection_statement_execute_non_select (store_cnc, ins_stmt, ins_params,
+								  NULL, error) == -1)) {
+			if (intrans)
+				gda_connection_rollback_transaction (store_cnc, NULL, NULL);
 			return NULL;
+		}
+		if (intrans)
+			gda_connection_commit_transaction (store_cnc, NULL, NULL);
+
 		res = g_new0 (GdaInternalCommandResult, 1);
 		res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
 	}



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