[libgda/LIBGDA_4.0] Honor the new SQL identifiers case sensitiveness flag in connections
- From: Vivien Malerba <vivien src gnome org>
- To: svn-commits-list gnome org
- Subject: [libgda/LIBGDA_4.0] Honor the new SQL identifiers case sensitiveness flag in connections
- Date: Thu, 23 Jul 2009 19:37:20 +0000 (UTC)
commit 2e9ff8bb001f31aad83b66e4c82da760985de497
Author: Vivien Malerba <malerba gnome-db org>
Date: Thu Jul 23 21:27:18 2009 +0200
Honor the new SQL identifiers case sensitiveness flag in connections
when rendering SQL from a GdaSqlStatement
libgda/gda-statement.c | 91 ++++++++++++++++--------
libgda/sql-parser/gda-statement-struct-parts.c | 16 +++-
libgda/sql-parser/gda-statement-struct-parts.h | 7 ++-
libgda/sqlite/gda-sqlite-provider.c | 58 ++++++++++++----
4 files changed, 123 insertions(+), 49 deletions(-)
---
diff --git a/libgda/gda-statement.c b/libgda/gda-statement.c
index 4d2d15f..751ed8d 100644
--- a/libgda/gda-statement.c
+++ b/libgda/gda-statement.c
@@ -1292,7 +1292,8 @@ default_render_param_spec (GdaSqlParamSpec *pspec, GdaSqlExpr *expr, GdaSqlRende
}
static gchar *
-default_render_expr (GdaSqlExpr *expr, GdaSqlRenderingContext *context, gboolean *is_default, gboolean *is_null, GError **error)
+default_render_expr (GdaSqlExpr *expr, GdaSqlRenderingContext *context, gboolean *is_default,
+ gboolean *is_null, GError **error)
{
GString *string;
gchar *str = NULL;
@@ -1316,13 +1317,45 @@ default_render_expr (GdaSqlExpr *expr, GdaSqlRenderingContext *context, gboolean
if (!str) goto err;
}
else if (expr->value) {
- 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;
+ 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 ("");
+ 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 {
+ 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 (expr->func) {
str = context->render_function (GDA_SQL_ANY_PART (expr->func), context, error);
@@ -1378,7 +1411,12 @@ default_render_field (GdaSqlField *field, GdaSqlRenderingContext *context, GErro
/* can't have: field->field_name not a valid SQL identifier */
if (!gda_sql_any_part_check_structure (GDA_SQL_ANY_PART (field), error)) return NULL;
- return g_strdup (field->field_name);
+ GdaConnectionOptions cncoptions = 0;
+ if (context->cnc)
+ g_object_get (G_OBJECT (context->cnc), "options", &cncoptions, NULL);
+ return gda_sql_identifier_quote (field->field_name, context->cnc, context->provider,
+ FALSE,
+ cncoptions & GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE);
}
static gchar *
@@ -1400,11 +1438,15 @@ default_render_table (GdaSqlTable *table, GdaSqlRenderingContext *context, GErro
gint i;
GString *string;
+ GdaConnectionOptions cncoptions = 0;
+ if (context->cnc)
+ g_object_get (G_OBJECT (context->cnc), "options", &cncoptions, NULL);
string = g_string_new ("");
for (i = 0; ids_array [i]; i++) {
gchar *tmp;
tmp = gda_sql_identifier_quote (ids_array [i], context->cnc, context->provider,
- FALSE, FALSE);
+ FALSE,
+ cncoptions & GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE);
g_free (ids_array [i]);
ids_array [i] = tmp;
if (i != 0)
@@ -1746,6 +1788,7 @@ default_render_select_target (GdaSqlSelectTarget *target, GdaSqlRenderingContext
{
GString *string;
gchar *str;
+ gpointer tmp;
g_return_val_if_fail (target, NULL);
g_return_val_if_fail (GDA_SQL_ANY_PART (target)->type == GDA_SQL_ANY_SQL_SELECT_TARGET, NULL);
@@ -1758,29 +1801,15 @@ default_render_select_target (GdaSqlSelectTarget *target, GdaSqlRenderingContext
if (!str)
return NULL;
string = g_string_new (str);
+ g_free (str);
}
else {
- gchar **ids_array;
- ids_array = gda_sql_identifier_split (g_value_get_string (target->expr->value));
- if (!ids_array) {
- g_set_error (error, GDA_SQL_ERROR, GDA_SQL_STRUCTURE_CONTENTS_ERROR,
- "%s", _("Malformed expression in select target"));
- return NULL;
- }
-
- gint i;
- string = g_string_new ("");
- for (i = 0; ids_array [i]; i++) {
- gchar *tmp;
- tmp = gda_sql_identifier_quote (ids_array [i], context->cnc, context->provider,
- FALSE, FALSE);
- g_free (ids_array [i]);
- ids_array [i] = tmp;
- if (i != 0)
- g_string_append_c (string, '.');
- g_string_append (string, ids_array [i]);
- }
- g_strfreev (ids_array);
+ tmp = target->expr->value_is_ident;
+ target->expr->value_is_ident = (gpointer) 0x1;
+ str = context->render_expr (target->expr, context, NULL, NULL, error);
+ target->expr->value_is_ident = tmp;
+ string = g_string_new (str);
+ g_free (str);
}
if (target->as)
diff --git a/libgda/sql-parser/gda-statement-struct-parts.c b/libgda/sql-parser/gda-statement-struct-parts.c
index 753b121..60e8b5a 100644
--- a/libgda/sql-parser/gda-statement-struct-parts.c
+++ b/libgda/sql-parser/gda-statement-struct-parts.c
@@ -81,7 +81,7 @@ gda_sql_expr_free (GdaSqlExpr *expr)
}
gda_sql_case_free (expr->case_s);
g_free (expr->cast_as);
-
+ expr->value_is_ident = (gpointer) 0x1;
g_free (expr);
}
@@ -131,6 +131,8 @@ gda_sql_expr_copy (GdaSqlExpr *expr)
if (expr->cast_as)
copy->cast_as = g_strdup (expr->cast_as);
+
+ copy->value_is_ident = expr->value_is_ident;
return copy;
}
@@ -201,6 +203,12 @@ gda_sql_expr_serialize (GdaSqlExpr *expr)
g_free (str);
}
+ if (expr->value_is_ident) {
+ str = _json_quote_string (expr->cast_as);
+ g_string_append (string, ",\"sqlident\":\"TRUE\"");
+ g_free (str);
+ }
+
g_string_append_c (string, '}');
str = string->str;
g_string_free (string, FALSE);
@@ -416,7 +424,7 @@ gda_sql_table_take_name (GdaSqlTable *table, GValue *value)
/**
* gda_sql_function_new
- * @parent: a #GdaSqlExpr structure
+ * @parent: a #GdaSqlAnyPart structure
*
* Creates a new #GdaSqlFunction structure initated.
*
@@ -568,7 +576,7 @@ gda_sql_function_take_args_list (GdaSqlFunction *function, GSList *args)
/**
* gda_sql_operation_new
- * @parent: a #GdaSqlExpr structure
+ * @parent: a #GdaSqlAnyPart structure
*
* Creates a new #GdaSqlOperation structure and sets its parent to @parent.
*
@@ -834,7 +842,7 @@ gda_sql_operation_operator_from_string (const gchar *op)
/**
* gda_sql_case_new
- * @parent: a #GdaSqlExpr structure
+ * @parent: a #GdaSqlAnyPart structure
*
* Creates a new #GdaSqlCase structure and sets its parent to @parent.
*
diff --git a/libgda/sql-parser/gda-statement-struct-parts.h b/libgda/sql-parser/gda-statement-struct-parts.h
index 56d377d..c5d81d6 100644
--- a/libgda/sql-parser/gda-statement-struct-parts.h
+++ b/libgda/sql-parser/gda-statement-struct-parts.h
@@ -55,8 +55,13 @@ struct _GdaSqlExpr {
gchar *cast_as;
+ gpointer value_is_ident; /* pointer to a boolean to keep ABI from 4.0.
+ * Non NULL if @value represents an SQL identifier
+ * Mem in _NOT_ allocated!
+ */
+
+ /*< private >*/
/* Padding for future expansion */
- gpointer _gda_reserved1;
gpointer _gda_reserved2;
};
diff --git a/libgda/sqlite/gda-sqlite-provider.c b/libgda/sqlite/gda-sqlite-provider.c
index 4b23280..1d269a4 100644
--- a/libgda/sqlite/gda-sqlite-provider.c
+++ b/libgda/sqlite/gda-sqlite-provider.c
@@ -1496,20 +1496,52 @@ sqlite_render_expr (GdaSqlExpr *expr, GdaSqlRenderingContext *context,
if (!str) goto err;
}
else if (expr->value) {
- 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");
+ 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 ("");
+ 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 if (!g_ascii_strcasecmp (str, "TRUE")) {
- g_free (str);
- str = g_strdup ("1");
+ 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 if (!g_ascii_strcasecmp (str, "TRUE")) {
+ g_free (str);
+ str = g_strdup ("1");
+ }
}
}
else if (expr->func) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]