Re: [gnome-db][PATCH] gda_recorset_to_array



On 14 Aug 2001 23:10:11 +0200, Rodrigo Moya wrote:
> On 14 Aug 2001 22:50:49 +0200, Diego Gonzalez wrote:
> > hi
> > 
> > 	Here is a path against gda-recordset.[c-h] that Rodrigo asked me to
> > send. It implements gda_recordset_to_array, it returns a GPtrArray
> > containing the hole recordset.
> > 
> > 	I don't know if this is the best way to do it, but here it is anyway. 
> > 
> yes, it is ok. I just checked it in, with only one modification: I
> removed the cursor location stuff, as it was useless
> 
oops, I'm sorry but it was not ok :-( a more correct implementation:

GPtrArray *
gda_recordset_to_array (GdaRecordset *rs)
{
        GPtrArray *array, *row;
        GdaField *rc;
        gint fields, j;
        gulong position;

        g_return_val_if_fail (GDA_IS_RECORDSET(rs), 0);
        g_return_val_if_fail (rs->open, 0);

        position = gda_recordset_move_first(rs);
	fields = gda_recordset_rowsize (rs);

        array = g_ptr_array_new();

        while (position != GDA_RECORDSET_INVALID_POSITION &&
               !gda_recordset_eof (rs)) {
                row = g_ptr_array_new();

                for (j = 0; j < fields; j++) {
                        rc = gda_recordset_field_idx(rs, j);
                        g_ptr_array_add(row, rc);
                }

                g_ptr_array_add(array, row);
                position = gda_recordset_move_next (rs);
        }

        return array;
}

and, this is not 100% correct, since it's adding to each row just a
reference to the GdaField's stored in the GdaRecordset. This is wrong
because those GdaField are replaced each time you _move on the
recordset. So, what should be done is to _clone the GdaField "rc". But,
we need to implement the gda_field_clone function :-(

do you want to do it?

cheers
-- 
Rodrigo Moya <rodrigo gnome-db org> - <rodrigo ximian com>
http://www.gnome-db.org/ - http://www.ximian.com/




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