Revision 9674 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/sqlQueryValidation/SQLQueryValidation.java
SQLQueryValidation.java | ||
---|---|---|
114 | 114 |
return true; |
115 | 115 |
} |
116 | 116 |
|
117 |
// Converts all apostrophes between aphostrophes to double inverted commas ( " ) |
|
118 |
int index = 0; |
|
119 |
boolean is_word = false; // by default isn't a word |
|
120 |
String formatted_query = new String(); |
|
121 |
char c; |
|
122 |
|
|
123 |
while (index < query.length()) { |
|
124 |
c = query.charAt(index); |
|
125 |
if (c == '\'') { |
|
126 |
if (is_word == false) { |
|
127 |
if ((index > 0) && ((query.charAt(index-1) == ' ') || (query.charAt(index-1) == '(')) ) { |
|
128 |
is_word = true; |
|
129 |
} |
|
130 |
|
|
131 |
formatted_query += c; |
|
132 |
} |
|
133 |
else { |
|
134 |
if (index == (query.length() -1)) { |
|
135 |
// is_word = false; |
|
136 |
formatted_query += c; |
|
137 |
} |
|
138 |
else { |
|
139 |
if (((query.charAt(index+1) == ' ') || (query.charAt(index+1) == ')')) ) { |
|
140 |
is_word = false; |
|
141 |
formatted_query += c; |
|
142 |
} |
|
143 |
else { |
|
144 |
formatted_query += "\""; // Convert ' to " |
|
145 |
} |
|
146 |
} |
|
147 |
} |
|
148 |
} |
|
149 |
else { |
|
150 |
formatted_query += c; |
|
151 |
} |
|
152 |
|
|
153 |
index ++; |
|
154 |
} |
|
155 |
|
|
156 |
// Converts all ocurrences of the symbol " ( double inverted commas ) to space because Zql doesn't support that symbol |
|
117 | 157 |
if (onlyWhereStatement) |
118 |
completeQuery = preQuery + query.trim().replaceAll("\"", " "); |
|
158 |
completeQuery = preQuery + formatted_query.trim().replaceAll("\"", " ");
|
|
119 | 159 |
else |
120 |
completeQuery = query.trim().replaceAll("\"", " "); |
|
160 |
completeQuery = formatted_query.trim().replaceAll("\"", " ");
|
|
121 | 161 |
|
122 | 162 |
if ((completeQuery.length() > 0) && (completeQuery.charAt(completeQuery.length() - 1) != ';')) |
123 | 163 |
completeQuery += ";"; |
Also available in: Unified diff