]> saetta.ns0.it Git - libgdaex/commitdiff
Possible bug in libga gda_connection_get_meta_store_data_v.
authorAndrea Zagli <andrea.zagli@email.it>
Wed, 24 Jan 2018 17:04:47 +0000 (18:04 +0100)
committerAndrea Zagli <andrea.zagli@email.it>
Wed, 24 Jan 2018 17:04:47 +0000 (18:04 +0100)
src/gdaex.c
tests/metastore.c

index a7b369cf8c7ccf199c3ff5afcef349a8cc9954ed..2334b94b4f4259019a2860802a555f53b71c1ee4 100644 (file)
@@ -3861,15 +3861,30 @@ GdaDataModel
                        gda_meta_context_free (mcontext);
                }
 
-       gval = gda_value_new (G_TYPE_STRING);
-       g_value_take_string (gval, (gchar *)table_name);
+       /* possibile libgda bug: varchar length is always 0 */
+       /* gval = gda_value_new (G_TYPE_STRING); */
+       /* g_value_take_string (gval, (gchar *)table_name); */
 
        error = NULL;
-       dm = gda_connection_get_meta_store_data (priv->gda_conn,
-                                                GDA_CONNECTION_META_FIELDS,
-                                                &error,
-                                                1,
-                                                "name", gval);
+       /* dm = gda_connection_get_meta_store_data (priv->gda_conn, */
+       /*                                          GDA_CONNECTION_META_FIELDS, */
+       /*                                          &error, */
+       /*                                          1, */
+       /*                                          "name", gval); */
+
+       GdaMetaStore *mstore;
+       mstore = gda_connection_get_meta_store ((GdaConnection *)gdaex_get_gdaconnection (gdaex));
+       dm = gda_meta_store_extract_v (mstore,
+                                      g_strdup_printf ("SELECT c.column_name, c.data_type, c.gtype,"
+                                                       " CASE WHEN c.character_maximum_length > 0 THEN c.character_maximum_length ELSE c.numeric_precision END AS numeric_precision,"
+                                                       " c.numeric_scale, c.is_nullable AS Nullable,"
+                                                       " c.column_default, c.extra"
+                                                       " FROM _columns as c NATURAL JOIN _tables as t"
+                                                       " WHERE t.table_short_name='%s'"
+                                                       " ORDER BY c.ordinal_position",
+                                                       table_name),
+                                      NULL,
+                                      &error);
 
        if (dm == NULL
            || error != NULL)
@@ -3878,7 +3893,7 @@ GdaDataModel
                                   error != NULL && error->message != NULL ? error->message : _("no detail."));
                }
 
-       gda_value_free (gval);
+       /* gda_value_free (gval); */
 
        return dm;
 }
index f3f89d8f1ee335af3c6fa180983baac4db73d1e5..57a16dad0fd32f7f26fcf81bf8148adcf9606720 100644 (file)
@@ -16,6 +16,8 @@
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
+#include <glib/gprintf.h>
+
 #include <libgdaex.h>
 
 int
@@ -57,10 +59,20 @@ main (int argc, char **argv)
                                                        for (rowf = 0; rowf < rowsf; rowf++)
                                                                {
                                                                        g_printf ("\t- %s (%s - %d)\n",
-                                                                                 gdaex_data_model_get_value_stringify_at (dmf, rowf, 0),
-                                                                                 gdaex_data_model_get_value_stringify_at (dmf, rowf, 1),
-                                                                                 gdaex_data_model_get_value_integer_at (dmf, rowf, 3));
+                                                                                 gdaex_data_model_get_field_value_stringify_at (dmf, rowf, "column_name"),
+                                                                                 gdaex_data_model_get_field_value_stringify_at (dmf, rowf, "data_type"),
+                                                                                 gdaex_data_model_get_field_value_integer_at (dmf, rowf, "numeric_precision"));
                                                                }
+
+                                                       gchar *dmstr;
+                                                       dmstr = gda_data_model_export_to_string (dmf,
+                                                                                                GDA_DATA_MODEL_IO_TEXT_TABLE,
+                                                                                                NULL, 0,
+                                                                                                NULL, 0,
+                                                                                                NULL);
+                                                       g_printf ("%s\n",dmstr);
+                                                       g_free (dmstr);
+
                                                        g_object_unref (dmf);
                                                }