[gnome-db] New patch: add getCommandType and getCommandText to Recordset
- From: Gonzalo Paniagua Javier <gonzalo gnome-db org>
- To: Gnome-db list <gnome-db-list gnome org>
- Subject: [gnome-db] New patch: add getCommandType and getCommandText to Recordset
- Date: Tue, 22 Jan 2002 04:32:53 +0100
Hi!
This patch do what the subject says. Moreover, includes changes
to the postgres provider and the gda-test to make the changes
done in IDL+libgda show that they are working.
When the patch gets approved I will add doc-comments to
gda-recordset and gda-server-recordset.
Bye!
--
Gonzalo Paniagua Javier <gonzalo gnome-db org>
http://www.gnome-db.org/~gonzalo/
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/libgda/ChangeLog,v
retrieving revision 1.118
diff -u -r1.118 ChangeLog
--- ChangeLog 2002/01/21 00:49:32 1.118
+++ ChangeLog 2002/01/22 03:21:40
@@ -1,3 +1,22 @@
+2002-01-22 Gonzalo Paniagua Javier <gonzalo gnome-db org>
+
+ * idl/GNOME_Database.idl: moved declarations of Command* before
+ Recordset. Added getCommandText() and getCommandType() to the
+ Recordset interface.
+
+ * libgda/gda-recordset.[ch] (gda_recordset_command_type):
+ (gda_recordset_command_text): new functions to retrieve the text and
+ type of the query that generated the recordset.
+
+ * libgda/gda-server-recordset.[ch] (impl_Recordset_getCommandText):
+ (impl_Recordset_getCommandType): new functions.
+
+ * providers/postgres/gda-postgres-provider.c (process_sql_commands):
+ sets the command type and text for each recordset.
+
+ * testing/models.c (display_recordset_data): display the type and text
+ of the query. Now it works for postgres provider.
+
2002-01-21 Gonzalo Paniagua Javier <gonzalo gnome-db org>
* idl/GNOME_Database.idl:
Index: idl/GNOME_Database.idl
===================================================================
RCS file: /cvs/gnome/libgda/idl/GNOME_Database.idl,v
retrieving revision 1.19
diff -u -r1.19 GNOME_Database.idl
--- idl/GNOME_Database.idl 2002/01/21 00:49:33 1.19
+++ idl/GNOME_Database.idl 2002/01/22 03:21:40
@@ -83,6 +83,31 @@
};
/*
+ * The Command struct contains information about a
+ * command to be executed on the server
+ */
+ typedef long CommandOptions;
+ const CommandOptions IGNORE_ERRORS = 1;
+ const CommandOptions STOP_ON_ERRORS = 1 << 1;
+ const CommandOptions BAD_OPTION = 1 << 2;
+ const CommandOptions DEFAULT_OPTION = 1 << 1;
+
+
+ enum CommandType {
+ COMMAND_TYPE_SQL,
+ COMMAND_TYPE_XML,
+ COMMAND_TYPE_PROCEDURE,
+ COMMAND_TYPE_TABLE,
+ COMMAND_TYPE_INVALID
+ };
+
+ struct Command {
+ string text;
+ CommandType type;
+ CommandOptions options;
+ };
+
+ /*
* The Recordset interface contains all information
* about a set of rows returned by the underlying
* provider as a result of executing a command
@@ -104,6 +129,8 @@
interface Recordset : Bonobo::Unknown {
RowAttributes describe () raises (DriverError);
long getRowCount ();
+ string getCommandText ();
+ CommandType getCommandType ();
boolean moveFirst () raises (DriverError);
boolean moveNext () raises (DriverError);
@@ -113,31 +140,6 @@
Row fetch () raises (DriverError);
};
typedef sequence<Recordset> RecordsetList;
-
- /*
- * The Command struct contains information about a
- * command to be executed on the server
- */
- typedef long CommandOptions;
- const CommandOptions IGNORE_ERRORS = 1;
- const CommandOptions STOP_ON_ERRORS = 1 << 1;
- const CommandOptions BAD_OPTION = 1 << 2;
- const CommandOptions DEFAULT_OPTION = 1 << 1;
-
-
- enum CommandType {
- COMMAND_TYPE_SQL,
- COMMAND_TYPE_XML,
- COMMAND_TYPE_PROCEDURE,
- COMMAND_TYPE_TABLE,
- COMMAND_TYPE_INVALID
- };
-
- struct Command {
- string text;
- CommandType type;
- CommandOptions options;
- };
/*
* The Client interface is implemented by GDA clients,
Index: libgda/gda-recordset.c
===================================================================
RCS file: /cvs/gnome/libgda/libgda/gda-recordset.c,v
retrieving revision 1.9
diff -u -r1.9 gda-recordset.c
--- libgda/gda-recordset.c 2002/01/15 16:23:38 1.9
+++ libgda/gda-recordset.c 2002/01/22 03:21:40
@@ -37,6 +37,8 @@
gint row_count;
gboolean load_completed;
+ gchar *cmd_text;
+ GdaCommandType cmd_type;
};
static void gda_recordset_class_init (GdaRecordsetClass *klass);
@@ -204,6 +206,8 @@
recset->priv->timeout_id = -1;
recset->priv->row_count = -1;
recset->priv->load_completed = FALSE;
+ recset->priv->cmd_text = NULL;
+ recset->priv->cmd_type = GDA_COMMAND_TYPE_INVALID;
}
static void
@@ -228,12 +232,28 @@
if (recset->priv->attributes != NULL)
CORBA_free (recset->priv->attributes);
+ if (recset->priv->cmd_text != NULL)
+ CORBA_free (recset->priv->cmd_text);
+
g_free (recset->priv);
recset->priv = NULL;
parent_class->finalize (object);
}
+const gchar *
+gda_recordset_get_command_text (GdaRecordset *recset) {
+ g_return_val_if_fail (GDA_IS_RECORDSET (recset), NULL);
+ return recset->priv->cmd_text;
+}
+
+GdaCommandType
+gda_recordset_get_command_type (GdaRecordset *recset) {
+ g_return_val_if_fail (GDA_IS_RECORDSET (recset), GDA_COMMAND_TYPE_INVALID);
+ return recset->priv->cmd_type;
+
+}
+
/**
* gda_recordset_new:
* @corba_recset: a GNOME_Database_Recordset object
@@ -295,6 +315,12 @@
recset->priv->load_completed = TRUE;
}
+
+ recset->priv->cmd_text = GNOME_Database_Recordset_getCommandText (
+ recset->priv->corba_recset, &ev);
+
+ recset->priv->cmd_type = GNOME_Database_Recordset_getCommandType (
+ recset->priv->corba_recset, &ev);
return recset;
}
Index: libgda/gda-recordset.h
===================================================================
RCS file: /cvs/gnome/libgda/libgda/gda-recordset.h,v
retrieving revision 1.6
diff -u -r1.6 gda-recordset.h
--- libgda/gda-recordset.h 2002/01/11 16:37:48 1.6
+++ libgda/gda-recordset.h 2002/01/22 03:21:40
@@ -53,6 +53,9 @@
GdaRecordset *gda_recordset_new (GdaConnection *cnc,
GNOME_Database_Recordset corba_recset);
+const gchar *gda_recordset_get_command_text (GdaRecordset *recset);
+GdaCommandType gda_recordset_get_command_type (GdaRecordset *recset);
+
G_END_DECLS
#endif
Index: libgda/gda-server-recordset.c
===================================================================
RCS file: /cvs/gnome/libgda/libgda/gda-server-recordset.c,v
retrieving revision 1.12
diff -u -r1.12 gda-server-recordset.c
--- libgda/gda-server-recordset.c 2002/01/14 15:00:53 1.12
+++ libgda/gda-server-recordset.c 2002/01/22 03:21:41
@@ -23,6 +23,7 @@
#include <bonobo/bonobo-exception.h>
#include <bonobo/bonobo-i18n.h>
#include <libgda/gda-server-recordset.h>
+#include <libgda/gda-command.h>
#define PARENT_TYPE BONOBO_OBJECT_TYPE
@@ -34,6 +35,8 @@
glong current_pos;
gboolean is_eof;
GPtrArray *rows;
+ gchar *cmd_text;
+ GdaCommandType cmd_type;
};
static void gda_server_recordset_class_init (GdaServerRecordsetClass *klass);
@@ -210,6 +213,34 @@
return row;
}
+static CORBA_string
+impl_Recordset_getCommandText (PortableServer_Servant servant,
+ CORBA_Environment *ev)
+{
+ const gchar *string;
+
+ GdaServerRecordset *recset = (GdaServerRecordset *)
+ bonobo_object (servant);
+
+ bonobo_return_val_if_fail (GDA_IS_SERVER_RECORDSET (recset),
+ NULL, ev);
+
+ string = gda_server_recordset_get_command_text (recset);
+ return CORBA_string_dup (string ? string : "");
+}
+
+static GdaCommandType
+impl_Recordset_getCommandType (PortableServer_Servant servant,
+ CORBA_Environment *ev)
+{
+ GdaServerRecordset *recset = (GdaServerRecordset *) bonobo_object (servant);
+
+ bonobo_return_val_if_fail (GDA_IS_SERVER_RECORDSET (recset),
+ GDA_COMMAND_TYPE_INVALID, ev);
+
+ return gda_server_recordset_get_command_type (recset);
+}
+
/*
* GdaServerRecordset class implementation
*/
@@ -233,6 +264,8 @@
epv->movePrevious = impl_Recordset_movePrevious;
epv->moveLast = impl_Recordset_moveLast;
epv->fetch = impl_Recordset_fetch;
+ epv->getCommandText = impl_Recordset_getCommandText;
+ epv->getCommandType = impl_Recordset_getCommandType;
}
static void
@@ -247,6 +280,8 @@
recset->priv->current_pos = 0;
recset->priv->is_eof = FALSE;
recset->priv->rows = g_ptr_array_new ();
+ recset->priv->cmd_text = NULL;
+ recset->priv->cmd_type = GDA_COMMAND_TYPE_INVALID;
}
static void
@@ -266,6 +301,9 @@
gda_row_free (row);
}
g_ptr_array_free (recset->priv->rows, TRUE);
+
+ if (recset->priv->cmd_text)
+ g_free (recset->priv->cmd_text);
g_free (recset->priv);
recset->priv = NULL;
@@ -342,3 +380,52 @@
g_return_if_fail (GDA_IS_SERVER_RECORDSET (recset));
recset->priv->desc_func = func;
}
+
+/**
+ * gda_server_recordset_get_command_text
+ */
+const gchar *
+gda_server_recordset_get_command_text (GdaServerRecordset *recset)
+{
+ g_return_val_if_fail (GDA_IS_SERVER_RECORDSET (recset), NULL);
+ return recset->priv->cmd_text;
+}
+
+/**
+ * gda_server_recordset_set_command_text
+ */
+void
+gda_server_recordset_set_command_text (GdaServerRecordset *recset,
+ const gchar *cmd_text)
+{
+ g_return_if_fail (GDA_IS_SERVER_RECORDSET (recset));
+ g_return_if_fail (cmd_text != NULL);
+
+ if (recset->priv->cmd_text)
+ g_free (recset->priv->cmd_text);
+
+ recset->priv->cmd_text = g_strdup (cmd_text);
+}
+
+/**
+ * gda_server_recordset_get_command_type
+ */
+GdaCommandType
+gda_server_recordset_get_command_type (GdaServerRecordset *recset)
+{
+ g_return_val_if_fail (GDA_IS_SERVER_RECORDSET (recset),
+ GDA_COMMAND_TYPE_INVALID);
+ return recset->priv->cmd_type;
+}
+
+/**
+ * gda_server_recordset_set_command_type
+ */
+void
+gda_server_recordset_set_command_type (GdaServerRecordset *recset,
+ GdaCommandType cmd_type)
+{
+ g_return_if_fail (GDA_IS_SERVER_RECORDSET (recset));
+ recset->priv->cmd_type = cmd_type;
+}
+
Index: libgda/gda-server-recordset.h
===================================================================
RCS file: /cvs/gnome/libgda/libgda/gda-server-recordset.h,v
retrieving revision 1.8
diff -u -r1.8 gda-server-recordset.h
--- libgda/gda-server-recordset.h 2002/01/14 15:00:53 1.8
+++ libgda/gda-server-recordset.h 2002/01/22 03:21:41
@@ -24,6 +24,7 @@
# define __gda_server_recordset_h__
#include <libgda/gda-row.h>
+#include <libgda/gda-command.h>
#include <libgda/gda-server-connection.h>
#include <bonobo/bonobo-xobject.h>
@@ -63,6 +64,13 @@
GdaServerRecordsetFetchFunc func);
void gda_server_recordset_set_describe_func (GdaServerRecordset *recset,
GdaServerRecordsetDescribeFunc func);
+
+const gchar *gda_server_recordset_get_command_text (GdaServerRecordset *recset);
+void gda_server_recordset_set_command_text (GdaServerRecordset *recset,
+ const gchar *cmd_text);
+GdaCommandType gda_server_recordset_get_command_type (GdaServerRecordset *recset);
+void gda_server_recordset_set_command_type (GdaServerRecordset *recset,
+ GdaCommandType cmd_type);
G_END_DECLS
Index: providers/postgres/gda-postgres-provider.c
===================================================================
RCS file: /cvs/gnome/libgda/providers/postgres/gda-postgres-provider.c,v
retrieving revision 1.9
diff -u -r1.9 gda-postgres-provider.c
--- providers/postgres/gda-postgres-provider.c 2002/01/21 00:49:36 1.9
+++ providers/postgres/gda-postgres-provider.c 2002/01/22 03:21:41
@@ -344,8 +344,11 @@
status == PGRES_TUPLES_OK ||
status == PGRES_COMMAND_OK) {
recset = gda_postgres_recordset_new (cnc, pg_res);
- if (GDA_IS_SERVER_RECORDSET (recset))
+ if (GDA_IS_SERVER_RECORDSET (recset)) {
+ gda_server_recordset_set_command_text (recset, arr[n]);
+ gda_server_recordset_set_command_type (recset, GDA_COMMAND_TYPE_SQL);
reclist = g_list_append (reclist, recset);
+ }
} else {
gda_server_connection_add_error (
cnc, gda_postgres_make_error (pconn));
Index: testing/models.c
===================================================================
RCS file: /cvs/gnome/libgda/testing/models.c,v
retrieving revision 1.5
diff -u -r1.5 models.c
--- testing/models.c 2002/01/14 23:40:15 1.5
+++ testing/models.c 2002/01/22 03:21:41
@@ -22,6 +22,34 @@
#include "models.h"
+static const char *
+command_type_to_string (GdaCommandType cmd_type)
+{
+ const gchar *type_name;
+
+ switch (cmd_type) {
+ case GDA_COMMAND_TYPE_SQL :
+ type_name = "SQL";
+ break;
+ case GDA_COMMAND_TYPE_XML :
+ type_name = "XML";
+ break;
+ case GDA_COMMAND_TYPE_PROCEDURE :
+ type_name = "PROCEDURE";
+ break;
+ case GDA_COMMAND_TYPE_TABLE :
+ type_name = "TABLE";
+ break;
+ case GDA_COMMAND_TYPE_INVALID :
+ type_name = "INVALID!";
+ break;
+ default:
+ type_name = "Unknown type.";
+ }
+
+ return type_name;
+}
+
/*
* display_recordset_data
* @model: a recordset with the data to display.
@@ -36,6 +64,8 @@
{
gint cols, rows;
gint c, r;
+ GdaCommandType cmd_type;
+ const gchar *cmd_text, *type_text;
g_return_if_fail (GDA_IS_RECORDSET (model));
@@ -44,6 +74,12 @@
g_print ("Displaying recordset %p, with %d columns and %d rows:\n",
model, cols, rows);
+
+ cmd_type = gda_recordset_get_command_type (GDA_RECORDSET (model));
+ type_text = command_type_to_string (cmd_type);
+ cmd_text = gda_recordset_get_command_text (GDA_RECORDSET (model));
+ g_print ("The query (type '%s') leading up to this result was:\n\t'%s'\n\n",
+ type_text, cmd_text ? cmd_text : "<null>");
for (r = 0; r < rows; r++) {
g_print ("\tRow %02d -------\n", r);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]