[libgda/LIBGDA_4.0] MySQL corrections



commit fafa3feed44659ece9f369594b152dc939816430
Author: Vivien Malerba <malerba gnome-db org>
Date:   Wed Jan 13 11:56:21 2010 +0100

    MySQL corrections
    
    
    * correctly report failed connection open error
    * don't add a space between a function and the opening parenthesis
    * meta data fetching correction

 providers/mysql/gda-mysql-meta.c     |    8 ++++-
 providers/mysql/gda-mysql-provider.c |   49 +++++++++++++++++++++++++++++++++-
 tests/meta-store/common.c            |    4 ++-
 3 files changed, 57 insertions(+), 4 deletions(-)
---
diff --git a/providers/mysql/gda-mysql-meta.c b/providers/mysql/gda-mysql-meta.c
index e1368f9..9e99c68 100644
--- a/providers/mysql/gda-mysql-meta.c
+++ b/providers/mysql/gda-mysql-meta.c
@@ -47,6 +47,7 @@ typedef enum {
         I_STMT_TABLES,
         I_STMT_TABLES_ALL,
         I_STMT_TABLE_NAMED,
+	I_STMT_VIEWS,
         I_STMT_VIEWS_ALL,
         I_STMT_VIEW_NAMED,
         I_STMT_COLUMNS_OF_TABLE,
@@ -114,11 +115,14 @@ static gchar *internal_sql[] = {
         /* I_STMT_TABLE_NAMED */
 	"SELECT IFNULL(table_catalog, table_schema) AS table_catalog, table_schema, table_name, CASE WHEN table_type LIKE '%VIEW%' THEN 'VIEW' ELSE table_type END, CASE table_type WHEN 'BASE TABLE' THEN TRUE ELSE FALSE END AS table_type, table_comment, " SHORT_NAME("table_schema", "table_name", "CONCAT(table_schema, '.', table_name)") " as short_name, CONCAT(table_schema, '.', table_name) AS table_full_name, NULL AS table_owner FROM INFORMATION_SCHEMA.tables WHERE IFNULL(table_catalog, table_schema) = BINARY ##cat::string AND table_schema = BINARY ##schema::string AND table_name = BINARY ##name::string",
 
+	/* I_STMT_VIEWS */
+	"SELECT IFNULL(table_catalog, table_schema) AS table_catalog, table_schema, table_name, view_definition, check_option, is_updatable FROM INFORMATION_SCHEMA.views WHERE table_schema = BINARY ##schema::string  UNION SELECT IFNULL(table_catalog, table_schema) AS table_catalog, table_schema, table_name, NULL, NULL, FALSE FROM INFORMATION_SCHEMA.tables WHERE table_schema='information_schema' AND table_type LIKE '%VIEW%' AND IFNULL(table_catalog, table_schema) = BINARY ##cat::string AND table_schema = BINARY ##schema::string",
+
         /* I_STMT_VIEWS_ALL */
 	"SELECT IFNULL(table_catalog, table_schema) AS table_catalog, table_schema, table_name, view_definition, check_option, is_updatable FROM INFORMATION_SCHEMA.views UNION SELECT IFNULL(table_catalog, table_schema) AS table_catalog, table_schema, table_name, NULL, NULL, FALSE FROM INFORMATION_SCHEMA.tables WHERE table_schema='information_schema' and table_type LIKE '%VIEW%'",
 
         /* I_STMT_VIEW_NAMED */
-	"SELECT IFNULL(table_catalog, table_schema) AS table_catalog, table_schema, table_name, view_definition, check_option, is_updatable FROM INFORMATION_SCHEMA.views WHERE table_catalog = BINARY ##cat::string AND table_schema = BINARY ##schema::string  UNION SELECT IFNULL(table_catalog, table_schema) AS table_catalog, table_schema, table_name, NULL, NULL, FALSE FROM INFORMATION_SCHEMA.tables WHERE table_schema='information_schema' AND table_type LIKE '%VIEW%' AND IFNULL(table_catalog, table_schema) = BINARY ##cat::string AND table_schema = BINARY ##schema::string",
+	"SELECT IFNULL(table_catalog, table_schema) AS table_catalog, table_schema, table_name, view_definition, check_option, is_updatable FROM INFORMATION_SCHEMA.views WHERE table_catalog = BINARY ##cat::string AND table_schema = BINARY ##schema::string AND table_name = BINARY ##name::string UNION SELECT IFNULL(table_catalog, table_schema) AS table_catalog, table_schema, table_name, NULL, NULL, FALSE FROM INFORMATION_SCHEMA.tables WHERE table_schema='information_schema' AND table_type LIKE '%VIEW%' AND IFNULL(table_catalog, table_schema) = BINARY ##cat::string AND table_schema = BINARY ##schema::string AND table_name = BINARY ##name::string",
 
         /* I_STMT_COLUMNS_OF_TABLE */
 	"SELECT IFNULL(table_catalog, table_schema) AS table_catalog, table_schema, table_name, column_name, ordinal_position, column_default, is_nullable, data_type, NULL, 'gchararray', character_maximum_length,character_octet_length, numeric_precision, numeric_scale, 0, character_set_name, character_set_name, character_set_name, collation_name, collation_name, collation_name, CASE WHEN extra = 'auto_increment' then '" GDA_EXTRA_AUTO_INCREMENT "' ELSE extra END, 1, column_comment FROM INFORMATION_SCHEMA.columns WHERE IFNULL(table_catalog, table_schema) = BINARY ##cat::string AND table_schema = BINARY ##schema::string AND table_name = BINARY ##name::string",
@@ -811,7 +815,7 @@ _gda_mysql_meta_tables_views (GdaServerProvider  *prov,
 		if (!retval)
 			return FALSE;
 
-		model_views = gda_connection_statement_execute_select_full (cnc, internal_stmt[I_STMT_VIEWS_ALL], i_set, 
+		model_views = gda_connection_statement_execute_select_full (cnc, internal_stmt[I_STMT_VIEWS], i_set, 
 									    GDA_STATEMENT_MODEL_RANDOM_ACCESS, col_types_views,
 									    error);
 		if (model_views == NULL)
diff --git a/providers/mysql/gda-mysql-provider.c b/providers/mysql/gda-mysql-provider.c
index 8bdd79e..c4f262e 100644
--- a/providers/mysql/gda-mysql-provider.c
+++ b/providers/mysql/gda-mysql-provider.c
@@ -630,7 +630,16 @@ gda_mysql_provider_open_connection (GdaServerProvider               *provider,
 					     (compress && ((*compress == 't') || (*compress == 'T'))) ? TRUE : FALSE,
 					     &error);
 	if (!mysql) {
-		_gda_mysql_make_error (cnc, mysql, NULL, NULL);
+		GdaConnectionEvent *event_error = gda_connection_event_new (GDA_CONNECTION_EVENT_ERROR);
+		gda_connection_event_set_sqlstate (event_error, _("Unknown"));
+		gda_connection_event_set_description (event_error,
+						      error && error->message ? error->message :
+						      _("No description"));
+		gda_connection_event_set_code (event_error, GDA_CONNECTION_EVENT_CODE_UNKNOWN);
+		gda_connection_event_set_source (event_error, "gda-mysql");
+		gda_connection_add_event (cnc, event_error);
+		g_clear_error (&error);
+
 		return FALSE;
 	}
 
@@ -1369,6 +1378,7 @@ gda_mysql_provider_create_parser (GdaServerProvider  *provider,
  * 
  * This method renders a #GdaStatement into its SQL representation.
  */
+static gchar *mysql_render_function (GdaSqlFunction *func, GdaSqlRenderingContext *context, GError **error);
 static gchar *
 gda_mysql_provider_statement_to_sql (GdaServerProvider    *provider,
 				     GdaConnection        *cnc,
@@ -1390,6 +1400,9 @@ gda_mysql_provider_statement_to_sql (GdaServerProvider    *provider,
         memset (&context, 0, sizeof (context));
         context.params = params;
         context.flags = flags;
+	context.render_function = (GdaSqlRenderingFunc) mysql_render_function; /* don't put any space between function name
+										* and the opening parenthesis, see
+										* http://blog.152.org/2009/12/mysql-error-1305-function-xxx-does-not.html */
 	if (cnc) {
 		context.cnc = cnc;
 		context.provider = gda_connection_get_provider (cnc);
@@ -1411,6 +1424,40 @@ gda_mysql_provider_statement_to_sql (GdaServerProvider    *provider,
         return str;
 }
 
+static gchar *
+mysql_render_function (GdaSqlFunction *func, GdaSqlRenderingContext *context, GError **error)
+{
+	GString *string;
+	gchar *str;
+	GSList *list;
+
+	g_return_val_if_fail (func, NULL);
+	g_return_val_if_fail (GDA_SQL_ANY_PART (func)->type == GDA_SQL_ANY_SQL_FUNCTION, NULL);
+
+	/* can't have: func->function_name == NULL */
+	if (!gda_sql_any_part_check_structure (GDA_SQL_ANY_PART (func), error)) return NULL;
+
+	string = g_string_new (func->function_name);
+	g_string_append_c (string, '(');
+	for (list = func->args_list; list; list = list->next) {
+		if (list != func->args_list)
+			g_string_append (string, ", ");
+		str = context->render_expr (list->data, context, NULL, NULL, error);
+		if (!str) goto err;
+		g_string_append (string, str);
+		g_free (str);
+	}
+	g_string_append_c (string, ')');
+
+	str = string->str;
+	g_string_free (string, FALSE);
+	return str;
+
+ err:
+	g_string_free (string, TRUE);
+	return NULL;
+}
+
 static GdaMysqlPStmt *
 real_prepare (GdaServerProvider *provider, GdaConnection *cnc, GdaStatement *stmt, GError **error)
 {
diff --git a/tests/meta-store/common.c b/tests/meta-store/common.c
index 012355d..ac10ae5 100644
--- a/tests/meta-store/common.c
+++ b/tests/meta-store/common.c
@@ -303,7 +303,9 @@ common_drop_all_tables (GdaMetaStore *store)
 		"_view_column_usage",
 		"_domain_constraints",
 		"_parameters",
-		"_routine_columns"
+		"_routine_columns",
+		"_table_indexes",
+		"_index_column_usage"
 	};
 	gchar *view_names [] = {
 		"_all_types",



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