[libgda] PostgreSQL: Added support for GdaText



commit 0a3e36d2a7843640246d8763de44b4ac4467203d
Author: Daniel Espinosa <esodan gmail com>
Date:   Fri May 24 15:26:39 2019 -0500

    PostgreSQL: Added support for GdaText
    
    GdaText now is used when 'text' type is returned by a query

 NEWS                                               |  7 ++
 providers/postgres/gda-postgres-recordset.c        |  5 ++
 .../reuseable/postgres/gda-postgres-reuseable.c    |  2 +
 tests/providers/TYPES_SCHEMA_PostgreSQL.xml        |  2 +-
 tests/providers/check_postgres.c                   |  1 +
 tests/providers/prov-test-common.c                 | 85 ++++++++++++++++++++--
 tests/providers/prov-test-common.h                 |  1 +
 7 files changed, 96 insertions(+), 7 deletions(-)
---
diff --git a/NEWS b/NEWS
index 84701217b..05dbb4a4e 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,10 @@
+libgda-6.0.0
+ - PostgreSQL now support GdaText values, so take care because some SELECT operations
+   concatenating strings return GdaText values instead of strings.
+ - Lot of memory leaks fixed
+
+================================================================================
+
 libgda 5.91.0
  - Added support for PostgreSQL version up to 11.0
  - Added new GdaText type for large texts types support
diff --git a/providers/postgres/gda-postgres-recordset.c b/providers/postgres/gda-postgres-recordset.c
index 632a89bcc..7b0c1a18d 100644
--- a/providers/postgres/gda-postgres-recordset.c
+++ b/providers/postgres/gda-postgres-recordset.c
@@ -585,6 +585,11 @@ set_value (GdaConnection *cnc, GdaRow *row, GValue *value, GType type, const gch
 
        if (type == G_TYPE_BOOLEAN)
                g_value_set_boolean (value, (*thevalue == 't') ? TRUE : FALSE);
+       else if (type == GDA_TYPE_TEXT) {
+    GdaText *txt = gda_text_new ();
+    gda_text_set_string (txt, thevalue);
+    g_value_take_boxed (value, txt);
+  }
        else if (type == G_TYPE_STRING) 
                g_value_set_string (value, thevalue);
        else if (type == G_TYPE_INT)
diff --git a/providers/reuseable/postgres/gda-postgres-reuseable.c 
b/providers/reuseable/postgres/gda-postgres-reuseable.c
index 6dadb9e58..a6bd70a13 100644
--- a/providers/reuseable/postgres/gda-postgres-reuseable.c
+++ b/providers/reuseable/postgres/gda-postgres-reuseable.c
@@ -263,6 +263,8 @@ postgres_name_to_g_type (const gchar *name, const gchar *conv_func_name)
                return GDA_TYPE_BLOB;
        else if (!strcmp (name, "bytea"))
                return GDA_TYPE_BINARY;
+       else if (!strcmp (name, "text"))
+    return GDA_TYPE_TEXT;
 
        /* other data types, using the conversion function name as a hint */
        if (!conv_func_name)
diff --git a/tests/providers/TYPES_SCHEMA_PostgreSQL.xml b/tests/providers/TYPES_SCHEMA_PostgreSQL.xml
index d07d45f25..a84fa5d63 100644
--- a/tests/providers/TYPES_SCHEMA_PostgreSQL.xml
+++ b/tests/providers/TYPES_SCHEMA_PostgreSQL.xml
@@ -241,7 +241,7 @@
     </gda_array_row>
     <gda_array_row>
       <gda_value>text</gda_value>
-      <gda_value>gchararray</gda_value>
+      <gda_value>GdaText</gda_value>
       <gda_value>variable-length string, no limit specified</gda_value>
       <gda_value isnull="t"/>
     </gda_array_row>
diff --git a/tests/providers/check_postgres.c b/tests/providers/check_postgres.c
index e666010d0..53fef8d48 100644
--- a/tests/providers/check_postgres.c
+++ b/tests/providers/check_postgres.c
@@ -77,6 +77,7 @@ main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv)
                number_failed += prov_test_common_load_data ();
                number_failed += prov_test_common_check_cursor_models ();
                number_failed += prov_test_common_check_data_select ();
+    number_failed += prov_test_common_values ();
                number_failed += prov_test_common_clean ();
        }
 
diff --git a/tests/providers/prov-test-common.c b/tests/providers/prov-test-common.c
index 1273747fa..0dc13e480 100644
--- a/tests/providers/prov-test-common.c
+++ b/tests/providers/prov-test-common.c
@@ -1078,13 +1078,14 @@ prov_test_common_check_timestamp (void)
                number_failed ++;
                goto out;
        }
