Re: [gnome-db] GdaSqlStatementSelect->where_cond



On 26 February 2010 16:39, Piotr Pokora <piotrek pokora gmail com> wrote:
> Vivien Malerba pisze:
>
> Hi!
>
>> You don't need to quote anything, but you need to to:
>> expr->value_is_ident = (gpointer) 0x1;
>
> It throws:
> CRITICAL **: gda_sql_identifier_split: assertion `id && *id' failed
>
> Code is more or less:
>
> GValue val = {0, };
> g_value_init (&val, G_TYPE_STRING);
> g_value_set_string (&val, "2010-01-01 00:00:00");
> expr->value = gda_value_new (G_VALUE_TYPE (&val));
> g_value_copy (&val , expr->value);
> expr->value_is_ident = (gpointer) 0x1;
> g_value_unset (&val);
> cond->operands = g_slist_append (cond->operands, expr);
>
> g_value_init (&val, G_TYPE_STRING);
> g_value_set_string (&val, "");
> expr->value = gda_value_new (G_VALUE_TYPE (&val));
> g_value_copy (&val , expr->value);
> expr->value_is_ident = (gpointer) 0x1;
> g_value_unset (&val);
> cond->operands = g_slist_append (cond->operands, expr);
>
>
> Without value_is_ident, sql is generated:
>
> WHERE ( FieldA = 2010-01-01 00:00:00) AND (FieldB = )
>
>> to specify that the GdaSqlExpr holds an SQL identifier.
>> See gda_sql_builder_add_id() in
>> http://git.gnome.org/browse/libgda/tree/libgda/gda-sql-builder.c
>
> I am not sure we are talking about the same expression value.
> I mean vale which is not field name, but value used in condition.
>

Yes, the tip I gave you earlier is for SQL identifiers (table or field
names for example), not for values, for which it's up to you to set
the GValue's string correctly:
g_value_set_string (&val,"'example'") for a string
g_value_set_string (&val,"123") for an int
...
Anyway for values I recommend to use variables
(GdaSqlExpr::param_spec) which your bind during the execution: you
then don't have to worry about how to represent them as a string.

The reason for this approach is again that this is meant to be used by
the SQL parsers.

Regards,

Vivien


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