[libgda/gtk3] Removed deprecated parts: gda_sql_identifier_*()



commit 6303a05d3ec88e10b8c3c9a12b276f3fd5d72724
Author: Vivien Malerba <malerba gnome-db org>
Date:   Mon Feb 28 18:30:08 2011 +0100

    Removed deprecated parts: gda_sql_identifier_*()

 doc/C/libgda-sections.txt                     |    6 +-
 libgda/gda-data-meta-wrapper.c                |    8 +-
 libgda/gda-data-select.c                      |    2 +-
 libgda/gda-meta-store.c                       |    4 +-
 libgda/gda-statement.c                        |    6 +-
 libgda/gda-util.c                             |   10 ++--
 libgda/libgda.symbols                         |    5 +-
 libgda/sql-parser/gda-statement-struct-util.c |   80 +++++--------------------
 libgda/sql-parser/gda-statement-struct-util.h |   14 ++--
 libgda/sqlite/gda-sqlite-provider.c           |    4 +-
 libgda/sqlite/gda-sqlite-util.c               |    6 +-
 providers/mysql/gda-mysql-provider.c          |   12 ++--
 providers/oracle/gda-oracle-meta.c            |    4 +-
 providers/oracle/gda-oracle-provider.c        |    8 +-
 providers/postgres/gda-postgres-provider.c    |    8 +-
 tests/test-sql-identifier.c                   |   36 +++++++++++-
 tools/command-exec.c                          |    2 +-
 17 files changed, 100 insertions(+), 115 deletions(-)
---
diff --git a/doc/C/libgda-sections.txt b/doc/C/libgda-sections.txt
index 43286e4..a980816 100644
--- a/doc/C/libgda-sections.txt
+++ b/doc/C/libgda-sections.txt
@@ -1127,9 +1127,6 @@ gda_sql_parser_parse_string_as_batch
 gda_sql_parser_parse_file_as_batch
 <SUBSECTION>
 gda_sql_identifier_quote
-gda_sql_identifier_needs_quotes
-gda_sql_identifier_add_quotes
-gda_sql_identifier_remove_quotes
 gda_sql_identifier_split
 <SUBSECTION Standard>
 GDA_IS_SQL_PARSER
@@ -1498,6 +1495,9 @@ gda_compute_unique_table_row_condition_with_cnc
 gda_sql_any_part_check_structure
 <SUBSECTION>
 gda_statement_rewrite_for_default_values
+<SUBSECTION>
+gda_sql_identifier_force_quotes
+gda_sql_identifier_prepare_for_compare
 </SECTION>
 
 <SECTION>
