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 .
25 #include <connectivity/sqlnode.hxx>
26 #include <connectivity/sqlparse.hxx>
27 #include <connectivity/sqlbison_exports.hxx>
28 #include <connectivity/sqlscan.hxx>
29 #include <connectivity/internalnode.hxx>
30 #include <com/sun/star/lang/Locale.hpp>
31 #include <com/sun/star/sdbc/DataType.hpp>
32 #include <com/sun/star/util/Date.hpp>
33 #include <com/sun/star/util/DateTime.hpp>
34 #include <com/sun/star/util/Time.hpp>
35 #include <com/sun/star/util/XNumberFormatter.hpp>
36 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
37 #include <com/sun/star/util/XNumberFormats.hpp>
38 #include <com/sun/star/util/NumberFormat.hpp>
39 #include <com/sun/star/util/XNumberFormatTypes.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/i18n/KParseType.hpp>
42 #include <com/sun/star/i18n/KParseTokens.hpp>
44 #include <osl/diagnose.h>
45 #include "connectivity/dbconversion.hxx"
46 #include <rtl/ustrbuf.hxx>
47 #include <sal/log.hxx>
51 #pragma warning(disable: 4324) // structure was padded due to alignment specifier
52 #pragma warning(disable: 4065) // switch statement contains 'default' but no 'case' labels
53 #pragma warning(disable: 4702) // unreachable code
57 # pragma GCC diagnostic ignored "-Wwrite-strings"
58 # pragma GCC diagnostic ignored "-Wunused-function"
61 inline connectivity
::OSQLInternalNode
* newNode
(const char* pNewValue
,
62 const connectivity
::SQLNodeType eNodeType
,
63 const sal_uInt32 nNodeID
= 0);
65 inline connectivity
::OSQLInternalNode
* newNode
(const OString
& _newValue
,
66 const connectivity
::SQLNodeType eNodeType
,
67 const sal_uInt32 nNodeID
= 0);
69 inline connectivity
::OSQLInternalNode
* newNode
(const OUString
& _newValue
,
70 const connectivity
::SQLNodeType eNodeType
,
71 const sal_uInt32 nNodeID
= 0);
74 // yyi is the internal number of the rule that is currently being reduced
75 // This can be mapped to external rule number via the yyrmap.
76 #if defined YYBISON && YYBISON >= 30800
77 #define SQL_NEW_RULE newNode("", SQLNodeType::Rule, yyr1[yyrule])
78 #define SQL_NEW_LISTRULE newNode("", SQLNodeType::ListRule, yyr1[yyrule])
79 #define SQL_NEW_COMMALISTRULE newNode("", SQLNodeType::CommaListRule, yyr1[yyrule])
81 #define SQL_NEW_RULE newNode("", SQLNodeType::Rule, yyr1[yyn])
82 #define SQL_NEW_LISTRULE newNode("", SQLNodeType::ListRule, yyr1[yyn])
83 #define SQL_NEW_COMMALISTRULE newNode("", SQLNodeType::CommaListRule, yyr1[yyn])
87 extern connectivity
::OSQLParser
* xxx_pGLOBAL_SQLPARSER
;
89 #define YYERROR_VERBOSE
91 #define SQLyyerror(s) \
93 xxx_pGLOBAL_SQLPARSER
->error(s
); \
96 using namespace connectivity
;
97 #define SQLyylex xxx_pGLOBAL_SQLPARSER->SQLlex
102 connectivity
::OSQLParseNode
* pParseNode
;
104 %type
<pParseNode
> '(' ')' ',' ':' ';' '?' '[' ']' '{' '}' '.' 'K' 'M' 'G' 'T' 'P'
106 %token
<pParseNode
> SQL_TOKEN_STRING SQL_TOKEN_ACCESS_DATE SQL_TOKEN_INT SQL_TOKEN_REAL_NUM
107 %token
<pParseNode
> SQL_TOKEN_INTNUM SQL_TOKEN_APPROXNUM SQL_TOKEN_NOT SQL_TOKEN_NAME
110 %nonassoc
<pParseNode
> SQL_TOKEN_UMINUS
114 /* literal keyword tokens */
116 %token
<pParseNode
> SQL_TOKEN_ALL SQL_TOKEN_ALTER SQL_TOKEN_AMMSC SQL_TOKEN_ANY SQL_TOKEN_AS SQL_TOKEN_ASC SQL_TOKEN_AT SQL_TOKEN_AUTHORIZATION SQL_TOKEN_AVG
118 %token
<pParseNode
> SQL_TOKEN_BETWEEN SQL_TOKEN_BIT SQL_TOKEN_BOTH SQL_TOKEN_BY
120 %token
<pParseNode
> SQL_TOKEN_CAST SQL_TOKEN_CHARACTER SQL_TOKEN_CHECK SQL_TOKEN_COLLATE SQL_TOKEN_COMMIT SQL_TOKEN_CONTINUE SQL_TOKEN_CONVERT SQL_TOKEN_COUNT SQL_TOKEN_CREATE SQL_TOKEN_CROSS
121 %token
<pParseNode
> SQL_TOKEN_CURRENT SQL_TOKEN_CURSOR
123 %token
<pParseNode
> SQL_TOKEN_DATE SQL_TOKEN_DATEVALUE SQL_TOKEN_DAY SQL_TOKEN_DEC SQL_TOKEN_DECIMAL SQL_TOKEN_DECLARE SQL_TOKEN_DEFAULT SQL_TOKEN_DELETE SQL_TOKEN_DESC
124 %token
<pParseNode
> SQL_TOKEN_DISTINCT SQL_TOKEN_DOUBLE SQL_TOKEN_DROP
126 %token
<pParseNode
> SQL_TOKEN_ESCAPE SQL_TOKEN_EXCEPT SQL_TOKEN_EXISTS SQL_TOKEN_FALSE SQL_TOKEN_FETCH SQL_TOKEN_FLOAT SQL_TOKEN_FOR SQL_TOKEN_FOREIGN SQL_TOKEN_FOUND SQL_TOKEN_FROM SQL_TOKEN_FULL
128 %token
<pParseNode
> SQL_TOKEN_GRANT SQL_TOKEN_GROUP SQL_TOKEN_HAVING SQL_TOKEN_IN SQL_TOKEN_INDICATOR SQL_TOKEN_INNER SQL_TOKEN_INTEGER SQL_TOKEN_INTO SQL_TOKEN_IS SQL_TOKEN_INTERSECT
130 %left
<pParseNode
> SQL_TOKEN_JOIN
131 %token
<pParseNode
> SQL_TOKEN_KEY SQL_TOKEN_LEADING SQL_TOKEN_LIKE SQL_TOKEN_LOCAL SQL_TOKEN_LOWER
132 %token
<pParseNode
> SQL_TOKEN_MAX SQL_TOKEN_MIN SQL_TOKEN_NATURAL SQL_TOKEN_NCHAR SQL_TOKEN_NULL SQL_TOKEN_NUMERIC
134 %token
<pParseNode
> SQL_TOKEN_OCTET_LENGTH SQL_TOKEN_OF SQL_TOKEN_ON SQL_TOKEN_OPTION SQL_TOKEN_ORDER SQL_TOKEN_OUTER
136 %token
<pParseNode
> SQL_TOKEN_PRECISION SQL_TOKEN_PRIMARY SQL_TOKEN_PRIVILEGES SQL_TOKEN_PROCEDURE SQL_TOKEN_PUBLIC
137 %token
<pParseNode
> SQL_TOKEN_REAL SQL_TOKEN_REFERENCES SQL_TOKEN_ROLLBACK
139 %token
<pParseNode
> SQL_TOKEN_SCHEMA SQL_TOKEN_SELECT SQL_TOKEN_SET SQL_TOKEN_SIZE SQL_TOKEN_SMALLINT SQL_TOKEN_SOME SQL_TOKEN_SQLCODE SQL_TOKEN_SQLERROR SQL_TOKEN_SUM
141 %token
<pParseNode
> SQL_TOKEN_TABLE SQL_TOKEN_TIME SQL_TOKEN_TIMESTAMP SQL_TOKEN_TIMEZONE_HOUR SQL_TOKEN_TIMEZONE_MINUTE SQL_TOKEN_TO SQL_TOKEN_TRAILING SQL_TOKEN_TRANSLATE SQL_TOKEN_TRIM SQL_TOKEN_TRUE SQL_TOKEN_UNION
142 %token
<pParseNode
> SQL_TOKEN_UNIQUE SQL_TOKEN_UNKNOWN SQL_TOKEN_UPDATE SQL_TOKEN_UPPER SQL_TOKEN_USAGE SQL_TOKEN_USER SQL_TOKEN_USING SQL_TOKEN_VALUES SQL_TOKEN_VIEW
143 %token
<pParseNode
> SQL_TOKEN_WHERE SQL_TOKEN_WITH SQL_TOKEN_WORK SQL_TOKEN_ZONE
146 %token
<pParseNode
> SQL_TOKEN_CALL SQL_TOKEN_D SQL_TOKEN_FN SQL_TOKEN_T SQL_TOKEN_TS SQL_TOKEN_OJ
147 /* string functions */
148 %token
<pParseNode
> SQL_TOKEN_ASCII SQL_TOKEN_BIT_LENGTH SQL_TOKEN_CHAR SQL_TOKEN_CHAR_LENGTH SQL_TOKEN_SQL_TOKEN_INTNUM
149 %token
<pParseNode
> SQL_TOKEN_CONCAT
150 %token
<pParseNode
> SQL_TOKEN_DIFFERENCE SQL_TOKEN_INSERT SQL_TOKEN_LCASE SQL_TOKEN_LEFT SQL_TOKEN_LENGTH SQL_TOKEN_LOCATE
151 %token
<pParseNode
> SQL_TOKEN_LOCATE_2 SQL_TOKEN_LTRIM SQL_TOKEN_POSITION SQL_TOKEN_REPEAT SQL_TOKEN_REPLACE
152 %token
<pParseNode
> SQL_TOKEN_RIGHT SQL_TOKEN_RTRIM SQL_TOKEN_SOUNDEX SQL_TOKEN_SPACE SQL_TOKEN_SUBSTRING SQL_TOKEN_UCASE
154 /* time and date functions */
155 %token
<pParseNode
> SQL_TOKEN_CURRENT_DATE SQL_TOKEN_CURRENT_TIME SQL_TOKEN_CURRENT_TIMESTAMP SQL_TOKEN_CURDATE SQL_TOKEN_CURTIME
156 %token
<pParseNode
> SQL_TOKEN_DAYNAME SQL_TOKEN_DAYOFMONTH SQL_TOKEN_DAYOFWEEK SQL_TOKEN_DAYOFYEAR SQL_TOKEN_EXTRACT
157 %token
<pParseNode
> SQL_TOKEN_HOUR SQL_TOKEN_MILLISECOND SQL_TOKEN_MINUTE SQL_TOKEN_MONTH SQL_TOKEN_MONTHNAME SQL_TOKEN_NOW SQL_TOKEN_QUARTER SQL_TOKEN_DATEDIFF
158 %token
<pParseNode
> SQL_TOKEN_SECOND SQL_TOKEN_TIMESTAMPADD SQL_TOKEN_TIMESTAMPDIFF SQL_TOKEN_TIMEVALUE SQL_TOKEN_WEEK SQL_TOKEN_WEEKDAY SQL_TOKEN_YEAR SQL_TOKEN_YEARDAY
159 %token
<pParseNode
> SQL_TOKEN_DATEADD
161 /* numeric functions */
162 %token
<pParseNode
> SQL_TOKEN_ABS SQL_TOKEN_ACOS SQL_TOKEN_ASIN SQL_TOKEN_ATAN SQL_TOKEN_ATAN2 SQL_TOKEN_CEILING
163 %token
<pParseNode
> SQL_TOKEN_COS SQL_TOKEN_COT SQL_TOKEN_DEGREES SQL_TOKEN_EXP SQL_TOKEN_FLOOR SQL_TOKEN_LOGF SQL_TOKEN_LOG SQL_TOKEN_LN
164 %token
<pParseNode
> SQL_TOKEN_LOG10 SQL_TOKEN_MOD SQL_TOKEN_PI SQL_TOKEN_POWER SQL_TOKEN_RADIANS SQL_TOKEN_RAND SQL_TOKEN_ROUNDMAGIC
165 %token
<pParseNode
> SQL_TOKEN_ROUND SQL_TOKEN_SIGN SQL_TOKEN_SIN SQL_TOKEN_SQRT SQL_TOKEN_TAN SQL_TOKEN_TRUNCATE
167 // computational operation
168 %token
<pParseNode
> SQL_TOKEN_EVERY SQL_TOKEN_INTERSECTION SQL_TOKEN_FUSION SQL_TOKEN_COLLECT SQL_TOKEN_VAR_POP SQL_TOKEN_VAR_SAMP
169 %token
<pParseNode
> SQL_TOKEN_STDDEV_SAMP SQL_TOKEN_STDDEV_POP
171 %token
<pParseNode
> SQL_TOKEN_RANK SQL_TOKEN_DENSE_RANK SQL_TOKEN_PERCENT_RANK SQL_TOKEN_CUME_DIST SQL_TOKEN_PERCENTILE_CONT SQL_TOKEN_PERCENTILE_DISC SQL_TOKEN_WITHIN SQL_TOKEN_ARRAY_AGG
172 %token
<pParseNode
> SQL_TOKEN_CASE SQL_TOKEN_THEN SQL_TOKEN_END SQL_TOKEN_NULLIF SQL_TOKEN_COALESCE SQL_TOKEN_WHEN SQL_TOKEN_ELSE
173 %token
<pParseNode
> SQL_TOKEN_BEFORE SQL_TOKEN_AFTER SQL_TOKEN_INSTEAD SQL_TOKEN_EACH SQL_TOKEN_REFERENCING SQL_TOKEN_BEGIN SQL_TOKEN_ATOMIC SQL_TOKEN_TRIGGER SQL_TOKEN_ROW SQL_TOKEN_STATEMENT
174 %token
<pParseNode
> SQL_TOKEN_NEW SQL_TOKEN_OLD
175 %token
<pParseNode
> SQL_TOKEN_VALUE SQL_TOKEN_CURRENT_CATALOG SQL_TOKEN_CURRENT_DEFAULT_TRANSFORM_GROUP SQL_TOKEN_CURRENT_PATH SQL_TOKEN_CURRENT_ROLE SQL_TOKEN_CURRENT_SCHEMA SQL_TOKEN_CURRENT_USER
176 %token
<pParseNode
> SQL_TOKEN_SESSION_USER SQL_TOKEN_SYSTEM_USER SQL_TOKEN_VARCHAR SQL_TOKEN_VARBINARY SQL_TOKEN_VARYING SQL_TOKEN_OBJECT SQL_TOKEN_NCLOB SQL_TOKEN_NATIONAL
177 %token
<pParseNode
> SQL_TOKEN_LARGE SQL_TOKEN_CLOB SQL_TOKEN_BLOB SQL_TOKEN_BIGINT SQL_TOKEN_BINARY SQL_TOKEN_WITHOUT SQL_TOKEN_BOOLEAN SQL_TOKEN_INTERVAL
179 %token
<pParseNode
> SQL_TOKEN_OVER SQL_TOKEN_ROW_NUMBER SQL_TOKEN_NTILE SQL_TOKEN_LEAD SQL_TOKEN_LAG SQL_TOKEN_RESPECT SQL_TOKEN_IGNORE SQL_TOKEN_NULLS
180 %token
<pParseNode
> SQL_TOKEN_FIRST_VALUE SQL_TOKEN_LAST_VALUE SQL_TOKEN_NTH_VALUE SQL_TOKEN_FIRST SQL_TOKEN_LAST
181 %token
<pParseNode
> SQL_TOKEN_EXCLUDE SQL_TOKEN_OTHERS SQL_TOKEN_TIES SQL_TOKEN_FOLLOWING SQL_TOKEN_UNBOUNDED SQL_TOKEN_PRECEDING SQL_TOKEN_RANGE SQL_TOKEN_ROWS
182 %token
<pParseNode
> SQL_TOKEN_PARTITION SQL_TOKEN_WINDOW SQL_TOKEN_NO
184 %token
<pParseNode
> SQL_TOKEN_LIMIT SQL_TOKEN_OFFSET SQL_TOKEN_NEXT SQL_TOKEN_ONLY
188 %left
<pParseNode
> SQL_TOKEN_OR
189 %left
<pParseNode
> SQL_TOKEN_AND
191 %left
<pParseNode
> SQL_LESSEQ SQL_GREATEQ SQL_NOTEQUAL SQL_LESS SQL_GREAT SQL_EQUAL
/* '<' '>' = <> < > <= >= != */
192 %left
<pParseNode
> '+' '-' SQL_CONCAT
193 %left
<pParseNode
> '*' '/'
194 %left SQL_TOKEN_NATURAL SQL_TOKEN_CROSS SQL_TOKEN_FULL SQL_TOKEN_LEFT SQL_TOKEN_RIGHT
201 %token
<pParseNode
> SQL_TOKEN_INVALIDSYMBOL
203 /*%type <pParseNode> sql_single_statement */
205 %type
<pParseNode
> sql
/*schema */
206 %type
<pParseNode
> column_def_opt_list column_def_opt table_constraint_def column_commalist
207 %type
<pParseNode
> view_def opt_with_check_option opt_column_commalist privilege_def
208 %type
<pParseNode
> opt_with_grant_option privileges operation_commalist operation
209 %type
<pParseNode
> grantee_commalist grantee opt_order_by_clause ordering_spec_commalist
210 %type
<pParseNode
> ordering_spec opt_asc_desc manipulative_statement commit_statement
211 %type
<pParseNode
> /*delete_statement_positioned*/ delete_statement_searched fetch_statement
212 %type
<pParseNode
> insert_statement values_or_query_spec
213 %type
<pParseNode
> rollback_statement select_statement_into opt_all_distinct
214 %type
<pParseNode
> /*update_statement_positioned*/ assignment_commalist assignment
215 %type
<pParseNode
> update_statement_searched target_commalist target opt_where_clause
216 %type
<pParseNode
> select_statement selection table_exp from_clause table_ref_commalist table_ref
217 %type
<pParseNode
> where_clause opt_group_by_clause column_ref_commalist opt_having_clause
218 %type
<pParseNode
> search_condition predicate comparison_predicate comparison_predicate_part_2 between_predicate between_predicate_part_2
219 %type
<pParseNode
> like_predicate opt_escape test_for_null null_predicate_part_2 in_predicate in_predicate_part_2 character_like_predicate_part_2 other_like_predicate_part_2
220 %type
<pParseNode
> all_or_any_predicate any_all_some existence_test subquery quantified_comparison_predicate_part_2
221 %type
<pParseNode
> scalar_exp_commalist parameter_ref literal parenthesized_boolean_value_expression
222 %type
<pParseNode
> column_ref data_type column cursor parameter range_variable user
/*like_check*/ datetime_unit
223 /* new rules at OJ */
224 %type
<pParseNode
> derived_column as_clause table_name num_primary term num_value_exp
225 %type
<pParseNode
> value_exp_primary num_value_fct unsigned_value_spec cast_spec set_fct_spec scalar_subquery
226 %type
<pParseNode
> position_exp extract_exp length_exp general_value_spec
227 %type
<pParseNode
> general_set_fct set_fct_type query_exp non_join_query_exp joined_table
228 %type
<pParseNode
> non_join_query_term non_join_query_primary simple_table
229 %type
<pParseNode
> table_value_const_list row_value_constructor
/*row_value_const_list*/ row_value_constructor_elem
230 %type
<pParseNode
> qualified_join value_exp query_term join_type outer_join_type join_condition boolean_term
231 %type
<pParseNode
> boolean_factor boolean_primary named_columns_join join_spec
232 %type
<pParseNode
> cast_operand cast_target factor datetime_value_exp
/*interval_value_exp*/ datetime_term datetime_factor
233 %type
<pParseNode
> datetime_primary datetime_value_fct time_zone time_zone_specifier
/*interval_term*/ interval_qualifier
234 %type
<pParseNode
> start_field non_second_datetime_field end_field single_datetime_field extract_field datetime_field time_zone_field
235 %type
<pParseNode
> char_length_exp octet_length_exp bit_length_exp select_sublist string_value_exp
236 %type
<pParseNode
> char_value_exp concatenation char_factor char_primary string_value_fct char_substring_fct
237 %type
<pParseNode
> form_conversion char_translation trim_fct trim_operands trim_spec bit_value_fct bit_substring_fct op_column_commalist
238 %type
<pParseNode
> /*bit_concatenation*/ bit_value_exp bit_factor bit_primary collate_clause char_value_fct unique_spec value_exp_commalist in_predicate_value unique_test update_source
239 %type
<pParseNode
> function_arg_commalist3 string_function_3Argument function_arg_commalist4 string_function_4Argument function_arg_commalist2 string_function_1Argument string_function_2Argument
240 %type
<pParseNode
> date_function_0Argument date_function_1Argument function_name12 function_name23 function_name1 function_name2 function_name3 function_name0 numeric_function_0Argument numeric_function_1Argument numeric_function_2Argument
241 %type
<pParseNode
> all query_primary sql_not for_length comparison column_val cross_union
/*opt_schema_element_list*/
242 %type
<pParseNode
> /*op_authorization op_schema*/ nil_fkt schema_element base_table_def base_table_element base_table_element_commalist
243 %type
<pParseNode
> column_def odbc_fct_spec odbc_call_spec odbc_fct_type op_parameter union_statement
244 %type
<pParseNode
> op_odbc_call_parameter odbc_parameter_commalist odbc_parameter function_args_commalist function_arg
245 %type
<pParseNode
> catalog_name schema_name table_node numeric_function string_function function_name date_function table_primary_as_range_column opt_as
246 %type
<pParseNode
> ordered_set_function inverse_distribution_function hypothetical_set_function hypothetical_set_function_value_expression_list rank_function_type within_group_specification inverse_distribution_function_type array_aggregate_function inverse_distribution_function_argument
247 %type
<pParseNode
> case_expression else_clause result_expression result case_abbreviation case_specification searched_when_clause simple_when_clause searched_case simple_case
248 %type
<pParseNode
> when_operand_list when_operand case_operand
249 %type
<pParseNode
> trigger_definition trigger_name trigger_action_time trigger_event transition_table_or_variable_list triggered_action trigger_column_list triggered_when_clause triggered_SQL_statement SQL_procedure_statement old_transition_variable_name new_transition_variable_name
250 %type
<pParseNode
> op_referencing op_trigger_columnlist op_triggered_action_for opt_row trigger_for SQL_procedure_statement_list transition_table_or_variable old_transition_table_name new_transition_table_name transition_table_name
251 %type
<pParseNode
> searched_when_clause_list simple_when_clause_list predefined_type opt_char_set_spec opt_collate_clause character_string_type national_character_string_type
252 %type
<pParseNode
> binary_string_type numeric_type boolean_type datetime_type interval_type opt_paren_precision paren_char_length opt_paren_char_large_length paren_character_large_object_length
253 %type
<pParseNode
> large_object_length opt_multiplier character_large_object_type national_character_large_object_type binary_large_object_string_type opt_with_or_without_time_zone
254 %type
<pParseNode
> approximate_numeric_type exact_numeric_type opt_paren_precision_scale
255 /* window function rules */
256 %type
<pParseNode
> window_function window_function_type ntile_function number_of_tiles lead_or_lag_function lead_or_lag lead_or_lag_extent offset default_expression null_treatment
257 %type
<pParseNode
> first_or_last_value_function first_or_last_value nth_value_function nth_row from_first_or_last window_name_or_specification in_line_window_specification opt_lead_or_lag_function
258 %type
<pParseNode
> opt_null_treatment opt_from_first_or_last simple_value_specification dynamic_parameter_specification window_name window_clause window_definition_list window_definition
259 %type
<pParseNode
> new_window_name existing_window_name window_partition_clause window_partition_column_reference_list window_partition_column_reference window_frame_clause
260 %type
<pParseNode
> window_frame_units window_frame_extent window_frame_start window_frame_preceding window_frame_between window_frame_bound_1 window_frame_bound_2 window_frame_bound window_frame_following window_frame_exclusion
261 %type
<pParseNode
> opt_window_frame_clause opt_window_partition_clause opt_existing_window_name window_specification opt_window_frame_exclusion opt_window_clause opt_offset
262 %type
<pParseNode
> opt_fetch_first_row_count fetch_first_clause offset_row_count fetch_first_row_count first_or_next row_or_rows opt_result_offset_clause result_offset_clause
263 /* LIMIT and OFFSET */
264 %type
<pParseNode
> opt_limit_offset_clause limit_offset_clause opt_fetch_first_clause
267 /* Return Parse Tree to OSQLParser
268 * (the access over yyval after calling the parser fails,
271 sql_single_statement:
273 { xxx_pGLOBAL_SQLPARSER
->setParseTree
( $1 ); }
275 { xxx_pGLOBAL_SQLPARSER
->setParseTree
( $1 ); }
278 /* schema definition language */
279 /* Note: other ``sql:sal_Unicode() rules appear later in the grammar */
282 manipulative_statement
294 | SQL_TOKEN_AUTHORIZATION user
304 | SQL_TOKEN_NAME '.' SQL_TOKEN_NAME
308 $$->append(newNode(".", SQLNodeType::Punctuation));
314 SQL_TOKEN_CREATE SQL_TOKEN_SCHEMA op_schema op_authorization opt_schema_element_list
325 opt_schema_element_list:
327 | schema_element_list
332 {$$ = SQL_NEW_LISTRULE;
334 | schema_element_list schema_element
348 SQL_TOKEN_CREATE SQL_TOKEN_TABLE table_node
'(' base_table_element_commalist
')'
353 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
355 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));}
358 base_table_element_commalist:
360 {$$
= SQL_NEW_COMMALISTRULE
;
362 | base_table_element_commalist
',' base_table_element
369 | table_constraint_def
373 column data_type column_def_opt_list
382 /* empty */ {$$
= SQL_NEW_LISTRULE
;}
383 | column_def_opt_list column_def_opt
393 | SQL_TOKEN_PRIMARY SQL_TOKEN_KEY
401 SQL_TOKEN_NOT SQL_TOKEN_NULL
406 | SQL_TOKEN_DEFAULT literal
410 | SQL_TOKEN_DEFAULT SQL_TOKEN_NULL
414 | SQL_TOKEN_DEFAULT SQL_TOKEN_USER
418 | SQL_TOKEN_DEFAULT nil_fkt
425 | SQL_TOKEN_CHECK
'(' search_condition
')'
428 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
430 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));}
431 | SQL_TOKEN_REFERENCES table_node
435 | SQL_TOKEN_REFERENCES table_node
'(' column_commalist
')'
439 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
441 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));}
444 table_constraint_def:
445 unique_spec
'(' column_commalist
')'
448 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
450 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));}
451 | SQL_TOKEN_FOREIGN SQL_TOKEN_KEY
'(' column_commalist
')' SQL_TOKEN_REFERENCES table_node
455 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
457 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
460 | SQL_TOKEN_FOREIGN SQL_TOKEN_KEY
'(' column_commalist
')' SQL_TOKEN_REFERENCES table_node
'(' column_commalist
')'
464 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
466 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
469 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
471 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));}
472 | SQL_TOKEN_CHECK
'(' search_condition
')'
475 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
477 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));}
480 /* empty */ {$$
= SQL_NEW_RULE
;}
481 |
'(' column_commalist
')'
483 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
485 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
489 column_commalist
',' column
493 {$$
= SQL_NEW_COMMALISTRULE
;
498 SQL_TOKEN_CREATE SQL_TOKEN_VIEW table_node opt_column_commalist SQL_TOKEN_AS select_statement opt_with_check_option
509 opt_with_check_option:
510 /* empty */ {$$
= SQL_NEW_RULE
;}
511 | SQL_TOKEN_WITH SQL_TOKEN_CHECK SQL_TOKEN_OPTION
518 opt_column_commalist:
519 /* empty */ {$$
= SQL_NEW_RULE
;}
520 |
'(' column_commalist
')'
522 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
524 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));}
528 SQL_TOKEN_GRANT privileges SQL_TOKEN_ON table_node SQL_TOKEN_TO grantee_commalist
529 opt_with_grant_option
540 opt_with_grant_option:
541 /* empty */ {$$
= SQL_NEW_RULE
;}
542 | SQL_TOKEN_WITH SQL_TOKEN_GRANT SQL_TOKEN_OPTION
550 SQL_TOKEN_ALL SQL_TOKEN_PRIVILEGES
554 | operation_commalist
559 {$$
= SQL_NEW_COMMALISTRULE
;
561 | operation_commalist
',' operation
568 | SQL_TOKEN_INSERT opt_column_commalist
573 | SQL_TOKEN_UPDATE opt_column_commalist
577 | SQL_TOKEN_REFERENCES opt_column_commalist
587 {$$
= SQL_NEW_COMMALISTRULE
;
589 | grantee_commalist
',' grantee
599 /* module language */
602 /* empty */ {$$
= SQL_NEW_RULE
;}
603 | SQL_TOKEN_ORDER SQL_TOKEN_BY ordering_spec_commalist
610 ordering_spec_commalist:
612 {$$
= SQL_NEW_COMMALISTRULE
;
614 | ordering_spec_commalist
',' ordering_spec
620 /* SQL_TOKEN_INTNUM opt_asc_desc
625 predicate opt_asc_desc
630 | row_value_constructor_elem opt_asc_desc
644 manipulative_statement_list:
645 manipulative_statement
646 {$$ = SQL_NEW_LISTRULE;
648 | manipulative_statement_list manipulative_statement
660 /* manipulative statements */
662 manipulative_statement:
664 /* | delete_statement_positioned*/
665 | delete_statement_searched
669 | select_statement_into
670 /* | update_statement_positioned*/
671 | update_statement_searched
673 |
'{' odbc_call_spec
'}'
676 $$
->append
(newNode
("{", SQLNodeType
::Punctuation
));
678 $$
->append
(newNode
("}", SQLNodeType
::Punctuation
));
684 | union_statement SQL_TOKEN_UNION all select_statement
694 SQL_TOKEN_COMMIT SQL_TOKEN_WORK
700 delete_statement_positioned:
701 SQL_TOKEN_DELETE SQL_TOKEN_FROM table_node SQL_TOKEN_WHERE SQL_TOKEN_CURRENT SQL_TOKEN_OF cursor
712 delete_statement_searched:
713 SQL_TOKEN_DELETE SQL_TOKEN_FROM table_node opt_where_clause
722 SQL_TOKEN_FETCH cursor SQL_TOKEN_INTO target_commalist
731 SQL_TOKEN_INSERT SQL_TOKEN_INTO table_node opt_column_commalist query_exp
739 values_or_query_spec:
740 SQL_TOKEN_VALUES
'(' table_value_const_list
')'
743 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
745 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
749 table_value_const_list:
750 row_value_constructor
751 {$$
= SQL_NEW_COMMALISTRULE
;
753 | table_value_const_list
',' row_value_constructor
758 row_value_const_list:
759 row_value_constructor_elem
760 {$$ = SQL_NEW_COMMALISTRULE;
762 | row_value_const_list ',' row_value_constructor_elem
767 row_value_constructor:
768 row_value_constructor_elem
769 /* | '(' row_value_const_list ')'
772 $$->append(newNode("(", SQLNodeType::Punctuation));
774 $$->append(newNode(")", SQLNodeType::Punctuation));
778 row_value_constructor_elem:
785 SQL_TOKEN_ROLLBACK SQL_TOKEN_WORK
792 /* INTO target_commalist herausgenommen */
793 select_statement_into:
794 SQL_TOKEN_SELECT opt_all_distinct selection SQL_TOKEN_INTO target_commalist table_exp
811 update_statement_positioned:
812 SQL_TOKEN_UPDATE table_node SQL_TOKEN_SET assignment_commalist
813 SQL_TOKEN_WHERE SQL_TOKEN_CURRENT SQL_TOKEN_OF cursor
825 assignment_commalist:
827 {$$
= SQL_NEW_COMMALISTRULE
;
829 | assignment_commalist
',' assignment
835 column SQL_EQUAL update_source
845 update_statement_searched:
846 SQL_TOKEN_UPDATE table_node SQL_TOKEN_SET assignment_commalist opt_where_clause
857 {$$
= SQL_NEW_COMMALISTRULE
;
859 | target_commalist
',' target
869 /* empty */ {$$
= SQL_NEW_RULE
;}
873 /* query expressions */
882 /* SELECT STATEMENT */
884 SQL_TOKEN_SELECT opt_all_distinct selection table_exp
898 $$
->append
(newNode
("*", SQLNodeType
::Punctuation
));
900 | scalar_exp_commalist
902 opt_result_offset_clause:
903 /* empty */ {$$
= SQL_NEW_RULE
;}
904 | result_offset_clause
906 result_offset_clause:
907 SQL_TOKEN_OFFSET offset_row_count row_or_rows
915 opt_fetch_first_row_count:
916 /* empty */ {$$
= SQL_NEW_RULE
;}
917 | fetch_first_row_count
927 opt_fetch_first_clause:
928 /* empty */ {$$
= SQL_NEW_RULE
;}
932 SQL_TOKEN_FETCH first_or_next opt_fetch_first_row_count row_or_rows SQL_TOKEN_ONLY
945 fetch_first_row_count:
949 opt_limit_offset_clause:
950 /* empty */ {$$
= SQL_NEW_RULE
;}
951 | limit_offset_clause
954 /* empty */ {$$
= SQL_NEW_RULE
;}
955 | SQL_TOKEN_OFFSET SQL_TOKEN_INTNUM
963 SQL_TOKEN_LIMIT SQL_TOKEN_INTNUM opt_offset
972 from_clause opt_where_clause opt_group_by_clause opt_having_clause opt_window_clause opt_order_by_clause opt_limit_offset_clause opt_result_offset_clause opt_fetch_first_clause
988 SQL_TOKEN_FROM table_ref_commalist
997 { $$
= SQL_NEW_COMMALISTRULE
;
999 | table_ref_commalist
',' table_ref
1005 /* empty */ {$$
= SQL_NEW_RULE
;}
1009 /* empty */ {$$
= SQL_NEW_RULE
;}
1012 table_primary_as_range_column:
1013 {$$
= SQL_NEW_RULE
;}
1014 | opt_as SQL_TOKEN_NAME op_column_commalist
1023 table_node table_primary_as_range_column
1029 | subquery range_variable op_column_commalist
1037 |
'{' SQL_TOKEN_OJ joined_table
'}'
1040 $$
->append
(newNode
("{", SQLNodeType
::Punctuation
));
1043 $$
->append
(newNode
("}", SQLNodeType
::Punctuation
));
1045 |
'(' joined_table
')'
1048 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1050 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1054 SQL_TOKEN_WHERE search_condition
1060 opt_group_by_clause:
1061 /* empty */ {$$
= SQL_NEW_RULE
;}
1062 | SQL_TOKEN_GROUP SQL_TOKEN_BY column_ref_commalist
1069 column_ref_commalist:
1071 {$$
= SQL_NEW_COMMALISTRULE
;
1074 {$$
= SQL_NEW_COMMALISTRULE
;
1076 | column_ref_commalist
',' column_ref
1079 | column_ref_commalist
',' set_fct_spec
1085 /* empty */ {$$
= SQL_NEW_RULE
;}
1086 | SQL_TOKEN_HAVING search_condition
1092 /* search conditions */
1095 |
'(' search_condition
')'
1096 { // boolean_primary: rule 2
1098 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1100 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1102 | row_value_constructor_elem
/*[^')' ',']*/
1104 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
())// boolean_primary: rule 3
1108 if
( SQL_ISTOKEN
( $1, NULL
))
1110 OSQLParseNode
* pColumnRef
= newNode
("", SQLNodeType
::Rule
,OSQLParser
::RuleID
(OSQLParseNode
::column_ref
));
1111 pColumnRef
->append
(newNode
(xxx_pGLOBAL_SQLPARSER
->getFieldName
(),SQLNodeType
::Name
));
1112 OSQLParseNode
* pTFN
= new OSQLInternalNode
("", SQLNodeType
::Rule
,OSQLParser
::RuleID
(OSQLParseNode
::test_for_null
));
1113 pTFN
->append
(pColumnRef
);
1115 OSQLParseNode
* pNPP2
= new OSQLInternalNode
("", SQLNodeType
::Rule
, OSQLParser
::RuleID
(OSQLParseNode
::null_predicate_part_2
));
1116 pNPP2
->append
(new OSQLInternalNode
("", SQLNodeType
::Keyword
, SQL_TOKEN_IS
));
1117 pNPP2
->append
(new OSQLInternalNode
("", SQLNodeType
::Rule
, OSQLParser
::RuleID
(OSQLParseNode
::sql_not
)));
1118 pNPP2
->append
(new OSQLInternalNode
("", SQLNodeType
::Keyword
, SQL_TOKEN_NULL
));
1119 pTFN
->append
(pNPP2
);
1127 nErg
= xxx_pGLOBAL_SQLPARSER
->buildComparisonRule
($$
,$1);
1131 OSQLParseNode
* pTemp
= $$
;
1132 $$
= pTemp
->removeAt
((sal_uInt32
)0);
1148 parenthesized_boolean_value_expression:
1149 '(' search_condition
')'
1150 { // boolean_primary: rule 2
1152 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1154 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1158 boolean_primary %dprec
2
1159 | SQL_TOKEN_NOT boolean_primary %dprec
1
1160 { // boolean_factor: rule 1
1168 | boolean_term SQL_TOKEN_AND boolean_factor
1170 $$
= SQL_NEW_RULE
; // boolean_term: rule 1
1178 | search_condition SQL_TOKEN_OR boolean_term
1180 $$
= SQL_NEW_RULE
; // search_condition
1187 comparison_predicate %dprec
1
1189 | all_or_any_predicate
1192 | test_for_null %dprec
2
1196 comparison_predicate_part_2:
1197 comparison row_value_constructor
1199 $$
= SQL_NEW_RULE
; // comparison_predicate: rule 1
1203 comparison_predicate:
1204 row_value_constructor comparison row_value_constructor
1206 $$
= SQL_NEW_RULE
; // comparison_predicate: rule 1
1211 | comparison row_value_constructor
1213 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
()) // comparison_predicate: rule 2
1216 sal_Int16 nErg
= xxx_pGLOBAL_SQLPARSER
->buildPredicateRule
($$
,$2,$1);
1219 OSQLParseNode
* pTemp
= $$
;
1220 $$
= pTemp
->removeAt
((sal_uInt32
)0);
1242 | SQL_TOKEN_IS sql_not SQL_TOKEN_DISTINCT SQL_TOKEN_FROM
1250 | SQL_TOKEN_IS sql_not
1257 between_predicate_part_2:
1258 sql_not SQL_TOKEN_BETWEEN row_value_constructor SQL_TOKEN_AND row_value_constructor
1260 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
()) // between_predicate: rule 2
1264 sal_Int16 nErg
= xxx_pGLOBAL_SQLPARSER
->buildPredicateRule
($$
,$3,$2,$5);
1267 OSQLParseNode
* pTemp
= $$
;
1268 $$
= pTemp
->removeAt
((sal_uInt32
)0);
1269 OSQLParseNode
* pColumnRef
= $$
->removeAt
((sal_uInt32
)0);
1271 OSQLParseNode
* pBetween_predicate
= new OSQLInternalNode
("", SQLNodeType
::Rule
,OSQLParser
::RuleID
(OSQLParseNode
::between_predicate
));
1272 pBetween_predicate
->append
(pColumnRef
);
1273 pBetween_predicate
->append
($$
);
1274 $$
= pBetween_predicate
;
1287 $$
= SQL_NEW_RULE
; // between_predicate: rule 1
1296 row_value_constructor between_predicate_part_2
1298 $$
= SQL_NEW_RULE
; // between_predicate: rule 1
1302 | between_predicate_part_2
1304 character_like_predicate_part_2:
1305 sql_not SQL_TOKEN_LIKE string_value_exp opt_escape
1307 $$
= SQL_NEW_RULE
; // like_predicate: rule 1
1314 other_like_predicate_part_2:
1315 sql_not SQL_TOKEN_LIKE value_exp_primary opt_escape
1317 $$
= SQL_NEW_RULE
; // like_predicate: rule 1
1325 row_value_constructor character_like_predicate_part_2
1327 $$
= SQL_NEW_RULE
; // like_predicate: rule 1
1331 | row_value_constructor other_like_predicate_part_2
1333 $$
= SQL_NEW_RULE
; // like_predicate: rule 3
1337 | character_like_predicate_part_2
1339 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
()) // like_predicate: rule 5
1341 OSQLParseNode
* pColumnRef
= newNode
("", SQLNodeType
::Rule
,OSQLParser
::RuleID
(OSQLParseNode
::column_ref
));
1342 pColumnRef
->append
(newNode
(xxx_pGLOBAL_SQLPARSER
->getFieldName
(),SQLNodeType
::Name
));
1345 $$
->append
(pColumnRef
);
1347 OSQLParseNode
* p2nd
= $1->removeAt
(2);
1348 OSQLParseNode
* p3rd
= $1->removeAt
(2);
1349 if
( !xxx_pGLOBAL_SQLPARSER
->buildLikeRule
($1,p2nd
,p3rd
) )
1359 | other_like_predicate_part_2
1361 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
()) // like_predicate: rule 6
1363 OSQLParseNode
* pColumnRef
= newNode
("", SQLNodeType
::Rule
,OSQLParser
::RuleID
(OSQLParseNode
::column_ref
));
1364 pColumnRef
->append
(newNode
(xxx_pGLOBAL_SQLPARSER
->getFieldName
(),SQLNodeType
::Name
));
1367 $$
->append
(pColumnRef
);
1369 OSQLParseNode
* p2nd
= $1->removeAt
(2);
1370 OSQLParseNode
* p3rd
= $1->removeAt
(2);
1371 if
( !xxx_pGLOBAL_SQLPARSER
->buildLikeRule
($1,p2nd
,p3rd
) )
1384 /* empty */ {$$
= SQL_NEW_RULE
;}
1385 | SQL_TOKEN_ESCAPE string_value_exp
1389 |
'{' SQL_TOKEN_ESCAPE SQL_TOKEN_STRING
'}'
1392 $$
->append
(newNode
("{", SQLNodeType
::Punctuation
));
1395 $$
->append
(newNode
("}", SQLNodeType
::Punctuation
));
1399 null_predicate_part_2:
1400 SQL_TOKEN_IS sql_not SQL_TOKEN_NULL
1402 $$
= SQL_NEW_RULE
; // test_for_null: rule 1
1407 | SQL_TOKEN_IS sql_not SQL_TOKEN_UNKNOWN
1409 $$
= SQL_NEW_RULE
; // test_for_null: rule 1
1416 row_value_constructor null_predicate_part_2
1418 $$
= SQL_NEW_RULE
; // test_for_null: rule 1
1422 | null_predicate_part_2
1424 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
())// test_for_null: rule 2
1426 OSQLParseNode
* pColumnRef
= newNode
("", SQLNodeType
::Rule
,OSQLParser
::RuleID
(OSQLParseNode
::column_ref
));
1427 pColumnRef
->append
(newNode
(xxx_pGLOBAL_SQLPARSER
->getFieldName
(),SQLNodeType
::Name
));
1430 $$
->append
(pColumnRef
);
1442 |
'(' value_exp_commalist
')'
1444 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1446 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1449 in_predicate_part_2:
1450 sql_not SQL_TOKEN_IN in_predicate_value
1452 $$
= SQL_NEW_RULE
;// in_predicate: rule 1
1459 row_value_constructor in_predicate_part_2
1461 $$
= SQL_NEW_RULE
;// in_predicate: rule 1
1465 | in_predicate_part_2
1467 if
( xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
() )// in_predicate: rule 2
1469 OSQLParseNode
* pColumnRef
= newNode
("", SQLNodeType
::Rule
,OSQLParser
::RuleID
(OSQLParseNode
::column_ref
));
1470 pColumnRef
->append
(newNode
(xxx_pGLOBAL_SQLPARSER
->getFieldName
(),SQLNodeType
::Name
));
1473 $$
->append
(pColumnRef
);
1480 quantified_comparison_predicate_part_2:
1481 comparison any_all_some subquery
1489 all_or_any_predicate:
1490 row_value_constructor quantified_comparison_predicate_part_2
1496 | quantified_comparison_predicate_part_2
1498 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
())
1500 OSQLParseNode
* pColumnRef
= newNode
("", SQLNodeType
::Rule
,OSQLParser
::RuleID
(OSQLParseNode
::column_ref
));
1501 pColumnRef
->append
(newNode
(xxx_pGLOBAL_SQLPARSER
->getFieldName
(),SQLNodeType
::Name
));
1504 $$
->append
(pColumnRef
);
1519 SQL_TOKEN_EXISTS subquery
1525 SQL_TOKEN_UNIQUE subquery
1533 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1535 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));}
1538 /* scalar expressions */
1539 scalar_exp_commalist:
1542 $$
= SQL_NEW_COMMALISTRULE
;
1545 | scalar_exp_commalist
',' select_sublist
1552 /* table_node '.' '*'
1556 $$->append(newNode(".", SQLNodeType::Punctuation));
1557 $$->append(newNode("*", SQLNodeType::Punctuation));
1572 $$ = newNode("*", SQLNodeType::Punctuation);
1576 $$ = newNode("?", SQLNodeType::Punctuation);
1582 $$->append(newNode("*", SQLNodeType::Punctuation));
1583 xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_False);
1589 $$->append(newNode("?", SQLNodeType::Punctuation));
1590 xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_False);
1598 | SQL_TOKEN_REAL_NUM
1600 | SQL_TOKEN_APPROXNUM
1601 | SQL_TOKEN_ACCESS_DATE
1602 /* rules for predicate check */
1603 | literal SQL_TOKEN_STRING
1605 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
())
1610 OSQLParser
::reduceLiteral
($$
, true
);
1615 | literal SQL_TOKEN_INT
1617 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
())
1622 OSQLParser
::reduceLiteral
($$
, true
);
1627 | literal SQL_TOKEN_REAL_NUM
1629 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
())
1634 OSQLParser
::reduceLiteral
($$
, true
);
1639 | literal SQL_TOKEN_APPROXNUM
1641 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
())
1646 OSQLParser
::reduceLiteral
($$
, true
);
1655 /* empty */ {$$
= SQL_NEW_RULE
;}
1656 | SQL_TOKEN_AS column
1665 SQL_TOKEN_POSITION
'(' value_exp SQL_TOKEN_IN value_exp
')'
1669 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1673 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1675 | SQL_TOKEN_POSITION
'(' value_exp_commalist
')'
1679 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1681 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1690 SQL_TOKEN_CHAR_LENGTH
'(' value_exp
')'
1694 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1696 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1698 | SQL_TOKEN_SQL_TOKEN_INTNUM
'(' value_exp
')'
1702 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1704 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1709 SQL_TOKEN_OCTET_LENGTH
'(' value_exp
')'
1713 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1715 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1719 SQL_TOKEN_BIT_LENGTH
'(' value_exp
')'
1723 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1725 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1746 non_second_datetime_field
1763 SQL_TOKEN_TIMEZONE_HOUR
1768 | SQL_TOKEN_TIMEZONE_MINUTE
1775 SQL_TOKEN_EXTRACT
'(' extract_field SQL_TOKEN_FROM value_exp
')'
1779 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1783 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1786 unsigned_value_spec:
1797 | SQL_TOKEN_CURRENT_CATALOG
1798 | SQL_TOKEN_CURRENT_DEFAULT_TRANSFORM_GROUP
1799 | SQL_TOKEN_CURRENT_PATH
1800 | SQL_TOKEN_CURRENT_ROLE
1801 | SQL_TOKEN_CURRENT_SCHEMA
1802 | SQL_TOKEN_CURRENT_USER
1803 | SQL_TOKEN_SESSION_USER
1804 | SQL_TOKEN_SYSTEM_USER
1808 |
'{' odbc_fct_spec
'}'
1811 $$
->append
(newNode
("{", SQLNodeType
::Punctuation
));
1813 $$
->append
(newNode
("}", SQLNodeType
::Punctuation
));
1815 | function_name
'(' ')'
1819 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1820 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1822 | function_name0
'(' ')'
1826 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1827 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1829 | function_name1
'(' function_arg
')'
1833 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1835 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1837 | function_name2
'(' function_arg_commalist2
')'
1841 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1843 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1845 | function_name3
'(' function_arg_commalist3
')'
1849 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1851 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1853 | string_function_4Argument
'(' function_arg_commalist4
')'
1857 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1859 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1861 | function_name
'(' function_args_commalist
')'
1865 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1867 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1869 | function_name12
'(' function_args_commalist
')'
1871 if
( $3->count
() == 1 ||
$3->count
() == 2 )
1875 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1877 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1882 | function_name23
'(' function_args_commalist
')'
1884 if
( $3->count
() == 2 ||
$3->count
() == 3)
1888 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1890 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1897 date_function_0Argument
1898 | numeric_function_0Argument
1901 string_function_1Argument
1902 | date_function_1Argument
1903 | numeric_function_1Argument
1906 string_function_2Argument
1907 | numeric_function_2Argument
1917 | SQL_TOKEN_DATEDIFF
1920 string_function_3Argument
1928 string_function_1Argument:
1940 string_function_2Argument:
1945 string_function_3Argument:
1948 string_function_4Argument:
1955 | SQL_TOKEN_DIFFERENCE
1956 | SQL_TOKEN_LOCATE_2
1959 date_function_0Argument:
1964 date_function_1Argument:
1966 | SQL_TOKEN_DAYOFMONTH
1967 | SQL_TOKEN_DAYOFYEAR
1970 | SQL_TOKEN_MONTHNAME
1977 | SQL_TOKEN_TIMEVALUE
1978 | SQL_TOKEN_DATEVALUE
1982 SQL_TOKEN_TIMESTAMPADD
1983 | SQL_TOKEN_TIMESTAMPDIFF
1986 numeric_function_0Argument:
1989 numeric_function_1Argument:
2007 | SQL_TOKEN_ROUNDMAGIC
2009 numeric_function_2Argument:
2016 | SQL_TOKEN_TRUNCATE
2020 window_function_type SQL_TOKEN_OVER window_name_or_specification
2028 window_function_type
:
2029 rank_function_type
'(' ')'
2033 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2034 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2036 | SQL_TOKEN_ROW_NUMBER
'(' ')'
2040 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2041 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2045 | lead_or_lag_function
2046 | first_or_last_value_function
2047 | nth_value_function
2050 SQL_TOKEN_NTILE
'(' number_of_tiles
')'
2054 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2056 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2059 dynamic_parameter_specification:
2062 simple_value_specification:
2066 simple_value_specification
2067 | dynamic_parameter_specification
2069 opt_lead_or_lag_function:
2070 /* empty */ {$$
= SQL_NEW_RULE
;}
2074 $$
->append
(newNode
(",", SQLNodeType
::Punctuation
));
2077 |
',' offset
',' default_expression
2080 $$
->append
(newNode
(",", SQLNodeType
::Punctuation
));
2082 $$
->append
(newNode
(",", SQLNodeType
::Punctuation
));
2087 /* empty */ {$$
= SQL_NEW_RULE
;}
2091 lead_or_lag_function:
2092 lead_or_lag
'(' lead_or_lag_extent opt_lead_or_lag_function
')' opt_null_treatment
2096 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2099 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2117 SQL_TOKEN_RESPECT SQL_TOKEN_NULLS
2118 | SQL_TOKEN_IGNORE SQL_TOKEN_NULLS
2120 first_or_last_value_function:
2121 first_or_last_value
'(' value_exp
')' opt_null_treatment
2125 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2127 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2131 first_or_last_value
:
2132 SQL_TOKEN_FIRST_VALUE
2133 | SQL_TOKEN_LAST_VALUE
2135 opt_from_first_or_last:
2136 /* empty */ {$$
= SQL_NEW_RULE
;}
2137 | from_first_or_last
2140 SQL_TOKEN_NTH_VALUE
'(' value_exp
',' nth_row
')' opt_from_first_or_last opt_null_treatment
2144 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2146 $$
->append
(newNode
(",", SQLNodeType
::Punctuation
));
2148 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2154 simple_value_specification
2155 | dynamic_parameter_specification
2158 SQL_TOKEN_FROM SQL_TOKEN_FIRST
2164 | SQL_TOKEN_FROM SQL_TOKEN_LAST
2174 window_name_or_specification:
2176 | in_line_window_specification
2178 in_line_window_specification:
2179 window_specification
2182 /* empty */ {$$
= SQL_NEW_RULE
;}
2186 SQL_TOKEN_WINDOW window_definition_list
2193 window_definition_list:
2194 window_definition_list
',' window_definition
2198 {$$
= SQL_NEW_COMMALISTRULE
;
2202 new_window_name SQL_TOKEN_AS window_specification
2213 window_specification:
2215 opt_existing_window_name
2216 opt_window_partition_clause
2218 opt_window_frame_clause
2222 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2227 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2230 opt_existing_window_name:
2231 /* empty */ {$$
= SQL_NEW_RULE
;}
2232 | existing_window_name
2234 opt_window_partition_clause:
2235 /* empty */ {$$
= SQL_NEW_RULE
;}
2236 | window_partition_clause
2238 opt_window_frame_clause:
2239 /* empty */ {$$
= SQL_NEW_RULE
;}
2240 | window_frame_clause
2242 existing_window_name:
2245 window_partition_clause:
2246 SQL_TOKEN_PARTITION SQL_TOKEN_BY window_partition_column_reference_list
2254 window_partition_column_reference_list:
2255 window_partition_column_reference_list
',' window_partition_column_reference
2258 | window_partition_column_reference
2259 {$$
= SQL_NEW_COMMALISTRULE
;
2262 window_partition_column_reference:
2263 column_ref opt_collate_clause
2270 opt_window_frame_exclusion:
2271 /* empty */ {$$
= SQL_NEW_RULE
;}
2272 | window_frame_exclusion
2274 window_frame_clause:
2275 window_frame_units window_frame_extent opt_window_frame_exclusion
2287 window_frame_extent:
2289 | window_frame_between
2292 SQL_TOKEN_UNBOUNDED SQL_TOKEN_PRECEDING
2298 | window_frame_preceding
2299 | SQL_TOKEN_CURRENT SQL_TOKEN_ROW
2306 window_frame_preceding:
2307 unsigned_value_spec SQL_TOKEN_PRECEDING
2314 window_frame_between:
2315 SQL_TOKEN_BETWEEN window_frame_bound_1 SQL_TOKEN_AND window_frame_bound_2
2324 window_frame_bound_1:
2327 window_frame_bound_2:
2332 | SQL_TOKEN_UNBOUNDED SQL_TOKEN_FOLLOWING
2338 | window_frame_following
2340 window_frame_following:
2341 unsigned_value_spec SQL_TOKEN_FOLLOWING
2348 window_frame_exclusion:
2349 SQL_TOKEN_EXCLUDE SQL_TOKEN_CURRENT SQL_TOKEN_ROW
2356 | SQL_TOKEN_EXCLUDE SQL_TOKEN_GROUP
2362 | SQL_TOKEN_EXCLUDE SQL_TOKEN_TIES
2368 | SQL_TOKEN_EXCLUDE SQL_TOKEN_NO SQL_TOKEN_OTHERS
2377 {$$
= SQL_NEW_RULE
;}
2381 $$
->append
(newNode
("?", SQLNodeType
::Punctuation
));
2386 op_parameter SQL_TOKEN_CALL table_node op_odbc_call_parameter
2396 op_odbc_call_parameter:
2397 {$$
= SQL_NEW_RULE
;}
2398 |
'(' odbc_parameter_commalist
')'
2401 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2403 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2407 odbc_parameter_commalist:
2409 {$$
= SQL_NEW_COMMALISTRULE
;
2411 | odbc_parameter_commalist
',' odbc_parameter
2418 /* empty */ {$$
= SQL_NEW_RULE
;}
2424 odbc_fct_type SQL_TOKEN_STRING
2430 | SQL_TOKEN_FN set_fct_spec
2445 set_fct_type
'(' opt_all_distinct function_arg
')'
2449 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2452 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2454 | SQL_TOKEN_COUNT
'(' '*' ')'
2458 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2459 $$
->append
(newNode
("*", SQLNodeType
::Punctuation
));
2460 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2462 | SQL_TOKEN_COUNT
'(' opt_all_distinct function_arg
')'
2466 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2469 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2471 | ordered_set_function
2472 | array_aggregate_function
2482 | SQL_TOKEN_STDDEV_POP
2483 | SQL_TOKEN_STDDEV_SAMP
2484 | SQL_TOKEN_VAR_SAMP
2488 | SQL_TOKEN_INTERSECTION
2491 ordered_set_function:
2492 hypothetical_set_function
2493 | inverse_distribution_function
2495 hypothetical_set_function:
2496 rank_function_type
'(' hypothetical_set_function_value_expression_list
')' within_group_specification
2500 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2502 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2505 | rank_function_type
'(' hypothetical_set_function_value_expression_list SQL_TOKEN_BY value_exp_commalist
')' within_group_specification
2509 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2513 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2518 within_group_specification:
2522 | SQL_TOKEN_WITHIN SQL_TOKEN_GROUP
'(' opt_order_by_clause
')'
2527 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2529 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2532 hypothetical_set_function_value_expression_list:
2536 inverse_distribution_function:
2537 inverse_distribution_function_type
'('inverse_distribution_function_argument
')' within_group_specification
2541 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2543 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2546 inverse_distribution_function_argument:
2549 inverse_distribution_function_type:
2550 SQL_TOKEN_PERCENTILE_CONT
2551 | SQL_TOKEN_PERCENTILE_DISC
2554 array_aggregate_function:
2555 SQL_TOKEN_ARRAY_AGG
'(' value_exp opt_order_by_clause
')'
2559 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2562 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2568 | SQL_TOKEN_DENSE_RANK
2569 | SQL_TOKEN_PERCENT_RANK
2570 | SQL_TOKEN_CUME_DIST
2573 SQL_TOKEN_LEFT %prec SQL_TOKEN_LEFT
2578 | SQL_TOKEN_RIGHT %prec SQL_TOKEN_RIGHT
2583 | SQL_TOKEN_FULL %prec SQL_TOKEN_FULL
2590 SQL_TOKEN_ON search_condition
2599 | named_columns_join
2602 /* empty */ {$$
= SQL_NEW_RULE
;}
2609 | outer_join_type SQL_TOKEN_OUTER
2617 table_ref SQL_TOKEN_CROSS SQL_TOKEN_JOIN table_ref
2628 /* when SQL_TOKEN_NATURAL, then no join_spec */
2629 table_ref SQL_TOKEN_NATURAL join_type SQL_TOKEN_JOIN table_ref
2638 | table_ref join_type SQL_TOKEN_JOIN table_ref join_spec
2653 SQL_TOKEN_USING
'(' column_commalist
')'
2657 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2659 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2664 | values_or_query_spec
2667 non_join_query_primary:
2669 |
'(' non_join_query_exp
')'
2672 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2674 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2677 non_join_query_term:
2678 non_join_query_primary
2679 | query_term SQL_TOKEN_INTERSECT all query_primary
2689 non_join_query_primary
2693 | query_exp SQL_TOKEN_UNION all query_term
2701 | query_exp SQL_TOKEN_EXCEPT all query_term
2711 /* empty*/ {$$
= SQL_NEW_RULE
;}
2715 non_join_query_exp
/*[^')']*/
2728 SQL_TOKEN_CAST
'(' cast_operand SQL_TOKEN_AS cast_target
')'
2732 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2736 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2749 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2751 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2762 |
'-' num_primary %prec SQL_TOKEN_UMINUS
2765 $$
->append
(newNode
("-", SQLNodeType
::Punctuation
));
2768 |
'+' num_primary %prec SQL_TOKEN_UMINUS
2771 $$
->append
(newNode
("+", SQLNodeType
::Punctuation
));
2782 $$
->append
(newNode
("*", SQLNodeType
::Punctuation
));
2789 $$
->append
(newNode
("/", SQLNodeType
::Punctuation
));
2796 | num_value_exp
'+' term
2800 $$
->append
(newNode
("+", SQLNodeType
::Punctuation
));
2803 | num_value_exp
'-' term
2807 $$
->append
(newNode
("-", SQLNodeType
::Punctuation
));
2812 /* value_exp_primary
2817 |*/ datetime_value_fct
2824 SQL_TOKEN_CURRENT_DATE
2829 | SQL_TOKEN_CURRENT_TIME
2834 | SQL_TOKEN_CURRENT_TIMESTAMP
2841 SQL_TOKEN_AT time_zone_specifier
2848 time_zone_specifier:
2854 /* | SQL_TOKEN_TIME SQL_TOKEN_ZONE interval_value_exp
2868 | datetime_primary time_zone
2885 | interval_term '*' factor
2889 $$->append(newNode("*", SQLNodeType::Punctuation));
2892 | interval_term '/' factor
2896 $$->append(newNode("/", SQLNodeType::Punctuation));
2907 /* | interval_value_exp '+' datetime_term
2911 $$->append(newNode("+", SQLNodeType::Punctuation));
2914 | datetime_value_exp '+' interval_term
2918 $$->append(newNode("+", SQLNodeType::Punctuation));
2921 | datetime_value_exp '-' interval_term
2925 $$->append(newNode("-", SQLNodeType::Punctuation));
2936 | interval_value_exp '+' interval_term
2940 $$->append(newNode("+", SQLNodeType::Punctuation));
2943 | interval_value_exp '-' interval_term
2947 $$->append(newNode("-", SQLNodeType::Punctuation));
2950 | '(' datetime_value_exp '-' datetime_term ')' interval_qualifier
2953 $$->append(newNode("(", SQLNodeType::Punctuation));
2955 $$->append(newNode("-", SQLNodeType::Punctuation));
2957 $$->append(newNode(")", SQLNodeType::Punctuation));
2962 non_second_datetime_field:
2971 | SQL_TOKEN_MILLISECOND
2982 | SQL_TOKEN_MILLISECOND
2986 non_second_datetime_field opt_paren_precision
2994 non_second_datetime_field
2995 | SQL_TOKEN_SECOND opt_paren_precision
3003 single_datetime_field:
3004 non_second_datetime_field opt_paren_precision
3010 | SQL_TOKEN_SECOND opt_paren_precision_scale
3019 start_field SQL_TOKEN_TO end_field
3026 | single_datetime_field
3029 function_arg_commalist2:
3030 function_arg
',' function_arg
3031 {$$
= SQL_NEW_COMMALISTRULE
;
3035 function_arg_commalist3:
3036 function_arg
',' function_arg
',' function_arg
3038 $$
= SQL_NEW_COMMALISTRULE
;
3044 function_arg_commalist4:
3045 function_arg
',' function_arg
',' function_arg
',' function_arg
3047 $$
= SQL_NEW_COMMALISTRULE
;
3054 value_exp_commalist:
3056 {$$
= SQL_NEW_COMMALISTRULE
;
3058 | value_exp_commalist
',' value_exp
3061 /* this rule is only valid if we check predicates */
3062 | value_exp_commalist
';' value_exp
3064 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
())
3075 | value_exp comparison value_exp
3082 | value_exp SQL_TOKEN_USING value_exp comparison value_exp
3090 | value_exp SQL_TOKEN_BY value_exp_commalist
3098 function_args_commalist:
3100 {$$
= SQL_NEW_COMMALISTRULE
;
3102 | function_args_commalist
',' function_arg
3105 /* this rule is only valid if we check predicates */
3106 | function_args_commalist
';' function_arg
3108 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
())
3116 | datetime_unit
',' function_arg
',' function_arg
3118 $$
= SQL_NEW_COMMALISTRULE
;
3126 num_value_exp
/*[^')']*/
3128 | datetime_value_exp
3147 char_value_exp
'+' char_factor
3151 $$
->append
(newNode
("+", SQLNodeType
::Punctuation
));
3154 | value_exp SQL_CONCAT value_exp
3168 SQL_TOKEN_COLLATE table_node
3177 | char_primary collate_clause
3196 SQL_TOKEN_SUBSTRING
'(' bit_value_exp SQL_TOKEN_FROM string_value_exp for_length
')'
3200 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3205 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3223 bit_value_exp '+' bit_factor
3227 $$->append(newNode("+", SQLNodeType::Punctuation));
3240 {$$
= SQL_NEW_RULE
;}
3241 /* value_exp_primary
3271 {$$
= SQL_NEW_RULE
;}
3272 | SQL_TOKEN_FOR value_exp
3280 SQL_TOKEN_SUBSTRING
'(' value_exp SQL_TOKEN_FROM value_exp for_length
')'
3284 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3289 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3291 | SQL_TOKEN_SUBSTRING
'(' value_exp_commalist
')'
3295 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3297 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3301 SQL_TOKEN_CONVERT
'(' string_value_exp SQL_TOKEN_USING table_node
')'
3305 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3309 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3311 | SQL_TOKEN_CONVERT
'(' cast_operand
',' cast_target
')'
3315 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3317 $$
->append
(newNode
(",", SQLNodeType
::Punctuation
));
3319 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3323 SQL_TOKEN_TRANSLATE
'(' string_value_exp SQL_TOKEN_USING table_node
')'
3327 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3331 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3335 SQL_TOKEN_TRIM
'(' trim_operands
')'
3339 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3341 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3345 trim_spec value_exp SQL_TOKEN_FROM value_exp
3353 | trim_spec SQL_TOKEN_FROM value_exp
3360 | value_exp SQL_TOKEN_FROM value_exp
3367 | SQL_TOKEN_FROM value_exp
3379 | SQL_TOKEN_TRAILING
3397 SQL_TOKEN_NAME
'.' schema_name
3401 $$
->append
(newNode
(".", SQLNodeType
::Punctuation
));
3404 | SQL_TOKEN_NAME
':' schema_name
3408 $$
->append
(newNode
(":", SQLNodeType
::Punctuation
));
3413 SQL_TOKEN_NAME
'.' table_name
3417 $$
->append
(newNode
(".", SQLNodeType
::Punctuation
));
3432 /* | table_node '.' column_val %prec '.'
3435 $$->append(newNode(".", SQLNodeType::Punctuation));
3438 | SQL_TOKEN_NAME
'.' column_val %prec
'.'
3441 $$
->append
(newNode
(".", SQLNodeType
::Punctuation
));
3444 | SQL_TOKEN_NAME
'.' SQL_TOKEN_NAME
'.' column_val %prec
'.'
3447 $$
->append
(newNode
(".", SQLNodeType
::Punctuation
));
3449 $$
->append
(newNode
(".", SQLNodeType
::Punctuation
));
3451 | SQL_TOKEN_NAME
'.' SQL_TOKEN_NAME
'.' SQL_TOKEN_NAME
'.' column_val %prec
'.'
3454 $$
->append
(newNode
(".", SQLNodeType
::Punctuation
));
3456 $$
->append
(newNode
(".", SQLNodeType
::Punctuation
));
3458 $$
->append
(newNode
(".", SQLNodeType
::Punctuation
));
3461 | SQL_TOKEN_NAME
':' SQL_TOKEN_NAME
'.' SQL_TOKEN_NAME
'.' column_val %prec
'.'
3464 $$
->append
(newNode
(":", SQLNodeType
::Punctuation
));
3466 $$
->append
(newNode
(".", SQLNodeType
::Punctuation
));
3468 $$
->append
(newNode
(".", SQLNodeType
::Punctuation
));
3471 /* | SQL_TOKEN_NAME ';' SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val
3474 $$->append(newNode(";", SQLNodeType::Punctuation));
3476 $$->append(newNode(".", SQLNodeType::Punctuation));
3478 $$->append(newNode(".", SQLNodeType::Punctuation));
3491 $$
->append
(newNode
("*", SQLNodeType
::Punctuation
));
3498 {$$
= SQL_NEW_RULE
;}
3499 | SQL_TOKEN_CHARACTER SQL_TOKEN_SET SQL_TOKEN_NAME
3508 {$$
= SQL_NEW_RULE
;}
3512 character_string_type opt_char_set_spec opt_collate_clause
3519 | national_character_string_type opt_collate_clause
3525 | binary_string_type
3531 character_string_type:
3532 SQL_TOKEN_CHARACTER opt_paren_precision
3538 | SQL_TOKEN_CHAR opt_paren_precision
3544 | SQL_TOKEN_CHARACTER SQL_TOKEN_VARYING paren_char_length
3551 | SQL_TOKEN_CHAR SQL_TOKEN_VARYING paren_char_length
3558 | SQL_TOKEN_VARCHAR paren_char_length
3564 | character_large_object_type
3566 opt_paren_precision:
3567 {$$
= SQL_NEW_RULE
;}
3571 '(' SQL_TOKEN_INTNUM
')'
3574 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3576 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3579 opt_paren_char_large_length:
3580 {$$
= SQL_NEW_RULE
;}
3581 | paren_character_large_object_length
3583 paren_character_large_object_length:
3584 '(' large_object_length
')'
3587 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3589 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3593 large_object_length:
3594 SQL_TOKEN_INTNUM opt_multiplier
3602 {$$
= SQL_NEW_RULE
;}
3606 $$
->append
(newNode
("K", SQLNodeType
::Punctuation
));
3611 $$
->append
(newNode
("M", SQLNodeType
::Punctuation
));
3616 $$
->append
(newNode
("G", SQLNodeType
::Punctuation
));
3621 $$
->append
(newNode
("T", SQLNodeType
::Punctuation
));
3626 $$
->append
(newNode
("P", SQLNodeType
::Punctuation
));
3629 character_large_object_type:
3630 SQL_TOKEN_CHARACTER SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3638 | SQL_TOKEN_CHAR SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3646 | SQL_TOKEN_CLOB opt_paren_char_large_length
3653 national_character_string_type:
3654 SQL_TOKEN_NATIONAL SQL_TOKEN_CHARACTER opt_paren_precision
3661 | SQL_TOKEN_NATIONAL SQL_TOKEN_CHAR opt_paren_precision
3668 | SQL_TOKEN_NCHAR opt_paren_precision
3674 | SQL_TOKEN_NATIONAL SQL_TOKEN_CHARACTER SQL_TOKEN_VARYING paren_char_length
3682 | SQL_TOKEN_NATIONAL SQL_TOKEN_CHAR SQL_TOKEN_VARYING paren_char_length
3690 | SQL_TOKEN_NCHAR SQL_TOKEN_VARYING paren_char_length
3697 | national_character_large_object_type
3699 national_character_large_object_type:
3700 SQL_TOKEN_NATIONAL SQL_TOKEN_CHARACTER SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3709 | SQL_TOKEN_NCHAR SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3717 | SQL_TOKEN_NCLOB opt_paren_char_large_length
3725 SQL_TOKEN_BINARY opt_paren_precision
3731 | SQL_TOKEN_BINARY SQL_TOKEN_VARYING paren_char_length
3738 | SQL_TOKEN_VARBINARY paren_char_length
3744 | binary_large_object_string_type
3746 binary_large_object_string_type:
3747 SQL_TOKEN_BINARY SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3755 | SQL_TOKEN_BLOB opt_paren_char_large_length
3764 | approximate_numeric_type
3766 opt_paren_precision_scale:
3767 {$$
= SQL_NEW_RULE
;}
3768 |
'(' SQL_TOKEN_INTNUM
')'
3771 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3773 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3775 |
'(' SQL_TOKEN_INTNUM
',' SQL_TOKEN_INTNUM
')'
3778 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3780 $$
->append
(newNode
(",", SQLNodeType
::Punctuation
));
3782 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3786 SQL_TOKEN_NUMERIC opt_paren_precision_scale
3792 | SQL_TOKEN_DECIMAL opt_paren_precision_scale
3798 | SQL_TOKEN_DEC opt_paren_precision_scale
3804 | SQL_TOKEN_SMALLINT
3809 approximate_numeric_type:
3810 SQL_TOKEN_FLOAT
'(' SQL_TOKEN_INTNUM
')'
3814 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3816 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3821 | SQL_TOKEN_DOUBLE SQL_TOKEN_PRECISION
3833 | SQL_TOKEN_TIME opt_paren_precision opt_with_or_without_time_zone
3840 | SQL_TOKEN_TIMESTAMP opt_paren_precision opt_with_or_without_time_zone
3848 opt_with_or_without_time_zone:
3849 {$$
= SQL_NEW_RULE
;}
3850 | SQL_TOKEN_WITH SQL_TOKEN_TIME SQL_TOKEN_ZONE
3857 | SQL_TOKEN_WITHOUT SQL_TOKEN_TIME SQL_TOKEN_ZONE
3866 SQL_TOKEN_INTERVAL interval_qualifier
3873 /* the various things you can name */
3877 | SQL_TOKEN_POSITION
3879 sal_uInt32 nNod
= $$
->getRuleID
();
3881 $$
= newNode
(OSQLParser
::TokenIDToStr
(nNod
), SQLNodeType
::Name
);
3883 | SQL_TOKEN_CHAR_LENGTH
3885 sal_uInt32 nNod
= $$
->getRuleID
();
3887 $$
= newNode
(OSQLParser
::TokenIDToStr
(nNod
), SQLNodeType
::Name
);
3891 sal_uInt32 nNod
= $$
->getRuleID
();
3893 $$
= newNode
(OSQLParser
::TokenIDToStr
(nNod
), SQLNodeType
::Name
);
3898 | case_specification
3901 SQL_TOKEN_NULLIF
'(' value_exp_commalist
')'
3905 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3907 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3909 | SQL_TOKEN_COALESCE
'(' value_exp
')'
3913 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3915 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3917 | SQL_TOKEN_COALESCE
'(' value_exp_commalist
')'
3921 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3923 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3931 SQL_TOKEN_CASE case_operand simple_when_clause_list else_clause SQL_TOKEN_END
3942 SQL_TOKEN_CASE searched_when_clause_list else_clause SQL_TOKEN_END
3951 simple_when_clause_list:
3954 $$
= SQL_NEW_LISTRULE
;
3957 | searched_when_clause_list simple_when_clause
3964 SQL_TOKEN_WHEN when_operand_list SQL_TOKEN_THEN result
3975 {$$
= SQL_NEW_COMMALISTRULE
;
3977 | when_operand_list
',' when_operand
3982 row_value_constructor_elem
3983 | comparison_predicate_part_2 %dprec
1
3984 | between_predicate_part_2
3985 | in_predicate_part_2
3986 | character_like_predicate_part_2
3987 | null_predicate_part_2 %dprec
2
3989 searched_when_clause_list:
3990 searched_when_clause
3992 $$
= SQL_NEW_LISTRULE
;
3995 | searched_when_clause_list searched_when_clause
4001 searched_when_clause:
4002 SQL_TOKEN_WHEN search_condition SQL_TOKEN_THEN result
4012 {$$
= SQL_NEW_RULE
;}
4013 | SQL_TOKEN_ELSE result
4027 row_value_constructor_elem
4030 cursor: SQL_TOKEN_NAME
4036 module: SQL_TOKEN_NAME
4045 $$
->append
(newNode
(":", SQLNodeType
::Punctuation
));
4048 {$$
= SQL_NEW_RULE
; // test
4049 $$
->append
(newNode
("?", SQLNodeType
::Punctuation
));}
4050 |
'[' SQL_TOKEN_NAME
']'
4052 $$
->append
(newNode
("[", SQLNodeType
::Punctuation
));
4054 $$
->append
(newNode
("]", SQLNodeType
::Punctuation
));}
4058 procedure: SQL_TOKEN_NAME
4065 {$$
= SQL_NEW_RULE
;}
4066 | opt_as SQL_TOKEN_NAME
4073 user: SQL_TOKEN_NAME
4076 /* PREDICATECHECK RULES */
4078 search_condition
/* checking predicats */
4080 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
()) // sql: rule 1
4083 if
( SQL_ISRULE
($$
,search_condition
) )
4085 $$
->insert
(0,newNode
("(", SQLNodeType
::Punctuation
));
4086 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
4092 |
'(' sql
')' /* checking predicats */
4095 SQL_TOKEN_CREATE SQL_TOKEN_TRIGGER trigger_name trigger_action_time trigger_event SQL_TOKEN_ON table_name op_referencing triggered_action
4113 | SQL_TOKEN_REFERENCING transition_table_or_variable_list
4120 trigger_action_time:
4123 | SQL_TOKEN_INSTEAD SQL_TOKEN_OF
4133 | SQL_TOKEN_UPDATE op_trigger_columnlist
4140 op_trigger_columnlist:
4144 | SQL_TOKEN_OF trigger_column_list
4151 trigger_column_list:
4155 op_triggered_action_for triggered_when_clause triggered_SQL_statement
4163 op_triggered_action_for:
4167 | SQL_TOKEN_FOR SQL_TOKEN_EACH trigger_for
4177 | SQL_TOKEN_STATEMENT
4179 triggered_when_clause:
4183 | SQL_TOKEN_WHEN parenthesized_boolean_value_expression
4190 triggered_SQL_statement:
4191 SQL_procedure_statement
4192 | SQL_TOKEN_BEGIN SQL_TOKEN_ATOMIC SQL_procedure_statement_list
';' SQL_TOKEN_END
4198 $$
->append
(newNode
(";", SQLNodeType
::Punctuation
));
4202 SQL_procedure_statement_list:
4203 SQL_procedure_statement
4205 $$
= SQL_NEW_LISTRULE
;
4208 | SQL_procedure_statement_list
';' SQL_procedure_statement
4214 SQL_procedure_statement:
4218 transition_table_or_variable_list:
4219 transition_table_or_variable
4221 $$
= SQL_NEW_LISTRULE
;
4224 | transition_table_or_variable_list transition_table_or_variable
4231 transition_table_or_variable:
4232 SQL_TOKEN_OLD opt_row opt_as old_transition_variable_name
4240 | SQL_TOKEN_NEW opt_row opt_as new_transition_variable_name
4248 | SQL_TOKEN_OLD SQL_TOKEN_TABLE opt_as old_transition_table_name
4256 | SQL_TOKEN_NEW SQL_TOKEN_TABLE opt_as new_transition_table_name
4265 old_transition_table_name:
4266 transition_table_name
4268 new_transition_table_name:
4269 transition_table_name
4271 transition_table_name:
4274 old_transition_variable_name:
4277 new_transition_variable_name:
4285 #if defined _MSC_VER
4286 #pragma warning(pop)
4289 using namespace
::com
::sun
::star
::sdbc
;
4290 using namespace
::com
::sun
::star
::beans
;
4291 using namespace
::com
::sun
::star
::uno
;
4292 using namespace
::com
::sun
::star
::i18n
;
4293 using namespace
::com
::sun
::star
::lang
;
4294 using namespace
::com
::sun
::star
::util
;
4295 using namespace
::osl
;
4296 using namespace
::dbtools
;
4298 connectivity::OSQLParser
* xxx_pGLOBAL_SQLPARSER
;
4300 connectivity::OSQLInternalNode
* newNode
(const char* pNewValue
,
4301 const connectivity
::SQLNodeType eNodeType
,
4302 const sal_uInt32 nNodeID
)
4304 return new connectivity
::OSQLInternalNode
(pNewValue
, eNodeType
, nNodeID
);
4307 connectivity::OSQLInternalNode
* newNode
(const OString
& _newValue
,
4308 const connectivity
::SQLNodeType eNodeType
,
4309 const sal_uInt32 nNodeID
)
4311 return new connectivity
::OSQLInternalNode
(_newValue
, eNodeType
, nNodeID
);
4314 connectivity::OSQLInternalNode
* newNode
(const OUString
& _newValue
,
4315 const connectivity
::SQLNodeType eNodeType
,
4316 const sal_uInt32 nNodeID
)
4318 return new connectivity
::OSQLInternalNode
(_newValue
, eNodeType
, nNodeID
);
4321 OParseContext::OParseContext
()
4326 OParseContext::~OParseContext
()
4331 OUString OParseContext
::getErrorMessage
(ErrorCode _eCode
) const
4336 case ErrorCode
::General
: aMsg
= "Syntax error in SQL expression"; break
;
4337 case ErrorCode
::ValueNoLike
: aMsg
= "The value #1 can not be used with LIKE."; break
;
4338 case ErrorCode
::FieldNoLike
: aMsg
= "LIKE can not be used with this field."; break
;
4339 case ErrorCode
::InvalidCompare
: aMsg
= "The entered criterion can not be compared with this field."; break
;
4340 case ErrorCode
::InvalidIntCompare
: aMsg
= "The field can not be compared with a number."; break
;
4341 case ErrorCode
::InvalidDateCompare
: aMsg
= "The field can not be compared with a date."; break
;
4342 case ErrorCode
::InvalidRealCompare
: aMsg
= "The field can not be compared with a floating point number."; break
;
4343 case ErrorCode
::InvalidTableNosuch
: aMsg
= "The database does not contain a table named \"#\"."; break
;
4344 case ErrorCode
::InvalidTableOrQuery
: aMsg
= "The database does contain neither a table nor a query named \"#\"."; break
;
4345 case ErrorCode
::InvalidColumn
: aMsg
= "The column \"#1\" is unknown in the table \"#2\"."; break
;
4346 case ErrorCode
::InvalidTableExist
: aMsg
= "The database already contains a table or view with name \"#\"."; break
;
4347 case ErrorCode
::InvalidQueryExist
: aMsg
= "The database already contains a query with name \"#\"."; break
;
4349 OSL_FAIL
( "OParseContext::getErrorMessage: unknown error code!" );
4356 OString OParseContext
::getIntlKeywordAscii
(InternationalKeyCode _eKey
) const
4361 case InternationalKeyCode
::Like
: aKeyword
= "LIKE"; break
;
4362 case InternationalKeyCode
::Not
: aKeyword
= "NOT"; break
;
4363 case InternationalKeyCode
::Null
: aKeyword
= "NULL"; break
;
4364 case InternationalKeyCode
::True
: aKeyword
= "True"; break
;
4365 case InternationalKeyCode
::False
: aKeyword
= "False"; break
;
4366 case InternationalKeyCode
::Is
: aKeyword
= "IS"; break
;
4367 case InternationalKeyCode
::Between
: aKeyword
= "BETWEEN"; break
;
4368 case InternationalKeyCode
::Or
: aKeyword
= "OR"; break
;
4369 case InternationalKeyCode
::And
: aKeyword
= "AND"; break
;
4370 case InternationalKeyCode
::Avg
: aKeyword
= "AVG"; break
;
4371 case InternationalKeyCode
::Count
: aKeyword
= "COUNT"; break
;
4372 case InternationalKeyCode
::Max
: aKeyword
= "MAX"; break
;
4373 case InternationalKeyCode
::Min
: aKeyword
= "MIN"; break
;
4374 case InternationalKeyCode
::Sum
: aKeyword
= "SUM"; break
;
4375 case InternationalKeyCode
::Every
: aKeyword
= "EVERY"; break
;
4376 case InternationalKeyCode
::Any
: aKeyword
= "ANY"; break
;
4377 case InternationalKeyCode
::Some
: aKeyword
= "SOME"; break
;
4378 case InternationalKeyCode
::StdDevPop
: aKeyword
= "STDDEV_POP"; break
;
4379 case InternationalKeyCode
::StdDevSamp
: aKeyword
= "STDDEV_SAMP"; break
;
4380 case InternationalKeyCode
::VarSamp
: aKeyword
= "VAR_SAMP"; break
;
4381 case InternationalKeyCode
::VarPop
: aKeyword
= "VAR_POP"; break
;
4382 case InternationalKeyCode
::Collect
: aKeyword
= "COLLECT"; break
;
4383 case InternationalKeyCode
::Fusion
: aKeyword
= "FUSION"; break
;
4384 case InternationalKeyCode
::Intersection
:aKeyword
= "INTERSECTION"; break
;
4385 case InternationalKeyCode
::None
: break
;
4387 OSL_FAIL
( "OParseContext::getIntlKeywordAscii: unknown key!" );
4394 IParseContext::InternationalKeyCode OParseContext
::getIntlKeyCode
(const OString
& rToken
) const
4396 static IParseContext
::InternationalKeyCode
const Intl_TokenID
[] =
4398 InternationalKeyCode
::Like
, InternationalKeyCode
::Not
, InternationalKeyCode
::Null
, InternationalKeyCode
::True
,
4399 InternationalKeyCode
::False
, InternationalKeyCode
::Is
, InternationalKeyCode
::Between
, InternationalKeyCode
::Or
,
4400 InternationalKeyCode
::And
, InternationalKeyCode
::Avg
, InternationalKeyCode
::Count
, InternationalKeyCode
::Max
,
4401 InternationalKeyCode
::Min
, InternationalKeyCode
::Sum
, InternationalKeyCode
::Every
,InternationalKeyCode
::Any
,InternationalKeyCode
::Some
,
4402 InternationalKeyCode
::StdDevPop
,InternationalKeyCode
::StdDevSamp
,InternationalKeyCode
::VarSamp
,
4403 InternationalKeyCode
::VarPop
,InternationalKeyCode
::Collect
,InternationalKeyCode
::Fusion
,InternationalKeyCode
::Intersection
4406 auto
const token
= std
::find_if
(std
::cbegin
(Intl_TokenID
), std
::cend
(Intl_TokenID
)
4407 , [&rToken
, this
](IParseContext
::InternationalKeyCode
const & tokenID
)
4408 { return rToken.equalsIgnoreAsciiCase
(getIntlKeywordAscii
(tokenID
)); });
4410 if
(std
::cend
(Intl_TokenID
) != token
)
4413 return InternationalKeyCode
::None
;
4417 static Locale
& impl_getLocaleInstance
( )
4419 static Locale s_aLocale
( "en", "US", "" );
4424 Locale OParseContext
::getPreferredLocale
( ) const
4426 return getDefaultLocale
();
4430 const Locale
& OParseContext
::getDefaultLocale
()
4432 return impl_getLocaleInstance
();
4435 // The (unfortunately global) yylval for the handing over of
4436 // values from the Scanner to the Parser. The global variable
4437 // is only used for a short term, the Parser reads the variable
4438 // immediately after the call of the Scanner into a same named own
4442 OUString ConvertLikeToken
(const OSQLParseNode
* pTokenNode
, const OSQLParseNode
* pEscapeNode
, bool bInternational
)
4444 OUStringBuffer aMatchStr
(0);
4445 if
(pTokenNode
->isToken
())
4447 sal_Unicode cEscape
= 0;
4448 if
(pEscapeNode
->count
())
4449 cEscape
= pEscapeNode
->getChild
(1)->getTokenValue
().toChar
();
4451 // Change place holder
4452 aMatchStr
= pTokenNode
->getTokenValue
();
4453 const sal_Int32 nLen
= aMatchStr.getLength
();
4454 OUStringBuffer sSearch
,sReplace
;
4455 if
( bInternational
)
4457 sSearch.append
("%_");
4458 sReplace.append
("*?");
4462 sSearch.append
("*?");
4463 sReplace.append
("%_");
4466 bool wasEscape
= false
;
4467 for
(sal_Int32 i
= 0; i
< nLen
; i
++)
4469 const sal_Unicode c
= aMatchStr
[i
];
4470 // SQL standard requires the escape to be followed
4471 // by a meta-character ('%', '_' or itself), else error
4472 // We are more lenient here and let it escape anything.
4473 // Especially since some databases (e.g. Microsoft SQL Server)
4474 // have more meta-characters than the standard, such as e.g. '[' and ']'
4486 if
(c
== sSearch
[0])
4488 else if
(c
== sSearch
[1])
4493 aMatchStr
[i
] = sReplace
[match
];
4497 return aMatchStr.makeStringAndClear
();
4500 sal_uInt32 OSQLParser
::s_nRuleIDs
[OSQLParseNode
::rule_count
+ 1];
4501 OSQLParser::RuleIDMap OSQLParser
::s_aReverseRuleIDLookup
;
4502 OParseContext OSQLParser
::s_aDefaultContext
;
4504 sal_Int32 OSQLParser
::s_nRefCount
= 0;
4505 // ::osl::Mutex OSQLParser::s_aMutex;
4506 OSQLScanner
* OSQLParser
::s_pScanner
= nullptr
;
4507 OSQLParseNodesGarbageCollector
* OSQLParser
::s_pGarbageCollector
= nullptr
;
4509 void setParser
(OSQLParser
* _pParser
)
4511 xxx_pGLOBAL_SQLPARSER
= _pParser
;
4514 void OSQLParser
::setParseTree
(OSQLParseNode
* pNewParseTree
)
4516 m_pParseTree.reset
(pNewParseTree
);
4520 /** Delete all comments in a query.
4522 See also getComment()/concatComment() implementation for
4523 OQueryController::translateStatement().
4525 static OUString delComment
( const OUString
& rQuery
)
4527 // First a quick search if there is any "--" or "//" or "/*", if not then the whole
4528 // copying loop is pointless.
4529 if
(rQuery.indexOf
("--") < 0 && rQuery.indexOf
("//") < 0 &&
4530 rQuery.indexOf
("/*") < 0)
4533 const sal_Unicode
* pCopy
= rQuery.getStr
();
4534 sal_Int32 nQueryLen
= rQuery.getLength
();
4535 bool bIsText1
= false
; // "text"
4536 bool bIsText2
= false
; // 'text'
4537 bool bComment2
= false
; // /* comment */
4538 bool bComment
= false
; // -- or // comment
4539 OUStringBuffer aBuf
(nQueryLen
);
4540 for
(sal_Int32 i
=0; i
< nQueryLen
; ++i
)
4544 if
((i
+1) < nQueryLen
)
4546 if
(pCopy
[i
]=='*' && pCopy
[i
+1]=='/')
4554 // comment can't close anymore, actually an error, but...
4558 if
(pCopy
[i
] == '\n')
4562 if
(pCopy
[i
] == '\"' && !bIsText2
)
4563 bIsText1
= !bIsText1
;
4564 else if
(pCopy
[i
] == '\'' && !bIsText1
)
4565 bIsText2
= !bIsText2
;
4566 if
(!bIsText1
&& !bIsText2
&& (i
+1) < nQueryLen
)
4568 if
((pCopy
[i
]=='-' && pCopy
[i
+1]=='-') ||
(pCopy
[i
]=='/' && pCopy
[i
+1]=='/'))
4570 else if
((pCopy
[i
]=='/' && pCopy
[i
+1]=='*'))
4574 if
(!bComment
&& !bComment2
)
4575 aBuf.append
( &pCopy
[i
], 1);
4577 return aBuf.makeStringAndClear
();
4580 std::unique_ptr
<OSQLParseNode
> OSQLParser
::parseTree
(OUString
& rErrorMessage
,
4581 const OUString
& rStatement
,
4582 bool bInternational
)
4586 // Guard the parsing
4587 std
::unique_lock aGuard
(getMutex
());
4591 // delete comments before parsing
4592 OUString sTemp
= delComment
(rStatement
);
4594 // defines how to scan
4595 s_pScanner
->SetRule
(OSQLScanner
::GetSQLRule
()); // initial
4596 s_pScanner
->prepareScan
(sTemp
, m_pContext
, bInternational
);
4598 SQLyylval.pParseNode
= nullptr
;
4600 m_pParseTree
= nullptr
;
4601 m_sErrorMessage
= "";
4604 if
(SQLyyparse
() != 0)
4606 // only set the error message, if it's not already set
4607 if
(m_sErrorMessage.isEmpty
())
4608 m_sErrorMessage
= s_pScanner
->getErrorMessage
();
4609 if
(m_sErrorMessage.isEmpty
())
4610 m_sErrorMessage
= m_pContext
->getErrorMessage
(IParseContext
::ErrorCode
::General
);
4612 rErrorMessage
= m_sErrorMessage
;
4614 // clear the garbage collector
4615 (*s_pGarbageCollector
)->clearAndDelete
();
4616 // coverity[leaked_storage : FALSE] - because the garbage collector deleted it
4617 m_pParseTree.release
();
4622 (*s_pGarbageCollector
)->clear
();
4625 // to work around a bug in MKS YACC return the member m_pParseTree
4626 // instead of Sdbyyval.pParseNode
4628 SAL_WARN_IF
(!m_pParseTree
, "connectivity.parse",
4629 "OSQLParser: Parser did not create ParseTree");
4630 return std
::move
(m_pParseTree
);
4634 OString OSQLParser
::TokenIDToStr
(sal_uInt32 nTokenID
, const IParseContext
* pContext
)
4639 IParseContext
::InternationalKeyCode eKeyCode
= IParseContext
::InternationalKeyCode
::None
;
4642 case SQL_TOKEN_LIKE
: eKeyCode
= IParseContext
::InternationalKeyCode
::Like
; break
;
4643 case SQL_TOKEN_NOT
: eKeyCode
= IParseContext
::InternationalKeyCode
::Not
; break
;
4644 case SQL_TOKEN_NULL
: eKeyCode
= IParseContext
::InternationalKeyCode
::Null
; break
;
4645 case SQL_TOKEN_TRUE
: eKeyCode
= IParseContext
::InternationalKeyCode
::True
; break
;
4646 case SQL_TOKEN_FALSE
: eKeyCode
= IParseContext
::InternationalKeyCode
::False
; break
;
4647 case SQL_TOKEN_IS
: eKeyCode
= IParseContext
::InternationalKeyCode
::Is
; break
;
4648 case SQL_TOKEN_BETWEEN
: eKeyCode
= IParseContext
::InternationalKeyCode
::Between
; break
;
4649 case SQL_TOKEN_OR
: eKeyCode
= IParseContext
::InternationalKeyCode
::Or
; break
;
4650 case SQL_TOKEN_AND
: eKeyCode
= IParseContext
::InternationalKeyCode
::And
; break
;
4651 case SQL_TOKEN_AVG
: eKeyCode
= IParseContext
::InternationalKeyCode
::Avg
; break
;
4652 case SQL_TOKEN_COUNT
: eKeyCode
= IParseContext
::InternationalKeyCode
::Count
; break
;
4653 case SQL_TOKEN_MAX
: eKeyCode
= IParseContext
::InternationalKeyCode
::Max
; break
;
4654 case SQL_TOKEN_MIN
: eKeyCode
= IParseContext
::InternationalKeyCode
::Min
; break
;
4655 case SQL_TOKEN_SUM
: eKeyCode
= IParseContext
::InternationalKeyCode
::Sum
; break
;
4657 if
( eKeyCode
!= IParseContext
::InternationalKeyCode
::None
)
4658 aStr
= pContext
->getIntlKeywordAscii
(eKeyCode
);
4663 // coverity[unsigned_compare : SUPPRESS] - YYTRANSLATE is out of our control
4664 aStr
= yytname
[YYTRANSLATE
(nTokenID
)];
4665 if
(aStr.startsWith
("SQL_TOKEN_"))
4666 aStr
= aStr.copy
(10);
4673 aStr
= aStr.toAsciiLowerCase
();
4679 #if OSL_DEBUG_LEVEL > 0
4680 OUString OSQLParser
::RuleIDToStr
(sal_uInt32 nRuleID
)
4682 OSL_ENSURE
(nRuleID
< std
::size
(yytname
), "OSQLParser::RuleIDToStr: Invalid nRuleId!");
4683 return OUString
::createFromAscii
(yytname
[nRuleID
]);
4688 sal_uInt32 OSQLParser
::StrToRuleID
(const OString
& rValue
)
4690 // Search for the given name in yytname and return the index
4691 // (or UNKNOWN_RULE, if not found)
4692 static sal_uInt32
const nLen
= std
::size
(yytname
)-1;
4693 for
(sal_uInt32 i
= YYTRANSLATE
(SQL_TOKEN_INVALIDSYMBOL
); i
< nLen
; ++i
)
4695 if
(rValue
== yytname
[i
])
4700 return OSQLParseNode
::UNKNOWN_RULE
;
4704 OSQLParseNode::Rule OSQLParser
::RuleIDToRule
( sal_uInt32 _nRule
)
4706 OSQLParser
::RuleIDMap
::const_iterator i
(s_aReverseRuleIDLookup.find
(_nRule
));
4707 if
(i
== s_aReverseRuleIDLookup.end
())
4709 SAL_INFO
("connectivity.parse",
4710 "connectivity::OSQLParser::RuleIDToRule cannot reverse-lookup rule. "
4711 "Reverse mapping incomplete? "
4712 "_nRule='" << _nRule
<< "' "
4713 "yytname[_nRule]='" << yytname
[_nRule
] << "'");
4714 return OSQLParseNode
::UNKNOWN_RULE
;
4721 sal_uInt32 OSQLParser
::RuleID
(OSQLParseNode
::Rule eRule
)
4723 return s_nRuleIDs
[(sal_uInt16
)eRule
];
4726 sal_Int16 OSQLParser
::buildNode
(OSQLParseNode
*& pAppend
,OSQLParseNode
* pCompare
,OSQLParseNode
* pLiteral
,OSQLParseNode
* pLiteral2
)
4728 OSQLParseNode
* pColumnRef
= new OSQLInternalNode
("", SQLNodeType
::Rule
,OSQLParser
::RuleID
(OSQLParseNode
::column_ref
));
4729 pColumnRef
->append
(new OSQLInternalNode
(m_sFieldName
,SQLNodeType
::Name
));
4730 OSQLParseNode
* pComp
= nullptr
;
4731 if
( SQL_ISTOKEN
( pCompare
, BETWEEN
) && pLiteral2
)
4732 pComp
= new OSQLInternalNode
("", SQLNodeType
::Rule
,OSQLParser
::RuleID
(OSQLParseNode
::between_predicate_part_2
));
4734 pComp
= new OSQLInternalNode
("", SQLNodeType
::Rule
,OSQLParser
::RuleID
(OSQLParseNode
::comparison_predicate
));
4736 pComp
->append
(pColumnRef
);
4737 pComp
->append
(pCompare
);
4738 pComp
->append
(pLiteral
);
4741 pComp
->append
(new OSQLInternalNode
("", SQLNodeType
::Keyword
,SQL_TOKEN_AND
));
4742 pComp
->append
(pLiteral2
);
4744 pAppend
->append
(pComp
);
4748 sal_Int16 OSQLParser
::buildStringNodes
(OSQLParseNode
*& pLiteral
)
4753 if
(SQL_ISRULE
(pLiteral
,set_fct_spec
) || SQL_ISRULE
(pLiteral
,general_set_fct
) || SQL_ISRULE
(pLiteral
,column_ref
)
4754 || SQL_ISRULE
(pLiteral
,subquery
))
4755 return
1; // here I have a function that I can't transform into a string
4757 if
(pLiteral
->getNodeType
() == SQLNodeType
::IntNum || pLiteral
->getNodeType
() == SQLNodeType
::ApproxNum || pLiteral
->getNodeType
() == SQLNodeType
::AccessDate
)
4759 OSQLParseNode
* pParent
= pLiteral
->getParent
();
4761 OSQLParseNode
* pNewNode
= new OSQLInternalNode
(pLiteral
->getTokenValue
(), SQLNodeType
::String
);
4762 pParent
->replaceAndDelete
(pLiteral
, pNewNode
);
4767 for
(size_t i
=0;i
<pLiteral
->count
();++i
)
4769 OSQLParseNode
* pChild
= pLiteral
->getChild
(i
);
4770 buildStringNodes
(pChild
);
4772 if
(SQL_ISRULE
(pLiteral
,term
) || SQL_ISRULE
(pLiteral
,value_exp_primary
))
4774 m_sErrorMessage
= m_pContext
->getErrorMessage
(IParseContext
::ErrorCode
::InvalidCompare
);
4780 sal_Int16 OSQLParser
::buildComparisonRule
(OSQLParseNode
*& pAppend
,OSQLParseNode
* pLiteral
)
4782 OSQLParseNode
* pComp
= new OSQLInternalNode
("=", SQLNodeType
::Equal
);
4783 return buildPredicateRule
(pAppend
,pLiteral
,pComp
);
4788 void OSQLParser
::reduceLiteral
(OSQLParseNode
*& pLiteral
, bool bAppendBlank
)
4790 OSL_ENSURE
(pLiteral
->isRule
(), "This is no Rule");
4791 OSL_ENSURE
(pLiteral
->count
() == 2, "OSQLParser::ReduceLiteral() Invalid count");
4792 OSQLParseNode
* pTemp
= pLiteral
;
4793 OUStringBuffer aValue
(pLiteral
->getChild
(0)->getTokenValue
());
4799 aValue.append
(pLiteral
->getChild
(1)->getTokenValue
());
4801 pLiteral
= new OSQLInternalNode
(aValue.makeStringAndClear
(),SQLNodeType
::String
);
4806 void OSQLParser
::error(const char *fmt
)
4808 if
(m_sErrorMessage.isEmpty
())
4810 OUString sStr
(fmt
,strlen
(fmt
),RTL_TEXTENCODING_UTF8
);
4811 OUString sSQL_TOKEN
("SQL_TOKEN_");
4813 sal_Int32 nPos1
= sStr.indexOf
(sSQL_TOKEN
);
4816 OUString sFirst
= sStr.copy
(0,nPos1
);
4817 sal_Int32 nPos2
= sStr.indexOf
(sSQL_TOKEN
,nPos1
+1);
4820 sFirst
+= sStr.subView
(nPos1
+sSQL_TOKEN.getLength
(),nPos2
-nPos1
-sSQL_TOKEN.getLength
());
4821 sFirst
+= sStr.subView
(nPos2
+sSQL_TOKEN.getLength
());
4824 sFirst
+= sStr.subView
(nPos1
+sSQL_TOKEN.getLength
());
4826 m_sErrorMessage
= sFirst
;
4829 m_sErrorMessage
= sStr
;
4831 OUString aError
= s_pScanner
->getErrorMessage
();
4832 if
(!aError.isEmpty
())
4834 m_sErrorMessage
+= ", ";
4835 m_sErrorMessage
+= aError
;
4840 int OSQLParser
::SQLlex
()
4842 return OSQLScanner
::SQLlex
();