[libgda] MySQL corrections
- From: Vivien Malerba <vivien src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgda] MySQL corrections
- Date: Wed, 13 Jan 2010 10:08:57 +0000 (UTC)
commit 95ed60cc74937e7926d3315e11915ee55fb6e44c
Author: Vivien Malerba <malerba gnome-db org>
Date: Wed Jan 13 10:11:28 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-provider.c | 51 ++++++++++++++++++++++++++-
providers/reuseable/mysql/gda-mysql-meta.c | 8 +++-
2 files changed, 55 insertions(+), 4 deletions(-)
---
diff --git a/providers/mysql/gda-mysql-provider.c b/providers/mysql/gda-mysql-provider.c
index ba02d13..c615e7b 100644
--- a/providers/mysql/gda-mysql-provider.c
+++ b/providers/mysql/gda-mysql-provider.c
@@ -503,7 +503,7 @@ real_open_connection (const gchar *host,
#if GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 18
g_set_error (error, 0, 0, "%s", mysql_error (mysql));
#else
- g_set_error_literal (error, 0, 0, mysql_error (mysql));
+ g_set_error_literal (error, GDA_SERVER_PROVIDER_ERROR, 0, mysql_error (mysql));
#endif
g_free (mysql);
mysql = NULL;
@@ -613,7 +613,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;
}
@@ -1361,6 +1370,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,
@@ -1382,6 +1392,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);
@@ -1403,6 +1416,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/providers/reuseable/mysql/gda-mysql-meta.c b/providers/reuseable/mysql/gda-mysql-meta.c
index be940dc..a1e98ab 100644
--- a/providers/reuseable/mysql/gda-mysql-meta.c
+++ b/providers/reuseable/mysql/gda-mysql-meta.c
@@ -48,6 +48,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,
@@ -115,11 +116,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",
@@ -855,7 +859,7 @@ _gda_mysql_meta_tables_views (GdaServerProvider *prov,
return FALSE;
model_views = gda_connection_statement_execute_select_full (cnc,
- internal_stmt[I_STMT_VIEWS_ALL],
+ internal_stmt[I_STMT_VIEWS],
i_set,
GDA_STATEMENT_MODEL_RANDOM_ACCESS,
_col_types_views,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]