2008/10/3 Daniel Espinosa
<esodan gmail com>
You have to init the GValue pointer first. You can use:
For upcomming Version 4.0 (the main difference is at GdaDataModel API)
GdaDataModel *model;
const GValue *integer;
GError *error = NULL;
integer = gda_value_new (G_TYPE_INT);
integer = gda_data_model_get_value_at (model, 0, 0, &error);
If you do this, then you'll have a memory leak as the "integer" value is lost in the 2nd line. I think the problem was that
the data model returned a GValue which has a type different than G_TYPE_INT. Before using any g_value_get*(), one must first check that the GValue value is of the expected type:
value = da_data_model_get_value_at (...)
if (G_VALUE_TYPE (value) == G_TYPE_INT)
myint = g_value_get_int (value);
else
/* the value represents a NULL value */
Note that a GdaDataModel, for a column always returns GValue of the same type for the different rows, or GDA_TYPE_NULL GValues.
You can check which type using gda_column_get_g_type ().
When the data model comes from the execution of a SELECT statement, you can force a column to be of a specific type by using gda_connection_statement_execute_select_full () and speficying the 5th argument.
Regards,
Vivien