GNOME Data Access manual |
---|
Before invoking a query you have to build the structure containing the command and you can do this with gda_command_new ().
The command type we most commonly use is GDA_COMMAND_TYPE_SQL because we will only focus on SQL queries[1]
typedef enum { GDA_COMMAND_OPTION_IGNORE_ERRORS = 1, GDA_COMMAND_OPTION_STOP_ON_ERRORS = 1 << 1, GDA_COMMAND_OPTION_BAD_OPTION = 1 << 2 } GdaCommandOptions;
Here you see an example of creating a command:
gint execute_sql_non_query (GdaConnection *connection, const gchar * buffer) { GdaCommand *command; gint number; command = gda_command_new (buffer, GDA_COMMAND_TYPE_SQL, GDA_COMMAND_OPTION_STOP_ON_ERRORS); number = gda_connection_execute_non_query (connection, command, NULL); gda_command_free (command); return (number); }
Non queries are queries that does not return data, only the number of rows affected, as a DELETE or an UPDATE. We use gda_connection_execute_non_query()
gint execute_sql_non_query (GdaConnection *connection, const gchar * buffer) { GdaCommand *command; gint number; command = gda_command_new (buffer, GDA_COMMAND_TYPE_SQL, GDA_COMMAND_OPTION_STOP_ON_ERRORS); number = gda_connection_execute_non_query (connection, command, NULL); gda_command_free (command); return (number); }
Normal queries are queries that return data (data models). You have two ways to do this:
You can use the first way when you want to invoke only a single command. Second way is used to execute several comma-separated sentences. It is recommended to use gda_connection_execute_single_command (). Here you see an example:
gboolean execute_sql_command (GdaConnection *connection, const gchar * buffer) { GdaCommand *command; GList *list; GList *node; gboolean errors=FALSE; GdaDataModel *dm; command = gda_command_new (buffer, GDA_COMMAND_TYPE_SQL, GDA_COMMAND_OPTION_STOP_ON_ERRORS); list = gda_connection_execute_command (connection, command, NULL); if (list!=NULL) for (node=g_list_first(list); node != NULL; node=g_list_next(node)) { dm=(GdaDataModel *) node->data; if (dm == NULL) { errors=TRUE; } else { show_table (dm); g_object_unref(dm); } } else { errors=TRUE; } gda_command_free (command); return (errors); }
[1] | There are other command types, as XMLand so on. |
<<< Connecting | Managing data models >>> |