Re: [gnome-db] Meta store and check if column exists
- From: Vivien Malerba <vmalerba gmail com>
- To: Piotr Pokora <piotrek pokora gmail com>
- Cc: gnome-db list <gnome-db-list gnome org>
- Subject: Re: [gnome-db] Meta store and check if column exists
- Date: Thu, 2 Dec 2010 20:42:58 +0100
On 2 December 2010 14:03, Piotr Pokora <piotrek pokora gmail com> wrote:
> Hi!
>
> Do I need to update meta store (gda_connection_update_meta_store())
> when I only check if particular column in table exists?
>
> Code which works:
>
> GdaMetaContext mcontext = {"_columns", 2, NULL, NULL};
> mcontext.column_names = g_new (gchar *, 2);
> mcontext.column_names[0] = "table_name";
> mcontext.column_names[1] = "column_name";
> mcontext.column_values = g_new (GValue *, 2);
> g_value_set_string ((mcontext.column_values[0] = gda_value_new
> (G_TYPE_STRING)), table_name);
> g_value_set_string ((mcontext.column_values[1] = gda_value_new
> (G_TYPE_STRING)), column_name);
>
>
> GdaDataModel *dm_schema =
> gda_connection_get_meta_store_data (mgd->priv->connection,
> GDA_CONNECTION_META_FIELDS, NULL, 2,
> "name", mcontext.column_values[0],
> "field_name", mcontext.column_values[1]);
>
> if (gda_data_model_get_n_rows (dm_schema) == 0)
> return FALSE; /* column doesn't exist */
>
> In case of SQLite, when column exists, and I update meta store, warn
> ing is thrown: 'constraint failed'. Without such update, there's no warning.
> Of course, meta store is updated when column is created in table.
You need to update the meta store (using
gda_connection_update_meta_store()) when you're not sure the database
schema has not changed since the last update (of course if the
connection is opened with the GDA_CONNECTION_OPTIONS_AUTO_META_DATA
flag and the meta store has been set then it is updated
automatically).
Also, if you can produce a stand alone program which illustrates the
'constraint failed' error, I'd be happy to correct the problem.
Regards,
Vivien
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]