[libgda] mysql: fixed DDL CREATE TABLE implementation
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] mysql: fixed DDL CREATE TABLE implementation
- Date: Mon, 14 Jan 2019 22:51:53 +0000 (UTC)
commit 04b44043bebc411c2be9bd2b1757c0a355257eea
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date: Fri Jan 11 18:20:58 2019 -0600
mysql: fixed DDL CREATE TABLE implementation
* Added error messages in MetaStore initialization
libgda/gda-meta-store.c | 38 ++++++++++++++++++++++++--------------
providers/mysql/gda-mysql-ddl.c | 6 +++---
tests/meta-store/common.c | 8 ++++----
3 files changed, 31 insertions(+), 21 deletions(-)
---
diff --git a/libgda/gda-meta-store.c b/libgda/gda-meta-store.c
index a7116a3dc..39a176dac 100644
--- a/libgda/gda-meta-store.c
+++ b/libgda/gda-meta-store.c
@@ -997,9 +997,10 @@ gda_meta_store_constructor (GType type,
store = (GdaMetaStore *) object;
GdaMetaStorePrivate *priv = gda_meta_store_get_instance_private (store);
- if (!priv->cnc && !been_specified)
+ if (!priv->cnc && !been_specified) {
/* in memory DB */
g_object_set (object, "cnc-string", "SQLite://DB_DIR=.;DB_NAME=__gda_tmp", NULL);
+ }
if (priv->cnc) {
gda_lockable_lock (GDA_LOCKABLE (priv->cnc));
@@ -1198,10 +1199,15 @@ gda_meta_store_set_property (GObject *object,
if (cnc) {
if (!gda_connection_open (cnc, &error)) {
g_object_unref (cnc);
+ g_warning (_("Could not open internal GdaMetaStore connection: %s"),
+ error && error->message ? error->message : _("No
detail"));
+ g_clear_error (&error);
cnc = NULL;
}
- }
- else {
+ } else {
+ g_warning (_("Could not create internal GdaMetaStore connection: %s"),
+ error && error->message ? error->message : _("No detail"));
+ g_clear_error (&error);
if (g_ascii_strcasecmp (cnc_string, "sqlite")) {
/* use _gda_config_sqlite_provider */
g_clear_error (&error);
@@ -1209,12 +1215,6 @@ gda_meta_store_set_property (GObject *object,
}
}
priv->cnc = cnc;
- if (!cnc) {
- g_warning ("Could not create internal GdaMetaStore connection:%s\n"
- "GdaMetaStore object will not work as expected",
- error && error->message ? error->message : _("No detail"));
- g_clear_error (&error);
- }
}
}
break;
@@ -1328,10 +1328,7 @@ initialize_cnc_struct (GdaMetaStore *store, GError **error)
if (schema_present)
return FALSE;
- if (error && *error) {
- g_error_free (*error);
- *error = NULL;
- }
+ g_clear_error (error);
/* assume schema not present => create it */
klass = (GdaMetaStoreClass *) G_OBJECT_GET_CLASS (store);
@@ -1344,9 +1341,22 @@ initialize_cnc_struct (GdaMetaStore *store, GError **error)
prov = gda_connection_get_provider (priv->cnc);
for (list = klass->cpriv->db_objects; list; list = list->next) {
DbObject *dbo = DB_OBJECT (list->data);
- /*g_print ("Creating object: %s\n", dbo->obj_name);*/
if (dbo->create_op) {
if (!gda_server_provider_perform_operation (prov, priv->cnc, dbo->create_op, error)) {
+ gchar *sql = NULL;
+ GError *lerror = NULL;
+ sql = gda_server_operation_render (dbo->create_op, &lerror);
+ if (sql == NULL) {
+ g_warning (_("Internal error while trying to render operation in
MetaStore creation: %s"),
+ lerror && lerror->message ? lerror->message : _("No error was
set"));
+ g_clear_error (&lerror);
+ } else {
+ g_warning ("Interna Error. Operation tried to create MetaStore table
'%s': %s",
+ dbo->obj_name, sql);
+ }
+ g_warning (_("Internal Error. Couldn't create MetaStore table '%s': %s"),
+ dbo->obj_name,
+ (*error) && (*error)->message ? (*error)->message : _("No error
was set"));
allok = FALSE;
break;
}
diff --git a/providers/mysql/gda-mysql-ddl.c b/providers/mysql/gda-mysql-ddl.c
index bcb502331..4ef85c5e6 100644
--- a/providers/mysql/gda-mysql-ddl.c
+++ b/providers/mysql/gda-mysql-ddl.c
@@ -384,8 +384,9 @@ gda_mysql_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
g_value_get_string (value) && *g_value_get_string (value)) {
g_string_append (string, " CHARACTER SET ");
g_string_append (string, g_value_get_string (value));
-
- if (gda_server_operation_get_value_at_path (op, "/TABLE_OPTIONS_P/TABLE_COLLATION")) {
+ value = gda_server_operation_get_value_at_path (op, "/TABLE_OPTIONS_P/TABLE_COLLATION");
+ if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) &&
+ g_value_get_string (value) && *g_value_get_string (value)) {
tmp = gda_connection_operation_get_sql_identifier_at (cnc, op,
"/TABLE_OPTIONS_P/TABLE_COLLATION",
error);
if (!tmp) {
@@ -501,7 +502,6 @@ gda_mysql_render_CREATE_TABLE (GdaServerProvider *provider, GdaConnection *cnc,
g_free (str);
}
}
-
sql = string->str;
g_string_free (string, FALSE);
diff --git a/tests/meta-store/common.c b/tests/meta-store/common.c
index 806a90b88..e8500857a 100644
--- a/tests/meta-store/common.c
+++ b/tests/meta-store/common.c
@@ -340,12 +340,12 @@ common_drop_all_tables (GdaMetaStore *store)
gint res;
GError *error = NULL;
- sql = g_strdup_printf ("DROP VIEW %s", view_names[i]);
+ sql = g_strdup_printf ("DROP VIEW IF EXISTS %s", view_names[i]);
stmt = gda_sql_parser_parse_string (parser, sql, NULL, NULL);
g_free (sql);
res = gda_connection_statement_execute_non_select (cnc, stmt, NULL, NULL, &error);
if (res == -1) {
- g_print ("DROP view '%s' error: %s\n", view_names[i],
+ g_print ("DROP VIEW IF EXISTS'%s' error: %s\n", view_names[i],
error && error->message ? error->message : "No detail");
if (error)
g_error_free (error);
@@ -359,12 +359,12 @@ common_drop_all_tables (GdaMetaStore *store)
gint res;
GError *error = NULL;
- sql = g_strdup_printf ("DROP TABLE %s", table_names[i]);
+ sql = g_strdup_printf ("DROP TABLE IF EXISTS %s", table_names[i]);
stmt = gda_sql_parser_parse_string (parser, sql, NULL, NULL);
g_free (sql);
res = gda_connection_statement_execute_non_select (cnc, stmt, NULL, NULL, &error);
if (res == -1) {
- g_print ("DROP table '%s' error: %s\n", table_names[i],
+ g_print ("DROP TABLE IF EXISTS '%s' error: %s\n", table_names[i],
error && error->message ? error->message : "No detail");
if (error)
g_error_free (error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]