tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / connectivity / source / parse / sqlbison.y
blob849f925d763706855c55233aad6075d702f76235
1 %glr-parser
2 %token-table
3 %{
4 /*
5 * This file is part of the LibreOffice project.
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 * This file incorporates work covered by the following license notice:
13 * Licensed to the Apache Software Foundation (ASF) under one or more
14 * contributor license agreements. See the NOTICE file distributed
15 * with this work for additional information regarding copyright
16 * ownership. The ASF licenses this file to you under the Apache
17 * License, Version 2.0 (the "License"); you may not use this file
18 * except in compliance with the License. You may obtain a copy of
19 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <vector>
23 #include <string.h>
25 #include <connectivity/sqlnode.hxx>
26 #include <connectivity/sqlparse.hxx>
27 #include <connectivity/sqlbison_exports.hxx>
28 #include <connectivity/sqlscan.hxx>
29 #include <connectivity/internalnode.hxx>
30 #include <com/sun/star/lang/Locale.hpp>
31 #include <com/sun/star/sdbc/DataType.hpp>
32 #include <com/sun/star/util/Date.hpp>
33 #include <com/sun/star/util/DateTime.hpp>
34 #include <com/sun/star/util/Time.hpp>
35 #include <com/sun/star/util/XNumberFormatter.hpp>
36 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
37 #include <com/sun/star/util/XNumberFormats.hpp>
38 #include <com/sun/star/util/NumberFormat.hpp>
39 #include <com/sun/star/util/XNumberFormatTypes.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/i18n/KParseType.hpp>
42 #include <com/sun/star/i18n/KParseTokens.hpp>
44 #include <osl/diagnose.h>
45 #include "connectivity/dbconversion.hxx"
46 #include <rtl/ustrbuf.hxx>
47 #include <sal/log.hxx>
49 #if defined _MSC_VER
50 #pragma warning(push)
51 #pragma warning(disable: 4324) // structure was padded due to alignment specifier
52 #pragma warning(disable: 4065) // switch statement contains 'default' but no 'case' labels
53 #pragma warning(disable: 4702) // unreachable code
54 #endif
56 #ifdef __GNUC__
57 # pragma GCC diagnostic ignored "-Wwrite-strings"
58 # pragma GCC diagnostic ignored "-Wunused-function"
59 #endif
61 inline connectivity::OSQLInternalNode* newNode(const char* pNewValue,
62 const connectivity::SQLNodeType eNodeType,
63 const sal_uInt32 nNodeID = 0);
65 inline connectivity::OSQLInternalNode* newNode(const OString& _newValue,
66 const connectivity::SQLNodeType eNodeType,
67 const sal_uInt32 nNodeID = 0);
69 inline connectivity::OSQLInternalNode* newNode(const OUString& _newValue,
70 const connectivity::SQLNodeType eNodeType,
71 const sal_uInt32 nNodeID = 0);
74 // yyi is the internal number of the rule that is currently being reduced
75 // This can be mapped to external rule number via the yyrmap.
76 #if defined YYBISON && YYBISON >= 30800
77 #define SQL_NEW_RULE newNode("", SQLNodeType::Rule, yyr1[yyrule])
78 #define SQL_NEW_LISTRULE newNode("", SQLNodeType::ListRule, yyr1[yyrule])
79 #define SQL_NEW_COMMALISTRULE newNode("", SQLNodeType::CommaListRule, yyr1[yyrule])
80 #else
81 #define SQL_NEW_RULE newNode("", SQLNodeType::Rule, yyr1[yyn])
82 #define SQL_NEW_LISTRULE newNode("", SQLNodeType::ListRule, yyr1[yyn])
83 #define SQL_NEW_COMMALISTRULE newNode("", SQLNodeType::CommaListRule, yyr1[yyn])
84 #endif
87 extern connectivity::OSQLParser* xxx_pGLOBAL_SQLPARSER;
89 #define YYERROR_VERBOSE
91 #define SQLyyerror(s) \
92 { \
93 xxx_pGLOBAL_SQLPARSER->error(s); \
96 using namespace connectivity;
97 #define SQLyylex xxx_pGLOBAL_SQLPARSER->SQLlex
99 /* symbolic tokens */
101 %union {
102 connectivity::OSQLParseNode * pParseNode;
104 %type <pParseNode> '(' ')' ',' ':' ';' '?' '[' ']' '{' '}' '.' 'K' 'M' 'G' 'T' 'P'
106 %token <pParseNode> SQL_TOKEN_STRING SQL_TOKEN_ACCESS_DATE SQL_TOKEN_INT SQL_TOKEN_REAL_NUM
107 %token <pParseNode> SQL_TOKEN_INTNUM SQL_TOKEN_APPROXNUM SQL_TOKEN_NOT SQL_TOKEN_NAME
110 %nonassoc <pParseNode> SQL_TOKEN_UMINUS
114 /* literal keyword tokens */
116 %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
118 %token <pParseNode> SQL_TOKEN_BETWEEN SQL_TOKEN_BIT SQL_TOKEN_BOTH SQL_TOKEN_BY
120 %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
121 %token <pParseNode> SQL_TOKEN_CURRENT SQL_TOKEN_CURSOR
123 %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
124 %token <pParseNode> SQL_TOKEN_DISTINCT SQL_TOKEN_DOUBLE SQL_TOKEN_DROP
126 %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
128 %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
130 %left <pParseNode> SQL_TOKEN_JOIN
131 %token <pParseNode> SQL_TOKEN_KEY SQL_TOKEN_LEADING SQL_TOKEN_LIKE SQL_TOKEN_LOCAL SQL_TOKEN_LOWER
132 %token <pParseNode> SQL_TOKEN_MAX SQL_TOKEN_MIN SQL_TOKEN_NATURAL SQL_TOKEN_NCHAR SQL_TOKEN_NULL SQL_TOKEN_NUMERIC
134 %token <pParseNode> SQL_TOKEN_OCTET_LENGTH SQL_TOKEN_OF SQL_TOKEN_ON SQL_TOKEN_OPTION SQL_TOKEN_ORDER SQL_TOKEN_OUTER
136 %token <pParseNode> SQL_TOKEN_PRECISION SQL_TOKEN_PRIMARY SQL_TOKEN_PRIVILEGES SQL_TOKEN_PROCEDURE SQL_TOKEN_PUBLIC
137 %token <pParseNode> SQL_TOKEN_REAL SQL_TOKEN_REFERENCES SQL_TOKEN_ROLLBACK
139 %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
141 %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
142 %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
143 %token <pParseNode> SQL_TOKEN_WHERE SQL_TOKEN_WITH SQL_TOKEN_WORK SQL_TOKEN_ZONE
145 /* ODBC KEYWORDS */
146 %token <pParseNode> SQL_TOKEN_CALL SQL_TOKEN_D SQL_TOKEN_FN SQL_TOKEN_T SQL_TOKEN_TS SQL_TOKEN_OJ
147 /* string functions */
148 %token <pParseNode> SQL_TOKEN_ASCII SQL_TOKEN_BIT_LENGTH SQL_TOKEN_CHAR SQL_TOKEN_CHAR_LENGTH SQL_TOKEN_SQL_TOKEN_INTNUM
149 %token <pParseNode> SQL_TOKEN_CONCAT
150 %token <pParseNode> SQL_TOKEN_DIFFERENCE SQL_TOKEN_INSERT SQL_TOKEN_LCASE SQL_TOKEN_LEFT SQL_TOKEN_LENGTH SQL_TOKEN_LOCATE
151 %token <pParseNode> SQL_TOKEN_LOCATE_2 SQL_TOKEN_LTRIM SQL_TOKEN_POSITION SQL_TOKEN_REPEAT SQL_TOKEN_REPLACE
152 %token <pParseNode> SQL_TOKEN_RIGHT SQL_TOKEN_RTRIM SQL_TOKEN_SOUNDEX SQL_TOKEN_SPACE SQL_TOKEN_SUBSTRING SQL_TOKEN_UCASE
154 /* time and date functions */
155 %token <pParseNode> SQL_TOKEN_CURRENT_DATE SQL_TOKEN_CURRENT_TIME SQL_TOKEN_CURRENT_TIMESTAMP SQL_TOKEN_CURDATE SQL_TOKEN_CURTIME
156 %token <pParseNode> SQL_TOKEN_DAYNAME SQL_TOKEN_DAYOFMONTH SQL_TOKEN_DAYOFWEEK SQL_TOKEN_DAYOFYEAR SQL_TOKEN_EXTRACT
157 %token <pParseNode> SQL_TOKEN_HOUR SQL_TOKEN_MILLISECOND SQL_TOKEN_MINUTE SQL_TOKEN_MONTH SQL_TOKEN_MONTHNAME SQL_TOKEN_NOW SQL_TOKEN_QUARTER SQL_TOKEN_DATEDIFF
158 %token <pParseNode> SQL_TOKEN_SECOND SQL_TOKEN_TIMESTAMPADD SQL_TOKEN_TIMESTAMPDIFF SQL_TOKEN_TIMEVALUE SQL_TOKEN_WEEK SQL_TOKEN_WEEKDAY SQL_TOKEN_YEAR SQL_TOKEN_YEARDAY
159 %token <pParseNode> SQL_TOKEN_DATEADD
161 /* numeric functions */
162 %token <pParseNode> SQL_TOKEN_ABS SQL_TOKEN_ACOS SQL_TOKEN_ASIN SQL_TOKEN_ATAN SQL_TOKEN_ATAN2 SQL_TOKEN_CEILING
163 %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
164 %token <pParseNode> SQL_TOKEN_LOG10 SQL_TOKEN_MOD SQL_TOKEN_PI SQL_TOKEN_POWER SQL_TOKEN_RADIANS SQL_TOKEN_RAND SQL_TOKEN_ROUNDMAGIC
165 %token <pParseNode> SQL_TOKEN_ROUND SQL_TOKEN_SIGN SQL_TOKEN_SIN SQL_TOKEN_SQRT SQL_TOKEN_TAN SQL_TOKEN_TRUNCATE
167 // computational operation
168 %token <pParseNode> SQL_TOKEN_EVERY SQL_TOKEN_INTERSECTION SQL_TOKEN_FUSION SQL_TOKEN_COLLECT SQL_TOKEN_VAR_POP SQL_TOKEN_VAR_SAMP
169 %token <pParseNode> SQL_TOKEN_STDDEV_SAMP SQL_TOKEN_STDDEV_POP
171 %token <pParseNode> SQL_TOKEN_RANK SQL_TOKEN_DENSE_RANK SQL_TOKEN_PERCENT_RANK SQL_TOKEN_CUME_DIST SQL_TOKEN_PERCENTILE_CONT SQL_TOKEN_PERCENTILE_DISC SQL_TOKEN_WITHIN SQL_TOKEN_ARRAY_AGG
172 %token <pParseNode> SQL_TOKEN_CASE SQL_TOKEN_THEN SQL_TOKEN_END SQL_TOKEN_NULLIF SQL_TOKEN_COALESCE SQL_TOKEN_WHEN SQL_TOKEN_ELSE
173 %token <pParseNode> SQL_TOKEN_BEFORE SQL_TOKEN_AFTER SQL_TOKEN_INSTEAD SQL_TOKEN_EACH SQL_TOKEN_REFERENCING SQL_TOKEN_BEGIN SQL_TOKEN_ATOMIC SQL_TOKEN_TRIGGER SQL_TOKEN_ROW SQL_TOKEN_STATEMENT
174 %token <pParseNode> SQL_TOKEN_NEW SQL_TOKEN_OLD
175 %token <pParseNode> SQL_TOKEN_VALUE SQL_TOKEN_CURRENT_CATALOG SQL_TOKEN_CURRENT_DEFAULT_TRANSFORM_GROUP SQL_TOKEN_CURRENT_PATH SQL_TOKEN_CURRENT_ROLE SQL_TOKEN_CURRENT_SCHEMA SQL_TOKEN_CURRENT_USER
176 %token <pParseNode> SQL_TOKEN_SESSION_USER SQL_TOKEN_SYSTEM_USER SQL_TOKEN_VARCHAR SQL_TOKEN_VARBINARY SQL_TOKEN_VARYING SQL_TOKEN_OBJECT SQL_TOKEN_NCLOB SQL_TOKEN_NATIONAL
177 %token <pParseNode> SQL_TOKEN_LARGE SQL_TOKEN_CLOB SQL_TOKEN_BLOB SQL_TOKEN_BIGINT SQL_TOKEN_BINARY SQL_TOKEN_WITHOUT SQL_TOKEN_BOOLEAN SQL_TOKEN_INTERVAL
178 // window function
179 %token <pParseNode> SQL_TOKEN_OVER SQL_TOKEN_ROW_NUMBER SQL_TOKEN_NTILE SQL_TOKEN_LEAD SQL_TOKEN_LAG SQL_TOKEN_RESPECT SQL_TOKEN_IGNORE SQL_TOKEN_NULLS
180 %token <pParseNode> SQL_TOKEN_FIRST_VALUE SQL_TOKEN_LAST_VALUE SQL_TOKEN_NTH_VALUE SQL_TOKEN_FIRST SQL_TOKEN_LAST
181 %token <pParseNode> SQL_TOKEN_EXCLUDE SQL_TOKEN_OTHERS SQL_TOKEN_TIES SQL_TOKEN_FOLLOWING SQL_TOKEN_UNBOUNDED SQL_TOKEN_PRECEDING SQL_TOKEN_RANGE SQL_TOKEN_ROWS
182 %token <pParseNode> SQL_TOKEN_PARTITION SQL_TOKEN_WINDOW SQL_TOKEN_NO
183 // LIMIT and OFFSEt
184 %token <pParseNode> SQL_TOKEN_LIMIT SQL_TOKEN_OFFSET SQL_TOKEN_NEXT SQL_TOKEN_ONLY
186 /* operators */
187 %left SQL_TOKEN_NAME
188 %left <pParseNode> SQL_TOKEN_OR
189 %left <pParseNode> SQL_TOKEN_AND
191 %left <pParseNode> SQL_LESSEQ SQL_GREATEQ SQL_NOTEQUAL SQL_LESS SQL_GREAT SQL_EQUAL /* '<' '>' = <> < > <= >= != */
192 %left <pParseNode> '+' '-' SQL_CONCAT
193 %left <pParseNode> '*' '/'
194 %left SQL_TOKEN_NATURAL SQL_TOKEN_CROSS SQL_TOKEN_FULL SQL_TOKEN_LEFT SQL_TOKEN_RIGHT
195 %left ')'
196 %right '='
197 %right '.'
198 %right '('
201 %token <pParseNode> SQL_TOKEN_INVALIDSYMBOL
203 /*%type <pParseNode> sql_single_statement */
205 %type <pParseNode> sql /*schema */
206 %type <pParseNode> column_def_opt_list column_def_opt table_constraint_def column_commalist
207 %type <pParseNode> view_def opt_with_check_option opt_column_commalist privilege_def
208 %type <pParseNode> opt_with_grant_option privileges operation_commalist operation
209 %type <pParseNode> grantee_commalist grantee opt_order_by_clause ordering_spec_commalist
210 %type <pParseNode> ordering_spec opt_asc_desc manipulative_statement commit_statement
211 %type <pParseNode> /*delete_statement_positioned*/ delete_statement_searched fetch_statement
212 %type <pParseNode> insert_statement values_or_query_spec
213 %type <pParseNode> rollback_statement select_statement_into opt_all_distinct
214 %type <pParseNode> /*update_statement_positioned*/ assignment_commalist assignment
215 %type <pParseNode> update_statement_searched target_commalist target opt_where_clause
216 %type <pParseNode> select_statement selection table_exp from_clause table_ref_commalist table_ref
217 %type <pParseNode> where_clause opt_group_by_clause column_ref_commalist opt_having_clause
218 %type <pParseNode> search_condition predicate comparison_predicate comparison_predicate_part_2 between_predicate between_predicate_part_2
219 %type <pParseNode> like_predicate opt_escape test_for_null null_predicate_part_2 in_predicate in_predicate_part_2 character_like_predicate_part_2 other_like_predicate_part_2
220 %type <pParseNode> all_or_any_predicate any_all_some existence_test subquery quantified_comparison_predicate_part_2
221 %type <pParseNode> scalar_exp_commalist parameter_ref literal parenthesized_boolean_value_expression
222 %type <pParseNode> column_ref data_type column cursor parameter range_variable user /*like_check*/ datetime_unit
223 /* new rules at OJ */
224 %type <pParseNode> derived_column as_clause table_name num_primary term num_value_exp
225 %type <pParseNode> value_exp_primary num_value_fct unsigned_value_spec cast_spec set_fct_spec scalar_subquery
226 %type <pParseNode> position_exp extract_exp length_exp general_value_spec
227 %type <pParseNode> general_set_fct set_fct_type query_exp non_join_query_exp joined_table
228 %type <pParseNode> non_join_query_term non_join_query_primary simple_table
229 %type <pParseNode> table_value_const_list row_value_constructor /*row_value_const_list*/ row_value_constructor_elem
230 %type <pParseNode> qualified_join value_exp query_term join_type outer_join_type join_condition boolean_term
231 %type <pParseNode> boolean_factor boolean_primary named_columns_join join_spec
232 %type <pParseNode> cast_operand cast_target factor datetime_value_exp /*interval_value_exp*/ datetime_term datetime_factor
233 %type <pParseNode> datetime_primary datetime_value_fct time_zone time_zone_specifier /*interval_term*/ interval_qualifier
234 %type <pParseNode> start_field non_second_datetime_field end_field single_datetime_field extract_field datetime_field time_zone_field
235 %type <pParseNode> char_length_exp octet_length_exp bit_length_exp select_sublist string_value_exp
236 %type <pParseNode> char_value_exp concatenation char_factor char_primary string_value_fct char_substring_fct
237 %type <pParseNode> form_conversion char_translation trim_fct trim_operands trim_spec bit_value_fct bit_substring_fct op_column_commalist
238 %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
239 %type <pParseNode> function_arg_commalist3 string_function_3Argument function_arg_commalist4 string_function_4Argument function_arg_commalist2 string_function_1Argument string_function_2Argument
240 %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
241 %type <pParseNode> all query_primary sql_not for_length comparison column_val cross_union /*opt_schema_element_list*/
242 %type <pParseNode> /*op_authorization op_schema*/ nil_fkt schema_element base_table_def base_table_element base_table_element_commalist
243 %type <pParseNode> column_def odbc_fct_spec odbc_call_spec odbc_fct_type op_parameter union_statement
244 %type <pParseNode> op_odbc_call_parameter odbc_parameter_commalist odbc_parameter function_args_commalist function_arg
245 %type <pParseNode> catalog_name schema_name table_node numeric_function string_function function_name date_function table_primary_as_range_column opt_as
246 %type <pParseNode> ordered_set_function inverse_distribution_function hypothetical_set_function hypothetical_set_function_value_expression_list rank_function_type within_group_specification inverse_distribution_function_type array_aggregate_function inverse_distribution_function_argument
247 %type <pParseNode> case_expression else_clause result_expression result case_abbreviation case_specification searched_when_clause simple_when_clause searched_case simple_case
248 %type <pParseNode> when_operand_list when_operand case_operand
249 %type <pParseNode> trigger_definition trigger_name trigger_action_time trigger_event transition_table_or_variable_list triggered_action trigger_column_list triggered_when_clause triggered_SQL_statement SQL_procedure_statement old_transition_variable_name new_transition_variable_name
250 %type <pParseNode> op_referencing op_trigger_columnlist op_triggered_action_for opt_row trigger_for SQL_procedure_statement_list transition_table_or_variable old_transition_table_name new_transition_table_name transition_table_name
251 %type <pParseNode> searched_when_clause_list simple_when_clause_list predefined_type opt_char_set_spec opt_collate_clause character_string_type national_character_string_type
252 %type <pParseNode> binary_string_type numeric_type boolean_type datetime_type interval_type opt_paren_precision paren_char_length opt_paren_char_large_length paren_character_large_object_length
253 %type <pParseNode> large_object_length opt_multiplier character_large_object_type national_character_large_object_type binary_large_object_string_type opt_with_or_without_time_zone
254 %type <pParseNode> approximate_numeric_type exact_numeric_type opt_paren_precision_scale
255 /* window function rules */
256 %type <pParseNode> window_function window_function_type ntile_function number_of_tiles lead_or_lag_function lead_or_lag lead_or_lag_extent offset default_expression null_treatment
257 %type <pParseNode> first_or_last_value_function first_or_last_value nth_value_function nth_row from_first_or_last window_name_or_specification in_line_window_specification opt_lead_or_lag_function
258 %type <pParseNode> opt_null_treatment opt_from_first_or_last simple_value_specification dynamic_parameter_specification window_name window_clause window_definition_list window_definition
259 %type <pParseNode> new_window_name existing_window_name window_partition_clause window_partition_column_reference_list window_partition_column_reference window_frame_clause
260 %type <pParseNode> window_frame_units window_frame_extent window_frame_start window_frame_preceding window_frame_between window_frame_bound_1 window_frame_bound_2 window_frame_bound window_frame_following window_frame_exclusion
261 %type <pParseNode> opt_window_frame_clause opt_window_partition_clause opt_existing_window_name window_specification opt_window_frame_exclusion opt_window_clause opt_offset
262 %type <pParseNode> opt_fetch_first_row_count fetch_first_clause offset_row_count fetch_first_row_count first_or_next row_or_rows opt_result_offset_clause result_offset_clause
263 /* LIMIT and OFFSET */
264 %type <pParseNode> opt_limit_offset_clause limit_offset_clause opt_fetch_first_clause
267 /* Return Parse Tree to OSQLParser
268 * (the access over yyval after calling the parser fails,
271 sql_single_statement:
273 { xxx_pGLOBAL_SQLPARSER->setParseTree( $1 ); }
274 | sql ';'
275 { xxx_pGLOBAL_SQLPARSER->setParseTree( $1 ); }
278 /* schema definition language */
279 /* Note: other ``sql:sal_Unicode() rules appear later in the grammar */
281 sql:
282 manipulative_statement
283 | schema_element
285 $$ = SQL_NEW_RULE;
286 $$->append($1);
290 /***
292 op_authorization:
293 {$$ = SQL_NEW_RULE;}
294 | SQL_TOKEN_AUTHORIZATION user
296 $$ = SQL_NEW_RULE;
297 $$->append($1);
298 $$->append($2);
301 op_schema:
302 {$$ = SQL_NEW_RULE;}
303 | SQL_TOKEN_NAME
304 | SQL_TOKEN_NAME '.' SQL_TOKEN_NAME
306 $$ = SQL_NEW_RULE;
307 $$->append($1);
308 $$->append(newNode(".", SQLNodeType::Punctuation));
309 $$->append($3);
313 schema:
314 SQL_TOKEN_CREATE SQL_TOKEN_SCHEMA op_schema op_authorization opt_schema_element_list
316 $$ = SQL_NEW_RULE;
317 $$->append($1);
318 $$->append($2);
319 $$->append($3);
320 $$->append($4);
321 $$->append($5);
325 opt_schema_element_list:
326 {$$ = SQL_NEW_RULE;}
327 | schema_element_list
330 schema_element_list:
331 schema_element
332 {$$ = SQL_NEW_LISTRULE;
333 $$->append($1);}
334 | schema_element_list schema_element
335 {$1->append($2);
336 $$ = $1;}
340 schema_element:
341 base_table_def
342 | view_def
343 | privilege_def
344 | trigger_definition
347 base_table_def:
348 SQL_TOKEN_CREATE SQL_TOKEN_TABLE table_node '(' base_table_element_commalist ')'
349 {$$ = SQL_NEW_RULE;
350 $$->append($1);
351 $$->append($2);
352 $$->append($3);
353 $$->append(newNode("(", SQLNodeType::Punctuation));
354 $$->append($5);
355 $$->append(newNode(")", SQLNodeType::Punctuation));}
358 base_table_element_commalist:
359 base_table_element
360 {$$ = SQL_NEW_COMMALISTRULE;
361 $$->append($1);}
362 | base_table_element_commalist ',' base_table_element
363 {$1->append($3);
364 $$ = $1;}
367 base_table_element:
368 column_def
369 | table_constraint_def
372 column_def:
373 column data_type column_def_opt_list
374 {$$ = SQL_NEW_RULE;
375 $$->append($1);
376 $$->append($2);
377 $$->append($3);
381 column_def_opt_list:
382 /* empty */ {$$ = SQL_NEW_LISTRULE;}
383 | column_def_opt_list column_def_opt
384 {$1->append($2);
385 $$ = $1;}
388 nil_fkt:
389 datetime_value_fct
391 unique_spec:
392 SQL_TOKEN_UNIQUE
393 | SQL_TOKEN_PRIMARY SQL_TOKEN_KEY
395 $$ = SQL_NEW_RULE;
396 $$->append($1);
397 $$->append($2);
400 column_def_opt:
401 SQL_TOKEN_NOT SQL_TOKEN_NULL
402 {$$ = SQL_NEW_RULE;
403 $$->append($1);
404 $$->append($2);}
405 | unique_spec
406 | SQL_TOKEN_DEFAULT literal
407 {$$ = SQL_NEW_RULE;
408 $$->append($1);
409 $$->append($2);}
410 | SQL_TOKEN_DEFAULT SQL_TOKEN_NULL
411 {$$ = SQL_NEW_RULE;
412 $$->append($1);
413 $$->append($2);}
414 | SQL_TOKEN_DEFAULT SQL_TOKEN_USER
415 {$$ = SQL_NEW_RULE;
416 $$->append($1);
417 $$->append($2);}
418 | SQL_TOKEN_DEFAULT nil_fkt
420 $$ = SQL_NEW_RULE;
421 $$->append($1);
422 $$->append($2);
424 | SQL_TOKEN_CHECK
425 | SQL_TOKEN_CHECK '(' search_condition ')'
426 {$$ = SQL_NEW_RULE;
427 $$->append($1);
428 $$->append(newNode("(", SQLNodeType::Punctuation));
429 $$->append($3);
430 $$->append(newNode(")", SQLNodeType::Punctuation));}
431 | SQL_TOKEN_REFERENCES table_node
432 {$$ = SQL_NEW_RULE;
433 $$->append($1);
434 $$->append($2);}
435 | SQL_TOKEN_REFERENCES table_node '(' column_commalist ')'
436 {$$ = SQL_NEW_RULE;
437 $$->append($1);
438 $$->append($2);
439 $$->append(newNode("(", SQLNodeType::Punctuation));
440 $$->append($4);
441 $$->append(newNode(")", SQLNodeType::Punctuation));}
444 table_constraint_def:
445 unique_spec '(' column_commalist ')'
446 {$$ = SQL_NEW_RULE;
447 $$->append($1);
448 $$->append(newNode("(", SQLNodeType::Punctuation));
449 $$->append($3);
450 $$->append(newNode(")", SQLNodeType::Punctuation));}
451 | SQL_TOKEN_FOREIGN SQL_TOKEN_KEY '(' column_commalist ')' SQL_TOKEN_REFERENCES table_node
452 {$$ = SQL_NEW_RULE;
453 $$->append($1);
454 $$->append($2);
455 $$->append(newNode("(", SQLNodeType::Punctuation));
456 $$->append($4);
457 $$->append(newNode(")", SQLNodeType::Punctuation));
458 $$->append($6);
459 $$->append($7);}
460 | SQL_TOKEN_FOREIGN SQL_TOKEN_KEY '(' column_commalist ')' SQL_TOKEN_REFERENCES table_node '(' column_commalist ')'
461 {$$ = SQL_NEW_RULE;
462 $$->append($1);
463 $$->append($2);
464 $$->append(newNode("(", SQLNodeType::Punctuation));
465 $$->append($4);
466 $$->append(newNode(")", SQLNodeType::Punctuation));
467 $$->append($6);
468 $$->append($7);
469 $$->append(newNode("(", SQLNodeType::Punctuation));
470 $$->append($9);
471 $$->append(newNode(")", SQLNodeType::Punctuation));}
472 | SQL_TOKEN_CHECK '(' search_condition ')'
473 {$$ = SQL_NEW_RULE;
474 $$->append($1);
475 $$->append(newNode("(", SQLNodeType::Punctuation));
476 $$->append($3);
477 $$->append(newNode(")", SQLNodeType::Punctuation));}
479 op_column_commalist:
480 /* empty */ {$$ = SQL_NEW_RULE;}
481 | '(' column_commalist ')'
482 {$$ = SQL_NEW_RULE;
483 $$->append(newNode("(", SQLNodeType::Punctuation));
484 $$->append($2);
485 $$->append(newNode(")", SQLNodeType::Punctuation));
488 column_commalist:
489 column_commalist ',' column
490 {$1->append($3);
491 $$ = $1;}
492 | column
493 {$$ = SQL_NEW_COMMALISTRULE;
494 $$->append($1);}
497 view_def:
498 SQL_TOKEN_CREATE SQL_TOKEN_VIEW table_node opt_column_commalist SQL_TOKEN_AS select_statement opt_with_check_option
499 {$$ = SQL_NEW_RULE;
500 $$->append($1);
501 $$->append($2);
502 $$->append($3);
503 $$->append($4);
504 $$->append($5);
505 $$->append($6);
506 $$->append($7);}
509 opt_with_check_option:
510 /* empty */ {$$ = SQL_NEW_RULE;}
511 | SQL_TOKEN_WITH SQL_TOKEN_CHECK SQL_TOKEN_OPTION
512 {$$ = SQL_NEW_RULE;
513 $$->append($1);
514 $$->append($2);
515 $$->append($3);}
518 opt_column_commalist:
519 /* empty */ {$$ = SQL_NEW_RULE;}
520 | '(' column_commalist ')'
521 {$$ = SQL_NEW_RULE;
522 $$->append(newNode("(", SQLNodeType::Punctuation));
523 $$->append($2);
524 $$->append(newNode(")", SQLNodeType::Punctuation));}
527 privilege_def:
528 SQL_TOKEN_GRANT privileges SQL_TOKEN_ON table_node SQL_TOKEN_TO grantee_commalist
529 opt_with_grant_option
530 {$$ = SQL_NEW_RULE;
531 $$->append($1);
532 $$->append($2);
533 $$->append($3);
534 $$->append($4);
535 $$->append($5);
536 $$->append($6);
537 $$->append($7);}
540 opt_with_grant_option:
541 /* empty */ {$$ = SQL_NEW_RULE;}
542 | SQL_TOKEN_WITH SQL_TOKEN_GRANT SQL_TOKEN_OPTION
543 {$$ = SQL_NEW_RULE;
544 $$->append($1);
545 $$->append($2);
546 $$->append($3);}
549 privileges:
550 SQL_TOKEN_ALL SQL_TOKEN_PRIVILEGES
551 {$$ = SQL_NEW_RULE;
552 $$->append($1);
553 $$->append($2);}
554 | operation_commalist
557 operation_commalist:
558 operation
559 {$$ = SQL_NEW_COMMALISTRULE;
560 $$->append($1);}
561 | operation_commalist ',' operation
562 {$1->append($3);
563 $$ = $1;}
566 operation:
567 SQL_TOKEN_SELECT
568 | SQL_TOKEN_INSERT opt_column_commalist
569 {$$ = SQL_NEW_RULE;
570 $$->append($1);
571 $$->append($2);}
572 | SQL_TOKEN_DELETE
573 | SQL_TOKEN_UPDATE opt_column_commalist
574 {$$ = SQL_NEW_RULE;
575 $$->append($1);
576 $$->append($2);}
577 | SQL_TOKEN_REFERENCES opt_column_commalist
578 {$$ = SQL_NEW_RULE;
579 $$->append($1);
580 $$->append($2);}
581 | SQL_TOKEN_USAGE
585 grantee_commalist:
586 grantee
587 {$$ = SQL_NEW_COMMALISTRULE;
588 $$->append($1);}
589 | grantee_commalist ',' grantee
590 {$1->append($3);
591 $$ = $1;}
594 grantee:
595 SQL_TOKEN_PUBLIC
596 | user
599 /* module language */
601 opt_order_by_clause:
602 /* empty */ {$$ = SQL_NEW_RULE;}
603 | SQL_TOKEN_ORDER SQL_TOKEN_BY ordering_spec_commalist
604 {$$ = SQL_NEW_RULE;
605 $$->append($1);
606 $$->append($2);
607 $$->append($3);}
610 ordering_spec_commalist:
611 ordering_spec
612 {$$ = SQL_NEW_COMMALISTRULE;
613 $$->append($1);}
614 | ordering_spec_commalist ',' ordering_spec
615 {$1->append($3);
616 $$ = $1;}
619 ordering_spec:
620 /* SQL_TOKEN_INTNUM opt_asc_desc
621 {$$ = SQL_NEW_RULE;
622 $$->append($1);
623 $$->append($2);}
625 predicate opt_asc_desc
626 {$$ = SQL_NEW_RULE;
627 $$->append($1);
628 $$->append($2);}
630 | row_value_constructor_elem opt_asc_desc
631 {$$ = SQL_NEW_RULE;
632 $$->append($1);
633 $$->append($2);}
636 opt_asc_desc:
637 {$$ = SQL_NEW_RULE;}
638 | SQL_TOKEN_ASC
639 | SQL_TOKEN_DESC
643 /***
644 manipulative_statement_list:
645 manipulative_statement
646 {$$ = SQL_NEW_LISTRULE;
647 $$->append($1);}
648 | manipulative_statement_list manipulative_statement
649 {$1->append($2);
650 $$ = $1;}
652 ***/
654 sql_not:
655 /* vide */
656 {$$ = SQL_NEW_RULE;}
657 | SQL_TOKEN_NOT
660 /* manipulative statements */
662 manipulative_statement:
663 commit_statement
664 /* | delete_statement_positioned*/
665 | delete_statement_searched
666 | fetch_statement
667 | insert_statement
668 | rollback_statement
669 | select_statement_into
670 /* | update_statement_positioned*/
671 | update_statement_searched
672 | union_statement
673 | '{' odbc_call_spec '}'
675 $$ = SQL_NEW_RULE;
676 $$->append(newNode("{", SQLNodeType::Punctuation));
677 $$->append($2);
678 $$->append(newNode("}", SQLNodeType::Punctuation));
682 union_statement:
683 select_statement
684 | union_statement SQL_TOKEN_UNION all select_statement
686 $$ = SQL_NEW_RULE;
687 $$->append($1);
688 $$->append($2);
689 $$->append($3);
690 $$->append($4);
693 commit_statement:
694 SQL_TOKEN_COMMIT SQL_TOKEN_WORK
695 {$$ = SQL_NEW_RULE;
696 $$->append($1);
697 $$->append($2);}
700 delete_statement_positioned:
701 SQL_TOKEN_DELETE SQL_TOKEN_FROM table_node SQL_TOKEN_WHERE SQL_TOKEN_CURRENT SQL_TOKEN_OF cursor
702 {$$ = SQL_NEW_RULE;
703 $$->append($1);
704 $$->append($2);
705 $$->append($3);
706 $$->append($4);
707 $$->append($5);
708 $$->append($6);
709 $$->append($7);}
712 delete_statement_searched:
713 SQL_TOKEN_DELETE SQL_TOKEN_FROM table_node opt_where_clause
714 {$$ = SQL_NEW_RULE;
715 $$->append($1);
716 $$->append($2);
717 $$->append($3);
718 $$->append($4);}
721 fetch_statement:
722 SQL_TOKEN_FETCH cursor SQL_TOKEN_INTO target_commalist
723 {$$ = SQL_NEW_RULE;
724 $$->append($1);
725 $$->append($2);
726 $$->append($3);
727 $$->append($4);}
730 insert_statement:
731 SQL_TOKEN_INSERT SQL_TOKEN_INTO table_node opt_column_commalist query_exp
732 {$$ = SQL_NEW_RULE;
733 $$->append($1);
734 $$->append($2);
735 $$->append($3);
736 $$->append($4);
737 $$->append($5);}
739 values_or_query_spec:
740 SQL_TOKEN_VALUES '(' table_value_const_list ')'
741 {$$ = SQL_NEW_RULE;
742 $$->append($1);
743 $$->append(newNode("(", SQLNodeType::Punctuation));
744 $$->append($3);
745 $$->append(newNode(")", SQLNodeType::Punctuation));
749 table_value_const_list:
750 row_value_constructor
751 {$$ = SQL_NEW_COMMALISTRULE;
752 $$->append($1);}
753 | table_value_const_list ',' row_value_constructor
754 {$1->append($3);
755 $$ = $1;}
758 row_value_const_list:
759 row_value_constructor_elem
760 {$$ = SQL_NEW_COMMALISTRULE;
761 $$->append($1);}
762 | row_value_const_list ',' row_value_constructor_elem
763 {$1->append($3);
764 $$ = $1;}
767 row_value_constructor:
768 row_value_constructor_elem
769 /* | '(' row_value_const_list ')'
771 $$ = SQL_NEW_RULE;
772 $$->append(newNode("(", SQLNodeType::Punctuation));
773 $$->append($2);
774 $$->append(newNode(")", SQLNodeType::Punctuation));
778 row_value_constructor_elem:
779 value_exp /*[^')']*/
780 | SQL_TOKEN_DEFAULT
784 rollback_statement:
785 SQL_TOKEN_ROLLBACK SQL_TOKEN_WORK
786 {$$ = SQL_NEW_RULE;
787 $$->append($1);
788 $$->append($2);}
792 /* INTO target_commalist herausgenommen */
793 select_statement_into:
794 SQL_TOKEN_SELECT opt_all_distinct selection SQL_TOKEN_INTO target_commalist table_exp
795 {$$ = SQL_NEW_RULE;
796 $$->append($1);
797 $$->append($2);
798 $$->append($3);
799 $$->append($4);
800 $$->append($5);
801 $$->append($6); }
804 opt_all_distinct:
805 {$$ = SQL_NEW_RULE;}
806 | SQL_TOKEN_ALL
807 | SQL_TOKEN_DISTINCT
811 update_statement_positioned:
812 SQL_TOKEN_UPDATE table_node SQL_TOKEN_SET assignment_commalist
813 SQL_TOKEN_WHERE SQL_TOKEN_CURRENT SQL_TOKEN_OF cursor
814 {$$ = SQL_NEW_RULE;
815 $$->append($1);
816 $$->append($2);
817 $$->append($3);
818 $$->append($4);
819 $$->append($5);
820 $$->append($6);
821 $$->append($7);
822 $$->append($8);}
825 assignment_commalist:
826 assignment
827 {$$ = SQL_NEW_COMMALISTRULE;
828 $$->append($1);}
829 | assignment_commalist ',' assignment
830 {$1->append($3);
831 $$ = $1;}
834 assignment:
835 column SQL_EQUAL update_source
836 {$$ = SQL_NEW_RULE;
837 $$->append($1);
838 $$->append($2);
839 $$->append($3);}
841 update_source:
842 value_exp
843 | SQL_TOKEN_DEFAULT
845 update_statement_searched:
846 SQL_TOKEN_UPDATE table_node SQL_TOKEN_SET assignment_commalist opt_where_clause
847 {$$ = SQL_NEW_RULE;
848 $$->append($1);
849 $$->append($2);
850 $$->append($3);
851 $$->append($4);
852 $$->append($5);}
855 target_commalist:
856 target
857 {$$ = SQL_NEW_COMMALISTRULE;
858 $$->append($1);}
859 | target_commalist ',' target
860 {$1->append($3);
861 $$ = $1;}
864 target:
865 parameter_ref
868 opt_where_clause:
869 /* empty */ {$$ = SQL_NEW_RULE;}
870 | where_clause
873 /* query expressions */
875 query_term:
876 non_join_query_term
878 $$ = SQL_NEW_RULE;
879 $$->append($1);
882 /* SELECT STATEMENT */
883 select_statement:
884 SQL_TOKEN_SELECT opt_all_distinct selection table_exp
886 $$ = SQL_NEW_RULE;
887 $$->append($1);
888 $$->append($2);
889 $$->append($3);
890 $$->append($4);
894 selection:
897 $$ = SQL_NEW_RULE;
898 $$->append(newNode("*", SQLNodeType::Punctuation));
900 | scalar_exp_commalist
902 opt_result_offset_clause:
903 /* empty */ {$$ = SQL_NEW_RULE;}
904 | result_offset_clause
906 result_offset_clause:
907 SQL_TOKEN_OFFSET offset_row_count row_or_rows
909 $$ = SQL_NEW_RULE;
910 $$->append($1);
911 $$->append($2);
912 $$->append($3);
915 opt_fetch_first_row_count:
916 /* empty */ {$$ = SQL_NEW_RULE;}
917 | fetch_first_row_count
919 first_or_next:
920 SQL_TOKEN_FIRST
921 | SQL_TOKEN_NEXT
923 row_or_rows:
924 SQL_TOKEN_ROW
925 | SQL_TOKEN_ROWS
927 opt_fetch_first_clause:
928 /* empty */ {$$ = SQL_NEW_RULE;}
929 | fetch_first_clause
931 fetch_first_clause:
932 SQL_TOKEN_FETCH first_or_next opt_fetch_first_row_count row_or_rows SQL_TOKEN_ONLY
934 $$ = SQL_NEW_RULE;
935 $$->append($1);
936 $$->append($2);
937 $$->append($3);
938 $$->append($4);
939 $$->append($5);
942 offset_row_count:
943 literal
945 fetch_first_row_count:
946 literal
949 opt_limit_offset_clause:
950 /* empty */ {$$ = SQL_NEW_RULE;}
951 | limit_offset_clause
953 opt_offset:
954 /* empty */ {$$ = SQL_NEW_RULE;}
955 | SQL_TOKEN_OFFSET SQL_TOKEN_INTNUM
957 $$ = SQL_NEW_RULE;
958 $$->append($1);
959 $$->append($2);
962 limit_offset_clause:
963 SQL_TOKEN_LIMIT SQL_TOKEN_INTNUM opt_offset
965 $$ = SQL_NEW_RULE;
966 $$->append($1);
967 $$->append($2);
968 $$->append($3);
971 table_exp:
972 from_clause opt_where_clause opt_group_by_clause opt_having_clause opt_window_clause opt_order_by_clause opt_limit_offset_clause opt_result_offset_clause opt_fetch_first_clause
974 $$ = SQL_NEW_RULE;
975 $$->append($1);
976 $$->append($2);
977 $$->append($3);
978 $$->append($4);
979 $$->append($5);
980 $$->append($6);
981 $$->append($7);
982 $$->append($8);
983 $$->append($9);
987 from_clause:
988 SQL_TOKEN_FROM table_ref_commalist
989 { $$ = SQL_NEW_RULE;
990 $$->append($1);
991 $$->append($2); }
994 table_ref_commalist:
996 table_ref
997 { $$ = SQL_NEW_COMMALISTRULE;
998 $$->append($1); }
999 | table_ref_commalist ',' table_ref
1000 { $1->append($3);
1001 $$ = $1; }
1004 opt_as:
1005 /* empty */ {$$ = SQL_NEW_RULE;}
1006 | SQL_TOKEN_AS
1008 opt_row:
1009 /* empty */ {$$ = SQL_NEW_RULE;}
1010 | SQL_TOKEN_ROW
1012 table_primary_as_range_column:
1013 {$$ = SQL_NEW_RULE;}
1014 | opt_as SQL_TOKEN_NAME op_column_commalist
1016 $$ = SQL_NEW_RULE;
1017 $$->append($1);
1018 $$->append($2);
1019 $$->append($3);
1022 table_ref:
1023 table_node table_primary_as_range_column
1025 $$ = SQL_NEW_RULE;
1026 $$->append($1);
1027 $$->append($2);
1029 | subquery range_variable op_column_commalist
1031 $$ = SQL_NEW_RULE;
1032 $$->append($1);
1033 $$->append($2);
1034 $$->append($3);
1036 | joined_table
1037 | '{' SQL_TOKEN_OJ joined_table '}'
1039 $$ = SQL_NEW_RULE;
1040 $$->append(newNode("{", SQLNodeType::Punctuation));
1041 $$->append($2);
1042 $$->append($3);
1043 $$->append(newNode("}", SQLNodeType::Punctuation));
1045 | '(' joined_table ')'
1047 $$ = SQL_NEW_RULE;
1048 $$->append(newNode("(", SQLNodeType::Punctuation));
1049 $$->append($2);
1050 $$->append(newNode(")", SQLNodeType::Punctuation));
1053 where_clause:
1054 SQL_TOKEN_WHERE search_condition
1055 {$$ = SQL_NEW_RULE;
1056 $$->append($1);
1057 $$->append($2);}
1060 opt_group_by_clause:
1061 /* empty */ {$$ = SQL_NEW_RULE;}
1062 | SQL_TOKEN_GROUP SQL_TOKEN_BY column_ref_commalist
1063 {$$ = SQL_NEW_RULE;
1064 $$->append($1);
1065 $$->append($2);
1066 $$->append($3);}
1069 column_ref_commalist:
1070 column_ref
1071 {$$ = SQL_NEW_COMMALISTRULE;
1072 $$->append($1);}
1073 | set_fct_spec
1074 {$$ = SQL_NEW_COMMALISTRULE;
1075 $$->append($1);}
1076 | column_ref_commalist ',' column_ref
1077 {$1->append($3);
1078 $$ = $1;}
1079 | column_ref_commalist ',' set_fct_spec
1080 {$1->append($3);
1081 $$ = $1;}
1084 opt_having_clause:
1085 /* empty */ {$$ = SQL_NEW_RULE;}
1086 | SQL_TOKEN_HAVING search_condition
1087 {$$ = SQL_NEW_RULE;
1088 $$->append($1);
1089 $$->append($2);}
1092 /* search conditions */
1093 boolean_primary:
1094 predicate
1095 | '(' search_condition ')'
1096 { // boolean_primary: rule 2
1097 $$ = SQL_NEW_RULE;
1098 $$->append(newNode("(", SQLNodeType::Punctuation));
1099 $$->append($2);
1100 $$->append(newNode(")", SQLNodeType::Punctuation));
1102 | row_value_constructor_elem /*[^')' ',']*/
1104 if(xxx_pGLOBAL_SQLPARSER->inPredicateCheck())// boolean_primary: rule 3
1106 $$ = SQL_NEW_RULE;
1107 sal_Int16 nErg = 0;
1108 if ( SQL_ISTOKEN( $1, NULL))
1110 OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1111 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1112 OSQLParseNode* pTFN = new OSQLInternalNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::test_for_null));
1113 pTFN->append(pColumnRef);
1115 OSQLParseNode* pNPP2 = new OSQLInternalNode("", SQLNodeType::Rule, OSQLParser::RuleID(OSQLParseNode::null_predicate_part_2));
1116 pNPP2->append(new OSQLInternalNode("", SQLNodeType::Keyword, SQL_TOKEN_IS));
1117 pNPP2->append(new OSQLInternalNode("", SQLNodeType::Rule, OSQLParser::RuleID(OSQLParseNode::sql_not)));
1118 pNPP2->append(new OSQLInternalNode("", SQLNodeType::Keyword, SQL_TOKEN_NULL));
1119 pTFN->append(pNPP2);
1121 $$->append(pTFN);
1123 nErg = 1;
1125 else
1127 nErg = xxx_pGLOBAL_SQLPARSER->buildComparisonRule($$,$1);
1129 if(nErg == 1)
1131 OSQLParseNode* pTemp = $$;
1132 $$ = pTemp->removeAt((sal_uInt32)0);
1133 delete pTemp;
1135 else
1137 delete $$;
1138 if(nErg)
1139 YYERROR;
1140 else
1141 YYABORT;
1144 else
1145 YYERROR;
1148 parenthesized_boolean_value_expression:
1149 '(' search_condition ')'
1150 { // boolean_primary: rule 2
1151 $$ = SQL_NEW_RULE;
1152 $$->append(newNode("(", SQLNodeType::Punctuation));
1153 $$->append($2);
1154 $$->append(newNode(")", SQLNodeType::Punctuation));
1157 boolean_factor:
1158 boolean_primary %dprec 2
1159 | SQL_TOKEN_NOT boolean_primary %dprec 1
1160 { // boolean_factor: rule 1
1161 $$ = SQL_NEW_RULE;
1162 $$->append($1);
1163 $$->append($2);
1166 boolean_term:
1167 boolean_factor
1168 | boolean_term SQL_TOKEN_AND boolean_factor
1170 $$ = SQL_NEW_RULE; // boolean_term: rule 1
1171 $$->append($1);
1172 $$->append($2);
1173 $$->append($3);
1176 search_condition:
1177 boolean_term
1178 | search_condition SQL_TOKEN_OR boolean_term
1180 $$ = SQL_NEW_RULE; // search_condition
1181 $$->append($1);
1182 $$->append($2);
1183 $$->append($3);
1186 predicate:
1187 comparison_predicate %dprec 1
1188 | between_predicate
1189 | all_or_any_predicate
1190 | existence_test
1191 | unique_test
1192 | test_for_null %dprec 2
1193 | in_predicate
1194 | like_predicate
1196 comparison_predicate_part_2:
1197 comparison row_value_constructor
1199 $$ = SQL_NEW_RULE; // comparison_predicate: rule 1
1200 $$->append($1);
1201 $$->append($2);
1203 comparison_predicate:
1204 row_value_constructor comparison row_value_constructor
1206 $$ = SQL_NEW_RULE; // comparison_predicate: rule 1
1207 $$->append($1);
1208 $$->append($2);
1209 $$->append($3);
1211 | comparison row_value_constructor
1213 if(xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // comparison_predicate: rule 2
1215 $$ = SQL_NEW_RULE;
1216 sal_Int16 nErg = xxx_pGLOBAL_SQLPARSER->buildPredicateRule($$,$2,$1);
1217 if(nErg == 1)
1219 OSQLParseNode* pTemp = $$;
1220 $$ = pTemp->removeAt((sal_uInt32)0);
1221 delete pTemp;
1223 else
1225 delete $$;
1226 YYABORT;
1229 else
1231 YYERROR;
1235 comparison:
1236 SQL_LESS
1237 | SQL_NOTEQUAL
1238 | SQL_EQUAL
1239 | SQL_GREAT
1240 | SQL_LESSEQ
1241 | SQL_GREATEQ
1242 | SQL_TOKEN_IS sql_not SQL_TOKEN_DISTINCT SQL_TOKEN_FROM
1244 $$ = SQL_NEW_RULE;
1245 $$->append($1);
1246 $$->append($2);
1247 $$->append($3);
1248 $$->append($4);
1250 | SQL_TOKEN_IS sql_not
1252 $$ = SQL_NEW_RULE;
1253 $$->append($1);
1254 $$->append($2);
1257 between_predicate_part_2:
1258 sql_not SQL_TOKEN_BETWEEN row_value_constructor SQL_TOKEN_AND row_value_constructor
1260 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // between_predicate: rule 2
1262 $$ = SQL_NEW_RULE;
1264 sal_Int16 nErg = xxx_pGLOBAL_SQLPARSER->buildPredicateRule($$,$3,$2,$5);
1265 if(nErg == 1)
1267 OSQLParseNode* pTemp = $$;
1268 $$ = pTemp->removeAt((sal_uInt32)0);
1269 OSQLParseNode* pColumnRef = $$->removeAt((sal_uInt32)0);
1270 $$->insert(0,$1);
1271 OSQLParseNode* pBetween_predicate = new OSQLInternalNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::between_predicate));
1272 pBetween_predicate->append(pColumnRef);
1273 pBetween_predicate->append($$);
1274 $$ = pBetween_predicate;
1276 delete pTemp;
1277 delete $4;
1279 else
1281 delete $$;
1282 YYABORT;
1285 else
1287 $$ = SQL_NEW_RULE; // between_predicate: rule 1
1288 $$->append($1);
1289 $$->append($2);
1290 $$->append($3);
1291 $$->append($4);
1292 $$->append($5);
1295 between_predicate:
1296 row_value_constructor between_predicate_part_2
1298 $$ = SQL_NEW_RULE; // between_predicate: rule 1
1299 $$->append($1);
1300 $$->append($2);
1302 | between_predicate_part_2
1304 character_like_predicate_part_2:
1305 sql_not SQL_TOKEN_LIKE string_value_exp opt_escape
1307 $$ = SQL_NEW_RULE; // like_predicate: rule 1
1308 $$->append($1);
1309 $$->append($2);
1310 $$->append($3);
1311 $$->append($4);
1314 other_like_predicate_part_2:
1315 sql_not SQL_TOKEN_LIKE value_exp_primary opt_escape
1317 $$ = SQL_NEW_RULE; // like_predicate: rule 1
1318 $$->append($1);
1319 $$->append($2);
1320 $$->append($3);
1321 $$->append($4);
1324 like_predicate:
1325 row_value_constructor character_like_predicate_part_2
1327 $$ = SQL_NEW_RULE; // like_predicate: rule 1
1328 $$->append($1);
1329 $$->append($2);
1331 | row_value_constructor other_like_predicate_part_2
1333 $$ = SQL_NEW_RULE; // like_predicate: rule 3
1334 $$->append($1);
1335 $$->append($2);
1337 | character_like_predicate_part_2
1339 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // like_predicate: rule 5
1341 OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1342 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1344 $$ = SQL_NEW_RULE;
1345 $$->append(pColumnRef);
1346 $$->append($1);
1347 OSQLParseNode* p2nd = $1->removeAt(2);
1348 OSQLParseNode* p3rd = $1->removeAt(2);
1349 if ( !xxx_pGLOBAL_SQLPARSER->buildLikeRule($1,p2nd,p3rd) )
1351 delete $$;
1352 YYABORT;
1354 $1->append(p3rd);
1356 else
1357 YYERROR;
1359 | other_like_predicate_part_2
1361 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // like_predicate: rule 6
1363 OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1364 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1366 $$ = SQL_NEW_RULE;
1367 $$->append(pColumnRef);
1368 $$->append($1);
1369 OSQLParseNode* p2nd = $1->removeAt(2);
1370 OSQLParseNode* p3rd = $1->removeAt(2);
1371 if ( !xxx_pGLOBAL_SQLPARSER->buildLikeRule($1,p2nd,p3rd) )
1373 delete $$;
1374 YYABORT;
1376 $1->append(p3rd);
1378 else
1379 YYERROR;
1383 opt_escape:
1384 /* empty */ {$$ = SQL_NEW_RULE;}
1385 | SQL_TOKEN_ESCAPE string_value_exp
1386 {$$ = SQL_NEW_RULE;
1387 $$->append($1);
1388 $$->append($2);}
1389 | '{' SQL_TOKEN_ESCAPE SQL_TOKEN_STRING '}'
1391 $$ = SQL_NEW_RULE;
1392 $$->append(newNode("{", SQLNodeType::Punctuation));
1393 $$->append($2);
1394 $$->append($3);
1395 $$->append(newNode("}", SQLNodeType::Punctuation));
1399 null_predicate_part_2:
1400 SQL_TOKEN_IS sql_not SQL_TOKEN_NULL
1402 $$ = SQL_NEW_RULE; // test_for_null: rule 1
1403 $$->append($1);
1404 $$->append($2);
1405 $$->append($3);
1407 | SQL_TOKEN_IS sql_not SQL_TOKEN_UNKNOWN
1409 $$ = SQL_NEW_RULE; // test_for_null: rule 1
1410 $$->append($1);
1411 $$->append($2);
1412 $$->append($3);
1415 test_for_null:
1416 row_value_constructor null_predicate_part_2
1418 $$ = SQL_NEW_RULE; // test_for_null: rule 1
1419 $$->append($1);
1420 $$->append($2);
1422 | null_predicate_part_2
1424 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())// test_for_null: rule 2
1426 OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1427 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1429 $$ = SQL_NEW_RULE;
1430 $$->append(pColumnRef);
1431 $$->append($1);
1433 else
1434 YYERROR;
1437 in_predicate_value:
1438 subquery
1439 {$$ = SQL_NEW_RULE;
1440 $$->append($1);
1442 | '(' value_exp_commalist ')'
1443 {$$ = SQL_NEW_RULE;
1444 $$->append(newNode("(", SQLNodeType::Punctuation));
1445 $$->append($2);
1446 $$->append(newNode(")", SQLNodeType::Punctuation));
1449 in_predicate_part_2:
1450 sql_not SQL_TOKEN_IN in_predicate_value
1452 $$ = SQL_NEW_RULE;// in_predicate: rule 1
1453 $$->append($1);
1454 $$->append($2);
1455 $$->append($3);
1458 in_predicate:
1459 row_value_constructor in_predicate_part_2
1461 $$ = SQL_NEW_RULE;// in_predicate: rule 1
1462 $$->append($1);
1463 $$->append($2);
1465 | in_predicate_part_2
1467 if ( xxx_pGLOBAL_SQLPARSER->inPredicateCheck() )// in_predicate: rule 2
1469 OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1470 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1472 $$ = SQL_NEW_RULE;
1473 $$->append(pColumnRef);
1474 $$->append($1);
1476 else
1477 YYERROR;
1480 quantified_comparison_predicate_part_2:
1481 comparison any_all_some subquery
1483 $$ = SQL_NEW_RULE;
1484 $$->append($1);
1485 $$->append($2);
1486 $$->append($3);
1489 all_or_any_predicate:
1490 row_value_constructor quantified_comparison_predicate_part_2
1492 $$ = SQL_NEW_RULE;
1493 $$->append($1);
1494 $$->append($2);
1496 | quantified_comparison_predicate_part_2
1498 if(xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1500 OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1501 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1503 $$ = SQL_NEW_RULE;
1504 $$->append(pColumnRef);
1505 $$->append($1);
1507 else
1508 YYERROR;
1512 any_all_some:
1513 SQL_TOKEN_ANY
1514 | SQL_TOKEN_ALL
1515 | SQL_TOKEN_SOME
1518 existence_test:
1519 SQL_TOKEN_EXISTS subquery
1520 {$$ = SQL_NEW_RULE;
1521 $$->append($1);
1522 $$->append($2);}
1524 unique_test:
1525 SQL_TOKEN_UNIQUE subquery
1526 {$$ = SQL_NEW_RULE;
1527 $$->append($1);
1528 $$->append($2);}
1530 subquery:
1531 '(' query_exp ')'
1532 {$$ = SQL_NEW_RULE;
1533 $$->append(newNode("(", SQLNodeType::Punctuation));
1534 $$->append($2);
1535 $$->append(newNode(")", SQLNodeType::Punctuation));}
1538 /* scalar expressions */
1539 scalar_exp_commalist:
1540 select_sublist
1542 $$ = SQL_NEW_COMMALISTRULE;
1543 $$->append($1);
1545 | scalar_exp_commalist ',' select_sublist
1547 $1->append($3);
1548 $$ = $1;
1551 select_sublist:
1552 /* table_node '.' '*'
1554 $$ = SQL_NEW_RULE;
1555 $$->append($1);
1556 $$->append(newNode(".", SQLNodeType::Punctuation));
1557 $$->append(newNode("*", SQLNodeType::Punctuation));
1560 derived_column
1564 parameter_ref:
1565 parameter
1569 op_like:
1572 $$ = newNode("*", SQLNodeType::Punctuation);
1574 | '?'
1576 $$ = newNode("?", SQLNodeType::Punctuation);
1578 | op_like '*'
1580 $$ = SQL_NEW_RULE;
1581 $$->append($1);
1582 $$->append(newNode("*", SQLNodeType::Punctuation));
1583 xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_False);
1585 | op_like '?'
1587 $$ = SQL_NEW_RULE;
1588 $$->append($1);
1589 $$->append(newNode("?", SQLNodeType::Punctuation));
1590 xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_False);
1595 literal:
1596 /* SQL_TOKEN_STRING
1597 | */SQL_TOKEN_INT
1598 | SQL_TOKEN_REAL_NUM
1599 | SQL_TOKEN_INTNUM
1600 | SQL_TOKEN_APPROXNUM
1601 | SQL_TOKEN_ACCESS_DATE
1602 /* rules for predicate check */
1603 | literal SQL_TOKEN_STRING
1605 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1607 $$ = SQL_NEW_RULE;
1608 $$->append($1);
1609 $$->append($2);
1610 OSQLParser::reduceLiteral($$, true);
1612 else
1613 YYERROR;
1615 | literal SQL_TOKEN_INT
1617 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1619 $$ = SQL_NEW_RULE;
1620 $$->append($1);
1621 $$->append($2);
1622 OSQLParser::reduceLiteral($$, true);
1624 else
1625 YYERROR;
1627 | literal SQL_TOKEN_REAL_NUM
1629 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1631 $$ = SQL_NEW_RULE;
1632 $$->append($1);
1633 $$->append($2);
1634 OSQLParser::reduceLiteral($$, true);
1636 else
1637 YYERROR;
1639 | literal SQL_TOKEN_APPROXNUM
1641 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1643 $$ = SQL_NEW_RULE;
1644 $$->append($1);
1645 $$->append($2);
1646 OSQLParser::reduceLiteral($$, true);
1648 else
1649 YYERROR;
1653 /* miscellaneous */
1654 as_clause:
1655 /* empty */ {$$ = SQL_NEW_RULE;}
1656 | SQL_TOKEN_AS column
1658 $$ = SQL_NEW_RULE;
1659 $$->append($1);
1660 $$->append($2);
1662 | column
1664 position_exp:
1665 SQL_TOKEN_POSITION '(' value_exp SQL_TOKEN_IN value_exp ')'
1667 $$ = SQL_NEW_RULE;
1668 $$->append($1);
1669 $$->append(newNode("(", SQLNodeType::Punctuation));
1670 $$->append($3);
1671 $$->append($4);
1672 $$->append($5);
1673 $$->append(newNode(")", SQLNodeType::Punctuation));
1675 | SQL_TOKEN_POSITION '(' value_exp_commalist ')'
1677 $$ = SQL_NEW_RULE;
1678 $$->append($1);
1679 $$->append(newNode("(", SQLNodeType::Punctuation));
1680 $$->append($3);
1681 $$->append(newNode(")", SQLNodeType::Punctuation));
1684 num_value_fct:
1685 position_exp
1686 | extract_exp
1687 | length_exp
1689 char_length_exp:
1690 SQL_TOKEN_CHAR_LENGTH '(' value_exp ')'
1692 $$ = SQL_NEW_RULE;
1693 $$->append($1);
1694 $$->append(newNode("(", SQLNodeType::Punctuation));
1695 $$->append($3);
1696 $$->append(newNode(")", SQLNodeType::Punctuation));
1698 | SQL_TOKEN_SQL_TOKEN_INTNUM '(' value_exp ')'
1700 $$ = SQL_NEW_RULE;
1701 $$->append($1);
1702 $$->append(newNode("(", SQLNodeType::Punctuation));
1703 $$->append($3);
1704 $$->append(newNode(")", SQLNodeType::Punctuation));
1708 octet_length_exp:
1709 SQL_TOKEN_OCTET_LENGTH '(' value_exp ')'
1711 $$ = SQL_NEW_RULE;
1712 $$->append($1);
1713 $$->append(newNode("(", SQLNodeType::Punctuation));
1714 $$->append($3);
1715 $$->append(newNode(")", SQLNodeType::Punctuation));
1718 bit_length_exp:
1719 SQL_TOKEN_BIT_LENGTH '(' value_exp ')'
1721 $$ = SQL_NEW_RULE;
1722 $$->append($1);
1723 $$->append(newNode("(", SQLNodeType::Punctuation));
1724 $$->append($3);
1725 $$->append(newNode(")", SQLNodeType::Punctuation));
1728 length_exp:
1729 char_length_exp
1731 $$ = SQL_NEW_RULE;
1732 $$->append($1);
1734 | octet_length_exp
1736 $$ = SQL_NEW_RULE;
1737 $$->append($1);
1739 | bit_length_exp
1741 $$ = SQL_NEW_RULE;
1742 $$->append($1);
1745 datetime_field:
1746 non_second_datetime_field
1748 $$ = SQL_NEW_RULE;
1749 $$->append($1);
1751 | SQL_TOKEN_SECOND
1753 $$ = SQL_NEW_RULE;
1754 $$->append($1);
1757 extract_field:
1758 time_zone_field
1759 | datetime_field
1760 | value_exp
1762 time_zone_field:
1763 SQL_TOKEN_TIMEZONE_HOUR
1765 $$ = SQL_NEW_RULE;
1766 $$->append($1);
1768 | SQL_TOKEN_TIMEZONE_MINUTE
1770 $$ = SQL_NEW_RULE;
1771 $$->append($1);
1774 extract_exp:
1775 SQL_TOKEN_EXTRACT '(' extract_field SQL_TOKEN_FROM value_exp ')'
1777 $$ = SQL_NEW_RULE;
1778 $$->append($1);
1779 $$->append(newNode("(", SQLNodeType::Punctuation));
1780 $$->append($3);
1781 $$->append($4);
1782 $$->append($5);
1783 $$->append(newNode(")", SQLNodeType::Punctuation));
1786 unsigned_value_spec:
1787 general_value_spec
1788 | literal
1790 general_value_spec:
1791 parameter
1792 | SQL_TOKEN_USER
1793 | SQL_TOKEN_NULL
1794 | SQL_TOKEN_FALSE
1795 | SQL_TOKEN_TRUE
1796 | SQL_TOKEN_VALUE
1797 | SQL_TOKEN_CURRENT_CATALOG
1798 | SQL_TOKEN_CURRENT_DEFAULT_TRANSFORM_GROUP
1799 | SQL_TOKEN_CURRENT_PATH
1800 | SQL_TOKEN_CURRENT_ROLE
1801 | SQL_TOKEN_CURRENT_SCHEMA
1802 | SQL_TOKEN_CURRENT_USER
1803 | SQL_TOKEN_SESSION_USER
1804 | SQL_TOKEN_SYSTEM_USER
1806 set_fct_spec:
1807 general_set_fct
1808 | '{' odbc_fct_spec '}'
1810 $$ = SQL_NEW_RULE;
1811 $$->append(newNode("{", SQLNodeType::Punctuation));
1812 $$->append($2);
1813 $$->append(newNode("}", SQLNodeType::Punctuation));
1815 | function_name '(' ')'
1817 $$ = SQL_NEW_RULE;
1818 $$->append($1);
1819 $$->append(newNode("(", SQLNodeType::Punctuation));
1820 $$->append(newNode(")", SQLNodeType::Punctuation));
1822 | function_name0 '(' ')'
1824 $$ = SQL_NEW_RULE;
1825 $$->append($1);
1826 $$->append(newNode("(", SQLNodeType::Punctuation));
1827 $$->append(newNode(")", SQLNodeType::Punctuation));
1829 | function_name1 '(' function_arg ')'
1831 $$ = SQL_NEW_RULE;
1832 $$->append($1);
1833 $$->append(newNode("(", SQLNodeType::Punctuation));
1834 $$->append($3);
1835 $$->append(newNode(")", SQLNodeType::Punctuation));
1837 | function_name2 '(' function_arg_commalist2 ')'
1839 $$ = SQL_NEW_RULE;
1840 $$->append($1);
1841 $$->append(newNode("(", SQLNodeType::Punctuation));
1842 $$->append($3);
1843 $$->append(newNode(")", SQLNodeType::Punctuation));
1845 | function_name3 '(' function_arg_commalist3 ')'
1847 $$ = SQL_NEW_RULE;
1848 $$->append($1);
1849 $$->append(newNode("(", SQLNodeType::Punctuation));
1850 $$->append($3);
1851 $$->append(newNode(")", SQLNodeType::Punctuation));
1853 | string_function_4Argument '(' function_arg_commalist4 ')'
1855 $$ = SQL_NEW_RULE;
1856 $$->append($1);
1857 $$->append(newNode("(", SQLNodeType::Punctuation));
1858 $$->append($3);
1859 $$->append(newNode(")", SQLNodeType::Punctuation));
1861 | function_name '(' function_args_commalist ')'
1863 $$ = SQL_NEW_RULE;
1864 $$->append($1);
1865 $$->append(newNode("(", SQLNodeType::Punctuation));
1866 $$->append($3);
1867 $$->append(newNode(")", SQLNodeType::Punctuation));
1869 | function_name12 '(' function_args_commalist ')'
1871 if ( $3->count() == 1 || $3->count() == 2 )
1873 $$ = SQL_NEW_RULE;
1874 $$->append($1);
1875 $$->append(newNode("(", SQLNodeType::Punctuation));
1876 $$->append($3);
1877 $$->append(newNode(")", SQLNodeType::Punctuation));
1879 else
1880 YYERROR;
1882 | function_name23 '(' function_args_commalist ')'
1884 if ( $3->count() == 2 || $3->count() == 3)
1886 $$ = SQL_NEW_RULE;
1887 $$->append($1);
1888 $$->append(newNode("(", SQLNodeType::Punctuation));
1889 $$->append($3);
1890 $$->append(newNode(")", SQLNodeType::Punctuation));
1892 else
1893 YYERROR;
1896 function_name0:
1897 date_function_0Argument
1898 | numeric_function_0Argument
1900 function_name1:
1901 string_function_1Argument
1902 | date_function_1Argument
1903 | numeric_function_1Argument
1905 function_name2:
1906 string_function_2Argument
1907 | numeric_function_2Argument
1909 function_name12:
1910 SQL_TOKEN_ROUND
1911 | SQL_TOKEN_WEEK
1912 | SQL_TOKEN_LOGF
1913 | SQL_TOKEN_LOG
1915 function_name23:
1916 SQL_TOKEN_LOCATE
1917 | SQL_TOKEN_DATEDIFF
1919 function_name3:
1920 string_function_3Argument
1922 function_name:
1923 string_function
1924 | date_function
1925 | numeric_function
1926 | SQL_TOKEN_NAME
1928 string_function_1Argument:
1929 SQL_TOKEN_LENGTH
1930 | SQL_TOKEN_ASCII
1931 | SQL_TOKEN_LCASE
1932 | SQL_TOKEN_LOWER
1933 | SQL_TOKEN_LTRIM
1934 | SQL_TOKEN_RTRIM
1935 | SQL_TOKEN_SPACE
1936 | SQL_TOKEN_UCASE
1937 | SQL_TOKEN_UPPER
1940 string_function_2Argument:
1941 SQL_TOKEN_REPEAT
1942 | SQL_TOKEN_LEFT
1943 | SQL_TOKEN_RIGHT
1945 string_function_3Argument:
1946 SQL_TOKEN_REPLACE
1948 string_function_4Argument:
1949 SQL_TOKEN_INSERT
1952 string_function:
1953 SQL_TOKEN_CHAR
1954 | SQL_TOKEN_CONCAT
1955 | SQL_TOKEN_DIFFERENCE
1956 | SQL_TOKEN_LOCATE_2
1957 | SQL_TOKEN_SOUNDEX
1959 date_function_0Argument:
1960 SQL_TOKEN_CURDATE
1961 | SQL_TOKEN_CURTIME
1962 | SQL_TOKEN_NOW
1964 date_function_1Argument:
1965 SQL_TOKEN_DAYOFWEEK
1966 | SQL_TOKEN_DAYOFMONTH
1967 | SQL_TOKEN_DAYOFYEAR
1968 | SQL_TOKEN_MONTH
1969 | SQL_TOKEN_DAYNAME
1970 | SQL_TOKEN_MONTHNAME
1971 | SQL_TOKEN_QUARTER
1972 | SQL_TOKEN_HOUR
1973 | SQL_TOKEN_MINUTE
1974 | SQL_TOKEN_SECOND
1975 | SQL_TOKEN_YEAR
1976 | SQL_TOKEN_DAY
1977 | SQL_TOKEN_TIMEVALUE
1978 | SQL_TOKEN_DATEVALUE
1981 date_function:
1982 SQL_TOKEN_TIMESTAMPADD
1983 | SQL_TOKEN_TIMESTAMPDIFF
1984 | SQL_TOKEN_DATEADD
1986 numeric_function_0Argument:
1987 SQL_TOKEN_PI
1989 numeric_function_1Argument:
1990 SQL_TOKEN_ABS
1991 | SQL_TOKEN_ACOS
1992 | SQL_TOKEN_ASIN
1993 | SQL_TOKEN_ATAN
1994 | SQL_TOKEN_CEILING
1995 | SQL_TOKEN_COS
1996 | SQL_TOKEN_COT
1997 | SQL_TOKEN_DEGREES
1998 | SQL_TOKEN_FLOOR
1999 | SQL_TOKEN_SIGN
2000 | SQL_TOKEN_SIN
2001 | SQL_TOKEN_SQRT
2002 | SQL_TOKEN_TAN
2003 | SQL_TOKEN_EXP
2004 | SQL_TOKEN_LOG10
2005 | SQL_TOKEN_LN
2006 | SQL_TOKEN_RADIANS
2007 | SQL_TOKEN_ROUNDMAGIC
2009 numeric_function_2Argument:
2010 SQL_TOKEN_ATAN2
2011 | SQL_TOKEN_MOD
2012 | SQL_TOKEN_POWER
2014 numeric_function:
2015 SQL_TOKEN_RAND
2016 | SQL_TOKEN_TRUNCATE
2019 window_function:
2020 window_function_type SQL_TOKEN_OVER window_name_or_specification
2022 $$ = SQL_NEW_RULE;
2023 $$->append($1);
2024 $$->append($2);
2025 $$->append($3);
2028 window_function_type :
2029 rank_function_type '(' ')'
2031 $$ = SQL_NEW_RULE;
2032 $$->append($1);
2033 $$->append(newNode("(", SQLNodeType::Punctuation));
2034 $$->append(newNode(")", SQLNodeType::Punctuation));
2036 | SQL_TOKEN_ROW_NUMBER '(' ')'
2038 $$ = SQL_NEW_RULE;
2039 $$->append($1);
2040 $$->append(newNode("(", SQLNodeType::Punctuation));
2041 $$->append(newNode(")", SQLNodeType::Punctuation));
2043 | general_set_fct
2044 | ntile_function
2045 | lead_or_lag_function
2046 | first_or_last_value_function
2047 | nth_value_function
2049 ntile_function :
2050 SQL_TOKEN_NTILE '(' number_of_tiles ')'
2052 $$ = SQL_NEW_RULE;
2053 $$->append($1);
2054 $$->append(newNode("(", SQLNodeType::Punctuation));
2055 $$->append($3);
2056 $$->append(newNode(")", SQLNodeType::Punctuation));
2059 dynamic_parameter_specification:
2060 parameter
2062 simple_value_specification:
2063 literal
2065 number_of_tiles :
2066 simple_value_specification
2067 | dynamic_parameter_specification
2069 opt_lead_or_lag_function:
2070 /* empty */ {$$ = SQL_NEW_RULE;}
2071 | ',' offset
2073 $$ = SQL_NEW_RULE;
2074 $$->append(newNode(",", SQLNodeType::Punctuation));
2075 $$->append($2);
2077 | ',' offset ',' default_expression
2079 $$ = SQL_NEW_RULE;
2080 $$->append(newNode(",", SQLNodeType::Punctuation));
2081 $$->append($2);
2082 $$->append(newNode(",", SQLNodeType::Punctuation));
2083 $$->append($4);
2086 opt_null_treatment:
2087 /* empty */ {$$ = SQL_NEW_RULE;}
2088 | null_treatment
2091 lead_or_lag_function:
2092 lead_or_lag '(' lead_or_lag_extent opt_lead_or_lag_function ')' opt_null_treatment
2094 $$ = SQL_NEW_RULE;
2095 $$->append($1);
2096 $$->append(newNode("(", SQLNodeType::Punctuation));
2097 $$->append($3);
2098 $$->append($4);
2099 $$->append(newNode(")", SQLNodeType::Punctuation));
2100 $$->append($6);
2103 lead_or_lag:
2104 SQL_TOKEN_LEAD
2105 | SQL_TOKEN_LAG
2107 lead_or_lag_extent:
2108 value_exp
2110 offset:
2111 SQL_TOKEN_INTNUM
2113 default_expression:
2114 value_exp
2116 null_treatment:
2117 SQL_TOKEN_RESPECT SQL_TOKEN_NULLS
2118 | SQL_TOKEN_IGNORE SQL_TOKEN_NULLS
2120 first_or_last_value_function:
2121 first_or_last_value '(' value_exp ')' opt_null_treatment
2123 $$ = SQL_NEW_RULE;
2124 $$->append($1);
2125 $$->append(newNode("(", SQLNodeType::Punctuation));
2126 $$->append($3);
2127 $$->append(newNode(")", SQLNodeType::Punctuation));
2128 $$->append($5);
2131 first_or_last_value :
2132 SQL_TOKEN_FIRST_VALUE
2133 | SQL_TOKEN_LAST_VALUE
2135 opt_from_first_or_last:
2136 /* empty */ {$$ = SQL_NEW_RULE;}
2137 | from_first_or_last
2139 nth_value_function:
2140 SQL_TOKEN_NTH_VALUE '(' value_exp ',' nth_row ')' opt_from_first_or_last opt_null_treatment
2142 $$ = SQL_NEW_RULE;
2143 $$->append($1);
2144 $$->append(newNode("(", SQLNodeType::Punctuation));
2145 $$->append($3);
2146 $$->append(newNode(",", SQLNodeType::Punctuation));
2147 $$->append($5);
2148 $$->append(newNode(")", SQLNodeType::Punctuation));
2149 $$->append($7);
2150 $$->append($8);
2153 nth_row:
2154 simple_value_specification
2155 | dynamic_parameter_specification
2157 from_first_or_last:
2158 SQL_TOKEN_FROM SQL_TOKEN_FIRST
2160 $$ = SQL_NEW_RULE;
2161 $$->append($1);
2162 $$->append($2);
2164 | SQL_TOKEN_FROM SQL_TOKEN_LAST
2166 $$ = SQL_NEW_RULE;
2167 $$->append($1);
2168 $$->append($2);
2171 window_name:
2172 SQL_TOKEN_NAME
2174 window_name_or_specification:
2175 window_name
2176 | in_line_window_specification
2178 in_line_window_specification:
2179 window_specification
2181 opt_window_clause:
2182 /* empty */ {$$ = SQL_NEW_RULE;}
2183 | window_clause
2185 window_clause:
2186 SQL_TOKEN_WINDOW window_definition_list
2188 $$ = SQL_NEW_RULE;
2189 $$->append($1);
2190 $$->append($2);
2193 window_definition_list:
2194 window_definition_list ',' window_definition
2195 {$1->append($3);
2196 $$ = $1;}
2197 | window_definition
2198 {$$ = SQL_NEW_COMMALISTRULE;
2199 $$->append($1);}
2201 window_definition:
2202 new_window_name SQL_TOKEN_AS window_specification
2204 $$ = SQL_NEW_RULE;
2205 $$->append($1);
2206 $$->append($2);
2207 $$->append($3);
2210 new_window_name:
2211 window_name
2213 window_specification:
2215 opt_existing_window_name
2216 opt_window_partition_clause
2217 opt_order_by_clause
2218 opt_window_frame_clause
2221 $$ = SQL_NEW_RULE;
2222 $$->append(newNode("(", SQLNodeType::Punctuation));
2223 $$->append($2);
2224 $$->append($3);
2225 $$->append($4);
2226 $$->append($5);
2227 $$->append(newNode(")", SQLNodeType::Punctuation));
2230 opt_existing_window_name:
2231 /* empty */ {$$ = SQL_NEW_RULE;}
2232 | existing_window_name
2234 opt_window_partition_clause:
2235 /* empty */ {$$ = SQL_NEW_RULE;}
2236 | window_partition_clause
2238 opt_window_frame_clause:
2239 /* empty */ {$$ = SQL_NEW_RULE;}
2240 | window_frame_clause
2242 existing_window_name:
2243 window_name
2245 window_partition_clause:
2246 SQL_TOKEN_PARTITION SQL_TOKEN_BY window_partition_column_reference_list
2248 $$ = SQL_NEW_RULE;
2249 $$->append($1);
2250 $$->append($2);
2251 $$->append($3);
2254 window_partition_column_reference_list:
2255 window_partition_column_reference_list ',' window_partition_column_reference
2256 {$1->append($3);
2257 $$ = $1;}
2258 | window_partition_column_reference
2259 {$$ = SQL_NEW_COMMALISTRULE;
2260 $$->append($1);}
2262 window_partition_column_reference:
2263 column_ref opt_collate_clause
2265 $$ = SQL_NEW_RULE;
2266 $$->append($1);
2267 $$->append($2);
2270 opt_window_frame_exclusion:
2271 /* empty */ {$$ = SQL_NEW_RULE;}
2272 | window_frame_exclusion
2274 window_frame_clause:
2275 window_frame_units window_frame_extent opt_window_frame_exclusion
2277 $$ = SQL_NEW_RULE;
2278 $$->append($1);
2279 $$->append($2);
2280 $$->append($3);
2283 window_frame_units:
2284 SQL_TOKEN_ROWS
2285 | SQL_TOKEN_RANGE
2287 window_frame_extent:
2288 window_frame_start
2289 | window_frame_between
2291 window_frame_start:
2292 SQL_TOKEN_UNBOUNDED SQL_TOKEN_PRECEDING
2294 $$ = SQL_NEW_RULE;
2295 $$->append($1);
2296 $$->append($2);
2298 | window_frame_preceding
2299 | SQL_TOKEN_CURRENT SQL_TOKEN_ROW
2301 $$ = SQL_NEW_RULE;
2302 $$->append($1);
2303 $$->append($2);
2306 window_frame_preceding:
2307 unsigned_value_spec SQL_TOKEN_PRECEDING
2309 $$ = SQL_NEW_RULE;
2310 $$->append($1);
2311 $$->append($2);
2314 window_frame_between:
2315 SQL_TOKEN_BETWEEN window_frame_bound_1 SQL_TOKEN_AND window_frame_bound_2
2317 $$ = SQL_NEW_RULE;
2318 $$->append($1);
2319 $$->append($2);
2320 $$->append($3);
2321 $$->append($4);
2324 window_frame_bound_1:
2325 window_frame_bound
2327 window_frame_bound_2:
2328 window_frame_bound
2330 window_frame_bound:
2331 window_frame_start
2332 | SQL_TOKEN_UNBOUNDED SQL_TOKEN_FOLLOWING
2334 $$ = SQL_NEW_RULE;
2335 $$->append($1);
2336 $$->append($2);
2338 | window_frame_following
2340 window_frame_following:
2341 unsigned_value_spec SQL_TOKEN_FOLLOWING
2343 $$ = SQL_NEW_RULE;
2344 $$->append($1);
2345 $$->append($2);
2348 window_frame_exclusion:
2349 SQL_TOKEN_EXCLUDE SQL_TOKEN_CURRENT SQL_TOKEN_ROW
2351 $$ = SQL_NEW_RULE;
2352 $$->append($1);
2353 $$->append($2);
2354 $$->append($3);
2356 | SQL_TOKEN_EXCLUDE SQL_TOKEN_GROUP
2358 $$ = SQL_NEW_RULE;
2359 $$->append($1);
2360 $$->append($2);
2362 | SQL_TOKEN_EXCLUDE SQL_TOKEN_TIES
2364 $$ = SQL_NEW_RULE;
2365 $$->append($1);
2366 $$->append($2);
2368 | SQL_TOKEN_EXCLUDE SQL_TOKEN_NO SQL_TOKEN_OTHERS
2370 $$ = SQL_NEW_RULE;
2371 $$->append($1);
2372 $$->append($2);
2373 $$->append($3);
2376 op_parameter:
2377 {$$ = SQL_NEW_RULE;}
2378 | '?' SQL_EQUAL
2380 $$ = SQL_NEW_RULE;
2381 $$->append(newNode("?", SQLNodeType::Punctuation));
2382 $$->append($2);
2385 odbc_call_spec:
2386 op_parameter SQL_TOKEN_CALL table_node op_odbc_call_parameter
2388 $$ = SQL_NEW_RULE;
2389 $$->append($1);
2390 $$->append($2);
2391 $$->append($3);
2392 $$->append($4);
2396 op_odbc_call_parameter:
2397 {$$ = SQL_NEW_RULE;}
2398 | '(' odbc_parameter_commalist ')'
2400 $$ = SQL_NEW_RULE;
2401 $$->append(newNode("(", SQLNodeType::Punctuation));
2402 $$->append($2);
2403 $$->append(newNode(")", SQLNodeType::Punctuation));
2407 odbc_parameter_commalist:
2408 odbc_parameter
2409 {$$ = SQL_NEW_COMMALISTRULE;
2410 $$->append($1);}
2411 | odbc_parameter_commalist ',' odbc_parameter
2413 $1->append($3);
2414 $$ = $1;
2417 odbc_parameter:
2418 /* empty */ {$$ = SQL_NEW_RULE;}
2419 | literal
2420 | parameter
2423 odbc_fct_spec:
2424 odbc_fct_type SQL_TOKEN_STRING
2426 $$ = SQL_NEW_RULE;
2427 $$->append($1);
2428 $$->append($2);
2430 | SQL_TOKEN_FN set_fct_spec
2432 $$ = SQL_NEW_RULE;
2433 $$->append($1);
2434 $$->append($2);
2438 odbc_fct_type:
2439 SQL_TOKEN_D
2440 | SQL_TOKEN_T
2441 | SQL_TOKEN_TS
2444 general_set_fct:
2445 set_fct_type '(' opt_all_distinct function_arg ')'
2447 $$ = SQL_NEW_RULE;
2448 $$->append($1);
2449 $$->append(newNode("(", SQLNodeType::Punctuation));
2450 $$->append($3);
2451 $$->append($4);
2452 $$->append(newNode(")", SQLNodeType::Punctuation));
2454 | SQL_TOKEN_COUNT '(' '*' ')'
2456 $$ = SQL_NEW_RULE;
2457 $$->append($1);
2458 $$->append(newNode("(", SQLNodeType::Punctuation));
2459 $$->append(newNode("*", SQLNodeType::Punctuation));
2460 $$->append(newNode(")", SQLNodeType::Punctuation));
2462 | SQL_TOKEN_COUNT '(' opt_all_distinct function_arg ')'
2464 $$ = SQL_NEW_RULE;
2465 $$->append($1);
2466 $$->append(newNode("(", SQLNodeType::Punctuation));
2467 $$->append($3);
2468 $$->append($4);
2469 $$->append(newNode(")", SQLNodeType::Punctuation));
2471 | ordered_set_function
2472 | array_aggregate_function
2474 set_fct_type:
2475 SQL_TOKEN_AVG
2476 | SQL_TOKEN_MAX
2477 | SQL_TOKEN_MIN
2478 | SQL_TOKEN_SUM
2479 | SQL_TOKEN_EVERY
2480 | SQL_TOKEN_ANY
2481 | SQL_TOKEN_SOME
2482 | SQL_TOKEN_STDDEV_POP
2483 | SQL_TOKEN_STDDEV_SAMP
2484 | SQL_TOKEN_VAR_SAMP
2485 | SQL_TOKEN_VAR_POP
2486 | SQL_TOKEN_COLLECT
2487 | SQL_TOKEN_FUSION
2488 | SQL_TOKEN_INTERSECTION
2491 ordered_set_function:
2492 hypothetical_set_function
2493 | inverse_distribution_function
2495 hypothetical_set_function:
2496 rank_function_type '(' hypothetical_set_function_value_expression_list ')' within_group_specification
2498 $$ = SQL_NEW_RULE;
2499 $$->append($1);
2500 $$->append(newNode("(", SQLNodeType::Punctuation));
2501 $$->append($3);
2502 $$->append(newNode(")", SQLNodeType::Punctuation));
2503 $$->append($5);
2505 | rank_function_type '(' hypothetical_set_function_value_expression_list SQL_TOKEN_BY value_exp_commalist ')' within_group_specification
2507 $$ = SQL_NEW_RULE;
2508 $$->append($1);
2509 $$->append(newNode("(", SQLNodeType::Punctuation));
2510 $$->append($3);
2511 $$->append($4);
2512 $$->append($5);
2513 $$->append(newNode(")", SQLNodeType::Punctuation));
2514 $$->append($7);
2518 within_group_specification:
2520 $$ = SQL_NEW_RULE;
2522 | SQL_TOKEN_WITHIN SQL_TOKEN_GROUP '(' opt_order_by_clause ')'
2524 $$ = SQL_NEW_RULE;
2525 $$->append($1);
2526 $$->append($2);
2527 $$->append(newNode("(", SQLNodeType::Punctuation));
2528 $$->append($4);
2529 $$->append(newNode(")", SQLNodeType::Punctuation));
2532 hypothetical_set_function_value_expression_list:
2533 value_exp_commalist
2536 inverse_distribution_function:
2537 inverse_distribution_function_type '('inverse_distribution_function_argument ')' within_group_specification
2539 $$ = SQL_NEW_RULE;
2540 $$->append($1);
2541 $$->append(newNode("(", SQLNodeType::Punctuation));
2542 $$->append($3);
2543 $$->append(newNode(")", SQLNodeType::Punctuation));
2546 inverse_distribution_function_argument:
2547 num_value_exp
2549 inverse_distribution_function_type:
2550 SQL_TOKEN_PERCENTILE_CONT
2551 | SQL_TOKEN_PERCENTILE_DISC
2554 array_aggregate_function:
2555 SQL_TOKEN_ARRAY_AGG '(' value_exp opt_order_by_clause ')'
2557 $$ = SQL_NEW_RULE;
2558 $$->append($1);
2559 $$->append(newNode("(", SQLNodeType::Punctuation));
2560 $$->append($3);
2561 $$->append($4);
2562 $$->append(newNode(")", SQLNodeType::Punctuation));
2566 rank_function_type:
2567 SQL_TOKEN_RANK
2568 | SQL_TOKEN_DENSE_RANK
2569 | SQL_TOKEN_PERCENT_RANK
2570 | SQL_TOKEN_CUME_DIST
2572 outer_join_type:
2573 SQL_TOKEN_LEFT %prec SQL_TOKEN_LEFT
2575 $$ = SQL_NEW_RULE;
2576 $$->append($1);
2578 | SQL_TOKEN_RIGHT %prec SQL_TOKEN_RIGHT
2580 $$ = SQL_NEW_RULE;
2581 $$->append($1);
2583 | SQL_TOKEN_FULL %prec SQL_TOKEN_FULL
2585 $$ = SQL_NEW_RULE;
2586 $$->append($1);
2589 join_condition:
2590 SQL_TOKEN_ON search_condition
2592 $$ = SQL_NEW_RULE;
2593 $$->append($1);
2594 $$->append($2);
2597 join_spec:
2598 join_condition
2599 | named_columns_join
2601 join_type:
2602 /* empty */ {$$ = SQL_NEW_RULE;}
2603 | SQL_TOKEN_INNER
2605 $$ = SQL_NEW_RULE;
2606 $$->append($1);
2608 | outer_join_type
2609 | outer_join_type SQL_TOKEN_OUTER
2611 $$ = SQL_NEW_RULE;
2612 $$->append($1);
2613 $$->append($2);
2616 cross_union:
2617 table_ref SQL_TOKEN_CROSS SQL_TOKEN_JOIN table_ref
2619 $$ = SQL_NEW_RULE;
2620 $$->append($1);
2621 $$->append($2);
2622 $$->append($3);
2623 $$->append($4);
2627 qualified_join:
2628 /* when SQL_TOKEN_NATURAL, then no join_spec */
2629 table_ref SQL_TOKEN_NATURAL join_type SQL_TOKEN_JOIN table_ref
2631 $$ = SQL_NEW_RULE;
2632 $$->append($1);
2633 $$->append($2);
2634 $$->append($3);
2635 $$->append($4);
2636 $$->append($5);
2638 | table_ref join_type SQL_TOKEN_JOIN table_ref join_spec
2640 $$ = SQL_NEW_RULE;
2641 $$->append($1);
2642 $$->append($2);
2643 $$->append($3);
2644 $$->append($4);
2645 $$->append($5);
2647 | cross_union
2649 joined_table:
2650 qualified_join
2652 named_columns_join:
2653 SQL_TOKEN_USING '(' column_commalist ')'
2655 $$ = SQL_NEW_RULE;
2656 $$->append($1);
2657 $$->append(newNode("(", SQLNodeType::Punctuation));
2658 $$->append($3);
2659 $$->append(newNode(")", SQLNodeType::Punctuation));
2662 simple_table:
2663 select_statement
2664 | values_or_query_spec
2667 non_join_query_primary:
2668 simple_table
2669 | '(' non_join_query_exp ')'
2671 $$ = SQL_NEW_RULE;
2672 $$->append(newNode("(", SQLNodeType::Punctuation));
2673 $$->append($2);
2674 $$->append(newNode(")", SQLNodeType::Punctuation));
2677 non_join_query_term:
2678 non_join_query_primary
2679 | query_term SQL_TOKEN_INTERSECT all query_primary
2681 $$ = SQL_NEW_RULE;
2682 $$->append($1);
2683 $$->append($2);
2684 $$->append($3);
2685 $$->append($4);
2688 query_primary:
2689 non_join_query_primary
2691 non_join_query_exp:
2692 non_join_query_term
2693 | query_exp SQL_TOKEN_UNION all query_term
2695 $$ = SQL_NEW_RULE;
2696 $$->append($1);
2697 $$->append($2);
2698 $$->append($3);
2699 $$->append($4);
2701 | query_exp SQL_TOKEN_EXCEPT all query_term
2703 $$ = SQL_NEW_RULE;
2704 $$->append($1);
2705 $$->append($2);
2706 $$->append($3);
2707 $$->append($4);
2710 all:
2711 /* empty*/ {$$ = SQL_NEW_RULE;}
2712 | SQL_TOKEN_ALL
2714 query_exp:
2715 non_join_query_exp /*[^')']*/
2717 scalar_subquery:
2718 subquery
2720 cast_operand:
2721 value_exp
2723 cast_target:
2724 table_node
2725 | data_type
2727 cast_spec:
2728 SQL_TOKEN_CAST '(' cast_operand SQL_TOKEN_AS cast_target ')'
2730 $$ = SQL_NEW_RULE;
2731 $$->append($1);
2732 $$->append(newNode("(", SQLNodeType::Punctuation));
2733 $$->append($3);
2734 $$->append($4);
2735 $$->append($5);
2736 $$->append(newNode(")", SQLNodeType::Punctuation));
2739 value_exp_primary:
2740 unsigned_value_spec
2741 | column_ref
2742 | set_fct_spec
2743 | scalar_subquery
2744 | case_expression
2745 | window_function
2746 | '(' value_exp ')'
2748 $$ = SQL_NEW_RULE;
2749 $$->append(newNode("(", SQLNodeType::Punctuation));
2750 $$->append($2);
2751 $$->append(newNode(")", SQLNodeType::Punctuation));
2753 | cast_spec
2756 num_primary:
2757 value_exp_primary
2758 | num_value_fct
2760 factor:
2761 num_primary
2762 | '-' num_primary %prec SQL_TOKEN_UMINUS
2764 $$ = SQL_NEW_RULE;
2765 $$->append(newNode("-", SQLNodeType::Punctuation));
2766 $$->append($2);
2768 | '+' num_primary %prec SQL_TOKEN_UMINUS
2770 $$ = SQL_NEW_RULE;
2771 $$->append(newNode("+", SQLNodeType::Punctuation));
2772 $$->append($2);
2776 term:
2777 factor
2778 | term '*' factor
2780 $$ = SQL_NEW_RULE;
2781 $$->append($1);
2782 $$->append(newNode("*", SQLNodeType::Punctuation));
2783 $$->append($3);
2785 | term '/' factor
2787 $$ = SQL_NEW_RULE;
2788 $$->append($1);
2789 $$->append(newNode("/", SQLNodeType::Punctuation));
2790 $$->append($3);
2794 num_value_exp:
2795 term
2796 | num_value_exp '+' term
2798 $$ = SQL_NEW_RULE;
2799 $$->append($1);
2800 $$->append(newNode("+", SQLNodeType::Punctuation));
2801 $$->append($3);
2803 | num_value_exp '-' term
2805 $$ = SQL_NEW_RULE;
2806 $$->append($1);
2807 $$->append(newNode("-", SQLNodeType::Punctuation));
2808 $$->append($3);
2811 datetime_primary:
2812 /* value_exp_primary
2814 $$ = SQL_NEW_RULE;
2815 $$->append($1);
2817 |*/ datetime_value_fct
2819 $$ = SQL_NEW_RULE;
2820 $$->append($1);
2823 datetime_value_fct:
2824 SQL_TOKEN_CURRENT_DATE
2826 $$ = SQL_NEW_RULE;
2827 $$->append($1);
2829 | SQL_TOKEN_CURRENT_TIME
2831 $$ = SQL_NEW_RULE;
2832 $$->append($1);
2834 | SQL_TOKEN_CURRENT_TIMESTAMP
2836 $$ = SQL_NEW_RULE;
2837 $$->append($1);
2840 time_zone:
2841 SQL_TOKEN_AT time_zone_specifier
2843 $$ = SQL_NEW_RULE;
2844 $$->append($1);
2845 $$->append($2);
2848 time_zone_specifier:
2849 SQL_TOKEN_LOCAL
2851 $$ = SQL_NEW_RULE;
2852 $$->append($1);
2854 /* | SQL_TOKEN_TIME SQL_TOKEN_ZONE interval_value_exp
2856 $$ = SQL_NEW_RULE;
2857 $$->append($1);
2858 $$->append($2);
2859 $$->append($3);
2862 datetime_factor:
2863 datetime_primary
2865 $$ = SQL_NEW_RULE;
2866 $$->append($1);
2868 | datetime_primary time_zone
2870 $$ = SQL_NEW_RULE;
2871 $$->append($1);
2872 $$->append($2);
2875 datetime_term:
2876 datetime_factor
2878 $$ = SQL_NEW_RULE;
2879 $$->append($1);
2883 interval_term:
2884 literal
2885 | interval_term '*' factor
2887 $$ = SQL_NEW_RULE;
2888 $$->append($1);
2889 $$->append(newNode("*", SQLNodeType::Punctuation));
2890 $$->append($3);
2892 | interval_term '/' factor
2894 $$ = SQL_NEW_RULE;
2895 $$->append($1);
2896 $$->append(newNode("/", SQLNodeType::Punctuation));
2897 $$->append($3);
2901 datetime_value_exp:
2902 datetime_term
2904 $$ = SQL_NEW_RULE;
2905 $$->append($1);
2907 /* | interval_value_exp '+' datetime_term
2909 $$ = SQL_NEW_RULE;
2910 $$->append($1);
2911 $$->append(newNode("+", SQLNodeType::Punctuation));
2912 $$->append($3);
2914 | datetime_value_exp '+' interval_term
2916 $$ = SQL_NEW_RULE;
2917 $$->append($1);
2918 $$->append(newNode("+", SQLNodeType::Punctuation));
2919 $$->append($3);
2921 | datetime_value_exp '-' interval_term
2923 $$ = SQL_NEW_RULE;
2924 $$->append($1);
2925 $$->append(newNode("-", SQLNodeType::Punctuation));
2926 $$->append($3);
2928 */ ;
2930 interval_value_exp:
2931 interval_term
2933 $$ = SQL_NEW_RULE;
2934 $$->append($1);
2936 | interval_value_exp '+' interval_term
2938 $$ = SQL_NEW_RULE;
2939 $$->append($1);
2940 $$->append(newNode("+", SQLNodeType::Punctuation));
2941 $$->append($3);
2943 | interval_value_exp '-' interval_term
2945 $$ = SQL_NEW_RULE;
2946 $$->append($1);
2947 $$->append(newNode("-", SQLNodeType::Punctuation));
2948 $$->append($3);
2950 | '(' datetime_value_exp '-' datetime_term ')' interval_qualifier
2952 $$ = SQL_NEW_RULE;
2953 $$->append(newNode("(", SQLNodeType::Punctuation));
2954 $$->append($2);
2955 $$->append(newNode("-", SQLNodeType::Punctuation));
2956 $$->append($4);
2957 $$->append(newNode(")", SQLNodeType::Punctuation));
2958 $$->append($6);
2962 non_second_datetime_field:
2963 SQL_TOKEN_YEAR
2964 | SQL_TOKEN_YEARDAY
2965 | SQL_TOKEN_MONTH
2966 | SQL_TOKEN_WEEK
2967 | SQL_TOKEN_WEEKDAY
2968 | SQL_TOKEN_DAY
2969 | SQL_TOKEN_HOUR
2970 | SQL_TOKEN_MINUTE
2971 | SQL_TOKEN_MILLISECOND
2974 datetime_unit:
2975 SQL_TOKEN_YEAR
2976 | SQL_TOKEN_MONTH
2977 | SQL_TOKEN_WEEK
2978 | SQL_TOKEN_DAY
2979 | SQL_TOKEN_HOUR
2980 | SQL_TOKEN_MINUTE
2981 | SQL_TOKEN_SECOND
2982 | SQL_TOKEN_MILLISECOND
2985 start_field:
2986 non_second_datetime_field opt_paren_precision
2988 $$ = SQL_NEW_RULE;
2989 $$->append($1);
2990 $$->append($2);
2993 end_field:
2994 non_second_datetime_field
2995 | SQL_TOKEN_SECOND opt_paren_precision
2997 $$ = SQL_NEW_RULE;
2998 $$->append($1);
2999 $$->append($2);
3003 single_datetime_field:
3004 non_second_datetime_field opt_paren_precision
3006 $$ = SQL_NEW_RULE;
3007 $$->append($1);
3008 $$->append($2);
3010 | SQL_TOKEN_SECOND opt_paren_precision_scale
3012 $$ = SQL_NEW_RULE;
3013 $$->append($1);
3014 $$->append($2);
3018 interval_qualifier:
3019 start_field SQL_TOKEN_TO end_field
3021 $$ = SQL_NEW_RULE;
3022 $$->append($1);
3023 $$->append($2);
3024 $$->append($3);
3026 | single_datetime_field
3029 function_arg_commalist2:
3030 function_arg ',' function_arg
3031 {$$ = SQL_NEW_COMMALISTRULE;
3032 $$->append($1);
3033 $$->append($3);}
3035 function_arg_commalist3:
3036 function_arg ',' function_arg ',' function_arg
3038 $$ = SQL_NEW_COMMALISTRULE;
3039 $$->append($1);
3040 $$->append($3);
3041 $$->append($5);
3044 function_arg_commalist4:
3045 function_arg ',' function_arg ',' function_arg ',' function_arg
3047 $$ = SQL_NEW_COMMALISTRULE;
3048 $$->append($1);
3049 $$->append($3);
3050 $$->append($5);
3051 $$->append($7);
3054 value_exp_commalist:
3055 value_exp
3056 {$$ = SQL_NEW_COMMALISTRULE;
3057 $$->append($1);}
3058 | value_exp_commalist ',' value_exp
3059 {$1->append($3);
3060 $$ = $1;}
3061 /* this rule is only valid if we check predicates */
3062 | value_exp_commalist ';' value_exp
3064 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
3066 $1->append($3);
3067 $$ = $1;
3069 else
3070 YYERROR;
3073 function_arg:
3074 result
3075 | value_exp comparison value_exp
3077 $$ = SQL_NEW_RULE;
3078 $$->append($1);
3079 $$->append($2);
3080 $$->append($3);
3082 | value_exp SQL_TOKEN_USING value_exp comparison value_exp
3084 $$ = SQL_NEW_RULE;
3085 $$->append($1);
3086 $$->append($2);
3087 $$->append($3);
3088 $$->append($4);
3090 | value_exp SQL_TOKEN_BY value_exp_commalist
3092 $$ = SQL_NEW_RULE;
3093 $$->append($1);
3094 $$->append($2);
3095 $$->append($3);
3098 function_args_commalist:
3099 function_arg
3100 {$$ = SQL_NEW_COMMALISTRULE;
3101 $$->append($1);}
3102 | function_args_commalist ',' function_arg
3103 {$1->append($3);
3104 $$ = $1;}
3105 /* this rule is only valid if we check predicates */
3106 | function_args_commalist ';' function_arg
3108 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
3110 $1->append($3);
3111 $$ = $1;
3113 else
3114 YYERROR;
3116 | datetime_unit ',' function_arg ',' function_arg
3118 $$ = SQL_NEW_COMMALISTRULE;
3119 $$->append($1);
3120 $$->append($3);
3121 $$->append($5);
3125 value_exp:
3126 num_value_exp /*[^')']*/
3127 | string_value_exp
3128 | datetime_value_exp
3130 $$ = SQL_NEW_RULE;
3131 $$->append($1);
3134 string_value_exp:
3135 char_value_exp
3136 /* | bit_value_exp
3138 $$ = SQL_NEW_RULE;
3139 $$->append($1);
3141 */ ;
3142 char_value_exp:
3143 char_factor
3144 | concatenation
3146 concatenation:
3147 char_value_exp '+' char_factor
3149 $$ = SQL_NEW_RULE;
3150 $$->append($1);
3151 $$->append(newNode("+", SQLNodeType::Punctuation));
3152 $$->append($3);
3154 | value_exp SQL_CONCAT value_exp
3156 $$ = SQL_NEW_RULE;
3157 $$->append($1);
3158 $$->append($2);
3159 $$->append($3);
3163 char_primary:
3164 SQL_TOKEN_STRING
3165 | string_value_fct
3167 collate_clause:
3168 SQL_TOKEN_COLLATE table_node
3170 $$ = SQL_NEW_RULE;
3171 $$->append($1);
3172 $$->append($2);
3175 char_factor:
3176 char_primary
3177 | char_primary collate_clause
3179 $$ = SQL_NEW_RULE;
3180 $$->append($1);
3181 $$->append($2);
3184 string_value_fct:
3185 char_value_fct
3186 | bit_value_fct
3188 bit_value_fct:
3189 bit_substring_fct
3191 $$ = SQL_NEW_RULE;
3192 $$->append($1);
3195 bit_substring_fct:
3196 SQL_TOKEN_SUBSTRING '(' bit_value_exp SQL_TOKEN_FROM string_value_exp for_length ')'
3198 $$ = SQL_NEW_RULE;
3199 $$->append($1);
3200 $$->append(newNode("(", SQLNodeType::Punctuation));
3201 $$->append($3);
3202 $$->append($4);
3203 $$->append($5);
3204 $$->append($6);
3205 $$->append(newNode(")", SQLNodeType::Punctuation));
3208 bit_value_exp:
3209 bit_factor
3211 $$ = SQL_NEW_RULE;
3212 $$->append($1);
3216 bit_concatenation
3218 $$ = SQL_NEW_RULE;
3219 $$->append($1);
3222 bit_concatenation:
3223 bit_value_exp '+' bit_factor
3225 $$ = SQL_NEW_RULE;
3226 $$->append($1);
3227 $$->append(newNode("+", SQLNodeType::Punctuation));
3228 $$->append($3);
3232 bit_factor:
3233 bit_primary
3235 $$ = SQL_NEW_RULE;
3236 $$->append($1);
3239 bit_primary:
3240 {$$ = SQL_NEW_RULE;}
3241 /* value_exp_primary
3243 $$ = SQL_NEW_RULE;
3244 $$->append($1);
3246 | string_value_fct
3248 $$ = SQL_NEW_RULE;
3249 $$->append($1);
3252 char_value_fct:
3253 char_substring_fct
3254 | form_conversion
3256 $$ = SQL_NEW_RULE;
3257 $$->append($1);
3259 | char_translation
3261 $$ = SQL_NEW_RULE;
3262 $$->append($1);
3264 | trim_fct
3266 $$ = SQL_NEW_RULE;
3267 $$->append($1);
3270 for_length:
3271 {$$ = SQL_NEW_RULE;}
3272 | SQL_TOKEN_FOR value_exp
3274 $$ = SQL_NEW_RULE;
3275 $$->append($1);
3276 $$->append($2);
3279 char_substring_fct:
3280 SQL_TOKEN_SUBSTRING '(' value_exp SQL_TOKEN_FROM value_exp for_length ')'
3282 $$ = SQL_NEW_RULE;
3283 $$->append($1);
3284 $$->append(newNode("(", SQLNodeType::Punctuation));
3285 $$->append($3);
3286 $$->append($4);
3287 $$->append($5);
3288 $$->append($6);
3289 $$->append(newNode(")", SQLNodeType::Punctuation));
3291 | SQL_TOKEN_SUBSTRING '(' value_exp_commalist ')'
3293 $$ = SQL_NEW_RULE;
3294 $$->append($1);
3295 $$->append(newNode("(", SQLNodeType::Punctuation));
3296 $$->append($3);
3297 $$->append(newNode(")", SQLNodeType::Punctuation));
3300 form_conversion:
3301 SQL_TOKEN_CONVERT '(' string_value_exp SQL_TOKEN_USING table_node ')'
3303 $$ = SQL_NEW_RULE;
3304 $$->append($1);
3305 $$->append(newNode("(", SQLNodeType::Punctuation));
3306 $$->append($3);
3307 $$->append($4);
3308 $$->append($5);
3309 $$->append(newNode(")", SQLNodeType::Punctuation));
3311 | SQL_TOKEN_CONVERT '(' cast_operand ',' cast_target ')'
3313 $$ = SQL_NEW_RULE;
3314 $$->append($1);
3315 $$->append(newNode("(", SQLNodeType::Punctuation));
3316 $$->append($3);
3317 $$->append(newNode(",", SQLNodeType::Punctuation));
3318 $$->append($5);
3319 $$->append(newNode(")", SQLNodeType::Punctuation));
3322 char_translation:
3323 SQL_TOKEN_TRANSLATE '(' string_value_exp SQL_TOKEN_USING table_node ')'
3325 $$ = SQL_NEW_RULE;
3326 $$->append($1);
3327 $$->append(newNode("(", SQLNodeType::Punctuation));
3328 $$->append($3);
3329 $$->append($4);
3330 $$->append($5);
3331 $$->append(newNode(")", SQLNodeType::Punctuation));
3334 trim_fct:
3335 SQL_TOKEN_TRIM '(' trim_operands ')'
3337 $$ = SQL_NEW_RULE;
3338 $$->append($1);
3339 $$->append(newNode("(", SQLNodeType::Punctuation));
3340 $$->append($3);
3341 $$->append(newNode(")", SQLNodeType::Punctuation));
3344 trim_operands:
3345 trim_spec value_exp SQL_TOKEN_FROM value_exp
3347 $$ = SQL_NEW_RULE;
3348 $$->append($1);
3349 $$->append($2);
3350 $$->append($3);
3351 $$->append($4);
3353 | trim_spec SQL_TOKEN_FROM value_exp
3355 $$ = SQL_NEW_RULE;
3356 $$->append($1);
3357 $$->append($2);
3358 $$->append($3);
3360 | value_exp SQL_TOKEN_FROM value_exp
3362 $$ = SQL_NEW_RULE;
3363 $$->append($1);
3364 $$->append($2);
3365 $$->append($3);
3367 | SQL_TOKEN_FROM value_exp
3369 $$ = SQL_NEW_RULE;
3370 $$->append($1);
3371 $$->append($2);
3373 | value_exp
3376 trim_spec:
3377 SQL_TOKEN_BOTH
3378 | SQL_TOKEN_LEADING
3379 | SQL_TOKEN_TRAILING
3382 derived_column:
3383 value_exp as_clause
3385 $$ = SQL_NEW_RULE;
3386 $$->append($1);
3387 $$->append($2);
3390 /* Tabellenname */
3391 table_node:
3392 table_name
3393 | schema_name
3394 | catalog_name
3396 catalog_name:
3397 SQL_TOKEN_NAME '.' schema_name
3399 $$ = SQL_NEW_RULE;
3400 $$->append($1);
3401 $$->append(newNode(".", SQLNodeType::Punctuation));
3402 $$->append($3);
3404 | SQL_TOKEN_NAME ':' schema_name
3406 $$ = SQL_NEW_RULE;
3407 $$->append($1);
3408 $$->append(newNode(":", SQLNodeType::Punctuation));
3409 $$->append($3);
3412 schema_name:
3413 SQL_TOKEN_NAME '.' table_name
3415 $$ = SQL_NEW_RULE;
3416 $$->append($1);
3417 $$->append(newNode(".", SQLNodeType::Punctuation));
3418 $$->append($3);
3422 table_name:
3423 SQL_TOKEN_NAME
3424 {$$ = SQL_NEW_RULE;
3425 $$->append($1);}
3427 /* Columns */
3428 column_ref:
3429 column
3430 {$$ = SQL_NEW_RULE;
3431 $$->append($1);}
3432 /* | table_node '.' column_val %prec '.'
3433 {$$ = SQL_NEW_RULE;
3434 $$->append($1);
3435 $$->append(newNode(".", SQLNodeType::Punctuation));
3436 $$->append($3);}
3438 | SQL_TOKEN_NAME '.' column_val %prec '.'
3439 {$$ = SQL_NEW_RULE;
3440 $$->append($1);
3441 $$->append(newNode(".", SQLNodeType::Punctuation));
3442 $$->append($3);
3444 | SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val %prec '.'
3445 {$$ = SQL_NEW_RULE;
3446 $$->append($1);
3447 $$->append(newNode(".", SQLNodeType::Punctuation));
3448 $$->append($3);
3449 $$->append(newNode(".", SQLNodeType::Punctuation));
3450 $$->append($5);}
3451 | SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val %prec '.'
3452 {$$ = SQL_NEW_RULE;
3453 $$->append($1);
3454 $$->append(newNode(".", SQLNodeType::Punctuation));
3455 $$->append($3);
3456 $$->append(newNode(".", SQLNodeType::Punctuation));
3457 $$->append($5);
3458 $$->append(newNode(".", SQLNodeType::Punctuation));
3459 $$->append($7);
3461 | SQL_TOKEN_NAME ':' SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val %prec '.'
3462 {$$ = SQL_NEW_RULE;
3463 $$->append($1);
3464 $$->append(newNode(":", SQLNodeType::Punctuation));
3465 $$->append($3);
3466 $$->append(newNode(".", SQLNodeType::Punctuation));
3467 $$->append($5);
3468 $$->append(newNode(".", SQLNodeType::Punctuation));
3469 $$->append($7);
3471 /* | SQL_TOKEN_NAME ';' SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val
3472 {$$ = SQL_NEW_RULE;
3473 $$->append($1);
3474 $$->append(newNode(";", SQLNodeType::Punctuation));
3475 $$->append($3);
3476 $$->append(newNode(".", SQLNodeType::Punctuation));
3477 $$->append($5);
3478 $$->append(newNode(".", SQLNodeType::Punctuation));
3479 $$->append($7);
3481 */ ;
3483 /* data types */
3484 column_val:
3485 column
3486 {$$ = SQL_NEW_RULE;
3487 $$->append($1);}
3488 | '*'
3490 $$ = SQL_NEW_RULE;
3491 $$->append(newNode("*", SQLNodeType::Punctuation));
3494 data_type:
3495 predefined_type
3497 opt_char_set_spec:
3498 {$$ = SQL_NEW_RULE;}
3499 | SQL_TOKEN_CHARACTER SQL_TOKEN_SET SQL_TOKEN_NAME
3501 $$ = SQL_NEW_RULE;
3502 $$->append($1);
3503 $$->append($2);
3504 $$->append($3);
3507 opt_collate_clause:
3508 {$$ = SQL_NEW_RULE;}
3509 | collate_clause
3511 predefined_type:
3512 character_string_type opt_char_set_spec opt_collate_clause
3514 $$ = SQL_NEW_RULE;
3515 $$->append($1);
3516 $$->append($2);
3517 $$->append($3);
3519 | national_character_string_type opt_collate_clause
3521 $$ = SQL_NEW_RULE;
3522 $$->append($1);
3523 $$->append($2);
3525 | binary_string_type
3526 | numeric_type
3527 | boolean_type
3528 | datetime_type
3529 | interval_type
3531 character_string_type:
3532 SQL_TOKEN_CHARACTER opt_paren_precision
3534 $$ = SQL_NEW_RULE;
3535 $$->append($1);
3536 $$->append($2);
3538 | SQL_TOKEN_CHAR opt_paren_precision
3540 $$ = SQL_NEW_RULE;
3541 $$->append($1);
3542 $$->append($2);
3544 | SQL_TOKEN_CHARACTER SQL_TOKEN_VARYING paren_char_length
3546 $$ = SQL_NEW_RULE;
3547 $$->append($1);
3548 $$->append($2);
3549 $$->append($3);
3551 | SQL_TOKEN_CHAR SQL_TOKEN_VARYING paren_char_length
3553 $$ = SQL_NEW_RULE;
3554 $$->append($1);
3555 $$->append($2);
3556 $$->append($3);
3558 | SQL_TOKEN_VARCHAR paren_char_length
3560 $$ = SQL_NEW_RULE;
3561 $$->append($1);
3562 $$->append($2);
3564 | character_large_object_type
3566 opt_paren_precision:
3567 {$$ = SQL_NEW_RULE;}
3568 | paren_char_length
3570 paren_char_length:
3571 '(' SQL_TOKEN_INTNUM ')'
3573 $$ = SQL_NEW_RULE;
3574 $$->append(newNode("(", SQLNodeType::Punctuation));
3575 $$->append($2);
3576 $$->append(newNode(")", SQLNodeType::Punctuation));
3579 opt_paren_char_large_length:
3580 {$$ = SQL_NEW_RULE;}
3581 | paren_character_large_object_length
3583 paren_character_large_object_length:
3584 '(' large_object_length ')'
3586 $$ = SQL_NEW_RULE;
3587 $$->append(newNode("(", SQLNodeType::Punctuation));
3588 $$->append($2);
3589 $$->append(newNode(")", SQLNodeType::Punctuation));
3593 large_object_length:
3594 SQL_TOKEN_INTNUM opt_multiplier
3596 $$ = SQL_NEW_RULE;
3597 $$->append($1);
3598 $$->append($2);
3601 opt_multiplier:
3602 {$$ = SQL_NEW_RULE;}
3603 | 'K'
3605 $$ = SQL_NEW_RULE;
3606 $$->append(newNode("K", SQLNodeType::Punctuation));
3608 | 'M'
3610 $$ = SQL_NEW_RULE;
3611 $$->append(newNode("M", SQLNodeType::Punctuation));
3613 | 'G'
3615 $$ = SQL_NEW_RULE;
3616 $$->append(newNode("G", SQLNodeType::Punctuation));
3618 | 'T'
3620 $$ = SQL_NEW_RULE;
3621 $$->append(newNode("T", SQLNodeType::Punctuation));
3623 | 'P'
3625 $$ = SQL_NEW_RULE;
3626 $$->append(newNode("P", SQLNodeType::Punctuation));
3629 character_large_object_type:
3630 SQL_TOKEN_CHARACTER SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3632 $$ = SQL_NEW_RULE;
3633 $$->append($1);
3634 $$->append($2);
3635 $$->append($3);
3636 $$->append($4);
3638 | SQL_TOKEN_CHAR SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3640 $$ = SQL_NEW_RULE;
3641 $$->append($1);
3642 $$->append($2);
3643 $$->append($3);
3644 $$->append($4);
3646 | SQL_TOKEN_CLOB opt_paren_char_large_length
3648 $$ = SQL_NEW_RULE;
3649 $$->append($1);
3650 $$->append($2);
3653 national_character_string_type:
3654 SQL_TOKEN_NATIONAL SQL_TOKEN_CHARACTER opt_paren_precision
3656 $$ = SQL_NEW_RULE;
3657 $$->append($1);
3658 $$->append($2);
3659 $$->append($3);
3661 | SQL_TOKEN_NATIONAL SQL_TOKEN_CHAR opt_paren_precision
3663 $$ = SQL_NEW_RULE;
3664 $$->append($1);
3665 $$->append($2);
3666 $$->append($3);
3668 | SQL_TOKEN_NCHAR opt_paren_precision
3670 $$ = SQL_NEW_RULE;
3671 $$->append($1);
3672 $$->append($2);
3674 | SQL_TOKEN_NATIONAL SQL_TOKEN_CHARACTER SQL_TOKEN_VARYING paren_char_length
3676 $$ = SQL_NEW_RULE;
3677 $$->append($1);
3678 $$->append($2);
3679 $$->append($3);
3680 $$->append($4);
3682 | SQL_TOKEN_NATIONAL SQL_TOKEN_CHAR SQL_TOKEN_VARYING paren_char_length
3684 $$ = SQL_NEW_RULE;
3685 $$->append($1);
3686 $$->append($2);
3687 $$->append($3);
3688 $$->append($4);
3690 | SQL_TOKEN_NCHAR SQL_TOKEN_VARYING paren_char_length
3692 $$ = SQL_NEW_RULE;
3693 $$->append($1);
3694 $$->append($2);
3695 $$->append($3);
3697 | national_character_large_object_type
3699 national_character_large_object_type:
3700 SQL_TOKEN_NATIONAL SQL_TOKEN_CHARACTER SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3702 $$ = SQL_NEW_RULE;
3703 $$->append($1);
3704 $$->append($2);
3705 $$->append($3);
3706 $$->append($4);
3707 $$->append($5);
3709 | SQL_TOKEN_NCHAR SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3711 $$ = SQL_NEW_RULE;
3712 $$->append($1);
3713 $$->append($2);
3714 $$->append($3);
3715 $$->append($4);
3717 | SQL_TOKEN_NCLOB opt_paren_char_large_length
3719 $$ = SQL_NEW_RULE;
3720 $$->append($1);
3721 $$->append($2);
3724 binary_string_type:
3725 SQL_TOKEN_BINARY opt_paren_precision
3727 $$ = SQL_NEW_RULE;
3728 $$->append($1);
3729 $$->append($2);
3731 | SQL_TOKEN_BINARY SQL_TOKEN_VARYING paren_char_length
3733 $$ = SQL_NEW_RULE;
3734 $$->append($1);
3735 $$->append($2);
3736 $$->append($3);
3738 | SQL_TOKEN_VARBINARY paren_char_length
3740 $$ = SQL_NEW_RULE;
3741 $$->append($1);
3742 $$->append($2);
3744 | binary_large_object_string_type
3746 binary_large_object_string_type:
3747 SQL_TOKEN_BINARY SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3749 $$ = SQL_NEW_RULE;
3750 $$->append($1);
3751 $$->append($2);
3752 $$->append($3);
3753 $$->append($4);
3755 | SQL_TOKEN_BLOB opt_paren_char_large_length
3757 $$ = SQL_NEW_RULE;
3758 $$->append($1);
3759 $$->append($2);
3762 numeric_type:
3763 exact_numeric_type
3764 | approximate_numeric_type
3766 opt_paren_precision_scale:
3767 {$$ = SQL_NEW_RULE;}
3768 | '(' SQL_TOKEN_INTNUM ')'
3770 $$ = SQL_NEW_RULE;
3771 $$->append(newNode("(", SQLNodeType::Punctuation));
3772 $$->append($2);
3773 $$->append(newNode(")", SQLNodeType::Punctuation));
3775 | '(' SQL_TOKEN_INTNUM ',' SQL_TOKEN_INTNUM ')'
3777 $$ = SQL_NEW_RULE;
3778 $$->append(newNode("(", SQLNodeType::Punctuation));
3779 $$->append($2);
3780 $$->append(newNode(",", SQLNodeType::Punctuation));
3781 $$->append($4);
3782 $$->append(newNode(")", SQLNodeType::Punctuation));
3785 exact_numeric_type:
3786 SQL_TOKEN_NUMERIC opt_paren_precision_scale
3788 $$ = SQL_NEW_RULE;
3789 $$->append($1);
3790 $$->append($2);
3792 | SQL_TOKEN_DECIMAL opt_paren_precision_scale
3794 $$ = SQL_NEW_RULE;
3795 $$->append($1);
3796 $$->append($2);
3798 | SQL_TOKEN_DEC opt_paren_precision_scale
3800 $$ = SQL_NEW_RULE;
3801 $$->append($1);
3802 $$->append($2);
3804 | SQL_TOKEN_SMALLINT
3805 | SQL_TOKEN_INTEGER
3806 | SQL_TOKEN_INT
3807 | SQL_TOKEN_BIGINT
3809 approximate_numeric_type:
3810 SQL_TOKEN_FLOAT '(' SQL_TOKEN_INTNUM ')'
3812 $$ = SQL_NEW_RULE;
3813 $$->append($1);
3814 $$->append(newNode("(", SQLNodeType::Punctuation));
3815 $$->append($3);
3816 $$->append(newNode(")", SQLNodeType::Punctuation));
3818 | SQL_TOKEN_FLOAT
3819 | SQL_TOKEN_REAL
3820 | SQL_TOKEN_DOUBLE
3821 | SQL_TOKEN_DOUBLE SQL_TOKEN_PRECISION
3823 $$ = SQL_NEW_RULE;
3824 $$->append($1);
3825 $$->append($2);
3828 boolean_type:
3829 SQL_TOKEN_BOOLEAN
3831 datetime_type:
3832 SQL_TOKEN_DATE
3833 | SQL_TOKEN_TIME opt_paren_precision opt_with_or_without_time_zone
3835 $$ = SQL_NEW_RULE;
3836 $$->append($1);
3837 $$->append($2);
3838 $$->append($3);
3840 | SQL_TOKEN_TIMESTAMP opt_paren_precision opt_with_or_without_time_zone
3842 $$ = SQL_NEW_RULE;
3843 $$->append($1);
3844 $$->append($2);
3845 $$->append($3);
3848 opt_with_or_without_time_zone:
3849 {$$ = SQL_NEW_RULE;}
3850 | SQL_TOKEN_WITH SQL_TOKEN_TIME SQL_TOKEN_ZONE
3852 $$ = SQL_NEW_RULE;
3853 $$->append($1);
3854 $$->append($2);
3855 $$->append($3);
3857 | SQL_TOKEN_WITHOUT SQL_TOKEN_TIME SQL_TOKEN_ZONE
3859 $$ = SQL_NEW_RULE;
3860 $$->append($1);
3861 $$->append($2);
3862 $$->append($3);
3865 interval_type:
3866 SQL_TOKEN_INTERVAL interval_qualifier
3868 $$ = SQL_NEW_RULE;
3869 $$->append($1);
3870 $$->append($2);
3873 /* the various things you can name */
3875 column:
3876 SQL_TOKEN_NAME
3877 | SQL_TOKEN_POSITION
3879 sal_uInt32 nNod = $$->getRuleID();
3880 delete $$;
3881 $$ = newNode(OSQLParser::TokenIDToStr(nNod), SQLNodeType::Name);
3883 | SQL_TOKEN_CHAR_LENGTH
3885 sal_uInt32 nNod = $$->getRuleID();
3886 delete $$;
3887 $$ = newNode(OSQLParser::TokenIDToStr(nNod), SQLNodeType::Name);
3889 | SQL_TOKEN_EXTRACT
3891 sal_uInt32 nNod = $$->getRuleID();
3892 delete $$;
3893 $$ = newNode(OSQLParser::TokenIDToStr(nNod), SQLNodeType::Name);
3896 case_expression:
3897 case_abbreviation
3898 | case_specification
3900 case_abbreviation:
3901 SQL_TOKEN_NULLIF '(' value_exp_commalist ')'
3903 $$ = SQL_NEW_RULE;
3904 $$->append($1);
3905 $$->append(newNode("(", SQLNodeType::Punctuation));
3906 $$->append($3);
3907 $$->append(newNode(")", SQLNodeType::Punctuation));
3909 | SQL_TOKEN_COALESCE '(' value_exp ')'
3911 $$ = SQL_NEW_RULE;
3912 $$->append($1);
3913 $$->append(newNode("(", SQLNodeType::Punctuation));
3914 $$->append($3);
3915 $$->append(newNode(")", SQLNodeType::Punctuation));
3917 | SQL_TOKEN_COALESCE '(' value_exp_commalist ')'
3919 $$ = SQL_NEW_RULE;
3920 $$->append($1);
3921 $$->append(newNode("(", SQLNodeType::Punctuation));
3922 $$->append($3);
3923 $$->append(newNode(")", SQLNodeType::Punctuation));
3926 case_specification:
3927 simple_case
3928 | searched_case
3930 simple_case:
3931 SQL_TOKEN_CASE case_operand simple_when_clause_list else_clause SQL_TOKEN_END
3933 $$ = SQL_NEW_RULE;
3934 $$->append($1);
3935 $$->append($2);
3936 $$->append($3);
3937 $$->append($4);
3938 $$->append($5);
3941 searched_case:
3942 SQL_TOKEN_CASE searched_when_clause_list else_clause SQL_TOKEN_END
3944 $$ = SQL_NEW_RULE;
3945 $$->append($1);
3946 $$->append($2);
3947 $$->append($3);
3948 $$->append($4);
3951 simple_when_clause_list:
3952 simple_when_clause
3954 $$ = SQL_NEW_LISTRULE;
3955 $$->append($1);
3957 | searched_when_clause_list simple_when_clause
3959 $1->append($2);
3960 $$ = $1;
3963 simple_when_clause:
3964 SQL_TOKEN_WHEN when_operand_list SQL_TOKEN_THEN result
3966 $$ = SQL_NEW_RULE;
3967 $$->append($1);
3968 $$->append($2);
3969 $$->append($3);
3970 $$->append($4);
3973 when_operand_list:
3974 when_operand
3975 {$$ = SQL_NEW_COMMALISTRULE;
3976 $$->append($1);}
3977 | when_operand_list ',' when_operand
3978 {$1->append($3);
3979 $$ = $1;}
3981 when_operand:
3982 row_value_constructor_elem
3983 | comparison_predicate_part_2 %dprec 1
3984 | between_predicate_part_2
3985 | in_predicate_part_2
3986 | character_like_predicate_part_2
3987 | null_predicate_part_2 %dprec 2
3989 searched_when_clause_list:
3990 searched_when_clause
3992 $$ = SQL_NEW_LISTRULE;
3993 $$->append($1);
3995 | searched_when_clause_list searched_when_clause
3997 $1->append($2);
3998 $$ = $1;
4001 searched_when_clause:
4002 SQL_TOKEN_WHEN search_condition SQL_TOKEN_THEN result
4004 $$ = SQL_NEW_RULE;
4005 $$->append($1);
4006 $$->append($2);
4007 $$->append($3);
4008 $$->append($4);
4011 else_clause:
4012 {$$ = SQL_NEW_RULE;}
4013 | SQL_TOKEN_ELSE result
4015 $$ = SQL_NEW_RULE;
4016 $$->append($1);
4017 $$->append($2);
4020 result:
4021 result_expression
4023 result_expression:
4024 value_exp
4026 case_operand:
4027 row_value_constructor_elem
4030 cursor: SQL_TOKEN_NAME
4031 {$$ = SQL_NEW_RULE;
4032 $$->append($1);}
4035 /***
4036 module: SQL_TOKEN_NAME
4037 {$$ = SQL_NEW_RULE;
4038 $$->append($1);}
4040 ***/
4042 parameter:
4043 ':' SQL_TOKEN_NAME
4044 {$$ = SQL_NEW_RULE;
4045 $$->append(newNode(":", SQLNodeType::Punctuation));
4046 $$->append($2);}
4047 | '?'
4048 {$$ = SQL_NEW_RULE; // test
4049 $$->append(newNode("?", SQLNodeType::Punctuation));}
4050 | '[' SQL_TOKEN_NAME ']'
4051 {$$ = SQL_NEW_RULE;
4052 $$->append(newNode("[", SQLNodeType::Punctuation));
4053 $$->append($2);
4054 $$->append(newNode("]", SQLNodeType::Punctuation));}
4057 /***
4058 procedure: SQL_TOKEN_NAME
4059 {$$ = SQL_NEW_RULE;
4060 $$->append($1);}
4062 ***/
4064 range_variable:
4065 {$$ = SQL_NEW_RULE;}
4066 | opt_as SQL_TOKEN_NAME
4067 {$$ = SQL_NEW_RULE;
4068 $$->append($1);
4069 $$->append($2);
4073 user: SQL_TOKEN_NAME
4076 /* PREDICATECHECK RULES */
4077 sql:
4078 search_condition /* checking predicats */
4080 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // sql: rule 1
4082 $$ = $1;
4083 if ( SQL_ISRULE($$,search_condition) )
4085 $$->insert(0,newNode("(", SQLNodeType::Punctuation));
4086 $$->append(newNode(")", SQLNodeType::Punctuation));
4089 else
4090 YYERROR;
4092 | '(' sql ')' /* checking predicats */
4094 trigger_definition:
4095 SQL_TOKEN_CREATE SQL_TOKEN_TRIGGER trigger_name trigger_action_time trigger_event SQL_TOKEN_ON table_name op_referencing triggered_action
4097 $$ = SQL_NEW_RULE;
4098 $$->append($1);
4099 $$->append($2);
4100 $$->append($3);
4101 $$->append($4);
4102 $$->append($5);
4103 $$->append($6);
4104 $$->append($7);
4105 $$->append($8);
4106 $$->append($9);
4109 op_referencing:
4111 $$ = SQL_NEW_RULE;
4113 | SQL_TOKEN_REFERENCING transition_table_or_variable_list
4115 $$ = SQL_NEW_RULE;
4116 $$->append($1);
4117 $$->append($2);
4120 trigger_action_time:
4121 SQL_TOKEN_BEFORE
4122 | SQL_TOKEN_AFTER
4123 | SQL_TOKEN_INSTEAD SQL_TOKEN_OF
4125 $$ = SQL_NEW_RULE;
4126 $$->append($1);
4127 $$->append($2);
4130 trigger_event:
4131 SQL_TOKEN_INSERT
4132 | SQL_TOKEN_DELETE
4133 | SQL_TOKEN_UPDATE op_trigger_columnlist
4135 $$ = SQL_NEW_RULE;
4136 $$->append($1);
4137 $$->append($2);
4140 op_trigger_columnlist:
4142 $$ = SQL_NEW_RULE;
4144 | SQL_TOKEN_OF trigger_column_list
4146 $$ = SQL_NEW_RULE;
4147 $$->append($1);
4148 $$->append($2);
4151 trigger_column_list:
4152 column_commalist
4154 triggered_action:
4155 op_triggered_action_for triggered_when_clause triggered_SQL_statement
4157 $$ = SQL_NEW_RULE;
4158 $$->append($1);
4159 $$->append($2);
4160 $$->append($3);
4163 op_triggered_action_for:
4165 $$ = SQL_NEW_RULE;
4167 | SQL_TOKEN_FOR SQL_TOKEN_EACH trigger_for
4169 $$ = SQL_NEW_RULE;
4170 $$->append($1);
4171 $$->append($2);
4172 $$->append($3);
4175 trigger_for:
4176 SQL_TOKEN_ROW
4177 | SQL_TOKEN_STATEMENT
4179 triggered_when_clause:
4181 $$ = SQL_NEW_RULE;
4183 | SQL_TOKEN_WHEN parenthesized_boolean_value_expression
4185 $$ = SQL_NEW_RULE;
4186 $$->append($1);
4187 $$->append($2);
4190 triggered_SQL_statement:
4191 SQL_procedure_statement
4192 | SQL_TOKEN_BEGIN SQL_TOKEN_ATOMIC SQL_procedure_statement_list ';' SQL_TOKEN_END
4194 $$ = SQL_NEW_RULE;
4195 $$->append($1);
4196 $$->append($2);
4197 $$->append($3);
4198 $$->append(newNode(";", SQLNodeType::Punctuation));
4199 $$->append($5);
4202 SQL_procedure_statement_list:
4203 SQL_procedure_statement
4205 $$ = SQL_NEW_LISTRULE;
4206 $$->append($1);
4208 | SQL_procedure_statement_list ';' SQL_procedure_statement
4210 $1->append($3);
4211 $$ = $1;
4214 SQL_procedure_statement:
4218 transition_table_or_variable_list:
4219 transition_table_or_variable
4221 $$ = SQL_NEW_LISTRULE;
4222 $$->append($1);
4224 | transition_table_or_variable_list transition_table_or_variable
4226 $1->append($2);
4227 $$ = $1;
4231 transition_table_or_variable:
4232 SQL_TOKEN_OLD opt_row opt_as old_transition_variable_name
4234 $$ = SQL_NEW_RULE;
4235 $$->append($1);
4236 $$->append($2);
4237 $$->append($3);
4238 $$->append($4);
4240 | SQL_TOKEN_NEW opt_row opt_as new_transition_variable_name
4242 $$ = SQL_NEW_RULE;
4243 $$->append($1);
4244 $$->append($2);
4245 $$->append($3);
4246 $$->append($4);
4248 | SQL_TOKEN_OLD SQL_TOKEN_TABLE opt_as old_transition_table_name
4250 $$ = SQL_NEW_RULE;
4251 $$->append($1);
4252 $$->append($2);
4253 $$->append($3);
4254 $$->append($4);
4256 | SQL_TOKEN_NEW SQL_TOKEN_TABLE opt_as new_transition_table_name
4258 $$ = SQL_NEW_RULE;
4259 $$->append($1);
4260 $$->append($2);
4261 $$->append($3);
4262 $$->append($4);
4265 old_transition_table_name:
4266 transition_table_name
4268 new_transition_table_name:
4269 transition_table_name
4271 transition_table_name:
4272 SQL_TOKEN_NAME
4274 old_transition_variable_name:
4275 SQL_TOKEN_NAME
4277 new_transition_variable_name:
4278 SQL_TOKEN_NAME
4280 trigger_name:
4281 SQL_TOKEN_NAME
4285 #if defined _MSC_VER
4286 #pragma warning(pop)
4287 #endif
4289 using namespace ::com::sun::star::sdbc;
4290 using namespace ::com::sun::star::beans;
4291 using namespace ::com::sun::star::uno;
4292 using namespace ::com::sun::star::i18n;
4293 using namespace ::com::sun::star::lang;
4294 using namespace ::com::sun::star::util;
4295 using namespace ::osl;
4296 using namespace ::dbtools;
4298 connectivity::OSQLParser* xxx_pGLOBAL_SQLPARSER;
4300 connectivity::OSQLInternalNode* newNode(const char* pNewValue,
4301 const connectivity::SQLNodeType eNodeType,
4302 const sal_uInt32 nNodeID)
4304 return new connectivity::OSQLInternalNode(pNewValue, eNodeType, nNodeID);
4307 connectivity::OSQLInternalNode* newNode(const OString& _newValue,
4308 const connectivity::SQLNodeType eNodeType,
4309 const sal_uInt32 nNodeID)
4311 return new connectivity::OSQLInternalNode(_newValue, eNodeType, nNodeID);
4314 connectivity::OSQLInternalNode* newNode(const OUString& _newValue,
4315 const connectivity::SQLNodeType eNodeType,
4316 const sal_uInt32 nNodeID)
4318 return new connectivity::OSQLInternalNode(_newValue, eNodeType, nNodeID);
4321 OParseContext::OParseContext()
4326 OParseContext::~OParseContext()
4331 OUString OParseContext::getErrorMessage(ErrorCode _eCode) const
4333 OUString aMsg;
4334 switch (_eCode)
4336 case ErrorCode::General: aMsg = "Syntax error in SQL expression"; break;
4337 case ErrorCode::ValueNoLike: aMsg = "The value #1 can not be used with LIKE."; break;
4338 case ErrorCode::FieldNoLike: aMsg = "LIKE can not be used with this field."; break;
4339 case ErrorCode::InvalidCompare: aMsg = "The entered criterion can not be compared with this field."; break;
4340 case ErrorCode::InvalidIntCompare: aMsg = "The field can not be compared with a number."; break;
4341 case ErrorCode::InvalidDateCompare: aMsg = "The field can not be compared with a date."; break;
4342 case ErrorCode::InvalidRealCompare: aMsg = "The field can not be compared with a floating point number."; break;
4343 case ErrorCode::InvalidTableNosuch: aMsg = "The database does not contain a table named \"#\"."; break;
4344 case ErrorCode::InvalidTableOrQuery: aMsg = "The database does contain neither a table nor a query named \"#\"."; break;
4345 case ErrorCode::InvalidColumn: aMsg = "The column \"#1\" is unknown in the table \"#2\"."; break;
4346 case ErrorCode::InvalidTableExist: aMsg = "The database already contains a table or view with name \"#\"."; break;
4347 case ErrorCode::InvalidQueryExist: aMsg = "The database already contains a query with name \"#\"."; break;
4348 default:
4349 OSL_FAIL( "OParseContext::getErrorMessage: unknown error code!" );
4350 break;
4352 return aMsg;
4356 OString OParseContext::getIntlKeywordAscii(InternationalKeyCode _eKey) const
4358 OString aKeyword;
4359 switch (_eKey)
4361 case InternationalKeyCode::Like: aKeyword = "LIKE"; break;
4362 case InternationalKeyCode::Not: aKeyword = "NOT"; break;
4363 case InternationalKeyCode::Null: aKeyword = "NULL"; break;
4364 case InternationalKeyCode::True: aKeyword = "True"; break;
4365 case InternationalKeyCode::False: aKeyword = "False"; break;
4366 case InternationalKeyCode::Is: aKeyword = "IS"; break;
4367 case InternationalKeyCode::Between: aKeyword = "BETWEEN"; break;
4368 case InternationalKeyCode::Or: aKeyword = "OR"; break;
4369 case InternationalKeyCode::And: aKeyword = "AND"; break;
4370 case InternationalKeyCode::Avg: aKeyword = "AVG"; break;
4371 case InternationalKeyCode::Count: aKeyword = "COUNT"; break;
4372 case InternationalKeyCode::Max: aKeyword = "MAX"; break;
4373 case InternationalKeyCode::Min: aKeyword = "MIN"; break;
4374 case InternationalKeyCode::Sum: aKeyword = "SUM"; break;
4375 case InternationalKeyCode::Every: aKeyword = "EVERY"; break;
4376 case InternationalKeyCode::Any: aKeyword = "ANY"; break;
4377 case InternationalKeyCode::Some: aKeyword = "SOME"; break;
4378 case InternationalKeyCode::StdDevPop: aKeyword = "STDDEV_POP"; break;
4379 case InternationalKeyCode::StdDevSamp: aKeyword = "STDDEV_SAMP"; break;
4380 case InternationalKeyCode::VarSamp: aKeyword = "VAR_SAMP"; break;
4381 case InternationalKeyCode::VarPop: aKeyword = "VAR_POP"; break;
4382 case InternationalKeyCode::Collect: aKeyword = "COLLECT"; break;
4383 case InternationalKeyCode::Fusion: aKeyword = "FUSION"; break;
4384 case InternationalKeyCode::Intersection:aKeyword = "INTERSECTION"; break;
4385 case InternationalKeyCode::None: break;
4386 default:
4387 OSL_FAIL( "OParseContext::getIntlKeywordAscii: unknown key!" );
4388 break;
4390 return aKeyword;
4394 IParseContext::InternationalKeyCode OParseContext::getIntlKeyCode(const OString& rToken) const
4396 static IParseContext::InternationalKeyCode const Intl_TokenID[] =
4398 InternationalKeyCode::Like, InternationalKeyCode::Not, InternationalKeyCode::Null, InternationalKeyCode::True,
4399 InternationalKeyCode::False, InternationalKeyCode::Is, InternationalKeyCode::Between, InternationalKeyCode::Or,
4400 InternationalKeyCode::And, InternationalKeyCode::Avg, InternationalKeyCode::Count, InternationalKeyCode::Max,
4401 InternationalKeyCode::Min, InternationalKeyCode::Sum, InternationalKeyCode::Every,InternationalKeyCode::Any,InternationalKeyCode::Some,
4402 InternationalKeyCode::StdDevPop,InternationalKeyCode::StdDevSamp,InternationalKeyCode::VarSamp,
4403 InternationalKeyCode::VarPop,InternationalKeyCode::Collect,InternationalKeyCode::Fusion,InternationalKeyCode::Intersection
4406 auto const token = std::find_if(std::cbegin(Intl_TokenID), std::cend(Intl_TokenID)
4407 , [&rToken, this](IParseContext::InternationalKeyCode const & tokenID)
4408 { return rToken.equalsIgnoreAsciiCase(getIntlKeywordAscii(tokenID)); });
4410 if (std::cend(Intl_TokenID) != token)
4411 return *token;
4413 return InternationalKeyCode::None;
4417 static Locale& impl_getLocaleInstance( )
4419 static Locale s_aLocale( "en", "US", "" );
4420 return s_aLocale;
4424 Locale OParseContext::getPreferredLocale( ) const
4426 return getDefaultLocale();
4430 const Locale& OParseContext::getDefaultLocale()
4432 return impl_getLocaleInstance();
4435 // The (unfortunately global) yylval for the handing over of
4436 // values from the Scanner to the Parser. The global variable
4437 // is only used for a short term, the Parser reads the variable
4438 // immediately after the call of the Scanner into a same named own
4439 // member variable.
4442 OUString ConvertLikeToken(const OSQLParseNode* pTokenNode, const OSQLParseNode* pEscapeNode, bool bInternational)
4444 OUStringBuffer aMatchStr(0);
4445 if (pTokenNode->isToken())
4447 sal_Unicode cEscape = 0;
4448 if (pEscapeNode->count())
4449 cEscape = pEscapeNode->getChild(1)->getTokenValue().toChar();
4451 // Change place holder
4452 aMatchStr = pTokenNode->getTokenValue();
4453 const sal_Int32 nLen = aMatchStr.getLength();
4454 OUStringBuffer sSearch,sReplace;
4455 if ( bInternational )
4457 sSearch.append("%_");
4458 sReplace.append("*?");
4460 else
4462 sSearch.append("*?");
4463 sReplace.append("%_");
4466 bool wasEscape = false;
4467 for (sal_Int32 i = 0; i < nLen; i++)
4469 const sal_Unicode c = aMatchStr[i];
4470 // SQL standard requires the escape to be followed
4471 // by a meta-character ('%', '_' or itself), else error
4472 // We are more lenient here and let it escape anything.
4473 // Especially since some databases (e.g. Microsoft SQL Server)
4474 // have more meta-characters than the standard, such as e.g. '[' and ']'
4475 if (wasEscape)
4477 wasEscape=false;
4478 continue;
4480 if (c == cEscape)
4482 wasEscape=true;
4483 continue;
4485 int match = -1;
4486 if (c == sSearch[0])
4487 match=0;
4488 else if (c == sSearch[1])
4489 match=1;
4491 if (match != -1)
4493 aMatchStr[i] = sReplace[match];
4497 return aMatchStr.makeStringAndClear();
4500 sal_uInt32 OSQLParser::s_nRuleIDs[OSQLParseNode::rule_count + 1];
4501 OSQLParser::RuleIDMap OSQLParser::s_aReverseRuleIDLookup;
4502 OParseContext OSQLParser::s_aDefaultContext;
4504 sal_Int32 OSQLParser::s_nRefCount = 0;
4505 // ::osl::Mutex OSQLParser::s_aMutex;
4506 OSQLScanner* OSQLParser::s_pScanner = nullptr;
4507 OSQLParseNodesGarbageCollector* OSQLParser::s_pGarbageCollector = nullptr;
4509 void setParser(OSQLParser* _pParser)
4511 xxx_pGLOBAL_SQLPARSER = _pParser;
4514 void OSQLParser::setParseTree(OSQLParseNode* pNewParseTree)
4516 m_pParseTree.reset(pNewParseTree);
4520 /** Delete all comments in a query.
4522 See also getComment()/concatComment() implementation for
4523 OQueryController::translateStatement().
4525 static OUString delComment( const OUString& rQuery )
4527 // First a quick search if there is any "--" or "//" or "/*", if not then the whole
4528 // copying loop is pointless.
4529 if (rQuery.indexOf("--") < 0 && rQuery.indexOf("//") < 0 &&
4530 rQuery.indexOf("/*") < 0)
4531 return rQuery;
4533 const sal_Unicode* pCopy = rQuery.getStr();
4534 sal_Int32 nQueryLen = rQuery.getLength();
4535 bool bIsText1 = false; // "text"
4536 bool bIsText2 = false; // 'text'
4537 bool bComment2 = false; // /* comment */
4538 bool bComment = false; // -- or // comment
4539 OUStringBuffer aBuf(nQueryLen);
4540 for (sal_Int32 i=0; i < nQueryLen; ++i)
4542 if (bComment2)
4544 if ((i+1) < nQueryLen)
4546 if (pCopy[i]=='*' && pCopy[i+1]=='/')
4548 bComment2 = false;
4549 ++i;
4552 else
4554 // comment can't close anymore, actually an error, but...
4556 continue;
4558 if (pCopy[i] == '\n')
4559 bComment = false;
4560 else if (!bComment)
4562 if (pCopy[i] == '\"' && !bIsText2)
4563 bIsText1 = !bIsText1;
4564 else if (pCopy[i] == '\'' && !bIsText1)
4565 bIsText2 = !bIsText2;
4566 if (!bIsText1 && !bIsText2 && (i+1) < nQueryLen)
4568 if ((pCopy[i]=='-' && pCopy[i+1]=='-') || (pCopy[i]=='/' && pCopy[i+1]=='/'))
4569 bComment = true;
4570 else if ((pCopy[i]=='/' && pCopy[i+1]=='*'))
4571 bComment2 = true;
4574 if (!bComment && !bComment2)
4575 aBuf.append( &pCopy[i], 1);
4577 return aBuf.makeStringAndClear();
4580 std::unique_ptr<OSQLParseNode> OSQLParser::parseTree(OUString& rErrorMessage,
4581 const OUString& rStatement,
4582 bool bInternational)
4586 // Guard the parsing
4587 std::unique_lock aGuard(getMutex());
4588 // must be reset
4589 setParser(this);
4591 // delete comments before parsing
4592 OUString sTemp = delComment(rStatement);
4594 // defines how to scan
4595 s_pScanner->SetRule(OSQLScanner::GetSQLRule()); // initial
4596 s_pScanner->prepareScan(sTemp, m_pContext, bInternational);
4598 SQLyylval.pParseNode = nullptr;
4599 // SQLyypvt = NULL;
4600 m_pParseTree = nullptr;
4601 m_sErrorMessage = "";
4603 // start parsing
4604 if (SQLyyparse() != 0)
4606 // only set the error message, if it's not already set
4607 if (m_sErrorMessage.isEmpty())
4608 m_sErrorMessage = s_pScanner->getErrorMessage();
4609 if (m_sErrorMessage.isEmpty())
4610 m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ErrorCode::General);
4612 rErrorMessage = m_sErrorMessage;
4614 // clear the garbage collector
4615 (*s_pGarbageCollector)->clearAndDelete();
4616 // coverity[leaked_storage : FALSE] - because the garbage collector deleted it
4617 m_pParseTree.release();
4618 return nullptr;
4620 else
4622 (*s_pGarbageCollector)->clear();
4624 // return result:
4625 // to work around a bug in MKS YACC return the member m_pParseTree
4626 // instead of Sdbyyval.pParseNode
4628 SAL_WARN_IF(!m_pParseTree, "connectivity.parse",
4629 "OSQLParser: Parser did not create ParseTree");
4630 return std::move(m_pParseTree);
4634 OString OSQLParser::TokenIDToStr(sal_uInt32 nTokenID, const IParseContext* pContext)
4636 OString aStr;
4637 if (pContext)
4639 IParseContext::InternationalKeyCode eKeyCode = IParseContext::InternationalKeyCode::None;
4640 switch( nTokenID )
4642 case SQL_TOKEN_LIKE: eKeyCode = IParseContext::InternationalKeyCode::Like; break;
4643 case SQL_TOKEN_NOT: eKeyCode = IParseContext::InternationalKeyCode::Not; break;
4644 case SQL_TOKEN_NULL: eKeyCode = IParseContext::InternationalKeyCode::Null; break;
4645 case SQL_TOKEN_TRUE: eKeyCode = IParseContext::InternationalKeyCode::True; break;
4646 case SQL_TOKEN_FALSE: eKeyCode = IParseContext::InternationalKeyCode::False; break;
4647 case SQL_TOKEN_IS: eKeyCode = IParseContext::InternationalKeyCode::Is; break;
4648 case SQL_TOKEN_BETWEEN: eKeyCode = IParseContext::InternationalKeyCode::Between; break;
4649 case SQL_TOKEN_OR: eKeyCode = IParseContext::InternationalKeyCode::Or; break;
4650 case SQL_TOKEN_AND: eKeyCode = IParseContext::InternationalKeyCode::And; break;
4651 case SQL_TOKEN_AVG: eKeyCode = IParseContext::InternationalKeyCode::Avg; break;
4652 case SQL_TOKEN_COUNT: eKeyCode = IParseContext::InternationalKeyCode::Count; break;
4653 case SQL_TOKEN_MAX: eKeyCode = IParseContext::InternationalKeyCode::Max; break;
4654 case SQL_TOKEN_MIN: eKeyCode = IParseContext::InternationalKeyCode::Min; break;
4655 case SQL_TOKEN_SUM: eKeyCode = IParseContext::InternationalKeyCode::Sum; break;
4657 if ( eKeyCode != IParseContext::InternationalKeyCode::None )
4658 aStr = pContext->getIntlKeywordAscii(eKeyCode);
4661 if (aStr.isEmpty())
4663 // coverity[unsigned_compare : SUPPRESS] - YYTRANSLATE is out of our control
4664 aStr = yytname[YYTRANSLATE(nTokenID)];
4665 if(aStr.startsWith("SQL_TOKEN_"))
4666 aStr = aStr.copy(10);
4667 switch( nTokenID )
4669 case SQL_TOKEN_OJ:
4670 case SQL_TOKEN_TS:
4671 case SQL_TOKEN_T:
4672 case SQL_TOKEN_D:
4673 aStr = aStr.toAsciiLowerCase();
4676 return aStr;
4679 #if OSL_DEBUG_LEVEL > 0
4680 OUString OSQLParser::RuleIDToStr(sal_uInt32 nRuleID)
4682 OSL_ENSURE(nRuleID < std::size(yytname), "OSQLParser::RuleIDToStr: Invalid nRuleId!");
4683 return OUString::createFromAscii(yytname[nRuleID]);
4685 #endif
4688 sal_uInt32 OSQLParser::StrToRuleID(const OString & rValue)
4690 // Search for the given name in yytname and return the index
4691 // (or UNKNOWN_RULE, if not found)
4692 static sal_uInt32 const nLen = std::size(yytname)-1;
4693 for (sal_uInt32 i = YYTRANSLATE(SQL_TOKEN_INVALIDSYMBOL); i < nLen; ++i)
4695 if (rValue == yytname[i])
4696 return i;
4699 // Not found
4700 return OSQLParseNode::UNKNOWN_RULE;
4704 OSQLParseNode::Rule OSQLParser::RuleIDToRule( sal_uInt32 _nRule )
4706 OSQLParser::RuleIDMap::const_iterator i (s_aReverseRuleIDLookup.find(_nRule));
4707 if (i == s_aReverseRuleIDLookup.end())
4709 SAL_INFO("connectivity.parse",
4710 "connectivity::OSQLParser::RuleIDToRule cannot reverse-lookup rule. "
4711 "Reverse mapping incomplete? "
4712 "_nRule='" << _nRule << "' "
4713 "yytname[_nRule]='" << yytname[_nRule] << "'");
4714 return OSQLParseNode::UNKNOWN_RULE;
4716 else
4717 return i->second;
4721 sal_uInt32 OSQLParser::RuleID(OSQLParseNode::Rule eRule)
4723 return s_nRuleIDs[(sal_uInt16)eRule];
4726 sal_Int16 OSQLParser::buildNode(OSQLParseNode*& pAppend,OSQLParseNode* pCompare,OSQLParseNode* pLiteral,OSQLParseNode* pLiteral2)
4728 OSQLParseNode* pColumnRef = new OSQLInternalNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
4729 pColumnRef->append(new OSQLInternalNode(m_sFieldName,SQLNodeType::Name));
4730 OSQLParseNode* pComp = nullptr;
4731 if ( SQL_ISTOKEN( pCompare, BETWEEN) && pLiteral2 )
4732 pComp = new OSQLInternalNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::between_predicate_part_2));
4733 else
4734 pComp = new OSQLInternalNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::comparison_predicate));
4736 pComp->append(pColumnRef);
4737 pComp->append(pCompare);
4738 pComp->append(pLiteral);
4739 if ( pLiteral2 )
4741 pComp->append(new OSQLInternalNode("", SQLNodeType::Keyword,SQL_TOKEN_AND));
4742 pComp->append(pLiteral2);
4744 pAppend->append(pComp);
4745 return 1;
4748 sal_Int16 OSQLParser::buildStringNodes(OSQLParseNode*& pLiteral)
4750 if(!pLiteral)
4751 return 1;
4753 if(SQL_ISRULE(pLiteral,set_fct_spec) || SQL_ISRULE(pLiteral,general_set_fct) || SQL_ISRULE(pLiteral,column_ref)
4754 || SQL_ISRULE(pLiteral,subquery))
4755 return 1; // here I have a function that I can't transform into a string
4757 if(pLiteral->getNodeType() == SQLNodeType::IntNum || pLiteral->getNodeType() == SQLNodeType::ApproxNum || pLiteral->getNodeType() == SQLNodeType::AccessDate)
4759 OSQLParseNode* pParent = pLiteral->getParent();
4761 OSQLParseNode* pNewNode = new OSQLInternalNode(pLiteral->getTokenValue(), SQLNodeType::String);
4762 pParent->replaceAndDelete(pLiteral, pNewNode);
4763 pLiteral = nullptr;
4764 return 1;
4767 for(size_t i=0;i<pLiteral->count();++i)
4769 OSQLParseNode* pChild = pLiteral->getChild(i);
4770 buildStringNodes(pChild);
4772 if(SQL_ISRULE(pLiteral,term) || SQL_ISRULE(pLiteral,value_exp_primary))
4774 m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ErrorCode::InvalidCompare);
4775 return 0;
4777 return 1;
4780 sal_Int16 OSQLParser::buildComparisonRule(OSQLParseNode*& pAppend,OSQLParseNode* pLiteral)
4782 OSQLParseNode* pComp = new OSQLInternalNode("=", SQLNodeType::Equal);
4783 return buildPredicateRule(pAppend,pLiteral,pComp);
4788 void OSQLParser::reduceLiteral(OSQLParseNode*& pLiteral, bool bAppendBlank)
4790 OSL_ENSURE(pLiteral->isRule(), "This is no Rule");
4791 OSL_ENSURE(pLiteral->count() == 2, "OSQLParser::ReduceLiteral() Invalid count");
4792 OSQLParseNode* pTemp = pLiteral;
4793 OUStringBuffer aValue(pLiteral->getChild(0)->getTokenValue());
4794 if (bAppendBlank)
4796 aValue.append(" ");
4799 aValue.append(pLiteral->getChild(1)->getTokenValue());
4801 pLiteral = new OSQLInternalNode(aValue.makeStringAndClear(),SQLNodeType::String);
4802 delete pTemp;
4806 void OSQLParser::error(const char *fmt)
4808 if(m_sErrorMessage.isEmpty())
4810 OUString sStr(fmt,strlen(fmt),RTL_TEXTENCODING_UTF8);
4811 OUString sSQL_TOKEN("SQL_TOKEN_");
4813 sal_Int32 nPos1 = sStr.indexOf(sSQL_TOKEN);
4814 if(nPos1 != -1)
4816 OUString sFirst = sStr.copy(0,nPos1);
4817 sal_Int32 nPos2 = sStr.indexOf(sSQL_TOKEN,nPos1+1);
4818 if(nPos2 != -1)
4820 sFirst += sStr.subView(nPos1+sSQL_TOKEN.getLength(),nPos2-nPos1-sSQL_TOKEN.getLength());
4821 sFirst += sStr.subView(nPos2+sSQL_TOKEN.getLength());
4823 else
4824 sFirst += sStr.subView(nPos1+sSQL_TOKEN.getLength());
4826 m_sErrorMessage = sFirst;
4828 else
4829 m_sErrorMessage = sStr;
4831 OUString aError = s_pScanner->getErrorMessage();
4832 if(!aError.isEmpty())
4834 m_sErrorMessage += ", ";
4835 m_sErrorMessage += aError;
4840 int OSQLParser::SQLlex()
4842 return OSQLScanner::SQLlex();