Re: [gnome-db] gda_connection_create_table() equivalent.



On 8/27/06, Bas Driessen <bas driessen xobas com> wrote:

 Hello,

 I noticed that functions like gda_connection_create_table() have been
removed recently. This now should go through a new GdaServerOperation. Is it
possible to give an example of how I would create a table now? I used
function calls like this:

 gda_connection_create_table(connection, table_name,
columns, NULL)
>
 What would the equivalent be with this new GdaServerOperation? Any
clues/examples?

Example to create a table. The idea is to ask a provider for a
GdaServerOperation for a given operation to perform, then set the data
in the GdaServerOperation (here from an XML string), and the ask the
provider to execute the operation. The parameters to be set for each
kind of operation is provider-dependant, but there is a common set
mentionned in the libgda doc (such as table name and columns to create
a table).

For more examples, have a look at src/util.c and src/ws-tables.c in
mergeant. You can use libgnomedb's GnomeDbServerOperation widget to
have a GUI to enter the necessary parameters for a given
GdaServerOperation.

GdaServerOperation *op;
GError *error = NULL;

op = gda_server_provider_create_operation (prov, cnc,
GDA_SERVER_OPERATION_CREATE_TABLE, NULL, &error);
if (!op) {
   /* error */
}
else {
   /* we have to set the table parameters */
  const gchar *params = "
<serv_op_data>
 <op_data path="/TABLE_DEF_P/TABLE_NAME">testtable</op_data>
 <op_data path="/FIELDS_A">
   <gda_array_data>
     <gda_array_row>
       <gda_array_value colid="COLUMN_NAME">id</gda_array_value>
       <gda_array_value colid="COLUMN_TYPE">int</gda_array_value>
     </gda_array_row>
   </gda_array_data>
 </op_data>
</serv_op_data>"

   doc = xmlParseMemory (params, -1);
   if (!gda_server_operation_load_data_from_xml (op,
xmlDocGetRootElement (doc), &error)) {
       /* error */
   }
   else {
       gda_server_provider_perform_operation (prov, cnc, op, &error) {
           /* error */
       }
       else {
           /* ok, table created */
       }
   }
  xmlFreeDoc (doc);
  g_object_unref (op);
}

Hope this helps,

Vivien



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]