Re: [gnome-db] Patch for parameters and doc



El Martes, 6 de Mayo de 2003 11:06, Rodrigo Moya escribió:
> On Tue, 2003-04-29 at 13:14, Xabier Rodríguez Calvar wrote:
>
> some comments:
>
>  GdaParameter *
> -gda_parameter_new (const gchar *name, GdaValueType type)
> +gda_parameter_new (const gchar *name, GdaValue *value)
>  {
>
> I wouldn't use this at all. I would remove gda_parameter_new and add
> gda_parameter_new_int/string/double..., and a
> gda_parameter_new_from_value function. That would make the API more
> consistent, and reduce confusion.

	I disagree, because in the way you propose, the API is less extensible, 
because if you want to create a new type into GdaValue class, you have to 
change GdaParameter too, and in my way you don't have to :)

>
> +#ifdef G_DISABLE_CONST_RETURNS
> +#define G_CONST_RETURN
> +#else
> +#define G_CONST_RETURN const
> +#endif
> +

	You are right. Fixed...

>
> why do you need this? Isn't this already in glib headers?
>
> cheers

	I send the patch... Byes!

-- 
Xabier Rodríguez Calvar
Igalia S.L.














? patch.diff
Index: doc/C/libgda-docs.sgml
===================================================================
RCS file: /cvs/gnome/libgda/doc/C/libgda-docs.sgml,v
retrieving revision 1.39
diff -u -r1.39 libgda-docs.sgml
--- doc/C/libgda-docs.sgml	13 Dec 2002 17:33:41 -0000	1.39
+++ doc/C/libgda-docs.sgml	6 May 2003 20:22:50 -0000
@@ -982,46 +982,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">
@@ -1037,31 +1044,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">
@@ -1080,7 +1097,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>
@@ -1426,7 +1449,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);
@@ -1457,9 +1479,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>
@@ -1541,7 +1563,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");
@@ -1620,6 +1641,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>
@@ -1639,11 +1661,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)
@@ -1652,6 +1675,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 (
@@ -1676,6 +1701,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 (
@@ -1706,6 +1733,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	6 May 2003 20:22:51 -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: 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	6 May 2003 20:22:52 -0000
@@ -44,7 +44,7 @@
 /**
  * gda_parameter_new
  * @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 (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;
 }
@@ -129,7 +131,7 @@
  * gda_parameter_get_name
  * @param: a #GdaParameter object.
  *
- * Returns the name of the given #GdaParameter.
+ * Returns: the name of the given #GdaParameter.
  */
 const gchar *
 gda_parameter_get_name (GdaParameter *param)
@@ -140,6 +142,8 @@
 
 /**
  * gda_parameter_set_name
+ * @param: a #GdaParameter object.
+ * @name: the name you want to set.
  */
 void
 gda_parameter_set_name (GdaParameter *param, const gchar *name)
@@ -147,13 +151,15 @@
 	g_return_if_fail (param != NULL);
 	g_return_if_fail (name != NULL);
 
-	if (param->name != NULL)
-		g_free (param->name);
+	g_free (param->name);
 	param->name = g_strdup (name);
 }
 
 /**
  * gda_parameter_get_value
+ * @param: the parameter.
+ *
+ * Returns: the #GdaValue into de parameter.
  */
 const GdaValue *
 gda_parameter_get_value (GdaParameter *param)
@@ -164,11 +170,19 @@
 
 /**
  * gda_parameter_set_value
+ * @param: the parameter.
+ * @value: GDA value for this parameter.
+ *
+ * Sets a new #GdaValue into the parameter.
  */
 void
 gda_parameter_set_value (GdaParameter *param, GdaValue *value)
 {
-	/* FIXME */
+	g_return_if_fail (param != NULL);
+	g_return_if_fail (value != NULL);
+
+	gda_value_free(param->value);
+        param->value=gda_value_copy(value);
 }
 
 /**
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	6 May 2003 20:22:52 -0000
@@ -33,7 +33,7 @@
 	GdaValue *value;
 } GdaParameter;
 
-GdaParameter   *gda_parameter_new (const gchar *name, GdaValueType type);
+GdaParameter   *gda_parameter_new (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	6 May 2003 20:22:52 -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	6 May 2003 20:22:52 -0000
@@ -24,6 +24,7 @@
 #if !defined(__gda_row_h__)
 #  define __gda_row_h__
 
+
 #include <libgda/gda-field.h>
 
 G_BEGIN_DECLS
@@ -31,16 +32,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]