diff --git a/libgda/gda-data-meta-wrapper.c b/libgda/gda-data-meta-wrapper.c
index 02b9894..aba4810 100644
--- a/libgda/gda-data-meta-wrapper.c
+++ b/libgda/gda-data-meta-wrapper.c
@@ -494,7 +494,7 @@ _gda_data_meta_wrapper_compute_value (const GValue *value, GdaSqlIdentifierStyle
 		gboolean onechanged = FALSE;
 		for (i = 0; sa[i]; i++) {
 			if (identifier_needs_quotes (sa[i], mode)) {
-				gchar *tmp = gda_sql_identifier_add_quotes (sa[i]);
+				gchar *tmp = gda_sql_identifier_force_quotes (sa[i]);
 				g_free (sa[i]);
 				sa[i] = tmp;
 				onechanged = TRUE;
@@ -507,7 +507,7 @@ _gda_data_meta_wrapper_compute_value (const GValue *value, GdaSqlIdentifierStyle
 
 				if ((reserved_keyword_func && reserved_keyword_func (sa[i])) ||
 				    (! reserved_keyword_func && is_keyword (sa[i]))) {
-					gchar *tmp = gda_sql_identifier_add_quotes (sa[i]);
+					gchar *tmp = gda_sql_identifier_force_quotes (sa[i]);
 					g_free (sa[i]);
 					sa[i] = tmp;
 					onechanged = TRUE;
@@ -522,7 +522,7 @@ _gda_data_meta_wrapper_compute_value (const GValue *value, GdaSqlIdentifierStyle
 	else {
 		if (identifier_needs_quotes (str, mode)) {
 			retval = gda_value_new (G_TYPE_STRING);
-			g_value_take_string (retval, gda_sql_identifier_add_quotes (str));
+			g_value_take_string (retval, gda_sql_identifier_force_quotes (str));
 		}
 		else {
 			gchar *tmp = NULL;
@@ -531,7 +531,7 @@ _gda_data_meta_wrapper_compute_value (const GValue *value, GdaSqlIdentifierStyle
 
 			if ((reserved_keyword_func && reserved_keyword_func (tmp ? tmp : str)) ||
 			    (! reserved_keyword_func && is_keyword (tmp ? tmp : str))) {
-				gchar *tmp2 = gda_sql_identifier_add_quotes (tmp ? tmp : str);
+				gchar *tmp2 = gda_sql_identifier_force_quotes (tmp ? tmp : str);
 				if (tmp)
 					g_free (tmp);
 				tmp = tmp2;
diff --git a/libgda/gda-data-select.c b/libgda/gda-data-select.c
index f14357d..ae8dca6 100644
--- a/libgda/gda-data-select.c
+++ b/libgda/gda-data-select.c
@@ -3178,7 +3178,7 @@ compute_insert_select_params_mapping (GdaSet *sel_params, GdaSet *ins_values, Gd
 		}
 		g_assert (cdata.colid);
 		if ((*(cdata.colid) == '"') || (*(cdata.colid) == '`'))
-			gda_sql_identifier_remove_quotes ((gchar*) cdata.colid);
+			gda_sql_identifier_prepare_for_compare ((gchar*) cdata.colid);
 		/*g_print ("SEL param '%s' <=> column named '%s'\n", cdata.hid, cdata.colid);*/
 		
 		GSList *ins_list;
diff --git a/libgda/gda-meta-store.c b/libgda/gda-meta-store.c
index a4b0b91..420b2e0 100644
--- a/libgda/gda-meta-store.c
+++ b/libgda/gda-meta-store.c
@@ -3916,7 +3916,7 @@ gda_meta_store_schema_remove_custom_object (GdaMetaStore *store, const gchar *ob
 }
 
 /*
- * Makes sure @context is well formed, and call gda_sql_identifier_remove_quotes() on SQL
+ * Makes sure @context is well formed, and call gda_sql_identifier_prepare_for_compare() on SQL
  * identifiers's values
  *
  * Returns: a new #GdaMetaContext
@@ -3983,7 +3983,7 @@ _gda_meta_store_validate_context (GdaMetaStore *store, GdaMetaContext *context,
 							else if (G_VALUE_TYPE (context->column_values [i]) == G_TYPE_STRING) {
 								gchar *id;
 								id = g_value_dup_string (context->column_values [i]);
-								gda_sql_identifier_remove_quotes (id);
+								gda_sql_identifier_prepare_for_compare (id);
 								if (store->priv->ident_style == GDA_SQL_IDENTIFIERS_UPPER_CASE) {
 									/* move to upper case */
 									gchar *ptr;
diff --git a/libgda/gda-statement.c b/libgda/gda-statement.c
index bf67838..a308d0a 100644
--- a/libgda/gda-statement.c
+++ b/libgda/gda-statement.c
@@ -1290,7 +1290,7 @@ default_render_param_spec (GdaSqlParamSpec *pspec, GdaSqlExpr *expr, GdaSqlRende
 				     "%s", _("Unnamed parameter"));
 			goto err;
 		}
-		quoted_pname = gda_sql_identifier_add_quotes (pspec->name);
+		quoted_pname = gda_sql_identifier_force_quotes (pspec->name);
 
 		if (! (flag & (GDA_STATEMENT_SQL_PARAMS_LONG | GDA_STATEMENT_SQL_PARAMS_SHORT))) {
 			if (!expr->value || gda_value_is_null (expr->value) || strcmp (quoted_pname, pspec->name))
@@ -1315,12 +1315,12 @@ default_render_param_spec (GdaSqlParamSpec *pspec, GdaSqlExpr *expr, GdaSqlRende
 			g_string_append (string, " /* ");
 			g_string_append_printf (string, "name:%s", quoted_pname);
 			if (pspec->g_type) {
-				str = gda_sql_identifier_add_quotes (gda_g_type_to_string (pspec->g_type));
+				str = gda_sql_identifier_force_quotes (gda_g_type_to_string (pspec->g_type));
 				g_string_append_printf (string, " type:%s", str);
 				g_free (str);
 			}
 			if (pspec->descr) {
-				str = gda_sql_identifier_add_quotes (pspec->descr);
+				str = gda_sql_identifier_force_quotes (pspec->descr);
 				g_string_append_printf (string, " descr:%s", str);
 				g_free (str);
 			}
diff --git a/libgda/gda-util.c b/libgda/gda-util.c
index 9645950..16b1a06 100644
--- a/libgda/gda-util.c
+++ b/libgda/gda-util.c
@@ -2105,7 +2105,7 @@ gda_sql_identifier_quote (const gchar *id, GdaConnection *cnc, GdaServerProvider
 		gchar *tmp, *ptr;
 		tmp = _remove_quotes (g_strdup (id));
 		if (is_keyword (tmp)) {
-			ptr = gda_sql_identifier_add_quotes (tmp);
+			ptr = gda_sql_identifier_force_quotes (tmp);
 			g_free (tmp);
 			return ptr;
 		}
@@ -2117,7 +2117,7 @@ gda_sql_identifier_quote (const gchar *id, GdaConnection *cnc, GdaServerProvider
 				    (*ptr == '_'))
 					continue;
 				else {
-					ptr = gda_sql_identifier_add_quotes (tmp);
+					ptr = gda_sql_identifier_force_quotes (tmp);
 					g_free (tmp);
 					return ptr;
 				}
@@ -2132,7 +2132,7 @@ gda_sql_identifier_quote (const gchar *id, GdaConnection *cnc, GdaServerProvider
 					    (*ptr == '_'))
 						continue;
 					else {
-						ptr = gda_sql_identifier_add_quotes (tmp);
+						ptr = gda_sql_identifier_force_quotes (tmp);
 						g_free (tmp);
 						return ptr;
 					}
@@ -2140,7 +2140,7 @@ gda_sql_identifier_quote (const gchar *id, GdaConnection *cnc, GdaServerProvider
 				else if ((*ptr >= 'A') && (*ptr <= 'Z'))
 					*ptr += 'a' - 'A';
 				else if ((*ptr >= '0') && (*ptr <= '9') && (ptr == tmp)) {
-					ptr = gda_sql_identifier_add_quotes (tmp);
+					ptr = gda_sql_identifier_force_quotes (tmp);
 					g_free (tmp);
 					return ptr;
 				}
@@ -2155,7 +2155,7 @@ gda_sql_identifier_quote (const gchar *id, GdaConnection *cnc, GdaServerProvider
 			return g_strdup (id);
 		}
 		if (is_keyword (id) || _sql_identifier_needs_quotes (id) || force_quotes)
-			return gda_sql_identifier_add_quotes (id);
+			return gda_sql_identifier_force_quotes (id);
 		
 		/* nothing to do */
 		return g_strdup (id);
diff --git a/libgda/libgda.symbols b/libgda/libgda.symbols
index 1fb98b5..c0fd0a3 100644
--- a/libgda/libgda.symbols
+++ b/libgda/libgda.symbols
@@ -643,10 +643,9 @@
 	gda_sql_function_serialize
 	gda_sql_function_take_args_list
 	gda_sql_function_take_name
-	gda_sql_identifier_add_quotes
-	gda_sql_identifier_needs_quotes
+	gda_sql_identifier_force_quotes
+	gda_sql_identifier_prepare_for_compare
 	gda_sql_identifier_quote
-	gda_sql_identifier_remove_quotes
 	gda_sql_identifier_split
 	gda_sql_identifier_style_get_type
 	gda_sqlite_provider_get_type
diff --git a/libgda/sql-parser/gda-statement-struct-util.c b/libgda/sql-parser/gda-statement-struct-util.c
index fd65987..704e760 100644
--- a/libgda/sql-parser/gda-statement-struct-util.c
+++ b/libgda/sql-parser/gda-statement-struct-util.c
@@ -1,5 +1,8 @@
 /* 
- * Copyright (C) 2007 Vivien Malerba
+ * Copyright (C) 2007 - 2011 The GNOME Foundation.
+ *
+ * AUTHORS:
+ *      Vivien Malerba <malerba gnome-db org>
  *
  * This Library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public License as
@@ -138,18 +141,18 @@ _remove_quotes (gchar *str)
 }
 
 /**
- * gda_sql_identifier_add_quotes
+ * gda_sql_identifier_force_quotes
  * @str: an SQL identifier
  *
- * Add double quotes around the @str identifier. Use the gda_sql_identifier_needs_quotes()
- * function to tell if an identifier needs to be quoted.
+ * Add double quotes around the @str identifier. This function is normally used only by database provider's
+ * implementation.
  *
- * Returns: a new string
+ * For other uses, see gda_sql_identifier_quote().
  *
- * Deprecated: 4.0.3: Use gda_sql_identifier_quote() instead.
+ * Since: 5.0
  */
 gchar *
-gda_sql_identifier_add_quotes (const gchar *str)
+gda_sql_identifier_force_quotes (const gchar *str)
 {
 	gchar *retval, *rptr;
 	const gchar *sptr;
@@ -292,60 +295,7 @@ _string_is_identifier (const gchar *str)
 }
 
 /**
- * gda_sql_identifier_needs_quotes
- * @str: an SQL identifier
- *
- * Tells if @str needs to be quoted before using it in an SQL statement. To actually add quotes,
- * use gda_sql_identifier_add_quotes().
- *
- * To determine if quotes are needed: the following rules are applied:
- * <itemizedlist>
- *  <listitem><para>If the 1st character is a digit, then %TRUE is returned</para></listitem>
- *  <listitem><para>If there are mixed lower and upper case letters, then %TRUE is returned</para></listitem>
- *  <listitem><para>If there are other characters than digits, letters and the '_', '$' and '#', then %TRUE is returned</para></listitem>
- *  <listitem><para>Otherwise %FALSE is returned</para></listitem>
- * </itemizedlist>
- *
- * Returns: TRUE if @str needs some quotes
- *
- * Deprecated: 4.0.3: Not needed anymore because of the gda_sql_identifier_quote() function.
- */
-gboolean
-gda_sql_identifier_needs_quotes (const gchar *str)
-{
-	const gchar *ptr;
-	gchar icase = 0;
-
-	g_return_val_if_fail (str, FALSE);
-	for (ptr = str; *ptr; ptr++) {
-		/* quote if 1st char is a number */
-		if ((*ptr <= '9') && (*ptr >= '0')) {
-			if (ptr == str)
-				return TRUE;
-			continue;
-		}
-		if ((*ptr >= 'A') && (*ptr <= 'Z')) {
-			if (icase == 0) /* first alpha char encountered */
-				icase = 'U';
-			else if (icase == 'L') /* @str has mixed case */
-				return TRUE;
-			continue;
-		}
-		if ((*ptr >= 'a') && (*ptr <= 'z')) {
-			if (icase == 0) /* first alpha char encountered */
-				icase = 'L';
-			else if (icase == 'U')
-				return TRUE; /* @str has mixed case */
-			continue;
-		}
-		if ((*ptr != '$') && (*ptr != '_') && (*ptr != '#'))
-			return TRUE;
-	}
-	return FALSE;
-}
-
-/**
- * gda_sql_identifier_remove_quotes
+ * gda_sql_identifier_prepare_for_compare
  * @str: a quoted string
  *
  * Prepares @str to be compared:
@@ -359,14 +309,16 @@ gda_sql_identifier_needs_quotes (const gchar *str)
  *     of it is preceeded with a backslash character or with the delimiter character itself</para></listitem>
  * </itemizedlist>
  *
+ * This function is normally used only by database provider's implementation.
+ *
  * WARNING: @str must NOT be a composed identifier (&lt;part1&gt;."&lt;part2&gt;" for example)
  * 
  * Returns: @str
- * 
- * Deprecated: 4.0.3: Not needed anymore because of the gda_sql_identifier_quote() function.
+ *
+ * Since: 5.0
  */
 gchar *
-gda_sql_identifier_remove_quotes (gchar *str)
+gda_sql_identifier_prepare_for_compare (gchar *str)
 {
 	if (!str)
 		return NULL;
diff --git a/libgda/sql-parser/gda-statement-struct-util.h b/libgda/sql-parser/gda-statement-struct-util.h
index 08e68cf..fb1596e 100644
--- a/libgda/sql-parser/gda-statement-struct-util.h
+++ b/libgda/sql-parser/gda-statement-struct-util.h
@@ -1,5 +1,8 @@
-/* 
- * Copyright (C) 2007 - 2008 Vivien Malerba
+/*
+ * Copyright (C) 2007 - 2011 The GNOME Foundation.
+ *
+ * AUTHORS:
+ *      Vivien Malerba <malerba gnome-db org>
  *
  * This Library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public License as
@@ -31,11 +34,8 @@ gchar    *_json_quote_string (const gchar *str);
 gboolean  _string_is_identifier (const gchar *str);
 gboolean  _split_identifier_string (gchar *str, gchar **remain, gchar **last);
 
-#ifndef GDA_DISABLE_DEPRECATED
-gboolean  gda_sql_identifier_needs_quotes (const gchar *str);
-gchar    *gda_sql_identifier_add_quotes (const gchar *str);
-gchar    *gda_sql_identifier_remove_quotes (gchar *str);
-#endif
+gchar    *gda_sql_identifier_force_quotes (const gchar *str);
+gchar    *gda_sql_identifier_prepare_for_compare (gchar *str);
 
 /* to be removed, only here for debug */
 gchar    *gda_sql_value_stringify (const GValue *value);
diff --git a/libgda/sqlite/gda-sqlite-provider.c b/libgda/sqlite/gda-sqlite-provider.c
index fddd7e4..a99a297 100644
--- a/libgda/sqlite/gda-sqlite-provider.c
+++ b/libgda/sqlite/gda-sqlite-provider.c
@@ -1987,11 +1987,11 @@ add_oid_columns (GdaStatement *stmt, GHashTable **out_hash, gint *out_nb_cols_ad
 		
 		/* add to hash table */
 		add_index++;
-		g_hash_table_insert (hash, gda_sql_identifier_remove_quotes (g_strdup (name)),
+		g_hash_table_insert (hash, gda_sql_identifier_prepare_for_compare (g_strdup (name)),
 				     GINT_TO_POINTER (add_index)); /* ADDED 1 to column number,
 								    * don't forget to remove 1 when using */
 		if (target->as)
-			g_hash_table_insert (hash, gda_sql_identifier_remove_quotes (g_strdup (target->table_name)),
+			g_hash_table_insert (hash, gda_sql_identifier_prepare_for_compare (g_strdup (target->table_name)),
 					     GINT_TO_POINTER (add_index)); /* ADDED 1 to column number,
 									    * don't forget to remove 1 when using */
 		nb_cols_added ++;
diff --git a/libgda/sqlite/gda-sqlite-util.c b/libgda/sqlite/gda-sqlite-util.c
index 822b33a..128b207 100644
--- a/libgda/sqlite/gda-sqlite-util.c
+++ b/libgda/sqlite/gda-sqlite-util.c
@@ -255,7 +255,7 @@ _gda_sqlite_identifier_quote (G_GNUC_UNUSED GdaServerProvider *provider, GdaConn
 		gchar *tmp, *ptr;
 		tmp = sqlite_remove_quotes (g_strdup (id));
 		if (kwfunc (tmp)) {
-			ptr = gda_sql_identifier_add_quotes (tmp);
+			ptr = gda_sql_identifier_force_quotes (tmp);
 			g_free (tmp);
 			return ptr;
 		}
@@ -269,7 +269,7 @@ _gda_sqlite_identifier_quote (G_GNUC_UNUSED GdaServerProvider *provider, GdaConn
 				    (*ptr >= '_'))
 					continue;
 				else {
-					ptr = gda_sql_identifier_add_quotes (tmp);
+					ptr = gda_sql_identifier_force_quotes (tmp);
 					g_free (tmp);
 					return ptr;
 				}
@@ -286,7 +286,7 @@ _gda_sqlite_identifier_quote (G_GNUC_UNUSED GdaServerProvider *provider, GdaConn
 			/* there are already some quotes */
 			gchar *tmp, *ptr;
 			tmp = sqlite_remove_quotes (g_strdup (id));
-			ptr = gda_sql_identifier_add_quotes (tmp);
+			ptr = gda_sql_identifier_force_quotes (tmp);
 			g_free (tmp);
 			return ptr;
 		}
diff --git a/providers/mysql/gda-mysql-provider.c b/providers/mysql/gda-mysql-provider.c
index 77fdd1e..162a966 100644
--- a/providers/mysql/gda-mysql-provider.c
+++ b/providers/mysql/gda-mysql-provider.c
@@ -2880,7 +2880,7 @@ gda_mysql_identifier_quote (GdaServerProvider *provider, GdaConnection *cnc,
 			gchar *tmp, *ptr;
 			tmp = my_remove_quotes (g_strdup (id));
 			if (kwfunc (tmp)) {
-				ptr = gda_sql_identifier_add_quotes (tmp);
+				ptr = gda_sql_identifier_force_quotes (tmp);
 				g_free (tmp);
 				return ptr;
 			}
@@ -2890,13 +2890,13 @@ gda_mysql_identifier_quote (GdaServerProvider *provider, GdaConnection *cnc,
 				    (*ptr == '_'))
 					continue;
 				else {
-					ptr = gda_sql_identifier_add_quotes (tmp);
+					ptr = gda_sql_identifier_force_quotes (tmp);
 					g_free (tmp);
 					return ptr;
 				}
 			}
 			return tmp;
-			/*			ptr = gda_sql_identifier_add_quotes (tmp);
+			/*			ptr = gda_sql_identifier_force_quotes (tmp);
 			g_free (tmp);
 			return ptr;*/
 		}
@@ -2920,7 +2920,7 @@ gda_mysql_identifier_quote (GdaServerProvider *provider, GdaConnection *cnc,
 			gchar *tmp, *ptr;
 			tmp = my_remove_quotes (g_strdup (id));
 			if (kwfunc (tmp)) {
-				ptr = gda_sql_identifier_add_quotes (tmp);
+				ptr = gda_sql_identifier_force_quotes (tmp);
 				g_free (tmp);
 				return ptr;
 			}
@@ -2932,7 +2932,7 @@ gda_mysql_identifier_quote (GdaServerProvider *provider, GdaConnection *cnc,
 					    (*ptr == '_'))
 						continue;
 					else {
-						ptr = gda_sql_identifier_add_quotes (tmp);
+						ptr = gda_sql_identifier_force_quotes (tmp);
 						g_free (tmp);
 						return ptr;
 					}
@@ -2948,7 +2948,7 @@ gda_mysql_identifier_quote (GdaServerProvider *provider, GdaConnection *cnc,
 					    (*ptr == '_'))
 						continue;
 					else {
-						ptr = gda_sql_identifier_add_quotes (tmp);
+						ptr = gda_sql_identifier_force_quotes (tmp);
 						g_free (tmp);
 						return ptr;
 					}
diff --git a/providers/oracle/gda-oracle-meta.c b/providers/oracle/gda-oracle-meta.c
index 06c3315..3293610 100644
--- a/providers/oracle/gda-oracle-meta.c
+++ b/providers/oracle/gda-oracle-meta.c
@@ -501,7 +501,7 @@ oracle_identifier_to_value (const gchar *sqlid)
 		for (ptr = sqlid; *ptr; ptr++) {
 			if ((*ptr == ' ') || (*ptr != g_ascii_toupper (*ptr))) {
 				/* add quotes */
-				g_value_take_string (v, gda_sql_identifier_add_quotes (sqlid));
+				g_value_take_string (v, gda_sql_identifier_force_quotes (sqlid));
 				return v;
 			}
 		}
@@ -509,7 +509,7 @@ oracle_identifier_to_value (const gchar *sqlid)
 		g_value_set_string (v, sqlid);
 	}
 	else
-		g_value_take_string (v, gda_sql_identifier_add_quotes (sqlid));
+		g_value_take_string (v, gda_sql_identifier_force_quotes (sqlid));
 	return v;
 }
 
diff --git a/providers/oracle/gda-oracle-provider.c b/providers/oracle/gda-oracle-provider.c
index aef61a5..fb1ea49 100644
--- a/providers/oracle/gda-oracle-provider.c
+++ b/providers/oracle/gda-oracle-provider.c
@@ -2371,7 +2371,7 @@ gda_oracle_identifier_quote (GdaServerProvider *provider, GdaConnection *cnc,
 		gchar *tmp, *ptr;
 		tmp = ora_remove_quotes (g_strdup (id));
 		if (kwfunc (tmp)) {
-			ptr = gda_sql_identifier_add_quotes (tmp);
+			ptr = gda_sql_identifier_force_quotes (tmp);
 			g_free (tmp);
 			return ptr;
 		}
@@ -2383,7 +2383,7 @@ gda_oracle_identifier_quote (GdaServerProvider *provider, GdaConnection *cnc,
 				    (*ptr == '_'))
 					continue;
 				else {
-					ptr = gda_sql_identifier_add_quotes (tmp);
+					ptr = gda_sql_identifier_force_quotes (tmp);
 					g_free (tmp);
 					return ptr;
 				}
@@ -2402,7 +2402,7 @@ gda_oracle_identifier_quote (GdaServerProvider *provider, GdaConnection *cnc,
 					    (*ptr == '_'))
 						continue;
 					else {
-						ptr = gda_sql_identifier_add_quotes (tmp);
+						ptr = gda_sql_identifier_force_quotes (tmp);
 						g_free (tmp);
 						return ptr;
 					}
@@ -2410,7 +2410,7 @@ gda_oracle_identifier_quote (GdaServerProvider *provider, GdaConnection *cnc,
 				else if ((*ptr >= 'A') && (*ptr <= 'Z'))
 					*ptr += 'a' - 'A';
 				else if ((*ptr >= '0') && (*ptr <= '9') && (ptr == tmp)) {
-					ptr = gda_sql_identifier_add_quotes (tmp);
+					ptr = gda_sql_identifier_force_quotes (tmp);
 					g_free (tmp);
 					return ptr;
 				}
diff --git a/providers/postgres/gda-postgres-provider.c b/providers/postgres/gda-postgres-provider.c
index 7dc85ca..8f8feb7 100644
--- a/providers/postgres/gda-postgres-provider.c
+++ b/providers/postgres/gda-postgres-provider.c
@@ -2478,7 +2478,7 @@ gda_postgresql_identifier_quote (G_GNUC_UNUSED GdaServerProvider *provider, GdaC
 		gchar *tmp, *ptr;
 		tmp = pg_remove_quotes (g_strdup (id));
 		if (kwfunc (tmp)) {
-			ptr = gda_sql_identifier_add_quotes (tmp);
+			ptr = gda_sql_identifier_force_quotes (tmp);
 			g_free (tmp);
 			return ptr;
 		}
@@ -2490,7 +2490,7 @@ gda_postgresql_identifier_quote (G_GNUC_UNUSED GdaServerProvider *provider, GdaC
 				    (*ptr == '_'))
 					continue;
 				else {
-					ptr = gda_sql_identifier_add_quotes (tmp);
+					ptr = gda_sql_identifier_force_quotes (tmp);
 					g_free (tmp);
 					return ptr;
 				}
@@ -2505,7 +2505,7 @@ gda_postgresql_identifier_quote (G_GNUC_UNUSED GdaServerProvider *provider, GdaC
 					    (*ptr == '_'))
 						continue;
 					else {
-						ptr = gda_sql_identifier_add_quotes (tmp);
+						ptr = gda_sql_identifier_force_quotes (tmp);
 						g_free (tmp);
 						return ptr;
 					}
@@ -2513,7 +2513,7 @@ gda_postgresql_identifier_quote (G_GNUC_UNUSED GdaServerProvider *provider, GdaC
 				else if ((*ptr >= 'A') && (*ptr <= 'Z'))
 					*ptr += 'a' - 'A';
 				else if ((*ptr >= '0') && (*ptr <= '9') && (ptr == tmp)) {
-					ptr = gda_sql_identifier_add_quotes (tmp);
+					ptr = gda_sql_identifier_force_quotes (tmp);
 					g_free (tmp);
 					return ptr;
 				}
diff --git a/tests/test-sql-identifier.c b/tests/test-sql-identifier.c
index 8378986..e081f77 100644
--- a/tests/test-sql-identifier.c
+++ b/tests/test-sql-identifier.c
@@ -44,13 +44,47 @@ ATest tests[] = {
 	{"T8BLE_a", TRUE},
 };
 
+static gboolean
+identifier_needs_quotes (const gchar *str)
+{
+	const gchar *ptr;
+	gchar icase = 0;
+
+	g_return_val_if_fail (str, FALSE);
+	for (ptr = str; *ptr; ptr++) {
+		/* quote if 1st char is a number */
+		if ((*ptr <= '9') && (*ptr >= '0')) {
+			if (ptr == str)
+				return TRUE;
+			continue;
+		}
+		if ((*ptr >= 'A') && (*ptr <= 'Z')) {
+			if (icase == 0) /* first alpha char encountered */
+				icase = 'U';
+			else if (icase == 'L') /* @str has mixed case */
+				return TRUE;
+			continue;
+		}
+		if ((*ptr >= 'a') && (*ptr <= 'z')) {
+			if (icase == 0) /* first alpha char encountered */
+				icase = 'L';
+			else if (icase == 'U')
+				return TRUE; /* @str has mixed case */
+			continue;
+		}
+		if ((*ptr != '$') && (*ptr != '_') && (*ptr != '#'))
+			return TRUE;
+	}
+	return FALSE;
+}
+
 int
 main (int argc, char** argv)
 {
 	gint i, nfailed = 0;
 	for (i = 0; i < G_N_ELEMENTS (tests); i++) {
 		ATest *test = &(tests [i]);
-		if (gda_sql_identifier_needs_quotes (test->sql_identifier) != test->need_quotes) {
+		if (identifier_needs_quotes (test->sql_identifier) != test->need_quotes) {
 			g_print ("Failed for %s: reported %s\n", test->sql_identifier,
 				 test->need_quotes ? "no quotes needed" : "quotes needed");
 			nfailed++;
diff --git a/tools/command-exec.c b/tools/command-exec.c
index ddcee88..89c465a 100644
--- a/tools/command-exec.c
+++ b/tools/command-exec.c
@@ -398,7 +398,7 @@ gda_internal_command_list_tables (G_GNUC_UNUSED SqlConsole *console, GdaConnecti
 			"table_type LIKE '%TABLE%' "
 			"ORDER BY table_schema, table_name";
 
-		gchar *tmp = gda_sql_identifier_remove_quotes (g_strdup (args[0]));
+		gchar *tmp = gda_sql_identifier_prepare_for_compare (g_strdup (args[0]));
 		g_value_take_string (v = gda_value_new (G_TYPE_STRING), tmp);
 		model = gda_meta_store_extract (gda_connection_get_meta_store (cnc), sql, error, "tname", v, NULL);
 		gda_value_free (v);



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