merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / parse / sqlbison.y
blob97875dfd4de0ab8f560ebad72cf419d4b1563378
1 %{
2 //--------------------------------------------------------------------------
3 //
4 // DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 //
6 // Copyright 2008 by Sun Microsystems, Inc.
7 //
8 // OpenOffice.org - a multi-platform office productivity suite
9 //
10 // $RCSfile: sqlbison.y,v $
12 // $Revision: 1.66.6.5 $
14 // This file is part of OpenOffice.org.
16 // OpenOffice.org is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU Lesser General Public License version 3
18 // only, as published by the Free Software Foundation.
20 // OpenOffice.org is distributed in the hope that it will be useful,
21 // but WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 // GNU Lesser General Public License version 3 for more details
24 // (a copy is included in the LICENSE file that accompanied this code).
26 // You should have received a copy of the GNU Lesser General Public License
27 // version 3 along with OpenOffice.org. If not, see
28 // <http://www.openoffice.org/license.html>
29 // for a copy of the LGPLv3 License.
31 //--------------------------------------------------------------------------
33 #include <vector>
34 #include <string.h>
36 #ifndef _CONNECTIVITY_SQLNODE_HXX
37 #include <connectivity/sqlnode.hxx>
38 #endif
39 #ifndef _CONNECTIVITY_SQLPARSE_HXX
40 #include <connectivity/sqlparse.hxx>
41 #endif
42 #ifndef _CONNECTIVITY_SQLINTERNALNODE_HXX
43 #include <internalnode.hxx>
44 #endif
45 #ifndef _COM_SUN_STAR_LANG_LOCALE_HPP_
46 #include <com/sun/star/lang/Locale.hpp>
47 #endif
48 #ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_
49 #include <com/sun/star/sdbc/DataType.hpp>
50 #endif
51 #ifndef _COM_SUN_STAR_UTIL_DATE_HPP_
52 #include <com/sun/star/util/Date.hpp>
53 #endif
54 #ifndef _COM_SUN_STAR_UTIL_DATETIME_HPP_
55 #include <com/sun/star/util/DateTime.hpp>
56 #endif
57 #ifndef _COM_SUN_STAR_UTIL_TIME_HPP_
58 #include <com/sun/star/util/Time.hpp>
59 #endif
60 #ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATTER_HPP_
61 #include <com/sun/star/util/XNumberFormatter.hpp>
62 #endif
63 #ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATSSUPPLIER_HPP_
64 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
65 #endif
66 #ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATS_HPP_
67 #include <com/sun/star/util/XNumberFormats.hpp>
68 #endif
69 #ifndef _COM_SUN_STAR_UTIL_NUMBERFORMAT_HPP_
70 #include <com/sun/star/util/NumberFormat.hpp>
71 #endif
72 #ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATTYPES_HPP_
73 #include <com/sun/star/util/XNumberFormatTypes.hpp>
74 #endif
75 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
76 #include <com/sun/star/beans/XPropertySet.hpp>
77 #endif
78 #ifndef _COM_SUN_STAR_I18N_KPARSETYPE_HPP_
79 #include <com/sun/star/i18n/KParseType.hpp>
80 #endif
81 #ifndef _COM_SUN_STAR_I18N_KPARSETOKENS_HPP_
82 #include <com/sun/star/i18n/KParseTokens.hpp>
83 #endif
84 #ifndef _CONNECTIVITY_SQLSCAN_HXX
85 #include "sqlscan.hxx"
86 #endif
87 #ifndef _OSL_DIAGNOSE_H_
88 #include <osl/diagnose.h>
89 #endif
90 #ifndef _DBHELPER_DBCONVERSION_HXX_
91 #include "connectivity/dbconversion.hxx"
92 #endif
93 #include <rtl/ustrbuf.hxx>
95 #if defined __GNUC__
96 #pragma GCC system_header
97 #elif defined __SUNPRO_CC
98 #pragma disable_warn
99 #elif defined _MSC_VER
100 #pragma warning(push, 1)
101 #pragma warning(disable:4273 4701 4706)
102 #endif
104 static ::rtl::OUString aEmptyString;
106 static connectivity::OSQLInternalNode* newNode(const sal_Char* pNewValue,
107 const connectivity::SQLNodeType eNodeType,
108 const sal_uInt32 nNodeID = 0)
110 OSL_TRACE("connectivity: Rule Number: %d,%d",eNodeType,nNodeID);
111 return new connectivity::OSQLInternalNode(pNewValue, eNodeType, nNodeID);
114 static connectivity::OSQLInternalNode* newNode(const ::rtl::OString& _NewValue,
115 const connectivity::SQLNodeType eNodeType,
116 const sal_uInt32 nNodeID = 0)
118 OSL_TRACE("connectivity: Rule Number: %d,%d",eNodeType,nNodeID);
119 return new connectivity::OSQLInternalNode(_NewValue, eNodeType, nNodeID);
122 static connectivity::OSQLInternalNode* newNode(const ::rtl::OUString& _NewValue,
123 const connectivity::SQLNodeType eNodeType,
124 const sal_uInt32 nNodeID = 0)
126 OSL_TRACE("connectivity: Rule Number: %d,%d",eNodeType,nNodeID);
127 return new connectivity::OSQLInternalNode(_NewValue, eNodeType, nNodeID);
131 // yyi ist die interne Nr. der Regel, die gerade reduziert wird.
132 // Ueber die Mapping-Tabelle yyrmap wird daraus eine externe Regel-Nr.
133 #define SQL_NEW_RULE newNode(aEmptyString, SQL_NODE_RULE, yyr1[yyn])
134 #define SQL_NEW_LISTRULE newNode(aEmptyString, SQL_NODE_LISTRULE, yyr1[yyn])
135 #define SQL_NEW_COMMALISTRULE newNode(aEmptyString, SQL_NODE_COMMALISTRULE, yyr1[yyn])
138 connectivity::OSQLParser* xxx_pGLOBAL_SQLPARSER;
140 #define YYERROR_VERBOSE
142 #define SQLyyerror(s) \
144 xxx_pGLOBAL_SQLPARSER->error(s); \
147 using namespace connectivity;
148 #define SQLyylex xxx_pGLOBAL_SQLPARSER->SQLlex
150 /* symbolic tokens */
152 %union {
153 connectivity::OSQLParseNode * pParseNode;
155 %type <pParseNode> '(' ')' ',' ':' ';' '?' '[' ']' '{' '}' '.'
157 %token <pParseNode> SQL_TOKEN_STRING SQL_TOKEN_ACCESS_DATE SQL_TOKEN_INT SQL_TOKEN_REAL_NUM
158 %token <pParseNode> SQL_TOKEN_INTNUM SQL_TOKEN_APPROXNUM SQL_TOKEN_NOT SQL_TOKEN_NAME
161 %nonassoc <pParseNode> SQL_TOKEN_UMINUS
165 /* literal keyword tokens */
167 %token <pParseNode> SQL_TOKEN_ALL SQL_TOKEN_ALTER SQL_TOKEN_AMMSC SQL_TOKEN_ANY SQL_TOKEN_AS SQL_TOKEN_ASC SQL_TOKEN_AT SQL_TOKEN_AUTHORIZATION SQL_TOKEN_AVG
169 %token <pParseNode> SQL_TOKEN_BETWEEN SQL_TOKEN_BIT SQL_TOKEN_BOTH SQL_TOKEN_BY
171 %token <pParseNode> SQL_TOKEN_CAST SQL_TOKEN_CHARACTER SQL_TOKEN_CHECK SQL_TOKEN_COLLATE SQL_TOKEN_COMMIT SQL_TOKEN_CONTINUE SQL_TOKEN_CONVERT SQL_TOKEN_COUNT SQL_TOKEN_CREATE SQL_TOKEN_CROSS
172 %token <pParseNode> SQL_TOKEN_CURRENT SQL_TOKEN_CURSOR
174 %token <pParseNode> SQL_TOKEN_DATE SQL_TOKEN_DATEVALUE SQL_TOKEN_DAY SQL_TOKEN_DEC SQL_TOKEN_DECIMAL SQL_TOKEN_DECLARE SQL_TOKEN_DEFAULT SQL_TOKEN_DELETE SQL_TOKEN_DESC
175 %token <pParseNode> SQL_TOKEN_DISTINCT SQL_TOKEN_DOUBLE SQL_TOKEN_DROP
177 %token <pParseNode> SQL_TOKEN_ESCAPE SQL_TOKEN_EXCEPT SQL_TOKEN_EXISTS SQL_TOKEN_FALSE SQL_TOKEN_FETCH SQL_TOKEN_FLOAT SQL_TOKEN_FOR SQL_TOKEN_FOREIGN SQL_TOKEN_FOUND SQL_TOKEN_FROM SQL_TOKEN_FULL
179 %token <pParseNode> SQL_TOKEN_GRANT SQL_TOKEN_GROUP SQL_TOKEN_HAVING SQL_TOKEN_IN SQL_TOKEN_INDICATOR SQL_TOKEN_INNER SQL_TOKEN_INTEGER SQL_TOKEN_INTO SQL_TOKEN_IS SQL_TOKEN_INTERSECT
181 %token <pParseNode> SQL_TOKEN_JOIN SQL_TOKEN_KEY SQL_TOKEN_LEADING SQL_TOKEN_LIKE SQL_TOKEN_LOCAL SQL_TOKEN_LOWER
182 %token <pParseNode> SQL_TOKEN_MAX SQL_TOKEN_MIN SQL_TOKEN_NATURAL SQL_TOKEN_NCHAR SQL_TOKEN_NULL SQL_TOKEN_NUMERIC
184 %token <pParseNode> SQL_TOKEN_OCTET_LENGTH SQL_TOKEN_OF SQL_TOKEN_ON SQL_TOKEN_OPTION SQL_TOKEN_ORDER SQL_TOKEN_OUTER
186 %token <pParseNode> SQL_TOKEN_PRECISION SQL_TOKEN_PRIMARY SQL_TOKEN_PRIVILEGES SQL_TOKEN_PROCEDURE SQL_TOKEN_PUBLIC
187 %token <pParseNode> SQL_TOKEN_REAL SQL_TOKEN_REFERENCES SQL_TOKEN_ROLLBACK
189 %token <pParseNode> SQL_TOKEN_SCHEMA SQL_TOKEN_SELECT SQL_TOKEN_SET SQL_TOKEN_SIZE SQL_TOKEN_SMALLINT SQL_TOKEN_SOME SQL_TOKEN_SQLCODE SQL_TOKEN_SQLERROR SQL_TOKEN_SUM
191 %token <pParseNode> SQL_TOKEN_TABLE SQL_TOKEN_TIME SQL_TOKEN_TIMESTAMP SQL_TOKEN_TIMEZONE_HOUR SQL_TOKEN_TIMEZONE_MINUTE SQL_TOKEN_TO SQL_TOKEN_TRAILING SQL_TOKEN_TRANSLATE SQL_TOKEN_TRIM SQL_TOKEN_TRUE SQL_TOKEN_UNION
192 %token <pParseNode> SQL_TOKEN_UNIQUE SQL_TOKEN_UNKNOWN SQL_TOKEN_UPDATE SQL_TOKEN_UPPER SQL_TOKEN_USAGE SQL_TOKEN_USER SQL_TOKEN_USING SQL_TOKEN_VALUES SQL_TOKEN_VIEW
193 %token <pParseNode> SQL_TOKEN_WHERE SQL_TOKEN_WITH SQL_TOKEN_WORK SQL_TOKEN_ZONE
195 /* ODBC KEYWORDS */
196 %token <pParseNode> SQL_TOKEN_CALL SQL_TOKEN_D SQL_TOKEN_FN SQL_TOKEN_T SQL_TOKEN_TS SQL_TOKEN_OJ
197 /* string functions */
198 %token <pParseNode> SQL_TOKEN_ASCII SQL_TOKEN_BIT_LENGTH SQL_TOKEN_CHAR SQL_TOKEN_CHAR_LENGTH SQL_TOKEN_CHARACTER_LENGTH
199 %token <pParseNode> SQL_TOKEN_CONCAT
200 %token <pParseNode> SQL_TOKEN_DIFFERENCE SQL_TOKEN_INSERT SQL_TOKEN_LCASE SQL_TOKEN_LEFT SQL_TOKEN_LENGTH SQL_TOKEN_LOCATE
201 %token <pParseNode> SQL_TOKEN_LOCATE_2 SQL_TOKEN_LTRIM SQL_TOKEN_POSITION SQL_TOKEN_REPEAT SQL_TOKEN_REPLACE
202 %token <pParseNode> SQL_TOKEN_RIGHT SQL_TOKEN_RTRIM SQL_TOKEN_SOUNDEX SQL_TOKEN_SPACE SQL_TOKEN_SUBSTRING SQL_TOKEN_UCASE
204 /* time and date functions */
205 %token <pParseNode> SQL_TOKEN_CURRENT_DATE SQL_TOKEN_CURRENT_TIME SQL_TOKEN_CURRENT_TIMESTAMP SQL_TOKEN_CURDATE SQL_TOKEN_CURTIME
206 %token <pParseNode> SQL_TOKEN_DAYNAME SQL_TOKEN_DAYOFMONTH SQL_TOKEN_DAYOFWEEK SQL_TOKEN_DAYOFYEAR SQL_TOKEN_EXTRACT
207 %token <pParseNode> SQL_TOKEN_HOUR SQL_TOKEN_MINUTE SQL_TOKEN_MONTH SQL_TOKEN_MONTHNAME SQL_TOKEN_NOW SQL_TOKEN_QUARTER SQL_TOKEN_DATEDIFF
208 %token <pParseNode> SQL_TOKEN_SECOND SQL_TOKEN_TIMESTAMPADD SQL_TOKEN_TIMESTAMPDIFF SQL_TOKEN_TIMEVALUE SQL_TOKEN_WEEK SQL_TOKEN_YEAR
210 /* numeric functions */
211 %token <pParseNode> SQL_TOKEN_ABS SQL_TOKEN_ACOS SQL_TOKEN_ASIN SQL_TOKEN_ATAN SQL_TOKEN_ATAN2 SQL_TOKEN_CEILING
212 %token <pParseNode> SQL_TOKEN_COS SQL_TOKEN_COT SQL_TOKEN_DEGREES SQL_TOKEN_EXP SQL_TOKEN_FLOOR SQL_TOKEN_LOGF SQL_TOKEN_LOG SQL_TOKEN_LN
213 %token <pParseNode> SQL_TOKEN_LOG10 SQL_TOKEN_MOD SQL_TOKEN_PI SQL_TOKEN_POWER SQL_TOKEN_RADIANS SQL_TOKEN_RAND SQL_TOKEN_ROUNDMAGIC
214 %token <pParseNode> SQL_TOKEN_ROUND SQL_TOKEN_SIGN SQL_TOKEN_SIN SQL_TOKEN_SQRT SQL_TOKEN_TAN SQL_TOKEN_TRUNCATE
216 // computational operation
217 %token <pParseNode> SQL_TOKEN_EVERY SQL_TOKEN_INTERSECTION SQL_TOKEN_FUSION SQL_TOKEN_COLLECT SQL_TOKEN_VAR_POP SQL_TOKEN_VAR_SAMP
218 %token <pParseNode> SQL_TOKEN_STDDEV_SAMP SQL_TOKEN_STDDEV_POP
220 /* operators */
221 %left SQL_TOKEN_NAME
222 %left <pParseNode> SQL_TOKEN_OR
223 %left <pParseNode> SQL_TOKEN_AND
225 %left <pParseNode> SQL_LESSEQ SQL_GREATEQ SQL_NOTEQUAL SQL_LESS SQL_GREAT SQL_EQUAL /* '<' '>' = <> < > <= >= != */
226 %left <pParseNode> '+' '-' SQL_CONCAT
227 %left <pParseNode> '*' '/'
228 %left SQL_TOKEN_NATURAL SQL_TOKEN_CROSS SQL_TOKEN_FULL SQL_TOKEN_LEFT SQL_TOKEN_RIGHT
229 %left ')'
230 %right '='
231 %right '.'
232 %right '('
235 %token <pParseNode> SQL_TOKEN_INVALIDSYMBOL
237 /*%type <pParseNode> sql_single_statement */
239 %type <pParseNode> sql /*schema */
240 %type <pParseNode> column_def_opt_list column_def_opt table_constraint_def column_commalist
241 %type <pParseNode> view_def opt_with_check_option opt_column_commalist privilege_def
242 %type <pParseNode> opt_with_grant_option privileges operation_commalist operation
243 %type <pParseNode> grantee_commalist grantee opt_order_by_clause ordering_spec_commalist
244 %type <pParseNode> ordering_spec opt_asc_desc manipulative_statement commit_statement
245 %type <pParseNode> /*delete_statement_positioned*/ delete_statement_searched fetch_statement
246 %type <pParseNode> insert_statement values_or_query_spec
247 %type <pParseNode> rollback_statement select_statement_into opt_all_distinct
248 %type <pParseNode> /*update_statement_positioned*/ assignment_commalist assignment
249 %type <pParseNode> update_statement_searched target_commalist target opt_where_clause
250 %type <pParseNode> select_statement selection table_exp from_clause table_ref_commalist table_ref
251 %type <pParseNode> where_clause opt_group_by_clause column_ref_commalist opt_having_clause
252 %type <pParseNode> search_condition predicate comparison_predicate between_predicate
253 %type <pParseNode> like_predicate opt_escape test_for_null in_predicate
254 %type <pParseNode> all_or_any_predicate any_all_some existence_test subquery
255 %type <pParseNode> scalar_exp_commalist parameter_ref literal
256 %type <pParseNode> column_ref data_type column cursor parameter range_variable user /*like_check*/
257 /* neue Regeln bei OJ */
258 %type <pParseNode> derived_column as_clause table_name num_primary term num_value_exp
259 %type <pParseNode> value_exp_primary num_value_fct unsigned_value_spec cast_spec set_fct_spec scalar_subquery
260 %type <pParseNode> position_exp extract_exp length_exp general_value_spec
261 %type <pParseNode> general_set_fct set_fct_type query_exp non_join_query_exp joined_table
262 %type <pParseNode> non_join_query_term non_join_query_primary simple_table
263 %type <pParseNode> table_value_const_list row_value_constructor row_value_const_list row_value_constructor_elem
264 %type <pParseNode> qualified_join value_exp query_term join_type outer_join_type join_condition boolean_term
265 %type <pParseNode> boolean_factor truth_value boolean_test boolean_primary named_columns_join join_spec
266 %type <pParseNode> cast_operand cast_target factor datetime_value_exp /*interval_value_exp*/ datetime_term datetime_factor
267 %type <pParseNode> datetime_primary datetime_value_fct time_zone time_zone_specifier /*interval_term*/ /*interval_qualifier*/
268 %type <pParseNode> /*start_field*/ non_second_datetime_field /*end_field*/ /*single_datetime_field*/ extract_field datetime_field time_zone_field
269 %type <pParseNode> extract_source char_length_exp octet_length_exp bit_length_exp select_sublist string_value_exp
270 %type <pParseNode> char_value_exp concatenation char_factor char_primary string_value_fct char_substring_fct fold
271 %type <pParseNode> form_conversion char_translation trim_fct trim_operands trim_spec bit_value_fct bit_substring_fct op_column_commalist
272 %type <pParseNode> /*bit_concatenation*/ bit_value_exp bit_factor bit_primary collate_clause char_value_fct unique_spec value_exp_commalist in_predicate_value unique_test update_source
273 %type <pParseNode> function_arg_commalist3 string_function_3Argument function_arg_commalist4 string_function_4Argument function_arg_commalist2 string_function_1Argument string_function_2Argument
274 %type <pParseNode> date_function_0Argument date_function_1Argument function_name12 function_name23 function_name1 function_name2 function_name3 function_name0 numeric_function_0Argument numeric_function_1Argument numeric_function_2Argument date_function_3Argument
275 %type <pParseNode> all query_primary sql_not for_length upper_lower comparison column_val cross_union /*opt_schema_element_list*/
276 %type <pParseNode> /*op_authorization op_schema*/ nil_fkt schema_element base_table_def base_table_element base_table_element_commalist
277 %type <pParseNode> column_def odbc_fct_spec odbc_call_spec odbc_fct_type op_parameter union_statement
278 %type <pParseNode> op_odbc_call_parameter odbc_parameter_commalist odbc_parameter function_args_commalist function_arg
279 %type <pParseNode> catalog_name schema_name table_node numeric_function string_function function_name date_function table_primary_as_range_column opt_as
282 /* Parse Tree an OSQLParser zurueckliefern
283 * (der Zugriff ueber yyval nach Aufruf des Parsers scheitert,
286 sql_single_statement:
288 { xxx_pGLOBAL_SQLPARSER->setParseTree( $1 ); }
289 | sql ';'
290 { xxx_pGLOBAL_SQLPARSER->setParseTree( $1 ); }
293 sql_list:
294 sql_ ';'
295 {$$ = SQL_NEW_LISTRULE;
296 $$->append($1);
297 pSqlParseTreeRoot = $1; -- obsolete - Ergebnis in yyval! rdm }
298 | sql_list sql ';'
299 {$1->append($2);
300 $$ = $1;}
305 /* schema definition language */
306 /* Note: other ``sql:sal_Unicode() rules appear later in the grammar */
307 /***
308 sql:
309 schema
312 op_authorization:
313 {$$ = SQL_NEW_RULE;}
314 | SQL_TOKEN_AUTHORIZATION user
316 $$ = SQL_NEW_RULE;
317 $$->append($1);
318 $$->append($2);
321 op_schema:
322 {$$ = SQL_NEW_RULE;}
323 | SQL_TOKEN_NAME
324 | SQL_TOKEN_NAME '.' SQL_TOKEN_NAME
326 $$ = SQL_NEW_RULE;
327 $$->append($1);
328 $$->append($2 = newNode(".", SQL_NODE_PUNCTUATION));
329 $$->append($3);
333 schema:
334 SQL_TOKEN_CREATE SQL_TOKEN_SCHEMA op_schema op_authorization opt_schema_element_list
336 $$ = SQL_NEW_RULE;
337 $$->append($1);
338 $$->append($2);
339 $$->append($3);
340 $$->append($4);
341 $$->append($5);
345 opt_schema_element_list:
346 /* empty * / {$$ = SQL_NEW_RULE;}
347 | schema_glement_list
350 schema_element_list:
351 schema_element
352 {$$ = SQL_NEW_LISTRULE;
353 $$->append($1);}
354 | schema_element_list schema_element
355 {$1->append($2);
356 $$ = $1;}
359 sql:
360 schema_element
361 {$$ = SQL_NEW_RULE;
362 $$->append($1);
366 schema_element:
367 base_table_def
368 | view_def
369 | privilege_def
372 base_table_def:
373 SQL_TOKEN_CREATE SQL_TOKEN_TABLE table_node '(' base_table_element_commalist ')'
374 {$$ = SQL_NEW_RULE;
375 $$->append($1);
376 $$->append($2);
377 $$->append($3);
378 $$->append($4 = newNode("(", SQL_NODE_PUNCTUATION));
379 $$->append($5);
380 $$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));}
383 base_table_element_commalist:
384 base_table_element
385 {$$ = SQL_NEW_COMMALISTRULE;
386 $$->append($1);}
387 | base_table_element_commalist ',' base_table_element
388 {$1->append($3);
389 $$ = $1;}
392 base_table_element:
393 column_def
394 | table_constraint_def
397 column_def:
398 column data_type column_def_opt_list
399 {$$ = SQL_NEW_RULE;
400 $$->append($1);
401 $$->append($2);
402 $$->append($3);
406 column_def_opt_list:
407 /* empty */ {$$ = SQL_NEW_LISTRULE;}
408 | column_def_opt_list column_def_opt
409 {$1->append($2);
410 $$ = $1;}
413 nil_fkt:
414 datetime_value_fct
416 unique_spec:
417 SQL_TOKEN_UNIQUE
418 | SQL_TOKEN_PRIMARY SQL_TOKEN_KEY
420 $$ = SQL_NEW_RULE;
421 $$->append($1);
422 $$->append($2);
425 column_def_opt:
426 SQL_TOKEN_NOT SQL_TOKEN_NULL
427 {$$ = SQL_NEW_RULE;
428 $$->append($1);
429 $$->append($2);}
430 | unique_spec
431 | SQL_TOKEN_DEFAULT literal
432 {$$ = SQL_NEW_RULE;
433 $$->append($1);
434 $$->append($2);}
435 | SQL_TOKEN_DEFAULT SQL_TOKEN_NULL
436 {$$ = SQL_NEW_RULE;
437 $$->append($1);
438 $$->append($2);}
439 | SQL_TOKEN_DEFAULT SQL_TOKEN_USER
440 {$$ = SQL_NEW_RULE;
441 $$->append($1);
442 $$->append($2);}
443 | SQL_TOKEN_DEFAULT nil_fkt
445 $$ = SQL_NEW_RULE;
446 $$->append($1);
447 $$->append($2);
449 | SQL_TOKEN_CHECK
450 | SQL_TOKEN_CHECK '(' search_condition ')'
451 {$$ = SQL_NEW_RULE;
452 $$->append($1);
453 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
454 $$->append($3);
455 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));}
456 | SQL_TOKEN_REFERENCES table_node
457 {$$ = SQL_NEW_RULE;
458 $$->append($1);
459 $$->append($2);}
460 | SQL_TOKEN_REFERENCES table_node '(' column_commalist ')'
461 {$$ = SQL_NEW_RULE;
462 $$->append($1);
463 $$->append($2);
464 $$->append($3 = newNode("(", SQL_NODE_PUNCTUATION));
465 $$->append($4);
466 $$->append($5 = newNode(")", SQL_NODE_PUNCTUATION));}
469 table_constraint_def:
470 unique_spec '(' column_commalist ')'
471 {$$ = SQL_NEW_RULE;
472 $$->append($1);
473 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
474 $$->append($3);
475 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));}
476 | SQL_TOKEN_FOREIGN SQL_TOKEN_KEY '(' column_commalist ')' SQL_TOKEN_REFERENCES table_node
477 {$$ = SQL_NEW_RULE;
478 $$->append($1);
479 $$->append($2);
480 $$->append($3 = newNode("(", SQL_NODE_PUNCTUATION));
481 $$->append($4);
482 $$->append($5 = newNode(")", SQL_NODE_PUNCTUATION));
483 $$->append($6);
484 $$->append($7);}
485 | SQL_TOKEN_FOREIGN SQL_TOKEN_KEY '(' column_commalist ')' SQL_TOKEN_REFERENCES table_node '(' column_commalist ')'
486 {$$ = SQL_NEW_RULE;
487 $$->append($1);
488 $$->append($2);
489 $$->append($3 = newNode("(", SQL_NODE_PUNCTUATION));
490 $$->append($4);
491 $$->append($5 = newNode(")", SQL_NODE_PUNCTUATION));
492 $$->append($6);
493 $$->append($7);
494 $$->append($8 = newNode("(", SQL_NODE_PUNCTUATION));
495 $$->append($9);
496 $$->append($10 = newNode(")", SQL_NODE_PUNCTUATION));}
497 | SQL_TOKEN_CHECK '(' search_condition ')'
498 {$$ = SQL_NEW_RULE;
499 $$->append($1);
500 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
501 $$->append($3);
502 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));}
504 op_column_commalist:
505 /* empty */ {$$ = SQL_NEW_RULE;}
506 | '(' column_commalist ')'
507 {$$ = SQL_NEW_RULE;
508 $$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
509 $$->append($2);
510 $$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
513 column_commalist:
514 column_commalist ',' column
515 {$1->append($3);
516 $$ = $1;}
517 | column
518 {$$ = SQL_NEW_COMMALISTRULE;
519 $$->append($1);}
522 view_def:
523 SQL_TOKEN_CREATE SQL_TOKEN_VIEW table_node opt_column_commalist SQL_TOKEN_AS select_statement opt_with_check_option
524 {$$ = SQL_NEW_RULE;
525 $$->append($1);
526 $$->append($2);
527 $$->append($3);
528 $$->append($4);
529 $$->append($5);
530 $$->append($6);
531 $$->append($7);}
534 opt_with_check_option:
535 /* empty */ {$$ = SQL_NEW_RULE;}
536 | SQL_TOKEN_WITH SQL_TOKEN_CHECK SQL_TOKEN_OPTION
537 {$$ = SQL_NEW_RULE;
538 $$->append($1);
539 $$->append($2);
540 $$->append($3);}
543 opt_column_commalist:
544 /* empty */ {$$ = SQL_NEW_RULE;}
545 | '(' column_commalist ')'
546 {$$ = SQL_NEW_RULE;
547 $$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
548 $$->append($2);
549 $$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));}
552 privilege_def:
553 SQL_TOKEN_GRANT privileges SQL_TOKEN_ON table_node SQL_TOKEN_TO grantee_commalist
554 opt_with_grant_option
555 {$$ = SQL_NEW_RULE;
556 $$->append($1);
557 $$->append($2);
558 $$->append($3);
559 $$->append($4);
560 $$->append($5);
561 $$->append($6);
562 $$->append($7);}
565 opt_with_grant_option:
566 /* empty */ {$$ = SQL_NEW_RULE;}
567 | SQL_TOKEN_WITH SQL_TOKEN_GRANT SQL_TOKEN_OPTION
568 {$$ = SQL_NEW_RULE;
569 $$->append($1);
570 $$->append($2);
571 $$->append($3);}
574 privileges:
575 SQL_TOKEN_ALL SQL_TOKEN_PRIVILEGES
576 {$$ = SQL_NEW_RULE;
577 $$->append($1);
578 $$->append($2);}
579 | operation_commalist
582 operation_commalist:
583 operation
584 {$$ = SQL_NEW_COMMALISTRULE;
585 $$->append($1);}
586 | operation_commalist ',' operation
587 {$1->append($3);
588 $$ = $1;}
591 operation:
592 SQL_TOKEN_SELECT
593 | SQL_TOKEN_INSERT opt_column_commalist
594 {$$ = SQL_NEW_RULE;
595 $$->append($1);
596 $$->append($2);}
597 | SQL_TOKEN_DELETE
598 | SQL_TOKEN_UPDATE opt_column_commalist
599 {$$ = SQL_NEW_RULE;
600 $$->append($1);
601 $$->append($2);}
602 | SQL_TOKEN_REFERENCES opt_column_commalist
603 {$$ = SQL_NEW_RULE;
604 $$->append($1);
605 $$->append($2);}
606 | SQL_TOKEN_USAGE
610 grantee_commalist:
611 grantee
612 {$$ = SQL_NEW_COMMALISTRULE;
613 $$->append($1);}
614 | grantee_commalist ',' grantee
615 {$1->append($3);
616 $$ = $1;}
619 grantee:
620 SQL_TOKEN_PUBLIC
621 | user
624 /* module language */
626 opt_order_by_clause:
627 /* empty */ {$$ = SQL_NEW_RULE;}
628 | SQL_TOKEN_ORDER SQL_TOKEN_BY ordering_spec_commalist
629 {$$ = SQL_NEW_RULE;
630 $$->append($1);
631 $$->append($2);
632 $$->append($3);}
635 ordering_spec_commalist:
636 ordering_spec
637 {$$ = SQL_NEW_COMMALISTRULE;
638 $$->append($1);}
639 | ordering_spec_commalist ',' ordering_spec
640 {$1->append($3);
641 $$ = $1;}
644 ordering_spec:
645 /* SQL_TOKEN_INTNUM opt_asc_desc
646 {$$ = SQL_NEW_RULE;
647 $$->append($1);
648 $$->append($2);}
650 predicate opt_asc_desc
651 {$$ = SQL_NEW_RULE;
652 $$->append($1);
653 $$->append($2);}
655 | row_value_constructor_elem opt_asc_desc
656 {$$ = SQL_NEW_RULE;
657 $$->append($1);
658 $$->append($2);}
661 opt_asc_desc:
662 {$$ = SQL_NEW_RULE;}
663 | SQL_TOKEN_ASC
664 | SQL_TOKEN_DESC
668 /***
669 manipulative_statement_list:
670 manipulative_statement
671 {$$ = SQL_NEW_LISTRULE;
672 $$->append($1);}
673 | manipulative_statement_list manipulative_statement
674 {$1->append($2);
675 $$ = $1;}
677 ***/
679 sql_not:
680 {$$ = SQL_NEW_RULE;}
681 | SQL_TOKEN_NOT
684 /* manipulative statements */
686 sql: manipulative_statement
689 manipulative_statement:
690 commit_statement
691 /* | delete_statement_positioned*/
692 | delete_statement_searched
693 | fetch_statement
694 | insert_statement
695 | rollback_statement
696 | select_statement_into
697 /* | update_statement_positioned*/
698 | update_statement_searched
699 | union_statement
700 | '{' odbc_call_spec '}'
702 $$ = SQL_NEW_RULE;
703 $$->append($1 = newNode("{", SQL_NODE_PUNCTUATION));
704 $$->append($2);
705 $$->append($3 = newNode("}", SQL_NODE_PUNCTUATION));
709 union_statement:
710 select_statement
711 | union_statement SQL_TOKEN_UNION all select_statement
713 $$ = SQL_NEW_RULE;
714 $$->append($1);
715 $$->append($2);
716 $$->append($3);
717 $$->append($4);
720 commit_statement:
721 SQL_TOKEN_COMMIT SQL_TOKEN_WORK
722 {$$ = SQL_NEW_RULE;
723 $$->append($1);
724 $$->append($2);}
727 delete_statement_positioned:
728 SQL_TOKEN_DELETE SQL_TOKEN_FROM table_node SQL_TOKEN_WHERE SQL_TOKEN_CURRENT SQL_TOKEN_OF cursor
729 {$$ = SQL_NEW_RULE;
730 $$->append($1);
731 $$->append($2);
732 $$->append($3);
733 $$->append($4);
734 $$->append($5);
735 $$->append($6);
736 $$->append($7);}
739 delete_statement_searched:
740 SQL_TOKEN_DELETE SQL_TOKEN_FROM table_node opt_where_clause
741 {$$ = SQL_NEW_RULE;
742 $$->append($1);
743 $$->append($2);
744 $$->append($3);
745 $$->append($4);}
748 fetch_statement:
749 SQL_TOKEN_FETCH cursor SQL_TOKEN_INTO target_commalist
750 {$$ = SQL_NEW_RULE;
751 $$->append($1);
752 $$->append($2);
753 $$->append($3);
754 $$->append($4);}
757 insert_statement:
758 SQL_TOKEN_INSERT SQL_TOKEN_INTO table_node opt_column_commalist values_or_query_spec
759 {$$ = SQL_NEW_RULE;
760 $$->append($1);
761 $$->append($2);
762 $$->append($3);
763 $$->append($4);
764 $$->append($5);}
766 values_or_query_spec:
767 SQL_TOKEN_VALUES '(' table_value_const_list ')'
768 {$$ = SQL_NEW_RULE;
769 $$->append($1);
770 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
771 $$->append($3);
772 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
776 table_value_const_list:
777 row_value_constructor
778 {$$ = SQL_NEW_COMMALISTRULE;
779 $$->append($1);}
780 | table_value_const_list ',' row_value_constructor
781 {$1->append($3);
782 $$ = $1;}
784 row_value_const_list:
785 row_value_constructor_elem
786 {$$ = SQL_NEW_COMMALISTRULE;
787 $$->append($1);}
788 | row_value_const_list ',' row_value_constructor_elem
789 {$1->append($3);
790 $$ = $1;}
792 row_value_constructor:
793 row_value_constructor_elem
794 /* | '(' row_value_const_list ')'
796 $$ = SQL_NEW_RULE;
797 $$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
798 $$->append($2);
799 $$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
803 row_value_constructor_elem:
804 value_exp /*[^')']*/
805 | SQL_TOKEN_DEFAULT
809 rollback_statement:
810 SQL_TOKEN_ROLLBACK SQL_TOKEN_WORK
811 {$$ = SQL_NEW_RULE;
812 $$->append($1);
813 $$->append($2);}
817 /* INTO target_commalist herausgenommen */
818 select_statement_into:
819 SQL_TOKEN_SELECT opt_all_distinct selection SQL_TOKEN_INTO target_commalist table_exp
820 {$$ = SQL_NEW_RULE;
821 $$->append($1);
822 $$->append($2);
823 $$->append($3);
824 $$->append($4);
825 $$->append($5);
826 $$->append($6); }
829 opt_all_distinct:
830 {$$ = SQL_NEW_RULE;}
831 | SQL_TOKEN_ALL
832 | SQL_TOKEN_DISTINCT
836 update_statement_positioned:
837 SQL_TOKEN_UPDATE table_node SQL_TOKEN_SET assignment_commalist
838 SQL_TOKEN_WHERE SQL_TOKEN_CURRENT SQL_TOKEN_OF cursor
839 {$$ = SQL_NEW_RULE;
840 $$->append($1);
841 $$->append($2);
842 $$->append($3);
843 $$->append($4);
844 $$->append($5);
845 $$->append($6);
846 $$->append($7);
847 $$->append($8);}
850 assignment_commalist:
851 assignment
852 {$$ = SQL_NEW_COMMALISTRULE;
853 $$->append($1);}
854 | assignment_commalist ',' assignment
855 {$1->append($3);
856 $$ = $1;}
859 assignment:
860 column SQL_EQUAL update_source
861 {$$ = SQL_NEW_RULE;
862 $$->append($1);
863 $$->append($2);
864 $$->append($3);}
866 update_source:
867 value_exp
868 | SQL_TOKEN_DEFAULT
870 update_statement_searched:
871 SQL_TOKEN_UPDATE table_node SQL_TOKEN_SET assignment_commalist opt_where_clause
872 {$$ = SQL_NEW_RULE;
873 $$->append($1);
874 $$->append($2);
875 $$->append($3);
876 $$->append($4);
877 $$->append($5);}
880 target_commalist:
881 target
882 {$$ = SQL_NEW_COMMALISTRULE;
883 $$->append($1);}
884 | target_commalist ',' target
885 {$1->append($3);
886 $$ = $1;}
889 target:
890 parameter_ref
893 opt_where_clause:
894 /* empty */ {$$ = SQL_NEW_RULE;}
895 | where_clause
898 /* query expressions */
900 query_term:
901 non_join_query_term
903 $$ = SQL_NEW_RULE;
904 $$->append($1);
907 /* SELECT STATEMENT */
908 select_statement:
909 SQL_TOKEN_SELECT opt_all_distinct selection table_exp
911 $$ = SQL_NEW_RULE;
912 $$->append($1);
913 $$->append($2);
914 $$->append($3);
915 $$->append($4);
919 selection:
922 $$ = SQL_NEW_RULE;
923 $$->append($1 = newNode("*", SQL_NODE_PUNCTUATION));
925 | scalar_exp_commalist
928 table_exp:
929 from_clause
930 opt_where_clause
931 opt_group_by_clause
932 opt_having_clause
933 opt_order_by_clause
934 {$$ = SQL_NEW_RULE;
935 $$->append($1);
936 $$->append($2);
937 $$->append($3);
938 $$->append($4);
939 $$->append($5);}
942 from_clause:
943 SQL_TOKEN_FROM table_ref_commalist
944 {$$ = SQL_NEW_RULE;
945 $$->append($1);
946 $$->append($2);}
949 table_ref_commalist:
951 table_ref
952 {$$ = SQL_NEW_COMMALISTRULE;
953 $$->append($1);}
954 | table_ref_commalist ',' table_ref
955 {$1->append($3);
956 $$ = $1;}
959 opt_as:
960 /* empty */ {$$ = SQL_NEW_RULE;}
961 | SQL_TOKEN_AS
963 table_primary_as_range_column:
964 {$$ = SQL_NEW_RULE;}
965 | opt_as SQL_TOKEN_NAME op_column_commalist
966 {$$ = SQL_NEW_RULE;
967 $$->append($1);
968 $$->append($2);
969 $$->append($3);
972 table_ref:
973 table_node table_primary_as_range_column
975 $$ = SQL_NEW_RULE;
976 $$->append($1);
977 $$->append($2);
979 | subquery range_variable op_column_commalist
981 $$ = SQL_NEW_RULE;
982 $$->append($1);
983 $$->append($2);
984 $$->append($3);
986 | joined_table
987 | '{' SQL_TOKEN_OJ joined_table '}'
989 $$ = SQL_NEW_RULE;
990 $$->append($1 = newNode("{", SQL_NODE_PUNCTUATION));
991 $$->append($2);
992 $$->append($3);
993 $$->append($4 = newNode("}", SQL_NODE_PUNCTUATION));
995 | '(' joined_table ')'
997 $$ = SQL_NEW_RULE;
998 $$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
999 $$->append($2);
1000 $$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
1003 where_clause:
1004 SQL_TOKEN_WHERE search_condition
1005 {$$ = SQL_NEW_RULE;
1006 $$->append($1);
1007 $$->append($2);}
1010 opt_group_by_clause:
1011 /* empty */ {$$ = SQL_NEW_RULE;}
1012 | SQL_TOKEN_GROUP SQL_TOKEN_BY column_ref_commalist
1013 {$$ = SQL_NEW_RULE;
1014 $$->append($1);
1015 $$->append($2);
1016 $$->append($3);}
1019 column_ref_commalist:
1020 column_ref
1021 {$$ = SQL_NEW_COMMALISTRULE;
1022 $$->append($1);}
1023 | set_fct_spec
1024 {$$ = SQL_NEW_COMMALISTRULE;
1025 $$->append($1);}
1026 | column_ref_commalist ',' column_ref
1027 {$1->append($3);
1028 $$ = $1;}
1029 | column_ref_commalist ',' set_fct_spec
1030 {$1->append($3);
1031 $$ = $1;}
1034 opt_having_clause:
1035 /* empty */ {$$ = SQL_NEW_RULE;}
1036 | SQL_TOKEN_HAVING search_condition
1037 {$$ = SQL_NEW_RULE;
1038 $$->append($1);
1039 $$->append($2);}
1042 /* search conditions */
1043 truth_value:
1044 SQL_TOKEN_TRUE
1045 | SQL_TOKEN_FALSE
1046 | SQL_TOKEN_UNKNOWN
1047 | SQL_TOKEN_NULL
1049 boolean_primary:
1050 predicate
1051 | '(' search_condition ')'
1052 { // boolean_primary: rule 2
1053 $$ = SQL_NEW_RULE;
1054 $$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
1055 $$->append($2);
1056 $$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
1058 | row_value_constructor_elem /*[^')' ',']*/
1060 if(xxx_pGLOBAL_SQLPARSER->inPredicateCheck())// boolean_primary: rule 3
1062 $$ = SQL_NEW_RULE;
1063 sal_Int16 nErg = xxx_pGLOBAL_SQLPARSER->buildComparsionRule($$,$1);
1064 if(nErg == 1)
1066 OSQLParseNode* pTemp = $$;
1067 $$ = pTemp->removeAt((sal_uInt32)0);
1068 delete pTemp;
1070 else
1072 delete $$;
1073 if(nErg)
1074 YYERROR;
1075 else
1076 YYABORT;
1079 else
1080 YYERROR;
1084 boolean_test:
1085 boolean_primary
1086 | boolean_primary SQL_TOKEN_IS sql_not truth_value
1088 $$ = SQL_NEW_RULE;
1089 $$->append($1);
1090 $$->append($2);
1091 $$->append($3);
1092 $$->append($4);
1095 boolean_factor:
1096 boolean_test
1097 | SQL_TOKEN_NOT boolean_test
1098 { // boolean_factor: rule 1
1099 $$ = SQL_NEW_RULE;
1100 $$->append($1);
1101 $$->append($2);
1104 boolean_term:
1105 boolean_factor
1106 | boolean_term SQL_TOKEN_AND boolean_factor
1108 $$ = SQL_NEW_RULE; // boolean_term: rule 1
1109 $$->append($1);
1110 $$->append($2);
1111 $$->append($3);
1114 search_condition:
1115 boolean_term
1116 | search_condition SQL_TOKEN_OR boolean_term
1118 $$ = SQL_NEW_RULE; // search_condition
1119 $$->append($1);
1120 $$->append($2);
1121 $$->append($3);
1124 predicate:
1125 comparison_predicate
1126 | between_predicate
1127 | all_or_any_predicate
1128 | existence_test
1129 | unique_test
1130 | test_for_null
1131 | in_predicate
1132 | like_predicate
1135 comparison_predicate:
1136 row_value_constructor comparison row_value_constructor
1138 $$ = SQL_NEW_RULE; // comparison_predicate: rule 1
1139 $$->append($1);
1140 $$->append($2);
1141 $$->append($3);
1143 | comparison row_value_constructor
1145 if(xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // comparison_predicate: rule 2
1147 $$ = SQL_NEW_RULE;
1148 sal_Int16 nErg = xxx_pGLOBAL_SQLPARSER->buildPredicateRule($$,$2,$1);
1149 if(nErg == 1)
1151 OSQLParseNode* pTemp = $$;
1152 $$ = pTemp->removeAt((sal_uInt32)0);
1153 delete pTemp;
1155 else
1157 delete $$;
1158 YYABORT;
1161 else
1163 YYERROR;
1167 comparison:
1168 SQL_LESS
1169 | SQL_NOTEQUAL
1170 | SQL_EQUAL
1171 | SQL_GREAT
1172 | SQL_LESSEQ
1173 | SQL_GREATEQ
1175 between_predicate:
1176 row_value_constructor sql_not SQL_TOKEN_BETWEEN row_value_constructor SQL_TOKEN_AND row_value_constructor
1177 {$$ = SQL_NEW_RULE; // between_predicate: rule 1
1178 $$->append($1);
1179 $$->append($2);
1180 $$->append($3);
1181 $$->append($4);
1182 $$->append($5);
1183 $$->append($6);
1185 | sql_not SQL_TOKEN_BETWEEN row_value_constructor SQL_TOKEN_AND row_value_constructor
1187 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // between_predicate: rule 2
1189 $$ = SQL_NEW_RULE;
1191 sal_Int16 nErg = xxx_pGLOBAL_SQLPARSER->buildPredicateRule($$,$3,$2,$5);
1192 if(nErg == 1)
1194 OSQLParseNode* pTemp = $$;
1195 $$ = pTemp->removeAt((sal_uInt32)0);
1196 $$->insert(1,$1);
1197 delete pTemp;
1198 delete $4;
1200 else
1202 delete $$;
1203 YYABORT;
1206 else
1207 YYERROR;
1211 like_predicate:
1212 row_value_constructor SQL_TOKEN_NOT SQL_TOKEN_LIKE string_value_exp opt_escape
1214 $$ = SQL_NEW_RULE; // like_predicate: rule 1
1215 $$->append($1);
1216 $$->append($2);
1217 $$->append($3);
1218 $$->append($4);
1219 $$->append($5);
1221 | row_value_constructor SQL_TOKEN_LIKE string_value_exp opt_escape
1223 $$ = SQL_NEW_RULE; // like_predicate: rule 2
1224 $$->append($1);
1225 $$->append($2);
1226 $$->append($3);
1227 $$->append($4);
1229 | row_value_constructor SQL_TOKEN_NOT SQL_TOKEN_LIKE value_exp_primary opt_escape
1231 $$ = SQL_NEW_RULE; // like_predicate: rule 3
1232 $$->append($1);
1233 $$->append($2);
1234 $$->append($3);
1235 $$->append($4);
1236 $$->append($5);
1238 | row_value_constructor SQL_TOKEN_LIKE value_exp_primary opt_escape
1240 $$ = SQL_NEW_RULE; // like_predicate: rule 4
1241 $$->append($1);
1242 $$->append($2);
1243 $$->append($3);
1244 $$->append($4);
1246 | sql_not SQL_TOKEN_LIKE string_value_exp opt_escape
1248 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // like_predicate: rule 5
1250 OSQLParseNode* pColumnRef = newNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::column_ref));
1251 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQL_NODE_NAME));
1253 $$ = SQL_NEW_RULE;
1254 $$->append(pColumnRef);
1255 $$->append($1);
1256 $$->append($2);
1257 if (xxx_pGLOBAL_SQLPARSER->buildLikeRule($$,$3,$4))
1258 $$->append($4);
1259 else
1261 delete $$;
1262 YYABORT;
1265 else
1266 YYERROR;
1268 | sql_not SQL_TOKEN_LIKE value_exp_primary opt_escape
1270 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // like_predicate: rule 6
1272 OSQLParseNode* pColumnRef = newNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::column_ref));
1273 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQL_NODE_NAME));
1275 $$ = SQL_NEW_RULE;
1276 $$->append(pColumnRef);
1277 $$->append($1);
1278 $$->append($2);
1279 if (xxx_pGLOBAL_SQLPARSER->buildLikeRule($$,$3,$4))
1280 $$->append($4);
1281 else
1283 delete $$;
1284 YYABORT;
1287 else
1288 YYERROR;
1292 opt_escape:
1293 /* empty */ {$$ = SQL_NEW_RULE;}
1294 | SQL_TOKEN_ESCAPE string_value_exp
1295 {$$ = SQL_NEW_RULE;
1296 $$->append($1);
1297 $$->append($2);}
1298 | '{' SQL_TOKEN_ESCAPE SQL_TOKEN_STRING '}'
1300 $$ = SQL_NEW_RULE;
1301 $$->append($1 = newNode("{", SQL_NODE_PUNCTUATION));
1302 $$->append($2);
1303 $$->append($3);
1304 $$->append($4 = newNode("}", SQL_NODE_PUNCTUATION));
1308 test_for_null:
1309 row_value_constructor SQL_TOKEN_IS sql_not truth_value
1311 $$ = SQL_NEW_RULE; // test_for_null: rule 1
1312 $$->append($1);
1313 $$->append($2);
1314 $$->append($3);
1315 $$->append($4);
1317 | SQL_TOKEN_IS sql_not truth_value
1319 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())// test_for_null: rule 2
1321 OSQLParseNode* pColumnRef = newNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::column_ref));
1322 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQL_NODE_NAME));
1324 $$ = SQL_NEW_RULE;
1325 $$->append(pColumnRef);
1326 $$->append($1);
1327 $$->append($2);
1328 $$->append($3);
1330 else
1331 YYERROR;
1334 in_predicate_value:
1335 subquery
1336 {$$ = SQL_NEW_RULE;
1337 $$->append($1);
1339 | '(' value_exp_commalist ')'
1340 {$$ = SQL_NEW_RULE;
1341 $$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
1342 $$->append($2);
1343 $$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
1346 in_predicate:
1347 row_value_constructor sql_not SQL_TOKEN_IN in_predicate_value
1349 $$ = SQL_NEW_RULE;// in_predicate: rule 1
1350 $$->append($1);
1351 $$->append($2);
1352 $$->append($3);
1353 $$->append($4);
1355 | sql_not SQL_TOKEN_IN in_predicate_value
1357 if ( xxx_pGLOBAL_SQLPARSER->inPredicateCheck() )// in_predicate: rule 2
1359 OSQLParseNode* pColumnRef = newNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::column_ref));
1360 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQL_NODE_NAME));
1362 $$ = SQL_NEW_RULE;
1363 $$->append(pColumnRef);
1364 $$->append($1);
1365 $$->append($2);
1366 $$->append($3);
1367 // hello
1369 else
1370 YYERROR;
1373 all_or_any_predicate:
1374 row_value_constructor comparison any_all_some subquery
1376 $$ = SQL_NEW_RULE;
1377 $$->append($1);
1378 $$->append($2);
1379 $$->append($3);
1380 $$->append($4);
1382 | comparison any_all_some subquery
1384 if(xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1386 OSQLParseNode* pColumnRef = newNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::column_ref));
1387 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQL_NODE_NAME));
1389 $$ = SQL_NEW_RULE;
1390 $$->append(pColumnRef);
1391 $$->append($1);
1392 $$->append($2);
1393 $$->append($3);
1395 else
1396 YYERROR;
1400 any_all_some:
1401 SQL_TOKEN_ANY
1402 | SQL_TOKEN_ALL
1403 | SQL_TOKEN_SOME
1406 existence_test:
1407 SQL_TOKEN_EXISTS subquery
1408 {$$ = SQL_NEW_RULE;
1409 $$->append($1);
1410 $$->append($2);}
1412 unique_test:
1413 SQL_TOKEN_UNIQUE subquery
1414 {$$ = SQL_NEW_RULE;
1415 $$->append($1);
1416 $$->append($2);}
1418 subquery:
1419 '(' query_exp ')'
1420 {$$ = SQL_NEW_RULE;
1421 $$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
1422 $$->append($2);
1423 $$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));}
1426 /* scalar expressions */
1427 scalar_exp_commalist:
1428 select_sublist
1430 $$ = SQL_NEW_COMMALISTRULE;
1431 $$->append($1);
1433 | scalar_exp_commalist ',' select_sublist
1435 $1->append($3);
1436 $$ = $1;
1439 select_sublist:
1440 /* table_node '.' '*'
1442 $$ = SQL_NEW_RULE;
1443 $$->append($1);
1444 $$->append($2 = newNode(".", SQL_NODE_PUNCTUATION));
1445 $$->append($3 = newNode("*", SQL_NODE_PUNCTUATION));
1448 derived_column
1452 parameter_ref:
1453 parameter
1457 op_like:
1460 $$ = newNode("*", SQL_NODE_PUNCTUATION);
1462 | '?'
1464 $$ = newNode("?", SQL_NODE_PUNCTUATION);
1466 | op_like '*'
1468 $$ = SQL_NEW_RULE;
1469 $$->append($1);
1470 $$->append($2 = newNode("*", SQL_NODE_PUNCTUATION));
1471 xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_False);
1473 | op_like '?'
1475 $$ = SQL_NEW_RULE;
1476 $$->append($1);
1477 $$->append($2 = newNode("?", SQL_NODE_PUNCTUATION));
1478 xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_False);
1483 literal:
1484 /* SQL_TOKEN_STRING
1485 | */SQL_TOKEN_INT
1486 | SQL_TOKEN_REAL_NUM
1487 | SQL_TOKEN_INTNUM
1488 | SQL_TOKEN_APPROXNUM
1489 | SQL_TOKEN_ACCESS_DATE
1490 /* rules for predicate check */
1491 | literal SQL_TOKEN_STRING
1493 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1495 $$ = SQL_NEW_RULE;
1496 $$->append($1);
1497 $$->append($2);
1498 xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_True);
1500 else
1501 YYERROR;
1503 | literal SQL_TOKEN_INT
1505 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1507 $$ = SQL_NEW_RULE;
1508 $$->append($1);
1509 $$->append($2);
1510 xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_True);
1512 else
1513 YYERROR;
1515 | literal SQL_TOKEN_REAL_NUM
1517 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1519 $$ = SQL_NEW_RULE;
1520 $$->append($1);
1521 $$->append($2);
1522 xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_True);
1524 else
1525 YYERROR;
1527 | literal SQL_TOKEN_APPROXNUM
1529 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1531 $$ = SQL_NEW_RULE;
1532 $$->append($1);
1533 $$->append($2);
1534 xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_True);
1536 else
1537 YYERROR;
1541 /* miscellaneous */
1542 as_clause:
1543 /* empty */ {$$ = SQL_NEW_RULE;}
1544 | SQL_TOKEN_AS column
1546 $$ = SQL_NEW_RULE;
1547 $$->append($1);
1548 $$->append($2);
1550 | column
1552 position_exp:
1553 SQL_TOKEN_POSITION '(' value_exp SQL_TOKEN_IN value_exp ')'
1555 $$ = SQL_NEW_RULE;
1556 $$->append($1);
1557 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
1558 $$->append($3);
1559 $$->append($4);
1560 $$->append($5);
1561 $$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));
1563 | SQL_TOKEN_POSITION '(' value_exp_commalist ')'
1565 $$ = SQL_NEW_RULE;
1566 $$->append($1);
1567 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
1568 $$->append($3);
1569 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
1572 num_value_fct:
1573 position_exp
1574 | extract_exp
1575 | length_exp
1577 char_length_exp:
1578 SQL_TOKEN_CHAR_LENGTH '(' value_exp ')'
1580 $$ = SQL_NEW_RULE;
1581 $$->append($1);
1582 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
1583 $$->append($3);
1584 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
1586 | SQL_TOKEN_CHARACTER_LENGTH '(' value_exp ')'
1588 $$ = SQL_NEW_RULE;
1589 $$->append($1);
1590 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
1591 $$->append($3);
1592 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
1596 octet_length_exp:
1597 SQL_TOKEN_OCTET_LENGTH '(' value_exp ')'
1599 $$ = SQL_NEW_RULE;
1600 $$->append($1);
1601 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
1602 $$->append($3);
1603 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
1606 bit_length_exp:
1607 SQL_TOKEN_BIT_LENGTH '(' value_exp ')'
1609 $$ = SQL_NEW_RULE;
1610 $$->append($1);
1611 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
1612 $$->append($3);
1613 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
1616 length_exp:
1617 char_length_exp
1619 $$ = SQL_NEW_RULE;
1620 $$->append($1);
1622 | octet_length_exp
1624 $$ = SQL_NEW_RULE;
1625 $$->append($1);
1627 | bit_length_exp
1629 $$ = SQL_NEW_RULE;
1630 $$->append($1);
1633 datetime_field:
1634 non_second_datetime_field
1636 $$ = SQL_NEW_RULE;
1637 $$->append($1);
1639 | SQL_TOKEN_SECOND
1641 $$ = SQL_NEW_RULE;
1642 $$->append($1);
1645 extract_field:
1646 time_zone_field
1647 | datetime_field
1648 | value_exp
1650 time_zone_field:
1651 SQL_TOKEN_TIMEZONE_HOUR
1653 $$ = SQL_NEW_RULE;
1654 $$->append($1);
1656 | SQL_TOKEN_TIMEZONE_MINUTE
1658 $$ = SQL_NEW_RULE;
1659 $$->append($1);
1662 extract_source:
1663 datetime_value_exp
1665 $$ = SQL_NEW_RULE;
1666 $$->append($1);
1668 /* | interval_value_exp
1670 $$ = SQL_NEW_RULE;
1671 $$->append($1);
1672 } */
1674 extract_exp:
1675 SQL_TOKEN_EXTRACT '(' extract_field SQL_TOKEN_FROM value_exp ')'
1677 $$ = SQL_NEW_RULE;
1678 $$->append($1);
1679 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
1680 $$->append($3);
1681 $$->append($4);
1682 $$->append($5);
1683 $$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));
1686 unsigned_value_spec:
1687 general_value_spec
1688 | literal
1690 general_value_spec:
1691 parameter
1692 | SQL_TOKEN_USER
1693 | SQL_TOKEN_NULL
1694 | SQL_TOKEN_FALSE
1695 | SQL_TOKEN_TRUE
1697 set_fct_spec:
1698 general_set_fct
1699 | '{' odbc_fct_spec '}'
1701 $$ = SQL_NEW_RULE;
1702 $$->append($1 = newNode("{", SQL_NODE_PUNCTUATION));
1703 $$->append($2);
1704 $$->append($3 = newNode("}", SQL_NODE_PUNCTUATION));
1706 | function_name '(' ')'
1708 $$ = SQL_NEW_RULE;
1709 $$->append($1);
1710 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
1711 $$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
1713 | function_name0 '(' ')'
1715 $$ = SQL_NEW_RULE;
1716 $$->append($1);
1717 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
1718 $$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
1720 | function_name1 '(' function_arg ')'
1722 $$ = SQL_NEW_RULE;
1723 $$->append($1);
1724 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
1725 $$->append($3);
1726 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
1728 | function_name2 '(' function_arg_commalist2 ')'
1730 $$ = SQL_NEW_RULE;
1731 $$->append($1);
1732 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
1733 $$->append($3);
1734 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
1736 | function_name3 '(' function_arg_commalist3 ')'
1738 $$ = SQL_NEW_RULE;
1739 $$->append($1);
1740 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
1741 $$->append($3);
1742 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
1744 | string_function_4Argument '(' function_arg_commalist4 ')'
1746 $$ = SQL_NEW_RULE;
1747 $$->append($1);
1748 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
1749 $$->append($3);
1750 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
1752 | function_name '(' function_args_commalist ')'
1754 $$ = SQL_NEW_RULE;
1755 $$->append($1);
1756 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
1757 $$->append($3);
1758 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
1760 | function_name12 '(' function_args_commalist ')'
1762 if ( $3->count() == 1 || $3->count() == 2 )
1764 $$ = SQL_NEW_RULE;
1765 $$->append($1);
1766 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
1767 $$->append($3);
1768 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
1770 else
1771 YYERROR;
1773 | function_name23 '(' function_args_commalist ')'
1775 if ( $3->count() == 2 || $3->count() == 3)
1777 $$ = SQL_NEW_RULE;
1778 $$->append($1);
1779 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
1780 $$->append($3);
1781 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
1783 else
1784 YYERROR;
1787 function_name0:
1788 date_function_0Argument
1789 | numeric_function_0Argument
1791 function_name1:
1792 string_function_1Argument
1793 | date_function_1Argument
1794 | numeric_function_1Argument
1796 function_name2:
1797 string_function_2Argument
1798 | numeric_function_2Argument
1800 function_name12:
1801 SQL_TOKEN_ROUND
1802 | SQL_TOKEN_WEEK
1803 | SQL_TOKEN_LOGF
1804 | SQL_TOKEN_LOG
1806 function_name23:
1807 SQL_TOKEN_LOCATE
1809 function_name3:
1810 string_function_3Argument
1811 | date_function_3Argument
1813 function_name:
1814 string_function
1815 | date_function
1816 | numeric_function
1817 | SQL_TOKEN_NAME
1819 string_function_1Argument:
1820 SQL_TOKEN_LENGTH
1821 | SQL_TOKEN_ASCII
1822 | SQL_TOKEN_LCASE
1823 | SQL_TOKEN_LTRIM
1824 | SQL_TOKEN_RTRIM
1825 | SQL_TOKEN_SPACE
1826 | SQL_TOKEN_UCASE
1829 string_function_2Argument:
1830 SQL_TOKEN_REPEAT
1831 | SQL_TOKEN_LEFT
1832 | SQL_TOKEN_RIGHT
1834 string_function_3Argument:
1835 SQL_TOKEN_REPLACE
1837 string_function_4Argument:
1838 SQL_TOKEN_INSERT
1841 string_function:
1842 SQL_TOKEN_CHAR
1843 | SQL_TOKEN_CONCAT
1844 | SQL_TOKEN_DIFFERENCE
1845 | SQL_TOKEN_LOCATE_2
1846 | SQL_TOKEN_SOUNDEX
1848 date_function_0Argument:
1849 SQL_TOKEN_CURDATE
1850 | SQL_TOKEN_CURTIME
1851 | SQL_TOKEN_NOW
1853 date_function_1Argument:
1854 SQL_TOKEN_DAYOFWEEK
1855 | SQL_TOKEN_DAYOFMONTH
1856 | SQL_TOKEN_DAYOFYEAR
1857 | SQL_TOKEN_MONTH
1858 | SQL_TOKEN_DAYNAME
1859 | SQL_TOKEN_MONTHNAME
1860 | SQL_TOKEN_QUARTER
1861 | SQL_TOKEN_HOUR
1862 | SQL_TOKEN_MINUTE
1863 | SQL_TOKEN_SECOND
1864 | SQL_TOKEN_YEAR
1865 | SQL_TOKEN_DAY
1866 | SQL_TOKEN_TIMEVALUE
1867 | SQL_TOKEN_DATEVALUE
1869 date_function_3Argument:
1870 SQL_TOKEN_DATEDIFF
1872 date_function:
1873 SQL_TOKEN_TIMESTAMPADD
1874 | SQL_TOKEN_TIMESTAMPDIFF
1876 numeric_function_0Argument:
1877 SQL_TOKEN_PI
1879 numeric_function_1Argument:
1880 SQL_TOKEN_ABS
1881 | SQL_TOKEN_ACOS
1882 | SQL_TOKEN_ASIN
1883 | SQL_TOKEN_ATAN
1884 | SQL_TOKEN_CEILING
1885 | SQL_TOKEN_COS
1886 | SQL_TOKEN_COT
1887 | SQL_TOKEN_DEGREES
1888 | SQL_TOKEN_FLOOR
1889 | SQL_TOKEN_SIGN
1890 | SQL_TOKEN_SIN
1891 | SQL_TOKEN_SQRT
1892 | SQL_TOKEN_TAN
1893 | SQL_TOKEN_EXP
1894 | SQL_TOKEN_LOG10
1895 | SQL_TOKEN_LN
1896 | SQL_TOKEN_RADIANS
1897 | SQL_TOKEN_ROUNDMAGIC
1899 numeric_function_2Argument:
1900 SQL_TOKEN_ATAN2
1901 | SQL_TOKEN_MOD
1902 | SQL_TOKEN_POWER
1904 numeric_function:
1905 SQL_TOKEN_RAND
1906 | SQL_TOKEN_TRUNCATE
1908 op_parameter:
1909 {$$ = SQL_NEW_RULE;}
1910 | '?' SQL_EQUAL
1912 $$ = SQL_NEW_RULE;
1913 $$->append($1 = newNode("?", SQL_NODE_PUNCTUATION));
1914 $$->append($2);
1917 odbc_call_spec:
1918 op_parameter SQL_TOKEN_CALL table_node op_odbc_call_parameter
1920 $$ = SQL_NEW_RULE;
1921 $$->append($1);
1922 $$->append($2);
1923 $$->append($3);
1924 $$->append($4);
1928 op_odbc_call_parameter:
1929 {$$ = SQL_NEW_RULE;}
1930 | '(' odbc_parameter_commalist ')'
1932 $$ = SQL_NEW_RULE;
1933 $$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
1934 $$->append($2);
1935 $$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
1939 odbc_parameter_commalist:
1940 odbc_parameter
1941 {$$ = SQL_NEW_COMMALISTRULE;
1942 $$->append($1);}
1943 | odbc_parameter_commalist ',' odbc_parameter
1945 $1->append($3);
1946 $$ = $1;
1949 odbc_parameter:
1950 /* empty */ {$$ = SQL_NEW_RULE;}
1951 | literal
1952 | parameter
1955 odbc_fct_spec:
1956 odbc_fct_type SQL_TOKEN_STRING
1958 $$ = SQL_NEW_RULE;
1959 $$->append($1);
1960 $$->append($2);
1964 odbc_fct_type:
1965 SQL_TOKEN_FN
1966 | SQL_TOKEN_D
1967 | SQL_TOKEN_T
1968 | SQL_TOKEN_TS
1971 general_set_fct:
1972 set_fct_type '(' opt_all_distinct value_exp ')'
1974 $$ = SQL_NEW_RULE;
1975 $$->append($1);
1976 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
1977 $$->append($3);
1978 $$->append($4);
1979 $$->append($5 = newNode(")", SQL_NODE_PUNCTUATION));
1981 | SQL_TOKEN_COUNT '(' '*' ')'
1983 $$ = SQL_NEW_RULE;
1984 $$->append($1);
1985 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
1986 $$->append($3 = newNode("*", SQL_NODE_PUNCTUATION));
1987 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
1989 | SQL_TOKEN_COUNT '(' opt_all_distinct value_exp ')'
1991 $$ = SQL_NEW_RULE;
1992 $$->append($1);
1993 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
1994 $$->append($3);
1995 $$->append($4);
1996 $$->append($5 = newNode(")", SQL_NODE_PUNCTUATION));
1999 set_fct_type:
2000 SQL_TOKEN_AVG
2001 | SQL_TOKEN_MAX
2002 | SQL_TOKEN_MIN
2003 | SQL_TOKEN_SUM
2004 | SQL_TOKEN_EVERY
2005 | SQL_TOKEN_ANY
2006 | SQL_TOKEN_SOME
2007 | SQL_TOKEN_STDDEV_POP
2008 | SQL_TOKEN_STDDEV_SAMP
2009 | SQL_TOKEN_VAR_SAMP
2010 | SQL_TOKEN_VAR_POP
2011 | SQL_TOKEN_COLLECT
2012 | SQL_TOKEN_FUSION
2013 | SQL_TOKEN_INTERSECTION
2016 outer_join_type:
2017 SQL_TOKEN_LEFT %prec SQL_TOKEN_LEFT
2019 $$ = SQL_NEW_RULE;
2020 $$->append($1);
2022 | SQL_TOKEN_RIGHT %prec SQL_TOKEN_RIGHT
2024 $$ = SQL_NEW_RULE;
2025 $$->append($1);
2027 | SQL_TOKEN_FULL %prec SQL_TOKEN_FULL
2029 $$ = SQL_NEW_RULE;
2030 $$->append($1);
2033 join_condition:
2034 SQL_TOKEN_ON search_condition
2036 $$ = SQL_NEW_RULE;
2037 $$->append($1);
2038 $$->append($2);
2041 join_spec:
2042 join_condition
2043 | named_columns_join
2045 join_type:
2046 SQL_TOKEN_INNER
2048 $$ = SQL_NEW_RULE;
2049 $$->append($1);
2051 | outer_join_type
2052 | outer_join_type SQL_TOKEN_OUTER
2054 $$ = SQL_NEW_RULE;
2055 $$->append($1);
2056 $$->append($2);
2059 cross_union:
2060 table_ref /*[SQL_TOKEN_CROSS]*/ SQL_TOKEN_CROSS SQL_TOKEN_JOIN table_ref
2062 $$ = SQL_NEW_RULE;
2063 $$->append($1);
2064 $$->append($2);
2065 $$->append($3);
2066 $$->append($4);
2070 qualified_join:
2071 /* wenn SQL_TOKEN_NATURAL, dann keine join_spec */
2072 table_ref /*[SQL_TOKEN_NATURAL]*/ SQL_TOKEN_NATURAL join_type SQL_TOKEN_JOIN table_ref
2074 $$ = SQL_NEW_RULE;
2075 $$->append($1);
2076 $$->append($2);
2077 $$->append($3);
2078 $$->append($4);
2079 $$->append($5);
2081 | table_ref join_type SQL_TOKEN_JOIN table_ref join_spec
2083 $$ = SQL_NEW_RULE;
2084 $$->append($1);
2085 $$->append($2);
2086 $$->append($3);
2087 $$->append($4);
2088 $$->append($5);
2090 | cross_union
2092 joined_table:
2093 qualified_join
2095 named_columns_join:
2096 SQL_TOKEN_USING '(' column_commalist ')'
2098 $$ = SQL_NEW_RULE;
2099 $$->append($1);
2100 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
2101 $$->append($3);
2102 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
2105 simple_table:
2106 select_statement
2107 | values_or_query_spec
2110 non_join_query_primary:
2111 simple_table
2112 | '(' non_join_query_exp ')'
2114 $$ = SQL_NEW_RULE;
2115 $$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
2116 $$->append($2);
2117 $$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
2120 non_join_query_term:
2121 non_join_query_primary
2122 | query_term SQL_TOKEN_INTERSECT all query_primary
2124 $$ = SQL_NEW_RULE;
2125 $$->append($1);
2126 $$->append($2);
2127 $$->append($3);
2128 $$->append($4);
2131 query_primary:
2132 non_join_query_primary
2134 non_join_query_exp:
2135 non_join_query_term
2136 | query_exp SQL_TOKEN_UNION all query_term
2138 $$ = SQL_NEW_RULE;
2139 $$->append($1);
2140 $$->append($2);
2141 $$->append($3);
2142 $$->append($4);
2144 | query_exp SQL_TOKEN_EXCEPT all query_term
2146 $$ = SQL_NEW_RULE;
2147 $$->append($1);
2148 $$->append($2);
2149 $$->append($3);
2150 $$->append($4);
2153 all:
2154 /* empty*/ {$$ = SQL_NEW_RULE;}
2155 | SQL_TOKEN_ALL
2157 query_exp:
2158 non_join_query_exp /*[^')']*/
2160 scalar_subquery:
2161 subquery
2163 cast_operand:
2164 value_exp
2166 cast_target:
2167 table_node
2168 | data_type
2170 cast_spec:
2171 SQL_TOKEN_CAST '(' cast_operand SQL_TOKEN_AS cast_target ')'
2173 $$ = SQL_NEW_RULE;
2174 $$->append($1);
2175 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
2176 $$->append($3);
2177 $$->append($4);
2178 $$->append($5);
2179 $$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));
2182 value_exp_primary:
2183 unsigned_value_spec
2184 | column_ref
2185 | set_fct_spec
2186 | scalar_subquery
2187 | '(' value_exp ')'
2189 $$ = SQL_NEW_RULE;
2190 $$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
2191 $$->append($2);
2192 $$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
2194 | cast_spec
2197 num_primary:
2198 value_exp_primary
2199 | num_value_fct
2201 factor:
2202 num_primary
2203 | '-' num_primary %prec SQL_TOKEN_UMINUS
2205 $$ = SQL_NEW_RULE;
2206 $$->append($1 = newNode("-", SQL_NODE_PUNCTUATION));
2207 $$->append($2);
2209 | '+' num_primary %prec SQL_TOKEN_UMINUS
2211 $$ = SQL_NEW_RULE;
2212 $$->append($1 = newNode("+", SQL_NODE_PUNCTUATION));
2213 $$->append($2);
2217 term:
2218 factor
2219 | term '*' factor
2221 $$ = SQL_NEW_RULE;
2222 $$->append($1);
2223 $$->append($2 = newNode("*", SQL_NODE_PUNCTUATION));
2224 $$->append($3);
2226 | term '/' factor
2228 $$ = SQL_NEW_RULE;
2229 $$->append($1);
2230 $$->append($2 = newNode("/", SQL_NODE_PUNCTUATION));
2231 $$->append($3);
2235 num_value_exp:
2236 term
2237 | num_value_exp '+' term
2239 $$ = SQL_NEW_RULE;
2240 $$->append($1);
2241 $$->append($2 = newNode("+", SQL_NODE_PUNCTUATION));
2242 $$->append($3);
2244 | num_value_exp '-' term
2246 $$ = SQL_NEW_RULE;
2247 $$->append($1);
2248 $$->append($2 = newNode("-", SQL_NODE_PUNCTUATION));
2249 $$->append($3);
2252 datetime_primary:
2253 /* value_exp_primary
2255 $$ = SQL_NEW_RULE;
2256 $$->append($1);
2258 |*/ datetime_value_fct
2260 $$ = SQL_NEW_RULE;
2261 $$->append($1);
2264 datetime_value_fct:
2265 SQL_TOKEN_CURRENT_DATE
2267 $$ = SQL_NEW_RULE;
2268 $$->append($1);
2270 | SQL_TOKEN_CURRENT_TIME
2272 $$ = SQL_NEW_RULE;
2273 $$->append($1);
2275 | SQL_TOKEN_CURRENT_TIMESTAMP
2277 $$ = SQL_NEW_RULE;
2278 $$->append($1);
2281 time_zone:
2282 SQL_TOKEN_AT time_zone_specifier
2284 $$ = SQL_NEW_RULE;
2285 $$->append($1);
2286 $$->append($2);
2289 time_zone_specifier:
2290 SQL_TOKEN_LOCAL
2292 $$ = SQL_NEW_RULE;
2293 $$->append($1);
2295 /* | SQL_TOKEN_TIME SQL_TOKEN_ZONE interval_value_exp
2297 $$ = SQL_NEW_RULE;
2298 $$->append($1);
2299 $$->append($2);
2300 $$->append($3);
2303 datetime_factor:
2304 datetime_primary
2306 $$ = SQL_NEW_RULE;
2307 $$->append($1);
2309 | datetime_primary time_zone
2311 $$ = SQL_NEW_RULE;
2312 $$->append($1);
2313 $$->append($2);
2316 datetime_term:
2317 datetime_factor
2319 $$ = SQL_NEW_RULE;
2320 $$->append($1);
2324 interval_term:
2325 literal
2326 | interval_term '*' factor
2328 $$ = SQL_NEW_RULE;
2329 $$->append($1);
2330 $$->append($2 = newNode("*", SQL_NODE_PUNCTUATION));
2331 $$->append($3);
2333 | interval_term '/' factor
2335 $$ = SQL_NEW_RULE;
2336 $$->append($1);
2337 $$->append($2 = newNode("/", SQL_NODE_PUNCTUATION));
2338 $$->append($3);
2342 datetime_value_exp:
2343 datetime_term
2345 $$ = SQL_NEW_RULE;
2346 $$->append($1);
2348 /* | interval_value_exp '+' datetime_term
2350 $$ = SQL_NEW_RULE;
2351 $$->append($1);
2352 $$->append($2 = newNode("+", SQL_NODE_PUNCTUATION));
2353 $$->append($3);
2355 | datetime_value_exp '+' interval_term
2357 $$ = SQL_NEW_RULE;
2358 $$->append($1);
2359 $$->append($2 = newNode("+", SQL_NODE_PUNCTUATION));
2360 $$->append($3);
2362 | datetime_value_exp '-' interval_term
2364 $$ = SQL_NEW_RULE;
2365 $$->append($1);
2366 $$->append($2 = newNode("-", SQL_NODE_PUNCTUATION));
2367 $$->append($3);
2369 */ ;
2371 interval_value_exp:
2372 interval_term
2374 $$ = SQL_NEW_RULE;
2375 $$->append($1);
2377 | interval_value_exp '+' interval_term
2379 $$ = SQL_NEW_RULE;
2380 $$->append($1);
2381 $$->append($2 = newNode("+", SQL_NODE_PUNCTUATION));
2382 $$->append($3);
2384 | interval_value_exp '-' interval_term
2386 $$ = SQL_NEW_RULE;
2387 $$->append($1);
2388 $$->append($2 = newNode("-", SQL_NODE_PUNCTUATION));
2389 $$->append($3);
2391 | '(' datetime_value_exp '-' datetime_term ')' interval_qualifier
2393 $$ = SQL_NEW_RULE;
2394 $$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
2395 $$->append($2);
2396 $$->append($3 = newNode("-", SQL_NODE_PUNCTUATION));
2397 $$->append($4);
2398 $$->append($5 = newNode(")", SQL_NODE_PUNCTUATION));
2399 $$->append($6);
2403 non_second_datetime_field:
2404 SQL_TOKEN_YEAR
2405 | SQL_TOKEN_MONTH
2406 | SQL_TOKEN_DAY
2407 | SQL_TOKEN_HOUR
2408 | SQL_TOKEN_MINUTE
2410 /*start_field:
2411 non_second_datetime_field
2413 $$ = SQL_NEW_RULE;
2414 $$->append($1);
2416 | non_second_datetime_field '(' SQL_TOKEN_INTNUM ')'
2418 $$ = SQL_NEW_RULE;
2419 $$->append($1);
2420 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
2421 $$->append($3);
2422 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
2425 end_field:
2426 non_second_datetime_field
2428 $$ = SQL_NEW_RULE;
2429 $$->append($1);
2431 | SQL_TOKEN_SECOND
2433 $$ = SQL_NEW_RULE;
2434 $$->append($1);
2436 | SQL_TOKEN_SECOND '(' SQL_TOKEN_INTNUM ')'
2438 $$ = SQL_NEW_RULE;
2439 $$->append($1);
2440 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
2441 $$->append($3);
2442 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
2447 single_datetime_field:
2448 non_second_datetime_field
2450 $$ = SQL_NEW_RULE;
2451 $$->append($1);
2453 | non_second_datetime_field '(' SQL_TOKEN_INTNUM ')'
2455 $$ = SQL_NEW_RULE;
2456 $$->append($1);
2457 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
2458 $$->append($3);
2459 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
2461 | SQL_TOKEN_SECOND
2463 $$ = SQL_NEW_RULE;
2464 $$->append($1);
2466 | SQL_TOKEN_SECOND '(' SQL_TOKEN_INTNUM ')'
2468 $$ = SQL_NEW_RULE;
2469 $$->append($1);
2470 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
2471 $$->append($3);
2472 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
2474 | SQL_TOKEN_SECOND '(' SQL_TOKEN_INTNUM ',' SQL_TOKEN_INTNUM ')'
2476 $$ = SQL_NEW_RULE;
2477 $$->append($1);
2478 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
2479 $$->append($3);
2480 $$->append($4 = newNode(",", SQL_NODE_PUNCTUATION));
2481 $$->append($5);
2482 $$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));
2487 interval_qualifier:
2488 start_field SQL_TOKEN_TO end_field
2490 $$ = SQL_NEW_RULE;
2491 $$->append($1);
2492 $$->append($2);
2493 $$->append($3);
2495 | single_datetime_field
2497 $$ = SQL_NEW_RULE;
2498 $$->append($1);
2502 function_arg_commalist2:
2503 function_arg ',' function_arg
2504 {$$ = SQL_NEW_COMMALISTRULE;
2505 $$->append($1);
2506 $$->append($3);}
2508 function_arg_commalist3:
2509 function_arg ',' function_arg ',' function_arg
2511 $$ = SQL_NEW_COMMALISTRULE;
2512 $$->append($1);
2513 $$->append($3);
2514 $$->append($5);
2517 function_arg_commalist4:
2518 function_arg ',' function_arg ',' function_arg ',' function_arg
2520 $$ = SQL_NEW_COMMALISTRULE;
2521 $$->append($1);
2522 $$->append($3);
2523 $$->append($5);
2524 $$->append($7);
2527 value_exp_commalist:
2528 value_exp
2529 {$$ = SQL_NEW_COMMALISTRULE;
2530 $$->append($1);}
2531 | value_exp_commalist ',' value_exp
2532 {$1->append($3);
2533 $$ = $1;}
2534 /* this rule is only valid if we check predicates */
2535 | value_exp_commalist ';' value_exp
2537 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
2539 $1->append($3);
2540 $$ = $1;
2542 else
2543 YYERROR;
2546 function_arg:
2547 value_exp
2548 | value_exp comparison value_exp
2550 $$ = SQL_NEW_RULE;
2551 $$->append($1);
2552 $$->append($2);
2553 $$->append($3);
2556 function_args_commalist:
2557 function_arg
2558 {$$ = SQL_NEW_COMMALISTRULE;
2559 $$->append($1);}
2560 | function_args_commalist ',' function_arg
2561 {$1->append($3);
2562 $$ = $1;}
2563 /* this rule is only valid if we check predicates */
2564 | function_args_commalist ';' function_arg
2566 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
2568 $1->append($3);
2569 $$ = $1;
2571 else
2572 YYERROR;
2576 value_exp:
2577 num_value_exp /*[^')']*/
2578 | string_value_exp
2579 | datetime_value_exp
2581 $$ = SQL_NEW_RULE;
2582 $$->append($1);
2585 string_value_exp:
2586 char_value_exp
2587 /* | bit_value_exp
2589 $$ = SQL_NEW_RULE;
2590 $$->append($1);
2592 */ ;
2593 char_value_exp:
2594 char_factor
2595 | concatenation
2597 concatenation:
2598 char_value_exp '+' char_factor
2600 $$ = SQL_NEW_RULE;
2601 $$->append($1);
2602 $$->append($2 = newNode("+", SQL_NODE_PUNCTUATION));
2603 $$->append($3);
2605 | value_exp SQL_CONCAT value_exp
2607 $$ = SQL_NEW_RULE;
2608 $$->append($1);
2609 $$->append($2);
2610 $$->append($3);
2614 char_primary:
2615 SQL_TOKEN_STRING
2616 | string_value_fct
2618 collate_clause:
2619 SQL_TOKEN_COLLATE table_node
2621 $$ = SQL_NEW_RULE;
2622 $$->append($1);
2623 $$->append($2);
2626 char_factor:
2627 char_primary
2628 | char_primary collate_clause
2630 $$ = SQL_NEW_RULE;
2631 $$->append($1);
2632 $$->append($2);
2635 string_value_fct:
2636 char_value_fct
2637 | bit_value_fct
2639 bit_value_fct:
2640 bit_substring_fct
2642 $$ = SQL_NEW_RULE;
2643 $$->append($1);
2646 bit_substring_fct:
2647 SQL_TOKEN_SUBSTRING '(' bit_value_exp SQL_TOKEN_FROM string_value_exp for_length ')'
2649 $$ = SQL_NEW_RULE;
2650 $$->append($1);
2651 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
2652 $$->append($3);
2653 $$->append($4);
2654 $$->append($5);
2655 $$->append($6);
2656 $$->append($7 = newNode(")", SQL_NODE_PUNCTUATION));
2659 bit_value_exp:
2660 bit_factor
2662 $$ = SQL_NEW_RULE;
2663 $$->append($1);
2667 bit_concatenation
2669 $$ = SQL_NEW_RULE;
2670 $$->append($1);
2673 bit_concatenation:
2674 bit_value_exp '+' bit_factor
2676 $$ = SQL_NEW_RULE;
2677 $$->append($1);
2678 $$->append($2 = newNode("+", SQL_NODE_PUNCTUATION));
2679 $$->append($3);
2683 bit_factor:
2684 bit_primary
2686 $$ = SQL_NEW_RULE;
2687 $$->append($1);
2690 bit_primary:
2691 {$$ = SQL_NEW_RULE;}
2692 /* value_exp_primary
2694 $$ = SQL_NEW_RULE;
2695 $$->append($1);
2697 | string_value_fct
2699 $$ = SQL_NEW_RULE;
2700 $$->append($1);
2703 char_value_fct:
2704 char_substring_fct
2705 | fold
2706 | form_conversion
2708 $$ = SQL_NEW_RULE;
2709 $$->append($1);
2711 | char_translation
2713 $$ = SQL_NEW_RULE;
2714 $$->append($1);
2716 | trim_fct
2718 $$ = SQL_NEW_RULE;
2719 $$->append($1);
2722 for_length:
2723 {$$ = SQL_NEW_RULE;}
2724 | SQL_TOKEN_FOR value_exp
2726 $$ = SQL_NEW_RULE;
2727 $$->append($1);
2728 $$->append($2);
2731 char_substring_fct:
2732 SQL_TOKEN_SUBSTRING '(' value_exp SQL_TOKEN_FROM value_exp for_length ')'
2734 $$ = SQL_NEW_RULE;
2735 $$->append($1);
2736 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
2737 $$->append($3);
2738 $$->append($4);
2739 $$->append($5);
2740 $$->append($6);
2741 $$->append($7 = newNode(")", SQL_NODE_PUNCTUATION));
2743 | SQL_TOKEN_SUBSTRING '(' value_exp_commalist ')'
2745 $$ = SQL_NEW_RULE;
2746 $$->append($1);
2747 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
2748 $$->append($3);
2749 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
2752 upper_lower:
2753 SQL_TOKEN_UPPER
2754 | SQL_TOKEN_LOWER
2756 fold:
2757 upper_lower '(' value_exp ')'
2759 $$ = SQL_NEW_RULE;
2760 $$->append($1);
2761 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
2762 $$->append($3);
2763 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
2766 form_conversion:
2767 SQL_TOKEN_CONVERT '(' string_value_exp SQL_TOKEN_USING table_node ')'
2769 $$ = SQL_NEW_RULE;
2770 $$->append($1);
2771 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
2772 $$->append($3);
2773 $$->append($4);
2774 $$->append($5);
2775 $$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));
2777 | SQL_TOKEN_CONVERT '(' cast_operand ',' cast_target ')'
2779 $$ = SQL_NEW_RULE;
2780 $$->append($1);
2781 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
2782 $$->append($3);
2783 $$->append($2 = newNode(",", SQL_NODE_PUNCTUATION));
2784 $$->append($5);
2785 $$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));
2788 char_translation:
2789 SQL_TOKEN_TRANSLATE '(' string_value_exp SQL_TOKEN_USING table_node ')'
2791 $$ = SQL_NEW_RULE;
2792 $$->append($1);
2793 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
2794 $$->append($3);
2795 $$->append($4);
2796 $$->append($5);
2797 $$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));
2800 trim_fct:
2801 SQL_TOKEN_TRIM '(' trim_operands ')'
2803 $$ = SQL_NEW_RULE;
2804 $$->append($1);
2805 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
2806 $$->append($3);
2807 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
2810 trim_operands:
2811 trim_spec value_exp SQL_TOKEN_FROM value_exp
2813 $$ = SQL_NEW_RULE;
2814 $$->append($1);
2815 $$->append($2);
2816 $$->append($3);
2817 $$->append($4);
2819 | trim_spec SQL_TOKEN_FROM value_exp
2821 $$ = SQL_NEW_RULE;
2822 $$->append($1);
2823 $$->append($2);
2824 $$->append($3);
2826 | value_exp SQL_TOKEN_FROM value_exp
2828 $$ = SQL_NEW_RULE;
2829 $$->append($1);
2830 $$->append($2);
2831 $$->append($3);
2833 | SQL_TOKEN_FROM value_exp
2835 $$ = SQL_NEW_RULE;
2836 $$->append($1);
2837 $$->append($2);
2839 | value_exp
2842 trim_spec:
2843 SQL_TOKEN_BOTH
2844 | SQL_TOKEN_LEADING
2845 | SQL_TOKEN_TRAILING
2848 derived_column:
2849 value_exp as_clause
2851 $$ = SQL_NEW_RULE;
2852 $$->append($1);
2853 $$->append($2);
2856 /* Tabellenname */
2857 table_node:
2858 table_name
2859 | schema_name
2860 | catalog_name
2862 catalog_name:
2863 SQL_TOKEN_NAME '.' schema_name
2865 $$ = SQL_NEW_RULE;
2866 $$->append($1);
2867 $$->append($2 = newNode(".", SQL_NODE_PUNCTUATION));
2868 $$->append($3);
2870 | SQL_TOKEN_NAME ':' schema_name
2872 $$ = SQL_NEW_RULE;
2873 $$->append($1);
2874 $$->append($2 = newNode(":", SQL_NODE_PUNCTUATION));
2875 $$->append($3);
2878 schema_name:
2879 SQL_TOKEN_NAME '.' table_name
2881 $$ = SQL_NEW_RULE;
2882 $$->append($1);
2883 $$->append($2 = newNode(".", SQL_NODE_PUNCTUATION));
2884 $$->append($3);
2888 table_name:
2889 SQL_TOKEN_NAME
2890 {$$ = SQL_NEW_RULE;
2891 $$->append($1);}
2893 /* Columns */
2894 column_ref:
2895 column
2896 {$$ = SQL_NEW_RULE;
2897 $$->append($1);}
2898 /* | table_node '.' column_val %prec '.'
2899 {$$ = SQL_NEW_RULE;
2900 $$->append($1);
2901 $$->append($2 = newNode(".", SQL_NODE_PUNCTUATION));
2902 $$->append($3);}
2904 | SQL_TOKEN_NAME '.' column_val %prec '.'
2905 {$$ = SQL_NEW_RULE;
2906 $$->append($1);
2907 $$->append($2 = newNode(".", SQL_NODE_PUNCTUATION));
2908 $$->append($3);
2910 | SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val %prec '.'
2911 {$$ = SQL_NEW_RULE;
2912 $$->append($1);
2913 $$->append($2 = newNode(".", SQL_NODE_PUNCTUATION));
2914 $$->append($3);
2915 $$->append($4 = newNode(".", SQL_NODE_PUNCTUATION));
2916 $$->append($5);}
2917 | SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val %prec '.'
2918 {$$ = SQL_NEW_RULE;
2919 $$->append($1);
2920 $$->append($2= newNode(".", SQL_NODE_PUNCTUATION));
2921 $$->append($3);
2922 $$->append($4 = newNode(".", SQL_NODE_PUNCTUATION));
2923 $$->append($5);
2924 $$->append($6 = newNode(".", SQL_NODE_PUNCTUATION));
2925 $$->append($7);
2927 | SQL_TOKEN_NAME ':' SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val %prec '.'
2928 {$$ = SQL_NEW_RULE;
2929 $$->append($1);
2930 $$->append($2= newNode(":", SQL_NODE_PUNCTUATION));
2931 $$->append($3);
2932 $$->append($4 = newNode(".", SQL_NODE_PUNCTUATION));
2933 $$->append($5);
2934 $$->append($6 = newNode(".", SQL_NODE_PUNCTUATION));
2935 $$->append($7);
2937 /* | SQL_TOKEN_NAME ';' SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val
2938 {$$ = SQL_NEW_RULE;
2939 $$->append($1);
2940 $$->append($2= newNode(";", SQL_NODE_PUNCTUATION));
2941 $$->append($3);
2942 $$->append($4 = newNode(".", SQL_NODE_PUNCTUATION));
2943 $$->append($5);
2944 $$->append($6 = newNode(".", SQL_NODE_PUNCTUATION));
2945 $$->append($7);
2947 */ ;
2949 /* data types */
2950 column_val:
2951 column
2952 {$$ = SQL_NEW_RULE;
2953 $$->append($1);}
2954 | '*'
2956 $$ = SQL_NEW_RULE;
2957 $$->append($1 = newNode("*", SQL_NODE_PUNCTUATION));
2960 data_type:
2961 SQL_TOKEN_CHARACTER
2962 | SQL_TOKEN_CHARACTER '(' SQL_TOKEN_INTNUM ')'
2963 {$$ = SQL_NEW_RULE;
2964 $$->append($1);
2965 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
2966 $$->append($3);
2967 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));}
2968 | SQL_TOKEN_NUMERIC
2969 | SQL_TOKEN_NUMERIC '(' SQL_TOKEN_INTNUM ')'
2970 {$$ = SQL_NEW_RULE;
2971 $$->append($1);
2972 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
2973 $$->append($3);
2974 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));}
2975 | SQL_TOKEN_NUMERIC '(' SQL_TOKEN_INTNUM ',' SQL_TOKEN_INTNUM ')'
2976 {$$ = SQL_NEW_RULE;
2977 $$->append($1);
2978 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
2979 $$->append($3);
2980 $$->append($4 = newNode(",", SQL_NODE_PUNCTUATION));
2981 $$->append($5);
2982 $$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));}
2983 | SQL_TOKEN_DECIMAL
2984 | SQL_TOKEN_DECIMAL '(' SQL_TOKEN_INTNUM ')'
2985 {$$ = SQL_NEW_RULE;
2986 $$->append($1);
2987 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
2988 $$->append($3);
2989 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));}
2990 | SQL_TOKEN_DECIMAL '(' SQL_TOKEN_INTNUM ',' SQL_TOKEN_INTNUM ')'
2991 {$$ = SQL_NEW_RULE;
2992 $$->append($1);
2993 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
2994 $$->append($3);
2995 $$->append($4 = newNode(",", SQL_NODE_PUNCTUATION));
2996 $$->append($5);
2997 $$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));}
2998 | SQL_TOKEN_INTEGER
2999 | SQL_TOKEN_SMALLINT
3000 | SQL_TOKEN_FLOAT
3001 | SQL_TOKEN_FLOAT '(' SQL_TOKEN_INTNUM ')'
3002 {$$ = SQL_NEW_RULE;
3003 $$->append($1);
3004 $$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
3005 $$->append($3);
3006 $$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));}
3007 | SQL_TOKEN_REAL
3008 | SQL_TOKEN_DOUBLE SQL_TOKEN_PRECISION
3009 {$$ = SQL_NEW_RULE;
3010 $$->append($1);
3011 $$->append($2);}
3014 /* the various things you can name */
3016 column:
3017 SQL_TOKEN_NAME
3018 | SQL_TOKEN_POSITION
3020 sal_uInt32 nNod = $$->getRuleID();
3021 delete $$;
3022 $$ = newNode(xxx_pGLOBAL_SQLPARSER->TokenIDToStr(nNod), SQL_NODE_NAME);
3024 | SQL_TOKEN_CHAR_LENGTH
3026 sal_uInt32 nNod = $$->getRuleID();
3027 delete $$;
3028 $$ = newNode(xxx_pGLOBAL_SQLPARSER->TokenIDToStr(nNod), SQL_NODE_NAME);
3030 | SQL_TOKEN_EXTRACT
3032 sal_uInt32 nNod = $$->getRuleID();
3033 delete $$;
3034 $$ = newNode(xxx_pGLOBAL_SQLPARSER->TokenIDToStr(nNod), SQL_NODE_NAME);
3038 cursor: SQL_TOKEN_NAME
3039 {$$ = SQL_NEW_RULE;
3040 $$->append($1);}
3043 /***
3044 module: SQL_TOKEN_NAME
3045 {$$ = SQL_NEW_RULE;
3046 $$->append($1);}
3048 ***/
3050 parameter:
3051 ':' SQL_TOKEN_NAME
3052 {$$ = SQL_NEW_RULE;
3053 $$->append($1 = newNode(":", SQL_NODE_PUNCTUATION));
3054 $$->append($2);}
3055 | '?'
3056 {$$ = SQL_NEW_RULE; // test
3057 $$->append($1 = newNode("?", SQL_NODE_PUNCTUATION));}
3058 | '[' SQL_TOKEN_NAME ']'
3059 {$$ = SQL_NEW_RULE;
3060 $$->append($1 = newNode("[", SQL_NODE_PUNCTUATION));
3061 $$->append($2);
3062 $$->append($3 = newNode("]", SQL_NODE_PUNCTUATION));}
3065 /***
3066 procedure: SQL_TOKEN_NAME
3067 {$$ = SQL_NEW_RULE;
3068 $$->append($1);}
3070 ***/
3072 range_variable:
3073 {$$ = SQL_NEW_RULE;}
3074 | opt_as SQL_TOKEN_NAME
3075 {$$ = SQL_NEW_RULE;
3076 $$->append($1);
3077 $$->append($2);
3081 user: SQL_TOKEN_NAME
3084 /* PREDICATECHECK RULES */
3085 sql:
3086 search_condition /* checking predicats */
3088 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // sql: rule 1
3090 $$ = $1;
3091 if ( SQL_ISRULE($$,search_condition) )
3093 $$->insert(0,newNode("(", SQL_NODE_PUNCTUATION));
3094 $$->append(newNode(")", SQL_NODE_PUNCTUATION));
3097 else
3098 YYERROR;
3100 | '(' sql ')' /* checking predicats */
3105 using namespace ::com::sun::star::sdbc;
3106 using namespace ::com::sun::star::beans;
3107 using namespace ::com::sun::star::uno;
3108 using namespace ::com::sun::star::i18n;
3109 using namespace ::com::sun::star::lang;
3110 using namespace ::com::sun::star::util;
3111 using namespace ::osl;
3112 using namespace ::dbtools;
3113 // using namespace connectivity;
3115 //============================================================
3116 //= a helper for static ascii pseudo-unicode strings
3117 //============================================================
3118 // string constants
3119 struct _ConstAsciiString_
3121 sal_Int32 length;
3122 sal_Char const* str;
3124 operator rtl::OUString () const { return rtl::OUString(str, length, RTL_TEXTENCODING_ASCII_US); }
3125 // operator ::rtl::OUString () const { return ::rtl::OUString(str, length, RTL_TEXTENCODING_ASCII_US); }
3126 operator const sal_Char * () const { return str; }
3127 operator ::rtl::OString() const { return str; }
3130 #define IMPLEMENT_CONSTASCII_STRING( name, string ) \
3131 _ConstAsciiString_ const name = { sizeof(string)-1, string }
3133 IMPLEMENT_CONSTASCII_STRING(ERROR_STR_GENERAL, "Syntax error in SQL expression");
3134 IMPLEMENT_CONSTASCII_STRING(ERROR_STR_VALUE_NO_LIKE, "The value #1 can not be used with LIKE.");
3135 IMPLEMENT_CONSTASCII_STRING(ERROR_STR_FIELD_NO_LIKE, "LIKE can not be used with this field.");
3136 IMPLEMENT_CONSTASCII_STRING(ERROR_STR_INVALID_COMPARE, "The entered criterion can not be compared with this field.");
3137 IMPLEMENT_CONSTASCII_STRING(ERROR_STR_INVALID_DATE_COMPARE, "The field can not be compared with a date.");
3138 IMPLEMENT_CONSTASCII_STRING(ERROR_STR_INVALID_REAL_COMPARE, "The field can not be compared with a floating point number.");
3139 IMPLEMENT_CONSTASCII_STRING(ERROR_STR_INVALID_INT_COMPARE, "The field can not be compared with a number.");
3140 IMPLEMENT_CONSTASCII_STRING(ERROR_STR_INVALID_TABLE, "The database does not contain a table named \"#\".");
3141 IMPLEMENT_CONSTASCII_STRING(ERROR_STR_INVALID_TABLE_OR_QUERY, "The database does contain neither a table nor a query named \"#\".");
3142 IMPLEMENT_CONSTASCII_STRING(ERROR_STR_INVALID_COLUMN, "The column \"#1\" is unknown in the table \"#2\".");
3143 IMPLEMENT_CONSTASCII_STRING(ERROR_STR_INVALID_TABLE_EXIST, "The database already contains a table or view with name \"#\".");
3144 IMPLEMENT_CONSTASCII_STRING(ERROR_STR_INVALID_QUERY_EXIST, "The database already contains a query with name \"#\".");
3146 IMPLEMENT_CONSTASCII_STRING(KEY_STR_LIKE, "LIKE");
3147 IMPLEMENT_CONSTASCII_STRING(KEY_STR_NOT, "NOT");
3148 IMPLEMENT_CONSTASCII_STRING(KEY_STR_NULL, "NULL");
3149 IMPLEMENT_CONSTASCII_STRING(KEY_STR_TRUE, "True");
3150 IMPLEMENT_CONSTASCII_STRING(KEY_STR_FALSE, "False");
3151 IMPLEMENT_CONSTASCII_STRING(KEY_STR_IS, "IS");
3152 IMPLEMENT_CONSTASCII_STRING(KEY_STR_BETWEEN, "BETWEEN");
3153 IMPLEMENT_CONSTASCII_STRING(KEY_STR_OR, "OR");
3154 IMPLEMENT_CONSTASCII_STRING(KEY_STR_AND, "AND");
3155 IMPLEMENT_CONSTASCII_STRING(KEY_STR_AVG, "AVG");
3156 IMPLEMENT_CONSTASCII_STRING(KEY_STR_COUNT, "COUNT");
3157 IMPLEMENT_CONSTASCII_STRING(KEY_STR_MAX, "MAX");
3158 IMPLEMENT_CONSTASCII_STRING(KEY_STR_MIN, "MIN");
3159 IMPLEMENT_CONSTASCII_STRING(KEY_STR_SUM, "SUM");
3160 IMPLEMENT_CONSTASCII_STRING(KEY_STR_EVERY, "EVERY");
3161 IMPLEMENT_CONSTASCII_STRING(KEY_STR_ANY, "ANY");
3162 IMPLEMENT_CONSTASCII_STRING(KEY_STR_SOME, "SOME");
3163 IMPLEMENT_CONSTASCII_STRING(KEY_STR_STDDEV_POP, "STDDEV_POP");
3164 IMPLEMENT_CONSTASCII_STRING(KEY_STR_STDDEV_SAMP, "STDDEV_SAMP");
3165 IMPLEMENT_CONSTASCII_STRING(KEY_STR_VAR_SAMP, "VAR_SAMP");
3166 IMPLEMENT_CONSTASCII_STRING(KEY_STR_VAR_POP, "VAR_POP");
3167 IMPLEMENT_CONSTASCII_STRING(KEY_STR_COLLECT, "COLLECT");
3168 IMPLEMENT_CONSTASCII_STRING(KEY_STR_FUSION, "FUSION");
3169 IMPLEMENT_CONSTASCII_STRING(KEY_STR_INTERSECTION, "INTERSECTION");
3171 IMPLEMENT_CONSTASCII_STRING(FIELD_STR_NULLDATE, "NullDate");
3173 IMPLEMENT_CONSTASCII_STRING(STR_SQL_TOKEN, "SQL_TOKEN_");
3175 //==========================================================================
3176 //= OParseContext
3177 //==========================================================================
3178 //-----------------------------------------------------------------------------
3179 OParseContext::OParseContext()
3183 //-----------------------------------------------------------------------------
3184 OParseContext::~OParseContext()
3188 //-----------------------------------------------------------------------------
3189 ::rtl::OUString OParseContext::getErrorMessage(ErrorCode _eCode) const
3191 ::rtl::OUString aMsg;
3192 switch (_eCode)
3194 case ERROR_GENERAL: aMsg = ERROR_STR_GENERAL; break;
3195 case ERROR_VALUE_NO_LIKE: aMsg = ERROR_STR_VALUE_NO_LIKE; break;
3196 case ERROR_FIELD_NO_LIKE: aMsg = ERROR_STR_FIELD_NO_LIKE; break;
3197 case ERROR_INVALID_COMPARE: aMsg = ERROR_STR_INVALID_COMPARE; break;
3198 case ERROR_INVALID_INT_COMPARE: aMsg = ERROR_STR_INVALID_INT_COMPARE; break;
3199 case ERROR_INVALID_DATE_COMPARE: aMsg = ERROR_STR_INVALID_DATE_COMPARE; break;
3200 case ERROR_INVALID_REAL_COMPARE: aMsg = ERROR_STR_INVALID_REAL_COMPARE; break;
3201 case ERROR_INVALID_TABLE: aMsg = ERROR_STR_INVALID_TABLE; break;
3202 case ERROR_INVALID_TABLE_OR_QUERY: aMsg = ERROR_STR_INVALID_TABLE_OR_QUERY; break;
3203 case ERROR_INVALID_COLUMN: aMsg = ERROR_STR_INVALID_COLUMN; break;
3204 case ERROR_INVALID_TABLE_EXIST: aMsg = ERROR_STR_INVALID_TABLE_EXIST; break;
3205 case ERROR_INVALID_QUERY_EXIST: aMsg = ERROR_STR_INVALID_QUERY_EXIST; break;
3206 default:
3207 OSL_ENSURE( false, "OParseContext::getErrorMessage: unknown error code!" );
3208 break;
3210 return aMsg;
3213 //-----------------------------------------------------------------------------
3214 ::rtl::OString OParseContext::getIntlKeywordAscii(InternationalKeyCode _eKey) const
3216 ::rtl::OString aKeyword;
3217 switch (_eKey)
3219 case KEY_LIKE: aKeyword = KEY_STR_LIKE; break;
3220 case KEY_NOT: aKeyword = KEY_STR_NOT; break;
3221 case KEY_NULL: aKeyword = KEY_STR_NULL; break;
3222 case KEY_TRUE: aKeyword = KEY_STR_TRUE; break;
3223 case KEY_FALSE: aKeyword = KEY_STR_FALSE; break;
3224 case KEY_IS: aKeyword = KEY_STR_IS; break;
3225 case KEY_BETWEEN: aKeyword = KEY_STR_BETWEEN; break;
3226 case KEY_OR: aKeyword = KEY_STR_OR; break;
3227 case KEY_AND: aKeyword = KEY_STR_AND; break;
3228 case KEY_AVG: aKeyword = KEY_STR_AVG; break;
3229 case KEY_COUNT: aKeyword = KEY_STR_COUNT; break;
3230 case KEY_MAX: aKeyword = KEY_STR_MAX; break;
3231 case KEY_MIN: aKeyword = KEY_STR_MIN; break;
3232 case KEY_SUM: aKeyword = KEY_STR_SUM; break;
3233 case KEY_EVERY: aKeyword = KEY_STR_EVERY; break;
3234 case KEY_ANY: aKeyword = KEY_STR_ANY; break;
3235 case KEY_SOME: aKeyword = KEY_STR_SOME; break;
3236 case KEY_STDDEV_POP: aKeyword = KEY_STR_STDDEV_POP; break;
3237 case KEY_STDDEV_SAMP: aKeyword = KEY_STR_STDDEV_SAMP; break;
3238 case KEY_VAR_SAMP: aKeyword = KEY_STR_VAR_SAMP; break;
3239 case KEY_VAR_POP: aKeyword = KEY_STR_VAR_POP; break;
3240 case KEY_COLLECT: aKeyword = KEY_STR_COLLECT; break;
3241 case KEY_FUSION: aKeyword = KEY_STR_FUSION; break;
3242 case KEY_INTERSECTION:aKeyword = KEY_STR_INTERSECTION; break;
3243 case KEY_NONE: break;
3244 default:
3245 OSL_ENSURE( false, "OParseContext::getIntlKeywordAscii: unknown key!" );
3246 break;
3248 return aKeyword;
3251 //-----------------------------------------------------------------------------
3252 IParseContext::InternationalKeyCode OParseContext::getIntlKeyCode(const ::rtl::OString& rToken) const
3254 static IParseContext::InternationalKeyCode Intl_TokenID[] =
3256 KEY_LIKE, KEY_NOT, KEY_NULL, KEY_TRUE,
3257 KEY_FALSE, KEY_IS, KEY_BETWEEN, KEY_OR,
3258 KEY_AND, KEY_AVG, KEY_COUNT, KEY_MAX,
3259 KEY_MIN, KEY_SUM, KEY_EVERY,KEY_ANY,KEY_SOME,
3260 KEY_STDDEV_POP,KEY_STDDEV_SAMP,KEY_VAR_SAMP,
3261 KEY_VAR_POP,KEY_COLLECT,KEY_FUSION,KEY_INTERSECTION
3264 sal_uInt32 nCount = sizeof Intl_TokenID / sizeof Intl_TokenID[0];
3265 for (sal_uInt32 i = 0; i < nCount; i++)
3267 ::rtl::OString aKey = getIntlKeywordAscii(Intl_TokenID[i]);
3268 if (rToken.equalsIgnoreAsciiCase(aKey))
3269 return Intl_TokenID[i];
3272 return KEY_NONE;
3275 //------------------------------------------------------------------------------
3276 static Locale& impl_getLocaleInstance( )
3278 static Locale s_aLocale(
3279 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "en" ) ),
3280 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "US" ) ),
3281 ::rtl::OUString( )
3283 return s_aLocale;
3286 //------------------------------------------------------------------------------
3287 void OParseContext::setDefaultLocale( const ::com::sun::star::lang::Locale& _rLocale )
3289 impl_getLocaleInstance() = _rLocale;
3292 //------------------------------------------------------------------------------
3293 Locale OParseContext::getPreferredLocale( ) const
3295 return getDefaultLocale();
3298 //------------------------------------------------------------------------------
3299 const Locale& OParseContext::getDefaultLocale()
3301 return impl_getLocaleInstance();
3304 //==========================================================================
3305 //= misc
3306 //==========================================================================
3307 // Der (leider globale) yylval fuer die Uebergabe von
3308 // Werten vom Scanner an den Parser. Die globale Variable
3309 // wird nur kurzzeitig verwendet, der Parser liest die Variable
3310 // sofort nach dem Scanner-Aufruf in eine gleichnamige eigene
3311 // Member-Variable.
3313 const double fMilliSecondsPerDay = 86400000.0;
3315 //------------------------------------------------------------------------------
3318 //------------------------------------------------------------------
3319 ::rtl::OUString ConvertLikeToken(const OSQLParseNode* pTokenNode, const OSQLParseNode* pEscapeNode, sal_Bool bInternational)
3321 ::rtl::OUStringBuffer aMatchStr;
3322 if (pTokenNode->isToken())
3324 sal_Unicode cEscape = 0;
3325 if (pEscapeNode->count())
3326 cEscape = pEscapeNode->getChild(1)->getTokenValue().toChar();
3328 // Platzhalter austauschen
3329 aMatchStr = pTokenNode->getTokenValue();
3330 const sal_Int32 nLen = aMatchStr.getLength();
3331 ::rtl::OUStringBuffer sSearch,sReplace;
3332 if ( bInternational )
3334 sSearch.appendAscii("%_",2);
3335 sReplace.appendAscii("*?",2);
3337 else
3339 sSearch.appendAscii("*?",2);
3340 sReplace.appendAscii("%_",2);
3343 for (sal_Int32 i = 0; i < nLen; i++)
3345 const sal_Unicode c = aMatchStr.charAt(i);
3346 if (c == sSearch.charAt(0) || c == sSearch.charAt(1))
3348 if (i > 0 && aMatchStr.charAt(i-1) == cEscape)
3349 continue;
3350 else
3352 const sal_Unicode cCharacter = sReplace.charAt( (c == sSearch.charAt(0)) ? 0 : 1);
3353 aMatchStr.setCharAt(i , cCharacter);
3358 return aMatchStr.makeStringAndClear();
3361 //==========================================================================
3362 //= OSQLParser
3363 //==========================================================================
3365 sal_uInt32 OSQLParser::s_nRuleIDs[OSQLParseNode::rule_count + 1];
3366 OSQLParser::RuleIDMap OSQLParser::s_aReverseRuleIDLookup;
3367 OParseContext OSQLParser::s_aDefaultContext;
3369 sal_Int32 OSQLParser::s_nRefCount = 0;
3370 // ::osl::Mutex OSQLParser::s_aMutex;
3371 OSQLScanner* OSQLParser::s_pScanner = 0;
3372 OSQLParseNodesGarbageCollector* OSQLParser::s_pGarbageCollector = 0;
3373 ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XLocaleData> OSQLParser::s_xLocaleData = NULL;
3374 //-----------------------------------------------------------------------------
3375 void setParser(OSQLParser* _pParser)
3377 xxx_pGLOBAL_SQLPARSER = _pParser;
3379 // -------------------------------------------------------------------------
3380 void OSQLParser::setParseTree(OSQLParseNode * pNewParseTree)
3382 ::osl::MutexGuard aGuard(getMutex());
3383 m_pParseTree = pNewParseTree;
3385 //-----------------------------------------------------------------------------
3386 OSQLParseNode* OSQLParser::parseTree(::rtl::OUString& rErrorMessage,
3387 const ::rtl::OUString& rStatement,
3388 sal_Bool bInternational)
3392 // Guard the parsing
3393 ::osl::MutexGuard aGuard(getMutex());
3394 // must be reset
3395 setParser(this);
3397 // defines how to scan
3398 s_pScanner->SetRule(s_pScanner->GetSQLRule()); // initial
3399 s_pScanner->prepareScan(rStatement, m_pContext, bInternational);
3401 SQLyylval.pParseNode = NULL;
3402 // SQLyypvt = NULL;
3403 m_pParseTree = NULL;
3404 m_sErrorMessage = ::rtl::OUString();
3406 // ... und den Parser anwerfen ...
3407 if (SQLyyparse() != 0)
3409 // only set the error message, if it's not already set
3410 if (!m_sErrorMessage.getLength())
3411 m_sErrorMessage = s_pScanner->getErrorMessage();
3412 if (!m_sErrorMessage.getLength())
3413 m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_GENERAL);
3415 rErrorMessage = m_sErrorMessage;
3417 // clear the garbage collector
3418 (*s_pGarbageCollector)->clearAndDelete();
3419 return NULL;
3421 else
3423 (*s_pGarbageCollector)->clear();
3425 // Das Ergebnis liefern (den Root Parse Node):
3427 // OSL_ENSURE(Sdbyyval.pParseNode != NULL,"OSQLParser: Parser hat keinen ParseNode geliefert");
3428 // return Sdbyyval.pParseNode;
3429 // geht nicht wegen Bug in MKS YACC-erzeugtem Code (es wird ein falscher ParseNode
3430 // geliefert).
3432 // Stattdessen setzt die Parse-Routine jetzt den Member pParseTree
3433 // - einfach diesen zurueckliefern:
3434 OSL_ENSURE(m_pParseTree != NULL,"OSQLParser: Parser hat keinen ParseTree geliefert");
3435 return m_pParseTree;
3438 //-----------------------------------------------------------------------------
3439 ::rtl::OString OSQLParser::TokenIDToStr(sal_uInt32 nTokenID, const IParseContext* pContext)
3441 ::rtl::OString aStr;
3442 if (pContext)
3444 IParseContext::InternationalKeyCode eKeyCode = IParseContext::KEY_NONE;
3445 switch( nTokenID )
3447 case SQL_TOKEN_LIKE: eKeyCode = IParseContext::KEY_LIKE; break;
3448 case SQL_TOKEN_NOT: eKeyCode = IParseContext::KEY_NOT; break;
3449 case SQL_TOKEN_NULL: eKeyCode = IParseContext::KEY_NULL; break;
3450 case SQL_TOKEN_TRUE: eKeyCode = IParseContext::KEY_TRUE; break;
3451 case SQL_TOKEN_FALSE: eKeyCode = IParseContext::KEY_FALSE; break;
3452 case SQL_TOKEN_IS: eKeyCode = IParseContext::KEY_IS; break;
3453 case SQL_TOKEN_BETWEEN: eKeyCode = IParseContext::KEY_BETWEEN; break;
3454 case SQL_TOKEN_OR: eKeyCode = IParseContext::KEY_OR; break;
3455 case SQL_TOKEN_AND: eKeyCode = IParseContext::KEY_AND; break;
3456 case SQL_TOKEN_AVG: eKeyCode = IParseContext::KEY_AVG; break;
3457 case SQL_TOKEN_COUNT: eKeyCode = IParseContext::KEY_COUNT; break;
3458 case SQL_TOKEN_MAX: eKeyCode = IParseContext::KEY_MAX; break;
3459 case SQL_TOKEN_MIN: eKeyCode = IParseContext::KEY_MIN; break;
3460 case SQL_TOKEN_SUM: eKeyCode = IParseContext::KEY_SUM; break;
3462 if ( eKeyCode != IParseContext::KEY_NONE )
3463 aStr = pContext->getIntlKeywordAscii(eKeyCode);
3466 if (!aStr.getLength())
3468 aStr = yytname[YYTRANSLATE(nTokenID)];
3469 if(!aStr.compareTo("SQL_TOKEN_",10))
3470 aStr = aStr.copy(10);
3472 return aStr;
3475 //-----------------------------------------------------------------------------
3476 ::rtl::OUString OSQLParser::RuleIDToStr(sal_uInt32 nRuleID)
3478 OSL_ENSURE(nRuleID < (sizeof yytname/sizeof yytname[0]), "OSQLParser::RuleIDToStr: Invalid nRuleId!");
3479 return ::rtl::OUString::createFromAscii(yytname[nRuleID]);
3482 //-----------------------------------------------------------------------------
3483 sal_uInt32 OSQLParser::StrToRuleID(const ::rtl::OString & rValue)
3485 // In yysvar nach dem angegebenen Namen suchen, den Index zurueckliefern
3486 // (oder 0, wenn nicht gefunden)
3487 static sal_uInt32 nLen = sizeof(yytname)/sizeof(yytname[0]);
3488 for (sal_uInt32 i = YYTRANSLATE(SQL_TOKEN_INVALIDSYMBOL); i < (nLen-1); i++)
3490 if (yytname && rValue == yytname[i])
3491 return i;
3494 // Nicht gefunden
3495 return 0;
3498 //-----------------------------------------------------------------------------
3499 OSQLParseNode::Rule OSQLParser::RuleIDToRule( sal_uInt32 _nRule )
3501 return s_aReverseRuleIDLookup[ _nRule ];
3504 //-----------------------------------------------------------------------------
3505 sal_uInt32 OSQLParser::RuleID(OSQLParseNode::Rule eRule)
3507 return s_nRuleIDs[(sal_uInt16)eRule];
3509 // -------------------------------------------------------------------------
3510 sal_Int16 OSQLParser::buildNode(OSQLParseNode*& pAppend,OSQLParseNode* pCompare,OSQLParseNode* pLiteral,OSQLParseNode* pLiteral2)
3512 OSQLParseNode* pColumnRef = new OSQLInternalNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::column_ref));
3513 pColumnRef->append(new OSQLInternalNode(m_sFieldName,SQL_NODE_NAME));
3514 OSQLParseNode* pComp = NULL;
3515 if ( SQL_ISTOKEN( pCompare, BETWEEN) && pLiteral2 )
3516 pComp = new OSQLInternalNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::between_predicate));
3517 else
3518 pComp = new OSQLInternalNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::comparison_predicate));
3520 pComp->append(pColumnRef);
3521 pComp->append(pCompare);
3522 pComp->append(pLiteral);
3523 if ( pLiteral2 )
3525 pComp->append(new OSQLInternalNode(aEmptyString, SQL_NODE_KEYWORD,SQL_TOKEN_AND));
3526 pComp->append(pLiteral2);
3528 pAppend->append(pComp);
3529 return 1;
3531 //-----------------------------------------------------------------------------
3532 sal_Int16 OSQLParser::buildStringNodes(OSQLParseNode*& pLiteral)
3534 if(!pLiteral)
3535 return 1;
3537 if(SQL_ISRULE(pLiteral,set_fct_spec) || SQL_ISRULE(pLiteral,general_set_fct) || SQL_ISRULE(pLiteral,column_ref)
3538 || SQL_ISRULE(pLiteral,subquery))
3539 return 1; // here I have a function that I can't transform into a string
3541 if(pLiteral->getNodeType() == SQL_NODE_INTNUM || pLiteral->getNodeType() == SQL_NODE_APPROXNUM || pLiteral->getNodeType() == SQL_NODE_ACCESS_DATE)
3543 OSQLParseNode* pParent = pLiteral->getParent();
3545 OSQLParseNode* pNewNode = new OSQLInternalNode(pLiteral->getTokenValue(), SQL_NODE_STRING);
3546 pParent->replace(pLiteral, pNewNode);
3547 delete pLiteral;
3548 pLiteral = NULL;
3549 return 1;
3552 for(sal_uInt32 i=0;i<pLiteral->count();++i)
3554 OSQLParseNode* pChild = pLiteral->getChild(i);
3555 buildStringNodes(pChild);
3557 if(SQL_ISRULE(pLiteral,term) || SQL_ISRULE(pLiteral,value_exp_primary))
3559 m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_COMPARE);
3560 return 0;
3562 return 1;
3564 //-----------------------------------------------------------------------------
3565 sal_Int16 OSQLParser::buildComparsionRule(OSQLParseNode*& pAppend,OSQLParseNode* pLiteral)
3567 OSQLParseNode* pComp = new OSQLInternalNode(::rtl::OUString::createFromAscii("="), SQL_NODE_EQUAL);
3568 return buildPredicateRule(pAppend,pLiteral,pComp);
3572 //-----------------------------------------------------------------------------
3573 void OSQLParser::reduceLiteral(OSQLParseNode*& pLiteral, sal_Bool bAppendBlank)
3575 OSL_ENSURE(pLiteral->isRule(), "This is no ::com::sun::star::chaos::Rule");
3576 OSL_ENSURE(pLiteral->count() == 2, "OSQLParser::ReduceLiteral() Invalid count");
3577 OSQLParseNode* pTemp = pLiteral;
3578 ::rtl::OUStringBuffer aValue(pLiteral->getChild(0)->getTokenValue());
3579 if (bAppendBlank)
3581 aValue.appendAscii(" ");
3584 aValue.append(pLiteral->getChild(1)->getTokenValue());
3586 pLiteral = new OSQLInternalNode(aValue.makeStringAndClear(),SQL_NODE_STRING);
3587 delete pTemp;
3590 // -------------------------------------------------------------------------
3591 void OSQLParser::error(sal_Char *fmt)
3593 if(!m_sErrorMessage.getLength())
3595 ::rtl::OUString sStr(fmt,strlen(fmt),RTL_TEXTENCODING_UTF8);
3596 ::rtl::OUString sSQL_TOKEN(::rtl::OUString::createFromAscii("SQL_TOKEN_"));
3598 sal_Int32 nPos1 = sStr.indexOf(sSQL_TOKEN);
3599 if(nPos1 != -1)
3601 ::rtl::OUString sFirst = sStr.copy(0,nPos1);
3602 sal_Int32 nPos2 = sStr.indexOf(sSQL_TOKEN,nPos1+1);
3603 if(nPos2 != -1)
3605 ::rtl::OUString sSecond = sStr.copy(nPos1+sSQL_TOKEN.getLength(),nPos2-nPos1-sSQL_TOKEN.getLength());
3606 sFirst += sSecond;
3607 sFirst += sStr.copy(nPos2+sSQL_TOKEN.getLength());
3609 else
3610 sFirst += sStr.copy(nPos1+sSQL_TOKEN.getLength());
3612 m_sErrorMessage = sFirst;
3614 else
3615 m_sErrorMessage = sStr;
3617 ::rtl::OUString aError = s_pScanner->getErrorMessage();
3618 if(aError.getLength())
3620 m_sErrorMessage += ::rtl::OUString::createFromAscii(", ");
3621 m_sErrorMessage += aError;
3625 // -------------------------------------------------------------------------
3626 int OSQLParser::SQLlex()
3628 return s_pScanner->SQLlex();
3631 #if defined __SUNPRO_CC
3632 #pragma enable_warn
3633 #elif defined _MSC_VER
3634 #pragma warning(pop)
3635 #endif