[libgda] SQLite: ddl uses default type for given type's name
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] SQLite: ddl uses default type for given type's name
- Date: Wed, 18 Mar 2020 18:06:53 +0000 (UTC)
commit f8d38f6caa2ac47b489a3d744d21cef673120370
Author: Daniel Espinosa <esodan gmail com>
Date: Wed Mar 18 11:15:50 2020 -0600
SQLite: ddl uses default type for given type's name
SQLite now supports to parse provided type's name for
column's types in server operations, to GType in order
to find the default DB's type; parse fails just fallback
to use the provided name.
SQLite default type for texts changed from "string" to
native SQLite's type "TEXT".
Tests for server operation now uses random test DB's names.
libgda/sqlite/gda-sqlite-ddl.c | 11 +++++++++--
libgda/sqlite/gda-sqlite-provider.c | 2 +-
tests/test-server-operation-sqlite.c | 37 +++++++++++++++++++++++++-----------
3 files changed, 36 insertions(+), 14 deletions(-)
---
diff --git a/libgda/sqlite/gda-sqlite-ddl.c b/libgda/sqlite/gda-sqlite-ddl.c
index 6f2bef20e..40dd3d76f 100644
--- a/libgda/sqlite/gda-sqlite-ddl.c
+++ b/libgda/sqlite/gda-sqlite-ddl.c
@@ -139,8 +139,15 @@ _gda_sqlite_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc
if (!pkautoinc) {
value1 = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_TYPE/%d",
i);
- g_string_append (string, g_value_get_string (value1));
-
+ GType gtype = g_type_from_name (g_value_get_string (value1));
+ if (gtype == G_TYPE_INVALID) {
+ g_string_append (string, g_value_get_string (value1));
+ } else {
+ g_string_append (string,
+ gda_server_provider_get_default_dbms_type (provider,
+ cnc, gtype));
+ }
+
value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_SIZE/%d",
i);
if (value && G_VALUE_HOLDS (value, G_TYPE_UINT)) {
g_string_append_printf (string, "(%d", g_value_get_uint (value));
diff --git a/libgda/sqlite/gda-sqlite-provider.c b/libgda/sqlite/gda-sqlite-provider.c
index 20f732a1f..0ec465272 100644
--- a/libgda/sqlite/gda-sqlite-provider.c
+++ b/libgda/sqlite/gda-sqlite-provider.c
@@ -2130,7 +2130,7 @@ gda_sqlite_provider_get_default_dbms_type (G_GNUC_UNUSED GdaServerProvider *prov
(type == G_TYPE_STRING) ||
(type == GDA_TYPE_TEXT) ||
(type == G_TYPE_INVALID))
- return "string";
+ return "text";
if ((type == G_TYPE_DOUBLE) ||
(type == GDA_TYPE_NUMERIC) ||
diff --git a/tests/test-server-operation-sqlite.c b/tests/test-server-operation-sqlite.c
index 60d89e795..90ee46197 100644
--- a/tests/test-server-operation-sqlite.c
+++ b/tests/test-server-operation-sqlite.c
@@ -41,7 +41,6 @@
#define PROVIDER_NAME "SQLite"
#define DB_TEST_BASE "sqlite_ddl_so_test"
-static int db_increment = 1;
typedef struct
{
@@ -56,7 +55,7 @@ test_server_operation_start (TestObjectFixture *fixture,
fixture->cnc = NULL;
fixture->provider = NULL;
- gchar *dbname = g_strdup_printf("DB_DIR=.;DB_NAME=%s_%d", DB_TEST_BASE, db_increment++);
+ gchar *dbname = g_strdup_printf("DB_DIR=.;DB_NAME=%s_%d", DB_TEST_BASE, g_random_int ());
fixture->cnc = gda_connection_open_from_string (PROVIDER_NAME,
dbname,
@@ -87,6 +86,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
G_GNUC_UNUSED gconstpointer user_data)
{
GdaServerOperation *op = NULL;
+ GError *error = NULL;
/* CREATE_TABLE operation */
op = gda_server_provider_create_operation (fixture->provider,
@@ -137,7 +137,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
res = gda_server_operation_set_value_at (op,
- "gint",
+ g_type_name (G_TYPE_INT),
NULL,
"/FIELDS_A/@COLUMN_TYPE/%d",
column_order);
@@ -187,7 +187,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
res = gda_server_operation_set_value_at (op,
- "gchararray",
+ "varchar",
NULL,
"/FIELDS_A/@COLUMN_TYPE/%d",
column_order);
@@ -244,7 +244,12 @@ test_server_operation_operations (TestObjectFixture *fixture,
res = gda_server_provider_perform_operation (fixture->provider,
fixture->cnc,
op,
- NULL);
+ &error);
+ if (error != NULL) {
+ g_print ("Error: %s",
+ error->message != NULL ? error->message : "No detail");
+ g_clear_error (&error);
+ }
g_assert_true (res);
@@ -296,7 +301,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
res = gda_server_operation_set_value_at (op,
- "gint",
+ g_type_name (G_TYPE_INT),
NULL,
"/FIELDS_A/@COLUMN_TYPE/%d",
column_order);
@@ -346,7 +351,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
res = gda_server_operation_set_value_at (op,
- "gchararray",
+ "varchar",
NULL,
"/FIELDS_A/@COLUMN_TYPE/%d",
column_order);
@@ -411,7 +416,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
res = gda_server_operation_set_value_at (op,
- "gint",
+ g_type_name (G_TYPE_INT),
NULL,
"/FIELDS_A/@COLUMN_TYPE/%d",
column_order);
@@ -493,7 +498,12 @@ test_server_operation_operations (TestObjectFixture *fixture,
res = gda_server_provider_perform_operation (fixture->provider,
fixture->cnc,
op,
- NULL);
+ &error);
+ if (error != NULL) {
+ g_print ("Error: %s",
+ error->message != NULL ? error->message : "No detail");
+ g_clear_error (&error);
+ }
g_assert_true (res);
/* END of CREATE_TABLE operation */
@@ -523,7 +533,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
res = gda_server_operation_set_value_at (op,
- "gfloat",
+ "decimal",
NULL,
"/COLUMN_DEF_P/COLUMN_TYPE");
@@ -553,7 +563,12 @@ test_server_operation_operations (TestObjectFixture *fixture,
res = gda_server_provider_perform_operation (fixture->provider,
fixture->cnc,
op,
- NULL);
+ &error);
+ if (error != NULL) {
+ g_print ("Error: %s",
+ error->message != NULL ? error->message : "No detail");
+ g_clear_error (&error);
+ }
g_assert_true (res);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]