[libgda] Removed GdaAttributesManager for GdaMetaStructColumn



commit 3c05922bc34a2a54c662961ead0d8f7737547297
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date:   Sat Feb 23 22:39:13 2019 -0600

    Removed GdaAttributesManager for GdaMetaStructColumn
    
    GdaMetStructColumn now holds its own auto increment flag
    and its description to avoid using a external manager
    
    Fixes for issue GNOME/libgda#173

 doc/C/libgda/libgda-6.0-sections.txt       |  5 +-
 libgda/gda-meta-struct-io.c                |  5 +-
 libgda/gda-meta-struct.c                   | 86 +++++-------------------------
 libgda/gda-meta-struct.h                   | 17 +-----
 libgda/gda-util.c                          |  9 ++--
 libgda/libgda.symbols                      |  3 --
 tests/raw-ddl-creator.c                    | 22 +++-----
 tools/browser/schema-browser/mgr-columns.c |  4 +-
 tools/browser/schema-browser/table-info.c  |  8 ++-
 tools/common/t-app.c                       | 27 ++--------
 tools/common/web-server.c                  | 29 ++--------
 11 files changed, 40 insertions(+), 175 deletions(-)
---
diff --git a/doc/C/libgda/libgda-6.0-sections.txt b/doc/C/libgda/libgda-6.0-sections.txt
index 1adfa6211..091834368 100644
--- a/doc/C/libgda/libgda-6.0-sections.txt
+++ b/doc/C/libgda/libgda-6.0-sections.txt
@@ -1718,10 +1718,6 @@ GdaMetaTable
 GdaMetaView
 GdaMetaTableColumn
 GDA_META_TABLE_COLUMN
-gda_meta_table_column_get_attribute
-gda_meta_table_column_set_attribute
-gda_meta_table_column_set_attribute_static
-gda_meta_table_column_foreach_attribute
 GdaMetaForeignKeyPolicy
 GdaMetaTableForeignKey
 GDA_META_TABLE_FOREIGN_KEY
@@ -2224,3 +2220,4 @@ GDA_TYPE_REPETITIVE_STATEMENT
 gda_repetitive_statement_get_type
 </SECTION>
 
