Re: [gnome-db] gda_connection_create_table() equivalent.
- From: Bas Driessen <bas driessen xobas com>
- To: Rodrigo Moya <rodrigo gnome-db org>
- Cc: GNOME-DB List <gnome-db-list gnome org>, Vivien Malerba <vmalerba gmail com>
- Subject: Re: [gnome-db] gda_connection_create_table() equivalent.
- Date: Mon, 28 Aug 2006 22:40:32 +1000
On Mon, 2006-08-28 at 14:03 +0200, Rodrigo Moya wrote:
On Sun, 2006-08-27 at 11:00 +0200, Vivien Malerba wrote:
> 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,
>
it would be nice to have in the API convenience functions that do all
this work for common operations, like creating a table. How do you see
it?
Agreed. Example of a simple drop table:
Old situation only 1 line:
status = gda_connection_drop_table(connection, extTableName);
New situation 31 lines (not tested yet, but should at least be close)
prov = gda_connection_get_provider_obj(connection);
op = gda_server_provider_create_operation (prov, connection, GDA_SERVER_OPERATION_DROP_TABLE, NULL, &error);
if (!op)
{
/* error */
}
else
{
/* we have to set the table parameters */
docOp = xmlNewDoc((const xmlChar *)XML_VERSION);
docOp->children = xmlNewDocNode(docOp, NULL, (const xmlChar *)"serv_op_data", NULL);
curOp = xmlDocGetRootElement(docOp);
curOp = xmlNewTextChild (curOp, NULL, (const xmlChar *)"op_data", (const xmlChar *)extTableName);
xmlNewProp (curOp, (const xmlChar *)"path", (const xmlChar *)"/TABLE_DESC_P/TABLE_NAME");
if (!gda_server_operation_load_data_from_xml (op, xmlDocGetRootElement (docOp), &error))
{
/* error */
}
else
{
if(!gda_server_provider_perform_operation (prov, connection, op, &error))
{
/* error */
}
}
xmlFreeDoc (docOp);
g_object_unref (op);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]