Re: [gnome-db] import from csv



On 26 October 2010 13:34, Andrea Zagli <azagli libero it> wrote:
> i didn't understand how to read from a csv file :-(
>
> i am under windows with libgda 4.1.11 (i'm using this version because i
> didn't test the last version yet)
>
> the code i'm using
>
>                        GdaSet *plist = gda_set_new_inline (14,
>                                                            "SEPARATOR",
> G_TYPE_STRING, ";",
>                                                            "ESCAPE_CHAR",
> G_TYPE_STRING, "",
>                                                            "G_TYPE_0",
> G_TYPE_GTYPE, G_TYPE_INT,
>                                                            "G_TYPE_1",
> G_TYPE_GTYPE, G_TYPE_STRING,
>                                                            "G_TYPE_2",
> G_TYPE_GTYPE, G_TYPE_STRING,
>                                                            "G_TYPE_3",
> G_TYPE_GTYPE, G_TYPE_STRING,
>                                                            "G_TYPE_4",
> G_TYPE_GTYPE, G_TYPE_STRING,
>                                                            "G_TYPE_5",
> G_TYPE_GTYPE, G_TYPE_STRING,
>                                                            "G_TYPE_6",
> G_TYPE_GTYPE, G_TYPE_STRING,
>                                                            "G_TYPE_7",
> G_TYPE_GTYPE, G_TYPE_STRING,
>                                                            "G_TYPE_8",
> G_TYPE_GTYPE, G_TYPE_STRING,
>                                                            "G_TYPE_9",
> G_TYPE_GTYPE, G_TYPE_STRING,
>                                                            "G_TYPE_10",
> G_TYPE_GTYPE, G_TYPE_STRING,
>                                                            "G_TYPE_11",
> G_TYPE_GTYPE, G_TYPE_STRING);
>                        dm = gda_data_model_import_new_file (filename, FALSE,
> plist);
>                        if (dm == NULL)
>                                {
>                                        /* error */
>                                        return NULL;
>                                }
>
> dm is not null; if i call gda_data_model_import_get_errors
> (GDA_DATA_MODEL_IMPORT (dm)) it returns a non null gslist but only with the
> message "no error"

The created data model will never be NULL.

The gda_data_model_import_get_errors() can (and should) be called
anytime the data model
is used to know if all went OK. However I have no idea how the "no
error" error message came to be...

>
> if i call gda_data_model_export_to_file i get an empty file; and if i call
> gda_data_model_get_n_rows i get -1

The created data model's access is not random (because of the FALSE
argument to gda_data_model_import_new_file()), and so it cannot know
the number of rows it contains.

Also the data model export functions don't currently work if the data
model does not have a random access (which is something I need to
correct). If you need to export DM, pass TRUE as the 2nd argument to
gda_data_model_import_new_file(), or you can use a
GdaDataAccessWrapper:
 GdaDataModel *wrapper;
 wrapper = gda_data_access_wrapper_new (dm);
 ...
 g_object_unref (wrapper);



Regards,

Vivien


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