+
diff --git a/libgda/gda-meta-struct-io.c b/libgda/gda-meta-struct-io.c
index bc4660d01..b7ce0cf14 100644
--- a/libgda/gda-meta-struct-io.c
+++ b/libgda/gda-meta-struct-io.c
@@ -274,10 +274,7 @@ create_table_object (GdaMetaStruct *mstruct, const GValue *catalog, const gchar
                        /* FIXME: handle default value */
                        extra = xmlGetProp (cnode, BAD_CAST "autoinc");
                        if (extra) {
-                               GValue *true_value;
-                               g_value_set_boolean ((true_value = gda_value_new (G_TYPE_BOOLEAN)), TRUE);
-                               gda_meta_table_column_set_attribute_static (tcol, 
GDA_ATTRIBUTE_AUTO_INCREMENT, true_value);
-                               gda_value_free (true_value);
+                               tcol->auto_incement = TRUE;
                                xmlFree (extra);
                        }
 
diff --git a/libgda/gda-meta-struct.c b/libgda/gda-meta-struct.c
index 5c8491018..8de477526 100644
--- a/libgda/gda-meta-struct.c
+++ b/libgda/gda-meta-struct.c
@@ -56,6 +56,8 @@ typedef struct {
        GHashTable   *index; /* key = [catalog].[schema].[name], value = a GdaMetaDbObject. Note: catalog, 
schema and name 
                              * are case sensitive (and don't have any double quote around them) */
        guint         features;
+       gboolean      auto_incement;
+       gchar        *desc;
 } GdaMetaStructPrivate;
 G_DEFINE_TYPE_WITH_PRIVATE (GdaMetaStruct, gda_meta_struct, G_TYPE_OBJECT)
 
@@ -70,8 +72,6 @@ static void gda_meta_view_free_contents (GdaMetaView *view);
 static void gda_meta_table_column_free (GdaMetaTableColumn *tcol);
 static void gda_meta_table_foreign_key_free (GdaMetaTableForeignKey *tfk);
 
-static GdaAttributesManager *att_mgr;
-
 /* properties */
 enum {
        PROP_0,
@@ -116,8 +116,6 @@ gda_meta_struct_class_init (GdaMetaStructClass *klass) {
        /* virtual methods */
        object_class->dispose = gda_meta_struct_dispose;
 
-       /* extra */
-       att_mgr = gda_attributes_manager_new (FALSE, NULL, NULL);
 }
 
 
@@ -127,6 +125,8 @@ gda_meta_struct_init (GdaMetaStruct *mstruct) {
        priv->store = NULL;
        priv->db_objects = NULL;
        priv->index = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+       priv->auto_incement = FALSE;
+       priv->desc = NULL;
 }
 
 
@@ -981,26 +981,23 @@ _meta_struct_complement (GdaMetaStruct *mstruct, GdaMetaDbObjectType type,
                        if (!gda_value_is_null (cvalue)) {
                                gchar **array, *tmp;
                                gint ai;
-                               GValue *true_value;
 
-                               g_value_set_boolean ((true_value = gda_value_new (G_TYPE_BOOLEAN)), TRUE);
                                cstr = g_value_get_string (cvalue);
                                array = g_strsplit (cstr, ",", 0);
                                for (ai = 0; array [ai]; ai++) {
                                        tmp = g_strstrip (array [ai]);
-                                       if (!strcmp (tmp, GDA_EXTRA_AUTO_INCREMENT))
-                                               gda_attributes_manager_set (att_mgr, tcol, 
GDA_ATTRIBUTE_AUTO_INCREMENT, 
-                                                                           true_value);
+                                       if (!g_strcmp0 (tmp, GDA_EXTRA_AUTO_INCREMENT)) {
+                                               tcol->auto_incement = TRUE;
+                                       }
                                }
-                               gda_value_free (true_value);
                                g_strfreev (array);
                        }
 
                        cvalue = gda_data_model_get_value_at (model, 10, i, error);
                        if (!cvalue) goto onerror;
-                       if (!gda_value_is_null (cvalue))
-                               gda_attributes_manager_set (att_mgr, tcol, GDA_ATTRIBUTE_DESCRIPTION, 
-                                                           cvalue);
+                       if (!gda_value_is_null (cvalue)) {
+                               tcol->desc = g_value_dup_string (cvalue);
+                       }
 
                }
                mt->columns = g_slist_reverse (mt->columns);
@@ -2090,7 +2087,9 @@ gda_meta_table_column_free (GdaMetaTableColumn *tcol)
        g_free (tcol->column_name);
        g_free (tcol->column_type);
        g_free (tcol->default_value);
-       gda_attributes_manager_clear (att_mgr, tcol);
+       if (tcol->desc != NULL) {
+               g_free (tcol->desc);
+       }
        g_free (tcol);
 }
 
@@ -2566,62 +2565,3 @@ _gda_meta_struct_add_db_object (GdaMetaStruct *mstruct, GdaMetaDbObject *dbo, GE
        }
 }
 
