Re: [gnome-db] Row Inserting: How to?





On 9/19/06, Daniel Espinosa <esodan gmail com> wrote:


2006/9/15, Vivien Malerba <vmalerba gmail com>:
On 9/15/06, Daniel Espinosa <esodan gmail com> wrote:
> I'm try to insert a row in a table I used the following code in an SQLite
> provider and it doesn't work:
>
> 1. Add a row using gda_data_model_append_row
>
> 2. Set each column's value using the returned row using
> gda_data_model_set_value_at (But says it isn't implemented)
>
>
> Then, how can I add a row to a GdaDataModel, using a procedures supported by
> *all* the prividers?

Use a GdaDataModelQuery data model (see extra/gnome-db-browser.c,
function table_view_contents()). Note that I'm currently improving it
so that it'll create the modifications queries when they are easy to
create.

>
> If I use the gda_data_model_append_values, the GList must be sorted to allow
> the procedure finds the correct value for the column's number?

Yes.

I have created a funtion gda_row_insert(GdaDataModel*, GError*, ...)

It can recive the *name* of the column and its *value* as strings; it sort the values and fill the ones missing as a GValue (a unset value created by g_new0(GValue, 1) ). I can print all the values and could check it sorts them in the correct way to call gda_data_model_append_values, but it *doesn't work*, it don't return an error or -1 and  if I print to the consol the content of the table afected the row doesn't exist!!
 
Do I miss understand the way to insert a row using the API? exist another way? I'm using the following procedure:

1- create a GList with the values (or an unset GValue representing a NULL one)
2. call gda_data_model_append_values, using that GList

That way of proceeding is correct, but  what happens depends of the real implementation of the GdaDataModel you use: some models are read-only, some are not (use gda_data_model_get_attributes_at() to test what can be done on a (row,column) value).

If you want to write data in a table, which I assume is what you want to do, then you should use a GdaDataModelQuery object (which itself implements the GdaDataModel interface) and set its UPDATE, DELETE and INSERT queries so it knows how to actually update, delete or insert a row in the table (note that I'm currently working to make the object create the UPDATE, DELETE and INSERT queries for the basic cases).


Cheers,

Vivien


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