4 // This file is part of the LibreOffice project.
6 // This Source Code Form is subject to the terms of the Mozilla Public
7 // License, v. 2.0. If a copy of the MPL was not distributed with this
8 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 // This file incorporates work covered by the following license notice:
12 // Licensed to the Apache Software Foundation (ASF) under one or more
13 // contributor license agreements. See the NOTICE file distributed
14 // with this work for additional information regarding copyright
15 // ownership. The ASF licenses this file to you under the Apache
16 // License, Version 2.0 (the "License"); you may not use this file
17 // except in compliance with the License. You may obtain a copy of
18 // the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "sal/config.h"
23 #define YY_EXIT 1 // YY_FATAL will not halt the application
31 #include <connectivity/internalnode.hxx>
33 #ifndef _CONNECTIVITY_SQLYACC_HXX
34 #define _CONNECTIVITY_SQLYACC_HXX
40 #include "sqlbison.hxx"
44 #include <osl/diagnose.h>
45 #include <rtl/strbuf.hxx>
46 #include <connectivity/sqlparse.hxx>
47 #include <connectivity/sqlscan.hxx>
50 #pragma warning(push, 1)
58 #define YY_NO_UNISTD_H
60 using namespace connectivity;
62 // Erzeugung der Blaetter fuer die Token
63 // Blaetter werden generell vom Lexer erzeugt
65 static sal_Int32 gatherString(int delim, sal_Int32 nTyp);
66 static sal_Int32 gatherName(const sal_Char*);
67 static sal_Int32 gatherNamePre(const sal_Char* );
68 // has to be set before the parser starts
69 OSQLScanner* xxx_pGLOBAL_SQLSCAN = NULL;
71 #define SQL_NEW_NODE(text, token) \
72 SQLyylval.pParseNode = new OSQLInternalNode(text, token);
74 #define SQL_NEW_KEYWORD(token) \
75 SQLyylval.pParseNode = new OSQLInternalNode("", SQL_NODE_KEYWORD, (token)); return token;
77 #define SQL_NEW_INTNUM SQL_NEW_NODE(::rtl::OUString(SQLyytext,strlen(SQLyytext),RTL_TEXTENCODING_UTF8), SQL_NODE_INTNUM); return SQL_TOKEN_INTNUM;
78 #define SQL_NEW_APPROXNUM SQL_NEW_NODE(::rtl::OUString(SQLyytext,strlen(SQLyytext),RTL_TEXTENCODING_UTF8), SQL_NODE_APPROXNUM); return SQL_TOKEN_APPROXNUM;
79 #define SQL_NEW_DATE SQL_NEW_NODE(::rtl::OUString(SQLyytext,strlen(SQLyytext),RTL_TEXTENCODING_UTF8), SQL_NODE_ACCESS_DATE); return SQL_TOKEN_ACCESS_DATE;
81 #define YY_INPUT(buf,result,max_size) \
83 int c = xxx_pGLOBAL_SQLSCAN->SQLyygetc(); \
84 result = (c == EOF) ? YY_NULL : (buf[0] = c, 1);\
87 #define YY_FATAL_ERROR(msg) \
89 xxx_pGLOBAL_SQLSCAN->SQLyyerror(msg); \
101 %option never-interactive
104 ABS {SQL_NEW_KEYWORD(SQL_TOKEN_ABS); }
105 ACOS {SQL_NEW_KEYWORD(SQL_TOKEN_ACOS); }
106 AFTER {SQL_NEW_KEYWORD(SQL_TOKEN_AFTER); }
107 ALL {SQL_NEW_KEYWORD(SQL_TOKEN_ALL); }
108 ALTER {SQL_NEW_KEYWORD(SQL_TOKEN_ALTER); }
109 AND {SQL_NEW_KEYWORD(SQL_TOKEN_AND); }
110 ANY {SQL_NEW_KEYWORD(SQL_TOKEN_ANY); }
111 ARRAY_AGG {SQL_NEW_KEYWORD(SQL_TOKEN_ARRAY_AGG); }
112 AS {SQL_NEW_KEYWORD(SQL_TOKEN_AS); }
113 ASC {SQL_NEW_KEYWORD(SQL_TOKEN_ASC); }
114 ASCII {SQL_NEW_KEYWORD(SQL_TOKEN_ASCII); }
115 ASIN {SQL_NEW_KEYWORD(SQL_TOKEN_ASIN); }
116 AT {SQL_NEW_KEYWORD(SQL_TOKEN_AT); }
117 ATAN {SQL_NEW_KEYWORD(SQL_TOKEN_ATAN); }
118 ATAN2 {SQL_NEW_KEYWORD(SQL_TOKEN_ATAN2); }
119 ATOMIC {SQL_NEW_KEYWORD(SQL_TOKEN_ATOMIC); }
120 AUTHORIZATION {SQL_NEW_KEYWORD(SQL_TOKEN_AUTHORIZATION); }
121 AVG {SQL_NEW_KEYWORD(SQL_TOKEN_AVG); }
123 BEFORE {SQL_NEW_KEYWORD(SQL_TOKEN_BEFORE); }
124 BEGIN {SQL_NEW_KEYWORD(SQL_TOKEN_BEGIN); }
125 BETWEEN {SQL_NEW_KEYWORD(SQL_TOKEN_BETWEEN); }
126 BIGINT {SQL_NEW_KEYWORD(SQL_TOKEN_BIGINT); }
127 BINARY {SQL_NEW_KEYWORD(SQL_TOKEN_BINARY); }
128 BIT {SQL_NEW_KEYWORD(SQL_TOKEN_BIT); }
129 BIT_LENGTH {SQL_NEW_KEYWORD(SQL_TOKEN_BIT_LENGTH); }
130 BLOB {SQL_NEW_KEYWORD(SQL_TOKEN_BLOB); }
131 BOTH {SQL_NEW_KEYWORD(SQL_TOKEN_BOTH); }
132 BY {SQL_NEW_KEYWORD(SQL_TOKEN_BY); }
134 CALL {SQL_NEW_KEYWORD(SQL_TOKEN_CALL); }
135 CASE {SQL_NEW_KEYWORD(SQL_TOKEN_CASE); }
136 CAST {SQL_NEW_KEYWORD(SQL_TOKEN_CAST); }
137 CEILING {SQL_NEW_KEYWORD(SQL_TOKEN_CEILING); }
138 CHAR {SQL_NEW_KEYWORD(SQL_TOKEN_CHAR); }
139 CHARACTER {SQL_NEW_KEYWORD(SQL_TOKEN_CHARACTER); }
140 CHAR(ACTER)?_LENGTH {SQL_NEW_KEYWORD(SQL_TOKEN_CHAR_LENGTH); }
141 CHECK {SQL_NEW_KEYWORD(SQL_TOKEN_CHECK); }
142 CLOB {SQL_NEW_KEYWORD(SQL_TOKEN_CLOB); }
143 COALESCE {SQL_NEW_KEYWORD(SQL_TOKEN_COALESCE); }
144 COLLATE {SQL_NEW_KEYWORD(SQL_TOKEN_COLLATE); }
145 COLLECT {SQL_NEW_KEYWORD(SQL_TOKEN_COLLECT); }
146 COMMIT {SQL_NEW_KEYWORD(SQL_TOKEN_COMMIT); }
147 CONCAT {SQL_NEW_KEYWORD(SQL_TOKEN_CONCAT); }
148 CONTINUE {SQL_NEW_KEYWORD(SQL_TOKEN_CONTINUE); }
149 CONVERT {SQL_NEW_KEYWORD(SQL_TOKEN_CONVERT); }
150 COS {SQL_NEW_KEYWORD(SQL_TOKEN_COS); }
151 COT {SQL_NEW_KEYWORD(SQL_TOKEN_COT); }
152 COUNT {SQL_NEW_KEYWORD(SQL_TOKEN_COUNT); }
153 CREATE {SQL_NEW_KEYWORD(SQL_TOKEN_CREATE); }
154 CROSS {SQL_NEW_KEYWORD(SQL_TOKEN_CROSS); }
155 CUME_RANK {SQL_NEW_KEYWORD(SQL_TOKEN_CUME_DIST); }
156 CURRENT {SQL_NEW_KEYWORD(SQL_TOKEN_CURRENT); }
157 CURRENT_DATE {SQL_NEW_KEYWORD(SQL_TOKEN_CURRENT_DATE); }
158 CURRENT_CATALOG {SQL_NEW_KEYWORD(SQL_TOKEN_CURRENT_CATALOG); }
159 CURRENT_DEFAULT_TRANSFORM_GROUP {SQL_NEW_KEYWORD(SQL_TOKEN_CURRENT_DEFAULT_TRANSFORM_GROUP); }
160 CURRENT_PATH {SQL_NEW_KEYWORD(SQL_TOKEN_CURRENT_PATH); }
161 CURRENT_ROLE {SQL_NEW_KEYWORD(SQL_TOKEN_CURRENT_ROLE); }
162 CURRENT_SCHEMA {SQL_NEW_KEYWORD(SQL_TOKEN_CURRENT_SCHEMA); }
163 CURRENT_USER {SQL_NEW_KEYWORD(SQL_TOKEN_CURRENT_USER); }
164 CURDATE {SQL_NEW_KEYWORD(SQL_TOKEN_CURDATE); }
165 CURRENT_TIME {SQL_NEW_KEYWORD(SQL_TOKEN_CURRENT_TIME); }
166 CURTIME {SQL_NEW_KEYWORD(SQL_TOKEN_CURTIME); }
167 CURRENT_TIMESTAMP {SQL_NEW_KEYWORD(SQL_TOKEN_CURRENT_TIMESTAMP); }
168 CURSOR {SQL_NEW_KEYWORD(SQL_TOKEN_CURSOR); }
170 D {SQL_NEW_KEYWORD(SQL_TOKEN_D); }
171 DATE {SQL_NEW_KEYWORD(SQL_TOKEN_DATE); }
172 DATEDIFF {SQL_NEW_KEYWORD(SQL_TOKEN_DATEDIFF); }
173 DATEVALUE {SQL_NEW_KEYWORD(SQL_TOKEN_DATEVALUE); }
174 DAY {SQL_NEW_KEYWORD(SQL_TOKEN_DAY); }
175 DAYNAME {SQL_NEW_KEYWORD(SQL_TOKEN_DAYNAME); }
176 DAYOFMONTH {SQL_NEW_KEYWORD(SQL_TOKEN_DAYOFMONTH); }
177 DAYOFWEEK {SQL_NEW_KEYWORD(SQL_TOKEN_DAYOFWEEK); }
178 DAYOFYEAR {SQL_NEW_KEYWORD(SQL_TOKEN_DAYOFYEAR); }
179 DEC {SQL_NEW_KEYWORD(SQL_TOKEN_DEC); }
180 DECIMAL {SQL_NEW_KEYWORD(SQL_TOKEN_DECIMAL); }
181 DECLARE {SQL_NEW_KEYWORD(SQL_TOKEN_DECLARE); }
182 DEFAULT {SQL_NEW_KEYWORD(SQL_TOKEN_DEFAULT); }
183 DEGREES {SQL_NEW_KEYWORD(SQL_TOKEN_DEGREES); }
184 DELETE {SQL_NEW_KEYWORD(SQL_TOKEN_DELETE); }
185 DENSE_RANK {SQL_NEW_KEYWORD(SQL_TOKEN_DENSE_RANK); }
186 DESC {SQL_NEW_KEYWORD(SQL_TOKEN_DESC); }
187 DIFFERENCE {SQL_NEW_KEYWORD(SQL_TOKEN_DIFFERENCE); }
188 DISTINCT {SQL_NEW_KEYWORD(SQL_TOKEN_DISTINCT); }
189 DOUBLE {SQL_NEW_KEYWORD(SQL_TOKEN_DOUBLE); }
190 DROP {SQL_NEW_KEYWORD(SQL_TOKEN_DROP); }
192 EACH {SQL_NEW_KEYWORD(SQL_TOKEN_EACH); }
193 ELSE {SQL_NEW_KEYWORD(SQL_TOKEN_ELSE); }
194 END {SQL_NEW_KEYWORD(SQL_TOKEN_END); }
195 EVERY {SQL_NEW_KEYWORD(SQL_TOKEN_EVERY); }
196 ESCAPE {SQL_NEW_KEYWORD(SQL_TOKEN_ESCAPE); }
197 EXCEPT {SQL_NEW_KEYWORD(SQL_TOKEN_EXCEPT); }
198 EXCLUDE {SQL_NEW_KEYWORD(SQL_TOKEN_EXCLUDE); }
199 EXISTS {SQL_NEW_KEYWORD(SQL_TOKEN_EXISTS); }
200 EXP {SQL_NEW_KEYWORD(SQL_TOKEN_EXP); }
201 EXTRACT {SQL_NEW_KEYWORD(SQL_TOKEN_EXTRACT); }
203 FALSE {SQL_NEW_KEYWORD(SQL_TOKEN_FALSE); }
204 FETCH {SQL_NEW_KEYWORD(SQL_TOKEN_FETCH); }
205 FIRST {SQL_NEW_KEYWORD(SQL_TOKEN_FIRST); }
206 FIRST_VALUE {SQL_NEW_KEYWORD(SQL_TOKEN_FIRST_VALUE); }
207 FLOAT {SQL_NEW_KEYWORD(SQL_TOKEN_FLOAT); }
208 FLOOR {SQL_NEW_KEYWORD(SQL_TOKEN_FLOOR); }
209 FN {SQL_NEW_KEYWORD(SQL_TOKEN_FN); }
210 FOLLOWING {SQL_NEW_KEYWORD(SQL_TOKEN_FOLLOWING); }
211 FOR {SQL_NEW_KEYWORD(SQL_TOKEN_FOR); }
212 FOREIGN {SQL_NEW_KEYWORD(SQL_TOKEN_FOREIGN); }
213 FOUND {SQL_NEW_KEYWORD(SQL_TOKEN_FOUND); }
214 FROM {SQL_NEW_KEYWORD(SQL_TOKEN_FROM); }
215 FULL {SQL_NEW_KEYWORD(SQL_TOKEN_FULL); }
216 FUSION {SQL_NEW_KEYWORD(SQL_TOKEN_FUSION); }
218 GRANT {SQL_NEW_KEYWORD(SQL_TOKEN_GRANT); }
219 GROUP {SQL_NEW_KEYWORD(SQL_TOKEN_GROUP); }
221 HAVING {SQL_NEW_KEYWORD(SQL_TOKEN_HAVING); }
222 HOUR {SQL_NEW_KEYWORD(SQL_TOKEN_HOUR); }
224 IGNORE {SQL_NEW_KEYWORD(SQL_TOKEN_IGNORE); }
225 IN {SQL_NEW_KEYWORD(SQL_TOKEN_IN); }
226 INNER {SQL_NEW_KEYWORD(SQL_TOKEN_INNER); }
227 INSERT {SQL_NEW_KEYWORD(SQL_TOKEN_INSERT); }
228 INSTEAD {SQL_NEW_KEYWORD(SQL_TOKEN_INSTEAD); }
229 INT(EGER)? {SQL_NEW_KEYWORD(SQL_TOKEN_INTEGER); }
230 INTERSECT {SQL_NEW_KEYWORD(SQL_TOKEN_INTERSECT); }
231 INTERVAL {SQL_NEW_KEYWORD(SQL_TOKEN_INTERVAL); }
232 INTERSECTION {SQL_NEW_KEYWORD(SQL_TOKEN_INTERSECTION); }
233 INTO {SQL_NEW_KEYWORD(SQL_TOKEN_INTO); }
234 IS {SQL_NEW_KEYWORD(SQL_TOKEN_IS); }
236 JOIN {SQL_NEW_KEYWORD(SQL_TOKEN_JOIN); }
238 KEY {SQL_NEW_KEYWORD(SQL_TOKEN_KEY); }
240 LAG {SQL_NEW_KEYWORD(SQL_TOKEN_LAG); }
241 LARGE {SQL_NEW_KEYWORD(SQL_TOKEN_LARGE); }
242 LAST {SQL_NEW_KEYWORD(SQL_TOKEN_LAST); }
243 LAST_VALUE {SQL_NEW_KEYWORD(SQL_TOKEN_LAST_VALUE); }
244 LCASE {SQL_NEW_KEYWORD(SQL_TOKEN_LCASE); }
245 LEAD {SQL_NEW_KEYWORD(SQL_TOKEN_LEAD); }
246 LEADING {SQL_NEW_KEYWORD(SQL_TOKEN_LEADING); }
247 LEFT {SQL_NEW_KEYWORD(SQL_TOKEN_LEFT); }
248 LENGTH {SQL_NEW_KEYWORD(SQL_TOKEN_LENGTH); }
249 LIKE {SQL_NEW_KEYWORD(SQL_TOKEN_LIKE); }
250 LIMIT {SQL_NEW_KEYWORD(SQL_TOKEN_LIMIT); }
251 LN {SQL_NEW_KEYWORD(SQL_TOKEN_LN); }
252 LOCAL {SQL_NEW_KEYWORD(SQL_TOKEN_LOCAL); }
253 LOCATE {SQL_NEW_KEYWORD(SQL_TOKEN_LOCATE); }
254 LOG {SQL_NEW_KEYWORD(SQL_TOKEN_LOG); }
255 LOGF {SQL_NEW_KEYWORD(SQL_TOKEN_LOGF); }
256 LOG10 {SQL_NEW_KEYWORD(SQL_TOKEN_LOG10); }
257 LOWER {SQL_NEW_KEYWORD(SQL_TOKEN_LOWER); }
258 LTRIM {SQL_NEW_KEYWORD(SQL_TOKEN_LTRIM); }
260 MAX {SQL_NEW_KEYWORD(SQL_TOKEN_MAX); }
261 MIN {SQL_NEW_KEYWORD(SQL_TOKEN_MIN); }
262 MINUTE {SQL_NEW_KEYWORD(SQL_TOKEN_MINUTE); }
263 MOD {SQL_NEW_KEYWORD(SQL_TOKEN_MOD); }
264 MONTH {SQL_NEW_KEYWORD(SQL_TOKEN_MONTH); }
265 MONTHNAME {SQL_NEW_KEYWORD(SQL_TOKEN_MONTHNAME); }
267 NATIONAL {SQL_NEW_KEYWORD(SQL_TOKEN_NATIONAL); }
268 NATURAL {SQL_NEW_KEYWORD(SQL_TOKEN_NATURAL); }
269 NCHAR {SQL_NEW_KEYWORD(SQL_TOKEN_NCHAR); }
270 NCLOB {SQL_NEW_KEYWORD(SQL_TOKEN_NCLOB); }
271 NEW {SQL_NEW_KEYWORD(SQL_TOKEN_NEW); }
272 NEXT {SQL_NEW_KEYWORD(SQL_TOKEN_NEXT); }
273 NO {SQL_NEW_KEYWORD(SQL_TOKEN_NO); }
274 NOT {SQL_NEW_KEYWORD(SQL_TOKEN_NOT); }
275 NOW {SQL_NEW_KEYWORD(SQL_TOKEN_NOW); }
276 NTH_VALUE {SQL_NEW_KEYWORD(SQL_TOKEN_NTH_VALUE); }
277 NTILE {SQL_NEW_KEYWORD(SQL_TOKEN_NTILE); }
278 NULL {SQL_NEW_KEYWORD(SQL_TOKEN_NULL); }
279 NULLIF {SQL_NEW_KEYWORD(SQL_TOKEN_NULLIF); }
280 NULLS {SQL_NEW_KEYWORD(SQL_TOKEN_NULLS); }
281 NUMERIC {SQL_NEW_KEYWORD(SQL_TOKEN_NUMERIC); }
283 OBJECT {SQL_NEW_KEYWORD(SQL_TOKEN_OBJECT); }
284 OCTET_LENGTH {SQL_NEW_KEYWORD(SQL_TOKEN_OCTET_LENGTH); }
285 OF {SQL_NEW_KEYWORD(SQL_TOKEN_OF); }
286 OFFSET {SQL_NEW_KEYWORD(SQL_TOKEN_OFFSET); }
287 OJ {SQL_NEW_KEYWORD(SQL_TOKEN_OJ); }
288 OLD {SQL_NEW_KEYWORD(SQL_TOKEN_OLD); }
289 ON {SQL_NEW_KEYWORD(SQL_TOKEN_ON); }
290 ONLY {SQL_NEW_KEYWORD(SQL_TOKEN_ONLY); }
291 OPTION {SQL_NEW_KEYWORD(SQL_TOKEN_OPTION); }
292 OR {SQL_NEW_KEYWORD(SQL_TOKEN_OR); }
293 ORDER {SQL_NEW_KEYWORD(SQL_TOKEN_ORDER); }
294 OTHERS {SQL_NEW_KEYWORD(SQL_TOKEN_OTHERS); }
295 OUTER {SQL_NEW_KEYWORD(SQL_TOKEN_OUTER); }
296 OVER {SQL_NEW_KEYWORD(SQL_TOKEN_OVER); }
298 PARTITION {SQL_NEW_KEYWORD(SQL_TOKEN_PARTITION); }
299 PERCENT_RANK {SQL_NEW_KEYWORD(SQL_TOKEN_PERCENT_RANK); }
300 PERCENTILE_CONT {SQL_NEW_KEYWORD(SQL_TOKEN_PERCENTILE_CONT); }
301 PERCENTILE_DISC {SQL_NEW_KEYWORD(SQL_TOKEN_PERCENTILE_DISC); }
302 PI {SQL_NEW_KEYWORD(SQL_TOKEN_PI); }
303 POSITION {SQL_NEW_KEYWORD(SQL_TOKEN_POSITION); }
304 POWER {SQL_NEW_KEYWORD(SQL_TOKEN_POWER); }
305 PRECEDING {SQL_NEW_KEYWORD(SQL_TOKEN_PRECEDING); }
306 PRECISION {SQL_NEW_KEYWORD(SQL_TOKEN_PRECISION); }
307 PRIMARY {SQL_NEW_KEYWORD(SQL_TOKEN_PRIMARY); }
308 PRIVILEGES {SQL_NEW_KEYWORD(SQL_TOKEN_PRIVILEGES); }
309 PROCEDURE {SQL_NEW_KEYWORD(SQL_TOKEN_PROCEDURE); }
310 PUBLIC {SQL_NEW_KEYWORD(SQL_TOKEN_PUBLIC); }
312 QUARTER {SQL_NEW_KEYWORD(SQL_TOKEN_QUARTER); }
314 RADIANS {SQL_NEW_KEYWORD(SQL_TOKEN_RADIANS); }
315 RAND {SQL_NEW_KEYWORD(SQL_TOKEN_RAND); }
316 RANGE {SQL_NEW_KEYWORD(SQL_TOKEN_RANGE); }
317 RANK {SQL_NEW_KEYWORD(SQL_TOKEN_RANK); }
318 REAL {SQL_NEW_KEYWORD(SQL_TOKEN_REAL); }
319 REFERENCES {SQL_NEW_KEYWORD(SQL_TOKEN_REFERENCES); }
320 REFERENCING {SQL_NEW_KEYWORD(SQL_TOKEN_REFERENCING); }
321 REPEAT {SQL_NEW_KEYWORD(SQL_TOKEN_REPEAT); }
322 REPLACE {SQL_NEW_KEYWORD(SQL_TOKEN_REPLACE); }
323 RESPECT {SQL_NEW_KEYWORD(SQL_TOKEN_RESPECT); }
324 ROLLBACK {SQL_NEW_KEYWORD(SQL_TOKEN_ROLLBACK); }
325 ROUND {SQL_NEW_KEYWORD(SQL_TOKEN_ROUND); }
326 ROUNDMAGIC {SQL_NEW_KEYWORD(SQL_TOKEN_ROUNDMAGIC); }
327 ROW {SQL_NEW_KEYWORD(SQL_TOKEN_ROW); }
328 ROWS {SQL_NEW_KEYWORD(SQL_TOKEN_ROWS); }
329 ROW_NUMBER {SQL_NEW_KEYWORD(SQL_TOKEN_ROW_NUMBER); }
330 RIGHT {SQL_NEW_KEYWORD(SQL_TOKEN_RIGHT); }
331 RTRIM {SQL_NEW_KEYWORD(SQL_TOKEN_RTRIM); }
333 SCHEMA {SQL_NEW_KEYWORD(SQL_TOKEN_SCHEMA); }
334 SECOND {SQL_NEW_KEYWORD(SQL_TOKEN_SECOND); }
335 SELECT {SQL_NEW_KEYWORD(SQL_TOKEN_SELECT); }
336 SET {SQL_NEW_KEYWORD(SQL_TOKEN_SET); }
337 SIZE {SQL_NEW_KEYWORD(SQL_TOKEN_SIZE); }
338 SIGN {SQL_NEW_KEYWORD(SQL_TOKEN_SIGN); }
339 SIN {SQL_NEW_KEYWORD(SQL_TOKEN_SIN); }
340 SMALLINT {SQL_NEW_KEYWORD(SQL_TOKEN_SMALLINT); }
341 SOME {SQL_NEW_KEYWORD(SQL_TOKEN_SOME); }
342 SOUNDEX {SQL_NEW_KEYWORD(SQL_TOKEN_SOUNDEX); }
343 SPACE {SQL_NEW_KEYWORD(SQL_TOKEN_SPACE); }
344 SQRT {SQL_NEW_KEYWORD(SQL_TOKEN_SQRT); }
345 STDDEV_POP {SQL_NEW_KEYWORD(SQL_TOKEN_STDDEV_POP); }
346 STDDEV_SAMP {SQL_NEW_KEYWORD(SQL_TOKEN_STDDEV_SAMP); }
347 STATEMENT {SQL_NEW_KEYWORD(SQL_TOKEN_STATEMENT); }
348 SUBSTRING {SQL_NEW_KEYWORD(SQL_TOKEN_SUBSTRING); }
349 SUM {SQL_NEW_KEYWORD(SQL_TOKEN_SUM); }
350 SESSION_USER {SQL_NEW_KEYWORD(SQL_TOKEN_SESSION_USER); }
351 SYSTEM_USER {SQL_NEW_KEYWORD(SQL_TOKEN_SYSTEM_USER); }
353 TABLE {SQL_NEW_KEYWORD(SQL_TOKEN_TABLE); }
354 TAN {SQL_NEW_KEYWORD(SQL_TOKEN_TAN); }
355 THEN {SQL_NEW_KEYWORD(SQL_TOKEN_THEN); }
356 TIES {SQL_NEW_KEYWORD(SQL_TOKEN_TIES); }
357 TIME {SQL_NEW_KEYWORD(SQL_TOKEN_TIME); }
358 TIMESTAMP {SQL_NEW_KEYWORD(SQL_TOKEN_TIMESTAMP); }
359 TIMESTAMPADD {SQL_NEW_KEYWORD(SQL_TOKEN_TIMESTAMPADD); }
360 TIMESTAMPDIFF {SQL_NEW_KEYWORD(SQL_TOKEN_TIMESTAMPDIFF); }
361 TIMEVALUE {SQL_NEW_KEYWORD(SQL_TOKEN_TIMEVALUE); }
362 TIMEZONE_HOUR {SQL_NEW_KEYWORD(SQL_TOKEN_TIMEZONE_HOUR); }
363 TIMEZONE_MINUTE {SQL_NEW_KEYWORD(SQL_TOKEN_TIMEZONE_MINUTE); }
364 TO {SQL_NEW_KEYWORD(SQL_TOKEN_TO); }
365 TRAILING {SQL_NEW_KEYWORD(SQL_TOKEN_TRAILING); }
366 TRANSLATE {SQL_NEW_KEYWORD(SQL_TOKEN_TRANSLATE); }
367 TRIGGER {SQL_NEW_KEYWORD(SQL_TOKEN_TRIGGER); }
368 TRIM {SQL_NEW_KEYWORD(SQL_TOKEN_TRIM); }
369 TRUE {SQL_NEW_KEYWORD(SQL_TOKEN_TRUE); }
370 TRUNCATE {SQL_NEW_KEYWORD(SQL_TOKEN_TRUNCATE); }
371 TS {SQL_NEW_KEYWORD(SQL_TOKEN_TS); }
372 T {SQL_NEW_KEYWORD(SQL_TOKEN_T); }
374 UCASE {SQL_NEW_KEYWORD(SQL_TOKEN_UCASE); }
375 UNBOUNDED {SQL_NEW_KEYWORD(SQL_TOKEN_UNBOUNDED); }
376 UNION {SQL_NEW_KEYWORD(SQL_TOKEN_UNION); }
377 UNIQUE {SQL_NEW_KEYWORD(SQL_TOKEN_UNIQUE); }
378 UNKNOWN {SQL_NEW_KEYWORD(SQL_TOKEN_UNKNOWN); }
379 UPDATE {SQL_NEW_KEYWORD(SQL_TOKEN_UPDATE); }
380 UPPER {SQL_NEW_KEYWORD(SQL_TOKEN_UPPER); }
381 USAGE {SQL_NEW_KEYWORD(SQL_TOKEN_USAGE); }
382 USER {SQL_NEW_KEYWORD(SQL_TOKEN_USER); }
383 USING {SQL_NEW_KEYWORD(SQL_TOKEN_USING); }
385 VARBINARY {SQL_NEW_KEYWORD(SQL_TOKEN_VARBINARY); }
386 VARCHAR {SQL_NEW_KEYWORD(SQL_TOKEN_VARCHAR); }
387 VARYING {SQL_NEW_KEYWORD(SQL_TOKEN_VARYING); }
388 VAR_POP {SQL_NEW_KEYWORD(SQL_TOKEN_VAR_POP); }
389 VAR_SAMP {SQL_NEW_KEYWORD(SQL_TOKEN_VAR_SAMP); }
390 VALUE {SQL_NEW_KEYWORD(SQL_TOKEN_VALUE); }
391 VALUES {SQL_NEW_KEYWORD(SQL_TOKEN_VALUES); }
392 VIEW {SQL_NEW_KEYWORD(SQL_TOKEN_VIEW); }
394 WEEK {SQL_NEW_KEYWORD(SQL_TOKEN_WEEK); }
395 WHEN {SQL_NEW_KEYWORD(SQL_TOKEN_WHEN); }
396 WHERE {SQL_NEW_KEYWORD(SQL_TOKEN_WHERE); }
397 WITH {SQL_NEW_KEYWORD(SQL_TOKEN_WITH); }
398 WITHIN {SQL_NEW_KEYWORD(SQL_TOKEN_WITHIN); }
399 WITHOUT {SQL_NEW_KEYWORD(SQL_TOKEN_WITHOUT); }
400 WORK {SQL_NEW_KEYWORD(SQL_TOKEN_WORK); }
402 YEAR {SQL_NEW_KEYWORD(SQL_TOKEN_YEAR); }
404 ZONE {SQL_NEW_KEYWORD(SQL_TOKEN_ZONE); }
406 "<" { SQL_NEW_NODE(::rtl::OUString(SQLyytext,strlen(SQLyytext),RTL_TEXTENCODING_UTF8), SQL_NODE_LESS);return SQL_LESS;}
407 ">" { SQL_NEW_NODE(::rtl::OUString(SQLyytext,strlen(SQLyytext),RTL_TEXTENCODING_UTF8), SQL_NODE_GREAT);return SQL_GREAT;}
408 "=" { SQL_NEW_NODE(::rtl::OUString(SQLyytext,strlen(SQLyytext),RTL_TEXTENCODING_UTF8), SQL_NODE_EQUAL);return SQL_EQUAL;}
409 "<=" { SQL_NEW_NODE(::rtl::OUString(SQLyytext,strlen(SQLyytext),RTL_TEXTENCODING_UTF8), SQL_NODE_LESSEQ);return SQL_LESSEQ;}
410 ">=" { SQL_NEW_NODE(::rtl::OUString(SQLyytext,strlen(SQLyytext),RTL_TEXTENCODING_UTF8), SQL_NODE_GREATEQ);return SQL_GREATEQ;}
411 "<>" { SQL_NEW_NODE(::rtl::OUString(SQLyytext,strlen(SQLyytext),RTL_TEXTENCODING_UTF8), SQL_NODE_NOTEQUAL);return SQL_NOTEQUAL;}
412 "!=" { SQL_NEW_NODE(::rtl::OUString(SQLyytext,strlen(SQLyytext),RTL_TEXTENCODING_UTF8), SQL_NODE_NOTEQUAL);return SQL_NOTEQUAL;}
413 "||" { SQL_NEW_NODE(::rtl::OUString(SQLyytext,strlen(SQLyytext),RTL_TEXTENCODING_UTF8), SQL_NODE_CONCAT);return SQL_CONCAT;}
416 [-+*/:(),.;?{}] { return SQLyytext[0]; }
419 <SQL>[A-Za-z\200-\277\300-\337\340-\357\360-\367\370-\373\374-\375][A-Za-z\200-\277\300-\337\340-\357\360-\367\370-\373\374-\375_0-9]* {return gatherName( SQLyytext);}
421 <SQL>([0-9]+) {SQL_NEW_INTNUM; }
424 <SQL>([0-9]+"."[0-9]*) |
425 <SQL>[0-9]+[eE][+-]?[0-9]+ |
426 <SQL>[0-9]+"."[0-9]*[eE][+-]?[0-9]+ |
427 <SQL>"."[0-9]*[eE][+-]?[0-9]+ {SQL_NEW_APPROXNUM; }
429 <PREDICATE_GER,PREDICATE_ENG,DATE>[A-Za-z\200-\277\300-\337\340-\357\360-\367\370-\373\374-\375][A-Za-z0-9_%.,*?\200-\277\300-\337\340-\357\360-\367\370-\373\374-\375]* {return gatherNamePre(SQLyytext);}
431 <PREDICATE_GER,PREDICATE_ENG>([0-9]+) {SQL_NEW_INTNUM; }
432 <PREDICATE_ENG>([0-9]{1,3}(","[0-9]{3})+) {SQL_NEW_INTNUM; }
433 <PREDICATE_GER>([0-9]{1,3}("."[0-9]{3})+) {SQL_NEW_INTNUM; }
435 <PREDICATE_ENG>([0-9]+"."[0-9]+) |
436 <PREDICATE_ENG>([0-9]{1,3}(","[0-9]{3})+"."[0-9]+) |
437 <PREDICATE_ENG>("."[0-9]+) {SQL_NEW_APPROXNUM; }
438 <PREDICATE_ENG>[0-9]+[eE][+-]?[0-9]+ |
439 <PREDICATE_ENG>[0-9]+"."[0-9]*[eE][+-]?[0-9]+ |
440 <PREDICATE_ENG>"."[0-9]*[eE][+-]?[0-9]+ {SQL_NEW_APPROXNUM; }
442 <PREDICATE_GER>([0-9]+","[0-9]+) |
443 <PREDICATE_GER>([0-9]{1,3}("."[0-9]{3})+","[0-9]+) |
444 <PREDICATE_GER>(","[0-9]+) {SQL_NEW_APPROXNUM; }
445 <PREDICATE_GER>[0-9]+[eE][+-]?[0-9]+ |
446 <PREDICATE_GER>[0-9]+","[0-9]*[eE][+-]?[0-9]+ |
447 <PREDICATE_GER>","[0-9]*[eE][+-]?[0-9]+ {SQL_NEW_APPROXNUM; }
449 <PREDICATE_GER,PREDICATE_ENG>[0-9.,][A-Za-z0-9_.,%]* {return gatherNamePre(SQLyytext);}
451 <SQL>\" { return gatherString('\"',0); }
452 <SQL>` { return gatherString('`' ,0); }
454 <PREDICATE_GER,PREDICATE_ENG,DATE,SQL>"[" { return gatherString(']' ,0);}
456 \' { return gatherString('\'',1); }
458 <PREDICATE_GER,PREDICATE_ENG,DATE># { return gatherString('#' ,2); }
460 <DATE>[0-9]{1,4}[^ ]*[0-9] |
461 <DATE>[0-9]{1,4}[^ ]*[0-9][ ][0-9]{1,4}[^ ]*[0-9] { SQL_NEW_DATE; }
463 <STRING>["-""+""*""/"":""("")"",""."";""?""{""}"] { return SQLyytext[0]; } /* */
464 <STRING>"[" { return gatherString(']' ,0); }
465 <STRING>[^ ':["?"]* { return gatherNamePre(SQLyytext); }
473 . {YY_FATAL_ERROR("Invalid symbol"); return SQL_TOKEN_INVALIDSYMBOL;}
477 // Kludge around a bug (well, Posix incompatibility) in flex 2.5.x
478 // http://bugs.debian.org/cgi-bin/bugreport.cgi?archive=no&bug=189332
479 #if YY_FLEX_MAJOR_VERSION >= 2 && YY_FLEX_MINOR_VERSION >= 5
481 #ifndef YY_FLUSH_BUFFER
482 #define YY_FLUSH_BUFFER SQLyy_flush_buffer(YY_CURRENT_BUFFER )
486 #define yytext_ptr SQLyytext
491 // Versions of flex apparently differ in whether input() resp. yyinput() returns
492 // zero or EOF upon end of file:
493 inline bool checkeof(int c) { return c == 0 || c == EOF; }
496 * Read SQL string literal
498 * '' 'a string' 'quote '' within string'
499 * "" "a string" "quote "" within string"
500 * nTyp == 0 -> SQL_NODE_NAME
501 * nTyp == 1 -> SQL_NODE_STRING
502 * nTyp == 2 -> SQL_NODE_ACCESS_DATE
504 sal_Int32 gatherString(int delim, sal_Int32 nTyp)
507 ::rtl::OStringBuffer sBuffer(256);
509 while (!checkeof(ch = yyinput()))
513 if ((ch = yyinput()) != delim)
521 SQL_NEW_NODE(::rtl::OStringToOUString(sBuffer.makeStringAndClear(),RTL_TEXTENCODING_UTF8), SQL_NODE_NAME);
522 return SQL_TOKEN_NAME;
524 SQL_NEW_NODE(::rtl::OStringToOUString(sBuffer.makeStringAndClear(),RTL_TEXTENCODING_UTF8), SQL_NODE_STRING);
525 return SQL_TOKEN_STRING;
527 SQL_NEW_NODE(::rtl::OStringToOUString(sBuffer.makeStringAndClear(),RTL_TEXTENCODING_UTF8), SQL_NODE_ACCESS_DATE);
528 return SQL_TOKEN_ACCESS_DATE;
533 sBuffer.append(static_cast<sal_Char>(ch));
537 else if (nTyp != 1 && (ch == '\r' || ch == '\n') )
541 sBuffer.append(static_cast<sal_Char>(ch));
544 YY_FATAL_ERROR("Unterminated name string");
545 return SQL_TOKEN_INVALIDSYMBOL;
548 sal_Int32 mapEnumToToken(IParseContext::InternationalKeyCode _eKeyCode )
550 sal_Int32 nTokenID = 0;
553 case IParseContext::KEY_LIKE: nTokenID = SQL_TOKEN_LIKE; break;
554 case IParseContext::KEY_NOT: nTokenID = SQL_TOKEN_NOT; break;
555 case IParseContext::KEY_NULL: nTokenID = SQL_TOKEN_NULL; break;
556 case IParseContext::KEY_TRUE: nTokenID = SQL_TOKEN_TRUE; break;
557 case IParseContext::KEY_FALSE: nTokenID = SQL_TOKEN_FALSE; break;
558 case IParseContext::KEY_IS: nTokenID = SQL_TOKEN_IS; break;
559 case IParseContext::KEY_BETWEEN: nTokenID = SQL_TOKEN_BETWEEN; break;
560 case IParseContext::KEY_OR: nTokenID = SQL_TOKEN_OR; break;
561 case IParseContext::KEY_AND: nTokenID = SQL_TOKEN_AND; break;
562 case IParseContext::KEY_AVG: nTokenID = SQL_TOKEN_AVG; break;
563 case IParseContext::KEY_COUNT: nTokenID = SQL_TOKEN_COUNT; break;
564 case IParseContext::KEY_MAX: nTokenID = SQL_TOKEN_MAX; break;
565 case IParseContext::KEY_MIN: nTokenID = SQL_TOKEN_MIN; break;
566 case IParseContext::KEY_SUM: nTokenID = SQL_TOKEN_SUM; break;
567 case IParseContext::KEY_EVERY: nTokenID = SQL_TOKEN_EVERY; break;
568 case IParseContext::KEY_ANY: nTokenID = SQL_TOKEN_ANY; break;
569 case IParseContext::KEY_SOME: nTokenID = SQL_TOKEN_SOME; break;
570 case IParseContext::KEY_STDDEV_POP: nTokenID = SQL_TOKEN_STDDEV_POP; break;
571 case IParseContext::KEY_STDDEV_SAMP: nTokenID = SQL_TOKEN_STDDEV_SAMP; break;
572 case IParseContext::KEY_VAR_SAMP: nTokenID = SQL_TOKEN_VAR_SAMP; break;
573 case IParseContext::KEY_VAR_POP: nTokenID = SQL_TOKEN_VAR_POP; break;
574 case IParseContext::KEY_COLLECT: nTokenID = SQL_TOKEN_COLLECT; break;
575 case IParseContext::KEY_FUSION: nTokenID = SQL_TOKEN_FUSION; break;
576 case IParseContext::KEY_INTERSECTION: nTokenID = SQL_TOKEN_INTERSECTION; break;
578 OSL_FAIL( "mapEnumToToken: unsupported key!" );
583 * Read SQL Name literal
584 * Valid Names or international keywords:
585 * As we have international keywords, we test first on them
587 sal_Int32 gatherName(const sal_Char* text)
590 OSL_ENSURE(xxx_pGLOBAL_SQLSCAN,"You forgot to set the scanner!");
591 IParseContext::InternationalKeyCode eKeyCode = xxx_pGLOBAL_SQLSCAN->getInternationalTokenID(text);
594 case IParseContext::KEY_LIKE:
595 case IParseContext::KEY_NOT:
596 case IParseContext::KEY_NULL:
597 case IParseContext::KEY_TRUE:
598 case IParseContext::KEY_FALSE:
599 case IParseContext::KEY_IS:
600 case IParseContext::KEY_BETWEEN:
601 case IParseContext::KEY_OR:
602 case IParseContext::KEY_AND:
603 case IParseContext::KEY_COUNT:
604 case IParseContext::KEY_AVG:
605 case IParseContext::KEY_MAX:
606 case IParseContext::KEY_MIN:
607 case IParseContext::KEY_SUM:
608 case IParseContext::KEY_EVERY:
609 case IParseContext::KEY_ANY:
610 case IParseContext::KEY_SOME:
611 case IParseContext::KEY_STDDEV_POP:
612 case IParseContext::KEY_STDDEV_SAMP:
613 case IParseContext::KEY_VAR_SAMP:
614 case IParseContext::KEY_VAR_POP:
615 case IParseContext::KEY_COLLECT:
616 case IParseContext::KEY_FUSION:
617 case IParseContext::KEY_INTERSECTION:
618 nToken = mapEnumToToken(eKeyCode);
619 SQL_NEW_KEYWORD(nToken);
622 SQL_NEW_NODE(::rtl::OUString(text,strlen(text),RTL_TEXTENCODING_UTF8), SQL_NODE_NAME);
623 return SQL_TOKEN_NAME;
627 Read SQL Name literal for predicate check
628 Valid Names or internatioanl keywords:
629 As we have international keywords, we test first on them
631 sal_Int32 gatherNamePre(const sal_Char* text)
634 OSL_ENSURE(xxx_pGLOBAL_SQLSCAN,"You forgot to set the scanner!");
635 IParseContext::InternationalKeyCode eKeyCode = xxx_pGLOBAL_SQLSCAN->getInternationalTokenID(text);
638 case IParseContext::KEY_LIKE:
639 case IParseContext::KEY_NOT:
640 case IParseContext::KEY_NULL:
641 case IParseContext::KEY_TRUE:
642 case IParseContext::KEY_FALSE:
643 case IParseContext::KEY_IS:
644 case IParseContext::KEY_BETWEEN:
645 case IParseContext::KEY_OR:
646 case IParseContext::KEY_AND:
647 case IParseContext::KEY_COUNT:
648 case IParseContext::KEY_AVG:
649 case IParseContext::KEY_MAX:
650 case IParseContext::KEY_MIN:
651 case IParseContext::KEY_SUM:
652 case IParseContext::KEY_EVERY:
653 case IParseContext::KEY_ANY:
654 case IParseContext::KEY_SOME:
655 case IParseContext::KEY_STDDEV_POP:
656 case IParseContext::KEY_STDDEV_SAMP:
657 case IParseContext::KEY_VAR_SAMP:
658 case IParseContext::KEY_VAR_POP:
659 case IParseContext::KEY_COLLECT:
660 case IParseContext::KEY_FUSION:
661 case IParseContext::KEY_INTERSECTION:
662 nToken = mapEnumToToken(eKeyCode);
663 SQL_NEW_KEYWORD(nToken);
666 // we need a special handling for parameter
668 ::rtl::OString sStmt = xxx_pGLOBAL_SQLSCAN->getStatement();
669 sal_Int32 nLength = strlen(text);
670 sal_Int32 nPos = xxx_pGLOBAL_SQLSCAN->GetCurrentPos() - nLength - 2;
671 if (sStmt.getStr()[nPos] == ':')
673 SQL_NEW_NODE(::rtl::OUString(text,nLength,RTL_TEXTENCODING_UTF8), SQL_NODE_NAME);
674 nToken = SQL_TOKEN_NAME;
678 SQL_NEW_NODE(::rtl::OUString(text,nLength,RTL_TEXTENCODING_UTF8), SQL_NODE_STRING);
679 nToken = SQL_TOKEN_STRING;
686 using namespace connectivity;
688 static bool IN_SQLyyerror;
689 //------------------------------------------------------------------------------
690 OSQLScanner::OSQLScanner()
693 , m_bInternational(sal_False)
694 , m_nRule(0) // 0 is INITIAL
696 IN_SQLyyerror = false;
699 //------------------------------------------------------------------------------
700 OSQLScanner::~OSQLScanner()
703 //------------------------------------------------------------------------------
704 void OSQLScanner::SQLyyerror(char const *fmt)
709 IN_SQLyyerror = true;
711 OSL_ENSURE(m_pContext, "OSQLScanner::SQLyyerror: No Context set");
712 m_sErrorMessage = ::rtl::OUString(fmt,strlen(fmt),RTL_TEXTENCODING_UTF8);
713 if (m_nCurrentPos < m_sStatement.getLength())
715 m_sErrorMessage += ::rtl::OUString(": ");
717 ::rtl::OUString aError;
718 static sal_Int32 BUFFERSIZE = 256;
719 static sal_Char* Buffer = 0;
721 Buffer = new sal_Char[BUFFERSIZE];
723 sal_Char *s = Buffer;
725 int ch = SQLyytext ? (SQLyytext[0] == 0 ? ' ' : SQLyytext[0]): ' ';
727 while (!checkeof(ch = yyinput()))
731 if ((ch = yyinput()) != ' ')
737 aError = ::rtl::OUString(Buffer,nPos,RTL_TEXTENCODING_UTF8);
743 if (++nPos == BUFFERSIZE)
745 ::rtl::OString aBuf(Buffer);
748 Buffer = new sal_Char[BUFFERSIZE];
749 for(sal_Int32 i=0;i<aBuf.getLength();++i,++Buffer)
750 *Buffer = aBuf.getStr()[i];
755 m_sErrorMessage += aError;
759 IN_SQLyyerror = false;
763 //------------------------------------------------------------------------------
764 void OSQLScanner::prepareScan(const ::rtl::OUString & rNewStatement, const IParseContext* pContext, bool bInternational)
769 m_sErrorMessage = ::rtl::OUString();
770 m_sStatement = ::rtl::OUStringToOString(rNewStatement, RTL_TEXTENCODING_UTF8);
772 m_bInternational = bInternational;
773 m_pContext = pContext;
776 //------------------------------------------------------------------------------
777 sal_Int32 OSQLScanner::SQLyygetc(void)
779 sal_Int32 nPos = (m_nCurrentPos >= m_sStatement.getLength()) ? EOF : m_sStatement.getStr()[m_nCurrentPos];
784 //------------------------------------------------------------------------------
785 IParseContext::InternationalKeyCode OSQLScanner::getInternationalTokenID(const sal_Char* sToken) const
787 OSL_ENSURE(m_pContext, "OSQLScanner::getInternationalTokenID: No Context set");
788 return (m_bInternational) ? m_pContext->getIntlKeyCode(::rtl::OString(sToken) ) : IParseContext::KEY_NONE;
790 // -------------------------------------------------------------------------
791 sal_Int32 OSQLScanner::GetGERRule() const { return PREDICATE_GER; }
792 sal_Int32 OSQLScanner::GetENGRule() const { return PREDICATE_ENG; }
793 sal_Int32 OSQLScanner::GetSQLRule() const { return SQL; }
794 sal_Int32 OSQLScanner::GetDATERule() const { return DATE; }
795 sal_Int32 OSQLScanner::GetSTRINGRule() const { return STRING; }
796 // -------------------------------------------------------------------------
797 void OSQLScanner::setScanner(bool _bNull)
799 xxx_pGLOBAL_SQLSCAN = _bNull ? NULL : this;
801 // -------------------------------------------------------------------------
802 sal_Int32 OSQLScanner::SQLlex()