-       cvalue = gda_data_model_get_typed_value_at (model, 0, 0, G_TYPE_STRING, FALSE, &error);
+       cvalue = gda_data_model_get_typed_value_at (model, 0, 0, GDA_TYPE_TEXT, FALSE, &error);
        if (!cvalue) {
                g_free (str);
                number_failed ++;
                goto out;
-       }       
-       if (strncmp (str, g_value_get_string (cvalue), 10)) { /* only compare date parts */
+       }
+  GdaText *text = g_value_get_boxed (cvalue);
+       if (strncmp (str, gda_text_get_string (text), 10)) { /* only compare date parts */
                g_set_error (&error, TEST_ERROR, TEST_ERROR_GENERIC,
                             "Returned GdaDataHandler returned wrong result: '%s' and expected '%s'", str, 
g_value_get_string (cvalue));
                g_free (str);
@@ -1238,13 +1239,14 @@ prov_test_common_check_date (void)
                number_failed ++;
                goto out;
        }
-       cvalue = gda_data_model_get_typed_value_at (model, 0, 0, G_TYPE_STRING, FALSE, &error);
+       cvalue = gda_data_model_get_typed_value_at (model, 0, 0, GDA_TYPE_TEXT, FALSE, &error);
        if (!cvalue) {
                g_free (str);
                number_failed ++;
                goto out;
-       }       
-       if (strncmp (str, g_value_get_string (cvalue), 10)) { /* only compare date parts */
+       }
+  GdaText *text = g_value_get_boxed (cvalue);
+       if (strncmp (str, gda_text_get_string (text), 10)) { /* only compare date parts */
                g_set_error (&error, TEST_ERROR, TEST_ERROR_GENERIC,
                             "Returned GdaDataHandler returned wrong result: '%s' and expected '%s'", str, 
g_value_get_string (cvalue));
                g_free (str);
@@ -1364,3 +1366,74 @@ out:
 
        return number_failed;
 }
+
+/*
+ *
+ * Test Value type conversion support
+ *
+ */
+int
+prov_test_common_values (void)
+{
+       GError *error = NULL;
+       int number_failed = 0;
+
+#ifdef CHECK_EXTRA_INFO
+       g_print ("\n============= %s() =============\n", __FUNCTION__);
+#endif
+
+       gchar* sql = "CREATE TABLE IF NOT EXISTS test_values (name TEXT)";
+  gda_connection_execute_non_select_command (cnc, sql, &error);
+  if (error != NULL) {
+    g_warning ("Error: %s",
+                error && error->message ? error->message : "No detail");
+    return 1;
+  }
+  sql = "INSERT INTO test_values (name) VALUES ('test text')";
+  gda_connection_execute_non_select_command (cnc, sql, &error);
+  if (error != NULL) {
+    g_warning ("Error: %s",
+                error && error->message ? error->message : "No detail");
+    return 1;
+  }
+  sql = "SELECT name FROM test_values";
+  GdaDataModel *res = gda_connection_execute_select_command (cnc, sql, &error);
+  if (error != NULL) {
+    g_warning ("Error: %s",
+                error && error->message ? error->message : "No detail");
+    return 1;
+  }
+  g_assert (res != NULL);
+  g_assert (gda_data_model_get_n_rows (res) >= 0);
+  const GValue *valo = gda_data_model_get_value_at (res, 0, 0, &error);
+  if (error != NULL) {
+    g_warning ("Error: %s",
+                error && error->message ? error->message : "No detail");
+    number_failed++;
+  }
+  GdaColumn *col = gda_data_model_describe_column (res, 0);
+  g_assert (gda_column_get_g_type (col) == GDA_TYPE_TEXT);
+  g_message ("Column of Type GdaText: as %s", g_type_name (G_VALUE_TYPE (valo)));
+  g_assert (G_VALUE_TYPE (valo) == GDA_TYPE_TEXT);
+  const GValue *val = gda_data_model_get_typed_value_at (res, 0, 0, GDA_TYPE_TEXT, TRUE, &error);
+  if (error != NULL) {
+    g_warning ("Error: %s",
+                error && error->message ? error->message : "No detail");
+    number_failed++;
+  } else {
+    GValue *dst = gda_value_new (G_TYPE_STRING);
+    g_assert (g_value_type_transformable (G_VALUE_TYPE (val), G_VALUE_TYPE (dst)));
+    g_assert (g_value_transform (val, dst));
+  }
+
+  sql = "DROP TABLE IF EXISTS  test_values";
+  gda_connection_execute_non_select_command (cnc, sql, &error);
+  if (error != NULL) {
+    g_warning ("Error: %s",
+                error && error->message ? error->message : "No detail");
+    return 1;
+  }
+  g_message ("Dropped Table 'test_values'");
+
+       return number_failed;
+}
diff --git a/tests/providers/prov-test-common.h b/tests/providers/prov-test-common.h
index 521d09e9f..94867964f 100644
--- a/tests/providers/prov-test-common.h
+++ b/tests/providers/prov-test-common.h
@@ -38,5 +38,6 @@ int prov_test_common_check_timestamp (void);
 int prov_test_common_check_date (void);
 int prov_test_common_clean (void);
 int prov_test_common_check_bigint (void);
+int prov_test_common_values (void);
 
 #endif


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