[gnome-db] GdaDataModelFilterSQL query



Hi all,
I have one query regarding the GdaDataModelFilterSQL class in libgda. I ran the below code and found out that the SQL query does not support the where clause. In the below code the gda_data_model_filter_sql_run() should have returned just one column. However when i dump the model i can see 2 columns. Debugging the code i found out that the where clause is not taken into consideration when generating results. I want to know if this is intentional. I looked up the API reference and could not find any thing that indicated to it. Please tell me if this is intentional and if i am using the GdaDataModelFilterSQL  class correctly.

---------------- code snippet -----------------------

#include <libgda/libgda.h>
#include <stdio.h>

#define NoError  0
#define Error 1

int main()
{
        int retVal = NoError  ;
        FILE *fp = NULL;
        GdaDataModelFilterSQL *filter = NULL;
        GList *list = NULL;
        GdaColumn *column1,*column2;
        GValue *value = NULL;

        gda_init ("TestGDA", NULL, 0, NULL);

        GdaDataModel *model = gda_data_model_array_new_with_g_types(2,G_TYPE_INT,G_TYPE_STRING);

        if(!model)
        {
                retVal = Error ;
        goto end;
        }

        if(!model || gda_data_model_get_n_columns(model) != 2)
        {
                retVal = Error ;
        goto end;
        }


        column1 = gda_data_model_describe_column(GDA_DATA_MODEL(model),0);

        if(!column1)
        {
                retVal = Error ;
        goto end;
        }
gda_column_set_title(column1,"col1");
    gda_column_set_name(column1,"col1");

    column2 = gda_data_model_describe_column(GDA_DATA_MODEL(model),1);

    if(!column2)
    {
        retVal = Error ;
        goto end;
    }

    gda_column_set_title(column2,"col2");
    gda_column_set_name(column2,"col2");

    g_value_set_int(value = gda_value_new(G_TYPE_INT),10);
    list = g_list_append(list,value);

    g_value_set_string(value = gda_value_new(G_TYPE_STRING),"test");
    list = g_list_append(list,value);

    gda_data_model_append_values(GDA_DATA_MODEL(model),list,NULL);

    g_list_foreach(list,(GFunc)gda_value_free,NULL);
    g_list_free(list);

    g_value_set_int(value = gda_value_new(G_TYPE_INT),11);
    list = g_list_append(list,value);

    g_value_set_string(value = gda_value_new(G_TYPE_STRING),"test1");
    list = g_list_append(list,value);

    gda_data_model_append_values(GDA_DATA_MODEL(model),list,NULL);

    g_list_foreach(list,(GFunc)gda_value_free,NULL);
    g_list_free(list);

    filter = (GdaDataModelFilterSQL *)gda_data_model_filter_sql_new ();
if(!filter)
    {
        retVal = Error ;
        goto end;
    }

    gda_data_model_filter_sql_add_source(filter,"test",model);

    gda_data_model_filter_sql_set_sql(filter,"select col1 from test where col1=10");

    if(!gda_data_model_filter_sql_run(filter))
    {
        retVal = Error ;
        goto end;
    }

    fp = fopen("test.txt","w");

    gda_data_model_dump(GDA_DATA_MODEL(filter),fp);

    fclose(fp);


end:

        g_object_unref(G_OBJECT(model));
        return retVal;
}

---------------- End code snippet -----------------------

 

Regards,

Sumit

 

Sumit Kumar Jain

Call me: +91-9880472974




Get the freedom to save as many mails as you wish. Click here to know how.

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