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/macros.h>
48 #include <sal/log.hxx>
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
58 # pragma GCC diagnostic ignored "-Wwrite-strings"
59 # pragma GCC diagnostic ignored "-Wunused-function"
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) \
88 xxx_pGLOBAL_SQLPARSER
->error(s
); \
91 using namespace connectivity
;
92 #define SQLyylex xxx_pGLOBAL_SQLPARSER->SQLlex
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
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
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
178 %token
<pParseNode
> SQL_TOKEN_LIMIT SQL_TOKEN_OFFSET SQL_TOKEN_NEXT SQL_TOKEN_ONLY
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
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 ); }
269 { xxx_pGLOBAL_SQLPARSER
->setParseTree
( $1 ); }
272 /* schema definition language */
273 /* Note: other ``sql:sal_Unicode() rules appear later in the grammar */
276 manipulative_statement
288 | SQL_TOKEN_AUTHORIZATION user
298 | SQL_TOKEN_NAME '.' SQL_TOKEN_NAME
302 $$->append(newNode(".", SQLNodeType::Punctuation));
308 SQL_TOKEN_CREATE SQL_TOKEN_SCHEMA op_schema op_authorization opt_schema_element_list
319 opt_schema_element_list:
321 | schema_glement_list
326 {$$ = SQL_NEW_LISTRULE;
328 | schema_element_list schema_element
342 SQL_TOKEN_CREATE SQL_TOKEN_TABLE table_node
'(' base_table_element_commalist
')'
347 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
349 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));}
352 base_table_element_commalist:
354 {$$
= SQL_NEW_COMMALISTRULE
;
356 | base_table_element_commalist
',' base_table_element
363 | table_constraint_def
367 column data_type column_def_opt_list
376 /* empty */ {$$
= SQL_NEW_LISTRULE
;}
377 | column_def_opt_list column_def_opt
387 | SQL_TOKEN_PRIMARY SQL_TOKEN_KEY
395 SQL_TOKEN_NOT SQL_TOKEN_NULL
400 | SQL_TOKEN_DEFAULT literal
404 | SQL_TOKEN_DEFAULT SQL_TOKEN_NULL
408 | SQL_TOKEN_DEFAULT SQL_TOKEN_USER
412 | SQL_TOKEN_DEFAULT nil_fkt
419 | SQL_TOKEN_CHECK
'(' search_condition
')'
422 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
424 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));}
425 | SQL_TOKEN_REFERENCES table_node
429 | SQL_TOKEN_REFERENCES table_node
'(' column_commalist
')'
433 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
435 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));}
438 table_constraint_def:
439 unique_spec
'(' column_commalist
')'
442 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
444 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));}
445 | SQL_TOKEN_FOREIGN SQL_TOKEN_KEY
'(' column_commalist
')' SQL_TOKEN_REFERENCES table_node
449 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
451 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
454 | SQL_TOKEN_FOREIGN SQL_TOKEN_KEY
'(' column_commalist
')' SQL_TOKEN_REFERENCES table_node
'(' column_commalist
')'
458 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
460 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
463 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
465 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));}
466 | SQL_TOKEN_CHECK
'(' search_condition
')'
469 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
471 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));}
474 /* empty */ {$$
= SQL_NEW_RULE
;}
475 |
'(' column_commalist
')'
477 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
479 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
483 column_commalist
',' column
487 {$$
= SQL_NEW_COMMALISTRULE
;
492 SQL_TOKEN_CREATE SQL_TOKEN_VIEW table_node opt_column_commalist SQL_TOKEN_AS select_statement opt_with_check_option
503 opt_with_check_option:
504 /* empty */ {$$
= SQL_NEW_RULE
;}
505 | SQL_TOKEN_WITH SQL_TOKEN_CHECK SQL_TOKEN_OPTION
512 opt_column_commalist:
513 /* empty */ {$$
= SQL_NEW_RULE
;}
514 |
'(' column_commalist
')'
516 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
518 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));}
522 SQL_TOKEN_GRANT privileges SQL_TOKEN_ON table_node SQL_TOKEN_TO grantee_commalist
523 opt_with_grant_option
534 opt_with_grant_option:
535 /* empty */ {$$
= SQL_NEW_RULE
;}
536 | SQL_TOKEN_WITH SQL_TOKEN_GRANT SQL_TOKEN_OPTION
544 SQL_TOKEN_ALL SQL_TOKEN_PRIVILEGES
548 | operation_commalist
553 {$$
= SQL_NEW_COMMALISTRULE
;
555 | operation_commalist
',' operation
562 | SQL_TOKEN_INSERT opt_column_commalist
567 | SQL_TOKEN_UPDATE opt_column_commalist
571 | SQL_TOKEN_REFERENCES opt_column_commalist
581 {$$
= SQL_NEW_COMMALISTRULE
;
583 | grantee_commalist
',' grantee
593 /* module language */
596 /* empty */ {$$
= SQL_NEW_RULE
;}
597 | SQL_TOKEN_ORDER SQL_TOKEN_BY ordering_spec_commalist
604 ordering_spec_commalist:
606 {$$
= SQL_NEW_COMMALISTRULE
;
608 | ordering_spec_commalist
',' ordering_spec
614 /* SQL_TOKEN_INTNUM opt_asc_desc
619 predicate opt_asc_desc
624 | row_value_constructor_elem opt_asc_desc
638 manipulative_statement_list:
639 manipulative_statement
640 {$$ = SQL_NEW_LISTRULE;
642 | manipulative_statement_list manipulative_statement
654 /* manipulative statements */
656 manipulative_statement:
658 /* | delete_statement_positioned*/
659 | delete_statement_searched
663 | select_statement_into
664 /* | update_statement_positioned*/
665 | update_statement_searched
667 |
'{' odbc_call_spec
'}'
670 $$
->append
(newNode
("{", SQLNodeType
::Punctuation
));
672 $$
->append
(newNode
("}", SQLNodeType
::Punctuation
));
678 | union_statement SQL_TOKEN_UNION all select_statement
688 SQL_TOKEN_COMMIT SQL_TOKEN_WORK
694 delete_statement_positioned:
695 SQL_TOKEN_DELETE SQL_TOKEN_FROM table_node SQL_TOKEN_WHERE SQL_TOKEN_CURRENT SQL_TOKEN_OF cursor
706 delete_statement_searched:
707 SQL_TOKEN_DELETE SQL_TOKEN_FROM table_node opt_where_clause
716 SQL_TOKEN_FETCH cursor SQL_TOKEN_INTO target_commalist
725 SQL_TOKEN_INSERT SQL_TOKEN_INTO table_node opt_column_commalist query_exp
733 values_or_query_spec:
734 SQL_TOKEN_VALUES
'(' table_value_const_list
')'
737 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
739 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
743 table_value_const_list:
744 row_value_constructor
745 {$$
= SQL_NEW_COMMALISTRULE
;
747 | table_value_const_list
',' row_value_constructor
752 row_value_const_list:
753 row_value_constructor_elem
754 {$$ = SQL_NEW_COMMALISTRULE;
756 | row_value_const_list ',' row_value_constructor_elem
761 row_value_constructor:
762 row_value_constructor_elem
763 /* | '(' row_value_const_list ')'
766 $$->append(newNode("(", SQLNodeType::Punctuation));
768 $$->append(newNode(")", SQLNodeType::Punctuation));
772 row_value_constructor_elem:
779 SQL_TOKEN_ROLLBACK SQL_TOKEN_WORK
786 /* INTO target_commalist herausgenommen */
787 select_statement_into:
788 SQL_TOKEN_SELECT opt_all_distinct selection SQL_TOKEN_INTO target_commalist table_exp
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
819 assignment_commalist:
821 {$$
= SQL_NEW_COMMALISTRULE
;
823 | assignment_commalist
',' assignment
829 column SQL_EQUAL update_source
839 update_statement_searched:
840 SQL_TOKEN_UPDATE table_node SQL_TOKEN_SET assignment_commalist opt_where_clause
851 {$$
= SQL_NEW_COMMALISTRULE
;
853 | target_commalist
',' target
863 /* empty */ {$$
= SQL_NEW_RULE
;}
867 /* query expressions */
876 /* SELECT STATEMENT */
878 SQL_TOKEN_SELECT opt_all_distinct selection table_exp
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
909 opt_fetch_first_row_count:
910 /* empty */ {$$
= SQL_NEW_RULE
;}
911 | fetch_first_row_count
921 opt_fetch_first_clause:
922 /* empty */ {$$
= SQL_NEW_RULE
;}
926 SQL_TOKEN_FETCH first_or_next opt_fetch_first_row_count row_or_rows SQL_TOKEN_ONLY
939 fetch_first_row_count:
943 opt_limit_offset_clause:
944 /* empty */ {$$
= SQL_NEW_RULE
;}
945 | limit_offset_clause
948 /* empty */ {$$
= SQL_NEW_RULE
;}
949 | SQL_TOKEN_OFFSET SQL_TOKEN_INTNUM
957 SQL_TOKEN_LIMIT SQL_TOKEN_INTNUM opt_offset
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
982 SQL_TOKEN_FROM table_ref_commalist
991 { $$
= SQL_NEW_COMMALISTRULE
;
993 | table_ref_commalist
',' table_ref
999 /* empty */ {$$
= SQL_NEW_RULE
;}
1003 /* empty */ {$$
= SQL_NEW_RULE
;}
1006 table_primary_as_range_column:
1007 {$$
= SQL_NEW_RULE
;}
1008 | opt_as SQL_TOKEN_NAME op_column_commalist
1017 table_node table_primary_as_range_column
1023 | subquery range_variable op_column_commalist
1031 |
'{' SQL_TOKEN_OJ joined_table
'}'
1034 $$
->append
(newNode
("{", SQLNodeType
::Punctuation
));
1037 $$
->append
(newNode
("}", SQLNodeType
::Punctuation
));
1039 |
'(' joined_table
')'
1042 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1044 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1048 SQL_TOKEN_WHERE search_condition
1054 opt_group_by_clause:
1055 /* empty */ {$$
= SQL_NEW_RULE
;}
1056 | SQL_TOKEN_GROUP SQL_TOKEN_BY column_ref_commalist
1063 column_ref_commalist:
1065 {$$
= SQL_NEW_COMMALISTRULE
;
1068 {$$
= SQL_NEW_COMMALISTRULE
;
1070 | column_ref_commalist
',' column_ref
1073 | column_ref_commalist
',' set_fct_spec
1079 /* empty */ {$$
= SQL_NEW_RULE
;}
1080 | SQL_TOKEN_HAVING search_condition
1086 /* search conditions */
1089 |
'(' search_condition
')'
1090 { // boolean_primary: rule 2
1092 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1094 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1096 | row_value_constructor_elem
/*[^')' ',']*/
1098 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
())// boolean_primary: rule 3
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
);
1121 nErg
= xxx_pGLOBAL_SQLPARSER
->buildComparsionRule
($$
,$1);
1125 OSQLParseNode
* pTemp
= $$
;
1126 $$
= pTemp
->removeAt
((sal_uInt32
)0);
1142 parenthesized_boolean_value_expression:
1143 '(' search_condition
')'
1144 { // boolean_primary: rule 2
1146 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1148 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1152 boolean_primary %dprec
2
1153 | SQL_TOKEN_NOT boolean_primary %dprec
1
1154 { // boolean_factor: rule 1
1162 | boolean_term SQL_TOKEN_AND boolean_factor
1164 $$
= SQL_NEW_RULE
; // boolean_term: rule 1
1172 | search_condition SQL_TOKEN_OR boolean_term
1174 $$
= SQL_NEW_RULE
; // search_condition
1181 comparison_predicate %dprec
1
1183 | all_or_any_predicate
1186 | test_for_null %dprec
2
1190 comparison_predicate_part_2:
1191 comparison row_value_constructor
1193 $$
= SQL_NEW_RULE
; // comparison_predicate: rule 1
1197 comparison_predicate:
1198 row_value_constructor comparison row_value_constructor
1200 $$
= SQL_NEW_RULE
; // comparison_predicate: rule 1
1205 | comparison row_value_constructor
1207 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
()) // comparison_predicate: rule 2
1210 sal_Int16 nErg
= xxx_pGLOBAL_SQLPARSER
->buildPredicateRule
($$
,$2,$1);
1213 OSQLParseNode
* pTemp
= $$
;
1214 $$
= pTemp
->removeAt
((sal_uInt32
)0);
1236 | SQL_TOKEN_IS sql_not SQL_TOKEN_DISTINCT SQL_TOKEN_FROM
1244 | SQL_TOKEN_IS sql_not
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
1258 sal_Int16 nErg
= xxx_pGLOBAL_SQLPARSER
->buildPredicateRule
($$
,$3,$2,$5);
1261 OSQLParseNode
* pTemp
= $$
;
1262 $$
= pTemp
->removeAt
((sal_uInt32
)0);
1263 OSQLParseNode
* pColumnRef
= $$
->removeAt
((sal_uInt32
)0);
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
;
1281 $$
= SQL_NEW_RULE
; // between_predicate: rule 1
1290 row_value_constructor between_predicate_part_2
1292 $$
= SQL_NEW_RULE
; // between_predicate: rule 1
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
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
1319 row_value_constructor character_like_predicate_part_2
1321 $$
= SQL_NEW_RULE
; // like_predicate: rule 1
1325 | row_value_constructor other_like_predicate_part_2
1327 $$
= SQL_NEW_RULE
; // like_predicate: rule 3
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
));
1339 $$
->append
(pColumnRef
);
1341 OSQLParseNode
* p2nd
= $1->removeAt
(2);
1342 OSQLParseNode
* p3rd
= $1->removeAt
(2);
1343 if
( !xxx_pGLOBAL_SQLPARSER
->buildLikeRule
($1,p2nd
,p3rd
) )
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
));
1361 $$
->append
(pColumnRef
);
1363 OSQLParseNode
* p2nd
= $1->removeAt
(2);
1364 OSQLParseNode
* p3rd
= $1->removeAt
(2);
1365 if
( !xxx_pGLOBAL_SQLPARSER
->buildLikeRule
($1,p2nd
,p3rd
) )
1378 /* empty */ {$$
= SQL_NEW_RULE
;}
1379 | SQL_TOKEN_ESCAPE string_value_exp
1383 |
'{' SQL_TOKEN_ESCAPE SQL_TOKEN_STRING
'}'
1386 $$
->append
(newNode
("{", SQLNodeType
::Punctuation
));
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
1401 | SQL_TOKEN_IS sql_not SQL_TOKEN_UNKNOWN
1403 $$
= SQL_NEW_RULE
; // test_for_null: rule 1
1410 row_value_constructor null_predicate_part_2
1412 $$
= SQL_NEW_RULE
; // test_for_null: rule 1
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
));
1424 $$
->append
(pColumnRef
);
1436 |
'(' value_exp_commalist
')'
1438 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
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
1453 row_value_constructor in_predicate_part_2
1455 $$
= SQL_NEW_RULE
;// in_predicate: rule 1
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
));
1467 $$
->append
(pColumnRef
);
1474 quantified_comparison_predicate_part_2:
1475 comparison any_all_some subquery
1483 all_or_any_predicate:
1484 row_value_constructor quantified_comparison_predicate_part_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
));
1498 $$
->append
(pColumnRef
);
1513 SQL_TOKEN_EXISTS subquery
1519 SQL_TOKEN_UNIQUE subquery
1527 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1529 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));}
1532 /* scalar expressions */
1533 scalar_exp_commalist:
1536 $$
= SQL_NEW_COMMALISTRULE
;
1539 | scalar_exp_commalist
',' select_sublist
1546 /* table_node '.' '*'
1550 $$->append(newNode(".", SQLNodeType::Punctuation));
1551 $$->append(newNode("*", SQLNodeType::Punctuation));
1566 $$ = newNode("*", SQLNodeType::Punctuation);
1570 $$ = newNode("?", SQLNodeType::Punctuation);
1576 $$->append(newNode("*", SQLNodeType::Punctuation));
1577 xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_False);
1583 $$->append(newNode("?", SQLNodeType::Punctuation));
1584 xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_False);
1592 | SQL_TOKEN_REAL_NUM
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
())
1604 OSQLParser
::reduceLiteral
($$
, true
);
1609 | literal SQL_TOKEN_INT
1611 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
())
1616 OSQLParser
::reduceLiteral
($$
, true
);
1621 | literal SQL_TOKEN_REAL_NUM
1623 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
())
1628 OSQLParser
::reduceLiteral
($$
, true
);
1633 | literal SQL_TOKEN_APPROXNUM
1635 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
())
1640 OSQLParser
::reduceLiteral
($$
, true
);
1649 /* empty */ {$$
= SQL_NEW_RULE
;}
1650 | SQL_TOKEN_AS column
1659 SQL_TOKEN_POSITION
'(' value_exp SQL_TOKEN_IN value_exp
')'
1663 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1667 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1669 | SQL_TOKEN_POSITION
'(' value_exp_commalist
')'
1673 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1675 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1684 SQL_TOKEN_CHAR_LENGTH
'(' value_exp
')'
1688 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1690 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1692 | SQL_TOKEN_SQL_TOKEN_INTNUM
'(' value_exp
')'
1696 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1698 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1703 SQL_TOKEN_OCTET_LENGTH
'(' value_exp
')'
1707 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1709 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1713 SQL_TOKEN_BIT_LENGTH
'(' value_exp
')'
1717 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1719 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1740 non_second_datetime_field
1757 SQL_TOKEN_TIMEZONE_HOUR
1762 | SQL_TOKEN_TIMEZONE_MINUTE
1769 SQL_TOKEN_EXTRACT
'(' extract_field SQL_TOKEN_FROM value_exp
')'
1773 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1777 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1780 unsigned_value_spec:
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
1802 |
'{' odbc_fct_spec
'}'
1805 $$
->append
(newNode
("{", SQLNodeType
::Punctuation
));
1807 $$
->append
(newNode
("}", SQLNodeType
::Punctuation
));
1809 | function_name
'(' ')'
1813 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1814 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1816 | function_name0
'(' ')'
1820 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1821 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1823 | function_name1
'(' function_arg
')'
1827 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1829 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1831 | function_name2
'(' function_arg_commalist2
')'
1835 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1837 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1839 | function_name3
'(' function_arg_commalist3
')'
1843 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1845 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1847 | string_function_4Argument
'(' function_arg_commalist4
')'
1851 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1853 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1855 | function_name
'(' function_args_commalist
')'
1859 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1861 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1863 | function_name12
'(' function_args_commalist
')'
1865 if
( $3->count
() == 1 ||
$3->count
() == 2 )
1869 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1871 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1876 | function_name23
'(' function_args_commalist
')'
1878 if
( $3->count
() == 2 ||
$3->count
() == 3)
1882 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
1884 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
1891 date_function_0Argument
1892 | numeric_function_0Argument
1895 string_function_1Argument
1896 | date_function_1Argument
1897 | numeric_function_1Argument
1900 string_function_2Argument
1901 | numeric_function_2Argument
1911 | SQL_TOKEN_DATEDIFF
1914 string_function_3Argument
1922 string_function_1Argument:
1932 string_function_2Argument:
1937 string_function_3Argument:
1940 string_function_4Argument:
1947 | SQL_TOKEN_DIFFERENCE
1948 | SQL_TOKEN_LOCATE_2
1951 date_function_0Argument:
1956 date_function_1Argument:
1958 | SQL_TOKEN_DAYOFMONTH
1959 | SQL_TOKEN_DAYOFYEAR
1962 | SQL_TOKEN_MONTHNAME
1969 | SQL_TOKEN_TIMEVALUE
1970 | SQL_TOKEN_DATEVALUE
1974 SQL_TOKEN_TIMESTAMPADD
1975 | SQL_TOKEN_TIMESTAMPDIFF
1977 numeric_function_0Argument:
1980 numeric_function_1Argument:
1998 | SQL_TOKEN_ROUNDMAGIC
2000 numeric_function_2Argument:
2007 | SQL_TOKEN_TRUNCATE
2011 window_function_type SQL_TOKEN_OVER window_name_or_specification
2019 window_function_type
:
2020 rank_function_type
'(' ')'
2024 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2025 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2027 | SQL_TOKEN_ROW_NUMBER
'(' ')'
2031 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2032 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2036 | lead_or_lag_function
2037 | first_or_last_value_function
2038 | nth_value_function
2041 SQL_TOKEN_NTILE
'(' number_of_tiles
')'
2045 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2047 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2050 dynamic_parameter_specification:
2053 simple_value_specification:
2057 simple_value_specification
2058 | dynamic_parameter_specification
2060 opt_lead_or_lag_function:
2061 /* empty */ {$$
= SQL_NEW_RULE
;}
2065 $$
->append
(newNode
(",", SQLNodeType
::Punctuation
));
2068 |
',' offset
',' default_expression
2071 $$
->append
(newNode
(",", SQLNodeType
::Punctuation
));
2073 $$
->append
(newNode
(",", SQLNodeType
::Punctuation
));
2078 /* empty */ {$$
= SQL_NEW_RULE
;}
2082 lead_or_lag_function:
2083 lead_or_lag
'(' lead_or_lag_extent opt_lead_or_lag_function
')' opt_null_treatment
2087 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2090 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
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
2116 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2118 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
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
2131 SQL_TOKEN_NTH_VALUE
'(' value_exp
',' nth_row
')' opt_from_first_or_last opt_null_treatment
2135 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2137 $$
->append
(newNode
(",", SQLNodeType
::Punctuation
));
2139 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2145 simple_value_specification
2146 | dynamic_parameter_specification
2149 SQL_TOKEN_FROM SQL_TOKEN_FIRST
2155 | SQL_TOKEN_FROM SQL_TOKEN_LAST
2165 window_name_or_specification:
2167 | in_line_window_specification
2169 in_line_window_specification:
2170 window_specification
2173 /* empty */ {$$
= SQL_NEW_RULE
;}
2177 SQL_TOKEN_WINDOW window_definition_list
2184 window_definition_list:
2185 window_definition_list
',' window_definition
2189 {$$
= SQL_NEW_COMMALISTRULE
;
2193 new_window_name SQL_TOKEN_AS window_specification
2204 window_specification:
2205 '(' window_specification_details
')'
2208 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
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
2229 opt_window_frame_clause
2231 existing_window_name:
2234 window_partition_clause:
2235 SQL_TOKEN_PARTITION SQL_TOKEN_BY window_partition_column_reference_list
2243 window_partition_column_reference_list:
2244 window_partition_column_reference_list
',' window_partition_column_reference
2247 | window_partition_column_reference
2248 {$$
= SQL_NEW_COMMALISTRULE
;
2251 window_partition_column_reference:
2252 column_ref opt_collate_clause
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
2276 window_frame_extent:
2278 | window_frame_between
2281 SQL_TOKEN_UNBOUNDED SQL_TOKEN_PRECEDING
2287 | window_frame_preceding
2288 | SQL_TOKEN_CURRENT SQL_TOKEN_ROW
2295 window_frame_preceding:
2296 unsigned_value_spec SQL_TOKEN_PRECEDING
2303 window_frame_between:
2304 SQL_TOKEN_BETWEEN window_frame_bound_1 SQL_TOKEN_AND window_frame_bound_2
2313 window_frame_bound_1:
2316 window_frame_bound_2:
2321 | SQL_TOKEN_UNBOUNDED SQL_TOKEN_FOLLOWING
2327 | window_frame_following
2329 window_frame_following:
2330 unsigned_value_spec SQL_TOKEN_FOLLOWING
2337 window_frame_exclusion:
2338 SQL_TOKEN_EXCLUDE SQL_TOKEN_CURRENT SQL_TOKEN_ROW
2345 | SQL_TOKEN_EXCLUDE SQL_TOKEN_GROUP
2351 | SQL_TOKEN_EXCLUDE SQL_TOKEN_TIES
2357 | SQL_TOKEN_EXCLUDE SQL_TOKEN_NO SQL_TOKEN_OTHERS
2366 {$$
= SQL_NEW_RULE
;}
2370 $$
->append
(newNode
("?", SQLNodeType
::Punctuation
));
2375 op_parameter SQL_TOKEN_CALL table_node op_odbc_call_parameter
2385 op_odbc_call_parameter:
2386 {$$
= SQL_NEW_RULE
;}
2387 |
'(' odbc_parameter_commalist
')'
2390 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2392 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2396 odbc_parameter_commalist:
2398 {$$
= SQL_NEW_COMMALISTRULE
;
2400 | odbc_parameter_commalist
',' odbc_parameter
2407 /* empty */ {$$
= SQL_NEW_RULE
;}
2413 odbc_fct_type SQL_TOKEN_STRING
2419 | SQL_TOKEN_FN set_fct_spec
2434 set_fct_type
'(' opt_all_distinct function_arg
')'
2438 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2441 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2443 | SQL_TOKEN_COUNT
'(' '*' ')'
2447 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2448 $$
->append
(newNode
("*", SQLNodeType
::Punctuation
));
2449 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2451 | SQL_TOKEN_COUNT
'(' opt_all_distinct function_arg
')'
2455 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2458 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2460 | ordered_set_function
2461 | array_aggregate_function
2471 | SQL_TOKEN_STDDEV_POP
2472 | SQL_TOKEN_STDDEV_SAMP
2473 | SQL_TOKEN_VAR_SAMP
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
2489 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2491 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2494 | rank_function_type
'(' hypothetical_set_function_value_expression_list SQL_TOKEN_BY value_exp_commalist
')' within_group_specification
2498 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2502 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2507 within_group_specification:
2511 | SQL_TOKEN_WITHIN SQL_TOKEN_GROUP
'(' opt_order_by_clause
')'
2516 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2518 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2521 hypothetical_set_function_value_expression_list:
2525 inverse_distribution_function:
2526 inverse_distribution_function_type
'('inverse_distribution_function_argument
')' within_group_specification
2530 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2532 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2535 inverse_distribution_function_argument:
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
')'
2548 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2551 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2557 | SQL_TOKEN_DENSE_RANK
2558 | SQL_TOKEN_PERCENT_RANK
2559 | SQL_TOKEN_CUME_DIST
2562 SQL_TOKEN_LEFT %prec SQL_TOKEN_LEFT
2567 | SQL_TOKEN_RIGHT %prec SQL_TOKEN_RIGHT
2572 | SQL_TOKEN_FULL %prec SQL_TOKEN_FULL
2579 SQL_TOKEN_ON search_condition
2588 | named_columns_join
2591 /* empty */ {$$
= SQL_NEW_RULE
;}
2598 | outer_join_type SQL_TOKEN_OUTER
2606 table_ref SQL_TOKEN_CROSS SQL_TOKEN_JOIN table_ref
2617 /* when SQL_TOKEN_NATURAL, then no join_spec */
2618 table_ref SQL_TOKEN_NATURAL join_type SQL_TOKEN_JOIN table_ref
2627 | table_ref join_type SQL_TOKEN_JOIN table_ref join_spec
2642 SQL_TOKEN_USING
'(' column_commalist
')'
2646 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2648 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2653 | values_or_query_spec
2656 non_join_query_primary:
2658 |
'(' non_join_query_exp
')'
2661 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2663 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2666 non_join_query_term:
2667 non_join_query_primary
2668 | query_term SQL_TOKEN_INTERSECT all query_primary
2678 non_join_query_primary
2682 | query_exp SQL_TOKEN_UNION all query_term
2690 | query_exp SQL_TOKEN_EXCEPT all query_term
2700 /* empty*/ {$$
= SQL_NEW_RULE
;}
2704 non_join_query_exp
/*[^')']*/
2717 SQL_TOKEN_CAST
'(' cast_operand SQL_TOKEN_AS cast_target
')'
2721 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2725 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2738 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
2740 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
2751 |
'-' num_primary %prec SQL_TOKEN_UMINUS
2754 $$
->append
(newNode
("-", SQLNodeType
::Punctuation
));
2757 |
'+' num_primary %prec SQL_TOKEN_UMINUS
2760 $$
->append
(newNode
("+", SQLNodeType
::Punctuation
));
2771 $$
->append
(newNode
("*", SQLNodeType
::Punctuation
));
2778 $$
->append
(newNode
("/", SQLNodeType
::Punctuation
));
2785 | num_value_exp
'+' term
2789 $$
->append
(newNode
("+", SQLNodeType
::Punctuation
));
2792 | num_value_exp
'-' term
2796 $$
->append
(newNode
("-", SQLNodeType
::Punctuation
));
2801 /* value_exp_primary
2806 |*/ datetime_value_fct
2813 SQL_TOKEN_CURRENT_DATE
2818 | SQL_TOKEN_CURRENT_TIME
2823 | SQL_TOKEN_CURRENT_TIMESTAMP
2830 SQL_TOKEN_AT time_zone_specifier
2837 time_zone_specifier:
2843 /* | SQL_TOKEN_TIME SQL_TOKEN_ZONE interval_value_exp
2857 | datetime_primary time_zone
2874 | interval_term '*' factor
2878 $$->append(newNode("*", SQLNodeType::Punctuation));
2881 | interval_term '/' factor
2885 $$->append(newNode("/", SQLNodeType::Punctuation));
2896 /* | interval_value_exp '+' datetime_term
2900 $$->append(newNode("+", SQLNodeType::Punctuation));
2903 | datetime_value_exp '+' interval_term
2907 $$->append(newNode("+", SQLNodeType::Punctuation));
2910 | datetime_value_exp '-' interval_term
2914 $$->append(newNode("-", SQLNodeType::Punctuation));
2925 | interval_value_exp '+' interval_term
2929 $$->append(newNode("+", SQLNodeType::Punctuation));
2932 | interval_value_exp '-' interval_term
2936 $$->append(newNode("-", SQLNodeType::Punctuation));
2939 | '(' datetime_value_exp '-' datetime_term ')' interval_qualifier
2942 $$->append(newNode("(", SQLNodeType::Punctuation));
2944 $$->append(newNode("-", SQLNodeType::Punctuation));
2946 $$->append(newNode(")", SQLNodeType::Punctuation));
2951 non_second_datetime_field:
2959 non_second_datetime_field opt_paren_precision
2967 non_second_datetime_field
2968 | SQL_TOKEN_SECOND opt_paren_precision
2976 single_datetime_field:
2977 non_second_datetime_field opt_paren_precision
2983 | SQL_TOKEN_SECOND opt_paren_precision_scale
2992 start_field SQL_TOKEN_TO end_field
2999 | single_datetime_field
3002 function_arg_commalist2:
3003 function_arg
',' function_arg
3004 {$$
= SQL_NEW_COMMALISTRULE
;
3008 function_arg_commalist3:
3009 function_arg
',' function_arg
',' function_arg
3011 $$
= SQL_NEW_COMMALISTRULE
;
3017 function_arg_commalist4:
3018 function_arg
',' function_arg
',' function_arg
',' function_arg
3020 $$
= SQL_NEW_COMMALISTRULE
;
3027 value_exp_commalist:
3029 {$$
= SQL_NEW_COMMALISTRULE
;
3031 | value_exp_commalist
',' value_exp
3034 /* this rule is only valid if we check predicates */
3035 | value_exp_commalist
';' value_exp
3037 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
())
3048 | value_exp comparison value_exp
3055 | value_exp SQL_TOKEN_USING value_exp comparison value_exp
3063 | value_exp SQL_TOKEN_BY value_exp_commalist
3071 function_args_commalist:
3073 {$$
= SQL_NEW_COMMALISTRULE
;
3075 | function_args_commalist
',' function_arg
3078 /* this rule is only valid if we check predicates */
3079 | function_args_commalist
';' function_arg
3081 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
())
3092 num_value_exp
/*[^')']*/
3094 | datetime_value_exp
3113 char_value_exp
'+' char_factor
3117 $$
->append
(newNode
("+", SQLNodeType
::Punctuation
));
3120 | value_exp SQL_CONCAT value_exp
3134 SQL_TOKEN_COLLATE table_node
3143 | char_primary collate_clause
3162 SQL_TOKEN_SUBSTRING
'(' bit_value_exp SQL_TOKEN_FROM string_value_exp for_length
')'
3166 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3171 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3189 bit_value_exp '+' bit_factor
3193 $$->append(newNode("+", SQLNodeType::Punctuation));
3206 {$$
= SQL_NEW_RULE
;}
3207 /* value_exp_primary
3238 {$$
= SQL_NEW_RULE
;}
3239 | SQL_TOKEN_FOR value_exp
3247 SQL_TOKEN_SUBSTRING
'(' value_exp SQL_TOKEN_FROM value_exp for_length
')'
3251 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3256 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3258 | SQL_TOKEN_SUBSTRING
'(' value_exp_commalist
')'
3262 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3264 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3272 upper_lower
'(' value_exp
')'
3276 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3278 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3282 SQL_TOKEN_CONVERT
'(' string_value_exp SQL_TOKEN_USING table_node
')'
3286 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3290 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3292 | SQL_TOKEN_CONVERT
'(' cast_operand
',' cast_target
')'
3296 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3298 $$
->append
(newNode
(",", SQLNodeType
::Punctuation
));
3300 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3304 SQL_TOKEN_TRANSLATE
'(' string_value_exp SQL_TOKEN_USING table_node
')'
3308 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3312 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3316 SQL_TOKEN_TRIM
'(' trim_operands
')'
3320 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3322 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3326 trim_spec value_exp SQL_TOKEN_FROM value_exp
3334 | trim_spec SQL_TOKEN_FROM value_exp
3341 | value_exp SQL_TOKEN_FROM value_exp
3348 | SQL_TOKEN_FROM value_exp
3360 | SQL_TOKEN_TRAILING
3378 SQL_TOKEN_NAME
'.' schema_name
3382 $$
->append
(newNode
(".", SQLNodeType
::Punctuation
));
3385 | SQL_TOKEN_NAME
':' schema_name
3389 $$
->append
(newNode
(":", SQLNodeType
::Punctuation
));
3394 SQL_TOKEN_NAME
'.' table_name
3398 $$
->append
(newNode
(".", SQLNodeType
::Punctuation
));
3413 /* | table_node '.' column_val %prec '.'
3416 $$->append(newNode(".", SQLNodeType::Punctuation));
3419 | SQL_TOKEN_NAME
'.' column_val %prec
'.'
3422 $$
->append
(newNode
(".", SQLNodeType
::Punctuation
));
3425 | SQL_TOKEN_NAME
'.' SQL_TOKEN_NAME
'.' column_val %prec
'.'
3428 $$
->append
(newNode
(".", SQLNodeType
::Punctuation
));
3430 $$
->append
(newNode
(".", SQLNodeType
::Punctuation
));
3432 | SQL_TOKEN_NAME
'.' SQL_TOKEN_NAME
'.' SQL_TOKEN_NAME
'.' column_val %prec
'.'
3435 $$
->append
(newNode
(".", SQLNodeType
::Punctuation
));
3437 $$
->append
(newNode
(".", SQLNodeType
::Punctuation
));
3439 $$
->append
(newNode
(".", SQLNodeType
::Punctuation
));
3442 | SQL_TOKEN_NAME
':' SQL_TOKEN_NAME
'.' SQL_TOKEN_NAME
'.' column_val %prec
'.'
3445 $$
->append
(newNode
(":", SQLNodeType
::Punctuation
));
3447 $$
->append
(newNode
(".", SQLNodeType
::Punctuation
));
3449 $$
->append
(newNode
(".", SQLNodeType
::Punctuation
));
3452 /* | SQL_TOKEN_NAME ';' SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val
3455 $$->append(newNode(";", SQLNodeType::Punctuation));
3457 $$->append(newNode(".", SQLNodeType::Punctuation));
3459 $$->append(newNode(".", SQLNodeType::Punctuation));
3472 $$
->append
(newNode
("*", SQLNodeType
::Punctuation
));
3479 {$$
= SQL_NEW_RULE
;}
3480 | SQL_TOKEN_CHARACTER SQL_TOKEN_SET SQL_TOKEN_NAME
3489 {$$
= SQL_NEW_RULE
;}
3493 character_string_type opt_char_set_spec opt_collate_clause
3500 | national_character_string_type opt_collate_clause
3506 | binary_string_type
3512 character_string_type:
3513 SQL_TOKEN_CHARACTER opt_paren_precision
3519 | SQL_TOKEN_CHAR opt_paren_precision
3525 | SQL_TOKEN_CHARACTER SQL_TOKEN_VARYING paren_char_length
3532 | SQL_TOKEN_CHAR SQL_TOKEN_VARYING paren_char_length
3539 | SQL_TOKEN_VARCHAR paren_char_length
3545 | character_large_object_type
3547 opt_paren_precision:
3548 {$$
= SQL_NEW_RULE
;}
3552 '(' SQL_TOKEN_INTNUM
')'
3555 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
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
')'
3568 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3570 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3574 large_object_length:
3575 SQL_TOKEN_INTNUM opt_multiplier
3583 {$$
= SQL_NEW_RULE
;}
3587 $$
->append
(newNode
("K", SQLNodeType
::Punctuation
));
3592 $$
->append
(newNode
("M", SQLNodeType
::Punctuation
));
3597 $$
->append
(newNode
("G", SQLNodeType
::Punctuation
));
3602 $$
->append
(newNode
("T", SQLNodeType
::Punctuation
));
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
3619 | SQL_TOKEN_CHAR SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3627 | SQL_TOKEN_CLOB opt_paren_char_large_length
3634 national_character_string_type:
3635 SQL_TOKEN_NATIONAL SQL_TOKEN_CHARACTER opt_paren_precision
3642 | SQL_TOKEN_NATIONAL SQL_TOKEN_CHAR opt_paren_precision
3649 | SQL_TOKEN_NCHAR opt_paren_precision
3655 | SQL_TOKEN_NATIONAL SQL_TOKEN_CHARACTER SQL_TOKEN_VARYING paren_char_length
3663 | SQL_TOKEN_NATIONAL SQL_TOKEN_CHAR SQL_TOKEN_VARYING paren_char_length
3671 | SQL_TOKEN_NCHAR SQL_TOKEN_VARYING paren_char_length
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
3690 | SQL_TOKEN_NCHAR SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3698 | SQL_TOKEN_NCLOB opt_paren_char_large_length
3706 SQL_TOKEN_BINARY opt_paren_precision
3712 | SQL_TOKEN_BINARY SQL_TOKEN_VARYING paren_char_length
3719 | SQL_TOKEN_VARBINARY paren_char_length
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
3736 | SQL_TOKEN_BLOB opt_paren_char_large_length
3745 | approximate_numeric_type
3747 opt_paren_precision_scale:
3748 {$$
= SQL_NEW_RULE
;}
3749 |
'(' SQL_TOKEN_INTNUM
')'
3752 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3754 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3756 |
'(' SQL_TOKEN_INTNUM
',' SQL_TOKEN_INTNUM
')'
3759 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3761 $$
->append
(newNode
(",", SQLNodeType
::Punctuation
));
3763 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3767 SQL_TOKEN_NUMERIC opt_paren_precision_scale
3773 | SQL_TOKEN_DECIMAL opt_paren_precision_scale
3779 | SQL_TOKEN_DEC opt_paren_precision_scale
3785 | SQL_TOKEN_SMALLINT
3790 approximate_numeric_type:
3791 SQL_TOKEN_FLOAT
'(' SQL_TOKEN_INTNUM
')'
3795 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3797 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3802 | SQL_TOKEN_DOUBLE SQL_TOKEN_PRECISION
3814 | SQL_TOKEN_TIME opt_paren_precision opt_with_or_without_time_zone
3821 | SQL_TOKEN_TIMESTAMP opt_paren_precision opt_with_or_without_time_zone
3829 opt_with_or_without_time_zone:
3830 {$$
= SQL_NEW_RULE
;}
3831 | SQL_TOKEN_WITH SQL_TOKEN_TIME SQL_TOKEN_ZONE
3838 | SQL_TOKEN_WITHOUT SQL_TOKEN_TIME SQL_TOKEN_ZONE
3847 SQL_TOKEN_INTERVAL interval_qualifier
3854 /* the various things you can name */
3858 | SQL_TOKEN_POSITION
3860 sal_uInt32 nNod
= $$
->getRuleID
();
3862 $$
= newNode
(OSQLParser
::TokenIDToStr
(nNod
), SQLNodeType
::Name
);
3864 | SQL_TOKEN_CHAR_LENGTH
3866 sal_uInt32 nNod
= $$
->getRuleID
();
3868 $$
= newNode
(OSQLParser
::TokenIDToStr
(nNod
), SQLNodeType
::Name
);
3872 sal_uInt32 nNod
= $$
->getRuleID
();
3874 $$
= newNode
(OSQLParser
::TokenIDToStr
(nNod
), SQLNodeType
::Name
);
3879 | case_specification
3882 SQL_TOKEN_NULLIF
'(' value_exp_commalist
')'
3886 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3888 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3890 | SQL_TOKEN_COALESCE
'(' value_exp
')'
3894 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3896 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3898 | SQL_TOKEN_COALESCE
'(' value_exp_commalist
')'
3902 $$
->append
(newNode
("(", SQLNodeType
::Punctuation
));
3904 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
3912 SQL_TOKEN_CASE case_operand simple_when_clause_list else_clause SQL_TOKEN_END
3923 SQL_TOKEN_CASE searched_when_clause_list else_clause SQL_TOKEN_END
3932 simple_when_clause_list:
3935 $$
= SQL_NEW_LISTRULE
;
3938 | searched_when_clause_list simple_when_clause
3945 SQL_TOKEN_WHEN when_operand_list SQL_TOKEN_THEN result
3956 {$$
= SQL_NEW_COMMALISTRULE
;
3958 | when_operand_list
',' 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
;
3976 | searched_when_clause_list searched_when_clause
3982 searched_when_clause:
3983 SQL_TOKEN_WHEN search_condition SQL_TOKEN_THEN result
3993 {$$
= SQL_NEW_RULE
;}
3994 | SQL_TOKEN_ELSE result
4008 row_value_constructor_elem
4011 cursor: SQL_TOKEN_NAME
4017 module: SQL_TOKEN_NAME
4026 $$
->append
(newNode
(":", SQLNodeType
::Punctuation
));
4029 {$$
= SQL_NEW_RULE
; // test
4030 $$
->append
(newNode
("?", SQLNodeType
::Punctuation
));}
4031 |
'[' SQL_TOKEN_NAME
']'
4033 $$
->append
(newNode
("[", SQLNodeType
::Punctuation
));
4035 $$
->append
(newNode
("]", SQLNodeType
::Punctuation
));}
4039 procedure: SQL_TOKEN_NAME
4046 {$$
= SQL_NEW_RULE
;}
4047 | opt_as SQL_TOKEN_NAME
4054 user: SQL_TOKEN_NAME
4057 /* PREDICATECHECK RULES */
4059 search_condition
/* checking predicats */
4061 if
(xxx_pGLOBAL_SQLPARSER
->inPredicateCheck
()) // sql: rule 1
4064 if
( SQL_ISRULE
($$
,search_condition
) )
4066 $$
->insert
(0,newNode
("(", SQLNodeType
::Punctuation
));
4067 $$
->append
(newNode
(")", SQLNodeType
::Punctuation
));
4073 |
'(' sql
')' /* checking predicats */
4076 SQL_TOKEN_CREATE SQL_TOKEN_TRIGGER trigger_name trigger_action_time trigger_event SQL_TOKEN_ON table_name op_referencing triggered_action
4094 | SQL_TOKEN_REFERENCING transition_table_or_variable_list
4101 trigger_action_time:
4104 | SQL_TOKEN_INSTEAD SQL_TOKEN_OF
4114 | SQL_TOKEN_UPDATE op_trigger_columnlist
4121 op_trigger_columnlist:
4125 | SQL_TOKEN_OF trigger_column_list
4132 trigger_column_list:
4136 op_triggered_action_for triggered_when_clause triggered_SQL_statement
4144 op_triggered_action_for:
4148 | SQL_TOKEN_FOR SQL_TOKEN_EACH trigger_for
4158 | SQL_TOKEN_STATEMENT
4160 triggered_when_clause:
4164 | SQL_TOKEN_WHEN parenthesized_boolean_value_expression
4171 triggered_SQL_statement:
4172 SQL_procedure_statement
4173 | SQL_TOKEN_BEGIN SQL_TOKEN_ATOMIC SQL_procedure_statement_list
';' SQL_TOKEN_END
4179 $$
->append
(newNode
(";", SQLNodeType
::Punctuation
));
4183 SQL_procedure_statement_list:
4184 SQL_procedure_statement
4186 $$
= SQL_NEW_LISTRULE
;
4189 | SQL_procedure_statement_list
';' SQL_procedure_statement
4195 SQL_procedure_statement:
4199 transition_table_or_variable_list:
4200 transition_table_or_variable
4202 $$
= SQL_NEW_LISTRULE
;
4205 | transition_table_or_variable_list transition_table_or_variable
4212 transition_table_or_variable:
4213 SQL_TOKEN_OLD opt_row opt_as old_transition_variable_name
4221 | SQL_TOKEN_NEW opt_row opt_as new_transition_variable_name
4229 | SQL_TOKEN_OLD SQL_TOKEN_TABLE opt_as old_transition_table_name
4237 | SQL_TOKEN_NEW SQL_TOKEN_TABLE opt_as new_transition_table_name
4246 old_transition_table_name:
4247 transition_table_name
4249 new_transition_table_name:
4250 transition_table_name
4252 transition_table_name:
4255 old_transition_variable_name:
4258 new_transition_variable_name:
4266 #if defined _MSC_VER
4267 #pragma warning(pop)
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
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
;
4330 OSL_FAIL
( "OParseContext::getErrorMessage: unknown error code!" );
4337 OString OParseContext
::getIntlKeywordAscii
(InternationalKeyCode _eKey
) const
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
;
4368 OSL_FAIL
( "OParseContext::getIntlKeywordAscii: unknown key!" );
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", "" );
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
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
("*?");
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 ']'
4468 if
(c
== sSearch
[0])
4470 else if
(c
== sSearch
[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)
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
)
4528 if
((i
+1) < nQueryLen
)
4530 if
(pCopy
[i
]=='*' && pCopy
[i
+1]=='/')
4538 // comment can't close anymore, actually an error, but..
4542 if
(pCopy
[i
] == '\n')
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]=='/'))
4554 else if
((pCopy
[i
]=='/' && pCopy
[i
+1]=='*'))
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
());
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
;
4584 m_pParseTree
= nullptr
;
4585 m_sErrorMessage
= "";
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
();
4604 (*s_pGarbageCollector
)->clear
();
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
)
4621 IParseContext
::InternationalKeyCode eKeyCode
= IParseContext
::InternationalKeyCode
::None
;
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
);
4645 aStr
= yytname
[YYTRANSLATE
(nTokenID
)];
4646 if
(aStr.startsWith
("SQL_TOKEN_"))
4647 aStr
= aStr.copy
(10);
4654 aStr
= aStr.toAsciiLowerCase
();
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
]);
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
])
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
;
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
));
4715 pComp
= new OSQLInternalNode
("", SQLNodeType
::Rule
,OSQLParser
::RuleID
(OSQLParseNode
::comparison_predicate
));
4717 pComp
->append
(pColumnRef
);
4718 pComp
->append
(pCompare
);
4719 pComp
->append
(pLiteral
);
4722 pComp
->append
(new OSQLInternalNode
("", SQLNodeType
::Keyword
,SQL_TOKEN_AND
));
4723 pComp
->append
(pLiteral2
);
4725 pAppend
->append
(pComp
);
4729 sal_Int16 OSQLParser
::buildStringNodes
(OSQLParseNode
*& pLiteral
)
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
);
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
);
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
());
4781 aValue.append
(pLiteral
->getChild
(1)->getTokenValue
());
4783 pLiteral
= new OSQLInternalNode
(aValue.makeStringAndClear
(),SQLNodeType
::String
);
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
);
4798 OUString sFirst
= sStr.copy
(0,nPos1
);
4799 sal_Int32 nPos2
= sStr.indexOf
(sSQL_TOKEN
,nPos1
+1);
4802 OUString sSecond
= sStr.copy
(nPos1
+sSQL_TOKEN.getLength
(),nPos2
-nPos1
-sSQL_TOKEN.getLength
());
4804 sFirst
+= sStr.copy
(nPos2
+sSQL_TOKEN.getLength
());
4807 sFirst
+= sStr.copy
(nPos1
+sSQL_TOKEN.getLength
());
4809 m_sErrorMessage
= sFirst
;
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
();