[libgda/LIBGDA_4.2] Correction for bug #663357
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda/LIBGDA_4.2] Correction for bug #663357
- Date: Sun, 6 Nov 2011 17:52:04 +0000 (UTC)
commit 6660a4b1fbe8f409418ddb6cd0d31e7b76bc44b1
Author: Vivien Malerba <malerba gnome-db org>
Date: Sun Nov 6 18:21:16 2011 +0100
Correction for bug #663357
modifications made when treating bug #662922 were not propagated
to all the providers implementing their own expression rendering
method
libgda/gda-statement.c | 5 +-
libgda/sqlite/gda-sqlite-provider.c | 120 ++++++++++++++++++++------------
providers/mysql/gda-mysql-provider.c | 120 ++++++++++++++++++++------------
providers/oracle/gda-oracle-provider.c | 120 +++++++++++++++++++++-----------
4 files changed, 229 insertions(+), 136 deletions(-)
---
diff --git a/libgda/gda-statement.c b/libgda/gda-statement.c
index 6d109af..ce42cf3 100644
--- a/libgda/gda-statement.c
+++ b/libgda/gda-statement.c
@@ -1610,10 +1610,7 @@ default_render_expr (GdaSqlExpr *expr, GdaSqlRenderingContext *context, gboolean
str = g_strdup ("NULL");
}
- if (!str) {
- /* TO REMOVE */
- str = g_strdup ("[...]");
- }
+ if (!str) goto err;
if (expr->cast_as)
g_string_append_printf (string, "CAST (%s AS %s)", str, expr->cast_as);
diff --git a/libgda/sqlite/gda-sqlite-provider.c b/libgda/sqlite/gda-sqlite-provider.c
index 583df2c..0f74942 100644
--- a/libgda/sqlite/gda-sqlite-provider.c
+++ b/libgda/sqlite/gda-sqlite-provider.c
@@ -1927,6 +1927,9 @@ sqlite_render_operation (GdaSqlOperation *op, GdaSqlRenderingContext *context, G
return str;
}
+/*
+ * The difference with the default implementation is to render TRUE and FALSE as 0 and 1
+ */
static gchar *
sqlite_render_expr (GdaSqlExpr *expr, GdaSqlRenderingContext *context,
gboolean *is_default, gboolean *is_null,
@@ -1954,52 +1957,82 @@ sqlite_render_expr (GdaSqlExpr *expr, GdaSqlRenderingContext *context,
if (!str) goto err;
}
else if (expr->value) {
- if (expr->value_is_ident && (G_VALUE_TYPE (expr->value) == G_TYPE_STRING) &&
- g_value_get_string (expr->value)) {
- gchar **ids_array;
- gint i;
- GString *string = NULL;
- GdaConnectionOptions cncoptions = 0;
- if (context->cnc)
- g_object_get (G_OBJECT (context->cnc), "options", &cncoptions, NULL);
-
- ids_array = gda_sql_identifier_split (g_value_get_string (expr->value));
- if (!ids_array)
- str = g_value_dup_string (expr->value);
- else if (!(ids_array[0])) goto err;
- else {
- for (i = 0; ids_array[i]; i++) {
- gchar *tmp;
- if (!string)
- string = g_string_new ("");
+ if (G_VALUE_TYPE (expr->value) == G_TYPE_STRING) {
+ /* specific treatment for strings, see documentation about GdaSqlExpr's value attribute */
+ const gchar *vstr;
+ vstr = g_value_get_string (expr->value);
+ if (vstr) {
+ if (expr->value_is_ident) {
+ gchar **ids_array;
+ gint i;
+ GString *string = NULL;
+ GdaConnectionOptions cncoptions = 0;
+ if (context->cnc)
+ g_object_get (G_OBJECT (context->cnc), "options", &cncoptions, NULL);
+ ids_array = gda_sql_identifier_split (vstr);
+ if (!ids_array)
+ str = g_strdup (vstr);
+ else if (!(ids_array[0])) goto err;
+ else {
+ for (i = 0; ids_array[i]; i++) {
+ gchar *tmp;
+ if (!string)
+ string = g_string_new ("");
+ else
+ g_string_append_c (string, '.');
+ tmp = gda_sql_identifier_quote (ids_array[i], context->cnc,
+ context->provider, FALSE,
+ cncoptions & GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE);
+ g_string_append (string, tmp);
+ g_free (tmp);
+ }
+ g_strfreev (ids_array);
+ str = g_string_free (string, FALSE);
+ }
+ }
+ else {
+ /* we don't have an identifier */
+ if (!g_ascii_strcasecmp (vstr, "default")) {
+ if (is_default)
+ *is_default = TRUE;
+ str = g_strdup ("DEFAULT");
+ }
+ else if (!g_ascii_strcasecmp (vstr, "FALSE")) {
+ g_free (str);
+ str = g_strdup ("0");
+ }
+ else if (!g_ascii_strcasecmp (vstr, "TRUE")) {
+ g_free (str);
+ str = g_strdup ("1");
+ }
else
- g_string_append_c (string, '.');
- tmp = gda_sql_identifier_quote (ids_array[i], context->cnc,
- context->provider, FALSE,
- cncoptions & GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE);
- g_string_append (string, tmp);
- g_free (tmp);
+ str = g_strdup (vstr);
}
- g_strfreev (ids_array);
- str = g_string_free (string, FALSE);
}
- }
- else {
- str = gda_value_stringify (expr->value);
- if (!str) goto err;
- if (is_null && gda_value_is_null (expr->value))
- *is_null = TRUE;
- else if (is_default && (G_VALUE_TYPE (expr->value) == G_TYPE_STRING) &&
- !g_ascii_strcasecmp (g_value_get_string (expr->value), "default"))
- *is_default = TRUE;
- else if (!g_ascii_strcasecmp (str, "FALSE")) {
- g_free (str);
- str = g_strdup ("0");
+ else {
+ str = g_strdup ("NULL");
+ if (is_null)
+ *is_null = TRUE;
}
- else if (!g_ascii_strcasecmp (str, "TRUE")) {
- g_free (str);
- str = g_strdup ("1");
+ }
+ if (!str) {
+ /* use a GdaDataHandler to render the value as valid SQL */
+ GdaDataHandler *dh;
+ if (context->cnc) {
+ GdaServerProvider *prov;
+ prov = gda_connection_get_provider (context->cnc);
+ dh = gda_server_provider_get_data_handler_g_type (prov, context->cnc,
+ G_VALUE_TYPE (expr->value));
+ if (!dh) goto err;
}
+ else
+ dh = gda_data_handler_get_default (G_VALUE_TYPE (expr->value));
+
+ if (dh)
+ str = gda_data_handler_get_sql_from_value (dh, expr->value);
+ else
+ str = gda_value_stringify (expr->value);
+ if (!str) goto err;
}
}
else if (expr->func) {
@@ -2036,10 +2069,7 @@ sqlite_render_expr (GdaSqlExpr *expr, GdaSqlRenderingContext *context,
str = g_strdup ("NULL");
}
- if (!str) {
- /* TO REMOVE */
- str = g_strdup ("[...]");
- }
+ if (!str) goto err;
if (expr->cast_as)
g_string_append_printf (string, "CAST (%s AS %s)", str, expr->cast_as);
diff --git a/providers/mysql/gda-mysql-provider.c b/providers/mysql/gda-mysql-provider.c
index cd3b46a..f629b05 100644
--- a/providers/mysql/gda-mysql-provider.c
+++ b/providers/mysql/gda-mysql-provider.c
@@ -1584,6 +1584,9 @@ mysql_render_function (GdaSqlFunction *func, GdaSqlRenderingContext *context, GE
return NULL;
}
+/*
+ * The difference with the default implementation is to render TRUE and FALSE as 0 and 1
+ */
static gchar *
mysql_render_expr (GdaSqlExpr *expr, GdaSqlRenderingContext *context,
gboolean *is_default, gboolean *is_null,
@@ -1611,52 +1614,82 @@ mysql_render_expr (GdaSqlExpr *expr, GdaSqlRenderingContext *context,
if (!str) goto err;
}
else if (expr->value) {
- if (expr->value_is_ident && (G_VALUE_TYPE (expr->value) == G_TYPE_STRING) &&
- g_value_get_string (expr->value)) {
- gchar **ids_array;
- gint i;
- GString *string = NULL;
- GdaConnectionOptions cncoptions = 0;
- if (context->cnc)
- g_object_get (G_OBJECT (context->cnc), "options", &cncoptions, NULL);
-
- ids_array = gda_sql_identifier_split (g_value_get_string (expr->value));
- if (!ids_array)
- str = g_value_dup_string (expr->value);
- else if (!(ids_array[0])) goto err;
- else {
- for (i = 0; ids_array[i]; i++) {
- gchar *tmp;
- if (!string)
- string = g_string_new ("");
+ if (G_VALUE_TYPE (expr->value) == G_TYPE_STRING) {
+ /* specific treatment for strings, see documentation about GdaSqlExpr's value attribute */
+ const gchar *vstr;
+ vstr = g_value_get_string (expr->value);
+ if (vstr) {
+ if (expr->value_is_ident) {
+ gchar **ids_array;
+ gint i;
+ GString *string = NULL;
+ GdaConnectionOptions cncoptions = 0;
+ if (context->cnc)
+ g_object_get (G_OBJECT (context->cnc), "options", &cncoptions, NULL);
+ ids_array = gda_sql_identifier_split (vstr);
+ if (!ids_array)
+ str = g_strdup (vstr);
+ else if (!(ids_array[0])) goto err;
+ else {
+ for (i = 0; ids_array[i]; i++) {
+ gchar *tmp;
+ if (!string)
+ string = g_string_new ("");
+ else
+ g_string_append_c (string, '.');
+ tmp = gda_sql_identifier_quote (ids_array[i], context->cnc,
+ context->provider, FALSE,
+ cncoptions & GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE);
+ g_string_append (string, tmp);
+ g_free (tmp);
+ }
+ g_strfreev (ids_array);
+ str = g_string_free (string, FALSE);
+ }
+ }
+ else {
+ /* we don't have an identifier */
+ if (!g_ascii_strcasecmp (vstr, "default")) {
+ if (is_default)
+ *is_default = TRUE;
+ str = g_strdup ("DEFAULT");
+ }
+ else if (!g_ascii_strcasecmp (vstr, "FALSE")) {
+ g_free (str);
+ str = g_strdup ("0");
+ }
+ else if (!g_ascii_strcasecmp (vstr, "TRUE")) {
+ g_free (str);
+ str = g_strdup ("1");
+ }
else
- g_string_append_c (string, '.');
- tmp = gda_sql_identifier_quote (ids_array[i], context->cnc,
- context->provider, FALSE,
- cncoptions & GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE);
- g_string_append (string, tmp);
- g_free (tmp);
+ str = g_strdup (vstr);
}
- g_strfreev (ids_array);
- str = g_string_free (string, FALSE);
}
- }
- else {
- str = gda_value_stringify (expr->value);
- if (!str) goto err;
- if (is_null && gda_value_is_null (expr->value))
- *is_null = TRUE;
- else if (is_default && (G_VALUE_TYPE (expr->value) == G_TYPE_STRING) &&
- !g_ascii_strcasecmp (g_value_get_string (expr->value), "default"))
- *is_default = TRUE;
- else if (!g_ascii_strcasecmp (str, "FALSE")) {
- g_free (str);
- str = g_strdup ("0");
+ else {
+ str = g_strdup ("NULL");
+ if (is_null)
+ *is_null = TRUE;
}
- else if (!g_ascii_strcasecmp (str, "TRUE")) {
- g_free (str);
- str = g_strdup ("1");
+ }
+ if (!str) {
+ /* use a GdaDataHandler to render the value as valid SQL */
+ GdaDataHandler *dh;
+ if (context->cnc) {
+ GdaServerProvider *prov;
+ prov = gda_connection_get_provider (context->cnc);
+ dh = gda_server_provider_get_data_handler_g_type (prov, context->cnc,
+ G_VALUE_TYPE (expr->value));
+ if (!dh) goto err;
}
+ else
+ dh = gda_data_handler_get_default (G_VALUE_TYPE (expr->value));
+
+ if (dh)
+ str = gda_data_handler_get_sql_from_value (dh, expr->value);
+ else
+ str = gda_value_stringify (expr->value);
+ if (!str) goto err;
}
}
else if (expr->func) {
@@ -1693,10 +1726,7 @@ mysql_render_expr (GdaSqlExpr *expr, GdaSqlRenderingContext *context,
str = g_strdup ("NULL");
}
- if (!str) {
- /* TO REMOVE */
- str = g_strdup ("[...]");
- }
+ if (!str) goto err;
if (expr->cast_as)
g_string_append_printf (string, "CAST (%s AS %s)", str, expr->cast_as);
diff --git a/providers/oracle/gda-oracle-provider.c b/providers/oracle/gda-oracle-provider.c
index a800570..225c6e3 100644
--- a/providers/oracle/gda-oracle-provider.c
+++ b/providers/oracle/gda-oracle-provider.c
@@ -1289,7 +1289,7 @@ gda_oracle_provider_statement_to_sql (GdaServerProvider *provider, GdaConnection
context.flags = flags;
context.render_select = (GdaSqlRenderingFunc) oracle_render_select;
context.render_select_target = (GdaSqlRenderingFunc) oracle_render_select_target;
- context.render_expr = oracle_render_expr; /* render "FALSE" as 0 and TRUE as !0 */
+ context.render_expr = oracle_render_expr; /* render "FALSE" as 0 and TRUE as 1 */
str = gda_statement_to_sql_real (stmt, &context, error);
@@ -1466,6 +1466,9 @@ oracle_render_select (GdaSqlStatementSelect *stmt, GdaSqlRenderingContext *conte
return NULL;
}
+/*
+ * The difference with the default implementation is to render TRUE and FALSE as 0 and 1
+ */
static gchar *
oracle_render_expr (GdaSqlExpr *expr, GdaSqlRenderingContext *context,
gboolean *is_default, gboolean *is_null,
@@ -1493,46 +1496,82 @@ oracle_render_expr (GdaSqlExpr *expr, GdaSqlRenderingContext *context,
if (!str) goto err;
}
else if (expr->value) {
- if (expr->value_is_ident && (G_VALUE_TYPE (expr->value) == G_TYPE_STRING)) {
- gchar **ids_array;
- gint i;
- GString *string = NULL;
- GdaConnectionOptions cncoptions = 0;
- if (context->cnc)
- g_object_get (G_OBJECT (context->cnc), "options", &cncoptions, NULL);
-
- ids_array = gda_sql_identifier_split (g_value_get_string (expr->value));
- if ((!ids_array) || !(ids_array[0])) goto err;
- for (i = 0; ids_array[i]; i++) {
- gchar *tmp;
- if (!string)
- string = g_string_new ("");
- else
- g_string_append_c (string, '.');
- tmp = gda_sql_identifier_quote (ids_array[i], context->cnc, context->provider, FALSE,
- cncoptions & GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE);
- g_string_append (string, tmp);
- g_free (tmp);
+ if (G_VALUE_TYPE (expr->value) == G_TYPE_STRING) {
+ /* specific treatment for strings, see documentation about GdaSqlExpr's value attribute */
+ const gchar *vstr;
+ vstr = g_value_get_string (expr->value);
+ if (vstr) {
+ if (expr->value_is_ident) {
+ gchar **ids_array;
+ gint i;
+ GString *string = NULL;
+ GdaConnectionOptions cncoptions = 0;
+ if (context->cnc)
+ g_object_get (G_OBJECT (context->cnc), "options", &cncoptions, NULL);
+ ids_array = gda_sql_identifier_split (vstr);
+ if (!ids_array)
+ str = g_strdup (vstr);
+ else if (!(ids_array[0])) goto err;
+ else {
+ for (i = 0; ids_array[i]; i++) {
+ gchar *tmp;
+ if (!string)
+ string = g_string_new ("");
+ else
+ g_string_append_c (string, '.');
+ tmp = gda_sql_identifier_quote (ids_array[i], context->cnc,
+ context->provider, FALSE,
+ cncoptions & GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE);
+ g_string_append (string, tmp);
+ g_free (tmp);
+ }
+ g_strfreev (ids_array);
+ str = g_string_free (string, FALSE);
+ }
+ }
+ else {
+ /* we don't have an identifier */
+ if (!g_ascii_strcasecmp (vstr, "default")) {
+ if (is_default)
+ *is_default = TRUE;
+ str = g_strdup ("DEFAULT");
+ }
+ else if (!g_ascii_strcasecmp (vstr, "FALSE")) {
+ g_free (str);
+ str = g_strdup ("0");
+ }
+ else if (!g_ascii_strcasecmp (vstr, "TRUE")) {
+ g_free (str);
+ str = g_strdup ("1");
+ }
+ else
+ str = g_strdup (vstr);
+ }
}
- g_strfreev (ids_array);
- str = g_string_free (string, FALSE);
- }
- else {
- str = gda_value_stringify (expr->value);
- if (!str) goto err;
- if (is_null && gda_value_is_null (expr->value))
- *is_null = TRUE;
- else if (is_default && (G_VALUE_TYPE (expr->value) == G_TYPE_STRING) &&
- !g_ascii_strcasecmp (g_value_get_string (expr->value), "default"))
- *is_default = TRUE;
- else if (!g_ascii_strcasecmp (str, "FALSE")) {
- g_free (str);
- str = g_strdup ("0");
+ else {
+ str = g_strdup ("NULL");
+ if (is_null)
+ *is_null = TRUE;
}
- else if (!g_ascii_strcasecmp (str, "TRUE")) {
- g_free (str);
- str = g_strdup ("1");
+ }
+ if (!str) {
+ /* use a GdaDataHandler to render the value as valid SQL */
+ GdaDataHandler *dh;
+ if (context->cnc) {
+ GdaServerProvider *prov;
+ prov = gda_connection_get_provider (context->cnc);
+ dh = gda_server_provider_get_data_handler_g_type (prov, context->cnc,
+ G_VALUE_TYPE (expr->value));
+ if (!dh) goto err;
}
+ else
+ dh = gda_data_handler_get_default (G_VALUE_TYPE (expr->value));
+
+ if (dh)
+ str = gda_data_handler_get_sql_from_value (dh, expr->value);
+ else
+ str = gda_value_stringify (expr->value);
+ if (!str) goto err;
}
}
else if (expr->func) {
@@ -1566,10 +1605,7 @@ oracle_render_expr (GdaSqlExpr *expr, GdaSqlRenderingContext *context,
str = g_strdup ("NULL");
}
- if (!str) {
- /* TO REMOVE */
- str = g_strdup ("[...]");
- }
+ if (!str) goto err;
if (expr->cast_as)
g_string_append_printf (string, "CAST (%s AS %s)", str, expr->cast_as);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]