]> saetta.ns0.it Git - gdadbcopy/commitdiff
Changed method to obtain fields informations.
authorAndrea Zagli <azagli@libero.it>
Thu, 22 Nov 2012 20:29:33 +0000 (21:29 +0100)
committerAndrea Zagli <azagli@libero.it>
Thu, 22 Nov 2012 20:29:33 +0000 (21:29 +0100)
src/main.c
tests/db.db

index 001de4a457fb674dd204541da52108946ba05292..eb60f697bdef1baedf767298c36c532137321016 100644 (file)
@@ -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
index aa2abdd6b9cfe1fa1397a7dab066c9cf65a94fa5..6b88bd9cb1841cc069c831cf19be577b87b4828f 100644 (file)
Binary files a/tests/db.db and b/tests/db.db differ