From 76c3139b2bf94ba3786a14c2c1f563a2ccbdc6b8 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Thu, 22 Nov 2012 21:29:33 +0100 Subject: [PATCH] Changed method to obtain fields informations. --- src/main.c | 64 ++++++++++++++++++++++++++++++---------------------- tests/db.db | Bin 3072 -> 3072 bytes 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/main.c b/src/main.c index 001de4a..eb60f69 100644 --- a/src/main.c +++ b/src/main.c @@ -67,13 +67,13 @@ read_fields (const gchar *table_name, GdaServerOperation *op) GdaMetaContext mcontext = {"_columns", 1, NULL, NULL}; GValue *gval; + GdaMetaStore *store; + GdaMetaStruct *mstruct; + GdaMetaDbObject *dbo; + GSList *list; + GdaMetaTableColumn *column; - GdaDataModel *dm_fields; - - guint rows; - guint row; - - error = NULL; + guint i; mcontext.column_names = g_new (gchar *, 1); mcontext.column_names[0] = "table_name"; @@ -83,6 +83,7 @@ read_fields (const gchar *table_name, GdaServerOperation *op) g_value_take_string (mcontext.column_values[0], gda_sql_identifier_quote (table_name, gda_conn_ref_db, NULL, FALSE, FALSE)); + error = NULL; if (!gda_connection_update_meta_store (gda_conn_ref_db, &mcontext, &error)) { g_warning ("Unable to update database metastore: %s", @@ -91,37 +92,49 @@ read_fields (const gchar *table_name, GdaServerOperation *op) } error = NULL; + gval = gda_value_new (G_TYPE_STRING); g_value_take_string (gval, (gchar *)table_name); - dm_fields = gda_connection_get_meta_store_data (gda_conn_ref_db, - GDA_CONNECTION_META_FIELDS, - &error, - 1, - "name", gval); - if (dm_fields != NULL && error == NULL) + + store = gda_connection_get_meta_store (gda_conn_ref_db); + mstruct = gda_meta_struct_new (store, GDA_META_STRUCT_FEATURE_NONE); + dbo = gda_meta_struct_complement (mstruct, GDA_META_DB_TABLE, + NULL, NULL, + gval, &error); + + gda_value_free (gval); + if (dbo != NULL) { - rows = gda_data_model_get_n_rows (dm_fields); - for (row = 0; row < rows; row++) + GdaMetaTable *table = GDA_META_TABLE (dbo); + + i = 0; + for (list = table->columns; list; list = list->next, i++) { - g_message ("\t\tField: %s - %s - %s - %d - %d", gda_value_stringify (gda_data_model_get_value_at (dm_fields, 0, row, NULL)), - gda_value_stringify (gda_data_model_get_value_at (dm_fields, 1, row, NULL)), - gda_value_stringify (gda_data_model_get_value_at (dm_fields, 2, row, NULL)), - g_value_get_int (gda_data_model_get_value_at (dm_fields, 3, row, NULL)), - g_value_get_int (gda_data_model_get_value_at (dm_fields, 4, row, NULL))); + column = (GdaMetaTableColumn *)list->data; + g_message ("\t\tField: %s - %s - %d - %d - %d - %s", + column->column_name, + column->column_type, + column->gtype, + column->pkey, + column->nullok, + column->default_value); + error = NULL; if (!gda_server_operation_set_value_at (op, - gda_value_stringify (gda_data_model_get_value_at (dm_fields, 0, row, NULL)), + column->column_name, &error, - g_strdup_printf ("/FIELDS_A/@COLUMN_NAME/%d", row))) + g_strdup_printf ("/FIELDS_A/@COLUMN_NAME/%d", i))) { g_warning ("Error on setting GdaServerOperation's value: %s.", error != NULL && error->message != NULL ? error->message : "no details"); continue; } + + error = NULL; if (!gda_server_operation_set_value_at (op, - gda_value_stringify (gda_data_model_get_value_at (dm_fields, 1, row, NULL)), + column->column_type, &error, - g_strdup_printf ("/FIELDS_A/@COLUMN_TYPE/%d", row))) + g_strdup_printf ("/FIELDS_A/@COLUMN_TYPE/%d", i))) { g_warning ("Error on setting GdaServerOperation's value: %s.", error != NULL && error->message != NULL ? error->message : "no details"); @@ -129,10 +142,7 @@ read_fields (const gchar *table_name, GdaServerOperation *op) } } } - if (dm_fields != NULL) - { - g_object_unref (dm_fields); - } + g_object_unref (mstruct); } static void diff --git a/tests/db.db b/tests/db.db index aa2abdd6b9cfe1fa1397a7dab066c9cf65a94fa5..6b88bd9cb1841cc069c831cf19be577b87b4828f 100644 GIT binary patch delta 49 vcmZpWXpop7Ehxdjz`zW|Oi(N_QOB53Vq?N`W>!X!)aFL!HkQp3nDdwcv3m$< delta 48 wcmZpWXpop7Ey%;bz`zW}OhB4vqK+{m&&Gu1%!?IRSXdc>LQI0HfRoR{#J2 -- 2.49.0