i'm trying the new libgda-3

my problem is that i didn't understand very well how gdaquery and gdaqueryfield 
joins together

this is the code

#include <libgda/libgda.h>

int
main (int argc, char **argv)
{
        GdaClient *client;
        GdaConnection *conn;
        GdaDict *dict;
        GdaQuery *qu;
        GdaObject *dm;
        GError *error = NULL;

        gda_init ("test", "1.0", argc, argv);

        client = gda_client_new ();

        conn = gda_client_open_connection_from_string (client, "SQLite", 
"DB_DIR=/media/disk/libgda3_gdaquery;DB_NAME=test.db", NULL, NULL, 0, &error);

        if (conn == NULL)
                {
                        g_fprintf (stderr, "Errore apertura 
connessione.\n%s\n", error->message);
                }
        else
                {
                        GdaQueryTarget *qutarget;
                        GdaQueryField *qufield;
                        GdaQueryField *quvalue;
                        GValue *value;

                        value = g_malloc0 (sizeof (GValue));

                        error = NULL;
                        dict = gda_dict_new ();
                        gda_dict_set_connection (GDA_DICT (dict), conn);

                        qu = gda_query_new (GDA_DICT (dict));
                        if (qu == NULL)
                                {
                                        g_fprintf (stderr, "Errore in 
gda_query_new.\n");
                                }

                        gda_query_set_query_type (GDA_QUERY (qu), 
GDA_QUERY_TYPE_UPDATE);

                        qutarget = gda_query_target_new (GDA_QUERY (qu), 
"appo");

                        qufield = gda_query_field_field_new (GDA_QUERY (qu), 
"ciccio");
                        gda_query_field_set_visible (GDA_QUERY_FIELD (qufield), 
TRUE);

                        quvalue = gda_query_field_value_new (GDA_QUERY (qu), 
G_TYPE_STRING);
                        g_value_init (value, G_TYPE_STRING);
                        g_value_set_string (value, "paperino");
                        gda_query_field_value_set_value (GDA_QUERY_FIELD_VALUE 
(quvalue), value);
                        gda_query_field_set_visible (GDA_QUERY_FIELD (quvalue), 
TRUE);

                        g_object_set (qufield,
                                      "target", qutarget,
                                      "target-id", "appo",
                                      "target-name", "appo",
                                      "value-provider", quvalue,
                                      NULL);

                        if (!gda_query_add_target (GDA_QUERY (qu), 
GDA_QUERY_TARGET (qutarget), &error))
                                {
                                        g_fprintf (stderr, "Errore in 
add_target.\n%s\n", error->message);
                                }

                        error = NULL;
                        dm = gda_query_execute (GDA_QUERY (qu), NULL, FALSE, 
&error);
                        if (error != NULL)
                                {
                                        g_fprintf (stderr, "Errore in 
esecuzione query.\n%s\n", error->message);
                                }

                        g_fprintf (stderr, "SQL: %s\n", gda_query_get_sql_text 
(GDA_QUERY (qu)));
                }


        return 0;
}

when i execute it, it returns an error on gda_query_execute because the query's 
sql is wrong; in fact gda_query_get_sql_text returns "update appo set "

instead I thought to have created "update appo set ciccio='paperino'"

what am I mistaking?

thanks in advance
_______________________________________________
gnome-db-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gnome-db-list

Reply via email to