[libgda] Correctly handle SQL identifiers containing a double quote



commit 85f5c34440402460a9c17131e194a58deb30d66e
Author: Vivien Malerba <malerba gnome-db org>
Date:   Sun Jan 8 15:13:37 2012 +0100

    Correctly handle SQL identifiers containing a double quote
    
    in _split_identifier_string() and _string_is_identifier()

 libgda/sql-parser/gda-statement-struct-util.c |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/libgda/sql-parser/gda-statement-struct-util.c b/libgda/sql-parser/gda-statement-struct-util.c
index d18dead..89ba43e 100644
--- a/libgda/sql-parser/gda-statement-struct-util.c
+++ b/libgda/sql-parser/gda-statement-struct-util.c
@@ -283,9 +283,16 @@ _string_is_identifier (const gchar *str)
 		ptr = str + 1;
 	else
 		ptr = str;
-	for (; 
-	     IdChar(*ptr) || (*ptr == '*') || (*ptr == '.') || (*ptr == '-') || (((*ptr == '"') || (*ptr == '`')) && ptr[1] == 0); 
-	     ptr++);
+	for (; IdChar(*ptr) ||
+		     (*ptr == '*') ||
+		     (*ptr == '.') ||
+		     (*ptr == '-') ||
+		     ((*ptr == '"') && (ptr[1] == '"')) ||
+		     (((*ptr == '"') || (*ptr == '`')) && ptr[1] == 0);
+	     ptr++) {
+		if ((*ptr == '"') && (ptr[1] == '"'))
+			ptr++;
+	}
 	if (*ptr) 
 		return FALSE;
 	if (((*str == '"') && (ptr[-1] == '"')) ||
@@ -395,8 +402,13 @@ _split_identifier_string (gchar *str, gchar **remain, gchar **last)
 	}
 
 	for (ptr = str + strlen (str) - 1; ptr >= str; ptr--) {
-		if (*ptr == '"') 
+		if (*ptr == '"') {
+			if ((ptr > str) && (ptr[-1] == '"')) {
+				ptr--;
+				continue;
+			}
 			inq = !inq;
+		}
 		else if ((*ptr == '.') && !inq) {
 			*ptr = 0;
 			*remain = str;



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