Re: [gnome-db] Patch for parameters and doc
- From: Xabier =?iso-8859-15?q?Rodr=EDguez=20Calvar?= <xrcalvar igalia com>
- To: gnome-db-list gnome org
- Subject: Re: [gnome-db] Patch for parameters and doc
- Date: Tue, 13 May 2003 00:38:05 +0200
El Viernes, 9 de Mayo de 2003 13:57, Rodrigo Moya escribió:
> eh, please, the ChangeLog entry :-) After that, I'll really commit :-)
Fixed!
Cheers
--
Xabier Rodríguez Calvar
Igalia S.L.
? compilar.sh
? nohup.out
? patch.diff
? doc/C/tmpl/gda-report-item-label.sgml
? doc/C/tmpl/gda-report-item-pagefooter.sgml
? doc/C/tmpl/gda-report-item-pageheader.sgml
? doc/C/tmpl/gda-report-item-report.sgml
? doc/C/tmpl/gda-report-item-reportfooter.sgml
? doc/C/tmpl/gda-report-item-reportheader.sgml
? doc/C/tmpl/gda-report-item.sgml
? doc/C/tmpl/gda-report-valid.sgml
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/libgda/ChangeLog,v
retrieving revision 1.520
diff -u -r1.520 ChangeLog
--- ChangeLog 10 May 2003 21:44:38 -0000 1.520
+++ ChangeLog 12 May 2003 22:20:07 -0000
@@ -1,3 +1,13 @@
+2003-05-13 Xabier Rodríguez Calvar <xrcalvar igalia com>
+
+ * doc/C: some changes to make it more solid
+ * libgda/gda-row.*: introduced G_CONST_RETURN in
+ gda_row_get_value() to have the const in the doc but not in the
+ real version
+ * libgda/gda-parameter.*: removed gda_parameter_new(), adding
+ gda_parameter_new_from_value() to make the API more solid and
+ removed some checkings for null because they were not necessary.
+
2003-05-10 Danilo Schoeneberg <dj starfire-programming net>
* configure.in:
Index: doc/C/libgda-docs.sgml
===================================================================
RCS file: /cvs/gnome/libgda/doc/C/libgda-docs.sgml,v
retrieving revision 1.40
diff -u -r1.40 libgda-docs.sgml
--- doc/C/libgda-docs.sgml 8 May 2003 21:28:23 -0000 1.40
+++ doc/C/libgda-docs.sgml 12 May 2003 22:20:20 -0000
@@ -983,46 +983,53 @@
LINKEND="gda-main-quit">gda_main_quit()</LINK> in order to finish the program.
</para>
<PROGRAMLISTING>
- void
- do_stuff ()
- {
- GdaClient *client;
- GdaConnection *connection;
-
- list_providers ();
- list_datasources ();
-
- client = gda_client_new ();
-
- g_print ("CONNECTING\n");
- connection = gda_client_open_connection (client, "calvaris", NULL, NULL);
- g_print ("CONNECTED\n");
-
- proving_errors (connection);
-
- process_accounts(connection);
-
- process_accounts2(connection);
-
- gda_client_close_all_connections (client);
-
- gda_main_quit();
- }
-
-
- int
- main (int argc, char **argv)
- {
-
- g_print ("STARTING\n");
- gda_init ("TestGDA", "0.1", argc, argv);
-
- save_ds ();
- // remove_ds();
-
- gda_main_run ((GdaInitFunc) do_stuff, (gpointer) NULL);
- // do_stuff();
- }
+ void
+ do_stuff ()
+ {
+ GdaClient *client;
+ GdaConnection *connection;
+
+ list_providers ();
+ list_datasources ();
+
+ client = gda_client_new ();
+
+ g_print ("CONNECTING\n");
+ connection = gda_client_open_connection (client, "calvaris", NULL, NULL,
+ GDA_CONNECTION_OPTIONS_READ_ONLY);
+
+ g_print ("CONNECTED\n");
+
+ execute_some_queries (connection);
+
+ g_print ("ERRORS PROVED!\n");
+
+ process_accounts(connection);
+
+ gda_client_close_all_connections (client);
+
+ g_object_unref(G_OBJECT(client));
+
+ play_with_parameters();
+
+ gda_main_quit();
+ }
+
+
+ int
+ main (int argc, char **argv)
+ {
+
+ g_print ("STARTING\n");
+ gda_init ("TestGDA", "0.1", argc, argv);
+
+ save_ds ();
+
+ gda_main_run ((GdaInitFunc) do_stuff, (gpointer) NULL);
+ /* do_stuff(); */
+ g_print("ENDING\n");
+
+ }
</PROGRAMLISTING>
</sect1>
<sect1 ID="connections">
@@ -1038,31 +1045,41 @@
<AREASPEC UNITS="LINECOLUMN">
<AREA ID="connecting-1" COORDS="10 1">
<AREA ID="connecting-2" COORDS="13 1">
- <AREA ID="connecting-3" COORDS="20 1">
- </AREASPEC>
+ <AREA ID="connecting-3" COORDS="24 1">
+ <AREA ID="connecting-4" COORDS="26 1">
+</AREASPEC>
<programlisting>
- void
- do_stuff ()
- {
- GdaClient *client;
- GdaConnection *connection;
-
- list_providers ();
- list_datasources ();
-
- client = gda_client_new ();
-
- g_print ("CONNECTING\n");
- connection = gda_client_open_connection (client, "calvaris", NULL, NULL);
- g_print ("CONNECTED\n");
-
- proving_errors (connection);
-
- process_accounts(connection);
-
- gda_client_close_all_connections (client);
-
- }
+ void
+ do_stuff ()
+ {
+ GdaClient *client;
+ GdaConnection *connection;
+
+ list_providers ();
+ list_datasources ();
+
+ client = gda_client_new ();
+
+ g_print ("CONNECTING\n");
+ connection = gda_client_open_connection (client, "calvaris", NULL, NULL,
+ GDA_CONNECTION_OPTIONS_READ_ONLY);
+
+ g_print ("CONNECTED\n");
+
+ execute_some_queries (connection);
+
+ g_print ("ERRORS PROVED!\n");
+
+ process_accounts(connection);
+
+ gda_client_close_all_connections (client);
+
+ g_object_unref(G_OBJECT(client));
+
+ play_with_parameters();
+
+ gda_main_quit();
+ }
</programlisting>
<CALLOUTLIST>
<CALLOUT AREAREFS="connecting-1">
@@ -1081,7 +1098,13 @@
It's a good practice to close connections when you finish using them. It
doesn't mean that you must close them each time you use them. It's better
open the connections when program starts and use them during the whole
- execution.
+ execution. This function frees the <LINK LINKEND="libgda-GdaConnection">GdaConnection</LINK>
+ objects attached to the <LINK LINKEND="libgda-GdaClient">GdaClient</LINK>.
+ </para>
+ </callout>
+ <CALLOUT AREAREFS="connecting-4">
+ <para>
+ When finishing with the client, I have to free it.
</para>
</callout>
</CALLOUTLIST>
@@ -1427,7 +1450,6 @@
for (column_id = 0; column_id < gda_data_model_get_n_columns (dm);
column_id++)
{
- /* We don't need to free this value! */
value = gda_row_get_value (row, column_id);
string=gda_value_stringify (value);
g_print ("%s\t", string);
@@ -1458,9 +1480,9 @@
LINKEND="gda-row-get-value">gda_row_get_value ()
</LINK>. Notice that <LINK
LINKEND="gda-row-get-value">gda_row_get_value ()</LINK>
- doesn't return a <EMPHASIS>const <LINK
+ returns a <EMPHASIS>const <LINK
LINKEND="libgda-gda-value">GdaValue</LINK></EMPHASIS>, so we
- have to free it.
+ do not have to free it.
</PARA>
</CALLOUT>
</CALLOUTLIST>
@@ -1542,7 +1564,6 @@
value = gda_row_get_value (row, column_id);
string=gda_value_stringify (value);
g_print ("%s\t", string);
- gda_value_free(value);
g_free(string);
}
g_print ("\n");
@@ -1621,6 +1642,7 @@
</para>
<ORDEREDLIST NUMERATION="arabic">
<LISTITEM><para>Create transaction</para></LISTITEM>
+ <LISTITEM><para>Change, if needed, the isolation level</para></LISTITEM>
<LISTITEM><para>Link transaction to a connection</para></LISTITEM>
<LISTITEM>
<para>For each command you want to execute:</para>
@@ -1640,11 +1662,12 @@
<PROGRAMLISTINGCO>
<AREASPEC UNITS="LINECOLUMN">
<AREA ID="transactions-1" COORDS="6 1">
- <AREA ID="transactions-2" COORDS="7 1">
- <AREA ID="transactions-3" COORDS="14 1">
- <AREA ID="transactions-4" COORDS="27 1">
- <AREA ID="transactions-5" COORDS="28 1">
- <AREA ID="transactions-6" COORDS="51 1">
+ <AREA ID="transactions-1a" COORDS="7 1">
+ <AREA ID="transactions-2" COORDS="9 1">
+ <AREA ID="transactions-3" COORDS="16 1">
+ <AREA ID="transactions-4" COORDS="29 1">
+ <AREA ID="transactions-5" COORDS="30 1">
+ <AREA ID="transactions-6" COORDS="55 1">
</AREASPEC>
<programlisting>
void process_accounts(GdaConnection *connection)
@@ -1653,6 +1676,8 @@
GdaCommand *command;
transaction_one=gda_transaction_new("accounts1");
+ gda_transaction_set_isolation_level(transaction_one,
+ GDA_TRANSACTION_ISOLATION_SERIALIZABLE);
gda_connection_begin_transaction(connection,transaction_one);
command=gda_command_new (
@@ -1677,6 +1702,8 @@
g_object_unref(transaction_one);
transaction_two=gda_transaction_new("accounts2");
+ gda_transaction_set_isolation_level(transaction_two,
+ GDA_TRANSACTION_ISOLATION_SERIALIZABLE);
gda_connection_begin_transaction(connection,transaction_two);
command=gda_command_new (
@@ -1707,6 +1734,11 @@
<CALLOUT AREAREFS="transactions-1">
<PARA>
Creates first transaction.
+ </PARA>
+ </CALLOUT>
+ <CALLOUT AREAREFS="transactions-1a">
+ <PARA>
+ Changes the isolation level.
</PARA>
</CALLOUT>
<CALLOUT AREAREFS="transactions-2">
Index: doc/C/examples/full_example.c
===================================================================
RCS file: /cvs/gnome/libgda/doc/C/examples/full_example.c,v
retrieving revision 1.2
diff -u -r1.2 full_example.c
--- doc/C/examples/full_example.c 3 Feb 2003 17:12:09 -0000 1.2
+++ doc/C/examples/full_example.c 12 May 2003 22:20:21 -0000
@@ -1,378 +1,383 @@
- #include <libgda/libgda.h>
- #include <stdio.h>
+#include <libgda/libgda.h>
+#include <stdio.h>
- #define DEFAULT_BUFFER_SIZE 1024
-
-
- gboolean
- get_errors (GdaConnection *connection)
+#define DEFAULT_BUFFER_SIZE 1024
+
+
+gboolean
+get_errors (GdaConnection * connection)
+{
+ GList *list;
+ GList *node;
+ GdaError *error;
+
+ list = (GList *) gda_connection_get_errors (connection);
+
+ for (node = g_list_first (list); node != NULL; node = g_list_next (node))
{
- GList *list;
- GList *node;
- GdaError *error;
-
- list = (GList *) gda_connection_get_errors (connection);
-
- for (node = g_list_first (list); node != NULL; node = g_list_next (node))
- {
- error = (GdaError *) node->data;
- g_print ("Error no: %d\t", gda_error_get_number (error));
- g_print ("desc: %s\t", gda_error_get_description (error));
- g_print ("source: %s\t", gda_error_get_source (error));
- g_print ("sqlstate: %s\n", gda_error_get_sqlstate (error));
- }
+ error = (GdaError *) node->data;
+ g_print ("Error no: %d\t", gda_error_get_number (error));
+ g_print ("desc: %s\t", gda_error_get_description (error));
+ g_print ("source: %s\t", gda_error_get_source (error));
+ g_print ("sqlstate: %s\n", gda_error_get_sqlstate (error));
}
-
-
-
- void
- show_table (GdaDataModel * dm)
+}
+
+
+
+void
+show_table (GdaDataModel * dm)
+{
+ gint row_id;
+ gint column_id;
+ GdaValue *value;
+ gchar *string;
+
+ for (column_id = 0; column_id < gda_data_model_get_n_columns (dm);
+ column_id++)
+ g_print ("%s\t", gda_data_model_get_column_title (dm, column_id));
+ g_print ("\n");
+
+ for (row_id = 0; row_id < gda_data_model_get_n_rows (dm); row_id++)
{
- gint row_id;
- gint column_id;
- GdaValue *value;
- gchar *string;
-
for (column_id = 0; column_id < gda_data_model_get_n_columns (dm);
- column_id++)
- g_print("%s\t",gda_data_model_get_column_title (dm, column_id));
- g_print("\n");
-
- for (row_id = 0; row_id < gda_data_model_get_n_rows (dm); row_id++)
- {
- for (column_id = 0; column_id < gda_data_model_get_n_columns (dm);
- column_id++)
- {
- value =
- (GdaValue *) gda_data_model_get_value_at (dm, column_id, row_id);
- string=gda_value_stringify (value);
- g_print ("%s\t", string);
- g_free(string);
- }
- g_print("\n");
- }
+ column_id++)
+ {
+ value =
+ (GdaValue *) gda_data_model_get_value_at (dm, column_id, row_id);
+ string = gda_value_stringify (value);
+ g_print ("%s\t", string);
+ g_free (string);
+ }
+ g_print ("\n");
}
-
-
-
- void
- show_table2 (GdaDataModel * dm)
+}
+
+
+
+void
+show_table2 (GdaDataModel * dm)
+{
+ gint row_id;
+ gint column_id;
+ GdaValue *value;
+ GdaRow *row;
+ gchar *string;
+
+ for (column_id = 0; column_id < gda_data_model_get_n_columns (dm);
+ column_id++)
+ g_print ("%s\t", gda_data_model_get_column_title (dm, column_id));
+ g_print ("\n");
+
+ for (row_id = 0; row_id < gda_data_model_get_n_rows (dm); row_id++)
{
- gint row_id;
- gint column_id;
- GdaValue *value;
- GdaRow *row;
- gchar *string;
-
+ row = (GdaRow *) gda_data_model_get_row (dm, row_id);
for (column_id = 0; column_id < gda_data_model_get_n_columns (dm);
- column_id++)
- g_print("%s\t",gda_data_model_get_column_title (dm, column_id));
- g_print("\n");
-
- for (row_id = 0; row_id < gda_data_model_get_n_rows (dm); row_id++)
- {
- row = (GdaRow *) gda_data_model_get_row (dm, row_id);
- for (column_id = 0; column_id < gda_data_model_get_n_columns (dm);
- column_id++)
- {
- value = gda_row_get_value (row, column_id);
- string=gda_value_stringify (value);
- g_print ("%s\t", string);
- gda_value_free(value);
- g_free(string);
- }
- g_print ("\n");
- }
- }
-
-
-
- void process_accounts(GdaConnection *connection)
- {
- GdaTransaction *transaction_one, *transaction_two;
- GdaCommand *command;
-
- transaction_one=gda_transaction_new("accounts1");
- gda_connection_begin_transaction(connection,transaction_one);
-
- command=gda_command_new (
- "UPDATE accounts SET balance=balance+50"
- "WHERE account_code=456",
- GDA_COMMAND_TYPE_SQL,
- GDA_COMMAND_OPTION_STOP_ON_ERRORS);
- gda_command_set_transaction(command,transaction_one);
- gda_connection_execute_non_query(connection,command,NULL);
- gda_command_free(command);
-
- command=gda_command_new (
- "UPDATE accounts SET balance=balance-50"
- "WHERE account_code=12",
- GDA_COMMAND_TYPE_SQL,
- GDA_COMMAND_OPTION_STOP_ON_ERRORS);
- gda_command_set_transaction(command,transaction_one);
- gda_connection_execute_non_query(connection,command,NULL);
- gda_command_free(command);
-
- gda_connection_commit_transaction(connection,transaction_one);
- g_object_unref(transaction_one);
-
- transaction_two=gda_transaction_new("accounts2");
- gda_connection_begin_transaction(connection,transaction_two);
-
- command=gda_command_new (
- "UPDATE accounts SET balance=balance+400"
- "WHERE account_code=456",
- GDA_COMMAND_TYPE_SQL,
- GDA_COMMAND_OPTION_STOP_ON_ERRORS);
- gda_command_set_transaction(command,transaction_two);
- gda_connection_execute_non_query(connection,command,NULL);
- gda_command_free(command);
-
- command=gda_command_new (
- "UPDATE accounts SET balance=balance-400"
- "WHERE account_code=12",
- GDA_COMMAND_TYPE_SQL,
- GDA_COMMAND_OPTION_STOP_ON_ERRORS);
- gda_command_set_transaction(command,transaction_two);
- gda_connection_execute_non_query(connection,command,NULL);
- gda_command_free(command);
-
- gda_connection_rollback_transaction(connection,transaction_two);
- g_object_unref(transaction_two);
-
- execute_sql_command(connection,"SELECT * FROM accounts");
- }
-
-
- void process_accounts2(GdaConnection *connection)
- {/*
- GdaBatch *batch;
- GdaCommand *command;
-
- batch=gda_batch_new();
- gda_batch_add_command(batch,
- "UPDATE accounts SET balance=balance+300"
- "WHERE account_code=456"
- );
- gda_batch_add_command(batch,
- "UPDATE accounts SET balance=balance-300"
- "WHERE account_code=12",
- );
- gda_batch_set_connection(batch,connection);
- gda_batch_set_transaction_mode(batch,TRUE);
- if (gda_batch_start(batch))
- g_print("BATCH OK\n");
- else
- g_print("BATCH failed\n");
-
- execute_sql_command(connection,"SELECT * FROM accounts");
- */}
-
-
- gint
- 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);
- }
-
-
-
- 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);
- }
-
-
-
- void
- proving_errors (GdaConnection *connection)
- {
-
- execute_sql_non_query (connection,
- "DELETE FROM cliente"
- );
- execute_sql_non_query (connection,
- "INSERT INTO cliente(cd_cli, dni, nombr, direc, telef) "
- "VALUES ('1', '1234', 'Xabier',"
- "'Rua Unha calquera', '123')"
- "; INSERT INTO cliente(cd_cli, dni, nombr, direc, telef) "
- "VALUES ('2', '2345', 'Rodriguez',"
- "'Rua Outra calquera', '234')"
- );
- execute_sql_non_query (connection,
- "INSERT INTO cliente(cd_cli, dni, nombr, direc, telef) "
- "VALUES ('1', '1234', 'Xabier',"
- "'Rua Unha calquera', '123')"
- "; INSERT INTO cliente(cd_cli, dni, nombr, direc, telef) "
- "VALUES ('2', '2345', 'Rodriguez',"
- "'Rua Outra calquera', '234')"
- );
- execute_sql_command (connection, "SELECT * FROM cliente");
-
-
- execute_sql_non_query (connection,
- "DELETE FROM accounts;"
- "INSERT INTO accounts"
- "(client_code, account_code, balance)"
- "VALUES (123, 456, 1000);"
- "INSERT INTO accounts"
- "(client_code, account_code, balance)"
- "VALUES (789, 012, 5000);"
- );
-
- execute_sql_command (connection, "SELECT * FROM accounts");
-
- }
-
-
-
- void
- list_datasources (void)
- {
- GList *ds_list;
- GList *node;
- GdaDataSourceInfo *info;
-
- ds_list = gda_config_get_data_source_list ();
-
+ column_id++)
+ {
+ value = gda_row_get_value (row, column_id);
+ string = gda_value_stringify (value);
+ g_print ("%s\t", string);
+ g_free (string);
+ }
g_print ("\n");
- for (node = g_list_first (ds_list); node != NULL; node = g_list_next (node))
- {
- info = (GdaDataSourceInfo *) node->data;
-
- g_print
- ("NAME: %s PROVIDER: %s CNC: %s DESC: %s USER: %s PASSWORD: %s\n",
- info->name, info->provider, info->cnc_string, info->description,
- info->username, info->password);
-
- }
- g_print ("\n");
-
- gda_config_free_data_source_list (ds_list);
-
- }
-
-
-
- void
- list_providers (void)
- {
- GList *prov_list;
- GList *node;
- GdaProviderInfo *info;
-
- prov_list = gda_config_get_provider_list ();
-
- for (node = g_list_first (prov_list); node != NULL;
- node = g_list_next (node))
- {
- info = (GdaProviderInfo *) node->data;
-
- g_print ("ID: %s\n", info->id);
-
- }
-
- gda_config_free_provider_list (prov_list);
-
}
-
-
-
- void
- do_stuff ()
- {
- GdaClient *client;
- GdaConnection *connection;
-
- list_providers ();
- list_datasources ();
-
- client = gda_client_new ();
-
- g_print ("CONNECTING\n");
- connection = gda_client_open_connection (client, "calvaris", NULL, NULL);
- g_print ("CONNECTED\n");
-
- proving_errors (connection);
-
- process_accounts(connection);
-
- process_accounts2(connection);
-
- gda_client_close_all_connections (client);
-
- gda_main_quit();
- }
-
-
-
- void
- save_ds ()
+}
+
+
+
+void
+process_accounts (GdaConnection * connection)
+{
+ GdaTransaction *transaction_one, *transaction_two;
+ GdaCommand *command;
+
+ transaction_one = gda_transaction_new ("accounts1");
+ gda_transaction_set_isolation_level (transaction_one,
+ GDA_TRANSACTION_ISOLATION_SERIALIZABLE);
+ gda_connection_begin_transaction (connection, transaction_one);
+
+ command = gda_command_new ("UPDATE accounts SET balance=balance+50"
+ "WHERE account_code=456",
+ GDA_COMMAND_TYPE_SQL,
+ GDA_COMMAND_OPTION_STOP_ON_ERRORS);
+ gda_command_set_transaction (command, transaction_one);
+ gda_connection_execute_non_query (connection, command, NULL);
+ gda_command_free (command);
+
+ command = gda_command_new ("UPDATE accounts SET balance=balance-50"
+ "WHERE account_code=12",
+ GDA_COMMAND_TYPE_SQL,
+ GDA_COMMAND_OPTION_STOP_ON_ERRORS);
+ gda_command_set_transaction (command, transaction_one);
+ gda_connection_execute_non_query (connection, command, NULL);
+ gda_command_free (command);
+
+ gda_connection_commit_transaction (connection, transaction_one);
+ g_object_unref (transaction_one);
+
+ transaction_two = gda_transaction_new ("accounts2");
+ gda_transaction_set_isolation_level (transaction_two,
+ GDA_TRANSACTION_ISOLATION_SERIALIZABLE);
+ gda_connection_begin_transaction (connection, transaction_two);
+
+ command = gda_command_new ("UPDATE accounts SET balance=balance+400"
+ "WHERE account_code=456",
+ GDA_COMMAND_TYPE_SQL,
+ GDA_COMMAND_OPTION_STOP_ON_ERRORS);
+ gda_command_set_transaction (command, transaction_two);
+ gda_connection_execute_non_query (connection, command, NULL);
+ gda_command_free (command);
+
+ command = gda_command_new ("UPDATE accounts SET balance=balance-400"
+ "WHERE account_code=12",
+ GDA_COMMAND_TYPE_SQL,
+ GDA_COMMAND_OPTION_STOP_ON_ERRORS);
+ gda_command_set_transaction (command, transaction_two);
+ gda_connection_execute_non_query (connection, command, NULL);
+ gda_command_free (command);
+
+ gda_connection_rollback_transaction (connection, transaction_two);
+ g_object_unref (transaction_two);
+
+ execute_sql_command (connection, "SELECT * FROM accounts");
+}
+
+
+gint
+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;
+ get_errors (connection);
+ }
+ else
+ {
+ show_table2 (dm);
+ g_object_unref (dm);
+ }
+ }
+ else
{
- gda_config_save_data_source ("calvaris", "PostgreSQL", "DATABASE=calvaris",
- "cosa de calvaris", NULL, NULL);
+ errors = TRUE;
+ get_errors (connection);
}
-
-
-
- void
- remove_ds ()
+ gda_command_free (command);
+
+ return (errors);
+}
+
+
+
+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);
+}
+
+
+
+void
+execute_some_queries (GdaConnection * connection)
+{
+
+ execute_sql_non_query (connection, "DELETE FROM cliente");
+ execute_sql_non_query (connection,
+ "INSERT INTO cliente(cd_cli, dni, nombr, direc, telef) "
+ "VALUES ('1', '1234', 'Xabier',"
+ "'Rua Unha calquera', '123')"
+ "; INSERT INTO cliente(cd_cli, dni, nombr, direc, telef) "
+ "VALUES ('2', '2345', 'Rodriguez',"
+ "'Rua Outra calquera', '234')");
+ execute_sql_non_query (connection,
+ "INSERT INTO cliente(cd_cli, dni, nombr, direc, telef) "
+ "VALUES ('1', '1234', 'Xabier',"
+ "'Rua Unha calquera', '123')"
+ "; INSERT INTO cliente(cd_cli, dni, nombr, direc, telef) "
+ "VALUES ('2', '2345', 'Rodriguez',"
+ "'Rua Outra calquera', '234')");
+ execute_sql_command (connection, "SELECT * FROM cliente");
+
+
+ execute_sql_non_query (connection,
+ "DELETE FROM accounts;"
+ "INSERT INTO accounts"
+ "(client_code, account_code, balance)"
+ "VALUES (123, 456, 1000);"
+ "INSERT INTO accounts"
+ "(client_code, account_code, balance)"
+ "VALUES (789, 012, 5000);");
+
+ execute_sql_command (connection, "SELECT * FROM accounts");
+}
+
+
+
+void
+list_datasources (void)
+{
+ GList *ds_list;
+ GList *node;
+ GdaDataSourceInfo *info;
+
+ ds_list = gda_config_get_data_source_list ();
+
+ g_print ("\n");
+ for (node = g_list_first (ds_list); node != NULL; node = g_list_next (node))
{
- gda_config_remove_data_source("calvaris");
+ info = (GdaDataSourceInfo *) node->data;
+
+ g_print
+ ("NAME: %s PROVIDER: %s CNC: %s DESC: %s USER: %s PASSWORD: %s\n",
+ info->name, info->provider, info->cnc_string, info->description,
+ info->username, info->password);
+
}
-
-
-
- int
- main (int argc, char **argv)
+ g_print ("\n");
+
+ gda_config_free_data_source_list (ds_list);
+
+}
+
+
+
+void
+list_providers (void)
+{
+ GList *prov_list;
+ GList *node;
+ GdaProviderInfo *info;
+
+ prov_list = gda_config_get_provider_list ();
+
+ for (node = g_list_first (prov_list); node != NULL;
+ node = g_list_next (node))
{
-
- g_print ("STARTING\n");
- gda_init ("TestGDA", "0.1", argc, argv);
-
- save_ds ();
- /* remove_ds(); */
-
- gda_main_run ((GdaInitFunc) do_stuff, (gpointer) NULL);
- /* do_stuff(); */
-
+ info = (GdaProviderInfo *) node->data;
+
+ g_print ("ID: %s\n", info->id);
+
}
+
+ gda_config_free_provider_list (prov_list);
+
+}
+
+
+void
+play_with_parameters ()
+{
+ GdaParameterList *list;
+ GdaParameter *parameter;
+ GdaValue *value;
+
+ list = gda_parameter_list_new ();
+
+ value = gda_value_new_integer (10);
+ parameter = gda_parameter_new ("p1", value);
+ gda_parameter_list_add_parameter (list, parameter);
+ gda_value_free (value);
+
+ value = gda_value_new_integer (2);
+ parameter = gda_parameter_new ("p2", value);
+ gda_parameter_list_add_parameter (list, parameter);
+ gda_value_free (value);
+
+ gda_parameter_list_free (list);
+}
+
+
+
+void
+do_stuff ()
+{
+ GdaClient *client;
+ GdaConnection *connection;
+
+ list_providers ();
+ list_datasources ();
+
+ client = gda_client_new ();
+
+ g_print ("CONNECTING\n");
+ connection = gda_client_open_connection (client, "calvaris", NULL, NULL,
+ GDA_CONNECTION_OPTIONS_READ_ONLY);
+
+ g_print ("CONNECTED\n");
+
+ execute_some_queries (connection);
+
+ g_print ("ERRORS PROVED!\n");
+
+ process_accounts (connection);
+
+ gda_client_close_all_connections (client);
+
+ g_object_unref (G_OBJECT (client));
+
+ play_with_parameters ();
+
+ gda_main_quit ();
+}
+
+
+
+void
+save_ds ()
+{
+ gda_config_save_data_source ("calvaris", "PostgreSQL", "DATABASE=calvaris",
+ "cosa de calvaris", NULL, NULL);
+}
+
+
+
+void
+remove_ds ()
+{
+ gda_config_remove_data_source ("calvaris");
+}
+
+
+
+int
+main (int argc, char **argv)
+{
+
+ g_print ("STARTING\n");
+ gda_init ("TestGDA", "0.1", argc, argv);
+
+ save_ds ();
+ /* remove_ds(); */
+
+ gda_main_run ((GdaInitFunc) do_stuff, (gpointer) NULL);
+ /* do_stuff(); */
+ g_print ("ENDING\n");
+
+}
Index: doc/C/tmpl/gda-parameter.sgml
===================================================================
RCS file: /cvs/gnome/libgda/doc/C/tmpl/gda-parameter.sgml,v
retrieving revision 1.12
diff -u -r1.12 gda-parameter.sgml
--- doc/C/tmpl/gda-parameter.sgml 26 Mar 2003 12:32:40 -0000 1.12
+++ doc/C/tmpl/gda-parameter.sgml 12 May 2003 22:20:22 -0000
@@ -20,16 +20,6 @@
</para>
-<!-- ##### FUNCTION gda_parameter_new ##### -->
-<para>
-
-</para>
-
- name:
- type:
- Returns:
-
-
<!-- ##### FUNCTION gda_parameter_new_gobject ##### -->
<para>
Index: libgda/gda-parameter.c
===================================================================
RCS file: /cvs/gnome/libgda/libgda/gda-parameter.c,v
retrieving revision 1.20
diff -u -r1.20 gda-parameter.c
--- libgda/gda-parameter.c 17 Jan 2003 00:56:16 -0000 1.20
+++ libgda/gda-parameter.c 12 May 2003 22:20:23 -0000
@@ -42,9 +42,9 @@
}
/**
- * gda_parameter_new
+ * gda_parameter_new_from_value
* @name: name for the parameter being created.
- * @type: GDA value type for this parameter.
+ * @value: GDA value for this parameter.
*
* Create a new #GdaParameter object, which is usually used
* with #GdaParameterList.
@@ -52,14 +52,16 @@
* Returns: the newly created #GdaParameter.
*/
GdaParameter *
-gda_parameter_new (const gchar *name, GdaValueType type)
+gda_parameter_new_from_value (const gchar *name, GdaValue *value)
{
GdaParameter *param;
+ g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (value != NULL, NULL);
+
param = g_new0 (GdaParameter, 1);
param->name = g_strdup (name);
- param->value = gda_value_new_null ();
- param->value->type = type;
+ param->value = gda_value_copy (value);
return param;
}
Index: libgda/gda-parameter.h
===================================================================
RCS file: /cvs/gnome/libgda/libgda/gda-parameter.h,v
retrieving revision 1.13
diff -u -r1.13 gda-parameter.h
--- libgda/gda-parameter.h 17 Jan 2003 00:56:16 -0000 1.13
+++ libgda/gda-parameter.h 12 May 2003 22:20:23 -0000
@@ -33,7 +33,7 @@
GdaValue *value;
} GdaParameter;
-GdaParameter *gda_parameter_new (const gchar *name, GdaValueType type);
+GdaParameter *gda_parameter_new_from_value (const gchar *name, GdaValue *value);
GdaParameter *gda_parameter_new_gobject (const gchar *name, const GObject *value);
GdaParameter *gda_parameter_new_string (const gchar *name, const gchar *value);
void gda_parameter_free (GdaParameter *param);
Index: libgda/gda-row.c
===================================================================
RCS file: /cvs/gnome/libgda/libgda/gda-row.c,v
retrieving revision 1.33
diff -u -r1.33 gda-row.c
--- libgda/gda-row.c 10 Jan 2003 04:13:59 -0000 1.33
+++ libgda/gda-row.c 12 May 2003 22:20:24 -0000
@@ -201,7 +201,7 @@
*
* Returns: a pointer to the #GdaValue in the position @num of @row.
*/
-GdaValue *
+G_CONST_RETURN GdaValue *
gda_row_get_value (GdaRow *row, gint num)
{
g_return_val_if_fail (row != NULL, NULL);
Index: libgda/gda-row.h
===================================================================
RCS file: /cvs/gnome/libgda/libgda/gda-row.h,v
retrieving revision 1.25
diff -u -r1.25 gda-row.h
--- libgda/gda-row.h 10 Jan 2003 04:13:59 -0000 1.25
+++ libgda/gda-row.h 12 May 2003 22:20:24 -0000
@@ -31,16 +31,16 @@
typedef struct _GdaDataModel GdaDataModel;
typedef struct _GdaRow GdaRow;
-GdaRow *gda_row_new (GdaDataModel *model, gint count);
-GdaRow *gda_row_new_from_list (GdaDataModel *model, const GList *values);
-void gda_row_free (GdaRow *row);
-GdaDataModel *gda_row_get_model (GdaRow *row);
-gint gda_row_get_number (GdaRow *row);
-void gda_row_set_number (GdaRow *row, gint number);
-const gchar *gda_row_get_id (GdaRow *row);
-void gda_row_set_id (GdaRow *row, const gchar *id);
-GdaValue *gda_row_get_value (GdaRow *row, gint num);
-gint gda_row_get_length (GdaRow *row);
+GdaRow *gda_row_new (GdaDataModel *model, gint count);
+GdaRow *gda_row_new_from_list (GdaDataModel *model, const GList *values);
+void gda_row_free (GdaRow *row);
+GdaDataModel *gda_row_get_model (GdaRow *row);
+gint gda_row_get_number (GdaRow *row);
+void gda_row_set_number (GdaRow *row, gint number);
+const gchar *gda_row_get_id (GdaRow *row);
+void gda_row_set_id (GdaRow *row, const gchar *id);
+G_CONST_RETURN GdaValue *gda_row_get_value (GdaRow *row, gint num);
+gint gda_row_get_length (GdaRow *row);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]