[libgda] postgresql: metadata uses no contexts



commit 171093b93bb7bbeb211155a8458f1ef69e525109
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date:   Tue Jan 8 18:45:55 2019 -0600

    postgresql: metadata uses no contexts
    
    PostgreSQL provider now uses no contexts while updating
    meta data, to avoid some issues. Fixed _columns table
    update too.
    
    Added new methods and updated documentation to GdaMetaContext
    to improve handling on _columns table updates.

 libgda/gda-connection.c                          | 34 +++++++++++----------
 libgda/gda-meta-store.c                          | 19 ++++++++++--
 libgda/gda-meta-store.h                          |  1 +
 libgda/gda-server-provider-private.h             |  6 ++++
 providers/reuseable/postgres/gda-postgres-meta.c | 38 ++++++++++--------------
 tests/providers/meson.build                      |  2 +-
 6 files changed, 57 insertions(+), 43 deletions(-)
---
diff --git a/libgda/gda-connection.c b/libgda/gda-connection.c
index 25e358e4a..44121b921 100644
--- a/libgda/gda-connection.c
+++ b/libgda/gda-connection.c
@@ -4108,27 +4108,30 @@ local_meta_update (GdaServerProvider *provider, GdaConnection *cnc, GdaMetaConte
                         *  -1- @character_set_catalog, @character_set_schema, @character_set_name
                         *  -2- @collation_catalog, @collation_schema, @collation_name
                         */
-                       i = check_parameters (context, error, 3,
-                                             &catalog, G_TYPE_STRING,
-                                             &schema, G_TYPE_STRING,
-                                             &name, G_TYPE_STRING, NULL,
-                                             "table_catalog", &catalog, "table_schema", &schema, 
"table_name", &name, NULL,
-                                             "character_set_catalog", &catalog, "character_set_schema", 
&schema, "character_set_name", &name, NULL,
-                                             "collation_catalog", &catalog, "collation_schema", &schema, 
"collation_name", &name, NULL);
-                       if (i < 0)
-                               return FALSE;
-                       
-                       ASSERT_TABLE_NAME (tname, "columns");
-                       if (i == 0) {
+                       if (gda_meta_context_get_n_columns (context) == 3)
+                       {
+                               i = check_parameters (context, error, 3,
+                                                           &catalog, G_TYPE_STRING,
+                                                           &schema, G_TYPE_STRING,
+                                                           &name, G_TYPE_STRING, NULL,
+                                                           "table_catalog", &catalog, "table_schema", 
&schema, "table_name", &name, NULL,
+                                                           "character_set_catalog", &catalog, 
"character_set_schema", &schema, "character_set_name", &name, NULL,
+                                                           "collation_catalog", &catalog, 
"collation_schema", &schema, "collation_name", &name, NULL);
+                               if (i < 0)
+                                       return FALSE;
+
+                               ASSERT_TABLE_NAME (tname, "columns");
                                retval = _gda_server_provider_meta_3arg (provider, cnc, store, context,
                                                                         GDA_SERVER_META_COLUMNS, catalog, 
schema, name, error);
                                WARN_META_UPDATE_FAILURE (retval, "columns");
-                               return retval;
                        }
                        else {
-                               /* nothing to do */
-                               return TRUE;
+                               ASSERT_TABLE_NAME (tname, "columns");
+                               retval = _gda_server_provider_meta_0arg (provider, cnc, store, context,
+                                                                        GDA_SERVER_META__COLUMNS, error);
+                               WARN_META_UPDATE_FAILURE (retval, "columns");
                        }
+                       return retval;
                }
                else if ((tname[1] == 'o') && (tname[2] == 'l')) {
                        /* _collations, params: 
@@ -4987,7 +4990,6 @@ gda_connection_update_meta_store (GdaConnection *cnc, GdaMetaContext *context, G
                for (i = 0; i < nb; i++) {
                        /*g_print ("%s() %s(cnc=>%p store=>%p)\n", __FUNCTION__, rmeta [i].func_name, cnc, 
store);*/
                        lcontext.table_name = rmeta [i].table_name;
-      g_message ("Updating FULL mata store at table: %s", gda_meta_context_get_table (&lcontext));
                        if (! _gda_server_provider_meta_0arg (provider, cnc, store, &lcontext,
                                                              rmeta[i].func_type, error)) {
                                /*
diff --git a/libgda/gda-meta-store.c b/libgda/gda-meta-store.c
index b9db24a00..eebb67229 100644
--- a/libgda/gda-meta-store.c
+++ b/libgda/gda-meta-store.c
@@ -435,10 +435,13 @@ gda_meta_context_free (GdaMetaContext *ctx)
  * @ctx: a #GdaMetaContext
  *
  * Creates a string representation of given context.
+ *
+ * Returns: (transfer full): a new string with the representation of the context
  */
 gchar*
 gda_meta_context_stringify (GdaMetaContext *ctx)
 {
+       g_return_val_if_fail (ctx != NULL, g_strdup (""));
        gint i;
        gchar *str;
        GString *string = g_string_new ("{");
@@ -460,6 +463,19 @@ gda_meta_context_stringify (GdaMetaContext *ctx)
        return str;
 }
 
+/**
+ * gda_meta_context_get_n_columns:
+ * @ctx: a #GdaMetaContext
+ *
+ * Returns: the number of columns in the context
+ */
+gint
+gda_meta_context_get_n_columns (GdaMetaContext *ctx)
+{
+       g_return_val_if_fail (ctx != NULL, 0);
+       return ctx->size;
+}
+
 
 G_DEFINE_BOXED_TYPE(GdaMetaContext, gda_meta_context, gda_meta_context_copy, gda_meta_context_free)
 
@@ -3587,9 +3603,6 @@ gda_meta_store_modify_v (GdaMetaStore *store, const gchar *table_name,
                                        g_print ("\n");
 #endif
                                        GError *suggest_reports_error = NULL;
-                                       gchar *s = gda_meta_context_stringify (&context);
-                                       g_message ("Modify Meta store, using Context: %s", s);
-                                       g_free (s);
                                        g_signal_emit (store, gda_meta_store_signals[SUGGEST_UPDATE], 0, 
&context,
                                                       &suggest_reports_error);
                                        g_free (context.column_values);
diff --git a/libgda/gda-meta-store.h b/libgda/gda-meta-store.h
index 6398a8a74..1f72612c3 100644
--- a/libgda/gda-meta-store.h
+++ b/libgda/gda-meta-store.h
@@ -219,6 +219,7 @@ void              gda_meta_context_set_columns            (GdaMetaContext *ctx,
                                                           GdaConnection *cnc);
 void              gda_meta_context_free                   (GdaMetaContext *ctx);
 gchar            *gda_meta_context_stringify              (GdaMetaContext *ctx);
+gint              gda_meta_context_get_n_columns          (GdaMetaContext *ctx);
 
 G_END_DECLS
 
diff --git a/libgda/gda-server-provider-private.h b/libgda/gda-server-provider-private.h
index 24ee178e4..9e543ad72 100644
--- a/libgda/gda-server-provider-private.h
+++ b/libgda/gda-server-provider-private.h
@@ -140,6 +140,12 @@ _gda_server_provider_meta_4arg (GdaServerProvider *provider, GdaConnection *cnc,
                                GdaServerProviderMetaType type, const GValue *value0, const GValue *value1, 
const GValue *value2, const GValue *value3, GError **error);
 
 
+gboolean
+_gda_server_provider_meta_5arg (GdaServerProvider *provider, GdaConnection *cnc,
+                               GdaMetaStore *meta, GdaMetaContext *ctx,
+                               GdaServerProviderMetaType type, const GValue *value0, const GValue *value1, 
const GValue *value2, const GValue *value3, const GValue *value4, GError **error);
+
+
 G_END_DECLS
 
 #endif
diff --git a/providers/reuseable/postgres/gda-postgres-meta.c 
b/providers/reuseable/postgres/gda-postgres-meta.c
index 7f5750bd6..dcea2138f 100644
--- a/providers/reuseable/postgres/gda-postgres-meta.c
+++ b/providers/reuseable/postgres/gda-postgres-meta.c
@@ -432,7 +432,7 @@ _gda_postgres_meta__udt (G_GNUC_UNUSED GdaServerProvider *prov, GdaConnection *c
 
        gda_meta_store_set_reserved_keywords_func (store, _gda_postgres_reuseable_get_reserved_keywords_func
                                                   ((GdaProviderReuseable*) rdata));
-       retval = gda_meta_store_modify_with_context (store, context, model, error);
+       retval = gda_meta_store_modify (store, gda_meta_context_get_table (context), model, NULL, error, 
NULL);
        g_object_unref (model);
                
        return retval;
@@ -494,7 +494,7 @@ _gda_postgres_meta__udt_cols (G_GNUC_UNUSED GdaServerProvider *prov, GdaConnecti
 
        gda_meta_store_set_reserved_keywords_func (store, _gda_postgres_reuseable_get_reserved_keywords_func
                                                   ((GdaProviderReuseable*) rdata));
-       retval = gda_meta_store_modify_with_context (store, context, model, error);
+       retval = gda_meta_store_modify (store, gda_meta_context_get_table (context), model, NULL, error, 
NULL);
        g_object_unref (model);
                
        return retval;
@@ -655,7 +655,7 @@ _gda_postgres_meta__constraints_dom (G_GNUC_UNUSED GdaServerProvider *prov, GdaC
 
        gda_meta_store_set_reserved_keywords_func (store, _gda_postgres_reuseable_get_reserved_keywords_func
                                                   ((GdaProviderReuseable*) rdata));
-       retval = gda_meta_store_modify_with_context (store, context, model, error);
+       retval = gda_meta_store_modify (store, gda_meta_context_get_table (context), model, NULL, error, 
NULL);
        g_object_unref (model);
                
        return retval;
@@ -862,7 +862,7 @@ _gda_postgres_meta__schemata (G_GNUC_UNUSED GdaServerProvider *prov, GdaConnecti
 
        gda_meta_store_set_reserved_keywords_func (store, _gda_postgres_reuseable_get_reserved_keywords_func
                                                   ((GdaProviderReuseable*) rdata));
-       retval = gda_meta_store_modify_with_context (store, context, model, error);
+       retval = gda_meta_store_modify (store, gda_meta_context_get_table (context), model, NULL, error, 
NULL);
        g_object_unref (model);
        
        return retval;
@@ -948,21 +948,16 @@ _gda_postgres_meta__tables_views (G_GNUC_UNUSED GdaServerProvider *prov, GdaConn
                                                                    GDA_STATEMENT_MODEL_RANDOM_ACCESS,
                                                                    _col_types_views, error);
 
-       GdaMetaContext c2;
-       c2 = *context; /* copy contents, just because we need to modify @context->table_name */
        if (tables_model != NULL) {
-    g_message ("Updating Tables: %s", gda_data_model_dump_as_string (tables_model));
-               c2.table_name = "_tables";
                gda_meta_store_set_reserved_keywords_func (store, 
_gda_postgres_reuseable_get_reserved_keywords_func
                                                   ((GdaProviderReuseable*) rdata));
-               retval = gda_meta_store_modify_with_context (store, &c2, tables_model, error);
+               retval = gda_meta_store_modify (store, "_tables", tables_model, NULL, error, NULL);
          g_object_unref (tables_model);
        }
        if (views_model != NULL) {
-               c2.table_name = "_views";
                gda_meta_store_set_reserved_keywords_func (store, 
_gda_postgres_reuseable_get_reserved_keywords_func
                                                   ((GdaProviderReuseable*) rdata));
-               retval = gda_meta_store_modify_with_context (store, &c2, views_model, error);
+               retval = gda_meta_store_modify (store, "_views", views_model, NULL, error, NULL);
          g_object_unref (views_model);
        }
 
@@ -1136,7 +1131,7 @@ gboolean _gda_postgres_meta__columns (G_GNUC_UNUSED GdaServerProvider *prov, Gda
        if (retval) {
                gda_meta_store_set_reserved_keywords_func (store, 
_gda_postgres_reuseable_get_reserved_keywords_func
                                                   ((GdaProviderReuseable*) rdata));
-               retval = gda_meta_store_modify_with_context (store, context, proxy, error);
+               retval = gda_meta_store_modify (store, gda_meta_context_get_table (context), proxy, NULL, 
error, NULL);
        }
        g_object_unref (proxy);
        g_object_unref (model);
@@ -1279,7 +1274,7 @@ _gda_postgres_meta__view_cols (G_GNUC_UNUSED GdaServerProvider *prov, GdaConnect
 
        gda_meta_store_set_reserved_keywords_func (store, _gda_postgres_reuseable_get_reserved_keywords_func
                                                   ((GdaProviderReuseable*) rdata));
-       retval = gda_meta_store_modify_with_context (store, context, model, error);
+       retval = gda_meta_store_modify (store, gda_meta_context_get_table (context), model, NULL, error, 
NULL);
        g_object_unref (model);
        
        return retval;
@@ -1344,7 +1339,7 @@ _gda_postgres_meta__constraints_tab (G_GNUC_UNUSED GdaServerProvider *prov, GdaC
 
        gda_meta_store_set_reserved_keywords_func (store, _gda_postgres_reuseable_get_reserved_keywords_func
                                                   ((GdaProviderReuseable*) rdata));
-       retval = gda_meta_store_modify_with_context (store, context, model, error);
+       retval = gda_meta_store_modify (store, gda_meta_context_get_table (context), model, NULL, error, 
NULL);
        g_object_unref (model);
                
        return retval;
@@ -1435,7 +1430,7 @@ _gda_postgres_meta__constraints_ref (G_GNUC_UNUSED GdaServerProvider *prov, GdaC
 
        gda_meta_store_set_reserved_keywords_func (store, _gda_postgres_reuseable_get_reserved_keywords_func
                                                   ((GdaProviderReuseable*) rdata));
-       retval = gda_meta_store_modify_with_context (store, context, model, error);
+       retval = gda_meta_store_modify (store, gda_meta_context_get_table (context), model, NULL, error, 
NULL);
        g_object_unref (model);
                
        return retval;
@@ -1509,7 +1504,7 @@ _gda_postgres_meta__key_columns (G_GNUC_UNUSED GdaServerProvider *prov, GdaConne
 
        gda_meta_store_set_reserved_keywords_func (store, _gda_postgres_reuseable_get_reserved_keywords_func
                                                   ((GdaProviderReuseable*) rdata));
-       retval = gda_meta_store_modify_with_context (store, context, model, error);
+       retval = gda_meta_store_modify (store, gda_meta_context_get_table (context), model, NULL, error, 
NULL);
        g_object_unref (model);
                
        return retval;
@@ -1583,7 +1578,7 @@ _gda_postgres_meta__check_columns (G_GNUC_UNUSED GdaServerProvider *prov, GdaCon
 
        gda_meta_store_set_reserved_keywords_func (store, _gda_postgres_reuseable_get_reserved_keywords_func
                                                   ((GdaProviderReuseable*) rdata));
-       retval = gda_meta_store_modify_with_context (store, context, model, error);
+       retval = gda_meta_store_modify (store, gda_meta_context_get_table (context), model, NULL, error, 
NULL);
        g_object_unref (model);
                
        return retval;
@@ -1662,7 +1657,7 @@ _gda_postgres_meta__triggers (G_GNUC_UNUSED GdaServerProvider *prov, GdaConnecti
 
        gda_meta_store_set_reserved_keywords_func (store, _gda_postgres_reuseable_get_reserved_keywords_func
                                                   ((GdaProviderReuseable*) rdata));
-       retval = gda_meta_store_modify_with_context (store, context, model, error);
+       retval = gda_meta_store_modify (store, gda_meta_context_get_table (context), model, NULL, error, 
NULL);
        g_object_unref (model);
                
        return retval;
@@ -1920,9 +1915,6 @@ _gda_postgres_meta_routine_col (G_GNUC_UNUSED GdaServerProvider *prov, GdaConnec
                if (!retval)
                        break;
        }
-                                       gchar *s = gda_meta_context_stringify (context);
-                                       g_message ("Context used by _routine_col: %s", s);
-                                       g_free (s);
 
        if (retval) {
                gda_meta_store_set_reserved_keywords_func (store, 
_gda_postgres_reuseable_get_reserved_keywords_func
@@ -2046,7 +2038,7 @@ _gda_postgres_meta__indexes_tab (G_GNUC_UNUSED GdaServerProvider *prov, GdaConne
 
        gda_meta_store_set_reserved_keywords_func (store, _gda_postgres_reuseable_get_reserved_keywords_func
                                                   ((GdaProviderReuseable*) rdata));
-       retval = gda_meta_store_modify_with_context (store, context, model, error);
+       retval = gda_meta_store_modify (store, gda_meta_context_get_table (context), model, NULL, error, 
NULL);
        g_object_unref (model);
 
        return retval;
@@ -2230,7 +2222,7 @@ _gda_postgres_meta__index_cols (G_GNUC_UNUSED GdaServerProvider *prov, GdaConnec
        gboolean retval;
        gda_meta_store_set_reserved_keywords_func (store, _gda_postgres_reuseable_get_reserved_keywords_func
                                                   ((GdaProviderReuseable*) rdata));
-       retval = gda_meta_store_modify_with_context (store, context, concat, error);
+       retval = gda_meta_store_modify (store, gda_meta_context_get_table (context), concat, NULL, error, 
NULL);
        g_object_unref (concat);
 
        return retval;
diff --git a/tests/providers/meson.build b/tests/providers/meson.build
index 64e5e2c80..deda29ac3 100644
--- a/tests/providers/meson.build
+++ b/tests/providers/meson.build
@@ -74,7 +74,7 @@ tchkpg = executable('check_postgres',
        install: false
        )
 test('ProviderPostgreSQL', tchkpg,
-       timeout: 800,
+       timeout: 2000,
        env: [
                'GDA_TOP_SRC_DIR='+meson.source_root(),
                'GDA_TOP_BUILD_DIR='+meson.build_root()


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