bump product version to 6.3.0.0.beta1
[LibreOffice.git] / connectivity / source / parse / sqlbison.y
blob013073b882d59001258e4946546f2a4172052b8b
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/macros.h>
48 #include <sal/log.hxx>
50 #if defined _MSC_VER
51 #pragma warning(push)
52 #pragma warning(disable: 4324) // structure was padded due to alignment specifier
53 #pragma warning(disable: 4065) // switch statement contains 'default' but no 'case' labels
54 #pragma warning(disable: 4702) // unreachable code
55 #endif
57 #ifdef __GNUC__
58 # pragma GCC diagnostic ignored "-Wwrite-strings"
59 # pragma GCC diagnostic ignored "-Wunused-function"
60 #endif
62 inline connectivity::OSQLInternalNode* newNode(const sal_Char* pNewValue,
63 const connectivity::SQLNodeType eNodeType,
64 const sal_uInt32 nNodeID = 0);
66 inline connectivity::OSQLInternalNode* newNode(const OString& _newValue,
67 const connectivity::SQLNodeType eNodeType,
68 const sal_uInt32 nNodeID = 0);
70 inline connectivity::OSQLInternalNode* newNode(const OUString& _newValue,
71 const connectivity::SQLNodeType eNodeType,
72 const sal_uInt32 nNodeID = 0);
75 // yyi is the internal number of the rule that is currently being reduced
76 // This can be mapped to external rule number via the yyrmap.
77 #define SQL_NEW_RULE newNode("", SQLNodeType::Rule, yyr1[yyn])
78 #define SQL_NEW_LISTRULE newNode("", SQLNodeType::ListRule, yyr1[yyn])
79 #define SQL_NEW_COMMALISTRULE newNode("", SQLNodeType::CommaListRule, yyr1[yyn])
82 extern connectivity::OSQLParser* xxx_pGLOBAL_SQLPARSER;
84 #define YYERROR_VERBOSE
86 #define SQLyyerror(s) \
87 { \
88 xxx_pGLOBAL_SQLPARSER->error(s); \
91 using namespace connectivity;
92 #define SQLyylex xxx_pGLOBAL_SQLPARSER->SQLlex
94 /* symbolic tokens */
96 %union {
97 connectivity::OSQLParseNode * pParseNode;
99 %type <pParseNode> '(' ')' ',' ':' ';' '?' '[' ']' '{' '}' '.' 'K' 'M' 'G' 'T' 'P'
101 %token <pParseNode> SQL_TOKEN_STRING SQL_TOKEN_ACCESS_DATE SQL_TOKEN_INT SQL_TOKEN_REAL_NUM
102 %token <pParseNode> SQL_TOKEN_INTNUM SQL_TOKEN_APPROXNUM SQL_TOKEN_NOT SQL_TOKEN_NAME
105 %nonassoc <pParseNode> SQL_TOKEN_UMINUS
109 /* literal keyword tokens */
111 %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
113 %token <pParseNode> SQL_TOKEN_BETWEEN SQL_TOKEN_BIT SQL_TOKEN_BOTH SQL_TOKEN_BY
115 %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
116 %token <pParseNode> SQL_TOKEN_CURRENT SQL_TOKEN_CURSOR
118 %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
119 %token <pParseNode> SQL_TOKEN_DISTINCT SQL_TOKEN_DOUBLE SQL_TOKEN_DROP
121 %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
123 %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
125 %left <pParseNode> SQL_TOKEN_JOIN
126 %token <pParseNode> SQL_TOKEN_KEY SQL_TOKEN_LEADING SQL_TOKEN_LIKE SQL_TOKEN_LOCAL SQL_TOKEN_LOWER
127 %token <pParseNode> SQL_TOKEN_MAX SQL_TOKEN_MIN SQL_TOKEN_NATURAL SQL_TOKEN_NCHAR SQL_TOKEN_NULL SQL_TOKEN_NUMERIC
129 %token <pParseNode> SQL_TOKEN_OCTET_LENGTH SQL_TOKEN_OF SQL_TOKEN_ON SQL_TOKEN_OPTION SQL_TOKEN_ORDER SQL_TOKEN_OUTER
131 %token <pParseNode> SQL_TOKEN_PRECISION SQL_TOKEN_PRIMARY SQL_TOKEN_PRIVILEGES SQL_TOKEN_PROCEDURE SQL_TOKEN_PUBLIC
132 %token <pParseNode> SQL_TOKEN_REAL SQL_TOKEN_REFERENCES SQL_TOKEN_ROLLBACK
134 %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
136 %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
137 %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
138 %token <pParseNode> SQL_TOKEN_WHERE SQL_TOKEN_WITH SQL_TOKEN_WORK SQL_TOKEN_ZONE
140 /* ODBC KEYWORDS */
141 %token <pParseNode> SQL_TOKEN_CALL SQL_TOKEN_D SQL_TOKEN_FN SQL_TOKEN_T SQL_TOKEN_TS SQL_TOKEN_OJ
142 /* string functions */
143 %token <pParseNode> SQL_TOKEN_ASCII SQL_TOKEN_BIT_LENGTH SQL_TOKEN_CHAR SQL_TOKEN_CHAR_LENGTH SQL_TOKEN_SQL_TOKEN_INTNUM
144 %token <pParseNode> SQL_TOKEN_CONCAT
145 %token <pParseNode> SQL_TOKEN_DIFFERENCE SQL_TOKEN_INSERT SQL_TOKEN_LCASE SQL_TOKEN_LEFT SQL_TOKEN_LENGTH SQL_TOKEN_LOCATE
146 %token <pParseNode> SQL_TOKEN_LOCATE_2 SQL_TOKEN_LTRIM SQL_TOKEN_POSITION SQL_TOKEN_REPEAT SQL_TOKEN_REPLACE
147 %token <pParseNode> SQL_TOKEN_RIGHT SQL_TOKEN_RTRIM SQL_TOKEN_SOUNDEX SQL_TOKEN_SPACE SQL_TOKEN_SUBSTRING SQL_TOKEN_UCASE
149 /* time and date functions */
150 %token <pParseNode> SQL_TOKEN_CURRENT_DATE SQL_TOKEN_CURRENT_TIME SQL_TOKEN_CURRENT_TIMESTAMP SQL_TOKEN_CURDATE SQL_TOKEN_CURTIME
151 %token <pParseNode> SQL_TOKEN_DAYNAME SQL_TOKEN_DAYOFMONTH SQL_TOKEN_DAYOFWEEK SQL_TOKEN_DAYOFYEAR SQL_TOKEN_EXTRACT
152 %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
153 %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
155 /* numeric functions */
156 %token <pParseNode> SQL_TOKEN_ABS SQL_TOKEN_ACOS SQL_TOKEN_ASIN SQL_TOKEN_ATAN SQL_TOKEN_ATAN2 SQL_TOKEN_CEILING
157 %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
158 %token <pParseNode> SQL_TOKEN_LOG10 SQL_TOKEN_MOD SQL_TOKEN_PI SQL_TOKEN_POWER SQL_TOKEN_RADIANS SQL_TOKEN_RAND SQL_TOKEN_ROUNDMAGIC
159 %token <pParseNode> SQL_TOKEN_ROUND SQL_TOKEN_SIGN SQL_TOKEN_SIN SQL_TOKEN_SQRT SQL_TOKEN_TAN SQL_TOKEN_TRUNCATE
161 // computational operation
162 %token <pParseNode> SQL_TOKEN_EVERY SQL_TOKEN_INTERSECTION SQL_TOKEN_FUSION SQL_TOKEN_COLLECT SQL_TOKEN_VAR_POP SQL_TOKEN_VAR_SAMP
163 %token <pParseNode> SQL_TOKEN_STDDEV_SAMP SQL_TOKEN_STDDEV_POP
165 %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
166 %token <pParseNode> SQL_TOKEN_CASE SQL_TOKEN_THEN SQL_TOKEN_END SQL_TOKEN_NULLIF SQL_TOKEN_COALESCE SQL_TOKEN_WHEN SQL_TOKEN_ELSE
167 %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
168 %token <pParseNode> SQL_TOKEN_NEW SQL_TOKEN_OLD
169 %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
170 %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
171 %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
172 // window function
173 %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
174 %token <pParseNode> SQL_TOKEN_FIRST_VALUE SQL_TOKEN_LAST_VALUE SQL_TOKEN_NTH_VALUE SQL_TOKEN_FIRST SQL_TOKEN_LAST
175 %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
176 %token <pParseNode> SQL_TOKEN_PARTITION SQL_TOKEN_WINDOW SQL_TOKEN_NO
177 // LIMIT and OFFSEt
178 %token <pParseNode> SQL_TOKEN_LIMIT SQL_TOKEN_OFFSET SQL_TOKEN_NEXT SQL_TOKEN_ONLY
180 /* operators */
181 %left SQL_TOKEN_NAME
182 %left <pParseNode> SQL_TOKEN_OR
183 %left <pParseNode> SQL_TOKEN_AND
185 %left <pParseNode> SQL_LESSEQ SQL_GREATEQ SQL_NOTEQUAL SQL_LESS SQL_GREAT SQL_EQUAL /* '<' '>' = <> < > <= >= != */
186 %left <pParseNode> '+' '-' SQL_CONCAT
187 %left <pParseNode> '*' '/'
188 %left SQL_TOKEN_NATURAL SQL_TOKEN_CROSS SQL_TOKEN_FULL SQL_TOKEN_LEFT SQL_TOKEN_RIGHT
189 %left ')'
190 %right '='
191 %right '.'
192 %right '('
195 %token <pParseNode> SQL_TOKEN_INVALIDSYMBOL
197 /*%type <pParseNode> sql_single_statement */
199 %type <pParseNode> sql /*schema */
200 %type <pParseNode> column_def_opt_list column_def_opt table_constraint_def column_commalist
201 %type <pParseNode> view_def opt_with_check_option opt_column_commalist privilege_def
202 %type <pParseNode> opt_with_grant_option privileges operation_commalist operation
203 %type <pParseNode> grantee_commalist grantee opt_order_by_clause ordering_spec_commalist
204 %type <pParseNode> ordering_spec opt_asc_desc manipulative_statement commit_statement
205 %type <pParseNode> /*delete_statement_positioned*/ delete_statement_searched fetch_statement
206 %type <pParseNode> insert_statement values_or_query_spec
207 %type <pParseNode> rollback_statement select_statement_into opt_all_distinct
208 %type <pParseNode> /*update_statement_positioned*/ assignment_commalist assignment
209 %type <pParseNode> update_statement_searched target_commalist target opt_where_clause
210 %type <pParseNode> select_statement selection table_exp from_clause table_ref_commalist table_ref
211 %type <pParseNode> where_clause opt_group_by_clause column_ref_commalist opt_having_clause
212 %type <pParseNode> search_condition predicate comparison_predicate comparison_predicate_part_2 between_predicate between_predicate_part_2
213 %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
214 %type <pParseNode> all_or_any_predicate any_all_some existence_test subquery quantified_comparison_predicate_part_2
215 %type <pParseNode> scalar_exp_commalist parameter_ref literal parenthesized_boolean_value_expression
216 %type <pParseNode> column_ref data_type column cursor parameter range_variable user /*like_check*/
217 /* new rules at OJ */
218 %type <pParseNode> derived_column as_clause table_name num_primary term num_value_exp
219 %type <pParseNode> value_exp_primary num_value_fct unsigned_value_spec cast_spec set_fct_spec scalar_subquery
220 %type <pParseNode> position_exp extract_exp length_exp general_value_spec
221 %type <pParseNode> general_set_fct set_fct_type query_exp non_join_query_exp joined_table
222 %type <pParseNode> non_join_query_term non_join_query_primary simple_table
223 %type <pParseNode> table_value_const_list row_value_constructor /*row_value_const_list*/ row_value_constructor_elem
224 %type <pParseNode> qualified_join value_exp query_term join_type outer_join_type join_condition boolean_term
225 %type <pParseNode> boolean_factor boolean_primary named_columns_join join_spec
226 %type <pParseNode> cast_operand cast_target factor datetime_value_exp /*interval_value_exp*/ datetime_term datetime_factor
227 %type <pParseNode> datetime_primary datetime_value_fct time_zone time_zone_specifier /*interval_term*/ interval_qualifier
228 %type <pParseNode> start_field non_second_datetime_field end_field single_datetime_field extract_field datetime_field time_zone_field
229 %type <pParseNode> char_length_exp octet_length_exp bit_length_exp select_sublist string_value_exp
230 %type <pParseNode> char_value_exp concatenation char_factor char_primary string_value_fct char_substring_fct fold
231 %type <pParseNode> form_conversion char_translation trim_fct trim_operands trim_spec bit_value_fct bit_substring_fct op_column_commalist
232 %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
233 %type <pParseNode> function_arg_commalist3 string_function_3Argument function_arg_commalist4 string_function_4Argument function_arg_commalist2 string_function_1Argument string_function_2Argument
234 %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
235 %type <pParseNode> all query_primary sql_not for_length upper_lower comparison column_val cross_union /*opt_schema_element_list*/
236 %type <pParseNode> /*op_authorization op_schema*/ nil_fkt schema_element base_table_def base_table_element base_table_element_commalist
237 %type <pParseNode> column_def odbc_fct_spec odbc_call_spec odbc_fct_type op_parameter union_statement
238 %type <pParseNode> op_odbc_call_parameter odbc_parameter_commalist odbc_parameter function_args_commalist function_arg
239 %type <pParseNode> catalog_name schema_name table_node numeric_function string_function function_name date_function table_primary_as_range_column opt_as
240 %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
241 %type <pParseNode> case_expression else_clause result_expression result case_abbreviation case_specification searched_when_clause simple_when_clause searched_case simple_case
242 %type <pParseNode> when_operand_list when_operand case_operand
243 %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
244 %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
245 %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
246 %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
247 %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
248 %type <pParseNode> approximate_numeric_type exact_numeric_type opt_paren_precision_scale
249 /* window function rules */
250 %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
251 %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
252 %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
253 %type <pParseNode> new_window_name window_specification_details existing_window_name window_partition_clause window_partition_column_reference_list window_partition_column_reference window_frame_clause
254 %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
255 %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
256 %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
257 /* LIMIT and OFFSET */
258 %type <pParseNode> opt_limit_offset_clause limit_offset_clause opt_fetch_first_clause
261 /* Return Parse Tree to OSQLParser
262 * (the access over yyval after calling the parser fails,
265 sql_single_statement:
267 { xxx_pGLOBAL_SQLPARSER->setParseTree( $1 ); }
268 | sql ';'
269 { xxx_pGLOBAL_SQLPARSER->setParseTree( $1 ); }
272 /* schema definition language */
273 /* Note: other ``sql:sal_Unicode() rules appear later in the grammar */
275 sql:
276 manipulative_statement
277 | schema_element
279 $$ = SQL_NEW_RULE;
280 $$->append($1);
284 /***
286 op_authorization:
287 {$$ = SQL_NEW_RULE;}
288 | SQL_TOKEN_AUTHORIZATION user
290 $$ = SQL_NEW_RULE;
291 $$->append($1);
292 $$->append($2);
295 op_schema:
296 {$$ = SQL_NEW_RULE;}
297 | SQL_TOKEN_NAME
298 | SQL_TOKEN_NAME '.' SQL_TOKEN_NAME
300 $$ = SQL_NEW_RULE;
301 $$->append($1);
302 $$->append(newNode(".", SQLNodeType::Punctuation));
303 $$->append($3);
307 schema:
308 SQL_TOKEN_CREATE SQL_TOKEN_SCHEMA op_schema op_authorization opt_schema_element_list
310 $$ = SQL_NEW_RULE;
311 $$->append($1);
312 $$->append($2);
313 $$->append($3);
314 $$->append($4);
315 $$->append($5);
319 opt_schema_element_list:
320 {$$ = SQL_NEW_RULE;}
321 | schema_glement_list
324 schema_element_list:
325 schema_element
326 {$$ = SQL_NEW_LISTRULE;
327 $$->append($1);}
328 | schema_element_list schema_element
329 {$1->append($2);
330 $$ = $1;}
334 schema_element:
335 base_table_def
336 | view_def
337 | privilege_def
338 | trigger_definition
341 base_table_def:
342 SQL_TOKEN_CREATE SQL_TOKEN_TABLE table_node '(' base_table_element_commalist ')'
343 {$$ = SQL_NEW_RULE;
344 $$->append($1);
345 $$->append($2);
346 $$->append($3);
347 $$->append(newNode("(", SQLNodeType::Punctuation));
348 $$->append($5);
349 $$->append(newNode(")", SQLNodeType::Punctuation));}
352 base_table_element_commalist:
353 base_table_element
354 {$$ = SQL_NEW_COMMALISTRULE;
355 $$->append($1);}
356 | base_table_element_commalist ',' base_table_element
357 {$1->append($3);
358 $$ = $1;}
361 base_table_element:
362 column_def
363 | table_constraint_def
366 column_def:
367 column data_type column_def_opt_list
368 {$$ = SQL_NEW_RULE;
369 $$->append($1);
370 $$->append($2);
371 $$->append($3);
375 column_def_opt_list:
376 /* empty */ {$$ = SQL_NEW_LISTRULE;}
377 | column_def_opt_list column_def_opt
378 {$1->append($2);
379 $$ = $1;}
382 nil_fkt:
383 datetime_value_fct
385 unique_spec:
386 SQL_TOKEN_UNIQUE
387 | SQL_TOKEN_PRIMARY SQL_TOKEN_KEY
389 $$ = SQL_NEW_RULE;
390 $$->append($1);
391 $$->append($2);
394 column_def_opt:
395 SQL_TOKEN_NOT SQL_TOKEN_NULL
396 {$$ = SQL_NEW_RULE;
397 $$->append($1);
398 $$->append($2);}
399 | unique_spec
400 | SQL_TOKEN_DEFAULT literal
401 {$$ = SQL_NEW_RULE;
402 $$->append($1);
403 $$->append($2);}
404 | SQL_TOKEN_DEFAULT SQL_TOKEN_NULL
405 {$$ = SQL_NEW_RULE;
406 $$->append($1);
407 $$->append($2);}
408 | SQL_TOKEN_DEFAULT SQL_TOKEN_USER
409 {$$ = SQL_NEW_RULE;
410 $$->append($1);
411 $$->append($2);}
412 | SQL_TOKEN_DEFAULT nil_fkt
414 $$ = SQL_NEW_RULE;
415 $$->append($1);
416 $$->append($2);
418 | SQL_TOKEN_CHECK
419 | SQL_TOKEN_CHECK '(' search_condition ')'
420 {$$ = SQL_NEW_RULE;
421 $$->append($1);
422 $$->append(newNode("(", SQLNodeType::Punctuation));
423 $$->append($3);
424 $$->append(newNode(")", SQLNodeType::Punctuation));}
425 | SQL_TOKEN_REFERENCES table_node
426 {$$ = SQL_NEW_RULE;
427 $$->append($1);
428 $$->append($2);}
429 | SQL_TOKEN_REFERENCES table_node '(' column_commalist ')'
430 {$$ = SQL_NEW_RULE;
431 $$->append($1);
432 $$->append($2);
433 $$->append(newNode("(", SQLNodeType::Punctuation));
434 $$->append($4);
435 $$->append(newNode(")", SQLNodeType::Punctuation));}
438 table_constraint_def:
439 unique_spec '(' column_commalist ')'
440 {$$ = SQL_NEW_RULE;
441 $$->append($1);
442 $$->append(newNode("(", SQLNodeType::Punctuation));
443 $$->append($3);
444 $$->append(newNode(")", SQLNodeType::Punctuation));}
445 | SQL_TOKEN_FOREIGN SQL_TOKEN_KEY '(' column_commalist ')' SQL_TOKEN_REFERENCES table_node
446 {$$ = SQL_NEW_RULE;
447 $$->append($1);
448 $$->append($2);
449 $$->append(newNode("(", SQLNodeType::Punctuation));
450 $$->append($4);
451 $$->append(newNode(")", SQLNodeType::Punctuation));
452 $$->append($6);
453 $$->append($7);}
454 | SQL_TOKEN_FOREIGN SQL_TOKEN_KEY '(' column_commalist ')' SQL_TOKEN_REFERENCES table_node '(' column_commalist ')'
455 {$$ = SQL_NEW_RULE;
456 $$->append($1);
457 $$->append($2);
458 $$->append(newNode("(", SQLNodeType::Punctuation));
459 $$->append($4);
460 $$->append(newNode(")", SQLNodeType::Punctuation));
461 $$->append($6);
462 $$->append($7);
463 $$->append(newNode("(", SQLNodeType::Punctuation));
464 $$->append($9);
465 $$->append(newNode(")", SQLNodeType::Punctuation));}
466 | SQL_TOKEN_CHECK '(' search_condition ')'
467 {$$ = SQL_NEW_RULE;
468 $$->append($1);
469 $$->append(newNode("(", SQLNodeType::Punctuation));
470 $$->append($3);
471 $$->append(newNode(")", SQLNodeType::Punctuation));}
473 op_column_commalist:
474 /* empty */ {$$ = SQL_NEW_RULE;}
475 | '(' column_commalist ')'
476 {$$ = SQL_NEW_RULE;
477 $$->append(newNode("(", SQLNodeType::Punctuation));
478 $$->append($2);
479 $$->append(newNode(")", SQLNodeType::Punctuation));
482 column_commalist:
483 column_commalist ',' column
484 {$1->append($3);
485 $$ = $1;}
486 | column
487 {$$ = SQL_NEW_COMMALISTRULE;
488 $$->append($1);}
491 view_def:
492 SQL_TOKEN_CREATE SQL_TOKEN_VIEW table_node opt_column_commalist SQL_TOKEN_AS select_statement opt_with_check_option
493 {$$ = SQL_NEW_RULE;
494 $$->append($1);
495 $$->append($2);
496 $$->append($3);
497 $$->append($4);
498 $$->append($5);
499 $$->append($6);
500 $$->append($7);}
503 opt_with_check_option:
504 /* empty */ {$$ = SQL_NEW_RULE;}
505 | SQL_TOKEN_WITH SQL_TOKEN_CHECK SQL_TOKEN_OPTION
506 {$$ = SQL_NEW_RULE;
507 $$->append($1);
508 $$->append($2);
509 $$->append($3);}
512 opt_column_commalist:
513 /* empty */ {$$ = SQL_NEW_RULE;}
514 | '(' column_commalist ')'
515 {$$ = SQL_NEW_RULE;
516 $$->append(newNode("(", SQLNodeType::Punctuation));
517 $$->append($2);
518 $$->append(newNode(")", SQLNodeType::Punctuation));}
521 privilege_def:
522 SQL_TOKEN_GRANT privileges SQL_TOKEN_ON table_node SQL_TOKEN_TO grantee_commalist
523 opt_with_grant_option
524 {$$ = SQL_NEW_RULE;
525 $$->append($1);
526 $$->append($2);
527 $$->append($3);
528 $$->append($4);
529 $$->append($5);
530 $$->append($6);
531 $$->append($7);}
534 opt_with_grant_option:
535 /* empty */ {$$ = SQL_NEW_RULE;}
536 | SQL_TOKEN_WITH SQL_TOKEN_GRANT SQL_TOKEN_OPTION
537 {$$ = SQL_NEW_RULE;
538 $$->append($1);
539 $$->append($2);
540 $$->append($3);}
543 privileges:
544 SQL_TOKEN_ALL SQL_TOKEN_PRIVILEGES
545 {$$ = SQL_NEW_RULE;
546 $$->append($1);
547 $$->append($2);}
548 | operation_commalist
551 operation_commalist:
552 operation
553 {$$ = SQL_NEW_COMMALISTRULE;
554 $$->append($1);}
555 | operation_commalist ',' operation
556 {$1->append($3);
557 $$ = $1;}
560 operation:
561 SQL_TOKEN_SELECT
562 | SQL_TOKEN_INSERT opt_column_commalist
563 {$$ = SQL_NEW_RULE;
564 $$->append($1);
565 $$->append($2);}
566 | SQL_TOKEN_DELETE
567 | SQL_TOKEN_UPDATE opt_column_commalist
568 {$$ = SQL_NEW_RULE;
569 $$->append($1);
570 $$->append($2);}
571 | SQL_TOKEN_REFERENCES opt_column_commalist
572 {$$ = SQL_NEW_RULE;
573 $$->append($1);
574 $$->append($2);}
575 | SQL_TOKEN_USAGE
579 grantee_commalist:
580 grantee
581 {$$ = SQL_NEW_COMMALISTRULE;
582 $$->append($1);}
583 | grantee_commalist ',' grantee
584 {$1->append($3);
585 $$ = $1;}
588 grantee:
589 SQL_TOKEN_PUBLIC
590 | user
593 /* module language */
595 opt_order_by_clause:
596 /* empty */ {$$ = SQL_NEW_RULE;}
597 | SQL_TOKEN_ORDER SQL_TOKEN_BY ordering_spec_commalist
598 {$$ = SQL_NEW_RULE;
599 $$->append($1);
600 $$->append($2);
601 $$->append($3);}
604 ordering_spec_commalist:
605 ordering_spec
606 {$$ = SQL_NEW_COMMALISTRULE;
607 $$->append($1);}
608 | ordering_spec_commalist ',' ordering_spec
609 {$1->append($3);
610 $$ = $1;}
613 ordering_spec:
614 /* SQL_TOKEN_INTNUM opt_asc_desc
615 {$$ = SQL_NEW_RULE;
616 $$->append($1);
617 $$->append($2);}
619 predicate opt_asc_desc
620 {$$ = SQL_NEW_RULE;
621 $$->append($1);
622 $$->append($2);}
624 | row_value_constructor_elem opt_asc_desc
625 {$$ = SQL_NEW_RULE;
626 $$->append($1);
627 $$->append($2);}
630 opt_asc_desc:
631 {$$ = SQL_NEW_RULE;}
632 | SQL_TOKEN_ASC
633 | SQL_TOKEN_DESC
637 /***
638 manipulative_statement_list:
639 manipulative_statement
640 {$$ = SQL_NEW_LISTRULE;
641 $$->append($1);}
642 | manipulative_statement_list manipulative_statement
643 {$1->append($2);
644 $$ = $1;}
646 ***/
648 sql_not:
649 /* vide */
650 {$$ = SQL_NEW_RULE;}
651 | SQL_TOKEN_NOT
654 /* manipulative statements */
656 manipulative_statement:
657 commit_statement
658 /* | delete_statement_positioned*/
659 | delete_statement_searched
660 | fetch_statement
661 | insert_statement
662 | rollback_statement
663 | select_statement_into
664 /* | update_statement_positioned*/
665 | update_statement_searched
666 | union_statement
667 | '{' odbc_call_spec '}'
669 $$ = SQL_NEW_RULE;
670 $$->append(newNode("{", SQLNodeType::Punctuation));
671 $$->append($2);
672 $$->append(newNode("}", SQLNodeType::Punctuation));
676 union_statement:
677 select_statement
678 | union_statement SQL_TOKEN_UNION all select_statement
680 $$ = SQL_NEW_RULE;
681 $$->append($1);
682 $$->append($2);
683 $$->append($3);
684 $$->append($4);
687 commit_statement:
688 SQL_TOKEN_COMMIT SQL_TOKEN_WORK
689 {$$ = SQL_NEW_RULE;
690 $$->append($1);
691 $$->append($2);}
694 delete_statement_positioned:
695 SQL_TOKEN_DELETE SQL_TOKEN_FROM table_node SQL_TOKEN_WHERE SQL_TOKEN_CURRENT SQL_TOKEN_OF cursor
696 {$$ = SQL_NEW_RULE;
697 $$->append($1);
698 $$->append($2);
699 $$->append($3);
700 $$->append($4);
701 $$->append($5);
702 $$->append($6);
703 $$->append($7);}
706 delete_statement_searched:
707 SQL_TOKEN_DELETE SQL_TOKEN_FROM table_node opt_where_clause
708 {$$ = SQL_NEW_RULE;
709 $$->append($1);
710 $$->append($2);
711 $$->append($3);
712 $$->append($4);}
715 fetch_statement:
716 SQL_TOKEN_FETCH cursor SQL_TOKEN_INTO target_commalist
717 {$$ = SQL_NEW_RULE;
718 $$->append($1);
719 $$->append($2);
720 $$->append($3);
721 $$->append($4);}
724 insert_statement:
725 SQL_TOKEN_INSERT SQL_TOKEN_INTO table_node opt_column_commalist query_exp
726 {$$ = SQL_NEW_RULE;
727 $$->append($1);
728 $$->append($2);
729 $$->append($3);
730 $$->append($4);
731 $$->append($5);}
733 values_or_query_spec:
734 SQL_TOKEN_VALUES '(' table_value_const_list ')'
735 {$$ = SQL_NEW_RULE;
736 $$->append($1);
737 $$->append(newNode("(", SQLNodeType::Punctuation));
738 $$->append($3);
739 $$->append(newNode(")", SQLNodeType::Punctuation));
743 table_value_const_list:
744 row_value_constructor
745 {$$ = SQL_NEW_COMMALISTRULE;
746 $$->append($1);}
747 | table_value_const_list ',' row_value_constructor
748 {$1->append($3);
749 $$ = $1;}
752 row_value_const_list:
753 row_value_constructor_elem
754 {$$ = SQL_NEW_COMMALISTRULE;
755 $$->append($1);}
756 | row_value_const_list ',' row_value_constructor_elem
757 {$1->append($3);
758 $$ = $1;}
761 row_value_constructor:
762 row_value_constructor_elem
763 /* | '(' row_value_const_list ')'
765 $$ = SQL_NEW_RULE;
766 $$->append(newNode("(", SQLNodeType::Punctuation));
767 $$->append($2);
768 $$->append(newNode(")", SQLNodeType::Punctuation));
772 row_value_constructor_elem:
773 value_exp /*[^')']*/
774 | SQL_TOKEN_DEFAULT
778 rollback_statement:
779 SQL_TOKEN_ROLLBACK SQL_TOKEN_WORK
780 {$$ = SQL_NEW_RULE;
781 $$->append($1);
782 $$->append($2);}
786 /* INTO target_commalist herausgenommen */
787 select_statement_into:
788 SQL_TOKEN_SELECT opt_all_distinct selection SQL_TOKEN_INTO target_commalist table_exp
789 {$$ = SQL_NEW_RULE;
790 $$->append($1);
791 $$->append($2);
792 $$->append($3);
793 $$->append($4);
794 $$->append($5);
795 $$->append($6); }
798 opt_all_distinct:
799 {$$ = SQL_NEW_RULE;}
800 | SQL_TOKEN_ALL
801 | SQL_TOKEN_DISTINCT
805 update_statement_positioned:
806 SQL_TOKEN_UPDATE table_node SQL_TOKEN_SET assignment_commalist
807 SQL_TOKEN_WHERE SQL_TOKEN_CURRENT SQL_TOKEN_OF cursor
808 {$$ = SQL_NEW_RULE;
809 $$->append($1);
810 $$->append($2);
811 $$->append($3);
812 $$->append($4);
813 $$->append($5);
814 $$->append($6);
815 $$->append($7);
816 $$->append($8);}
819 assignment_commalist:
820 assignment
821 {$$ = SQL_NEW_COMMALISTRULE;
822 $$->append($1);}
823 | assignment_commalist ',' assignment
824 {$1->append($3);
825 $$ = $1;}
828 assignment:
829 column SQL_EQUAL update_source
830 {$$ = SQL_NEW_RULE;
831 $$->append($1);
832 $$->append($2);
833 $$->append($3);}
835 update_source:
836 value_exp
837 | SQL_TOKEN_DEFAULT
839 update_statement_searched:
840 SQL_TOKEN_UPDATE table_node SQL_TOKEN_SET assignment_commalist opt_where_clause
841 {$$ = SQL_NEW_RULE;
842 $$->append($1);
843 $$->append($2);
844 $$->append($3);
845 $$->append($4);
846 $$->append($5);}
849 target_commalist:
850 target
851 {$$ = SQL_NEW_COMMALISTRULE;
852 $$->append($1);}
853 | target_commalist ',' target
854 {$1->append($3);
855 $$ = $1;}
858 target:
859 parameter_ref
862 opt_where_clause:
863 /* empty */ {$$ = SQL_NEW_RULE;}
864 | where_clause
867 /* query expressions */
869 query_term:
870 non_join_query_term
872 $$ = SQL_NEW_RULE;
873 $$->append($1);
876 /* SELECT STATEMENT */
877 select_statement:
878 SQL_TOKEN_SELECT opt_all_distinct selection table_exp
880 $$ = SQL_NEW_RULE;
881 $$->append($1);
882 $$->append($2);
883 $$->append($3);
884 $$->append($4);
888 selection:
891 $$ = SQL_NEW_RULE;
892 $$->append(newNode("*", SQLNodeType::Punctuation));
894 | scalar_exp_commalist
896 opt_result_offset_clause:
897 /* empty */ {$$ = SQL_NEW_RULE;}
898 | result_offset_clause
900 result_offset_clause:
901 SQL_TOKEN_OFFSET offset_row_count row_or_rows
903 $$ = SQL_NEW_RULE;
904 $$->append($1);
905 $$->append($2);
906 $$->append($3);
909 opt_fetch_first_row_count:
910 /* empty */ {$$ = SQL_NEW_RULE;}
911 | fetch_first_row_count
913 first_or_next:
914 SQL_TOKEN_FIRST
915 | SQL_TOKEN_NEXT
917 row_or_rows:
918 SQL_TOKEN_ROW
919 | SQL_TOKEN_ROWS
921 opt_fetch_first_clause:
922 /* empty */ {$$ = SQL_NEW_RULE;}
923 | fetch_first_clause
925 fetch_first_clause:
926 SQL_TOKEN_FETCH first_or_next opt_fetch_first_row_count row_or_rows SQL_TOKEN_ONLY
928 $$ = SQL_NEW_RULE;
929 $$->append($1);
930 $$->append($2);
931 $$->append($3);
932 $$->append($4);
933 $$->append($5);
936 offset_row_count:
937 literal
939 fetch_first_row_count:
940 literal
943 opt_limit_offset_clause:
944 /* empty */ {$$ = SQL_NEW_RULE;}
945 | limit_offset_clause
947 opt_offset:
948 /* empty */ {$$ = SQL_NEW_RULE;}
949 | SQL_TOKEN_OFFSET SQL_TOKEN_INTNUM
951 $$ = SQL_NEW_RULE;
952 $$->append($1);
953 $$->append($2);
956 limit_offset_clause:
957 SQL_TOKEN_LIMIT SQL_TOKEN_INTNUM opt_offset
959 $$ = SQL_NEW_RULE;
960 $$->append($1);
961 $$->append($2);
962 $$->append($3);
965 table_exp:
966 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
968 $$ = SQL_NEW_RULE;
969 $$->append($1);
970 $$->append($2);
971 $$->append($3);
972 $$->append($4);
973 $$->append($5);
974 $$->append($6);
975 $$->append($7);
976 $$->append($8);
977 $$->append($9);
981 from_clause:
982 SQL_TOKEN_FROM table_ref_commalist
983 { $$ = SQL_NEW_RULE;
984 $$->append($1);
985 $$->append($2); }
988 table_ref_commalist:
990 table_ref
991 { $$ = SQL_NEW_COMMALISTRULE;
992 $$->append($1); }
993 | table_ref_commalist ',' table_ref
994 { $1->append($3);
995 $$ = $1; }
998 opt_as:
999 /* empty */ {$$ = SQL_NEW_RULE;}
1000 | SQL_TOKEN_AS
1002 opt_row:
1003 /* empty */ {$$ = SQL_NEW_RULE;}
1004 | SQL_TOKEN_ROW
1006 table_primary_as_range_column:
1007 {$$ = SQL_NEW_RULE;}
1008 | opt_as SQL_TOKEN_NAME op_column_commalist
1010 $$ = SQL_NEW_RULE;
1011 $$->append($1);
1012 $$->append($2);
1013 $$->append($3);
1016 table_ref:
1017 table_node table_primary_as_range_column
1019 $$ = SQL_NEW_RULE;
1020 $$->append($1);
1021 $$->append($2);
1023 | subquery range_variable op_column_commalist
1025 $$ = SQL_NEW_RULE;
1026 $$->append($1);
1027 $$->append($2);
1028 $$->append($3);
1030 | joined_table
1031 | '{' SQL_TOKEN_OJ joined_table '}'
1033 $$ = SQL_NEW_RULE;
1034 $$->append(newNode("{", SQLNodeType::Punctuation));
1035 $$->append($2);
1036 $$->append($3);
1037 $$->append(newNode("}", SQLNodeType::Punctuation));
1039 | '(' joined_table ')'
1041 $$ = SQL_NEW_RULE;
1042 $$->append(newNode("(", SQLNodeType::Punctuation));
1043 $$->append($2);
1044 $$->append(newNode(")", SQLNodeType::Punctuation));
1047 where_clause:
1048 SQL_TOKEN_WHERE search_condition
1049 {$$ = SQL_NEW_RULE;
1050 $$->append($1);
1051 $$->append($2);}
1054 opt_group_by_clause:
1055 /* empty */ {$$ = SQL_NEW_RULE;}
1056 | SQL_TOKEN_GROUP SQL_TOKEN_BY column_ref_commalist
1057 {$$ = SQL_NEW_RULE;
1058 $$->append($1);
1059 $$->append($2);
1060 $$->append($3);}
1063 column_ref_commalist:
1064 column_ref
1065 {$$ = SQL_NEW_COMMALISTRULE;
1066 $$->append($1);}
1067 | set_fct_spec
1068 {$$ = SQL_NEW_COMMALISTRULE;
1069 $$->append($1);}
1070 | column_ref_commalist ',' column_ref
1071 {$1->append($3);
1072 $$ = $1;}
1073 | column_ref_commalist ',' set_fct_spec
1074 {$1->append($3);
1075 $$ = $1;}
1078 opt_having_clause:
1079 /* empty */ {$$ = SQL_NEW_RULE;}
1080 | SQL_TOKEN_HAVING search_condition
1081 {$$ = SQL_NEW_RULE;
1082 $$->append($1);
1083 $$->append($2);}
1086 /* search conditions */
1087 boolean_primary:
1088 predicate
1089 | '(' search_condition ')'
1090 { // boolean_primary: rule 2
1091 $$ = SQL_NEW_RULE;
1092 $$->append(newNode("(", SQLNodeType::Punctuation));
1093 $$->append($2);
1094 $$->append(newNode(")", SQLNodeType::Punctuation));
1096 | row_value_constructor_elem /*[^')' ',']*/
1098 if(xxx_pGLOBAL_SQLPARSER->inPredicateCheck())// boolean_primary: rule 3
1100 $$ = SQL_NEW_RULE;
1101 sal_Int16 nErg = 0;
1102 if ( SQL_ISTOKEN( $1, NULL))
1104 OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1105 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1106 OSQLParseNode* pTFN = new OSQLInternalNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::test_for_null));
1107 pTFN->append(pColumnRef);
1109 OSQLParseNode* pNPP2 = new OSQLInternalNode("", SQLNodeType::Rule, OSQLParser::RuleID(OSQLParseNode::null_predicate_part_2));
1110 pNPP2->append(new OSQLInternalNode("", SQLNodeType::Keyword, SQL_TOKEN_IS));
1111 pNPP2->append(new OSQLInternalNode("", SQLNodeType::Rule, OSQLParser::RuleID(OSQLParseNode::sql_not)));
1112 pNPP2->append(new OSQLInternalNode("", SQLNodeType::Keyword, SQL_TOKEN_NULL));
1113 pTFN->append(pNPP2);
1115 $$->append(pTFN);
1117 nErg = 1;
1119 else
1121 nErg = xxx_pGLOBAL_SQLPARSER->buildComparsionRule($$,$1);
1123 if(nErg == 1)
1125 OSQLParseNode* pTemp = $$;
1126 $$ = pTemp->removeAt((sal_uInt32)0);
1127 delete pTemp;
1129 else
1131 delete $$;
1132 if(nErg)
1133 YYERROR;
1134 else
1135 YYABORT;
1138 else
1139 YYERROR;
1142 parenthesized_boolean_value_expression:
1143 '(' search_condition ')'
1144 { // boolean_primary: rule 2
1145 $$ = SQL_NEW_RULE;
1146 $$->append(newNode("(", SQLNodeType::Punctuation));
1147 $$->append($2);
1148 $$->append(newNode(")", SQLNodeType::Punctuation));
1151 boolean_factor:
1152 boolean_primary %dprec 2
1153 | SQL_TOKEN_NOT boolean_primary %dprec 1
1154 { // boolean_factor: rule 1
1155 $$ = SQL_NEW_RULE;
1156 $$->append($1);
1157 $$->append($2);
1160 boolean_term:
1161 boolean_factor
1162 | boolean_term SQL_TOKEN_AND boolean_factor
1164 $$ = SQL_NEW_RULE; // boolean_term: rule 1
1165 $$->append($1);
1166 $$->append($2);
1167 $$->append($3);
1170 search_condition:
1171 boolean_term
1172 | search_condition SQL_TOKEN_OR boolean_term
1174 $$ = SQL_NEW_RULE; // search_condition
1175 $$->append($1);
1176 $$->append($2);
1177 $$->append($3);
1180 predicate:
1181 comparison_predicate %dprec 1
1182 | between_predicate
1183 | all_or_any_predicate
1184 | existence_test
1185 | unique_test
1186 | test_for_null %dprec 2
1187 | in_predicate
1188 | like_predicate
1190 comparison_predicate_part_2:
1191 comparison row_value_constructor
1193 $$ = SQL_NEW_RULE; // comparison_predicate: rule 1
1194 $$->append($1);
1195 $$->append($2);
1197 comparison_predicate:
1198 row_value_constructor comparison row_value_constructor
1200 $$ = SQL_NEW_RULE; // comparison_predicate: rule 1
1201 $$->append($1);
1202 $$->append($2);
1203 $$->append($3);
1205 | comparison row_value_constructor
1207 if(xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // comparison_predicate: rule 2
1209 $$ = SQL_NEW_RULE;
1210 sal_Int16 nErg = xxx_pGLOBAL_SQLPARSER->buildPredicateRule($$,$2,$1);
1211 if(nErg == 1)
1213 OSQLParseNode* pTemp = $$;
1214 $$ = pTemp->removeAt((sal_uInt32)0);
1215 delete pTemp;
1217 else
1219 delete $$;
1220 YYABORT;
1223 else
1225 YYERROR;
1229 comparison:
1230 SQL_LESS
1231 | SQL_NOTEQUAL
1232 | SQL_EQUAL
1233 | SQL_GREAT
1234 | SQL_LESSEQ
1235 | SQL_GREATEQ
1236 | SQL_TOKEN_IS sql_not SQL_TOKEN_DISTINCT SQL_TOKEN_FROM
1238 $$ = SQL_NEW_RULE;
1239 $$->append($1);
1240 $$->append($2);
1241 $$->append($3);
1242 $$->append($4);
1244 | SQL_TOKEN_IS sql_not
1246 $$ = SQL_NEW_RULE;
1247 $$->append($1);
1248 $$->append($2);
1251 between_predicate_part_2:
1252 sql_not SQL_TOKEN_BETWEEN row_value_constructor SQL_TOKEN_AND row_value_constructor
1254 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // between_predicate: rule 2
1256 $$ = SQL_NEW_RULE;
1258 sal_Int16 nErg = xxx_pGLOBAL_SQLPARSER->buildPredicateRule($$,$3,$2,$5);
1259 if(nErg == 1)
1261 OSQLParseNode* pTemp = $$;
1262 $$ = pTemp->removeAt((sal_uInt32)0);
1263 OSQLParseNode* pColumnRef = $$->removeAt((sal_uInt32)0);
1264 $$->insert(0,$1);
1265 OSQLParseNode* pBetween_predicate = new OSQLInternalNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::between_predicate));
1266 pBetween_predicate->append(pColumnRef);
1267 pBetween_predicate->append($$);
1268 $$ = pBetween_predicate;
1270 delete pTemp;
1271 delete $4;
1273 else
1275 delete $$;
1276 YYABORT;
1279 else
1281 $$ = SQL_NEW_RULE; // between_predicate: rule 1
1282 $$->append($1);
1283 $$->append($2);
1284 $$->append($3);
1285 $$->append($4);
1286 $$->append($5);
1289 between_predicate:
1290 row_value_constructor between_predicate_part_2
1292 $$ = SQL_NEW_RULE; // between_predicate: rule 1
1293 $$->append($1);
1294 $$->append($2);
1296 | between_predicate_part_2
1298 character_like_predicate_part_2:
1299 sql_not SQL_TOKEN_LIKE string_value_exp opt_escape
1301 $$ = SQL_NEW_RULE; // like_predicate: rule 1
1302 $$->append($1);
1303 $$->append($2);
1304 $$->append($3);
1305 $$->append($4);
1308 other_like_predicate_part_2:
1309 sql_not SQL_TOKEN_LIKE value_exp_primary opt_escape
1311 $$ = SQL_NEW_RULE; // like_predicate: rule 1
1312 $$->append($1);
1313 $$->append($2);
1314 $$->append($3);
1315 $$->append($4);
1318 like_predicate:
1319 row_value_constructor character_like_predicate_part_2
1321 $$ = SQL_NEW_RULE; // like_predicate: rule 1
1322 $$->append($1);
1323 $$->append($2);
1325 | row_value_constructor other_like_predicate_part_2
1327 $$ = SQL_NEW_RULE; // like_predicate: rule 3
1328 $$->append($1);
1329 $$->append($2);
1331 | character_like_predicate_part_2
1333 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // like_predicate: rule 5
1335 OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1336 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1338 $$ = SQL_NEW_RULE;
1339 $$->append(pColumnRef);
1340 $$->append($1);
1341 OSQLParseNode* p2nd = $1->removeAt(2);
1342 OSQLParseNode* p3rd = $1->removeAt(2);
1343 if ( !xxx_pGLOBAL_SQLPARSER->buildLikeRule($1,p2nd,p3rd) )
1345 delete $$;
1346 YYABORT;
1348 $1->append(p3rd);
1350 else
1351 YYERROR;
1353 | other_like_predicate_part_2
1355 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // like_predicate: rule 6
1357 OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1358 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1360 $$ = SQL_NEW_RULE;
1361 $$->append(pColumnRef);
1362 $$->append($1);
1363 OSQLParseNode* p2nd = $1->removeAt(2);
1364 OSQLParseNode* p3rd = $1->removeAt(2);
1365 if ( !xxx_pGLOBAL_SQLPARSER->buildLikeRule($1,p2nd,p3rd) )
1367 delete $$;
1368 YYABORT;
1370 $1->append(p3rd);
1372 else
1373 YYERROR;
1377 opt_escape:
1378 /* empty */ {$$ = SQL_NEW_RULE;}
1379 | SQL_TOKEN_ESCAPE string_value_exp
1380 {$$ = SQL_NEW_RULE;
1381 $$->append($1);
1382 $$->append($2);}
1383 | '{' SQL_TOKEN_ESCAPE SQL_TOKEN_STRING '}'
1385 $$ = SQL_NEW_RULE;
1386 $$->append(newNode("{", SQLNodeType::Punctuation));
1387 $$->append($2);
1388 $$->append($3);
1389 $$->append(newNode("}", SQLNodeType::Punctuation));
1393 null_predicate_part_2:
1394 SQL_TOKEN_IS sql_not SQL_TOKEN_NULL
1396 $$ = SQL_NEW_RULE; // test_for_null: rule 1
1397 $$->append($1);
1398 $$->append($2);
1399 $$->append($3);
1401 | SQL_TOKEN_IS sql_not SQL_TOKEN_UNKNOWN
1403 $$ = SQL_NEW_RULE; // test_for_null: rule 1
1404 $$->append($1);
1405 $$->append($2);
1406 $$->append($3);
1409 test_for_null:
1410 row_value_constructor null_predicate_part_2
1412 $$ = SQL_NEW_RULE; // test_for_null: rule 1
1413 $$->append($1);
1414 $$->append($2);
1416 | null_predicate_part_2
1418 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())// test_for_null: rule 2
1420 OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1421 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1423 $$ = SQL_NEW_RULE;
1424 $$->append(pColumnRef);
1425 $$->append($1);
1427 else
1428 YYERROR;
1431 in_predicate_value:
1432 subquery
1433 {$$ = SQL_NEW_RULE;
1434 $$->append($1);
1436 | '(' value_exp_commalist ')'
1437 {$$ = SQL_NEW_RULE;
1438 $$->append(newNode("(", SQLNodeType::Punctuation));
1439 $$->append($2);
1440 $$->append(newNode(")", SQLNodeType::Punctuation));
1443 in_predicate_part_2:
1444 sql_not SQL_TOKEN_IN in_predicate_value
1446 $$ = SQL_NEW_RULE;// in_predicate: rule 1
1447 $$->append($1);
1448 $$->append($2);
1449 $$->append($3);
1452 in_predicate:
1453 row_value_constructor in_predicate_part_2
1455 $$ = SQL_NEW_RULE;// in_predicate: rule 1
1456 $$->append($1);
1457 $$->append($2);
1459 | in_predicate_part_2
1461 if ( xxx_pGLOBAL_SQLPARSER->inPredicateCheck() )// in_predicate: rule 2
1463 OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1464 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1466 $$ = SQL_NEW_RULE;
1467 $$->append(pColumnRef);
1468 $$->append($1);
1470 else
1471 YYERROR;
1474 quantified_comparison_predicate_part_2:
1475 comparison any_all_some subquery
1477 $$ = SQL_NEW_RULE;
1478 $$->append($1);
1479 $$->append($2);
1480 $$->append($3);
1483 all_or_any_predicate:
1484 row_value_constructor quantified_comparison_predicate_part_2
1486 $$ = SQL_NEW_RULE;
1487 $$->append($1);
1488 $$->append($2);
1490 | quantified_comparison_predicate_part_2
1492 if(xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1494 OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1495 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1497 $$ = SQL_NEW_RULE;
1498 $$->append(pColumnRef);
1499 $$->append($1);
1501 else
1502 YYERROR;
1506 any_all_some:
1507 SQL_TOKEN_ANY
1508 | SQL_TOKEN_ALL
1509 | SQL_TOKEN_SOME
1512 existence_test:
1513 SQL_TOKEN_EXISTS subquery
1514 {$$ = SQL_NEW_RULE;
1515 $$->append($1);
1516 $$->append($2);}
1518 unique_test:
1519 SQL_TOKEN_UNIQUE subquery
1520 {$$ = SQL_NEW_RULE;
1521 $$->append($1);
1522 $$->append($2);}
1524 subquery:
1525 '(' query_exp ')'
1526 {$$ = SQL_NEW_RULE;
1527 $$->append(newNode("(", SQLNodeType::Punctuation));
1528 $$->append($2);
1529 $$->append(newNode(")", SQLNodeType::Punctuation));}
1532 /* scalar expressions */
1533 scalar_exp_commalist:
1534 select_sublist
1536 $$ = SQL_NEW_COMMALISTRULE;
1537 $$->append($1);
1539 | scalar_exp_commalist ',' select_sublist
1541 $1->append($3);
1542 $$ = $1;
1545 select_sublist:
1546 /* table_node '.' '*'
1548 $$ = SQL_NEW_RULE;
1549 $$->append($1);
1550 $$->append(newNode(".", SQLNodeType::Punctuation));
1551 $$->append(newNode("*", SQLNodeType::Punctuation));
1554 derived_column
1558 parameter_ref:
1559 parameter
1563 op_like:
1566 $$ = newNode("*", SQLNodeType::Punctuation);
1568 | '?'
1570 $$ = newNode("?", SQLNodeType::Punctuation);
1572 | op_like '*'
1574 $$ = SQL_NEW_RULE;
1575 $$->append($1);
1576 $$->append(newNode("*", SQLNodeType::Punctuation));
1577 xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_False);
1579 | op_like '?'
1581 $$ = SQL_NEW_RULE;
1582 $$->append($1);
1583 $$->append(newNode("?", SQLNodeType::Punctuation));
1584 xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_False);
1589 literal:
1590 /* SQL_TOKEN_STRING
1591 | */SQL_TOKEN_INT
1592 | SQL_TOKEN_REAL_NUM
1593 | SQL_TOKEN_INTNUM
1594 | SQL_TOKEN_APPROXNUM
1595 | SQL_TOKEN_ACCESS_DATE
1596 /* rules for predicate check */
1597 | literal SQL_TOKEN_STRING
1599 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1601 $$ = SQL_NEW_RULE;
1602 $$->append($1);
1603 $$->append($2);
1604 OSQLParser::reduceLiteral($$, true);
1606 else
1607 YYERROR;
1609 | literal SQL_TOKEN_INT
1611 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1613 $$ = SQL_NEW_RULE;
1614 $$->append($1);
1615 $$->append($2);
1616 OSQLParser::reduceLiteral($$, true);
1618 else
1619 YYERROR;
1621 | literal SQL_TOKEN_REAL_NUM
1623 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1625 $$ = SQL_NEW_RULE;
1626 $$->append($1);
1627 $$->append($2);
1628 OSQLParser::reduceLiteral($$, true);
1630 else
1631 YYERROR;
1633 | literal SQL_TOKEN_APPROXNUM
1635 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1637 $$ = SQL_NEW_RULE;
1638 $$->append($1);
1639 $$->append($2);
1640 OSQLParser::reduceLiteral($$, true);
1642 else
1643 YYERROR;
1647 /* miscellaneous */
1648 as_clause:
1649 /* empty */ {$$ = SQL_NEW_RULE;}
1650 | SQL_TOKEN_AS column
1652 $$ = SQL_NEW_RULE;
1653 $$->append($1);
1654 $$->append($2);
1656 | column
1658 position_exp:
1659 SQL_TOKEN_POSITION '(' value_exp SQL_TOKEN_IN value_exp ')'
1661 $$ = SQL_NEW_RULE;
1662 $$->append($1);
1663 $$->append(newNode("(", SQLNodeType::Punctuation));
1664 $$->append($3);
1665 $$->append($4);
1666 $$->append($5);
1667 $$->append(newNode(")", SQLNodeType::Punctuation));
1669 | SQL_TOKEN_POSITION '(' value_exp_commalist ')'
1671 $$ = SQL_NEW_RULE;
1672 $$->append($1);
1673 $$->append(newNode("(", SQLNodeType::Punctuation));
1674 $$->append($3);
1675 $$->append(newNode(")", SQLNodeType::Punctuation));
1678 num_value_fct:
1679 position_exp
1680 | extract_exp
1681 | length_exp
1683 char_length_exp:
1684 SQL_TOKEN_CHAR_LENGTH '(' value_exp ')'
1686 $$ = SQL_NEW_RULE;
1687 $$->append($1);
1688 $$->append(newNode("(", SQLNodeType::Punctuation));
1689 $$->append($3);
1690 $$->append(newNode(")", SQLNodeType::Punctuation));
1692 | SQL_TOKEN_SQL_TOKEN_INTNUM '(' value_exp ')'
1694 $$ = SQL_NEW_RULE;
1695 $$->append($1);
1696 $$->append(newNode("(", SQLNodeType::Punctuation));
1697 $$->append($3);
1698 $$->append(newNode(")", SQLNodeType::Punctuation));
1702 octet_length_exp:
1703 SQL_TOKEN_OCTET_LENGTH '(' value_exp ')'
1705 $$ = SQL_NEW_RULE;
1706 $$->append($1);
1707 $$->append(newNode("(", SQLNodeType::Punctuation));
1708 $$->append($3);
1709 $$->append(newNode(")", SQLNodeType::Punctuation));
1712 bit_length_exp:
1713 SQL_TOKEN_BIT_LENGTH '(' value_exp ')'
1715 $$ = SQL_NEW_RULE;
1716 $$->append($1);
1717 $$->append(newNode("(", SQLNodeType::Punctuation));
1718 $$->append($3);
1719 $$->append(newNode(")", SQLNodeType::Punctuation));
1722 length_exp:
1723 char_length_exp
1725 $$ = SQL_NEW_RULE;
1726 $$->append($1);
1728 | octet_length_exp
1730 $$ = SQL_NEW_RULE;
1731 $$->append($1);
1733 | bit_length_exp
1735 $$ = SQL_NEW_RULE;
1736 $$->append($1);
1739 datetime_field:
1740 non_second_datetime_field
1742 $$ = SQL_NEW_RULE;
1743 $$->append($1);
1745 | SQL_TOKEN_SECOND
1747 $$ = SQL_NEW_RULE;
1748 $$->append($1);
1751 extract_field:
1752 time_zone_field
1753 | datetime_field
1754 | value_exp
1756 time_zone_field:
1757 SQL_TOKEN_TIMEZONE_HOUR
1759 $$ = SQL_NEW_RULE;
1760 $$->append($1);
1762 | SQL_TOKEN_TIMEZONE_MINUTE
1764 $$ = SQL_NEW_RULE;
1765 $$->append($1);
1768 extract_exp:
1769 SQL_TOKEN_EXTRACT '(' extract_field SQL_TOKEN_FROM value_exp ')'
1771 $$ = SQL_NEW_RULE;
1772 $$->append($1);
1773 $$->append(newNode("(", SQLNodeType::Punctuation));
1774 $$->append($3);
1775 $$->append($4);
1776 $$->append($5);
1777 $$->append(newNode(")", SQLNodeType::Punctuation));
1780 unsigned_value_spec:
1781 general_value_spec
1782 | literal
1784 general_value_spec:
1785 parameter
1786 | SQL_TOKEN_USER
1787 | SQL_TOKEN_NULL
1788 | SQL_TOKEN_FALSE
1789 | SQL_TOKEN_TRUE
1790 | SQL_TOKEN_VALUE
1791 | SQL_TOKEN_CURRENT_CATALOG
1792 | SQL_TOKEN_CURRENT_DEFAULT_TRANSFORM_GROUP
1793 | SQL_TOKEN_CURRENT_PATH
1794 | SQL_TOKEN_CURRENT_ROLE
1795 | SQL_TOKEN_CURRENT_SCHEMA
1796 | SQL_TOKEN_CURRENT_USER
1797 | SQL_TOKEN_SESSION_USER
1798 | SQL_TOKEN_SYSTEM_USER
1800 set_fct_spec:
1801 general_set_fct
1802 | '{' odbc_fct_spec '}'
1804 $$ = SQL_NEW_RULE;
1805 $$->append(newNode("{", SQLNodeType::Punctuation));
1806 $$->append($2);
1807 $$->append(newNode("}", SQLNodeType::Punctuation));
1809 | function_name '(' ')'
1811 $$ = SQL_NEW_RULE;
1812 $$->append($1);
1813 $$->append(newNode("(", SQLNodeType::Punctuation));
1814 $$->append(newNode(")", SQLNodeType::Punctuation));
1816 | function_name0 '(' ')'
1818 $$ = SQL_NEW_RULE;
1819 $$->append($1);
1820 $$->append(newNode("(", SQLNodeType::Punctuation));
1821 $$->append(newNode(")", SQLNodeType::Punctuation));
1823 | function_name1 '(' function_arg ')'
1825 $$ = SQL_NEW_RULE;
1826 $$->append($1);
1827 $$->append(newNode("(", SQLNodeType::Punctuation));
1828 $$->append($3);
1829 $$->append(newNode(")", SQLNodeType::Punctuation));
1831 | function_name2 '(' function_arg_commalist2 ')'
1833 $$ = SQL_NEW_RULE;
1834 $$->append($1);
1835 $$->append(newNode("(", SQLNodeType::Punctuation));
1836 $$->append($3);
1837 $$->append(newNode(")", SQLNodeType::Punctuation));
1839 | function_name3 '(' function_arg_commalist3 ')'
1841 $$ = SQL_NEW_RULE;
1842 $$->append($1);
1843 $$->append(newNode("(", SQLNodeType::Punctuation));
1844 $$->append($3);
1845 $$->append(newNode(")", SQLNodeType::Punctuation));
1847 | string_function_4Argument '(' function_arg_commalist4 ')'
1849 $$ = SQL_NEW_RULE;
1850 $$->append($1);
1851 $$->append(newNode("(", SQLNodeType::Punctuation));
1852 $$->append($3);
1853 $$->append(newNode(")", SQLNodeType::Punctuation));
1855 | function_name '(' function_args_commalist ')'
1857 $$ = SQL_NEW_RULE;
1858 $$->append($1);
1859 $$->append(newNode("(", SQLNodeType::Punctuation));
1860 $$->append($3);
1861 $$->append(newNode(")", SQLNodeType::Punctuation));
1863 | function_name12 '(' function_args_commalist ')'
1865 if ( $3->count() == 1 || $3->count() == 2 )
1867 $$ = SQL_NEW_RULE;
1868 $$->append($1);
1869 $$->append(newNode("(", SQLNodeType::Punctuation));
1870 $$->append($3);
1871 $$->append(newNode(")", SQLNodeType::Punctuation));
1873 else
1874 YYERROR;
1876 | function_name23 '(' function_args_commalist ')'
1878 if ( $3->count() == 2 || $3->count() == 3)
1880 $$ = SQL_NEW_RULE;
1881 $$->append($1);
1882 $$->append(newNode("(", SQLNodeType::Punctuation));
1883 $$->append($3);
1884 $$->append(newNode(")", SQLNodeType::Punctuation));
1886 else
1887 YYERROR;
1890 function_name0:
1891 date_function_0Argument
1892 | numeric_function_0Argument
1894 function_name1:
1895 string_function_1Argument
1896 | date_function_1Argument
1897 | numeric_function_1Argument
1899 function_name2:
1900 string_function_2Argument
1901 | numeric_function_2Argument
1903 function_name12:
1904 SQL_TOKEN_ROUND
1905 | SQL_TOKEN_WEEK
1906 | SQL_TOKEN_LOGF
1907 | SQL_TOKEN_LOG
1909 function_name23:
1910 SQL_TOKEN_LOCATE
1911 | SQL_TOKEN_DATEDIFF
1913 function_name3:
1914 string_function_3Argument
1916 function_name:
1917 string_function
1918 | date_function
1919 | numeric_function
1920 | SQL_TOKEN_NAME
1922 string_function_1Argument:
1923 SQL_TOKEN_LENGTH
1924 | SQL_TOKEN_ASCII
1925 | SQL_TOKEN_LCASE
1926 | SQL_TOKEN_LTRIM
1927 | SQL_TOKEN_RTRIM
1928 | SQL_TOKEN_SPACE
1929 | SQL_TOKEN_UCASE
1932 string_function_2Argument:
1933 SQL_TOKEN_REPEAT
1934 | SQL_TOKEN_LEFT
1935 | SQL_TOKEN_RIGHT
1937 string_function_3Argument:
1938 SQL_TOKEN_REPLACE
1940 string_function_4Argument:
1941 SQL_TOKEN_INSERT
1944 string_function:
1945 SQL_TOKEN_CHAR
1946 | SQL_TOKEN_CONCAT
1947 | SQL_TOKEN_DIFFERENCE
1948 | SQL_TOKEN_LOCATE_2
1949 | SQL_TOKEN_SOUNDEX
1951 date_function_0Argument:
1952 SQL_TOKEN_CURDATE
1953 | SQL_TOKEN_CURTIME
1954 | SQL_TOKEN_NOW
1956 date_function_1Argument:
1957 SQL_TOKEN_DAYOFWEEK
1958 | SQL_TOKEN_DAYOFMONTH
1959 | SQL_TOKEN_DAYOFYEAR
1960 | SQL_TOKEN_MONTH
1961 | SQL_TOKEN_DAYNAME
1962 | SQL_TOKEN_MONTHNAME
1963 | SQL_TOKEN_QUARTER
1964 | SQL_TOKEN_HOUR
1965 | SQL_TOKEN_MINUTE
1966 | SQL_TOKEN_SECOND
1967 | SQL_TOKEN_YEAR
1968 | SQL_TOKEN_DAY
1969 | SQL_TOKEN_TIMEVALUE
1970 | SQL_TOKEN_DATEVALUE
1973 date_function:
1974 SQL_TOKEN_TIMESTAMPADD
1975 | SQL_TOKEN_TIMESTAMPDIFF
1977 numeric_function_0Argument:
1978 SQL_TOKEN_PI
1980 numeric_function_1Argument:
1981 SQL_TOKEN_ABS
1982 | SQL_TOKEN_ACOS
1983 | SQL_TOKEN_ASIN
1984 | SQL_TOKEN_ATAN
1985 | SQL_TOKEN_CEILING
1986 | SQL_TOKEN_COS
1987 | SQL_TOKEN_COT
1988 | SQL_TOKEN_DEGREES
1989 | SQL_TOKEN_FLOOR
1990 | SQL_TOKEN_SIGN
1991 | SQL_TOKEN_SIN
1992 | SQL_TOKEN_SQRT
1993 | SQL_TOKEN_TAN
1994 | SQL_TOKEN_EXP
1995 | SQL_TOKEN_LOG10
1996 | SQL_TOKEN_LN
1997 | SQL_TOKEN_RADIANS
1998 | SQL_TOKEN_ROUNDMAGIC
2000 numeric_function_2Argument:
2001 SQL_TOKEN_ATAN2
2002 | SQL_TOKEN_MOD
2003 | SQL_TOKEN_POWER
2005 numeric_function:
2006 SQL_TOKEN_RAND
2007 | SQL_TOKEN_TRUNCATE
2010 window_function:
2011 window_function_type SQL_TOKEN_OVER window_name_or_specification
2013 $$ = SQL_NEW_RULE;
2014 $$->append($1);
2015 $$->append($2);
2016 $$->append($3);
2019 window_function_type :
2020 rank_function_type '(' ')'
2022 $$ = SQL_NEW_RULE;
2023 $$->append($1);
2024 $$->append(newNode("(", SQLNodeType::Punctuation));
2025 $$->append(newNode(")", SQLNodeType::Punctuation));
2027 | SQL_TOKEN_ROW_NUMBER '(' ')'
2029 $$ = SQL_NEW_RULE;
2030 $$->append($1);
2031 $$->append(newNode("(", SQLNodeType::Punctuation));
2032 $$->append(newNode(")", SQLNodeType::Punctuation));
2034 | general_set_fct
2035 | ntile_function
2036 | lead_or_lag_function
2037 | first_or_last_value_function
2038 | nth_value_function
2040 ntile_function :
2041 SQL_TOKEN_NTILE '(' number_of_tiles ')'
2043 $$ = SQL_NEW_RULE;
2044 $$->append($1);
2045 $$->append(newNode("(", SQLNodeType::Punctuation));
2046 $$->append($3);
2047 $$->append(newNode(")", SQLNodeType::Punctuation));
2050 dynamic_parameter_specification:
2051 parameter
2053 simple_value_specification:
2054 literal
2056 number_of_tiles :
2057 simple_value_specification
2058 | dynamic_parameter_specification
2060 opt_lead_or_lag_function:
2061 /* empty */ {$$ = SQL_NEW_RULE;}
2062 | ',' offset
2064 $$ = SQL_NEW_RULE;
2065 $$->append(newNode(",", SQLNodeType::Punctuation));
2066 $$->append($2);
2068 | ',' offset ',' default_expression
2070 $$ = SQL_NEW_RULE;
2071 $$->append(newNode(",", SQLNodeType::Punctuation));
2072 $$->append($2);
2073 $$->append(newNode(",", SQLNodeType::Punctuation));
2074 $$->append($4);
2077 opt_null_treatment:
2078 /* empty */ {$$ = SQL_NEW_RULE;}
2079 | null_treatment
2082 lead_or_lag_function:
2083 lead_or_lag '(' lead_or_lag_extent opt_lead_or_lag_function ')' opt_null_treatment
2085 $$ = SQL_NEW_RULE;
2086 $$->append($1);
2087 $$->append(newNode("(", SQLNodeType::Punctuation));
2088 $$->append($3);
2089 $$->append($4);
2090 $$->append(newNode(")", SQLNodeType::Punctuation));
2091 $$->append($6);
2094 lead_or_lag:
2095 SQL_TOKEN_LEAD
2096 | SQL_TOKEN_LAG
2098 lead_or_lag_extent:
2099 value_exp
2101 offset:
2102 SQL_TOKEN_INTNUM
2104 default_expression:
2105 value_exp
2107 null_treatment:
2108 SQL_TOKEN_RESPECT SQL_TOKEN_NULLS
2109 | SQL_TOKEN_IGNORE SQL_TOKEN_NULLS
2111 first_or_last_value_function:
2112 first_or_last_value '(' value_exp ')' opt_null_treatment
2114 $$ = SQL_NEW_RULE;
2115 $$->append($1);
2116 $$->append(newNode("(", SQLNodeType::Punctuation));
2117 $$->append($3);
2118 $$->append(newNode(")", SQLNodeType::Punctuation));
2119 $$->append($5);
2122 first_or_last_value :
2123 SQL_TOKEN_FIRST_VALUE
2124 | SQL_TOKEN_LAST_VALUE
2126 opt_from_first_or_last:
2127 /* empty */ {$$ = SQL_NEW_RULE;}
2128 | from_first_or_last
2130 nth_value_function:
2131 SQL_TOKEN_NTH_VALUE '(' value_exp ',' nth_row ')' opt_from_first_or_last opt_null_treatment
2133 $$ = SQL_NEW_RULE;
2134 $$->append($1);
2135 $$->append(newNode("(", SQLNodeType::Punctuation));
2136 $$->append($3);
2137 $$->append(newNode(",", SQLNodeType::Punctuation));
2138 $$->append($5);
2139 $$->append(newNode(")", SQLNodeType::Punctuation));
2140 $$->append($7);
2141 $$->append($8);
2144 nth_row:
2145 simple_value_specification
2146 | dynamic_parameter_specification
2148 from_first_or_last:
2149 SQL_TOKEN_FROM SQL_TOKEN_FIRST
2151 $$ = SQL_NEW_RULE;
2152 $$->append($1);
2153 $$->append($2);
2155 | SQL_TOKEN_FROM SQL_TOKEN_LAST
2157 $$ = SQL_NEW_RULE;
2158 $$->append($1);
2159 $$->append($2);
2162 window_name:
2163 SQL_TOKEN_NAME
2165 window_name_or_specification:
2166 window_name
2167 | in_line_window_specification
2169 in_line_window_specification:
2170 window_specification
2172 opt_window_clause:
2173 /* empty */ {$$ = SQL_NEW_RULE;}
2174 | window_clause
2176 window_clause:
2177 SQL_TOKEN_WINDOW window_definition_list
2179 $$ = SQL_NEW_RULE;
2180 $$->append($1);
2181 $$->append($2);
2184 window_definition_list:
2185 window_definition_list ',' window_definition
2186 {$1->append($3);
2187 $$ = $1;}
2188 | window_definition
2189 {$$ = SQL_NEW_COMMALISTRULE;
2190 $$->append($1);}
2192 window_definition:
2193 new_window_name SQL_TOKEN_AS window_specification
2195 $$ = SQL_NEW_RULE;
2196 $$->append($1);
2197 $$->append($2);
2198 $$->append($3);
2201 new_window_name:
2202 window_name
2204 window_specification:
2205 '(' window_specification_details ')'
2207 $$ = SQL_NEW_RULE;
2208 $$->append(newNode("(", SQLNodeType::Punctuation));
2209 $$->append($2);
2210 $$->append(newNode(")", SQLNodeType::Punctuation));
2213 opt_existing_window_name:
2214 /* empty */ {$$ = SQL_NEW_RULE;}
2215 | existing_window_name
2217 opt_window_partition_clause:
2218 /* empty */ {$$ = SQL_NEW_RULE;}
2219 | window_partition_clause
2221 opt_window_frame_clause:
2222 /* empty */ {$$ = SQL_NEW_RULE;}
2223 | window_frame_clause
2225 window_specification_details:
2226 opt_existing_window_name
2227 opt_window_partition_clause
2228 opt_order_by_clause
2229 opt_window_frame_clause
2231 existing_window_name:
2232 window_name
2234 window_partition_clause:
2235 SQL_TOKEN_PARTITION SQL_TOKEN_BY window_partition_column_reference_list
2237 $$ = SQL_NEW_RULE;
2238 $$->append($1);
2239 $$->append($2);
2240 $$->append($3);
2243 window_partition_column_reference_list:
2244 window_partition_column_reference_list ',' window_partition_column_reference
2245 {$1->append($3);
2246 $$ = $1;}
2247 | window_partition_column_reference
2248 {$$ = SQL_NEW_COMMALISTRULE;
2249 $$->append($1);}
2251 window_partition_column_reference:
2252 column_ref opt_collate_clause
2254 $$ = SQL_NEW_RULE;
2255 $$->append($1);
2256 $$->append($2);
2259 opt_window_frame_exclusion:
2260 /* empty */ {$$ = SQL_NEW_RULE;}
2261 | window_frame_exclusion
2263 window_frame_clause:
2264 window_frame_units window_frame_extent opt_window_frame_exclusion
2266 $$ = SQL_NEW_RULE;
2267 $$->append($1);
2268 $$->append($2);
2269 $$->append($3);
2272 window_frame_units:
2273 SQL_TOKEN_ROWS
2274 | SQL_TOKEN_RANGE
2276 window_frame_extent:
2277 window_frame_start
2278 | window_frame_between
2280 window_frame_start:
2281 SQL_TOKEN_UNBOUNDED SQL_TOKEN_PRECEDING
2283 $$ = SQL_NEW_RULE;
2284 $$->append($1);
2285 $$->append($2);
2287 | window_frame_preceding
2288 | SQL_TOKEN_CURRENT SQL_TOKEN_ROW
2290 $$ = SQL_NEW_RULE;
2291 $$->append($1);
2292 $$->append($2);
2295 window_frame_preceding:
2296 unsigned_value_spec SQL_TOKEN_PRECEDING
2298 $$ = SQL_NEW_RULE;
2299 $$->append($1);
2300 $$->append($2);
2303 window_frame_between:
2304 SQL_TOKEN_BETWEEN window_frame_bound_1 SQL_TOKEN_AND window_frame_bound_2
2306 $$ = SQL_NEW_RULE;
2307 $$->append($1);
2308 $$->append($2);
2309 $$->append($3);
2310 $$->append($4);
2313 window_frame_bound_1:
2314 window_frame_bound
2316 window_frame_bound_2:
2317 window_frame_bound
2319 window_frame_bound:
2320 window_frame_start
2321 | SQL_TOKEN_UNBOUNDED SQL_TOKEN_FOLLOWING
2323 $$ = SQL_NEW_RULE;
2324 $$->append($1);
2325 $$->append($2);
2327 | window_frame_following
2329 window_frame_following:
2330 unsigned_value_spec SQL_TOKEN_FOLLOWING
2332 $$ = SQL_NEW_RULE;
2333 $$->append($1);
2334 $$->append($2);
2337 window_frame_exclusion:
2338 SQL_TOKEN_EXCLUDE SQL_TOKEN_CURRENT SQL_TOKEN_ROW
2340 $$ = SQL_NEW_RULE;
2341 $$->append($1);
2342 $$->append($2);
2343 $$->append($3);
2345 | SQL_TOKEN_EXCLUDE SQL_TOKEN_GROUP
2347 $$ = SQL_NEW_RULE;
2348 $$->append($1);
2349 $$->append($2);
2351 | SQL_TOKEN_EXCLUDE SQL_TOKEN_TIES
2353 $$ = SQL_NEW_RULE;
2354 $$->append($1);
2355 $$->append($2);
2357 | SQL_TOKEN_EXCLUDE SQL_TOKEN_NO SQL_TOKEN_OTHERS
2359 $$ = SQL_NEW_RULE;
2360 $$->append($1);
2361 $$->append($2);
2362 $$->append($3);
2365 op_parameter:
2366 {$$ = SQL_NEW_RULE;}
2367 | '?' SQL_EQUAL
2369 $$ = SQL_NEW_RULE;
2370 $$->append(newNode("?", SQLNodeType::Punctuation));
2371 $$->append($2);
2374 odbc_call_spec:
2375 op_parameter SQL_TOKEN_CALL table_node op_odbc_call_parameter
2377 $$ = SQL_NEW_RULE;
2378 $$->append($1);
2379 $$->append($2);
2380 $$->append($3);
2381 $$->append($4);
2385 op_odbc_call_parameter:
2386 {$$ = SQL_NEW_RULE;}
2387 | '(' odbc_parameter_commalist ')'
2389 $$ = SQL_NEW_RULE;
2390 $$->append(newNode("(", SQLNodeType::Punctuation));
2391 $$->append($2);
2392 $$->append(newNode(")", SQLNodeType::Punctuation));
2396 odbc_parameter_commalist:
2397 odbc_parameter
2398 {$$ = SQL_NEW_COMMALISTRULE;
2399 $$->append($1);}
2400 | odbc_parameter_commalist ',' odbc_parameter
2402 $1->append($3);
2403 $$ = $1;
2406 odbc_parameter:
2407 /* empty */ {$$ = SQL_NEW_RULE;}
2408 | literal
2409 | parameter
2412 odbc_fct_spec:
2413 odbc_fct_type SQL_TOKEN_STRING
2415 $$ = SQL_NEW_RULE;
2416 $$->append($1);
2417 $$->append($2);
2419 | SQL_TOKEN_FN set_fct_spec
2421 $$ = SQL_NEW_RULE;
2422 $$->append($1);
2423 $$->append($2);
2427 odbc_fct_type:
2428 SQL_TOKEN_D
2429 | SQL_TOKEN_T
2430 | SQL_TOKEN_TS
2433 general_set_fct:
2434 set_fct_type '(' opt_all_distinct function_arg ')'
2436 $$ = SQL_NEW_RULE;
2437 $$->append($1);
2438 $$->append(newNode("(", SQLNodeType::Punctuation));
2439 $$->append($3);
2440 $$->append($4);
2441 $$->append(newNode(")", SQLNodeType::Punctuation));
2443 | SQL_TOKEN_COUNT '(' '*' ')'
2445 $$ = SQL_NEW_RULE;
2446 $$->append($1);
2447 $$->append(newNode("(", SQLNodeType::Punctuation));
2448 $$->append(newNode("*", SQLNodeType::Punctuation));
2449 $$->append(newNode(")", SQLNodeType::Punctuation));
2451 | SQL_TOKEN_COUNT '(' opt_all_distinct function_arg ')'
2453 $$ = SQL_NEW_RULE;
2454 $$->append($1);
2455 $$->append(newNode("(", SQLNodeType::Punctuation));
2456 $$->append($3);
2457 $$->append($4);
2458 $$->append(newNode(")", SQLNodeType::Punctuation));
2460 | ordered_set_function
2461 | array_aggregate_function
2463 set_fct_type:
2464 SQL_TOKEN_AVG
2465 | SQL_TOKEN_MAX
2466 | SQL_TOKEN_MIN
2467 | SQL_TOKEN_SUM
2468 | SQL_TOKEN_EVERY
2469 | SQL_TOKEN_ANY
2470 | SQL_TOKEN_SOME
2471 | SQL_TOKEN_STDDEV_POP
2472 | SQL_TOKEN_STDDEV_SAMP
2473 | SQL_TOKEN_VAR_SAMP
2474 | SQL_TOKEN_VAR_POP
2475 | SQL_TOKEN_COLLECT
2476 | SQL_TOKEN_FUSION
2477 | SQL_TOKEN_INTERSECTION
2480 ordered_set_function:
2481 hypothetical_set_function
2482 | inverse_distribution_function
2484 hypothetical_set_function:
2485 rank_function_type '(' hypothetical_set_function_value_expression_list ')' within_group_specification
2487 $$ = SQL_NEW_RULE;
2488 $$->append($1);
2489 $$->append(newNode("(", SQLNodeType::Punctuation));
2490 $$->append($3);
2491 $$->append(newNode(")", SQLNodeType::Punctuation));
2492 $$->append($5);
2494 | rank_function_type '(' hypothetical_set_function_value_expression_list SQL_TOKEN_BY value_exp_commalist ')' within_group_specification
2496 $$ = SQL_NEW_RULE;
2497 $$->append($1);
2498 $$->append(newNode("(", SQLNodeType::Punctuation));
2499 $$->append($3);
2500 $$->append($4);
2501 $$->append($5);
2502 $$->append(newNode(")", SQLNodeType::Punctuation));
2503 $$->append($7);
2507 within_group_specification:
2509 $$ = SQL_NEW_RULE;
2511 | SQL_TOKEN_WITHIN SQL_TOKEN_GROUP '(' opt_order_by_clause ')'
2513 $$ = SQL_NEW_RULE;
2514 $$->append($1);
2515 $$->append($2);
2516 $$->append(newNode("(", SQLNodeType::Punctuation));
2517 $$->append($4);
2518 $$->append(newNode(")", SQLNodeType::Punctuation));
2521 hypothetical_set_function_value_expression_list:
2522 value_exp_commalist
2525 inverse_distribution_function:
2526 inverse_distribution_function_type '('inverse_distribution_function_argument ')' within_group_specification
2528 $$ = SQL_NEW_RULE;
2529 $$->append($1);
2530 $$->append(newNode("(", SQLNodeType::Punctuation));
2531 $$->append($3);
2532 $$->append(newNode(")", SQLNodeType::Punctuation));
2535 inverse_distribution_function_argument:
2536 num_value_exp
2538 inverse_distribution_function_type:
2539 SQL_TOKEN_PERCENTILE_CONT
2540 | SQL_TOKEN_PERCENTILE_DISC
2543 array_aggregate_function:
2544 SQL_TOKEN_ARRAY_AGG '(' value_exp opt_order_by_clause ')'
2546 $$ = SQL_NEW_RULE;
2547 $$->append($1);
2548 $$->append(newNode("(", SQLNodeType::Punctuation));
2549 $$->append($3);
2550 $$->append($4);
2551 $$->append(newNode(")", SQLNodeType::Punctuation));
2555 rank_function_type:
2556 SQL_TOKEN_RANK
2557 | SQL_TOKEN_DENSE_RANK
2558 | SQL_TOKEN_PERCENT_RANK
2559 | SQL_TOKEN_CUME_DIST
2561 outer_join_type:
2562 SQL_TOKEN_LEFT %prec SQL_TOKEN_LEFT
2564 $$ = SQL_NEW_RULE;
2565 $$->append($1);
2567 | SQL_TOKEN_RIGHT %prec SQL_TOKEN_RIGHT
2569 $$ = SQL_NEW_RULE;
2570 $$->append($1);
2572 | SQL_TOKEN_FULL %prec SQL_TOKEN_FULL
2574 $$ = SQL_NEW_RULE;
2575 $$->append($1);
2578 join_condition:
2579 SQL_TOKEN_ON search_condition
2581 $$ = SQL_NEW_RULE;
2582 $$->append($1);
2583 $$->append($2);
2586 join_spec:
2587 join_condition
2588 | named_columns_join
2590 join_type:
2591 /* empty */ {$$ = SQL_NEW_RULE;}
2592 | SQL_TOKEN_INNER
2594 $$ = SQL_NEW_RULE;
2595 $$->append($1);
2597 | outer_join_type
2598 | outer_join_type SQL_TOKEN_OUTER
2600 $$ = SQL_NEW_RULE;
2601 $$->append($1);
2602 $$->append($2);
2605 cross_union:
2606 table_ref SQL_TOKEN_CROSS SQL_TOKEN_JOIN table_ref
2608 $$ = SQL_NEW_RULE;
2609 $$->append($1);
2610 $$->append($2);
2611 $$->append($3);
2612 $$->append($4);
2616 qualified_join:
2617 /* when SQL_TOKEN_NATURAL, then no join_spec */
2618 table_ref SQL_TOKEN_NATURAL join_type SQL_TOKEN_JOIN table_ref
2620 $$ = SQL_NEW_RULE;
2621 $$->append($1);
2622 $$->append($2);
2623 $$->append($3);
2624 $$->append($4);
2625 $$->append($5);
2627 | table_ref join_type SQL_TOKEN_JOIN table_ref join_spec
2629 $$ = SQL_NEW_RULE;
2630 $$->append($1);
2631 $$->append($2);
2632 $$->append($3);
2633 $$->append($4);
2634 $$->append($5);
2636 | cross_union
2638 joined_table:
2639 qualified_join
2641 named_columns_join:
2642 SQL_TOKEN_USING '(' column_commalist ')'
2644 $$ = SQL_NEW_RULE;
2645 $$->append($1);
2646 $$->append(newNode("(", SQLNodeType::Punctuation));
2647 $$->append($3);
2648 $$->append(newNode(")", SQLNodeType::Punctuation));
2651 simple_table:
2652 select_statement
2653 | values_or_query_spec
2656 non_join_query_primary:
2657 simple_table
2658 | '(' non_join_query_exp ')'
2660 $$ = SQL_NEW_RULE;
2661 $$->append(newNode("(", SQLNodeType::Punctuation));
2662 $$->append($2);
2663 $$->append(newNode(")", SQLNodeType::Punctuation));
2666 non_join_query_term:
2667 non_join_query_primary
2668 | query_term SQL_TOKEN_INTERSECT all query_primary
2670 $$ = SQL_NEW_RULE;
2671 $$->append($1);
2672 $$->append($2);
2673 $$->append($3);
2674 $$->append($4);
2677 query_primary:
2678 non_join_query_primary
2680 non_join_query_exp:
2681 non_join_query_term
2682 | query_exp SQL_TOKEN_UNION all query_term
2684 $$ = SQL_NEW_RULE;
2685 $$->append($1);
2686 $$->append($2);
2687 $$->append($3);
2688 $$->append($4);
2690 | query_exp SQL_TOKEN_EXCEPT all query_term
2692 $$ = SQL_NEW_RULE;
2693 $$->append($1);
2694 $$->append($2);
2695 $$->append($3);
2696 $$->append($4);
2699 all:
2700 /* empty*/ {$$ = SQL_NEW_RULE;}
2701 | SQL_TOKEN_ALL
2703 query_exp:
2704 non_join_query_exp /*[^')']*/
2706 scalar_subquery:
2707 subquery
2709 cast_operand:
2710 value_exp
2712 cast_target:
2713 table_node
2714 | data_type
2716 cast_spec:
2717 SQL_TOKEN_CAST '(' cast_operand SQL_TOKEN_AS cast_target ')'
2719 $$ = SQL_NEW_RULE;
2720 $$->append($1);
2721 $$->append(newNode("(", SQLNodeType::Punctuation));
2722 $$->append($3);
2723 $$->append($4);
2724 $$->append($5);
2725 $$->append(newNode(")", SQLNodeType::Punctuation));
2728 value_exp_primary:
2729 unsigned_value_spec
2730 | column_ref
2731 | set_fct_spec
2732 | scalar_subquery
2733 | case_expression
2734 | window_function
2735 | '(' value_exp ')'
2737 $$ = SQL_NEW_RULE;
2738 $$->append(newNode("(", SQLNodeType::Punctuation));
2739 $$->append($2);
2740 $$->append(newNode(")", SQLNodeType::Punctuation));
2742 | cast_spec
2745 num_primary:
2746 value_exp_primary
2747 | num_value_fct
2749 factor:
2750 num_primary
2751 | '-' num_primary %prec SQL_TOKEN_UMINUS
2753 $$ = SQL_NEW_RULE;
2754 $$->append(newNode("-", SQLNodeType::Punctuation));
2755 $$->append($2);
2757 | '+' num_primary %prec SQL_TOKEN_UMINUS
2759 $$ = SQL_NEW_RULE;
2760 $$->append(newNode("+", SQLNodeType::Punctuation));
2761 $$->append($2);
2765 term:
2766 factor
2767 | term '*' factor
2769 $$ = SQL_NEW_RULE;
2770 $$->append($1);
2771 $$->append(newNode("*", SQLNodeType::Punctuation));
2772 $$->append($3);
2774 | term '/' factor
2776 $$ = SQL_NEW_RULE;
2777 $$->append($1);
2778 $$->append(newNode("/", SQLNodeType::Punctuation));
2779 $$->append($3);
2783 num_value_exp:
2784 term
2785 | num_value_exp '+' term
2787 $$ = SQL_NEW_RULE;
2788 $$->append($1);
2789 $$->append(newNode("+", SQLNodeType::Punctuation));
2790 $$->append($3);
2792 | num_value_exp '-' term
2794 $$ = SQL_NEW_RULE;
2795 $$->append($1);
2796 $$->append(newNode("-", SQLNodeType::Punctuation));
2797 $$->append($3);
2800 datetime_primary:
2801 /* value_exp_primary
2803 $$ = SQL_NEW_RULE;
2804 $$->append($1);
2806 |*/ datetime_value_fct
2808 $$ = SQL_NEW_RULE;
2809 $$->append($1);
2812 datetime_value_fct:
2813 SQL_TOKEN_CURRENT_DATE
2815 $$ = SQL_NEW_RULE;
2816 $$->append($1);
2818 | SQL_TOKEN_CURRENT_TIME
2820 $$ = SQL_NEW_RULE;
2821 $$->append($1);
2823 | SQL_TOKEN_CURRENT_TIMESTAMP
2825 $$ = SQL_NEW_RULE;
2826 $$->append($1);
2829 time_zone:
2830 SQL_TOKEN_AT time_zone_specifier
2832 $$ = SQL_NEW_RULE;
2833 $$->append($1);
2834 $$->append($2);
2837 time_zone_specifier:
2838 SQL_TOKEN_LOCAL
2840 $$ = SQL_NEW_RULE;
2841 $$->append($1);
2843 /* | SQL_TOKEN_TIME SQL_TOKEN_ZONE interval_value_exp
2845 $$ = SQL_NEW_RULE;
2846 $$->append($1);
2847 $$->append($2);
2848 $$->append($3);
2851 datetime_factor:
2852 datetime_primary
2854 $$ = SQL_NEW_RULE;
2855 $$->append($1);
2857 | datetime_primary time_zone
2859 $$ = SQL_NEW_RULE;
2860 $$->append($1);
2861 $$->append($2);
2864 datetime_term:
2865 datetime_factor
2867 $$ = SQL_NEW_RULE;
2868 $$->append($1);
2872 interval_term:
2873 literal
2874 | interval_term '*' factor
2876 $$ = SQL_NEW_RULE;
2877 $$->append($1);
2878 $$->append(newNode("*", SQLNodeType::Punctuation));
2879 $$->append($3);
2881 | interval_term '/' factor
2883 $$ = SQL_NEW_RULE;
2884 $$->append($1);
2885 $$->append(newNode("/", SQLNodeType::Punctuation));
2886 $$->append($3);
2890 datetime_value_exp:
2891 datetime_term
2893 $$ = SQL_NEW_RULE;
2894 $$->append($1);
2896 /* | interval_value_exp '+' datetime_term
2898 $$ = SQL_NEW_RULE;
2899 $$->append($1);
2900 $$->append(newNode("+", SQLNodeType::Punctuation));
2901 $$->append($3);
2903 | datetime_value_exp '+' interval_term
2905 $$ = SQL_NEW_RULE;
2906 $$->append($1);
2907 $$->append(newNode("+", SQLNodeType::Punctuation));
2908 $$->append($3);
2910 | datetime_value_exp '-' interval_term
2912 $$ = SQL_NEW_RULE;
2913 $$->append($1);
2914 $$->append(newNode("-", SQLNodeType::Punctuation));
2915 $$->append($3);
2917 */ ;
2919 interval_value_exp:
2920 interval_term
2922 $$ = SQL_NEW_RULE;
2923 $$->append($1);
2925 | interval_value_exp '+' interval_term
2927 $$ = SQL_NEW_RULE;
2928 $$->append($1);
2929 $$->append(newNode("+", SQLNodeType::Punctuation));
2930 $$->append($3);
2932 | interval_value_exp '-' interval_term
2934 $$ = SQL_NEW_RULE;
2935 $$->append($1);
2936 $$->append(newNode("-", SQLNodeType::Punctuation));
2937 $$->append($3);
2939 | '(' datetime_value_exp '-' datetime_term ')' interval_qualifier
2941 $$ = SQL_NEW_RULE;
2942 $$->append(newNode("(", SQLNodeType::Punctuation));
2943 $$->append($2);
2944 $$->append(newNode("-", SQLNodeType::Punctuation));
2945 $$->append($4);
2946 $$->append(newNode(")", SQLNodeType::Punctuation));
2947 $$->append($6);
2951 non_second_datetime_field:
2952 SQL_TOKEN_YEAR
2953 | SQL_TOKEN_MONTH
2954 | SQL_TOKEN_DAY
2955 | SQL_TOKEN_HOUR
2956 | SQL_TOKEN_MINUTE
2958 start_field:
2959 non_second_datetime_field opt_paren_precision
2961 $$ = SQL_NEW_RULE;
2962 $$->append($1);
2963 $$->append($2);
2966 end_field:
2967 non_second_datetime_field
2968 | SQL_TOKEN_SECOND opt_paren_precision
2970 $$ = SQL_NEW_RULE;
2971 $$->append($1);
2972 $$->append($2);
2976 single_datetime_field:
2977 non_second_datetime_field opt_paren_precision
2979 $$ = SQL_NEW_RULE;
2980 $$->append($1);
2981 $$->append($2);
2983 | SQL_TOKEN_SECOND opt_paren_precision_scale
2985 $$ = SQL_NEW_RULE;
2986 $$->append($1);
2987 $$->append($2);
2991 interval_qualifier:
2992 start_field SQL_TOKEN_TO end_field
2994 $$ = SQL_NEW_RULE;
2995 $$->append($1);
2996 $$->append($2);
2997 $$->append($3);
2999 | single_datetime_field
3002 function_arg_commalist2:
3003 function_arg ',' function_arg
3004 {$$ = SQL_NEW_COMMALISTRULE;
3005 $$->append($1);
3006 $$->append($3);}
3008 function_arg_commalist3:
3009 function_arg ',' function_arg ',' function_arg
3011 $$ = SQL_NEW_COMMALISTRULE;
3012 $$->append($1);
3013 $$->append($3);
3014 $$->append($5);
3017 function_arg_commalist4:
3018 function_arg ',' function_arg ',' function_arg ',' function_arg
3020 $$ = SQL_NEW_COMMALISTRULE;
3021 $$->append($1);
3022 $$->append($3);
3023 $$->append($5);
3024 $$->append($7);
3027 value_exp_commalist:
3028 value_exp
3029 {$$ = SQL_NEW_COMMALISTRULE;
3030 $$->append($1);}
3031 | value_exp_commalist ',' value_exp
3032 {$1->append($3);
3033 $$ = $1;}
3034 /* this rule is only valid if we check predicates */
3035 | value_exp_commalist ';' value_exp
3037 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
3039 $1->append($3);
3040 $$ = $1;
3042 else
3043 YYERROR;
3046 function_arg:
3047 result
3048 | value_exp comparison value_exp
3050 $$ = SQL_NEW_RULE;
3051 $$->append($1);
3052 $$->append($2);
3053 $$->append($3);
3055 | value_exp SQL_TOKEN_USING value_exp comparison value_exp
3057 $$ = SQL_NEW_RULE;
3058 $$->append($1);
3059 $$->append($2);
3060 $$->append($3);
3061 $$->append($4);
3063 | value_exp SQL_TOKEN_BY value_exp_commalist
3065 $$ = SQL_NEW_RULE;
3066 $$->append($1);
3067 $$->append($2);
3068 $$->append($3);
3071 function_args_commalist:
3072 function_arg
3073 {$$ = SQL_NEW_COMMALISTRULE;
3074 $$->append($1);}
3075 | function_args_commalist ',' function_arg
3076 {$1->append($3);
3077 $$ = $1;}
3078 /* this rule is only valid if we check predicates */
3079 | function_args_commalist ';' function_arg
3081 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
3083 $1->append($3);
3084 $$ = $1;
3086 else
3087 YYERROR;
3091 value_exp:
3092 num_value_exp /*[^')']*/
3093 | string_value_exp
3094 | datetime_value_exp
3096 $$ = SQL_NEW_RULE;
3097 $$->append($1);
3100 string_value_exp:
3101 char_value_exp
3102 /* | bit_value_exp
3104 $$ = SQL_NEW_RULE;
3105 $$->append($1);
3107 */ ;
3108 char_value_exp:
3109 char_factor
3110 | concatenation
3112 concatenation:
3113 char_value_exp '+' char_factor
3115 $$ = SQL_NEW_RULE;
3116 $$->append($1);
3117 $$->append(newNode("+", SQLNodeType::Punctuation));
3118 $$->append($3);
3120 | value_exp SQL_CONCAT value_exp
3122 $$ = SQL_NEW_RULE;
3123 $$->append($1);
3124 $$->append($2);
3125 $$->append($3);
3129 char_primary:
3130 SQL_TOKEN_STRING
3131 | string_value_fct
3133 collate_clause:
3134 SQL_TOKEN_COLLATE table_node
3136 $$ = SQL_NEW_RULE;
3137 $$->append($1);
3138 $$->append($2);
3141 char_factor:
3142 char_primary
3143 | char_primary collate_clause
3145 $$ = SQL_NEW_RULE;
3146 $$->append($1);
3147 $$->append($2);
3150 string_value_fct:
3151 char_value_fct
3152 | bit_value_fct
3154 bit_value_fct:
3155 bit_substring_fct
3157 $$ = SQL_NEW_RULE;
3158 $$->append($1);
3161 bit_substring_fct:
3162 SQL_TOKEN_SUBSTRING '(' bit_value_exp SQL_TOKEN_FROM string_value_exp for_length ')'
3164 $$ = SQL_NEW_RULE;
3165 $$->append($1);
3166 $$->append(newNode("(", SQLNodeType::Punctuation));
3167 $$->append($3);
3168 $$->append($4);
3169 $$->append($5);
3170 $$->append($6);
3171 $$->append(newNode(")", SQLNodeType::Punctuation));
3174 bit_value_exp:
3175 bit_factor
3177 $$ = SQL_NEW_RULE;
3178 $$->append($1);
3182 bit_concatenation
3184 $$ = SQL_NEW_RULE;
3185 $$->append($1);
3188 bit_concatenation:
3189 bit_value_exp '+' bit_factor
3191 $$ = SQL_NEW_RULE;
3192 $$->append($1);
3193 $$->append(newNode("+", SQLNodeType::Punctuation));
3194 $$->append($3);
3198 bit_factor:
3199 bit_primary
3201 $$ = SQL_NEW_RULE;
3202 $$->append($1);
3205 bit_primary:
3206 {$$ = SQL_NEW_RULE;}
3207 /* value_exp_primary
3209 $$ = SQL_NEW_RULE;
3210 $$->append($1);
3212 | string_value_fct
3214 $$ = SQL_NEW_RULE;
3215 $$->append($1);
3218 char_value_fct:
3219 char_substring_fct
3220 | fold
3221 | form_conversion
3223 $$ = SQL_NEW_RULE;
3224 $$->append($1);
3226 | char_translation
3228 $$ = SQL_NEW_RULE;
3229 $$->append($1);
3231 | trim_fct
3233 $$ = SQL_NEW_RULE;
3234 $$->append($1);
3237 for_length:
3238 {$$ = SQL_NEW_RULE;}
3239 | SQL_TOKEN_FOR value_exp
3241 $$ = SQL_NEW_RULE;
3242 $$->append($1);
3243 $$->append($2);
3246 char_substring_fct:
3247 SQL_TOKEN_SUBSTRING '(' value_exp SQL_TOKEN_FROM value_exp for_length ')'
3249 $$ = SQL_NEW_RULE;
3250 $$->append($1);
3251 $$->append(newNode("(", SQLNodeType::Punctuation));
3252 $$->append($3);
3253 $$->append($4);
3254 $$->append($5);
3255 $$->append($6);
3256 $$->append(newNode(")", SQLNodeType::Punctuation));
3258 | SQL_TOKEN_SUBSTRING '(' value_exp_commalist ')'
3260 $$ = SQL_NEW_RULE;
3261 $$->append($1);
3262 $$->append(newNode("(", SQLNodeType::Punctuation));
3263 $$->append($3);
3264 $$->append(newNode(")", SQLNodeType::Punctuation));
3267 upper_lower:
3268 SQL_TOKEN_UPPER
3269 | SQL_TOKEN_LOWER
3271 fold:
3272 upper_lower '(' value_exp ')'
3274 $$ = SQL_NEW_RULE;
3275 $$->append($1);
3276 $$->append(newNode("(", SQLNodeType::Punctuation));
3277 $$->append($3);
3278 $$->append(newNode(")", SQLNodeType::Punctuation));
3281 form_conversion:
3282 SQL_TOKEN_CONVERT '(' string_value_exp SQL_TOKEN_USING table_node ')'
3284 $$ = SQL_NEW_RULE;
3285 $$->append($1);
3286 $$->append(newNode("(", SQLNodeType::Punctuation));
3287 $$->append($3);
3288 $$->append($4);
3289 $$->append($5);
3290 $$->append(newNode(")", SQLNodeType::Punctuation));
3292 | SQL_TOKEN_CONVERT '(' cast_operand ',' cast_target ')'
3294 $$ = SQL_NEW_RULE;
3295 $$->append($1);
3296 $$->append(newNode("(", SQLNodeType::Punctuation));
3297 $$->append($3);
3298 $$->append(newNode(",", SQLNodeType::Punctuation));
3299 $$->append($5);
3300 $$->append(newNode(")", SQLNodeType::Punctuation));
3303 char_translation:
3304 SQL_TOKEN_TRANSLATE '(' string_value_exp SQL_TOKEN_USING table_node ')'
3306 $$ = SQL_NEW_RULE;
3307 $$->append($1);
3308 $$->append(newNode("(", SQLNodeType::Punctuation));
3309 $$->append($3);
3310 $$->append($4);
3311 $$->append($5);
3312 $$->append(newNode(")", SQLNodeType::Punctuation));
3315 trim_fct:
3316 SQL_TOKEN_TRIM '(' trim_operands ')'
3318 $$ = SQL_NEW_RULE;
3319 $$->append($1);
3320 $$->append(newNode("(", SQLNodeType::Punctuation));
3321 $$->append($3);
3322 $$->append(newNode(")", SQLNodeType::Punctuation));
3325 trim_operands:
3326 trim_spec value_exp SQL_TOKEN_FROM value_exp
3328 $$ = SQL_NEW_RULE;
3329 $$->append($1);
3330 $$->append($2);
3331 $$->append($3);
3332 $$->append($4);
3334 | trim_spec SQL_TOKEN_FROM value_exp
3336 $$ = SQL_NEW_RULE;
3337 $$->append($1);
3338 $$->append($2);
3339 $$->append($3);
3341 | value_exp SQL_TOKEN_FROM value_exp
3343 $$ = SQL_NEW_RULE;
3344 $$->append($1);
3345 $$->append($2);
3346 $$->append($3);
3348 | SQL_TOKEN_FROM value_exp
3350 $$ = SQL_NEW_RULE;
3351 $$->append($1);
3352 $$->append($2);
3354 | value_exp
3357 trim_spec:
3358 SQL_TOKEN_BOTH
3359 | SQL_TOKEN_LEADING
3360 | SQL_TOKEN_TRAILING
3363 derived_column:
3364 value_exp as_clause
3366 $$ = SQL_NEW_RULE;
3367 $$->append($1);
3368 $$->append($2);
3371 /* Tabellenname */
3372 table_node:
3373 table_name
3374 | schema_name
3375 | catalog_name
3377 catalog_name:
3378 SQL_TOKEN_NAME '.' schema_name
3380 $$ = SQL_NEW_RULE;
3381 $$->append($1);
3382 $$->append(newNode(".", SQLNodeType::Punctuation));
3383 $$->append($3);
3385 | SQL_TOKEN_NAME ':' schema_name
3387 $$ = SQL_NEW_RULE;
3388 $$->append($1);
3389 $$->append(newNode(":", SQLNodeType::Punctuation));
3390 $$->append($3);
3393 schema_name:
3394 SQL_TOKEN_NAME '.' table_name
3396 $$ = SQL_NEW_RULE;
3397 $$->append($1);
3398 $$->append(newNode(".", SQLNodeType::Punctuation));
3399 $$->append($3);
3403 table_name:
3404 SQL_TOKEN_NAME
3405 {$$ = SQL_NEW_RULE;
3406 $$->append($1);}
3408 /* Columns */
3409 column_ref:
3410 column
3411 {$$ = SQL_NEW_RULE;
3412 $$->append($1);}
3413 /* | table_node '.' column_val %prec '.'
3414 {$$ = SQL_NEW_RULE;
3415 $$->append($1);
3416 $$->append(newNode(".", SQLNodeType::Punctuation));
3417 $$->append($3);}
3419 | SQL_TOKEN_NAME '.' column_val %prec '.'
3420 {$$ = SQL_NEW_RULE;
3421 $$->append($1);
3422 $$->append(newNode(".", SQLNodeType::Punctuation));
3423 $$->append($3);
3425 | SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val %prec '.'
3426 {$$ = SQL_NEW_RULE;
3427 $$->append($1);
3428 $$->append(newNode(".", SQLNodeType::Punctuation));
3429 $$->append($3);
3430 $$->append(newNode(".", SQLNodeType::Punctuation));
3431 $$->append($5);}
3432 | SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val %prec '.'
3433 {$$ = SQL_NEW_RULE;
3434 $$->append($1);
3435 $$->append(newNode(".", SQLNodeType::Punctuation));
3436 $$->append($3);
3437 $$->append(newNode(".", SQLNodeType::Punctuation));
3438 $$->append($5);
3439 $$->append(newNode(".", SQLNodeType::Punctuation));
3440 $$->append($7);
3442 | SQL_TOKEN_NAME ':' SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val %prec '.'
3443 {$$ = SQL_NEW_RULE;
3444 $$->append($1);
3445 $$->append(newNode(":", SQLNodeType::Punctuation));
3446 $$->append($3);
3447 $$->append(newNode(".", SQLNodeType::Punctuation));
3448 $$->append($5);
3449 $$->append(newNode(".", SQLNodeType::Punctuation));
3450 $$->append($7);
3452 /* | SQL_TOKEN_NAME ';' SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val
3453 {$$ = SQL_NEW_RULE;
3454 $$->append($1);
3455 $$->append(newNode(";", SQLNodeType::Punctuation));
3456 $$->append($3);
3457 $$->append(newNode(".", SQLNodeType::Punctuation));
3458 $$->append($5);
3459 $$->append(newNode(".", SQLNodeType::Punctuation));
3460 $$->append($7);
3462 */ ;
3464 /* data types */
3465 column_val:
3466 column
3467 {$$ = SQL_NEW_RULE;
3468 $$->append($1);}
3469 | '*'
3471 $$ = SQL_NEW_RULE;
3472 $$->append(newNode("*", SQLNodeType::Punctuation));
3475 data_type:
3476 predefined_type
3478 opt_char_set_spec:
3479 {$$ = SQL_NEW_RULE;}
3480 | SQL_TOKEN_CHARACTER SQL_TOKEN_SET SQL_TOKEN_NAME
3482 $$ = SQL_NEW_RULE;
3483 $$->append($1);
3484 $$->append($2);
3485 $$->append($3);
3488 opt_collate_clause:
3489 {$$ = SQL_NEW_RULE;}
3490 | collate_clause
3492 predefined_type:
3493 character_string_type opt_char_set_spec opt_collate_clause
3495 $$ = SQL_NEW_RULE;
3496 $$->append($1);
3497 $$->append($2);
3498 $$->append($3);
3500 | national_character_string_type opt_collate_clause
3502 $$ = SQL_NEW_RULE;
3503 $$->append($1);
3504 $$->append($2);
3506 | binary_string_type
3507 | numeric_type
3508 | boolean_type
3509 | datetime_type
3510 | interval_type
3512 character_string_type:
3513 SQL_TOKEN_CHARACTER opt_paren_precision
3515 $$ = SQL_NEW_RULE;
3516 $$->append($1);
3517 $$->append($2);
3519 | SQL_TOKEN_CHAR opt_paren_precision
3521 $$ = SQL_NEW_RULE;
3522 $$->append($1);
3523 $$->append($2);
3525 | SQL_TOKEN_CHARACTER SQL_TOKEN_VARYING paren_char_length
3527 $$ = SQL_NEW_RULE;
3528 $$->append($1);
3529 $$->append($2);
3530 $$->append($3);
3532 | SQL_TOKEN_CHAR SQL_TOKEN_VARYING paren_char_length
3534 $$ = SQL_NEW_RULE;
3535 $$->append($1);
3536 $$->append($2);
3537 $$->append($3);
3539 | SQL_TOKEN_VARCHAR paren_char_length
3541 $$ = SQL_NEW_RULE;
3542 $$->append($1);
3543 $$->append($2);
3545 | character_large_object_type
3547 opt_paren_precision:
3548 {$$ = SQL_NEW_RULE;}
3549 | paren_char_length
3551 paren_char_length:
3552 '(' SQL_TOKEN_INTNUM ')'
3554 $$ = SQL_NEW_RULE;
3555 $$->append(newNode("(", SQLNodeType::Punctuation));
3556 $$->append($2);
3557 $$->append(newNode(")", SQLNodeType::Punctuation));
3560 opt_paren_char_large_length:
3561 {$$ = SQL_NEW_RULE;}
3562 | paren_character_large_object_length
3564 paren_character_large_object_length:
3565 '(' large_object_length ')'
3567 $$ = SQL_NEW_RULE;
3568 $$->append(newNode("(", SQLNodeType::Punctuation));
3569 $$->append($2);
3570 $$->append(newNode(")", SQLNodeType::Punctuation));
3574 large_object_length:
3575 SQL_TOKEN_INTNUM opt_multiplier
3577 $$ = SQL_NEW_RULE;
3578 $$->append($1);
3579 $$->append($2);
3582 opt_multiplier:
3583 {$$ = SQL_NEW_RULE;}
3584 | 'K'
3586 $$ = SQL_NEW_RULE;
3587 $$->append(newNode("K", SQLNodeType::Punctuation));
3589 | 'M'
3591 $$ = SQL_NEW_RULE;
3592 $$->append(newNode("M", SQLNodeType::Punctuation));
3594 | 'G'
3596 $$ = SQL_NEW_RULE;
3597 $$->append(newNode("G", SQLNodeType::Punctuation));
3599 | 'T'
3601 $$ = SQL_NEW_RULE;
3602 $$->append(newNode("T", SQLNodeType::Punctuation));
3604 | 'P'
3606 $$ = SQL_NEW_RULE;
3607 $$->append(newNode("P", SQLNodeType::Punctuation));
3610 character_large_object_type:
3611 SQL_TOKEN_CHARACTER SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3613 $$ = SQL_NEW_RULE;
3614 $$->append($1);
3615 $$->append($2);
3616 $$->append($3);
3617 $$->append($4);
3619 | SQL_TOKEN_CHAR SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3621 $$ = SQL_NEW_RULE;
3622 $$->append($1);
3623 $$->append($2);
3624 $$->append($3);
3625 $$->append($4);
3627 | SQL_TOKEN_CLOB opt_paren_char_large_length
3629 $$ = SQL_NEW_RULE;
3630 $$->append($1);
3631 $$->append($2);
3634 national_character_string_type:
3635 SQL_TOKEN_NATIONAL SQL_TOKEN_CHARACTER opt_paren_precision
3637 $$ = SQL_NEW_RULE;
3638 $$->append($1);
3639 $$->append($2);
3640 $$->append($3);
3642 | SQL_TOKEN_NATIONAL SQL_TOKEN_CHAR opt_paren_precision
3644 $$ = SQL_NEW_RULE;
3645 $$->append($1);
3646 $$->append($2);
3647 $$->append($3);
3649 | SQL_TOKEN_NCHAR opt_paren_precision
3651 $$ = SQL_NEW_RULE;
3652 $$->append($1);
3653 $$->append($2);
3655 | SQL_TOKEN_NATIONAL SQL_TOKEN_CHARACTER SQL_TOKEN_VARYING paren_char_length
3657 $$ = SQL_NEW_RULE;
3658 $$->append($1);
3659 $$->append($2);
3660 $$->append($3);
3661 $$->append($4);
3663 | SQL_TOKEN_NATIONAL SQL_TOKEN_CHAR SQL_TOKEN_VARYING paren_char_length
3665 $$ = SQL_NEW_RULE;
3666 $$->append($1);
3667 $$->append($2);
3668 $$->append($3);
3669 $$->append($4);
3671 | SQL_TOKEN_NCHAR SQL_TOKEN_VARYING paren_char_length
3673 $$ = SQL_NEW_RULE;
3674 $$->append($1);
3675 $$->append($2);
3676 $$->append($3);
3678 | national_character_large_object_type
3680 national_character_large_object_type:
3681 SQL_TOKEN_NATIONAL SQL_TOKEN_CHARACTER SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3683 $$ = SQL_NEW_RULE;
3684 $$->append($1);
3685 $$->append($2);
3686 $$->append($3);
3687 $$->append($4);
3688 $$->append($5);
3690 | SQL_TOKEN_NCHAR SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3692 $$ = SQL_NEW_RULE;
3693 $$->append($1);
3694 $$->append($2);
3695 $$->append($3);
3696 $$->append($4);
3698 | SQL_TOKEN_NCLOB opt_paren_char_large_length
3700 $$ = SQL_NEW_RULE;
3701 $$->append($1);
3702 $$->append($2);
3705 binary_string_type:
3706 SQL_TOKEN_BINARY opt_paren_precision
3708 $$ = SQL_NEW_RULE;
3709 $$->append($1);
3710 $$->append($2);
3712 | SQL_TOKEN_BINARY SQL_TOKEN_VARYING paren_char_length
3714 $$ = SQL_NEW_RULE;
3715 $$->append($1);
3716 $$->append($2);
3717 $$->append($3);
3719 | SQL_TOKEN_VARBINARY paren_char_length
3721 $$ = SQL_NEW_RULE;
3722 $$->append($1);
3723 $$->append($2);
3725 | binary_large_object_string_type
3727 binary_large_object_string_type:
3728 SQL_TOKEN_BINARY SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3730 $$ = SQL_NEW_RULE;
3731 $$->append($1);
3732 $$->append($2);
3733 $$->append($3);
3734 $$->append($4);
3736 | SQL_TOKEN_BLOB opt_paren_char_large_length
3738 $$ = SQL_NEW_RULE;
3739 $$->append($1);
3740 $$->append($2);
3743 numeric_type:
3744 exact_numeric_type
3745 | approximate_numeric_type
3747 opt_paren_precision_scale:
3748 {$$ = SQL_NEW_RULE;}
3749 | '(' SQL_TOKEN_INTNUM ')'
3751 $$ = SQL_NEW_RULE;
3752 $$->append(newNode("(", SQLNodeType::Punctuation));
3753 $$->append($2);
3754 $$->append(newNode(")", SQLNodeType::Punctuation));
3756 | '(' SQL_TOKEN_INTNUM ',' SQL_TOKEN_INTNUM ')'
3758 $$ = SQL_NEW_RULE;
3759 $$->append(newNode("(", SQLNodeType::Punctuation));
3760 $$->append($2);
3761 $$->append(newNode(",", SQLNodeType::Punctuation));
3762 $$->append($4);
3763 $$->append(newNode(")", SQLNodeType::Punctuation));
3766 exact_numeric_type:
3767 SQL_TOKEN_NUMERIC opt_paren_precision_scale
3769 $$ = SQL_NEW_RULE;
3770 $$->append($1);
3771 $$->append($2);
3773 | SQL_TOKEN_DECIMAL opt_paren_precision_scale
3775 $$ = SQL_NEW_RULE;
3776 $$->append($1);
3777 $$->append($2);
3779 | SQL_TOKEN_DEC opt_paren_precision_scale
3781 $$ = SQL_NEW_RULE;
3782 $$->append($1);
3783 $$->append($2);
3785 | SQL_TOKEN_SMALLINT
3786 | SQL_TOKEN_INTEGER
3787 | SQL_TOKEN_INT
3788 | SQL_TOKEN_BIGINT
3790 approximate_numeric_type:
3791 SQL_TOKEN_FLOAT '(' SQL_TOKEN_INTNUM ')'
3793 $$ = SQL_NEW_RULE;
3794 $$->append($1);
3795 $$->append(newNode("(", SQLNodeType::Punctuation));
3796 $$->append($3);
3797 $$->append(newNode(")", SQLNodeType::Punctuation));
3799 | SQL_TOKEN_FLOAT
3800 | SQL_TOKEN_REAL
3801 | SQL_TOKEN_DOUBLE
3802 | SQL_TOKEN_DOUBLE SQL_TOKEN_PRECISION
3804 $$ = SQL_NEW_RULE;
3805 $$->append($1);
3806 $$->append($2);
3809 boolean_type:
3810 SQL_TOKEN_BOOLEAN
3812 datetime_type:
3813 SQL_TOKEN_DATE
3814 | SQL_TOKEN_TIME opt_paren_precision opt_with_or_without_time_zone
3816 $$ = SQL_NEW_RULE;
3817 $$->append($1);
3818 $$->append($2);
3819 $$->append($3);
3821 | SQL_TOKEN_TIMESTAMP opt_paren_precision opt_with_or_without_time_zone
3823 $$ = SQL_NEW_RULE;
3824 $$->append($1);
3825 $$->append($2);
3826 $$->append($3);
3829 opt_with_or_without_time_zone:
3830 {$$ = SQL_NEW_RULE;}
3831 | SQL_TOKEN_WITH SQL_TOKEN_TIME SQL_TOKEN_ZONE
3833 $$ = SQL_NEW_RULE;
3834 $$->append($1);
3835 $$->append($2);
3836 $$->append($3);
3838 | SQL_TOKEN_WITHOUT SQL_TOKEN_TIME SQL_TOKEN_ZONE
3840 $$ = SQL_NEW_RULE;
3841 $$->append($1);
3842 $$->append($2);
3843 $$->append($3);
3846 interval_type:
3847 SQL_TOKEN_INTERVAL interval_qualifier
3849 $$ = SQL_NEW_RULE;
3850 $$->append($1);
3851 $$->append($2);
3854 /* the various things you can name */
3856 column:
3857 SQL_TOKEN_NAME
3858 | SQL_TOKEN_POSITION
3860 sal_uInt32 nNod = $$->getRuleID();
3861 delete $$;
3862 $$ = newNode(OSQLParser::TokenIDToStr(nNod), SQLNodeType::Name);
3864 | SQL_TOKEN_CHAR_LENGTH
3866 sal_uInt32 nNod = $$->getRuleID();
3867 delete $$;
3868 $$ = newNode(OSQLParser::TokenIDToStr(nNod), SQLNodeType::Name);
3870 | SQL_TOKEN_EXTRACT
3872 sal_uInt32 nNod = $$->getRuleID();
3873 delete $$;
3874 $$ = newNode(OSQLParser::TokenIDToStr(nNod), SQLNodeType::Name);
3877 case_expression:
3878 case_abbreviation
3879 | case_specification
3881 case_abbreviation:
3882 SQL_TOKEN_NULLIF '(' value_exp_commalist ')'
3884 $$ = SQL_NEW_RULE;
3885 $$->append($1);
3886 $$->append(newNode("(", SQLNodeType::Punctuation));
3887 $$->append($3);
3888 $$->append(newNode(")", SQLNodeType::Punctuation));
3890 | SQL_TOKEN_COALESCE '(' value_exp ')'
3892 $$ = SQL_NEW_RULE;
3893 $$->append($1);
3894 $$->append(newNode("(", SQLNodeType::Punctuation));
3895 $$->append($3);
3896 $$->append(newNode(")", SQLNodeType::Punctuation));
3898 | SQL_TOKEN_COALESCE '(' value_exp_commalist ')'
3900 $$ = SQL_NEW_RULE;
3901 $$->append($1);
3902 $$->append(newNode("(", SQLNodeType::Punctuation));
3903 $$->append($3);
3904 $$->append(newNode(")", SQLNodeType::Punctuation));
3907 case_specification:
3908 simple_case
3909 | searched_case
3911 simple_case:
3912 SQL_TOKEN_CASE case_operand simple_when_clause_list else_clause SQL_TOKEN_END
3914 $$ = SQL_NEW_RULE;
3915 $$->append($1);
3916 $$->append($2);
3917 $$->append($3);
3918 $$->append($4);
3919 $$->append($5);
3922 searched_case:
3923 SQL_TOKEN_CASE searched_when_clause_list else_clause SQL_TOKEN_END
3925 $$ = SQL_NEW_RULE;
3926 $$->append($1);
3927 $$->append($2);
3928 $$->append($3);
3929 $$->append($4);
3932 simple_when_clause_list:
3933 simple_when_clause
3935 $$ = SQL_NEW_LISTRULE;
3936 $$->append($1);
3938 | searched_when_clause_list simple_when_clause
3940 $1->append($2);
3941 $$ = $1;
3944 simple_when_clause:
3945 SQL_TOKEN_WHEN when_operand_list SQL_TOKEN_THEN result
3947 $$ = SQL_NEW_RULE;
3948 $$->append($1);
3949 $$->append($2);
3950 $$->append($3);
3951 $$->append($4);
3954 when_operand_list:
3955 when_operand
3956 {$$ = SQL_NEW_COMMALISTRULE;
3957 $$->append($1);}
3958 | when_operand_list ',' when_operand
3959 {$1->append($3);
3960 $$ = $1;}
3962 when_operand:
3963 row_value_constructor_elem
3964 | comparison_predicate_part_2 %dprec 1
3965 | between_predicate_part_2
3966 | in_predicate_part_2
3967 | character_like_predicate_part_2
3968 | null_predicate_part_2 %dprec 2
3970 searched_when_clause_list:
3971 searched_when_clause
3973 $$ = SQL_NEW_LISTRULE;
3974 $$->append($1);
3976 | searched_when_clause_list searched_when_clause
3978 $1->append($2);
3979 $$ = $1;
3982 searched_when_clause:
3983 SQL_TOKEN_WHEN search_condition SQL_TOKEN_THEN result
3985 $$ = SQL_NEW_RULE;
3986 $$->append($1);
3987 $$->append($2);
3988 $$->append($3);
3989 $$->append($4);
3992 else_clause:
3993 {$$ = SQL_NEW_RULE;}
3994 | SQL_TOKEN_ELSE result
3996 $$ = SQL_NEW_RULE;
3997 $$->append($1);
3998 $$->append($2);
4001 result:
4002 result_expression
4004 result_expression:
4005 value_exp
4007 case_operand:
4008 row_value_constructor_elem
4011 cursor: SQL_TOKEN_NAME
4012 {$$ = SQL_NEW_RULE;
4013 $$->append($1);}
4016 /***
4017 module: SQL_TOKEN_NAME
4018 {$$ = SQL_NEW_RULE;
4019 $$->append($1);}
4021 ***/
4023 parameter:
4024 ':' SQL_TOKEN_NAME
4025 {$$ = SQL_NEW_RULE;
4026 $$->append(newNode(":", SQLNodeType::Punctuation));
4027 $$->append($2);}
4028 | '?'
4029 {$$ = SQL_NEW_RULE; // test
4030 $$->append(newNode("?", SQLNodeType::Punctuation));}
4031 | '[' SQL_TOKEN_NAME ']'
4032 {$$ = SQL_NEW_RULE;
4033 $$->append(newNode("[", SQLNodeType::Punctuation));
4034 $$->append($2);
4035 $$->append(newNode("]", SQLNodeType::Punctuation));}
4038 /***
4039 procedure: SQL_TOKEN_NAME
4040 {$$ = SQL_NEW_RULE;
4041 $$->append($1);}
4043 ***/
4045 range_variable:
4046 {$$ = SQL_NEW_RULE;}
4047 | opt_as SQL_TOKEN_NAME
4048 {$$ = SQL_NEW_RULE;
4049 $$->append($1);
4050 $$->append($2);
4054 user: SQL_TOKEN_NAME
4057 /* PREDICATECHECK RULES */
4058 sql:
4059 search_condition /* checking predicats */
4061 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // sql: rule 1
4063 $$ = $1;
4064 if ( SQL_ISRULE($$,search_condition) )
4066 $$->insert(0,newNode("(", SQLNodeType::Punctuation));
4067 $$->append(newNode(")", SQLNodeType::Punctuation));
4070 else
4071 YYERROR;
4073 | '(' sql ')' /* checking predicats */
4075 trigger_definition:
4076 SQL_TOKEN_CREATE SQL_TOKEN_TRIGGER trigger_name trigger_action_time trigger_event SQL_TOKEN_ON table_name op_referencing triggered_action
4078 $$ = SQL_NEW_RULE;
4079 $$->append($1);
4080 $$->append($2);
4081 $$->append($3);
4082 $$->append($4);
4083 $$->append($5);
4084 $$->append($6);
4085 $$->append($7);
4086 $$->append($8);
4087 $$->append($9);
4090 op_referencing:
4092 $$ = SQL_NEW_RULE;
4094 | SQL_TOKEN_REFERENCING transition_table_or_variable_list
4096 $$ = SQL_NEW_RULE;
4097 $$->append($1);
4098 $$->append($2);
4101 trigger_action_time:
4102 SQL_TOKEN_BEFORE
4103 | SQL_TOKEN_AFTER
4104 | SQL_TOKEN_INSTEAD SQL_TOKEN_OF
4106 $$ = SQL_NEW_RULE;
4107 $$->append($1);
4108 $$->append($2);
4111 trigger_event:
4112 SQL_TOKEN_INSERT
4113 | SQL_TOKEN_DELETE
4114 | SQL_TOKEN_UPDATE op_trigger_columnlist
4116 $$ = SQL_NEW_RULE;
4117 $$->append($1);
4118 $$->append($2);
4121 op_trigger_columnlist:
4123 $$ = SQL_NEW_RULE;
4125 | SQL_TOKEN_OF trigger_column_list
4127 $$ = SQL_NEW_RULE;
4128 $$->append($1);
4129 $$->append($2);
4132 trigger_column_list:
4133 column_commalist
4135 triggered_action:
4136 op_triggered_action_for triggered_when_clause triggered_SQL_statement
4138 $$ = SQL_NEW_RULE;
4139 $$->append($1);
4140 $$->append($2);
4141 $$->append($3);
4144 op_triggered_action_for:
4146 $$ = SQL_NEW_RULE;
4148 | SQL_TOKEN_FOR SQL_TOKEN_EACH trigger_for
4150 $$ = SQL_NEW_RULE;
4151 $$->append($1);
4152 $$->append($2);
4153 $$->append($3);
4156 trigger_for:
4157 SQL_TOKEN_ROW
4158 | SQL_TOKEN_STATEMENT
4160 triggered_when_clause:
4162 $$ = SQL_NEW_RULE;
4164 | SQL_TOKEN_WHEN parenthesized_boolean_value_expression
4166 $$ = SQL_NEW_RULE;
4167 $$->append($1);
4168 $$->append($2);
4171 triggered_SQL_statement:
4172 SQL_procedure_statement
4173 | SQL_TOKEN_BEGIN SQL_TOKEN_ATOMIC SQL_procedure_statement_list ';' SQL_TOKEN_END
4175 $$ = SQL_NEW_RULE;
4176 $$->append($1);
4177 $$->append($2);
4178 $$->append($3);
4179 $$->append(newNode(";", SQLNodeType::Punctuation));
4180 $$->append($5);
4183 SQL_procedure_statement_list:
4184 SQL_procedure_statement
4186 $$ = SQL_NEW_LISTRULE;
4187 $$->append($1);
4189 | SQL_procedure_statement_list ';' SQL_procedure_statement
4191 $1->append($3);
4192 $$ = $1;
4195 SQL_procedure_statement:
4199 transition_table_or_variable_list:
4200 transition_table_or_variable
4202 $$ = SQL_NEW_LISTRULE;
4203 $$->append($1);
4205 | transition_table_or_variable_list transition_table_or_variable
4207 $1->append($2);
4208 $$ = $1;
4212 transition_table_or_variable:
4213 SQL_TOKEN_OLD opt_row opt_as old_transition_variable_name
4215 $$ = SQL_NEW_RULE;
4216 $$->append($1);
4217 $$->append($2);
4218 $$->append($3);
4219 $$->append($4);
4221 | SQL_TOKEN_NEW opt_row opt_as new_transition_variable_name
4223 $$ = SQL_NEW_RULE;
4224 $$->append($1);
4225 $$->append($2);
4226 $$->append($3);
4227 $$->append($4);
4229 | SQL_TOKEN_OLD SQL_TOKEN_TABLE opt_as old_transition_table_name
4231 $$ = SQL_NEW_RULE;
4232 $$->append($1);
4233 $$->append($2);
4234 $$->append($3);
4235 $$->append($4);
4237 | SQL_TOKEN_NEW SQL_TOKEN_TABLE opt_as new_transition_table_name
4239 $$ = SQL_NEW_RULE;
4240 $$->append($1);
4241 $$->append($2);
4242 $$->append($3);
4243 $$->append($4);
4246 old_transition_table_name:
4247 transition_table_name
4249 new_transition_table_name:
4250 transition_table_name
4252 transition_table_name:
4253 SQL_TOKEN_NAME
4255 old_transition_variable_name:
4256 SQL_TOKEN_NAME
4258 new_transition_variable_name:
4259 SQL_TOKEN_NAME
4261 trigger_name:
4262 SQL_TOKEN_NAME
4266 #if defined _MSC_VER
4267 #pragma warning(pop)
4268 #endif
4270 using namespace ::com::sun::star::sdbc;
4271 using namespace ::com::sun::star::beans;
4272 using namespace ::com::sun::star::uno;
4273 using namespace ::com::sun::star::i18n;
4274 using namespace ::com::sun::star::lang;
4275 using namespace ::com::sun::star::util;
4276 using namespace ::osl;
4277 using namespace ::dbtools;
4279 connectivity::OSQLParser* xxx_pGLOBAL_SQLPARSER;
4281 connectivity::OSQLInternalNode* newNode(const sal_Char* pNewValue,
4282 const connectivity::SQLNodeType eNodeType,
4283 const sal_uInt32 nNodeID)
4285 return new connectivity::OSQLInternalNode(pNewValue, eNodeType, nNodeID);
4288 connectivity::OSQLInternalNode* newNode(const OString& _newValue,
4289 const connectivity::SQLNodeType eNodeType,
4290 const sal_uInt32 nNodeID)
4292 return new connectivity::OSQLInternalNode(_newValue, eNodeType, nNodeID);
4295 connectivity::OSQLInternalNode* newNode(const OUString& _newValue,
4296 const connectivity::SQLNodeType eNodeType,
4297 const sal_uInt32 nNodeID)
4299 return new connectivity::OSQLInternalNode(_newValue, eNodeType, nNodeID);
4302 OParseContext::OParseContext()
4307 OParseContext::~OParseContext()
4312 OUString OParseContext::getErrorMessage(ErrorCode _eCode) const
4314 OUString aMsg;
4315 switch (_eCode)
4317 case ErrorCode::General: aMsg = "Syntax error in SQL expression"; break;
4318 case ErrorCode::ValueNoLike: aMsg = "The value #1 can not be used with LIKE."; break;
4319 case ErrorCode::FieldNoLike: aMsg = "LIKE can not be used with this field."; break;
4320 case ErrorCode::InvalidCompare: aMsg = "The entered criterion can not be compared with this field."; break;
4321 case ErrorCode::InvalidIntCompare: aMsg = "The field can not be compared with a number."; break;
4322 case ErrorCode::InvalidDateCompare: aMsg = "The field can not be compared with a date."; break;
4323 case ErrorCode::InvalidRealCompare: aMsg = "The field can not be compared with a floating point number."; break;
4324 case ErrorCode::InvalidTableNosuch: aMsg = "The database does not contain a table named \"#\"."; break;
4325 case ErrorCode::InvalidTableOrQuery: aMsg = "The database does contain neither a table nor a query named \"#\"."; break;
4326 case ErrorCode::InvalidColumn: aMsg = "The column \"#1\" is unknown in the table \"#2\"."; break;
4327 case ErrorCode::InvalidTableExist: aMsg = "The database already contains a table or view with name \"#\"."; break;
4328 case ErrorCode::InvalidQueryExist: aMsg = "The database already contains a query with name \"#\"."; break;
4329 default:
4330 OSL_FAIL( "OParseContext::getErrorMessage: unknown error code!" );
4331 break;
4333 return aMsg;
4337 OString OParseContext::getIntlKeywordAscii(InternationalKeyCode _eKey) const
4339 OString aKeyword;
4340 switch (_eKey)
4342 case InternationalKeyCode::Like: aKeyword = "LIKE"; break;
4343 case InternationalKeyCode::Not: aKeyword = "NOT"; break;
4344 case InternationalKeyCode::Null: aKeyword = "NULL"; break;
4345 case InternationalKeyCode::True: aKeyword = "True"; break;
4346 case InternationalKeyCode::False: aKeyword = "False"; break;
4347 case InternationalKeyCode::Is: aKeyword = "IS"; break;
4348 case InternationalKeyCode::Between: aKeyword = "BETWEEN"; break;
4349 case InternationalKeyCode::Or: aKeyword = "OR"; break;
4350 case InternationalKeyCode::And: aKeyword = "AND"; break;
4351 case InternationalKeyCode::Avg: aKeyword = "AVG"; break;
4352 case InternationalKeyCode::Count: aKeyword = "COUNT"; break;
4353 case InternationalKeyCode::Max: aKeyword = "MAX"; break;
4354 case InternationalKeyCode::Min: aKeyword = "MIN"; break;
4355 case InternationalKeyCode::Sum: aKeyword = "SUM"; break;
4356 case InternationalKeyCode::Every: aKeyword = "EVERY"; break;
4357 case InternationalKeyCode::Any: aKeyword = "ANY"; break;
4358 case InternationalKeyCode::Some: aKeyword = "SOME"; break;
4359 case InternationalKeyCode::StdDevPop: aKeyword = "STDDEV_POP"; break;
4360 case InternationalKeyCode::StdDevSamp: aKeyword = "STDDEV_SAMP"; break;
4361 case InternationalKeyCode::VarSamp: aKeyword = "VAR_SAMP"; break;
4362 case InternationalKeyCode::VarPop: aKeyword = "VAR_POP"; break;
4363 case InternationalKeyCode::Collect: aKeyword = "COLLECT"; break;
4364 case InternationalKeyCode::Fusion: aKeyword = "FUSION"; break;
4365 case InternationalKeyCode::Intersection:aKeyword = "INTERSECTION"; break;
4366 case InternationalKeyCode::None: break;
4367 default:
4368 OSL_FAIL( "OParseContext::getIntlKeywordAscii: unknown key!" );
4369 break;
4371 return aKeyword;
4375 IParseContext::InternationalKeyCode OParseContext::getIntlKeyCode(const OString& rToken) const
4377 static IParseContext::InternationalKeyCode Intl_TokenID[] =
4379 InternationalKeyCode::Like, InternationalKeyCode::Not, InternationalKeyCode::Null, InternationalKeyCode::True,
4380 InternationalKeyCode::False, InternationalKeyCode::Is, InternationalKeyCode::Between, InternationalKeyCode::Or,
4381 InternationalKeyCode::And, InternationalKeyCode::Avg, InternationalKeyCode::Count, InternationalKeyCode::Max,
4382 InternationalKeyCode::Min, InternationalKeyCode::Sum, InternationalKeyCode::Every,InternationalKeyCode::Any,InternationalKeyCode::Some,
4383 InternationalKeyCode::StdDevPop,InternationalKeyCode::StdDevSamp,InternationalKeyCode::VarSamp,
4384 InternationalKeyCode::VarPop,InternationalKeyCode::Collect,InternationalKeyCode::Fusion,InternationalKeyCode::Intersection
4387 sal_uInt32 nCount = SAL_N_ELEMENTS( Intl_TokenID );
4388 for (sal_uInt32 i = 0; i < nCount; i++)
4390 OString aKey = getIntlKeywordAscii(Intl_TokenID[i]);
4391 if (rToken.equalsIgnoreAsciiCase(aKey))
4392 return Intl_TokenID[i];
4395 return InternationalKeyCode::None;
4399 static Locale& impl_getLocaleInstance( )
4401 static Locale s_aLocale( "en", "US", "" );
4402 return s_aLocale;
4406 Locale OParseContext::getPreferredLocale( ) const
4408 return getDefaultLocale();
4412 const Locale& OParseContext::getDefaultLocale()
4414 return impl_getLocaleInstance();
4417 // The (unfortunately global) yylval for the handing over of
4418 // values from the Scanner to the Parser. The global variable
4419 // is only used for a short term, the Parser reads the variable
4420 // immediately after the call of the Scanner into a same named own
4421 // member variable.
4424 OUString ConvertLikeToken(const OSQLParseNode* pTokenNode, const OSQLParseNode* pEscapeNode, bool bInternational)
4426 OUStringBuffer aMatchStr(0);
4427 if (pTokenNode->isToken())
4429 sal_Unicode cEscape = 0;
4430 if (pEscapeNode->count())
4431 cEscape = pEscapeNode->getChild(1)->getTokenValue().toChar();
4433 // Change place holder
4434 aMatchStr = pTokenNode->getTokenValue();
4435 const sal_Int32 nLen = aMatchStr.getLength();
4436 OUStringBuffer sSearch,sReplace;
4437 if ( bInternational )
4439 sSearch.append("%_");
4440 sReplace.append("*?");
4442 else
4444 sSearch.append("*?");
4445 sReplace.append("%_");
4448 bool wasEscape = false;
4449 for (sal_Int32 i = 0; i < nLen; i++)
4451 const sal_Unicode c = aMatchStr[i];
4452 // SQL standard requires the escape to be followed
4453 // by a meta-character ('%', '_' or itself), else error
4454 // We are more lenient here and let it escape anything.
4455 // Especially since some databases (e.g. Microsoft SQL Server)
4456 // have more meta-characters than the standard, such as e.g. '[' and ']'
4457 if (wasEscape)
4459 wasEscape=false;
4460 continue;
4462 if (c == cEscape)
4464 wasEscape=true;
4465 continue;
4467 int match = -1;
4468 if (c == sSearch[0])
4469 match=0;
4470 else if (c == sSearch[1])
4471 match=1;
4473 if (match != -1)
4475 aMatchStr[i] = sReplace[match];
4479 return aMatchStr.makeStringAndClear();
4482 sal_uInt32 OSQLParser::s_nRuleIDs[OSQLParseNode::rule_count + 1];
4483 OSQLParser::RuleIDMap OSQLParser::s_aReverseRuleIDLookup;
4484 OParseContext OSQLParser::s_aDefaultContext;
4486 sal_Int32 OSQLParser::s_nRefCount = 0;
4487 // ::osl::Mutex OSQLParser::s_aMutex;
4488 OSQLScanner* OSQLParser::s_pScanner = nullptr;
4489 OSQLParseNodesGarbageCollector* OSQLParser::s_pGarbageCollector = nullptr;
4490 css::uno::Reference< css::i18n::XLocaleData4> OSQLParser::s_xLocaleData = nullptr;
4492 void setParser(OSQLParser* _pParser)
4494 xxx_pGLOBAL_SQLPARSER = _pParser;
4497 void OSQLParser::setParseTree(OSQLParseNode* pNewParseTree)
4499 ::osl::MutexGuard aGuard(getMutex());
4500 m_pParseTree.reset(pNewParseTree);
4504 /** Delete all comments in a query.
4506 See also getComment()/concatComment() implementation for
4507 OQueryController::translateStatement().
4509 static OUString delComment( const OUString& rQuery )
4511 // First a quick search if there is any "--" or "//" or "/*", if not then the whole
4512 // copying loop is pointless.
4513 if (rQuery.indexOf("--") < 0 && rQuery.indexOf("//") < 0 &&
4514 rQuery.indexOf("/*") < 0)
4515 return rQuery;
4517 const sal_Unicode* pCopy = rQuery.getStr();
4518 sal_Int32 nQueryLen = rQuery.getLength();
4519 bool bIsText1 = false; // "text"
4520 bool bIsText2 = false; // 'text'
4521 bool bComment2 = false; // /* comment */
4522 bool bComment = false; // -- or // comment
4523 OUStringBuffer aBuf(nQueryLen);
4524 for (sal_Int32 i=0; i < nQueryLen; ++i)
4526 if (bComment2)
4528 if ((i+1) < nQueryLen)
4530 if (pCopy[i]=='*' && pCopy[i+1]=='/')
4532 bComment2 = false;
4533 ++i;
4536 else
4538 // comment can't close anymore, actually an error, but..
4540 continue;
4542 if (pCopy[i] == '\n')
4543 bComment = false;
4544 else if (!bComment)
4546 if (pCopy[i] == '\"' && !bIsText2)
4547 bIsText1 = !bIsText1;
4548 else if (pCopy[i] == '\'' && !bIsText1)
4549 bIsText2 = !bIsText2;
4550 if (!bIsText1 && !bIsText2 && (i+1) < nQueryLen)
4552 if ((pCopy[i]=='-' && pCopy[i+1]=='-') || (pCopy[i]=='/' && pCopy[i+1]=='/'))
4553 bComment = true;
4554 else if ((pCopy[i]=='/' && pCopy[i+1]=='*'))
4555 bComment2 = true;
4558 if (!bComment && !bComment2)
4559 aBuf.append( &pCopy[i], 1);
4561 return aBuf.makeStringAndClear();
4564 std::unique_ptr<OSQLParseNode> OSQLParser::parseTree(OUString& rErrorMessage,
4565 const OUString& rStatement,
4566 bool bInternational)
4570 // Guard the parsing
4571 ::osl::MutexGuard aGuard(getMutex());
4572 // must be reset
4573 setParser(this);
4575 // delete comments before parsing
4576 OUString sTemp = delComment(rStatement);
4578 // defines how to scan
4579 s_pScanner->SetRule(OSQLScanner::GetSQLRule()); // initial
4580 s_pScanner->prepareScan(sTemp, m_pContext, bInternational);
4582 SQLyylval.pParseNode = nullptr;
4583 // SQLyypvt = NULL;
4584 m_pParseTree = nullptr;
4585 m_sErrorMessage = "";
4587 // start parsing
4588 if (SQLyyparse() != 0)
4590 // only set the error message, if it's not already set
4591 if (m_sErrorMessage.isEmpty())
4592 m_sErrorMessage = s_pScanner->getErrorMessage();
4593 if (m_sErrorMessage.isEmpty())
4594 m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ErrorCode::General);
4596 rErrorMessage = m_sErrorMessage;
4598 // clear the garbage collector
4599 (*s_pGarbageCollector)->clearAndDelete();
4600 return nullptr;
4602 else
4604 (*s_pGarbageCollector)->clear();
4606 // return result:
4607 // to work around a bug in MKS YACC return the member m_pParseTree
4608 // instead of Sdbyyval.pParseNode
4610 SAL_WARN_IF(!m_pParseTree, "connectivity.parse",
4611 "OSQLParser: Parser did not create ParseTree");
4612 return std::move(m_pParseTree);
4616 OString OSQLParser::TokenIDToStr(sal_uInt32 nTokenID, const IParseContext* pContext)
4618 OString aStr;
4619 if (pContext)
4621 IParseContext::InternationalKeyCode eKeyCode = IParseContext::InternationalKeyCode::None;
4622 switch( nTokenID )
4624 case SQL_TOKEN_LIKE: eKeyCode = IParseContext::InternationalKeyCode::Like; break;
4625 case SQL_TOKEN_NOT: eKeyCode = IParseContext::InternationalKeyCode::Not; break;
4626 case SQL_TOKEN_NULL: eKeyCode = IParseContext::InternationalKeyCode::Null; break;
4627 case SQL_TOKEN_TRUE: eKeyCode = IParseContext::InternationalKeyCode::True; break;
4628 case SQL_TOKEN_FALSE: eKeyCode = IParseContext::InternationalKeyCode::False; break;
4629 case SQL_TOKEN_IS: eKeyCode = IParseContext::InternationalKeyCode::Is; break;
4630 case SQL_TOKEN_BETWEEN: eKeyCode = IParseContext::InternationalKeyCode::Between; break;
4631 case SQL_TOKEN_OR: eKeyCode = IParseContext::InternationalKeyCode::Or; break;
4632 case SQL_TOKEN_AND: eKeyCode = IParseContext::InternationalKeyCode::And; break;
4633 case SQL_TOKEN_AVG: eKeyCode = IParseContext::InternationalKeyCode::Avg; break;
4634 case SQL_TOKEN_COUNT: eKeyCode = IParseContext::InternationalKeyCode::Count; break;
4635 case SQL_TOKEN_MAX: eKeyCode = IParseContext::InternationalKeyCode::Max; break;
4636 case SQL_TOKEN_MIN: eKeyCode = IParseContext::InternationalKeyCode::Min; break;
4637 case SQL_TOKEN_SUM: eKeyCode = IParseContext::InternationalKeyCode::Sum; break;
4639 if ( eKeyCode != IParseContext::InternationalKeyCode::None )
4640 aStr = pContext->getIntlKeywordAscii(eKeyCode);
4643 if (aStr.isEmpty())
4645 aStr = yytname[YYTRANSLATE(nTokenID)];
4646 if(aStr.startsWith("SQL_TOKEN_"))
4647 aStr = aStr.copy(10);
4648 switch( nTokenID )
4650 case SQL_TOKEN_OJ:
4651 case SQL_TOKEN_TS:
4652 case SQL_TOKEN_T:
4653 case SQL_TOKEN_D:
4654 aStr = aStr.toAsciiLowerCase();
4657 return aStr;
4660 #if OSL_DEBUG_LEVEL > 0
4661 OUString OSQLParser::RuleIDToStr(sal_uInt32 nRuleID)
4663 OSL_ENSURE(nRuleID < SAL_N_ELEMENTS(yytname), "OSQLParser::RuleIDToStr: Invalid nRuleId!");
4664 return OUString::createFromAscii(yytname[nRuleID]);
4666 #endif
4669 sal_uInt32 OSQLParser::StrToRuleID(const OString & rValue)
4671 // Search for the given name in yytname and return the index
4672 // (or UNKNOWN_RULE, if not found)
4673 static sal_uInt32 nLen = SAL_N_ELEMENTS(yytname);
4674 for (sal_uInt32 i = YYTRANSLATE(SQL_TOKEN_INVALIDSYMBOL); i < (nLen-1); i++)
4676 if (rValue == yytname[i])
4677 return i;
4680 // Not found
4681 return OSQLParseNode::UNKNOWN_RULE;
4685 OSQLParseNode::Rule OSQLParser::RuleIDToRule( sal_uInt32 _nRule )
4687 OSQLParser::RuleIDMap::const_iterator i (s_aReverseRuleIDLookup.find(_nRule));
4688 if (i == s_aReverseRuleIDLookup.end())
4690 SAL_INFO("connectivity.parse",
4691 "connectivity::OSQLParser::RuleIDToRule cannot reverse-lookup rule. "
4692 "Reverse mapping incomplete? "
4693 "_nRule='" << _nRule << "' "
4694 "yytname[_nRule]='" << yytname[_nRule] << "'");
4695 return OSQLParseNode::UNKNOWN_RULE;
4697 else
4698 return i->second;
4702 sal_uInt32 OSQLParser::RuleID(OSQLParseNode::Rule eRule)
4704 return s_nRuleIDs[(sal_uInt16)eRule];
4707 sal_Int16 OSQLParser::buildNode(OSQLParseNode*& pAppend,OSQLParseNode* pCompare,OSQLParseNode* pLiteral,OSQLParseNode* pLiteral2)
4709 OSQLParseNode* pColumnRef = new OSQLInternalNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
4710 pColumnRef->append(new OSQLInternalNode(m_sFieldName,SQLNodeType::Name));
4711 OSQLParseNode* pComp = nullptr;
4712 if ( SQL_ISTOKEN( pCompare, BETWEEN) && pLiteral2 )
4713 pComp = new OSQLInternalNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::between_predicate_part_2));
4714 else
4715 pComp = new OSQLInternalNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::comparison_predicate));
4717 pComp->append(pColumnRef);
4718 pComp->append(pCompare);
4719 pComp->append(pLiteral);
4720 if ( pLiteral2 )
4722 pComp->append(new OSQLInternalNode("", SQLNodeType::Keyword,SQL_TOKEN_AND));
4723 pComp->append(pLiteral2);
4725 pAppend->append(pComp);
4726 return 1;
4729 sal_Int16 OSQLParser::buildStringNodes(OSQLParseNode*& pLiteral)
4731 if(!pLiteral)
4732 return 1;
4734 if(SQL_ISRULE(pLiteral,set_fct_spec) || SQL_ISRULE(pLiteral,general_set_fct) || SQL_ISRULE(pLiteral,column_ref)
4735 || SQL_ISRULE(pLiteral,subquery))
4736 return 1; // here I have a function that I can't transform into a string
4738 if(pLiteral->getNodeType() == SQLNodeType::IntNum || pLiteral->getNodeType() == SQLNodeType::ApproxNum || pLiteral->getNodeType() == SQLNodeType::AccessDate)
4740 OSQLParseNode* pParent = pLiteral->getParent();
4742 OSQLParseNode* pNewNode = new OSQLInternalNode(pLiteral->getTokenValue(), SQLNodeType::String);
4743 pParent->replace(pLiteral, pNewNode);
4744 delete pLiteral;
4745 pLiteral = nullptr;
4746 return 1;
4749 for(size_t i=0;i<pLiteral->count();++i)
4751 OSQLParseNode* pChild = pLiteral->getChild(i);
4752 buildStringNodes(pChild);
4754 if(SQL_ISRULE(pLiteral,term) || SQL_ISRULE(pLiteral,value_exp_primary))
4756 m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ErrorCode::InvalidCompare);
4757 return 0;
4759 return 1;
4762 sal_Int16 OSQLParser::buildComparsionRule(OSQLParseNode*& pAppend,OSQLParseNode* pLiteral)
4764 OSQLParseNode* pComp = new OSQLInternalNode("=", SQLNodeType::Equal);
4765 return buildPredicateRule(pAppend,pLiteral,pComp);
4770 void OSQLParser::reduceLiteral(OSQLParseNode*& pLiteral, bool bAppendBlank)
4772 OSL_ENSURE(pLiteral->isRule(), "This is no Rule");
4773 OSL_ENSURE(pLiteral->count() == 2, "OSQLParser::ReduceLiteral() Invalid count");
4774 OSQLParseNode* pTemp = pLiteral;
4775 OUStringBuffer aValue(pLiteral->getChild(0)->getTokenValue());
4776 if (bAppendBlank)
4778 aValue.append(" ");
4781 aValue.append(pLiteral->getChild(1)->getTokenValue());
4783 pLiteral = new OSQLInternalNode(aValue.makeStringAndClear(),SQLNodeType::String);
4784 delete pTemp;
4788 void OSQLParser::error(const sal_Char *fmt)
4790 if(m_sErrorMessage.isEmpty())
4792 OUString sStr(fmt,strlen(fmt),RTL_TEXTENCODING_UTF8);
4793 OUString sSQL_TOKEN("SQL_TOKEN_");
4795 sal_Int32 nPos1 = sStr.indexOf(sSQL_TOKEN);
4796 if(nPos1 != -1)
4798 OUString sFirst = sStr.copy(0,nPos1);
4799 sal_Int32 nPos2 = sStr.indexOf(sSQL_TOKEN,nPos1+1);
4800 if(nPos2 != -1)
4802 OUString sSecond = sStr.copy(nPos1+sSQL_TOKEN.getLength(),nPos2-nPos1-sSQL_TOKEN.getLength());
4803 sFirst += sSecond;
4804 sFirst += sStr.copy(nPos2+sSQL_TOKEN.getLength());
4806 else
4807 sFirst += sStr.copy(nPos1+sSQL_TOKEN.getLength());
4809 m_sErrorMessage = sFirst;
4811 else
4812 m_sErrorMessage = sStr;
4814 OUString aError = s_pScanner->getErrorMessage();
4815 if(!aError.isEmpty())
4817 m_sErrorMessage += ", ";
4818 m_sErrorMessage += aError;
4823 int OSQLParser::SQLlex()
4825 return OSQLScanner::SQLlex();