[libgda/LIBGDA_4.2] Add GDA_SQL_OPERATOR_TYPE_ILIKE.



commit 7ca7fd13c5519d577f012d44374687425382ae4e
Author: Vivien Malerba <malerba gnome-db org>
Date:   Tue Jul 12 22:02:50 2011 +0200

    Add GDA_SQL_OPERATOR_TYPE_ILIKE.
    
    This allows use of the ILIKE operator, which is a PostgreSQL
    extension.

 libgda/gda-statement.c                         |    3 ++
 libgda/sql-parser/gda-sql-parser.c             |    1 +
 libgda/sql-parser/gda-statement-struct-parts.c |    7 ++++
 libgda/sql-parser/gda-statement-struct-parts.h |   37 +++++++++++++++++++++++-
 libgda/sql-parser/gda-statement-struct.c       |    1 +
 libgda/sql-parser/parser.y                     |    7 +++-
 6 files changed, 53 insertions(+), 3 deletions(-)
---
diff --git a/libgda/gda-statement.c b/libgda/gda-statement.c
index 4ae467d..964d525 100644
--- a/libgda/gda-statement.c
+++ b/libgda/gda-statement.c
@@ -1626,6 +1626,9 @@ default_render_operation (GdaSqlOperation *op, GdaSqlRenderingContext *context,
 	case GDA_SQL_OPERATOR_TYPE_LIKE:
 		str = g_strdup_printf ("%s LIKE %s", SQL_OPERAND (sql_list->data)->sql, SQL_OPERAND (sql_list->next->data)->sql);
 		break;
+	case GDA_SQL_OPERATOR_TYPE_ILIKE:
+		str = g_strdup_printf ("%s ILIKE %s", SQL_OPERAND (sql_list->data)->sql, SQL_OPERAND (sql_list->next->data)->sql);
+		break;
 	case GDA_SQL_OPERATOR_TYPE_GT:
 		str = g_strdup_printf ("%s > %s", SQL_OPERAND (sql_list->data)->sql, SQL_OPERAND (sql_list->next->data)->sql);
 		break;
diff --git a/libgda/sql-parser/gda-sql-parser.c b/libgda/sql-parser/gda-sql-parser.c
index 40e0a42..ef17c62 100644
--- a/libgda/sql-parser/gda-sql-parser.c
+++ b/libgda/sql-parser/gda-sql-parser.c
@@ -940,6 +940,7 @@ keywordCode (GdaSqlParser *parser, gchar *str, gint len)
 		g_hash_table_insert (keywords, "full", GINT_TO_POINTER (L_FULL));
 		g_hash_table_insert (keywords, "group", GINT_TO_POINTER (L_GROUP));
 		g_hash_table_insert (keywords, "having", GINT_TO_POINTER (L_HAVING));
+		g_hash_table_insert (keywords, "ilike", GINT_TO_POINTER (L_ILIKE));
 		g_hash_table_insert (keywords, "immediate", GINT_TO_POINTER (L_IMMEDIATE));
 		g_hash_table_insert (keywords, "in", GINT_TO_POINTER (L_IN));
 		g_hash_table_insert (keywords, "inner", GINT_TO_POINTER (L_INNER));
diff --git a/libgda/sql-parser/gda-statement-struct-parts.c b/libgda/sql-parser/gda-statement-struct-parts.c
index ece7e13..9cb24f9 100644
--- a/libgda/sql-parser/gda-statement-struct-parts.c
+++ b/libgda/sql-parser/gda-statement-struct-parts.c
@@ -732,6 +732,11 @@ gda_sql_operation_operator_to_string (GdaSqlOperatorType op)
 		return "NOT IN";
 	case GDA_SQL_OPERATOR_TYPE_LIKE:
 		return "LIKE";
+        /* ILIKE is a PostgreSQL extension for case-insensitive comparison.
+         * See http://developer.postgresql.org/pgdocs/postgres/functions-matching.html
+         */ 
+	case GDA_SQL_OPERATOR_TYPE_ILIKE:
+		return "ILIKE";
 	case GDA_SQL_OPERATOR_TYPE_BETWEEN:
 		return "BETWEEN";
 	case GDA_SQL_OPERATOR_TYPE_GT:
@@ -803,6 +808,8 @@ gda_sql_operation_operator_from_string (const gchar *op)
 			return GDA_SQL_OPERATOR_TYPE_IS;
 		else if (op[1] == 'N')
 			return GDA_SQL_OPERATOR_TYPE_IN;
+		else if (op[1] == 'L')
+			return GDA_SQL_OPERATOR_TYPE_ILIKE;
 		break;
 	case 'L':
 		return GDA_SQL_OPERATOR_TYPE_LIKE;
diff --git a/libgda/sql-parser/gda-statement-struct-parts.h b/libgda/sql-parser/gda-statement-struct-parts.h
index 4b137cf..3008221 100644
--- a/libgda/sql-parser/gda-statement-struct-parts.h
+++ b/libgda/sql-parser/gda-statement-struct-parts.h
@@ -179,6 +179,40 @@ void             gda_sql_function_take_args_list (GdaSqlFunction *function, GSLi
 /*
  * An operation on one or more expressions
  */
+/**
+ * GdaSqlOperatorType:
+ * @GDA_SQL_OPERATOR_TYPE_AND: 
+ * @GDA_SQL_OPERATOR_TYPE_OR: 
+ * @GDA_SQL_OPERATOR_TYPE_EQ: 
+ * @GDA_SQL_OPERATOR_TYPE_IS: 
+ * @GDA_SQL_OPERATOR_TYPE_LIKE:
+ * @GDA_SQL_OPERATOR_TYPE_ILIKE:  
+ * @GDA_SQL_OPERATOR_TYPE_BETWEEN: 
+ * @GDA_SQL_OPERATOR_TYPE_GT: 
+ * @GDA_SQL_OPERATOR_TYPE_LT: 
+ * @GDA_SQL_OPERATOR_TYPE_GEQ: 
+ * @GDA_SQL_OPERATOR_TYPE_LEQ: 
+ * @GDA_SQL_OPERATOR_TYPE_DIFF: 
+ * @GDA_SQL_OPERATOR_TYPE_REGEXP: 
+ * @GDA_SQL_OPERATOR_TYPE_REGEXP_CI: 
+ * @GDA_SQL_OPERATOR_TYPE_NOT_REGEXP: 
+ * @GDA_SQL_OPERATOR_TYPE_NOT_REGEXP_CI: 
+ * @GDA_SQL_OPERATOR_TYPE_SIMILAR: 
+ * @GDA_SQL_OPERATOR_TYPE_ISNULL: 
+ * @GDA_SQL_OPERATOR_TYPE_ISNOTNULL: 
+ * @GDA_SQL_OPERATOR_TYPE_NOT: 
+ * @GDA_SQL_OPERATOR_TYPE_IN: 
+ * @GDA_SQL_OPERATOR_TYPE_NOTIN: 
+ * @GDA_SQL_OPERATOR_TYPE_CONCAT: 
+ * @GDA_SQL_OPERATOR_TYPE_PLUS: 
+ * @GDA_SQL_OPERATOR_TYPE_MINUS: 
+ * @GDA_SQL_OPERATOR_TYPE_STAR: 
+ * @GDA_SQL_OPERATOR_TYPE_DIV: 
+ * @GDA_SQL_OPERATOR_TYPE_REM: 
+ * @GDA_SQL_OPERATOR_TYPE_BITAND: 
+ * @GDA_SQL_OPERATOR_TYPE_BITOR: 
+ * @GDA_SQL_OPERATOR_TYPE_BITNOT:
+ */
 typedef enum {
 	GDA_SQL_OPERATOR_TYPE_AND,
 	GDA_SQL_OPERATOR_TYPE_OR,
@@ -211,7 +245,8 @@ typedef enum {
 	GDA_SQL_OPERATOR_TYPE_REM,
 	GDA_SQL_OPERATOR_TYPE_BITAND,
 	GDA_SQL_OPERATOR_TYPE_BITOR,
-	GDA_SQL_OPERATOR_TYPE_BITNOT
+	GDA_SQL_OPERATOR_TYPE_BITNOT,
+	GDA_SQL_OPERATOR_TYPE_ILIKE
 } GdaSqlOperatorType;
 
 struct _GdaSqlOperation {
diff --git a/libgda/sql-parser/gda-statement-struct.c b/libgda/sql-parser/gda-statement-struct.c
index c7a9086..bbdc709 100644
--- a/libgda/sql-parser/gda-statement-struct.c
+++ b/libgda/sql-parser/gda-statement-struct.c
@@ -1039,6 +1039,7 @@ gda_sql_any_part_check_structure (GdaSqlAnyPart *node, GError **error)
 		case GDA_SQL_OPERATOR_TYPE_EQ:
 		case GDA_SQL_OPERATOR_TYPE_IS:
 		case GDA_SQL_OPERATOR_TYPE_LIKE:
+		case GDA_SQL_OPERATOR_TYPE_ILIKE:
 		case GDA_SQL_OPERATOR_TYPE_GT:
 		case GDA_SQL_OPERATOR_TYPE_LT:
 		case GDA_SQL_OPERATOR_TYPE_GEQ:
diff --git a/libgda/sql-parser/parser.y b/libgda/sql-parser/parser.y
index d675ac3..e62a19b 100644
--- a/libgda/sql-parser/parser.y
+++ b/libgda/sql-parser/parser.y
@@ -86,6 +86,8 @@ sql_operation_string_to_operator (const gchar *op)
 			return GDA_SQL_OPERATOR_TYPE_IS;
 		else if (op[1] == 'N')
 			return GDA_SQL_OPERATOR_TYPE_IN;
+		else if (op[1] == 'I')
+			return GDA_SQL_OPERATOR_TYPE_ILIKE;
 		break;
 	case 'L':
 		return GDA_SQL_OPERATOR_TYPE_LIKE;
@@ -237,7 +239,7 @@ compose_multiple_compounds (GdaSqlStatementCompoundType ctype, GdaSqlStatement *
 %fallback ID
   ABORT AFTER ANALYZE ASC ATTACH BEFORE BEGIN CASCADE CAST CONFLICT
   DATABASE DEFERRED DESC DETACH EACH END EXCLUSIVE EXPLAIN FAIL FOR
-  IGNORE IMMEDIATE INITIALLY INSTEAD LIKE MATCH PLAN
+  IGNORE IMMEDIATE INITIALLY INSTEAD LIKE ILIKE MATCH PLAN
   QUERY KEY OF OFFSET PRAGMA RAISE REPLACE RESTRICT ROW
   TEMP TRIGGER VACUUM VIEW VIRTUAL
   REINDEX RENAME CTIME_KW IF
@@ -252,7 +254,7 @@ compose_multiple_compounds (GdaSqlStatementCompoundType ctype, GdaSqlStatement *
 %left OR.
 %left AND.
 %right NOT.
-%left IS MATCH LIKE IN ISNULL NOTNULL DIFF EQ.
+%left IS MATCH LIKE ILIKE IN ISNULL NOTNULL DIFF EQ.
 %left BETWEEN.
 %left GT LEQ LT GEQ.
 %left REGEXP REGEXP_CI NOT_REGEXP NOT_REGEXP_CI.
@@ -821,6 +823,7 @@ expr(C) ::= expr(L) CONCAT expr(R). {C = compose_multiple_expr (GDA_SQL_OPERATOR
 expr(C) ::= expr(L) GT|LEQ|GEQ|LT(O) expr(R). {C = create_two_expr (string_to_op_type (O), L, R);}
 expr(C) ::= expr(L) DIFF|EQ(O) expr(R). {C = create_two_expr (string_to_op_type (O), L, R);}
 expr(C) ::= expr(L) LIKE expr(R). {C = create_two_expr (GDA_SQL_OPERATOR_TYPE_LIKE, L, R);}
+expr(C) ::= expr(L) ILIKE expr(R). {C = create_two_expr (GDA_SQL_OPERATOR_TYPE_ILIKE, L, R);}
 expr(C) ::= expr(L) REGEXP|REGEXP_CI|NOT_REGEXP|NOT_REGEXP_CI|SIMILAR(O) expr(R). {C = create_two_expr (string_to_op_type (O), L, R);}
 expr(C) ::= expr(L) BETWEEN expr(R) AND expr(E). {GdaSqlOperation *cond;
 						  C = gda_sql_expr_new (NULL);



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