-/**
- * gda_meta_table_column_get_attribute:
- * @tcol: a #GdaMetaTableColumn
- * @attribute: attribute name as a string
- *
- * Get the value associated to a named attribute.
- *
- * Attributes can have any name, but Libgda proposes some default names, see <link 
linkend="libgda-6.0-Attributes-manager.synopsis">this section</link>.
- *
- * Returns: (transfer none): a read-only #GValue, or %NULL if not attribute named @attribute has been set 
for @column
- */
-const GValue *
-gda_meta_table_column_get_attribute (GdaMetaTableColumn *tcol, const gchar *attribute)
-{
-       return gda_attributes_manager_get (att_mgr, tcol, attribute);
-}
-
-/**
- * gda_meta_table_column_set_attribute:
- * @tcol: a #GdaMetaTableColumn
- * @attribute: attribute name as a static string
- * @value: (nullable): a #GValue, or %NULL
- * @destroy: (nullable): function called when @attribute has to be freed, or %NULL
- *
- * Set the value associated to a named attribute.
- *
- * Attributes can have any name, but Libgda proposes some default names, see <link 
linkend="libgda-40-Attributes-manager.synopsis">this section</link>.
- * If there is already an attribute named @attribute set, then its value is replaced with the new @value, 
- * except if @value is %NULL, in which case the attribute is removed.
- *
- * Warning: @attribute is not copied, if it needs to be freed when not used anymore, then @destroy should 
point to
- * the functions which will free it (typically g_free()). If @attribute does not need to be freed, then 
@destroy can be %NULL.
- */
-void
-gda_meta_table_column_set_attribute (GdaMetaTableColumn *tcol, const gchar *attribute, const GValue *value,
-                                    GDestroyNotify destroy)
-{
-       const GValue *cvalue;
-       cvalue = gda_attributes_manager_get (att_mgr, tcol, attribute);
-       if ((value && cvalue && !gda_value_differ (cvalue, value)) ||
-           (!value && !cvalue))
-               return;
-
-       gda_attributes_manager_set_full (att_mgr, tcol, attribute, value, destroy);
-}
-
-/**
- * gda_meta_table_column_foreach_attribute:
- * @tcol: a #GdaMetaTableColumn
- * @func: (scope call): a #GdaAttributesManagerFunc function
- * @data: (closure): user data to be passed as last argument of @func each time it is called
- *
- * Calls @func for each attribute set to tcol
- */
-void
-gda_meta_table_column_foreach_attribute (GdaMetaTableColumn *tcol, GdaAttributesManagerFunc func, gpointer 
data)
-{
-       gda_attributes_manager_foreach (att_mgr, tcol, func, data);
-}
diff --git a/libgda/gda-meta-struct.h b/libgda/gda-meta-struct.h
index 20a208e9a..9bba1fc35 100644
--- a/libgda/gda-meta-struct.h
+++ b/libgda/gda-meta-struct.h
@@ -258,6 +258,8 @@ typedef struct {
        gboolean      pkey;
        gboolean      nullok;
        gchar        *default_value;
+       gboolean      auto_incement;
+       gchar        *desc;
 
        /*< private >*/
        /* Padding for future expansion */
@@ -277,21 +279,6 @@ typedef struct {
  */
 #define GDA_META_TABLE_COLUMN(col) ((GdaMetaTableColumn*)(col))
 
-const GValue *gda_meta_table_column_get_attribute (GdaMetaTableColumn *tcol, const gchar *attribute);
-void          gda_meta_table_column_set_attribute (GdaMetaTableColumn *tcol, const gchar *attribute, const 
GValue *value,
-                                                  GDestroyNotify destroy);
-/**
- * gda_meta_table_column_set_attribute_static:
- * @column: a #GdaMetaTableColumn
- * @attribute: attribute's name
- * @value: (nullable): a #GValue, or %NULL
- *
- * This function is similar to gda_meta_table_column_set_attribute() but for static strings
- */
-#define gda_meta_table_column_set_attribute_static(column,attribute,value) 
gda_meta_table_column_set_attribute((column),(attribute),(value),NULL)
-
-void          gda_meta_table_column_foreach_attribute (GdaMetaTableColumn *tcol, GdaAttributesManagerFunc 
func, gpointer data);
-
 /**
  * GdaMetaForeignKeyPolicy:
  * @GDA_META_FOREIGN_KEY_UNKNOWN: unspecified policy
diff --git a/libgda/gda-util.c b/libgda/gda-util.c
index 5b957e066..f3f8586f1 100644
--- a/libgda/gda-util.c
+++ b/libgda/gda-util.c
@@ -602,11 +602,8 @@ gda_utility_data_model_find_column_description (GdaDataSelect *model, const gcha
                        GdaMetaTableColumn *meta_table_column = select_field->validity_meta_table_column;
 
                        if (! strcmp (meta_table_column->column_name, field_name)) {
-                               const GValue *gvalue = gda_meta_table_column_get_attribute
-                                       (meta_table_column, GDA_ATTRIBUTE_DESCRIPTION);
-
                                gda_sql_statement_free (sql_statement);
-                               return gvalue ? g_value_get_string (gvalue) : NULL;
+                               return meta_table_column->desc;
                        }
                }
        }
@@ -1270,7 +1267,7 @@ gda_compute_dml_statements (GdaConnection *cnc, GdaStatement *select_stmt, gbool
                        if (tcol->default_value)
                                g_value_set_string ((expr->value = gda_value_new (G_TYPE_STRING)),
                                                    tcol->default_value);
-                       else if (gda_meta_table_column_get_attribute (tcol, GDA_ATTRIBUTE_AUTO_INCREMENT))
+                       else if (tcol->auto_incement)
                                expr->value = gda_value_new_default (GDA_EXTRA_AUTO_INCREMENT);
 
                        expr->param_spec = pspec;
@@ -1285,7 +1282,7 @@ gda_compute_dml_statements (GdaConnection *cnc, GdaStatement *select_stmt, gbool
                        if (tcol->default_value)
                                g_value_set_string ((expr->value = gda_value_new (G_TYPE_STRING)),
                                                    tcol->default_value);
-                       else if (gda_meta_table_column_get_attribute (tcol, GDA_ATTRIBUTE_AUTO_INCREMENT))
+                       else if (tcol->auto_incement)
                                expr->value = gda_value_new_default (GDA_EXTRA_AUTO_INCREMENT);
                        expr->param_spec = pspec;
                        ust->expr_list = g_slist_append (ust->expr_list, expr);
diff --git a/libgda/libgda.symbols b/libgda/libgda.symbols
index 92a83c5e4..d27e893c0 100644
--- a/libgda/libgda.symbols
+++ b/libgda/libgda.symbols
@@ -505,9 +505,6 @@
        gda_meta_struct_load_from_xml_file
        gda_meta_struct_new
        gda_meta_struct_sort_db_objects
-       gda_meta_table_column_foreach_attribute
-       gda_meta_table_column_get_attribute
-       gda_meta_table_column_set_attribute
        gda_null_get_type
        gda_numeric_copy
        gda_numeric_free
diff --git a/tests/raw-ddl-creator.c b/tests/raw-ddl-creator.c
index d5a429f5f..a0cf76b47 100644
--- a/tests/raw-ddl-creator.c
+++ b/tests/raw-ddl-creator.c
@@ -525,19 +525,6 @@ typedef struct {
        GError **error;
        gboolean allok;
 } FData;
-static void
-meta_table_column_foreach_attribute_func (const gchar *att_name, const GValue *value, FData *fdata)
-{
-       if (!fdata->allok)
-               return;
-       if (!strcmp (att_name, GDA_ATTRIBUTE_AUTO_INCREMENT) &&
-           (G_VALUE_TYPE (value) == G_TYPE_BOOLEAN) &&
-           g_value_get_boolean (value)) {
-               fdata->allok = gda_server_operation_set_value_at (fdata->op, "TRUE", fdata->error,
-                                                                 "/FIELDS_A/@COLUMN_AUTOINC/%d",
-                                                                 fdata->index);
-       }
-}
 
 static GdaServerOperation *
 create_server_operation_for_table (RawDDLCreator *ddlc, GdaServerProvider *prov, GdaConnection *cnc,
@@ -582,8 +569,13 @@ create_server_operation_for_table (RawDDLCreator *ddlc, GdaServerProvider *prov,
                fdata.index = index;
                fdata.error = error;
                fdata.allok = TRUE;
-               gda_meta_table_column_foreach_attribute (tcol, (GdaAttributesManagerFunc) 
meta_table_column_foreach_attribute_func,
-                                                        &fdata);
+
+               if (tcol->auto_incement) {
+                       fdata.allok = gda_server_operation_set_value_at (fdata.op, "TRUE", fdata.error,
+                                                                 "/FIELDS_A/@COLUMN_AUTOINC/%d",
+                                                                 fdata.index);
+               }
+
                if (!fdata.allok)
                        goto onerror;
 
diff --git a/tools/browser/schema-browser/mgr-columns.c b/tools/browser/schema-browser/mgr-columns.c
index 2d22827a6..b04a6dd5e 100644
--- a/tools/browser/schema-browser/mgr-columns.c
+++ b/tools/browser/schema-browser/mgr-columns.c
@@ -384,9 +384,7 @@ mgr_columns_update_children (GdaTreeManager *manager, GdaTreeNode *node, const G
                                details = g_string_new ("");
                        g_string_append (details, _("Foreign key"));
                }
-               const GValue *autoinc;
-               autoinc = gda_meta_table_column_get_attribute (col, GDA_ATTRIBUTE_AUTO_INCREMENT);
-               if (autoinc) {
+               if (col->auto_incement) {
                        if (details)
                                g_string_append (details, ", ");
                        else
diff --git a/tools/browser/schema-browser/table-info.c b/tools/browser/schema-browser/table-info.c
index d007530be..bdead3235 100644
--- a/tools/browser/schema-browser/table-info.c
+++ b/tools/browser/schema-browser/table-info.c
@@ -771,22 +771,20 @@ action_insert_cb (G_GNUC_UNUSED GSimpleAction *action, G_GNUC_UNUSED GVariant *s
        for (nthcol = 0, list = mtable->columns; list; nthcol++, list = list->next) {
                GdaMetaTableColumn *col = (GdaMetaTableColumn*) list->data;
                gchar *plugin;
-               const GValue *autoinc;
                GdaHolder *holder;
 
                plugin = t_connection_get_table_column_attribute (tinfo->priv->tcnc,
                                                                        mtable, col,
                                                                        T_CONNECTION_COLUMN_PLUGIN,
                                                                        NULL);
-               holder = gda_set_get_holder (params, col->column_name);
+               holder = gda_set_get_holder (params, col->column_name);;
                if (!holder)
                        continue;
 
-               autoinc = gda_meta_table_column_get_attribute (col, GDA_ATTRIBUTE_AUTO_INCREMENT);
                if (tinfo->priv->insert_columns_hash)
                        g_hash_table_insert (tinfo->priv->insert_columns_hash, GINT_TO_POINTER (nthcol), 
g_object_ref (holder));
                
-               if (!plugin && !col->default_value && !autoinc)
+               if (!plugin && !col->default_value && !col->auto_incement)
                        continue;
                if (plugin) {
                        g_object_set ((GObject*) holder, "plugin", plugin, NULL);
@@ -805,7 +803,7 @@ action_insert_cb (G_GNUC_UNUSED GSimpleAction *action, G_GNUC_UNUSED GVariant *s
                        g_object_set (holder, "description", tmp, NULL);
                        g_free (tmp);
                }
-               else if (autoinc) {
+               else if (col->auto_incement) {
                        GValue *dv;
                        g_value_set_string ((dv = gda_value_new (G_TYPE_STRING)), "");
                        gda_holder_set_default_value (holder, dv);
diff --git a/tools/common/t-app.c b/tools/common/t-app.c
index 3597a5633..6bcf70477 100644
--- a/tools/common/t-app.c
+++ b/tools/common/t-app.c
@@ -1692,21 +1692,6 @@ gda_internal_command_build_meta_struct (GdaConnection *cnc, const gchar **argv,
        return NULL;
 }
 
-static void
-meta_table_column_foreach_attribute_func (const gchar *att_name, const GValue *value, GString **string)
-{
-       if (!strcmp (att_name, GDA_ATTRIBUTE_AUTO_INCREMENT) && 
-           (G_VALUE_TYPE (value) == G_TYPE_BOOLEAN) && 
-           g_value_get_boolean (value)) {
-               if (*string) {
-                       g_string_append (*string, ", ");
-                       g_string_append (*string, _("Auto increment"));
-               }
-               else
-                       *string = g_string_new (_("Auto increment"));
-       }
-}
-
 ToolCommandResult *
 gda_internal_command_detail (ToolCommand *command, guint argc, const gchar **argv,
                             TContext *console, GError **error)
@@ -1865,7 +1850,6 @@ gda_internal_command_detail (ToolCommand *command, guint argc, const gchar **arg
                                GdaMetaTableColumn *tcol = GDA_META_TABLE_COLUMN (list->data);
                                GList *values = NULL;
                                GValue *val;
-                               GString *string = NULL;
 
                                g_value_set_string ((val = gda_value_new (G_TYPE_STRING)), tcol->column_name);
                                values = g_list_append (values, val);
@@ -1876,14 +1860,11 @@ gda_internal_command_detail (ToolCommand *command, guint argc, const gchar **arg
                                g_value_set_string ((val = gda_value_new (G_TYPE_STRING)), 
tcol->default_value);
                                values = g_list_append (values, val);
 
-                               gda_meta_table_column_foreach_attribute (tcol, 
-                                                                        (GdaAttributesManagerFunc) 
meta_table_column_foreach_attribute_func, &string);
-                               if (string) {
-                                       g_value_take_string ((val = gda_value_new (G_TYPE_STRING)), 
string->str);
-                                       g_string_free (string, FALSE);
-                               }
-                               else
+                               if (tcol->auto_incement) {
+                                       g_value_set_string ((val = gda_value_new (G_TYPE_STRING)), _("Auto 
increment"));
+                               } else  {
                                        val = gda_value_new_null ();
+                               }
                                values = g_list_append (values, val);
 
                                gda_data_model_append_values (model, values, NULL);
diff --git a/tools/common/web-server.c b/tools/common/web-server.c
index 7bd2e889e..044f1148b 100644
--- a/tools/common/web-server.c
+++ b/tools/common/web-server.c
@@ -826,21 +826,6 @@ get_for_cnc (WebServer *webserver, SoupMessage *msg, TConnection *tcnc, gchar **
        return retval;
 }
 
-static void
-meta_table_column_foreach_attribute_func (const gchar *att_name, const GValue *value, GString **string)
-{
-       if (!strcmp (att_name, GDA_ATTRIBUTE_AUTO_INCREMENT) && 
-           (G_VALUE_TYPE (value) == G_TYPE_BOOLEAN) && 
-           g_value_get_boolean (value)) {
-               if (*string) {
-                       g_string_append (*string, ", ");
-                       g_string_append (*string, _("Auto increment"));
-               }
-               else
-                       *string = g_string_new (_("Auto increment"));
-       }
-}
-
 static gchar *meta_struct_dump_as_graph (TConnection *tcnc, GdaMetaStruct *mstruct,
                                         GdaMetaDbObject *central_dbo, GError **error);
 static gboolean
@@ -869,8 +854,7 @@ compute_table_details (TConnection *tcnc, HtmlDoc *hdoc, WebServer *webserver,
 
        for (list = mt->columns; list; list = list->next) {
                GdaMetaTableColumn *tcol = GDA_META_TABLE_COLUMN (list->data);
-               GString *string = NULL;
-               
+
                tr = xmlNewChild (table, NULL, BAD_CAST "tr", NULL);
                td = xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST tcol->column_name);
                if (tcol->pkey)
@@ -879,14 +863,11 @@ compute_table_details (TConnection *tcnc, HtmlDoc *hdoc, WebServer *webserver,
                td = xmlNewChild (tr, NULL, BAD_CAST "td", tcol->nullok ? BAD_CAST _("yes") : BAD_CAST 
_("no"));
                td = xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST tcol->default_value);
 
-               gda_meta_table_column_foreach_attribute (tcol, 
-                                   (GdaAttributesManagerFunc) meta_table_column_foreach_attribute_func, 
&string);
-               if (string) {
-                       td = xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST string->str);
-                       g_string_free (string, TRUE);
-               }
-               else
+               if (tcol->auto_incement) {
+                       td = xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST _("Auto increment"));
+               } else {
                        td = xmlNewChild (tr, NULL, BAD_CAST "td", NULL);
+               }
        }
 
        /* finished if we don't have a table */


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