Re: [gnome-db] gda_value_new_from string()





2006/5/15, Vivien Malerba <vmalerba gmail com>:
On 5/15/06, Bas Driessen <bas driessen xobas com> wrote:
>
>
>  On Mon, 2006-05-15 at 09:45 +0200, Vivien Malerba wrote:
>
>  On 5/14/06, Murray Cumming < murrayc murrayc com> wrote:
> > On Sun, 2006-05-14 at 15:38 +1000, Bas Driessen wrote:
> > > Hello,
> > >
> > > Trying to get my applications to work with libgda CVS HEAD. Question
> > > regarding function gda_value_new_from string(). I have a line like
> > > this in my code:
> > >
> > > values = g_list_append(values,
> gda_value_new_from_string(dataValue,
> > > gda_column_get_gda_type(fa)));
> > >
> > > This transforms a string to a GdaValue using the correct type.
> > >
> > > Compiled with libgda CVS HEAD, this is failing now in most instances.
> > > Looking into gda_value_new_from_string(), it mostly fails the
> > > condition:
> > >
> > > if (g_value_type_transformable(G_TYPE_STRING, type))
> > >
> > > If my type is G_TYPE_STRING, all works OK, but if my type is
> > > G_TYPE_INT for instance, this test fails.
> > >
> > > How can I get this to work again? How can I get a string (=char*)
> > > converted to a GValue of G_TYPE_INT?
> >
> > I wonder how this would be suppose to work, if at all? Should the string
> > be human-readable (and therefore in the current locale.) or as used in a
> > SQL statement?
> >
> > Whenever I see "string representation" in the libgda documentation, I
> > need to see either "in the current locale", "in the SQL syntax", "in the
> > C locale", or something similar.
> >
>
> The SQL representation is supposed to be DBMS dependant (that is using
> whatever locale the DBMS we are connected to is using), and string
> representation is supposed to be in the locale the user is using.
>
> I'll update the documentation so there is no doubt about locales anymore.
>
>
>  Thanks Vivian, but still I am having problems finding a solution. The new
> gda_value_new_from_string() function is more limited than the old one before

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

> the GValue->GdaValue change.  Let's start at the core of the problems. How
> can I transform an integer value for instance to a GValue? There is no such
> function as gda_value_set_int for instance? Can you please advise?

value = g_new0 (GValue, 1);
g_value_init (value, G_TYPe_INT);
g_value_set_int (value, your_int_value);

or

value = gda_value_new (G_TYPE_INT);
g_value_set_int (value, your_int_value);

Cheers,

Vivien
_______________________________________________
gnome-db-list mailing list
gnome-db-list gnome org
http://mail.gnome.org/mailman/listinfo/gnome-db-list



--
Trabajar, la mejor arma para tu superación
"de grano en grano, se hace la arena" (R) (entrámite, pero para los cuates: LIBRE)

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