Re: [gnome-db] New patch. Closes bug #68577
- From: Gonzalo Paniagua Javier <gonzalo gnome-db org>
- To: Gnome-db list <gnome-db-list gnome org>
- Subject: Re: [gnome-db] New patch. Closes bug #68577
- Date: Thu, 17 Jan 2002 21:11:46 +0100
Here it is. Smaller than the preceding. Works ok.
I've also added documentation for gda-command.
Index: doc/C/ChangeLog
===================================================================
RCS file: /cvs/gnome/libgda/doc/C/ChangeLog,v
retrieving revision 1.23
diff -u -r1.23 ChangeLog
--- doc/C/ChangeLog 2002/01/15 12:36:58 1.23
+++ doc/C/ChangeLog 2002/01/17 20:05:43
@@ -1,3 +1,7 @@
+2002-01-17 Gonzalo Paniagua Javier <gonzalo gnome-db org>
+
+ * tmpl/gda-command.sgml: added documentation.
+
2002-01-15 Gonzalo Paniagua Javier <gonzalo gnome-db org>
* libgda-docs.sgml: added parameter information to the providers
Index: doc/C/tmpl/gda-command.sgml
===================================================================
RCS file: /cvs/gnome/libgda/doc/C/tmpl/gda-command.sgml,v
retrieving revision 1.2
diff -u -r1.2 gda-command.sgml
--- doc/C/tmpl/gda-command.sgml 2001/12/22 01:01:10 1.2
+++ doc/C/tmpl/gda-command.sgml 2002/01/17 20:05:43
@@ -2,10 +2,12 @@
gda-command
<!-- ##### SECTION Short_Description ##### -->
+Functions that deals with #GdaCommand.
-
<!-- ##### SECTION Long_Description ##### -->
<para>
+The #GdaCommand structure holds data needed to issue a command to the
+providers.
</para>
@@ -25,10 +27,12 @@
</para>
- GDA_COMMAND_TYPE_SQL:
+ GDA_COMMAND_TYPE_SQL: the text of the command is composed of zero or more SQL
+sentences.
@GDA_COMMAND_TYPE_XML:
@GDA_COMMAND_TYPE_PROCEDURE:
- GDA_COMMAND_TYPE_TABLE:
+ GDA_COMMAND_TYPE_TABLE: the text of the command is composed of zero or more
+table names.
@GDA_COMMAND_TYPE_INVALID:
<!-- ##### FUNCTION gda_command_new ##### -->
Index: idl/ChangeLog
===================================================================
RCS file: /cvs/gnome/libgda/idl/ChangeLog,v
retrieving revision 1.23
diff -u -r1.23 ChangeLog
--- idl/ChangeLog 2002/01/14 23:13:29 1.23
+++ idl/ChangeLog 2002/01/17 20:05:43
@@ -1,3 +1,8 @@
+2002-01-17 Gonzalo Paniagua Javier <gonzalo gnome-db org>
+
+ * GNOME_Database.idl: added enum CommandOption and new enum
+ CommandOption to Command.
+
2002-01-14 Rodrigo Moya <rodrigo gnome-db org>
* GNOME_Database.idl: added ValueList type
Index: idl/GNOME_Database.idl
===================================================================
RCS file: /cvs/gnome/libgda/idl/GNOME_Database.idl,v
retrieving revision 1.17
diff -u -r1.17 GNOME_Database.idl
--- idl/GNOME_Database.idl 2002/01/14 23:13:29 1.17
+++ idl/GNOME_Database.idl 2002/01/17 20:05:43
@@ -118,6 +118,12 @@
* The Command struct contains information about a
* command to be executed on the server
*/
+ enum CommandOption {
+ COMMAND_OPTION_IGNORE_ERRORS,
+ COMMAND_OPTION_STOP_ON_ERRORS,
+ COMMAND_OPTION_BAD_OPTION
+ };
+
enum CommandType {
COMMAND_TYPE_SQL,
COMMAND_TYPE_XML,
@@ -129,6 +135,7 @@
struct Command {
string text;
CommandType type;
+ CommandOption option;
};
/*
Index: libgda/ChangeLog
===================================================================
RCS file: /cvs/gnome/libgda/libgda/ChangeLog,v
retrieving revision 1.79
diff -u -r1.79 ChangeLog
--- libgda/ChangeLog 2002/01/15 20:12:52 1.79
+++ libgda/ChangeLog 2002/01/17 20:05:44
@@ -1,3 +1,9 @@
+2002-01-17 Gonzalo Paniagua Javier <gonzalo gnome-db org>
+
+ * gda-command.[ch]: added new GdaCommandOption member of GdaCommand
+ and get/set functions for it. Also added documentation for all the
+ functions.
+
2002-01-15 Gonzalo Paniagua Javier <gonzalo gnome-db org>
* gda-value.c: added documentation. Corrected changed parameter value
Index: libgda/gda-command.c
===================================================================
RCS file: /cvs/gnome/libgda/libgda/gda-command.c,v
retrieving revision 1.3
diff -u -r1.3 gda-command.c
--- libgda/gda-command.c 2002/01/11 16:37:47 1.3
+++ libgda/gda-command.c 2002/01/17 20:05:44
@@ -24,21 +24,34 @@
/**
* gda_command_new
+ * @text: the text of the command.
+ * @type: a #GdaCommandType value.
+ * @option: a #GdaCommandOption value.
+ *
+ * Creates a new #GdaCommand from the parameters that should be freed by
+ * calling #gda_command_free.
+ *
+ * Returns: a newly allocated #GdaCommand.
*/
GdaCommand *
-gda_command_new (const gchar *text, GdaCommandType type)
+gda_command_new (const gchar *text, GdaCommandType type,
+ GdaCommandOption option)
{
GdaCommand *cmd;
cmd = GNOME_Database_Command__alloc ();
gda_command_set_text (cmd, text);
gda_command_set_command_type (cmd, type);
+ gda_command_set_command_option (cmd, option);
return cmd;
}
/**
* gda_command_free
+ * @cmd: a #GdaCommand.
+ *
+ * Frees the resources allocated by #gda_command_new.
*/
void
gda_command_free (GdaCommand *cmd)
@@ -49,6 +62,11 @@
/**
* gda_command_get_text
+ * @cmd: a #GdaCommand.
+ *
+ * Get the command text held by @cmd.
+ *
+ * Returns: the command string of @cmd.
*/
const gchar *
gda_command_get_text (GdaCommand *cmd)
@@ -59,6 +77,10 @@
/**
* gda_command_set_text
+ * @cmd: a #GdaCommand
+ * @text: the command text.
+ *
+ * Sets the command text of @cmd.
*/
void
gda_command_set_text (GdaCommand *cmd, const gchar *text)
@@ -76,6 +98,11 @@
/**
* gda_command_get_command_type
+ * @cmd: a #GdaCommand.
+ *
+ * Gets the command type of @cmd.
+ *
+ * Returns: the command type of @cmd.
*/
GdaCommandType
gda_command_get_command_type (GdaCommand *cmd)
@@ -86,6 +113,10 @@
/**
* gda_command_set_command_type
+ * @cmd: a #GdaCommand
+ * @type: the command type.
+ *
+ * Sets the command type of @cmd.
*/
void
gda_command_set_command_type (GdaCommand *cmd, GdaCommandType type)
@@ -93,3 +124,35 @@
g_return_if_fail (cmd != NULL);
cmd->type = type;
}
+
+/**
+ * gda_command_get_command_option
+ * @cmd: a #GdaCommand.
+ *
+ * Gets the command option of @cmd.
+ *
+ * Returns: the command option of @cmd.
+ */
+GdaCommandOption
+gda_command_get_command_option (GdaCommand *cmd)
+{
+ g_return_val_if_fail (cmd != NULL, GDA_COMMAND_OPTION_BAD_OPTION);
+ return cmd->option;
+}
+
+/**
+ * gda_command_set_command_option
+ * @cmd: a #GdaCommand
+ * @option: the command option.
+ *
+ * Sets the command option of @cmd.
+ */
+void
+gda_command_set_command_option (GdaCommand *cmd, GdaCommandOption option)
+{
+ g_return_if_fail (cmd != NULL);
+ g_return_if_fail (option == GDA_COMMAND_OPTION_IGNORE_ERRORS ||
+ option == GDA_COMMAND_OPTION_STOP_ON_ERRORS);
+ cmd->option = option;
+}
+
Index: libgda/gda-command.h
===================================================================
RCS file: /cvs/gnome/libgda/libgda/gda-command.h,v
retrieving revision 1.4
diff -u -r1.4 gda-command.h
--- libgda/gda-command.h 2002/01/11 16:37:47 1.4
+++ libgda/gda-command.h 2002/01/17 20:05:44
@@ -29,6 +29,7 @@
G_BEGIN_DECLS
typedef GNOME_Database_Command GdaCommand;
+
typedef enum {
GDA_COMMAND_TYPE_SQL = GNOME_Database_COMMAND_TYPE_SQL,
GDA_COMMAND_TYPE_XML = GNOME_Database_COMMAND_TYPE_XML,
@@ -36,14 +37,26 @@
GDA_COMMAND_TYPE_TABLE = GNOME_Database_COMMAND_TYPE_TABLE,
GDA_COMMAND_TYPE_INVALID = GNOME_Database_COMMAND_TYPE_INVALID
} GdaCommandType;
+
+typedef enum {
+ GDA_COMMAND_OPTION_IGNORE_ERRORS =
+ GNOME_Database_COMMAND_OPTION_IGNORE_ERRORS,
+ GDA_COMMAND_OPTION_STOP_ON_ERRORS =
+ GNOME_Database_COMMAND_OPTION_STOP_ON_ERRORS,
+ GDA_COMMAND_OPTION_BAD_OPTION =
+ GNOME_Database_COMMAND_OPTION_BAD_OPTION
+} GdaCommandOption;
-GdaCommand *gda_command_new (const gchar *text, GdaCommandType type);
+GdaCommand *gda_command_new (const gchar *text, GdaCommandType type,
+ GdaCommandOption option);
void gda_command_free (GdaCommand *cmd);
const gchar *gda_command_get_text (GdaCommand *cmd);
void gda_command_set_text (GdaCommand *cmd, const gchar *text);
GdaCommandType gda_command_get_command_type (GdaCommand *cmd);
void gda_command_set_command_type (GdaCommand *cmd, GdaCommandType type);
+GdaCommandOption gda_command_get_command_option (GdaCommand *cmd);
+void gda_command_set_command_option (GdaCommand *cmd, GdaCommandOption option);
G_END_DECLS
Index: providers/postgres/ChangeLog
===================================================================
RCS file: /cvs/gnome/libgda/providers/postgres/ChangeLog,v
retrieving revision 1.12
diff -u -r1.12 ChangeLog
--- providers/postgres/ChangeLog 2002/01/15 01:53:25 1.12
+++ providers/postgres/ChangeLog 2002/01/17 20:05:44
@@ -1,3 +1,7 @@
+2002-01-17 Gonzalo Paniagua Javier <gonzalo gnome-db org>
+
+ * gda-postgres-provider.c: added support for GdaCommandOption.
+
2002-01-15 Gonzalo Paniagua Javier <gonzalo gnome-db org>
* gda-postgres-provider.c:
Index: providers/postgres/gda-postgres-provider.c
===================================================================
RCS file: /cvs/gnome/libgda/providers/postgres/gda-postgres-provider.c,v
retrieving revision 1.7
diff -u -r1.7 gda-postgres-provider.c
--- providers/postgres/gda-postgres-provider.c 2002/01/15 01:53:25 1.7
+++ providers/postgres/gda-postgres-provider.c 2002/01/17 20:05:45
@@ -305,7 +305,8 @@
}
static GList *
-process_sql_commands (GList *reclist, GdaServerConnection *cnc, const gchar *sql)
+process_sql_commands (GList *reclist, GdaServerConnection *cnc, const gchar *sql,
+ GdaCommandOption option)
{
GdaPostgresConnectionPrivate *priv_data;
PGconn *pconn;
@@ -339,7 +340,8 @@
}
status = PQresultStatus(pg_res);
- if (status == PGRES_TUPLES_OK ||
+ if (option == GDA_COMMAND_OPTION_IGNORE_ERRORS ||
+ status == PGRES_TUPLES_OK ||
status == PGRES_COMMAND_OK) {
recset = gda_postgres_recordset_new (cnc, pg_res);
if (GDA_IS_SERVER_RECORDSET (recset))
@@ -372,18 +374,21 @@
GList *reclist = NULL;
gchar *str;
GdaPostgresProvider *pg_prv = (GdaPostgresProvider *) provider;
+ GdaCommandOption option;
g_return_val_if_fail (GDA_IS_POSTGRES_PROVIDER (pg_prv), NULL);
g_return_val_if_fail (GDA_IS_SERVER_CONNECTION (cnc), NULL);
g_return_val_if_fail (cmd != NULL, NULL);
+ option = gda_command_get_command_option (cmd);
switch (gda_command_get_command_type (cmd)) {
case GDA_COMMAND_TYPE_SQL :
- reclist = process_sql_commands (reclist, cnc, gda_command_get_text (cmd));
+ reclist = process_sql_commands (reclist, cnc, gda_command_get_text (cmd),
+ option);
break;
case GDA_COMMAND_TYPE_TABLE :
str = g_strdup_printf ("SELECT * FROM %s", gda_command_get_text (cmd));
- reclist = process_sql_commands (reclist, cnc, str);
+ reclist = process_sql_commands (reclist, cnc, str, option);
g_free (str);
break;
default:
@@ -489,7 +494,8 @@
g_return_val_if_fail (GDA_IS_SERVER_CONNECTION (cnc), NULL);
reclist = process_sql_commands (NULL, cnc,
- "SELECT proname FROM pg_proc ORDER BY proname");
+ "SELECT proname FROM pg_proc ORDER BY proname",
+ GDA_COMMAND_OPTION_STOP_ON_ERRORS);
if (!reclist)
return NULL;
@@ -510,7 +516,8 @@
reclist = process_sql_commands (NULL, cnc,
"SELECT relname FROM pg_class WHERE relkind = 'r' AND "
- "relname !~ '^pg_' ORDER BY relname");
+ "relname !~ '^pg_' ORDER BY relname",
+ GDA_COMMAND_OPTION_STOP_ON_ERRORS);
if (!reclist)
return NULL;
@@ -577,7 +584,8 @@
reclist = process_sql_commands (NULL, cnc,
"SELECT relname FROM pg_class WHERE relkind = 'v' AND "
- "relname !~ '^pg_' ORDER BY relname");
+ "relname !~ '^pg_' ORDER BY relname",
+ GDA_COMMAND_OPTION_STOP_ON_ERRORS);
if (!reclist)
return NULL;
Index: testing/ChangeLog
===================================================================
RCS file: /cvs/gnome/libgda/testing/ChangeLog,v
retrieving revision 1.26
diff -u -r1.26 ChangeLog
--- testing/ChangeLog 2002/01/15 20:23:54 1.26
+++ testing/ChangeLog 2002/01/17 20:05:45
@@ -1,3 +1,7 @@
+2002-01-17 Gonzalo Paniagua Javier <gonzalo gnome-db org>
+
+ * postgres-test.c: added support GdaCommandOption.
+
2002-01-15 Gonzalo Paniagua Javier <gonzalo gnome-db org>
* models.h: added declaration of display_recordset_data().
Index: testing/postgres-test.c
===================================================================
RCS file: /cvs/gnome/libgda/testing/postgres-test.c,v
retrieving revision 1.3
diff -u -r1.3 postgres-test.c
--- testing/postgres-test.c 2002/01/14 23:40:15 1.3
+++ testing/postgres-test.c 2002/01/17 20:05:45
@@ -22,6 +22,9 @@
#include "postgres-test.h"
+#define IGNORE_ERR GDA_COMMAND_OPTION_IGNORE_ERRORS
+#define STOP_ON_ERR GDA_COMMAND_OPTION_STOP_ON_ERRORS
+
static gboolean
create_table (GdaConnection *cnc)
{
@@ -46,9 +49,10 @@
"timestamp_value timestamp, "
"null_value char(1) "
")",
- GDA_COMMAND_TYPE_SQL);
+ GDA_COMMAND_TYPE_SQL, STOP_ON_ERR);
- list = gda_connection_execute_command (cnc, create_command, NULL);
+ list = gda_connection_execute_command (cnc, create_command,
+ NULL);
retval = list == NULL ? FALSE : TRUE;
g_list_foreach (list, (GFunc) g_object_unref, NULL);
g_list_free (list);
@@ -65,7 +69,7 @@
GList *list;
drop_command = gda_command_new ( "drop table gda_postgres_test",
- GDA_COMMAND_TYPE_SQL);
+ GDA_COMMAND_TYPE_SQL, IGNORE_ERR);
list = gda_connection_execute_command (cnc, drop_command, NULL);
retval = list == NULL ? FALSE : TRUE;
@@ -113,7 +117,7 @@
"'2004-02-29 14:00:11.31', "
"'(1,0)' "
")",
- GDA_COMMAND_TYPE_SQL);
+ GDA_COMMAND_TYPE_SQL, STOP_ON_ERR);
list = gda_connection_execute_command (cnc, insert_command, NULL);
gda_command_free (insert_command);
@@ -128,9 +132,10 @@
GList *list;
select_command = gda_command_new ( "select * from gda_postgres_test",
- GDA_COMMAND_TYPE_SQL);
+ GDA_COMMAND_TYPE_SQL, STOP_ON_ERR);
- list = gda_connection_execute_command (cnc, select_command, NULL);
+ list = gda_connection_execute_command (cnc, select_command,
+ NULL);
gda_command_free (select_command);
return list;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]