Re: [gnome-db] gda_value_new_from string()



On Mon, 2006-05-15 at 14:57 -0500, Daniel Espinosa wrote:


The set_from_string() allows to transform an int to a string, it
should be used by the
gda_value_new_from_string() function, I'll correct this ASAP.


What about to register the functions to transform the types used by GDA in the GLib's GType system, to simplify the code implementation?

I tested the following transformation, with out register any function and it works! using the following code for each type:


integer = g_new0(GValue, 1);
g_value_init(integer, G_TYPE_INT); // Substitude to any type
g_value_set_int(integer, -255); // Use the correct g_value_set_* function
g_value_transform(integer, string); // This is the transformation itself
g_string_printf(txt, "Integer to String: int = %s\n", g_value_get_string(string)); // printing the  string

I tested to string the following types using GLib 2.8.3 in Ubuntu 5.10: INT, UINT, INT64, BOOLEAN

and from String: FLOAT, DOUBLE


I found that GLib resgister a lot of transformation functions, for string to type and int's to other types of int's, bools, etc.

You can find then in the function g_value_transforms_init:

http://cvs.gnome.org/viewcvs/glib/gobject/gvaluetransform.c?rev=1.13&view=markup


Thanks Daniel, I agree that the transformations work OK from any type to a string, but not the other way around. If you look at that source code link you provided you will see that there is only the function "value_transform_string_string()". There are no transformations from string to int for instance. Meaning that I have to check all the types and write that logic myself now. Don't understand why these transformation functions (string->other) do not exist for GValue types.

OK, well programming over that hurdle and I believe that there are more GValue issues, but can not confirm yet. One of those is in the function gda_postgres_recordset_append_row(). It only appears to work with G_TYPE_STRING GValues. It looks like this line is failing if the returning GValue is of type G_TYPE_INT (and mostly like all other non G_TYPE_STRING instances):

cur_val = gda_value_stringify (gda_row_get_value ((GdaRow *) row, i));

Have to investigate, but if this rings a bell with someone, please let me know.

Thanks,
Bas.



Attachment: signature.asc
Description: This is a digitally signed message part



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