1 %glr-parser
2 %token-table
3 %{
4 /*
5  * This file is part of the LibreOffice project.
6  *
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/.
10  *
11  * This file incorporates work covered by the following license notice:
12  *
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 .
20  */
21 
22 #include <vector>
23 #include <string.h>
24 
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>
43 
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>
49 
50 #if defined _MSC_VER
51 #pragma warning(push)
52 #pragma warning(disable: 4324) // structure was padded due to alignment specifier
53 #pragma warning(disable: 4065) // switch statement contains 'default' but no 'case' labels
54 #pragma warning(disable: 4702) // unreachable code
55 #endif
56 
57 #ifdef __GNUC__
58 # pragma GCC diagnostic ignored "-Wwrite-strings"
59 # pragma GCC diagnostic ignored "-Wunused-function"
60 #endif
61 
62 inline connectivity::OSQLInternalNode* newNode(const char* pNewValue,
63         const connectivity::SQLNodeType eNodeType,
64         const sal_uInt32 nNodeID = 0);
65 
66 inline connectivity::OSQLInternalNode* newNode(const OString& _newValue,
67         const connectivity::SQLNodeType eNodeType,
68         const sal_uInt32 nNodeID = 0);
69 
70 inline connectivity::OSQLInternalNode* newNode(const OUString& _newValue,
71         const connectivity::SQLNodeType eNodeType,
72         const sal_uInt32 nNodeID = 0);
73 
74 
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 #if defined YYBISON && YYBISON >= 30800
78 #define SQL_NEW_RULE 			newNode("", SQLNodeType::Rule, yyr1[yyrule])
79 #define SQL_NEW_LISTRULE 		newNode("", SQLNodeType::ListRule, yyr1[yyrule])
80 #define SQL_NEW_COMMALISTRULE   newNode("", SQLNodeType::CommaListRule, yyr1[yyrule])
81 #else
82 #define SQL_NEW_RULE 			newNode("", SQLNodeType::Rule, yyr1[yyn])
83 #define SQL_NEW_LISTRULE 		newNode("", SQLNodeType::ListRule, yyr1[yyn])
84 #define SQL_NEW_COMMALISTRULE   newNode("", SQLNodeType::CommaListRule, yyr1[yyn])
85 #endif
86 
87 
88 extern connectivity::OSQLParser* xxx_pGLOBAL_SQLPARSER;
89 
90 #define YYERROR_VERBOSE
91 
92 #define SQLyyerror(s)						\
93 {											\
94 	xxx_pGLOBAL_SQLPARSER->error(s);		\
95 }
96 
97 using namespace connectivity;
98 #define SQLyylex xxx_pGLOBAL_SQLPARSER->SQLlex
99 %}
100 	/* symbolic tokens */
101 
102 %union {
103 	connectivity::OSQLParseNode * pParseNode;
104 }
105 %type <pParseNode> '(' ')' ',' ':' ';' '?' '[' ']' '{' '}' '.' 'K' 'M' 'G' 'T' 'P'
106 
107 %token <pParseNode> SQL_TOKEN_STRING SQL_TOKEN_ACCESS_DATE SQL_TOKEN_INT SQL_TOKEN_REAL_NUM
108 %token <pParseNode> SQL_TOKEN_INTNUM SQL_TOKEN_APPROXNUM SQL_TOKEN_NOT SQL_TOKEN_NAME
109 
110 
111 %nonassoc <pParseNode> SQL_TOKEN_UMINUS
112 
113 
114 
115 	/* literal keyword tokens */
116 
117 %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 
119 %token <pParseNode> SQL_TOKEN_BETWEEN SQL_TOKEN_BIT SQL_TOKEN_BOTH SQL_TOKEN_BY
120 
121 %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
122 %token <pParseNode> SQL_TOKEN_CURRENT SQL_TOKEN_CURSOR
123 
124 %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
125 %token <pParseNode> SQL_TOKEN_DISTINCT SQL_TOKEN_DOUBLE SQL_TOKEN_DROP
126 
127 %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 
129 %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 
131 %left <pParseNode> SQL_TOKEN_JOIN
132 %token <pParseNode> SQL_TOKEN_KEY SQL_TOKEN_LEADING SQL_TOKEN_LIKE SQL_TOKEN_LOCAL SQL_TOKEN_LOWER
133 %token <pParseNode> SQL_TOKEN_MAX SQL_TOKEN_MIN SQL_TOKEN_NATURAL SQL_TOKEN_NCHAR SQL_TOKEN_NULL SQL_TOKEN_NUMERIC
134 
135 %token <pParseNode> SQL_TOKEN_OCTET_LENGTH SQL_TOKEN_OF SQL_TOKEN_ON SQL_TOKEN_OPTION SQL_TOKEN_ORDER SQL_TOKEN_OUTER
136 
137 %token <pParseNode> SQL_TOKEN_PRECISION SQL_TOKEN_PRIMARY SQL_TOKEN_PRIVILEGES SQL_TOKEN_PROCEDURE SQL_TOKEN_PUBLIC
138 %token <pParseNode> SQL_TOKEN_REAL SQL_TOKEN_REFERENCES SQL_TOKEN_ROLLBACK
139 
140 %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 
142 %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
143 %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
144 %token <pParseNode> SQL_TOKEN_WHERE SQL_TOKEN_WITH SQL_TOKEN_WORK SQL_TOKEN_ZONE
145 
146 /* ODBC KEYWORDS */
147 %token <pParseNode> SQL_TOKEN_CALL SQL_TOKEN_D SQL_TOKEN_FN SQL_TOKEN_T SQL_TOKEN_TS SQL_TOKEN_OJ
148 /* string functions */
149 %token <pParseNode> SQL_TOKEN_ASCII SQL_TOKEN_BIT_LENGTH  SQL_TOKEN_CHAR  SQL_TOKEN_CHAR_LENGTH  SQL_TOKEN_SQL_TOKEN_INTNUM
150 %token <pParseNode> SQL_TOKEN_CONCAT
151 %token <pParseNode> SQL_TOKEN_DIFFERENCE  SQL_TOKEN_INSERT SQL_TOKEN_LCASE  SQL_TOKEN_LEFT SQL_TOKEN_LENGTH  SQL_TOKEN_LOCATE
152 %token <pParseNode> SQL_TOKEN_LOCATE_2 SQL_TOKEN_LTRIM SQL_TOKEN_POSITION SQL_TOKEN_REPEAT SQL_TOKEN_REPLACE
153 %token <pParseNode> SQL_TOKEN_RIGHT SQL_TOKEN_RTRIM SQL_TOKEN_SOUNDEX SQL_TOKEN_SPACE  SQL_TOKEN_SUBSTRING SQL_TOKEN_UCASE
154 
155 /* time and date functions */
156 %token <pParseNode> SQL_TOKEN_CURRENT_DATE SQL_TOKEN_CURRENT_TIME SQL_TOKEN_CURRENT_TIMESTAMP SQL_TOKEN_CURDATE SQL_TOKEN_CURTIME
157 %token <pParseNode> SQL_TOKEN_DAYNAME  SQL_TOKEN_DAYOFMONTH  SQL_TOKEN_DAYOFWEEK  SQL_TOKEN_DAYOFYEAR SQL_TOKEN_EXTRACT
158 %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
159 %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
160 
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
166 
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
170 
171 %token <pParseNode> SQL_TOKEN_RANK SQL_TOKEN_DENSE_RANK	SQL_TOKEN_PERCENT_RANK	SQL_TOKEN_CUME_DIST SQL_TOKEN_PERCENTILE_CONT SQL_TOKEN_PERCENTILE_DISC SQL_TOKEN_WITHIN SQL_TOKEN_ARRAY_AGG
172 %token <pParseNode> SQL_TOKEN_CASE SQL_TOKEN_THEN SQL_TOKEN_END SQL_TOKEN_NULLIF SQL_TOKEN_COALESCE SQL_TOKEN_WHEN SQL_TOKEN_ELSE
173 %token <pParseNode> SQL_TOKEN_BEFORE SQL_TOKEN_AFTER SQL_TOKEN_INSTEAD SQL_TOKEN_EACH SQL_TOKEN_REFERENCING SQL_TOKEN_BEGIN SQL_TOKEN_ATOMIC SQL_TOKEN_TRIGGER SQL_TOKEN_ROW SQL_TOKEN_STATEMENT
174 %token <pParseNode> SQL_TOKEN_NEW SQL_TOKEN_OLD
175 %token <pParseNode> SQL_TOKEN_VALUE SQL_TOKEN_CURRENT_CATALOG SQL_TOKEN_CURRENT_DEFAULT_TRANSFORM_GROUP SQL_TOKEN_CURRENT_PATH SQL_TOKEN_CURRENT_ROLE SQL_TOKEN_CURRENT_SCHEMA SQL_TOKEN_CURRENT_USER
176 %token <pParseNode> SQL_TOKEN_SESSION_USER SQL_TOKEN_SYSTEM_USER SQL_TOKEN_VARCHAR SQL_TOKEN_VARBINARY SQL_TOKEN_VARYING SQL_TOKEN_OBJECT SQL_TOKEN_NCLOB SQL_TOKEN_NATIONAL
177 %token <pParseNode> SQL_TOKEN_LARGE SQL_TOKEN_CLOB SQL_TOKEN_BLOB SQL_TOKEN_BIGINT SQL_TOKEN_BINARY SQL_TOKEN_WITHOUT SQL_TOKEN_BOOLEAN SQL_TOKEN_INTERVAL
178 // window function
179 %token <pParseNode> SQL_TOKEN_OVER SQL_TOKEN_ROW_NUMBER SQL_TOKEN_NTILE SQL_TOKEN_LEAD SQL_TOKEN_LAG SQL_TOKEN_RESPECT SQL_TOKEN_IGNORE SQL_TOKEN_NULLS
180 %token <pParseNode> SQL_TOKEN_FIRST_VALUE SQL_TOKEN_LAST_VALUE SQL_TOKEN_NTH_VALUE SQL_TOKEN_FIRST SQL_TOKEN_LAST
181 %token <pParseNode> SQL_TOKEN_EXCLUDE SQL_TOKEN_OTHERS SQL_TOKEN_TIES SQL_TOKEN_FOLLOWING SQL_TOKEN_UNBOUNDED SQL_TOKEN_PRECEDING SQL_TOKEN_RANGE SQL_TOKEN_ROWS
182 %token <pParseNode> SQL_TOKEN_PARTITION SQL_TOKEN_WINDOW SQL_TOKEN_NO
183 // LIMIT and OFFSEt
184 %token <pParseNode> SQL_TOKEN_LIMIT SQL_TOKEN_OFFSET SQL_TOKEN_NEXT SQL_TOKEN_ONLY
185 
186 	/* operators */
187 %left SQL_TOKEN_NAME
188 %left <pParseNode> SQL_TOKEN_OR
189 %left <pParseNode> SQL_TOKEN_AND
190 
191 %left <pParseNode> SQL_LESSEQ SQL_GREATEQ SQL_NOTEQUAL SQL_LESS SQL_GREAT SQL_EQUAL /* '<' '>' = <> < > <= >= != */
192 %left <pParseNode> '+' '-' SQL_CONCAT
193 %left <pParseNode> '*' '/'
194 %left SQL_TOKEN_NATURAL SQL_TOKEN_CROSS SQL_TOKEN_FULL SQL_TOKEN_LEFT SQL_TOKEN_RIGHT
195 %left ')'
196 %right '='
197 %right '.'
198 %right '('
199 
200 
201 %token <pParseNode> SQL_TOKEN_INVALIDSYMBOL
202 
203 /*%type <pParseNode> sql_single_statement */
204 
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*/
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 fold
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 upper_lower 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
265 %%
266 
267 /* Return Parse Tree to OSQLParser
268  * (the access over yyval after calling the parser fails,
269  *
270  */
271 sql_single_statement:
272 		sql
273 		{ xxx_pGLOBAL_SQLPARSER->setParseTree( $1 ); }
274 	|	sql ';'
275 		{ xxx_pGLOBAL_SQLPARSER->setParseTree( $1 ); }
276 	;
277 
278 	/* schema definition language */
279 	/* Note: other ``sql:sal_Unicode() rules appear later in the grammar */
280 
281 sql:
282 		manipulative_statement
283 	|	schema_element
284            {
285                 $$ = SQL_NEW_RULE;
286 		$$->append($1);
287 	   }
288 	;
289 
290 /***
291 
292 op_authorization:
293 		{$$ = SQL_NEW_RULE;}
294 	|	SQL_TOKEN_AUTHORIZATION user
295 		{
296 			$$ = SQL_NEW_RULE;
297 			$$->append($1);
298 			$$->append($2);
299 		}
300 	;
301 op_schema:
302 		{$$ = SQL_NEW_RULE;}
303 	|	SQL_TOKEN_NAME
304 	|	SQL_TOKEN_NAME '.' SQL_TOKEN_NAME
305 		{
306 			$$ = SQL_NEW_RULE;
307 			$$->append($1);
308 			$$->append(newNode(".", SQLNodeType::Punctuation));
309 			$$->append($3);
310 		}
311 	;
312 
313 schema:
314 		SQL_TOKEN_CREATE SQL_TOKEN_SCHEMA op_schema op_authorization opt_schema_element_list
315 		{
316 			$$ = SQL_NEW_RULE;
317 			$$->append($1);
318 			$$->append($2);
319 			$$->append($3);
320 			$$->append($4);
321 			$$->append($5);
322 		}
323 	;
324 
325 opt_schema_element_list:
326 			{$$ = SQL_NEW_RULE;}
327 	|       schema_glement_list
328 	;
329 
330 schema_element_list:
331 		schema_element
332 			{$$ = SQL_NEW_LISTRULE;
333 			$$->append($1);}
334 	|       schema_element_list schema_element
335 			{$1->append($2);
336 			$$ = $1;}
337 	;
338 */
339 
340 schema_element:
341 			base_table_def
342 	|       view_def
343 	|       privilege_def
344 	|		trigger_definition
345 	;
346 
347 base_table_def:
348 		SQL_TOKEN_CREATE SQL_TOKEN_TABLE table_node '(' base_table_element_commalist ')'
349 		{$$ = SQL_NEW_RULE;
350 		$$->append($1);
351 		$$->append($2);
352 		$$->append($3);
353 		$$->append(newNode("(", SQLNodeType::Punctuation));
354 		$$->append($5);
355 		$$->append(newNode(")", SQLNodeType::Punctuation));}
356 	;
357 
358 base_table_element_commalist:
359 		base_table_element
360 		{$$ = SQL_NEW_COMMALISTRULE;
361 		$$->append($1);}
362 	|   base_table_element_commalist ',' base_table_element
363 		{$1->append($3);
364 		$$ = $1;}
365 	;
366 
367 base_table_element:
368 		column_def
369 	|	table_constraint_def
370 	;
371 
372 column_def:
373 		column data_type column_def_opt_list
374 			{$$ = SQL_NEW_RULE;
375 			$$->append($1);
376 			$$->append($2);
377 			$$->append($3);
378 			}
379 	;
380 
381 column_def_opt_list:
382 		/* empty */                 {$$ = SQL_NEW_LISTRULE;}
383 	|       column_def_opt_list column_def_opt
384 			{$1->append($2);
385 			$$ = $1;}
386 	;
387 
388 nil_fkt:
389 	datetime_value_fct
390 	;
391 unique_spec:
392 		SQL_TOKEN_UNIQUE
393 	|	SQL_TOKEN_PRIMARY SQL_TOKEN_KEY
394 		{
395 			$$ = SQL_NEW_RULE;
396 			$$->append($1);
397 			$$->append($2);
398 		}
399 	;
400 column_def_opt:
401 		SQL_TOKEN_NOT SQL_TOKEN_NULL
402 			{$$ = SQL_NEW_RULE;
403 			$$->append($1);
404 			$$->append($2);}
405 	|       unique_spec
406 	|       SQL_TOKEN_DEFAULT literal
407 			{$$ = SQL_NEW_RULE;
408 			$$->append($1);
409 			$$->append($2);}
410 	|       SQL_TOKEN_DEFAULT SQL_TOKEN_NULL
411 			{$$ = SQL_NEW_RULE;
412 			$$->append($1);
413 			$$->append($2);}
414 	|       SQL_TOKEN_DEFAULT SQL_TOKEN_USER
415 			{$$ = SQL_NEW_RULE;
416 			$$->append($1);
417 			$$->append($2);}
418 	|		SQL_TOKEN_DEFAULT nil_fkt
419 			{
420 				$$ = SQL_NEW_RULE;
421 				$$->append($1);
422 				$$->append($2);
423 			}
424 	|       SQL_TOKEN_CHECK
425 	|       SQL_TOKEN_CHECK '(' search_condition ')'
426 			{$$ = SQL_NEW_RULE;
427 			$$->append($1);
428 			$$->append(newNode("(", SQLNodeType::Punctuation));
429 			$$->append($3);
430 			$$->append(newNode(")", SQLNodeType::Punctuation));}
431 	|       SQL_TOKEN_REFERENCES table_node
432 			{$$ = SQL_NEW_RULE;
433 			$$->append($1);
434 			$$->append($2);}
435 	|       SQL_TOKEN_REFERENCES table_node '(' column_commalist ')'
436 			{$$ = SQL_NEW_RULE;
437 			$$->append($1);
438 			$$->append($2);
439 			$$->append(newNode("(", SQLNodeType::Punctuation));
440 			$$->append($4);
441 			$$->append(newNode(")", SQLNodeType::Punctuation));}
442 	;
443 
444 table_constraint_def:
445 		unique_spec '(' column_commalist ')'
446 			{$$ = SQL_NEW_RULE;
447 			$$->append($1);
448 			$$->append(newNode("(", SQLNodeType::Punctuation));
449 			$$->append($3);
450 			$$->append(newNode(")", SQLNodeType::Punctuation));}
451 	|       SQL_TOKEN_FOREIGN SQL_TOKEN_KEY '(' column_commalist ')' SQL_TOKEN_REFERENCES table_node
452 			{$$ = SQL_NEW_RULE;
453 			$$->append($1);
454 			$$->append($2);
455 			$$->append(newNode("(", SQLNodeType::Punctuation));
456 			$$->append($4);
457 			$$->append(newNode(")", SQLNodeType::Punctuation));
458 			$$->append($6);
459 			$$->append($7);}
460 	|       SQL_TOKEN_FOREIGN SQL_TOKEN_KEY '(' column_commalist ')' SQL_TOKEN_REFERENCES table_node '(' column_commalist ')'
461 			{$$ = SQL_NEW_RULE;
462 			$$->append($1);
463 			$$->append($2);
464 			$$->append(newNode("(", SQLNodeType::Punctuation));
465 			$$->append($4);
466 			$$->append(newNode(")", SQLNodeType::Punctuation));
467 			$$->append($6);
468 			$$->append($7);
469 			$$->append(newNode("(", SQLNodeType::Punctuation));
470 			$$->append($9);
471 			$$->append(newNode(")", SQLNodeType::Punctuation));}
472 	|       SQL_TOKEN_CHECK '(' search_condition ')'
473 			{$$ = SQL_NEW_RULE;
474 			$$->append($1);
475 			$$->append(newNode("(", SQLNodeType::Punctuation));
476 			$$->append($3);
477 			$$->append(newNode(")", SQLNodeType::Punctuation));}
478 	;
479 op_column_commalist:
480 	/* empty */ {$$ = SQL_NEW_RULE;}
481 	| '(' column_commalist ')'
482 		{$$ = SQL_NEW_RULE;
483 			$$->append(newNode("(", SQLNodeType::Punctuation));
484 			$$->append($2);
485 			$$->append(newNode(")", SQLNodeType::Punctuation));
486 		}
487 	;
488 column_commalist:
489 		column_commalist ',' column
490 			{$1->append($3);
491 			$$ = $1;}
492 	|	column
493 			{$$ = SQL_NEW_COMMALISTRULE;
494 			$$->append($1);}
495 	;
496 
497 view_def:
498 		SQL_TOKEN_CREATE SQL_TOKEN_VIEW table_node opt_column_commalist SQL_TOKEN_AS select_statement opt_with_check_option
499 			{$$ = SQL_NEW_RULE;
500 			$$->append($1);
501 			$$->append($2);
502 			$$->append($3);
503 			$$->append($4);
504 			$$->append($5);
505 			$$->append($6);
506 			$$->append($7);}
507 	;
508 
509 opt_with_check_option:
510 		/* empty */         {$$ = SQL_NEW_RULE;}
511 	|       SQL_TOKEN_WITH SQL_TOKEN_CHECK SQL_TOKEN_OPTION
512 			{$$ = SQL_NEW_RULE;
513 			$$->append($1);
514 			$$->append($2);
515 			$$->append($3);}
516 	;
517 
518 opt_column_commalist:
519 		/* empty */         {$$ = SQL_NEW_RULE;}
520 	|       '(' column_commalist ')'
521 			{$$ = SQL_NEW_RULE;
522 			$$->append(newNode("(", SQLNodeType::Punctuation));
523 			$$->append($2);
524 			$$->append(newNode(")", SQLNodeType::Punctuation));}
525 	;
526 
527 privilege_def:
528 		SQL_TOKEN_GRANT privileges SQL_TOKEN_ON table_node SQL_TOKEN_TO grantee_commalist
529 		opt_with_grant_option
530 			{$$ = SQL_NEW_RULE;
531 			$$->append($1);
532 			$$->append($2);
533 			$$->append($3);
534 			$$->append($4);
535 			$$->append($5);
536 			$$->append($6);
537 			$$->append($7);}
538 	;
539 
540 opt_with_grant_option:
541 		/* empty */         {$$ = SQL_NEW_RULE;}
542 	|       SQL_TOKEN_WITH SQL_TOKEN_GRANT SQL_TOKEN_OPTION
543 			{$$ = SQL_NEW_RULE;
544 			$$->append($1);
545 			$$->append($2);
546 			$$->append($3);}
547 	;
548 
549 privileges:
550 		SQL_TOKEN_ALL SQL_TOKEN_PRIVILEGES
551 			{$$ = SQL_NEW_RULE;
552 			$$->append($1);
553 			$$->append($2);}
554 	|       operation_commalist
555 	;
556 
557 operation_commalist:
558 		operation
559 			{$$ = SQL_NEW_COMMALISTRULE;
560 			$$->append($1);}
561 	|       operation_commalist ',' operation
562 			{$1->append($3);
563 			$$ = $1;}
564 	;
565 
566 operation:
567 			SQL_TOKEN_SELECT
568 	|       SQL_TOKEN_INSERT opt_column_commalist
569 			{$$ = SQL_NEW_RULE;
570 			$$->append($1);
571 			$$->append($2);}
572 	|       SQL_TOKEN_DELETE
573 	|       SQL_TOKEN_UPDATE opt_column_commalist
574 			{$$ = SQL_NEW_RULE;
575 			$$->append($1);
576 			$$->append($2);}
577 	|       SQL_TOKEN_REFERENCES opt_column_commalist
578 			{$$ = SQL_NEW_RULE;
579 			$$->append($1);
580 			$$->append($2);}
581 	|		SQL_TOKEN_USAGE
582 	;
583 
584 
585 grantee_commalist:
586 		grantee
587 			{$$ = SQL_NEW_COMMALISTRULE;
588 			$$->append($1);}
589 	|       grantee_commalist ',' grantee
590 			{$1->append($3);
591 			$$ = $1;}
592 	;
593 
594 grantee:
595 			SQL_TOKEN_PUBLIC
596 	|       user
597 	;
598 
599 	/* module language */
600 
601 opt_order_by_clause:
602 		/* empty */         {$$ = SQL_NEW_RULE;}
603 	|       SQL_TOKEN_ORDER SQL_TOKEN_BY ordering_spec_commalist
604 			{$$ = SQL_NEW_RULE;
605 			$$->append($1);
606 			$$->append($2);
607 			$$->append($3);}
608 	;
609 
610 ordering_spec_commalist:
611 		ordering_spec
612 			{$$ = SQL_NEW_COMMALISTRULE;
613 			$$->append($1);}
614 	|       ordering_spec_commalist ',' ordering_spec
615 			{$1->append($3);
616 			$$ = $1;}
617 	;
618 
619 ordering_spec:
620 /*		SQL_TOKEN_INTNUM opt_asc_desc
621 			{$$ = SQL_NEW_RULE;
622 			$$->append($1);
623 			$$->append($2);}
624 */
625 		predicate opt_asc_desc
626 			{$$ = SQL_NEW_RULE;
627 			$$->append($1);
628 			$$->append($2);}
629 
630 	|	row_value_constructor_elem opt_asc_desc
631 			{$$ = SQL_NEW_RULE;
632 			$$->append($1);
633 			$$->append($2);}
634 	;
635 
636 opt_asc_desc:
637 		{$$ = SQL_NEW_RULE;}
638 	|	SQL_TOKEN_ASC
639 	|	SQL_TOKEN_DESC
640 	;
641 
642 
643 /***
644 manipulative_statement_list:
645 		manipulative_statement
646 			{$$ = SQL_NEW_LISTRULE;
647 			$$->append($1);}
648 	|       manipulative_statement_list manipulative_statement
649 			{$1->append($2);
650 			$$ = $1;}
651 	;
652 ***/
653 
654 sql_not:
655 /* vide */
656 	{$$ = SQL_NEW_RULE;}
657 	|	SQL_TOKEN_NOT
658 	;
659 
660 /* manipulative statements */
661 
662 manipulative_statement:
663 			commit_statement
664 /*	|       delete_statement_positioned*/
665 	|       delete_statement_searched
666 	|       fetch_statement
667 	|       insert_statement
668 	|       rollback_statement
669 	|       select_statement_into
670 /*	|       update_statement_positioned*/
671 	|       update_statement_searched
672 	|		union_statement
673 	|		'{' odbc_call_spec '}'
674 		{
675 			$$ = SQL_NEW_RULE;
676 			$$->append(newNode("{", SQLNodeType::Punctuation));
677 			$$->append($2);
678 			$$->append(newNode("}", SQLNodeType::Punctuation));
679 		}
680 	;
681 
682 union_statement:
683 			select_statement
684 	|		union_statement SQL_TOKEN_UNION all select_statement
685 		{
686 			$$ = SQL_NEW_RULE;
687 			$$->append($1);
688 			$$->append($2);
689 			$$->append($3);
690 			$$->append($4);
691 		}
692 	;
693 commit_statement:
694 		SQL_TOKEN_COMMIT SQL_TOKEN_WORK
695 			{$$ = SQL_NEW_RULE;
696 			$$->append($1);
697 			$$->append($2);}
698 	;
699 /*
700 delete_statement_positioned:
701 		SQL_TOKEN_DELETE SQL_TOKEN_FROM table_node SQL_TOKEN_WHERE SQL_TOKEN_CURRENT SQL_TOKEN_OF cursor
702 			{$$ = SQL_NEW_RULE;
703 			$$->append($1);
704 			$$->append($2);
705 			$$->append($3);
706 			$$->append($4);
707 			$$->append($5);
708 			$$->append($6);
709 			$$->append($7);}
710 	;
711 */
712 delete_statement_searched:
713 		SQL_TOKEN_DELETE SQL_TOKEN_FROM table_node opt_where_clause
714 			{$$ = SQL_NEW_RULE;
715 			$$->append($1);
716 			$$->append($2);
717 			$$->append($3);
718 			$$->append($4);}
719 	;
720 
721 fetch_statement:
722 		SQL_TOKEN_FETCH cursor SQL_TOKEN_INTO target_commalist
723 			{$$ = SQL_NEW_RULE;
724 			$$->append($1);
725 			$$->append($2);
726 			$$->append($3);
727 			$$->append($4);}
728 	;
729 
730 insert_statement:
731 		SQL_TOKEN_INSERT SQL_TOKEN_INTO table_node opt_column_commalist query_exp
732 			{$$ = SQL_NEW_RULE;
733 			$$->append($1);
734 			$$->append($2);
735 			$$->append($3);
736 			$$->append($4);
737 			$$->append($5);}
738 	;
739 values_or_query_spec:
740 		SQL_TOKEN_VALUES '(' table_value_const_list ')'
741 		{$$ = SQL_NEW_RULE;
742 			$$->append($1);
743 			$$->append(newNode("(", SQLNodeType::Punctuation));
744 			$$->append($3);
745 			$$->append(newNode(")", SQLNodeType::Punctuation));
746 		}
747 	;
748 
749 table_value_const_list:
750 			row_value_constructor
751 			{$$ = SQL_NEW_COMMALISTRULE;
752 			$$->append($1);}
753 	|       table_value_const_list ',' row_value_constructor
754 			{$1->append($3);
755 			$$ = $1;}
756 	;
757 /*
758 row_value_const_list:
759 			row_value_constructor_elem
760 			{$$ = SQL_NEW_COMMALISTRULE;
761 			$$->append($1);}
762 	|       row_value_const_list ',' row_value_constructor_elem
763 			{$1->append($3);
764 			$$ = $1;}
765 	;
766 */
767 row_value_constructor:
768 			row_value_constructor_elem
769 /*	  |		'(' row_value_const_list ')'
770 			{
771 				$$ = SQL_NEW_RULE;
772 				$$->append(newNode("(", SQLNodeType::Punctuation));
773 				$$->append($2);
774 				$$->append(newNode(")", SQLNodeType::Punctuation));
775 			}
776 			*/
777 	;
778 row_value_constructor_elem:
779 			value_exp /*[^')']*/
780 	|		SQL_TOKEN_DEFAULT
781 	;
782 
783 
784 rollback_statement:
785 		SQL_TOKEN_ROLLBACK SQL_TOKEN_WORK
786 			{$$ = SQL_NEW_RULE;
787 			$$->append($1);
788 			$$->append($2);}
789 	;
790 
791 
792 		/* INTO target_commalist herausgenommen */
793 select_statement_into:
794 		SQL_TOKEN_SELECT opt_all_distinct selection SQL_TOKEN_INTO target_commalist table_exp
795 			{$$ = SQL_NEW_RULE;
796 			$$->append($1);
797 			$$->append($2);
798 			$$->append($3);
799 			$$->append($4);
800 			$$->append($5);
801 			$$->append($6); }
802 	;
803 
804 opt_all_distinct:
805 			{$$ = SQL_NEW_RULE;}
806 		|	SQL_TOKEN_ALL
807 		|	SQL_TOKEN_DISTINCT
808 
809 	;
810 /*
811 update_statement_positioned:
812 		SQL_TOKEN_UPDATE table_node SQL_TOKEN_SET assignment_commalist
813 		SQL_TOKEN_WHERE SQL_TOKEN_CURRENT SQL_TOKEN_OF cursor
814 			{$$ = SQL_NEW_RULE;
815 			$$->append($1);
816 			$$->append($2);
817 			$$->append($3);
818 			$$->append($4);
819 			$$->append($5);
820 			$$->append($6);
821 			$$->append($7);
822 			$$->append($8);}
823 	;
824 */
825 assignment_commalist:
826 			assignment
827 			{$$ = SQL_NEW_COMMALISTRULE;
828 			$$->append($1);}
829 	|       assignment_commalist ',' assignment
830 			{$1->append($3);
831 			$$ = $1;}
832 	;
833 
834 assignment:
835 		column SQL_EQUAL update_source
836 			{$$ = SQL_NEW_RULE;
837 			$$->append($1);
838 			$$->append($2);
839 			$$->append($3);}
840 	;
841 update_source:
842 		value_exp
843 	  | SQL_TOKEN_DEFAULT
844 	;
845 update_statement_searched:
846 		SQL_TOKEN_UPDATE table_node SQL_TOKEN_SET assignment_commalist opt_where_clause
847 			{$$ = SQL_NEW_RULE;
848 			$$->append($1);
849 			$$->append($2);
850 			$$->append($3);
851 			$$->append($4);
852 			$$->append($5);}
853 	;
854 
855 target_commalist:
856 		target
857 			{$$ = SQL_NEW_COMMALISTRULE;
858 			$$->append($1);}
859 	|       target_commalist ',' target
860 			{$1->append($3);
861 			$$ = $1;}
862 	;
863 
864 target:
865 		parameter_ref
866 	;
867 
868 opt_where_clause:
869 		/* empty */             {$$ = SQL_NEW_RULE;}
870 	|       where_clause
871 	;
872 
873 	/* query expressions */
874 
875 query_term:
876 		non_join_query_term
877 		{
878 			$$ = SQL_NEW_RULE;
879 			$$->append($1);
880 		}
881     ;
882 /* SELECT STATEMENT */
883 select_statement:
884 		SQL_TOKEN_SELECT opt_all_distinct selection table_exp
885 		{
886 			$$ = SQL_NEW_RULE;
887 			$$->append($1);
888 			$$->append($2);
889 			$$->append($3);
890 			$$->append($4);
891 		}
892 	;
893 
894 selection:
895 		'*'
896 		{
897 			$$ = SQL_NEW_RULE;
898 			$$->append(newNode("*", SQLNodeType::Punctuation));
899 		}
900 	|	scalar_exp_commalist
901 	;
902 opt_result_offset_clause:
903 		/* empty */ {$$ = SQL_NEW_RULE;}
904 	|	result_offset_clause
905 	;
906 result_offset_clause:
907 	SQL_TOKEN_OFFSET offset_row_count row_or_rows
908 	{
909 		$$ = SQL_NEW_RULE;
910 		$$->append($1);
911 		$$->append($2);
912 		$$->append($3);
913 	}
914 	;
915 opt_fetch_first_row_count:
916 		/* empty */ {$$ = SQL_NEW_RULE;}
917 	|	fetch_first_row_count
918 	;
919 first_or_next:
920 		SQL_TOKEN_FIRST
921 	|	SQL_TOKEN_NEXT
922 	;
923 row_or_rows:
924 		SQL_TOKEN_ROW
925 	|	SQL_TOKEN_ROWS
926 	;
927 opt_fetch_first_clause:
928 		/* empty */ {$$ = SQL_NEW_RULE;}
929 	|	fetch_first_clause
930 	;
931 fetch_first_clause:
932 	SQL_TOKEN_FETCH first_or_next opt_fetch_first_row_count row_or_rows SQL_TOKEN_ONLY
933 	{
934 		$$ = SQL_NEW_RULE;
935 		$$->append($1);
936 		$$->append($2);
937 		$$->append($3);
938 		$$->append($4);
939 		$$->append($5);
940 	}
941 	;
942 offset_row_count:
943 	literal
944 	;
945 fetch_first_row_count:
946 	literal
947 	;
948 
949 opt_limit_offset_clause:
950 		/* empty */ {$$ = SQL_NEW_RULE;}
951 	|	limit_offset_clause
952 	;
953 opt_offset:
954 		/* empty */ {$$ = SQL_NEW_RULE;}
955 	|	SQL_TOKEN_OFFSET SQL_TOKEN_INTNUM
956 	{
957 		$$ = SQL_NEW_RULE;
958 		$$->append($1);
959 		$$->append($2);
960 	}
961 	;
962 limit_offset_clause:
963 	SQL_TOKEN_LIMIT SQL_TOKEN_INTNUM opt_offset
964 	{
965 		$$ = SQL_NEW_RULE;
966 		$$->append($1);
967 		$$->append($2);
968 		$$->append($3);
969 	}
970 	;
971 table_exp:
972 		from_clause opt_where_clause opt_group_by_clause opt_having_clause opt_window_clause opt_order_by_clause opt_limit_offset_clause opt_result_offset_clause opt_fetch_first_clause
973 		{
974 			$$ = SQL_NEW_RULE;
975 			$$->append($1);
976 			$$->append($2);
977 			$$->append($3);
978 			$$->append($4);
979 			$$->append($5);
980 			$$->append($6);
981 			$$->append($7);
982 			$$->append($8);
983 			$$->append($9);
984 		}
985 	;
986 
987 from_clause:
988 		SQL_TOKEN_FROM table_ref_commalist
989 			{ $$ = SQL_NEW_RULE;
990 			  $$->append($1);
991 			  $$->append($2); }
992 	;
993 
994 table_ref_commalist:
995 
996 		table_ref
997 			{ $$ = SQL_NEW_COMMALISTRULE;
998 			  $$->append($1); }
999 	|       table_ref_commalist ',' table_ref
1000 			{ $1->append($3);
1001 			  $$ = $1; }
1002 	;
1003 
1004 opt_as:
1005 		/* empty */ {$$ = SQL_NEW_RULE;}
1006 	|	SQL_TOKEN_AS
1007 	;
1008 opt_row:
1009 		/* empty */ {$$ = SQL_NEW_RULE;}
1010 	|	SQL_TOKEN_ROW
1011 	;
1012 table_primary_as_range_column:
1013         {$$ = SQL_NEW_RULE;}
1014 	|   opt_as SQL_TOKEN_NAME op_column_commalist
1015 		{
1016 		    $$ = SQL_NEW_RULE;
1017 		    $$->append($1);
1018 		    $$->append($2);
1019 		    $$->append($3);
1020 		}
1021     ;
1022 table_ref:
1023         table_node table_primary_as_range_column
1024 		{
1025 			$$ = SQL_NEW_RULE;
1026 			$$->append($1);
1027 			$$->append($2);
1028 		}
1029 	|   subquery range_variable op_column_commalist
1030 		{
1031 			$$ = SQL_NEW_RULE;
1032 			$$->append($1);
1033 			$$->append($2);
1034 			$$->append($3);
1035 		}
1036 	|	joined_table
1037 	|	'{' SQL_TOKEN_OJ joined_table '}'
1038 		{
1039 			$$ = SQL_NEW_RULE;
1040 			$$->append(newNode("{", SQLNodeType::Punctuation));
1041 			$$->append($2);
1042 			$$->append($3);
1043 			$$->append(newNode("}", SQLNodeType::Punctuation));
1044 		}
1045 	|	'(' joined_table ')'
1046 		{
1047 			$$ = SQL_NEW_RULE;
1048 			$$->append(newNode("(", SQLNodeType::Punctuation));
1049 			$$->append($2);
1050 			$$->append(newNode(")", SQLNodeType::Punctuation));
1051 		}
1052 	;
1053 where_clause:
1054 		SQL_TOKEN_WHERE search_condition
1055 			{$$ = SQL_NEW_RULE;
1056 			$$->append($1);
1057 			$$->append($2);}
1058 	;
1059 
1060 opt_group_by_clause:
1061 		/* empty */      {$$ = SQL_NEW_RULE;}
1062 	|   SQL_TOKEN_GROUP SQL_TOKEN_BY column_ref_commalist
1063 			{$$ = SQL_NEW_RULE;
1064 			$$->append($1);
1065 			$$->append($2);
1066 			$$->append($3);}
1067 	;
1068 
1069 column_ref_commalist:
1070 		column_ref
1071 			{$$ = SQL_NEW_COMMALISTRULE;
1072 			$$->append($1);}
1073 	|	set_fct_spec
1074 		{$$ = SQL_NEW_COMMALISTRULE;
1075 			$$->append($1);}
1076 	|   column_ref_commalist ',' column_ref
1077 			{$1->append($3);
1078 			$$ = $1;}
1079 	|   column_ref_commalist ',' set_fct_spec
1080 			{$1->append($3);
1081 			$$ = $1;}
1082 	;
1083 
1084 opt_having_clause:
1085 		/* empty */                 {$$ = SQL_NEW_RULE;}
1086 	|       SQL_TOKEN_HAVING search_condition
1087 			{$$ = SQL_NEW_RULE;
1088 			$$->append($1);
1089 			$$->append($2);}
1090 	;
1091 
1092 	/* search conditions */
1093 boolean_primary:
1094 		predicate
1095 	|   '(' search_condition ')'
1096 		{ // boolean_primary: rule 2
1097 			$$ = SQL_NEW_RULE;
1098 			$$->append(newNode("(", SQLNodeType::Punctuation));
1099 			$$->append($2);
1100 			$$->append(newNode(")", SQLNodeType::Punctuation));
1101 		}
1102 	|	row_value_constructor_elem  /*[^')' ',']*/
1103 		{
1104                     if(xxx_pGLOBAL_SQLPARSER->inPredicateCheck())// boolean_primary: rule 3
1105                     {
1106                         $$ = SQL_NEW_RULE;
1107                         sal_Int16 nErg = 0;
1108                         if ( SQL_ISTOKEN( $1, NULL))
1109                         {
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);
1114 
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);
1120 
1121                             $$->append(pTFN);
1122 
1123                             nErg = 1;
1124                         }
1125                         else
1126                         {
1127                             nErg = xxx_pGLOBAL_SQLPARSER->buildComparisonRule($$,$1);
1128                         }
1129                         if(nErg == 1)
1130                         {
1131                             OSQLParseNode* pTemp = $$;
1132                             $$ = pTemp->removeAt((sal_uInt32)0);
1133                             delete pTemp;
1134                         }
1135                         else
1136                         {
1137                             delete $$;
1138                             if(nErg)
1139                                 YYERROR;
1140                             else
1141                                 YYABORT;
1142                         }
1143                     }
1144                     else
1145                         YYERROR;
1146                 }
1147 	;
1148 parenthesized_boolean_value_expression:
1149    '(' search_condition ')'
1150 	{ // boolean_primary: rule 2
1151 		$$ = SQL_NEW_RULE;
1152 		$$->append(newNode("(", SQLNodeType::Punctuation));
1153 		$$->append($2);
1154 		$$->append(newNode(")", SQLNodeType::Punctuation));
1155 	}
1156 	;
1157 boolean_factor:
1158 	    boolean_primary			%dprec 2
1159 	|   SQL_TOKEN_NOT boolean_primary	%dprec 1
1160 		{ // boolean_factor: rule 1
1161 		    $$ = SQL_NEW_RULE;
1162 		    $$->append($1);
1163 		    $$->append($2);
1164 		}
1165 	;
1166 boolean_term:
1167 		boolean_factor
1168 	|	boolean_term SQL_TOKEN_AND boolean_factor
1169 		{
1170 			$$ = SQL_NEW_RULE; // boolean_term: rule 1
1171 			$$->append($1);
1172 			$$->append($2);
1173 			$$->append($3);
1174 		}
1175 	;
1176 search_condition:
1177 		boolean_term
1178 	|	search_condition SQL_TOKEN_OR boolean_term
1179 		{
1180 			$$ = SQL_NEW_RULE; // search_condition
1181 			$$->append($1);
1182 			$$->append($2);
1183 			$$->append($3);
1184 		}
1185 	;
1186 predicate:
1187 		comparison_predicate     %dprec 1
1188 	|       between_predicate
1189 	|       all_or_any_predicate
1190 	|       existence_test
1191 	|		unique_test
1192 	|		test_for_null    %dprec 2
1193 	|       in_predicate
1194 	|       like_predicate
1195 	;
1196 comparison_predicate_part_2:
1197 		comparison row_value_constructor
1198 		{
1199 			$$ = SQL_NEW_RULE; // comparison_predicate: rule 1
1200 			$$->append($1);
1201 			$$->append($2);
1202 		}
1203 comparison_predicate:
1204 		row_value_constructor comparison row_value_constructor
1205 		{
1206 			$$ = SQL_NEW_RULE; // comparison_predicate: rule 1
1207 			$$->append($1);
1208 			$$->append($2);
1209 			$$->append($3);
1210 		}
1211 	|	comparison row_value_constructor
1212 		{
1213 			if(xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // comparison_predicate: rule 2
1214 			{
1215 				$$ = SQL_NEW_RULE;
1216 				sal_Int16 nErg = xxx_pGLOBAL_SQLPARSER->buildPredicateRule($$,$2,$1);
1217 				if(nErg == 1)
1218 				{
1219 					OSQLParseNode* pTemp = $$;
1220 					$$ = pTemp->removeAt((sal_uInt32)0);
1221 					delete pTemp;
1222 				}
1223 				else
1224 				{
1225 					delete $$;
1226 					YYABORT;
1227 				}
1228 			}
1229 			else
1230 			{
1231 				YYERROR;
1232 			}
1233 		}
1234 	;
1235 comparison:
1236 	    SQL_LESS
1237 	  | SQL_NOTEQUAL
1238 	  | SQL_EQUAL
1239 	  | SQL_GREAT
1240 	  | SQL_LESSEQ
1241 	  | SQL_GREATEQ
1242 	  | SQL_TOKEN_IS sql_not SQL_TOKEN_DISTINCT SQL_TOKEN_FROM
1243 	  	{
1244 		  $$ = SQL_NEW_RULE;
1245 		  $$->append($1);
1246 		  $$->append($2);
1247 		  $$->append($3);
1248 		  $$->append($4);
1249 		}
1250 	  | SQL_TOKEN_IS sql_not
1251 	  	{
1252 		  $$ = SQL_NEW_RULE;
1253 		  $$->append($1);
1254 		  $$->append($2);
1255 		}
1256 	;
1257 between_predicate_part_2:
1258 	sql_not SQL_TOKEN_BETWEEN row_value_constructor SQL_TOKEN_AND row_value_constructor
1259 		{
1260 			if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // between_predicate: rule 2
1261 			{
1262 				$$ = SQL_NEW_RULE;
1263 
1264 				sal_Int16 nErg = xxx_pGLOBAL_SQLPARSER->buildPredicateRule($$,$3,$2,$5);
1265 				if(nErg == 1)
1266 				{
1267 					OSQLParseNode* pTemp = $$;
1268 					$$ = pTemp->removeAt((sal_uInt32)0);
1269 					OSQLParseNode* pColumnRef = $$->removeAt((sal_uInt32)0);
1270 					$$->insert(0,$1);
1271 					OSQLParseNode* pBetween_predicate = new OSQLInternalNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::between_predicate));
1272 					pBetween_predicate->append(pColumnRef);
1273 					pBetween_predicate->append($$);
1274 					$$ = pBetween_predicate;
1275 
1276 					delete pTemp;
1277 					delete $4;
1278 				}
1279 				else
1280 				{
1281 					delete $$;
1282 					YYABORT;
1283 				}
1284 			}
1285 			else
1286 			{
1287 				$$ = SQL_NEW_RULE; // between_predicate: rule 1
1288 				$$->append($1);
1289 				$$->append($2);
1290 				$$->append($3);
1291 				$$->append($4);
1292 				$$->append($5);
1293 			}
1294 		}
1295 between_predicate:
1296 		row_value_constructor between_predicate_part_2
1297 		{
1298 			$$ = SQL_NEW_RULE; // between_predicate: rule 1
1299 			$$->append($1);
1300 			$$->append($2);
1301 		}
1302 	|	between_predicate_part_2
1303 	;
1304 character_like_predicate_part_2:
1305 	sql_not SQL_TOKEN_LIKE string_value_exp opt_escape
1306 		{
1307 			$$ = SQL_NEW_RULE; // like_predicate: rule 1
1308 			$$->append($1);
1309 			$$->append($2);
1310 			$$->append($3);
1311 			$$->append($4);
1312 		}
1313 	;
1314 other_like_predicate_part_2:
1315 	sql_not SQL_TOKEN_LIKE value_exp_primary opt_escape
1316 		{
1317 			$$ = SQL_NEW_RULE; // like_predicate: rule 1
1318 			$$->append($1);
1319 			$$->append($2);
1320 			$$->append($3);
1321 			$$->append($4);
1322 		}
1323 	;
1324 like_predicate:
1325 		row_value_constructor character_like_predicate_part_2
1326 		{
1327 			$$ = SQL_NEW_RULE; // like_predicate: rule 1
1328 			$$->append($1);
1329 			$$->append($2);
1330 		}
1331 	|	row_value_constructor other_like_predicate_part_2
1332 		{
1333 			$$ = SQL_NEW_RULE;  // like_predicate: rule 3
1334 			$$->append($1);
1335 			$$->append($2);
1336 		}
1337 	|	character_like_predicate_part_2
1338 		{
1339 			if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())  // like_predicate: rule 5
1340 			{
1341 				OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1342 				pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1343 
1344 				$$ = SQL_NEW_RULE;
1345 				$$->append(pColumnRef);
1346 				$$->append($1);
1347 				OSQLParseNode* p2nd = $1->removeAt(2);
1348 				OSQLParseNode* p3rd = $1->removeAt(2);
1349 				if ( !xxx_pGLOBAL_SQLPARSER->buildLikeRule($1,p2nd,p3rd) )
1350 				{
1351 					delete $$;
1352 					YYABORT;
1353 				}
1354 				$1->append(p3rd);
1355 			}
1356 			else
1357 				YYERROR;
1358 		}
1359 	|	other_like_predicate_part_2
1360 		{
1361 			if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // like_predicate: rule 6
1362 			{
1363 				OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1364 				pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1365 
1366 				$$ = SQL_NEW_RULE;
1367 				$$->append(pColumnRef);
1368 				$$->append($1);
1369 				OSQLParseNode* p2nd = $1->removeAt(2);
1370 				OSQLParseNode* p3rd = $1->removeAt(2);
1371 				if ( !xxx_pGLOBAL_SQLPARSER->buildLikeRule($1,p2nd,p3rd) )
1372 				{
1373 					delete $$;
1374 					YYABORT;
1375 				}
1376 				$1->append(p3rd);
1377 			}
1378 			else
1379 				YYERROR;
1380 		}
1381 	;
1382 
1383 opt_escape:
1384 		/* empty */                 {$$ = SQL_NEW_RULE;}
1385 	|   SQL_TOKEN_ESCAPE string_value_exp
1386 			{$$ = SQL_NEW_RULE;
1387 			$$->append($1);
1388 			$$->append($2);}
1389 	|	'{' SQL_TOKEN_ESCAPE SQL_TOKEN_STRING '}'
1390 		{
1391 			$$ = SQL_NEW_RULE;
1392 			$$->append(newNode("{", SQLNodeType::Punctuation));
1393 			$$->append($2);
1394 			$$->append($3);
1395 			$$->append(newNode("}", SQLNodeType::Punctuation));
1396 		}
1397 	;
1398 
1399 null_predicate_part_2:
1400 	  SQL_TOKEN_IS sql_not SQL_TOKEN_NULL
1401 	  {
1402 		$$ = SQL_NEW_RULE; // test_for_null: rule 1
1403 		$$->append($1);
1404 		$$->append($2);
1405 		$$->append($3);
1406 	  }
1407 	| SQL_TOKEN_IS sql_not SQL_TOKEN_UNKNOWN
1408 	  {
1409 		$$ = SQL_NEW_RULE; // test_for_null: rule 1
1410 		$$->append($1);
1411 		$$->append($2);
1412 		$$->append($3);
1413 	  }
1414 	;
1415 test_for_null:
1416 		row_value_constructor null_predicate_part_2
1417 		{
1418 			$$ = SQL_NEW_RULE; // test_for_null: rule 1
1419 			$$->append($1);
1420 			$$->append($2);
1421 		}
1422 	|	null_predicate_part_2
1423 		{
1424 			if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())// test_for_null: rule 2
1425 			{
1426 				OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1427 				pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1428 
1429 				$$ = SQL_NEW_RULE;
1430 				$$->append(pColumnRef);
1431 				$$->append($1);
1432 			}
1433 			else
1434 				YYERROR;
1435 		}
1436 	;
1437 in_predicate_value:
1438 		subquery
1439 		{$$ = SQL_NEW_RULE;
1440 			$$->append($1);
1441 		}
1442 	  | '(' value_exp_commalist ')'
1443 		{$$ = SQL_NEW_RULE;
1444 			$$->append(newNode("(", SQLNodeType::Punctuation));
1445 			$$->append($2);
1446 			$$->append(newNode(")", SQLNodeType::Punctuation));
1447 		}
1448 	;
1449 in_predicate_part_2:
1450 	sql_not SQL_TOKEN_IN in_predicate_value
1451 	{
1452 		$$ = SQL_NEW_RULE;// in_predicate: rule 1
1453 		$$->append($1);
1454 		$$->append($2);
1455 		$$->append($3);
1456 	}
1457 	;
1458 in_predicate:
1459 		row_value_constructor in_predicate_part_2
1460 		{
1461 			$$ = SQL_NEW_RULE;// in_predicate: rule 1
1462 			$$->append($1);
1463 			$$->append($2);
1464 		}
1465 	|	in_predicate_part_2
1466 		{
1467 			if ( xxx_pGLOBAL_SQLPARSER->inPredicateCheck() )// in_predicate: rule 2
1468 			{
1469 				OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1470 				pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1471 
1472 				$$ = SQL_NEW_RULE;
1473 				$$->append(pColumnRef);
1474 				$$->append($1);
1475 			}
1476 			else
1477 				YYERROR;
1478 		}
1479 	;
1480 quantified_comparison_predicate_part_2:
1481 	comparison any_all_some subquery
1482 	{
1483 		$$ = SQL_NEW_RULE;
1484 		$$->append($1);
1485 		$$->append($2);
1486 		$$->append($3);
1487 	}
1488 	;
1489 all_or_any_predicate:
1490 		row_value_constructor quantified_comparison_predicate_part_2
1491 		{
1492 			$$ = SQL_NEW_RULE;
1493 			$$->append($1);
1494 			$$->append($2);
1495 		}
1496 	|	quantified_comparison_predicate_part_2
1497 		{
1498 			if(xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1499 			{
1500 				OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1501 				pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1502 
1503 				$$ = SQL_NEW_RULE;
1504 				$$->append(pColumnRef);
1505 				$$->append($1);
1506 			}
1507 			else
1508 				YYERROR;
1509 		}
1510 	;
1511 
1512 any_all_some:
1513 			SQL_TOKEN_ANY
1514 	|       SQL_TOKEN_ALL
1515 	|       SQL_TOKEN_SOME
1516 	;
1517 
1518 existence_test:
1519 		SQL_TOKEN_EXISTS subquery
1520 			{$$ = SQL_NEW_RULE;
1521 			$$->append($1);
1522 			$$->append($2);}
1523 	;
1524 unique_test:
1525 		SQL_TOKEN_UNIQUE subquery
1526 		{$$ = SQL_NEW_RULE;
1527 			$$->append($1);
1528 			$$->append($2);}
1529 	;
1530 subquery:
1531 		'(' query_exp ')'
1532 			{$$ = SQL_NEW_RULE;
1533 			$$->append(newNode("(", SQLNodeType::Punctuation));
1534 			$$->append($2);
1535 			$$->append(newNode(")", SQLNodeType::Punctuation));}
1536 	;
1537 
1538 	/* scalar expressions */
1539 scalar_exp_commalist:
1540 		select_sublist
1541 		{
1542 			$$ = SQL_NEW_COMMALISTRULE;
1543 			$$->append($1);
1544 		}
1545 	|   scalar_exp_commalist ',' select_sublist
1546 		{
1547 			$1->append($3);
1548 			$$ = $1;
1549 		}
1550 	;
1551 select_sublist:
1552 /*		table_node '.' '*'
1553 		{
1554 			$$ = SQL_NEW_RULE;
1555 			$$->append($1);
1556 			$$->append(newNode(".", SQLNodeType::Punctuation));
1557 			$$->append(newNode("*", SQLNodeType::Punctuation));
1558 		}
1559 */
1560 		derived_column
1561 
1562 	;
1563 
1564 parameter_ref:
1565 		parameter
1566 	;
1567 
1568 /*
1569 op_like:
1570 		'*'
1571 		{
1572 			$$ = newNode("*", SQLNodeType::Punctuation);
1573 		}
1574 	|	'?'
1575 		{
1576 			$$ = newNode("?", SQLNodeType::Punctuation);
1577 		}
1578 	|   op_like	'*'
1579 		{
1580 			$$ = SQL_NEW_RULE;
1581 			$$->append($1);
1582 			$$->append(newNode("*", SQLNodeType::Punctuation));
1583 			xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_False);
1584 		}
1585 	|	op_like '?'
1586 		{
1587 			$$ = SQL_NEW_RULE;
1588 			$$->append($1);
1589 			$$->append(newNode("?", SQLNodeType::Punctuation));
1590 			xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_False);
1591 		}
1592 	;
1593 */
1594 
1595 literal:
1596 /*		SQL_TOKEN_STRING
1597 	|   */SQL_TOKEN_INT
1598 	|   SQL_TOKEN_REAL_NUM
1599 	|   SQL_TOKEN_INTNUM
1600 	|   SQL_TOKEN_APPROXNUM
1601 	|	SQL_TOKEN_ACCESS_DATE
1602 /*	rules for predicate check */
1603 	|	literal SQL_TOKEN_STRING
1604 		{
1605 			if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1606 			{
1607 				$$ = SQL_NEW_RULE;
1608 				$$->append($1);
1609 				$$->append($2);
1610 				OSQLParser::reduceLiteral($$, true);
1611 			}
1612 			else
1613 				YYERROR;
1614 		}
1615 	|	literal SQL_TOKEN_INT
1616 		{
1617 			if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1618 			{
1619 				$$ = SQL_NEW_RULE;
1620 				$$->append($1);
1621 				$$->append($2);
1622 				OSQLParser::reduceLiteral($$, true);
1623 			}
1624 			else
1625 				YYERROR;
1626 		}
1627 	|	literal SQL_TOKEN_REAL_NUM
1628 		{
1629 			if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1630 			{
1631 				$$ = SQL_NEW_RULE;
1632 				$$->append($1);
1633 				$$->append($2);
1634 				OSQLParser::reduceLiteral($$, true);
1635 			}
1636 			else
1637 				YYERROR;
1638 		}
1639 	|	literal SQL_TOKEN_APPROXNUM
1640 		{
1641 			if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1642 			{
1643 				$$ = SQL_NEW_RULE;
1644 				$$->append($1);
1645 				$$->append($2);
1646 				OSQLParser::reduceLiteral($$, true);
1647 			}
1648 			else
1649 				YYERROR;
1650 		}
1651 	;
1652 
1653 	/* miscellaneous */
1654 as_clause:
1655 		/* empty */ {$$ = SQL_NEW_RULE;}
1656 	|	SQL_TOKEN_AS column
1657 		{
1658 			$$ = SQL_NEW_RULE;
1659 			$$->append($1);
1660 			$$->append($2);
1661 		}
1662 	|	column
1663 	;
1664 position_exp:
1665 		SQL_TOKEN_POSITION '(' value_exp SQL_TOKEN_IN value_exp ')'
1666 		{
1667 			$$ = SQL_NEW_RULE;
1668 			$$->append($1);
1669 			$$->append(newNode("(", SQLNodeType::Punctuation));
1670 			$$->append($3);
1671 			$$->append($4);
1672 			$$->append($5);
1673 			$$->append(newNode(")", SQLNodeType::Punctuation));
1674 		}
1675 	|	SQL_TOKEN_POSITION '(' value_exp_commalist ')'
1676 		{
1677 			$$ = SQL_NEW_RULE;
1678 			$$->append($1);
1679 			$$->append(newNode("(", SQLNodeType::Punctuation));
1680 			$$->append($3);
1681 			$$->append(newNode(")", SQLNodeType::Punctuation));
1682 		}
1683 	;
1684 num_value_fct:
1685 		position_exp
1686 	|	extract_exp
1687 	|	length_exp
1688 	;
1689 char_length_exp:
1690 		SQL_TOKEN_CHAR_LENGTH '(' value_exp ')'
1691 		{
1692 			$$ = SQL_NEW_RULE;
1693 			$$->append($1);
1694 			$$->append(newNode("(", SQLNodeType::Punctuation));
1695 			$$->append($3);
1696 			$$->append(newNode(")", SQLNodeType::Punctuation));
1697 		}
1698 	|	SQL_TOKEN_SQL_TOKEN_INTNUM '(' value_exp ')'
1699 		{
1700 			$$ = SQL_NEW_RULE;
1701 			$$->append($1);
1702 			$$->append(newNode("(", SQLNodeType::Punctuation));
1703 			$$->append($3);
1704 			$$->append(newNode(")", SQLNodeType::Punctuation));
1705 		}
1706 
1707 	;
1708 octet_length_exp:
1709 		SQL_TOKEN_OCTET_LENGTH '(' value_exp ')'
1710 		{
1711 			$$ = SQL_NEW_RULE;
1712 			$$->append($1);
1713 			$$->append(newNode("(", SQLNodeType::Punctuation));
1714 			$$->append($3);
1715 			$$->append(newNode(")", SQLNodeType::Punctuation));
1716 		}
1717 	;
1718 bit_length_exp:
1719 		SQL_TOKEN_BIT_LENGTH '(' value_exp ')'
1720 		{
1721 			$$ = SQL_NEW_RULE;
1722 			$$->append($1);
1723 			$$->append(newNode("(", SQLNodeType::Punctuation));
1724 			$$->append($3);
1725 			$$->append(newNode(")", SQLNodeType::Punctuation));
1726 		}
1727 	;
1728 length_exp:
1729 		char_length_exp
1730 		{
1731 			$$ = SQL_NEW_RULE;
1732 			$$->append($1);
1733 		}
1734 	  | octet_length_exp
1735 		{
1736 			$$ = SQL_NEW_RULE;
1737 			$$->append($1);
1738 		}
1739 	  | bit_length_exp
1740 		{
1741 			$$ = SQL_NEW_RULE;
1742 			$$->append($1);
1743 		}
1744 	;
1745 datetime_field:
1746 		non_second_datetime_field
1747 		{
1748 			$$ = SQL_NEW_RULE;
1749 			$$->append($1);
1750 		}
1751 	  | SQL_TOKEN_SECOND
1752 		{
1753 			$$ = SQL_NEW_RULE;
1754 			$$->append($1);
1755 		}
1756 	;
1757 extract_field:
1758 	   time_zone_field
1759 	  | datetime_field
1760 	  |	value_exp
1761 	;
1762 time_zone_field:
1763 		SQL_TOKEN_TIMEZONE_HOUR
1764 		{
1765 			$$ = SQL_NEW_RULE;
1766 			$$->append($1);
1767 		}
1768 	  | SQL_TOKEN_TIMEZONE_MINUTE
1769 		{
1770 			$$ = SQL_NEW_RULE;
1771 			$$->append($1);
1772 		}
1773 	;
1774 extract_exp:
1775 		SQL_TOKEN_EXTRACT '(' extract_field SQL_TOKEN_FROM value_exp ')'
1776 		{
1777 			$$ = SQL_NEW_RULE;
1778 			$$->append($1);
1779 			$$->append(newNode("(", SQLNodeType::Punctuation));
1780 			$$->append($3);
1781 			$$->append($4);
1782 			$$->append($5);
1783 			$$->append(newNode(")", SQLNodeType::Punctuation));
1784 		}
1785 	;
1786 unsigned_value_spec:
1787 		general_value_spec
1788 	|	literal
1789 	;
1790 general_value_spec:
1791 		parameter
1792 	| SQL_TOKEN_USER
1793 	| SQL_TOKEN_NULL
1794 	| SQL_TOKEN_FALSE
1795 	| SQL_TOKEN_TRUE
1796 	| SQL_TOKEN_VALUE
1797 	| SQL_TOKEN_CURRENT_CATALOG
1798 	| SQL_TOKEN_CURRENT_DEFAULT_TRANSFORM_GROUP
1799 	| SQL_TOKEN_CURRENT_PATH
1800 	| SQL_TOKEN_CURRENT_ROLE
1801 	| SQL_TOKEN_CURRENT_SCHEMA
1802 	| SQL_TOKEN_CURRENT_USER
1803 	| SQL_TOKEN_SESSION_USER
1804 	| SQL_TOKEN_SYSTEM_USER
1805 	;
1806 set_fct_spec:
1807 		general_set_fct
1808 	|	'{' odbc_fct_spec '}'
1809 		{
1810 			$$ = SQL_NEW_RULE;
1811 			$$->append(newNode("{", SQLNodeType::Punctuation));
1812 			$$->append($2);
1813 			$$->append(newNode("}", SQLNodeType::Punctuation));
1814 		}
1815 	|	function_name '(' ')'
1816 		{
1817 			$$ = SQL_NEW_RULE;
1818 			$$->append($1);
1819 			$$->append(newNode("(", SQLNodeType::Punctuation));
1820 			$$->append(newNode(")", SQLNodeType::Punctuation));
1821 		}
1822 	|	function_name0 '(' ')'
1823 		{
1824 			$$ = SQL_NEW_RULE;
1825 			$$->append($1);
1826 			$$->append(newNode("(", SQLNodeType::Punctuation));
1827 			$$->append(newNode(")", SQLNodeType::Punctuation));
1828 		}
1829 	|	function_name1 '(' function_arg ')'
1830 		{
1831 			$$ = SQL_NEW_RULE;
1832 			$$->append($1);
1833 			$$->append(newNode("(", SQLNodeType::Punctuation));
1834 			$$->append($3);
1835 			$$->append(newNode(")", SQLNodeType::Punctuation));
1836 		}
1837 	|	function_name2 '(' function_arg_commalist2 ')'
1838 		{
1839 			$$ = SQL_NEW_RULE;
1840 			$$->append($1);
1841 			$$->append(newNode("(", SQLNodeType::Punctuation));
1842 			$$->append($3);
1843 			$$->append(newNode(")", SQLNodeType::Punctuation));
1844 		}
1845 	|	function_name3 '(' function_arg_commalist3 ')'
1846 		{
1847 			$$ = SQL_NEW_RULE;
1848 			$$->append($1);
1849 			$$->append(newNode("(", SQLNodeType::Punctuation));
1850 			$$->append($3);
1851 			$$->append(newNode(")", SQLNodeType::Punctuation));
1852 		}
1853 	|	string_function_4Argument '(' function_arg_commalist4 ')'
1854 		{
1855 			$$ = SQL_NEW_RULE;
1856 			$$->append($1);
1857 			$$->append(newNode("(", SQLNodeType::Punctuation));
1858 			$$->append($3);
1859 			$$->append(newNode(")", SQLNodeType::Punctuation));
1860 		}
1861 	|	function_name '(' function_args_commalist ')'
1862 		{
1863 			$$ = SQL_NEW_RULE;
1864 			$$->append($1);
1865 			$$->append(newNode("(", SQLNodeType::Punctuation));
1866 			$$->append($3);
1867 			$$->append(newNode(")", SQLNodeType::Punctuation));
1868 		}
1869 	|	function_name12 '(' function_args_commalist ')'
1870 		{
1871 			if ( $3->count() == 1 || $3->count() == 2 )
1872 			{
1873 				$$ = SQL_NEW_RULE;
1874 				$$->append($1);
1875 				$$->append(newNode("(", SQLNodeType::Punctuation));
1876 				$$->append($3);
1877 				$$->append(newNode(")", SQLNodeType::Punctuation));
1878 			}
1879 			else
1880 				YYERROR;
1881 		}
1882 	|	function_name23 '(' function_args_commalist ')'
1883 		{
1884 			if ( $3->count() == 2 || $3->count() == 3)
1885 			{
1886 				$$ = SQL_NEW_RULE;
1887 				$$->append($1);
1888 				$$->append(newNode("(", SQLNodeType::Punctuation));
1889 				$$->append($3);
1890 				$$->append(newNode(")", SQLNodeType::Punctuation));
1891 			}
1892 			else
1893 				YYERROR;
1894 		}
1895 	;
1896 function_name0:
1897 		date_function_0Argument
1898 	|	numeric_function_0Argument
1899 	;
1900 function_name1:
1901 		string_function_1Argument
1902 	|	date_function_1Argument
1903 	|	numeric_function_1Argument
1904 	;
1905 function_name2:
1906 		string_function_2Argument
1907 	|	numeric_function_2Argument
1908 	;
1909 function_name12:
1910 		SQL_TOKEN_ROUND
1911 	|	SQL_TOKEN_WEEK
1912 	|	SQL_TOKEN_LOGF
1913 	|	SQL_TOKEN_LOG
1914 	;
1915 function_name23:
1916 		SQL_TOKEN_LOCATE
1917 	|	SQL_TOKEN_DATEDIFF
1918 	;
1919 function_name3:
1920 		string_function_3Argument
1921 	;
1922 function_name:
1923 		string_function
1924 	|	date_function
1925 	|	numeric_function
1926 	|	SQL_TOKEN_NAME
1927 	;
1928 string_function_1Argument:
1929 		SQL_TOKEN_LENGTH
1930 	|	SQL_TOKEN_ASCII
1931 	|	SQL_TOKEN_LCASE
1932 	|	SQL_TOKEN_LTRIM
1933 	|	SQL_TOKEN_RTRIM
1934 	|	SQL_TOKEN_SPACE
1935 	|	SQL_TOKEN_UCASE
1936 	;
1937 
1938 string_function_2Argument:
1939 		SQL_TOKEN_REPEAT
1940 	|	SQL_TOKEN_LEFT
1941 	|	SQL_TOKEN_RIGHT
1942 	;
1943 string_function_3Argument:
1944 		SQL_TOKEN_REPLACE
1945 	;
1946 string_function_4Argument:
1947 		SQL_TOKEN_INSERT
1948 	;
1949 
1950 string_function:
1951 		SQL_TOKEN_CHAR
1952 	|	SQL_TOKEN_CONCAT
1953 	|	SQL_TOKEN_DIFFERENCE
1954 	|	SQL_TOKEN_LOCATE_2
1955 	|	SQL_TOKEN_SOUNDEX
1956 	;
1957 date_function_0Argument:
1958 		SQL_TOKEN_CURDATE
1959 	|	SQL_TOKEN_CURTIME
1960 	|	SQL_TOKEN_NOW
1961 	;
1962 date_function_1Argument:
1963 		SQL_TOKEN_DAYOFWEEK
1964 	|	SQL_TOKEN_DAYOFMONTH
1965 	|	SQL_TOKEN_DAYOFYEAR
1966 	|	SQL_TOKEN_MONTH
1967 	|	SQL_TOKEN_DAYNAME
1968 	|	SQL_TOKEN_MONTHNAME
1969 	|	SQL_TOKEN_QUARTER
1970 	|	SQL_TOKEN_HOUR
1971 	|	SQL_TOKEN_MINUTE
1972 	|	SQL_TOKEN_SECOND
1973 	|	SQL_TOKEN_YEAR
1974 	|	SQL_TOKEN_DAY
1975 	|	SQL_TOKEN_TIMEVALUE
1976 	|	SQL_TOKEN_DATEVALUE
1977 	;
1978 
1979 date_function:
1980 		SQL_TOKEN_TIMESTAMPADD
1981 	|	SQL_TOKEN_TIMESTAMPDIFF
1982 	;
1983 numeric_function_0Argument:
1984 		SQL_TOKEN_PI
1985 	;
1986 numeric_function_1Argument:
1987 		SQL_TOKEN_ABS
1988 	|	SQL_TOKEN_ACOS
1989 	|	SQL_TOKEN_ASIN
1990 	|	SQL_TOKEN_ATAN
1991 	|	SQL_TOKEN_CEILING
1992 	|	SQL_TOKEN_COS
1993 	|	SQL_TOKEN_COT
1994 	|	SQL_TOKEN_DEGREES
1995 	|	SQL_TOKEN_FLOOR
1996 	|	SQL_TOKEN_SIGN
1997 	|	SQL_TOKEN_SIN
1998 	|	SQL_TOKEN_SQRT
1999 	|	SQL_TOKEN_TAN
2000 	|	SQL_TOKEN_EXP
2001 	|	SQL_TOKEN_LOG10
2002 	|	SQL_TOKEN_LN
2003 	|	SQL_TOKEN_RADIANS
2004 	|	SQL_TOKEN_ROUNDMAGIC
2005 	;
2006 numeric_function_2Argument:
2007 		SQL_TOKEN_ATAN2
2008 	|	SQL_TOKEN_MOD
2009 	|	SQL_TOKEN_POWER
2010 	;
2011 numeric_function:
2012 		SQL_TOKEN_RAND
2013 	|	SQL_TOKEN_TRUNCATE
2014 	;
2015 
2016 window_function:
2017 	window_function_type SQL_TOKEN_OVER window_name_or_specification
2018 	{
2019 			$$ = SQL_NEW_RULE;
2020 			$$->append($1);
2021 			$$->append($2);
2022 			$$->append($3);
2023 	}
2024 	;
2025 window_function_type :
2026 		rank_function_type '(' ')'
2027 		{
2028 			$$ = SQL_NEW_RULE;
2029 			$$->append($1);
2030 			$$->append(newNode("(", SQLNodeType::Punctuation));
2031 			$$->append(newNode(")", SQLNodeType::Punctuation));
2032 		}
2033 	|	SQL_TOKEN_ROW_NUMBER '(' ')'
2034 		{
2035 			$$ = SQL_NEW_RULE;
2036 			$$->append($1);
2037 			$$->append(newNode("(", SQLNodeType::Punctuation));
2038 			$$->append(newNode(")", SQLNodeType::Punctuation));
2039 		}
2040 	| general_set_fct
2041 	| ntile_function
2042 	| lead_or_lag_function
2043 	| first_or_last_value_function
2044 	| nth_value_function
2045 ;
2046 ntile_function :
2047 	SQL_TOKEN_NTILE '(' number_of_tiles ')'
2048 	{
2049 			$$ = SQL_NEW_RULE;
2050 			$$->append($1);
2051 			$$->append(newNode("(", SQLNodeType::Punctuation));
2052 			$$->append($3);
2053 			$$->append(newNode(")", SQLNodeType::Punctuation));
2054 	}
2055 	;
2056 dynamic_parameter_specification:
2057 	parameter
2058 	;
2059 simple_value_specification:
2060 	literal
2061 	;
2062 number_of_tiles :
2063 		simple_value_specification
2064 	|	dynamic_parameter_specification
2065 	;
2066 opt_lead_or_lag_function:
2067 	/* empty */      {$$ = SQL_NEW_RULE;}
2068 	| ',' offset
2069 		{
2070 			$$ = SQL_NEW_RULE;
2071 			$$->append(newNode(",", SQLNodeType::Punctuation));
2072 			$$->append($2);
2073 		}
2074 	| ',' offset ',' default_expression
2075 		{
2076 			$$ = SQL_NEW_RULE;
2077 			$$->append(newNode(",", SQLNodeType::Punctuation));
2078 			$$->append($2);
2079 			$$->append(newNode(",", SQLNodeType::Punctuation));
2080 			$$->append($4);
2081 		}
2082 	;
2083 opt_null_treatment:
2084 		/* empty */      {$$ = SQL_NEW_RULE;}
2085 	|	null_treatment
2086 	;
2087 
2088 lead_or_lag_function:
2089 	lead_or_lag '(' lead_or_lag_extent opt_lead_or_lag_function ')'	opt_null_treatment
2090 	{
2091 			$$ = SQL_NEW_RULE;
2092 			$$->append($1);
2093 			$$->append(newNode("(", SQLNodeType::Punctuation));
2094 			$$->append($3);
2095 			$$->append($4);
2096 			$$->append(newNode(")", SQLNodeType::Punctuation));
2097 			$$->append($6);
2098 	}
2099 	;
2100 lead_or_lag:
2101 		SQL_TOKEN_LEAD
2102 	|	SQL_TOKEN_LAG
2103 	;
2104 lead_or_lag_extent:
2105 	value_exp
2106 	;
2107 offset:
2108 	SQL_TOKEN_INTNUM
2109 	;
2110 default_expression:
2111 	value_exp
2112 	;
2113 null_treatment:
2114 		SQL_TOKEN_RESPECT SQL_TOKEN_NULLS
2115 	|	SQL_TOKEN_IGNORE SQL_TOKEN_NULLS
2116 	;
2117 first_or_last_value_function:
2118 	first_or_last_value '(' value_exp ')' opt_null_treatment
2119 	{
2120 			$$ = SQL_NEW_RULE;
2121 			$$->append($1);
2122 			$$->append(newNode("(", SQLNodeType::Punctuation));
2123 			$$->append($3);
2124 			$$->append(newNode(")", SQLNodeType::Punctuation));
2125 			$$->append($5);
2126 	}
2127 	;
2128 first_or_last_value :
2129 		SQL_TOKEN_FIRST_VALUE
2130 	|	SQL_TOKEN_LAST_VALUE
2131 	;
2132 opt_from_first_or_last:
2133 		/* empty */      {$$ = SQL_NEW_RULE;}
2134 	|	from_first_or_last
2135 	;
2136 nth_value_function:
2137 	SQL_TOKEN_NTH_VALUE '(' value_exp ',' nth_row ')' opt_from_first_or_last opt_null_treatment
2138 	{
2139 			$$ = SQL_NEW_RULE;
2140 			$$->append($1);
2141 			$$->append(newNode("(", SQLNodeType::Punctuation));
2142 			$$->append($3);
2143 			$$->append(newNode(",", SQLNodeType::Punctuation));
2144 			$$->append($5);
2145 			$$->append(newNode(")", SQLNodeType::Punctuation));
2146 			$$->append($7);
2147 			$$->append($8);
2148 	}
2149 	;
2150 nth_row:
2151 		simple_value_specification
2152 	|	dynamic_parameter_specification
2153 	;
2154 from_first_or_last:
2155 		SQL_TOKEN_FROM SQL_TOKEN_FIRST
2156 		{
2157 			$$ = SQL_NEW_RULE;
2158 			$$->append($1);
2159 			$$->append($2);
2160 		}
2161 	|	SQL_TOKEN_FROM SQL_TOKEN_LAST
2162 		{
2163 			$$ = SQL_NEW_RULE;
2164 			$$->append($1);
2165 			$$->append($2);
2166 		}
2167 	;
2168 window_name:
2169 	SQL_TOKEN_NAME
2170 	;
2171 window_name_or_specification:
2172 		window_name
2173 	|	in_line_window_specification
2174 	;
2175 in_line_window_specification:
2176 	window_specification
2177 	;
2178 opt_window_clause:
2179 		/* empty */      {$$ = SQL_NEW_RULE;}
2180 	|	window_clause
2181 	;
2182 window_clause:
2183 	SQL_TOKEN_WINDOW window_definition_list
2184 	{
2185 		$$ = SQL_NEW_RULE;
2186 		$$->append($1);
2187 		$$->append($2);
2188 	}
2189 	;
2190 window_definition_list:
2191 		window_definition_list ',' window_definition
2192 			{$1->append($3);
2193 			$$ = $1;}
2194 	|	window_definition
2195 			{$$ = SQL_NEW_COMMALISTRULE;
2196 			$$->append($1);}
2197 	;
2198 window_definition:
2199 	new_window_name SQL_TOKEN_AS window_specification
2200 	{
2201 		$$ = SQL_NEW_RULE;
2202 		$$->append($1);
2203 		$$->append($2);
2204 		$$->append($3);
2205 	}
2206 	;
2207 new_window_name:
2208 	window_name
2209 	;
2210 window_specification:
2211 	'('
2212 		opt_existing_window_name
2213 		opt_window_partition_clause
2214 		opt_order_by_clause
2215 		opt_window_frame_clause
2216 	')'
2217 	{
2218 		$$ = SQL_NEW_RULE;
2219 		$$->append(newNode("(", SQLNodeType::Punctuation));
2220 		$$->append($2);
2221 		$$->append($3);
2222 		$$->append($4);
2223 		$$->append($5);
2224 		$$->append(newNode(")", SQLNodeType::Punctuation));
2225 	}
2226 	;
2227 opt_existing_window_name:
2228 		/* empty */      {$$ = SQL_NEW_RULE;}
2229 	|	existing_window_name
2230 	;
2231 opt_window_partition_clause:
2232 	/* empty */      {$$ = SQL_NEW_RULE;}
2233 	|	window_partition_clause
2234 	;
2235 opt_window_frame_clause:
2236 	/* empty */      {$$ = SQL_NEW_RULE;}
2237 	|	window_frame_clause
2238 	;
2239 existing_window_name:
2240 	window_name
2241 	;
2242 window_partition_clause:
2243 	SQL_TOKEN_PARTITION SQL_TOKEN_BY window_partition_column_reference_list
2244 	{
2245 		$$ = SQL_NEW_RULE;
2246 		$$->append($1);
2247 		$$->append($2);
2248 		$$->append($3);
2249 	}
2250 	;
2251 window_partition_column_reference_list:
2252 	window_partition_column_reference_list ',' window_partition_column_reference
2253 			{$1->append($3);
2254 			$$ = $1;}
2255 	|	window_partition_column_reference
2256 			{$$ = SQL_NEW_COMMALISTRULE;
2257 			$$->append($1);}
2258 	;
2259 window_partition_column_reference:
2260 	column_ref opt_collate_clause
2261 	{
2262 		$$ = SQL_NEW_RULE;
2263 		$$->append($1);
2264 		$$->append($2);
2265 	}
2266 	;
2267 opt_window_frame_exclusion:
2268 	/* empty */      {$$ = SQL_NEW_RULE;}
2269 	|	window_frame_exclusion
2270 	;
2271 window_frame_clause:
2272 	window_frame_units window_frame_extent opt_window_frame_exclusion
2273 	{
2274 		$$ = SQL_NEW_RULE;
2275 		$$->append($1);
2276 		$$->append($2);
2277 		$$->append($3);
2278 	}
2279 	;
2280 window_frame_units:
2281 		SQL_TOKEN_ROWS
2282 	|	SQL_TOKEN_RANGE
2283 	;
2284 window_frame_extent:
2285 		window_frame_start
2286 	|	window_frame_between
2287 	;
2288 window_frame_start:
2289 		SQL_TOKEN_UNBOUNDED SQL_TOKEN_PRECEDING
2290 		{
2291 			$$ = SQL_NEW_RULE;
2292 			$$->append($1);
2293 			$$->append($2);
2294 		}
2295 	|	window_frame_preceding
2296 	|	SQL_TOKEN_CURRENT SQL_TOKEN_ROW
2297 		{
2298 			$$ = SQL_NEW_RULE;
2299 			$$->append($1);
2300 			$$->append($2);
2301 		}
2302 	;
2303 window_frame_preceding:
2304 	unsigned_value_spec SQL_TOKEN_PRECEDING
2305 	{
2306 		$$ = SQL_NEW_RULE;
2307 		$$->append($1);
2308 		$$->append($2);
2309 	}
2310 	;
2311 window_frame_between:
2312 	SQL_TOKEN_BETWEEN window_frame_bound_1 SQL_TOKEN_AND window_frame_bound_2
2313 	{
2314 		$$ = SQL_NEW_RULE;
2315 		$$->append($1);
2316 		$$->append($2);
2317 		$$->append($3);
2318 		$$->append($4);
2319 	}
2320 	;
2321 window_frame_bound_1:
2322 	window_frame_bound
2323 	;
2324 window_frame_bound_2:
2325 	window_frame_bound
2326 	;
2327 window_frame_bound:
2328 	window_frame_start
2329 	| SQL_TOKEN_UNBOUNDED SQL_TOKEN_FOLLOWING
2330 	{
2331 		$$ = SQL_NEW_RULE;
2332 		$$->append($1);
2333 		$$->append($2);
2334 	}
2335 	| window_frame_following
2336 	;
2337 window_frame_following:
2338 	unsigned_value_spec SQL_TOKEN_FOLLOWING
2339 	{
2340 		$$ = SQL_NEW_RULE;
2341 		$$->append($1);
2342 		$$->append($2);
2343 	}
2344 	;
2345 window_frame_exclusion:
2346 		SQL_TOKEN_EXCLUDE SQL_TOKEN_CURRENT SQL_TOKEN_ROW
2347 		{
2348 			$$ = SQL_NEW_RULE;
2349 			$$->append($1);
2350 			$$->append($2);
2351 			$$->append($3);
2352 		}
2353 	|	SQL_TOKEN_EXCLUDE SQL_TOKEN_GROUP
2354 		{
2355 			$$ = SQL_NEW_RULE;
2356 			$$->append($1);
2357 			$$->append($2);
2358 		}
2359 	|	SQL_TOKEN_EXCLUDE SQL_TOKEN_TIES
2360 		{
2361 			$$ = SQL_NEW_RULE;
2362 			$$->append($1);
2363 			$$->append($2);
2364 		}
2365 	|	SQL_TOKEN_EXCLUDE SQL_TOKEN_NO SQL_TOKEN_OTHERS
2366 		{
2367 			$$ = SQL_NEW_RULE;
2368 			$$->append($1);
2369 			$$->append($2);
2370 			$$->append($3);
2371 		}
2372 	;
2373 op_parameter:
2374 		{$$ = SQL_NEW_RULE;}
2375 	|	'?' SQL_EQUAL
2376 		{
2377 			$$ = SQL_NEW_RULE;
2378 			$$->append(newNode("?", SQLNodeType::Punctuation));
2379 			$$->append($2);
2380 		}
2381 	;
2382 odbc_call_spec:
2383 		op_parameter SQL_TOKEN_CALL table_node op_odbc_call_parameter
2384 		{
2385 			$$ = SQL_NEW_RULE;
2386 			$$->append($1);
2387 			$$->append($2);
2388 			$$->append($3);
2389 			$$->append($4);
2390 		}
2391 	;
2392 
2393 op_odbc_call_parameter:
2394 		{$$ = SQL_NEW_RULE;}
2395 	|	'(' odbc_parameter_commalist ')'
2396 		{
2397 			$$ = SQL_NEW_RULE;
2398 			$$->append(newNode("(", SQLNodeType::Punctuation));
2399 			$$->append($2);
2400 			$$->append(newNode(")", SQLNodeType::Punctuation));
2401 		}
2402 	;
2403 
2404 odbc_parameter_commalist:
2405 		odbc_parameter
2406 		{$$ = SQL_NEW_COMMALISTRULE;
2407 			$$->append($1);}
2408 	|	odbc_parameter_commalist ',' odbc_parameter
2409 		{
2410 			$1->append($3);
2411 			$$ = $1;
2412 		}
2413 	;
2414 odbc_parameter:
2415 	/* empty */ 	{$$ = SQL_NEW_RULE;}
2416 	|	literal
2417 	|	parameter
2418 	;
2419 
2420 odbc_fct_spec:
2421 		odbc_fct_type SQL_TOKEN_STRING
2422 		{
2423 			$$ = SQL_NEW_RULE;
2424 			$$->append($1);
2425 			$$->append($2);
2426 		}
2427 	|	SQL_TOKEN_FN set_fct_spec
2428 		{
2429 			$$ = SQL_NEW_RULE;
2430 			$$->append($1);
2431 			$$->append($2);
2432 		}
2433 	;
2434 
2435 odbc_fct_type:
2436 		SQL_TOKEN_D
2437 	| 	SQL_TOKEN_T
2438 	| 	SQL_TOKEN_TS
2439 	;
2440 
2441 general_set_fct:
2442 		set_fct_type '(' opt_all_distinct function_arg ')'
2443 		{
2444 			$$ = SQL_NEW_RULE;
2445 			$$->append($1);
2446 			$$->append(newNode("(", SQLNodeType::Punctuation));
2447 			$$->append($3);
2448 			$$->append($4);
2449 			$$->append(newNode(")", SQLNodeType::Punctuation));
2450 		}
2451 	|	SQL_TOKEN_COUNT '(' '*' ')'
2452 		{
2453 			$$ = SQL_NEW_RULE;
2454 			$$->append($1);
2455 			$$->append(newNode("(", SQLNodeType::Punctuation));
2456 			$$->append(newNode("*", SQLNodeType::Punctuation));
2457 			$$->append(newNode(")", SQLNodeType::Punctuation));
2458 		}
2459 	|	SQL_TOKEN_COUNT '(' opt_all_distinct function_arg ')'
2460 		{
2461 			$$ = SQL_NEW_RULE;
2462 			$$->append($1);
2463 			$$->append(newNode("(", SQLNodeType::Punctuation));
2464 			$$->append($3);
2465 			$$->append($4);
2466 			$$->append(newNode(")", SQLNodeType::Punctuation));
2467 		}
2468 	|	ordered_set_function
2469 	|	array_aggregate_function
2470 	;
2471 set_fct_type:
2472 		SQL_TOKEN_AVG
2473 	|   SQL_TOKEN_MAX
2474 	|   SQL_TOKEN_MIN
2475 	|   SQL_TOKEN_SUM
2476 	|   SQL_TOKEN_EVERY
2477 	|   SQL_TOKEN_ANY
2478 	|   SQL_TOKEN_SOME
2479 	|   SQL_TOKEN_STDDEV_POP
2480 	|   SQL_TOKEN_STDDEV_SAMP
2481 	|   SQL_TOKEN_VAR_SAMP
2482 	|   SQL_TOKEN_VAR_POP
2483 	|   SQL_TOKEN_COLLECT
2484 	|   SQL_TOKEN_FUSION
2485 	|   SQL_TOKEN_INTERSECTION
2486 	;
2487 
2488 ordered_set_function:
2489 		hypothetical_set_function
2490 	|	inverse_distribution_function
2491 	;
2492 hypothetical_set_function:
2493 		rank_function_type '('	hypothetical_set_function_value_expression_list ')'	within_group_specification
2494 		{
2495 			$$ = SQL_NEW_RULE;
2496 			$$->append($1);
2497 			$$->append(newNode("(", SQLNodeType::Punctuation));
2498 			$$->append($3);
2499 			$$->append(newNode(")", SQLNodeType::Punctuation));
2500 			$$->append($5);
2501 		}
2502 	|	rank_function_type '('	hypothetical_set_function_value_expression_list SQL_TOKEN_BY value_exp_commalist ')'	within_group_specification
2503 	{
2504 		$$ = SQL_NEW_RULE;
2505 		$$->append($1);
2506 		$$->append(newNode("(", SQLNodeType::Punctuation));
2507 		$$->append($3);
2508 		$$->append($4);
2509 		$$->append($5);
2510 		$$->append(newNode(")", SQLNodeType::Punctuation));
2511 		$$->append($7);
2512 	}
2513 	;
2514 
2515 within_group_specification:
2516 	{
2517 		$$ = SQL_NEW_RULE;
2518 	}
2519 	|	SQL_TOKEN_WITHIN SQL_TOKEN_GROUP '(' opt_order_by_clause ')'
2520 	{
2521 		$$ = SQL_NEW_RULE;
2522 		$$->append($1);
2523 		$$->append($2);
2524 		$$->append(newNode("(", SQLNodeType::Punctuation));
2525 		$$->append($4);
2526 		$$->append(newNode(")", SQLNodeType::Punctuation));
2527 	}
2528 	;
2529 hypothetical_set_function_value_expression_list:
2530 	value_exp_commalist
2531 	;
2532 
2533 inverse_distribution_function:
2534 	inverse_distribution_function_type '('inverse_distribution_function_argument ')' within_group_specification
2535 	{
2536 		$$ = SQL_NEW_RULE;
2537 		$$->append($1);
2538 		$$->append(newNode("(", SQLNodeType::Punctuation));
2539 		$$->append($3);
2540 		$$->append(newNode(")", SQLNodeType::Punctuation));
2541 	}
2542 	;
2543 inverse_distribution_function_argument:
2544 		num_value_exp
2545 	;
2546 inverse_distribution_function_type:
2547 		SQL_TOKEN_PERCENTILE_CONT
2548 	|	SQL_TOKEN_PERCENTILE_DISC
2549 	;
2550 
2551 array_aggregate_function:
2552 	SQL_TOKEN_ARRAY_AGG '(' value_exp opt_order_by_clause ')'
2553 	{
2554 		$$ = SQL_NEW_RULE;
2555 		$$->append($1);
2556 		$$->append(newNode("(", SQLNodeType::Punctuation));
2557 		$$->append($3);
2558 		$$->append($4);
2559 		$$->append(newNode(")", SQLNodeType::Punctuation));
2560 	}
2561 	;
2562 
2563 rank_function_type:
2564 		SQL_TOKEN_RANK
2565 	|	SQL_TOKEN_DENSE_RANK
2566 	|	SQL_TOKEN_PERCENT_RANK
2567 	|	SQL_TOKEN_CUME_DIST
2568 	;
2569 outer_join_type:
2570 		SQL_TOKEN_LEFT %prec SQL_TOKEN_LEFT
2571 		{
2572 			$$ = SQL_NEW_RULE;
2573 			$$->append($1);
2574 		}
2575 	  | SQL_TOKEN_RIGHT %prec SQL_TOKEN_RIGHT
2576 		{
2577 			$$ = SQL_NEW_RULE;
2578 			$$->append($1);
2579 		}
2580 	  | SQL_TOKEN_FULL %prec SQL_TOKEN_FULL
2581 		{
2582 			$$ = SQL_NEW_RULE;
2583 			$$->append($1);
2584 		}
2585 	  ;
2586 join_condition:
2587 		SQL_TOKEN_ON search_condition
2588 		{
2589 			$$ = SQL_NEW_RULE;
2590 			$$->append($1);
2591 			$$->append($2);
2592 		}
2593 		;
2594 join_spec:
2595 		join_condition
2596 	  | named_columns_join
2597 	  ;
2598 join_type:
2599 		/* empty */ 	{$$ = SQL_NEW_RULE;}
2600 	  | SQL_TOKEN_INNER
2601 		{
2602 			$$ = SQL_NEW_RULE;
2603 			$$->append($1);
2604 		}
2605 	  | outer_join_type
2606 	  | outer_join_type SQL_TOKEN_OUTER
2607 		{
2608 			$$ = SQL_NEW_RULE;
2609 			$$->append($1);
2610 			$$->append($2);
2611 		}
2612 	;
2613 cross_union:
2614 		table_ref SQL_TOKEN_CROSS SQL_TOKEN_JOIN table_ref
2615 		{
2616 			$$ = SQL_NEW_RULE;
2617 			$$->append($1);
2618 			$$->append($2);
2619 			$$->append($3);
2620 			$$->append($4);
2621 		}
2622 	;
2623 
2624 qualified_join:
2625 		/* when SQL_TOKEN_NATURAL, then no join_spec */
2626 		table_ref SQL_TOKEN_NATURAL join_type SQL_TOKEN_JOIN table_ref
2627 		{
2628 			$$ = SQL_NEW_RULE;
2629 			$$->append($1);
2630 			$$->append($2);
2631 			$$->append($3);
2632 			$$->append($4);
2633 			$$->append($5);
2634 		}
2635 	|	table_ref join_type SQL_TOKEN_JOIN table_ref join_spec
2636 		{
2637 			$$ = SQL_NEW_RULE;
2638 			$$->append($1);
2639 			$$->append($2);
2640 			$$->append($3);
2641 			$$->append($4);
2642 			$$->append($5);
2643 		}
2644 	|	cross_union
2645 	;
2646 joined_table:
2647 		qualified_join
2648 	;
2649 named_columns_join:
2650 		SQL_TOKEN_USING '(' column_commalist ')'
2651 		{
2652 			$$ = SQL_NEW_RULE;
2653 			$$->append($1);
2654 			$$->append(newNode("(", SQLNodeType::Punctuation));
2655 			$$->append($3);
2656 			$$->append(newNode(")", SQLNodeType::Punctuation));
2657 		}
2658 	;
2659 simple_table:
2660 		select_statement
2661 	  | values_or_query_spec
2662 	  ;
2663 
2664 non_join_query_primary:
2665 		simple_table
2666 	  | '(' non_join_query_exp ')'
2667 		{
2668 			$$ = SQL_NEW_RULE;
2669 			$$->append(newNode("(", SQLNodeType::Punctuation));
2670 			$$->append($2);
2671 			$$->append(newNode(")", SQLNodeType::Punctuation));
2672 		}
2673 	  ;
2674 non_join_query_term:
2675 		non_join_query_primary
2676 	|	query_term SQL_TOKEN_INTERSECT all query_primary
2677 		{
2678 			$$ = SQL_NEW_RULE;
2679 			$$->append($1);
2680 			$$->append($2);
2681 			$$->append($3);
2682 			$$->append($4);
2683 		}
2684 	;
2685 query_primary:
2686 		non_join_query_primary
2687 	;
2688 non_join_query_exp:
2689 		non_join_query_term
2690 	  | query_exp SQL_TOKEN_UNION all query_term
2691 		{
2692 			$$ = SQL_NEW_RULE;
2693 			$$->append($1);
2694 			$$->append($2);
2695 			$$->append($3);
2696 			$$->append($4);
2697 		}
2698 	  | query_exp SQL_TOKEN_EXCEPT all query_term
2699 		{
2700 			$$ = SQL_NEW_RULE;
2701 			$$->append($1);
2702 			$$->append($2);
2703 			$$->append($3);
2704 			$$->append($4);
2705 		}
2706 	;
2707 all:
2708 	/* empty*/ {$$ = SQL_NEW_RULE;}
2709 	|	SQL_TOKEN_ALL
2710 	;
2711 query_exp:
2712 		non_join_query_exp /*[^')']*/
2713 	;
2714 scalar_subquery:
2715 		subquery
2716 	;
2717 cast_operand:
2718 		value_exp
2719 	;
2720 cast_target:
2721 		table_node
2722 	  | data_type
2723 	;
2724 cast_spec:
2725 	  SQL_TOKEN_CAST '(' cast_operand SQL_TOKEN_AS cast_target ')'
2726 	  {
2727 			$$ = SQL_NEW_RULE;
2728 			$$->append($1);
2729 			$$->append(newNode("(", SQLNodeType::Punctuation));
2730 			$$->append($3);
2731 			$$->append($4);
2732 			$$->append($5);
2733 			$$->append(newNode(")", SQLNodeType::Punctuation));
2734 		}
2735 	;
2736 value_exp_primary:
2737 		unsigned_value_spec
2738 	  | column_ref
2739 	  | set_fct_spec
2740 	  | scalar_subquery
2741 	  | case_expression
2742 	  | window_function
2743 	  | '(' value_exp ')'
2744 		{
2745 			$$ = SQL_NEW_RULE;
2746 			$$->append(newNode("(", SQLNodeType::Punctuation));
2747 			$$->append($2);
2748 			$$->append(newNode(")", SQLNodeType::Punctuation));
2749 		}
2750 	  | cast_spec
2751 	;
2752 
2753 num_primary:
2754 		value_exp_primary
2755 	  | num_value_fct
2756 	;
2757 factor:
2758 		num_primary
2759 	|	'-' num_primary  %prec SQL_TOKEN_UMINUS
2760 		{
2761 			$$ = SQL_NEW_RULE;
2762 			$$->append(newNode("-", SQLNodeType::Punctuation));
2763 			$$->append($2);
2764 		}
2765 	|	'+' num_primary  %prec SQL_TOKEN_UMINUS
2766 		{
2767 			$$ = SQL_NEW_RULE;
2768 			$$->append(newNode("+", SQLNodeType::Punctuation));
2769 			$$->append($2);
2770 		}
2771 	;
2772 
2773 term:
2774 		factor
2775 	  | term '*' factor
2776 		{
2777 			$$ = SQL_NEW_RULE;
2778 			$$->append($1);
2779 			$$->append(newNode("*", SQLNodeType::Punctuation));
2780 			$$->append($3);
2781 		}
2782 	  | term '/' factor
2783 		{
2784 			$$ = SQL_NEW_RULE;
2785 			$$->append($1);
2786 			$$->append(newNode("/", SQLNodeType::Punctuation));
2787 			$$->append($3);
2788 		}
2789 	  ;
2790 
2791 num_value_exp:
2792 		term
2793 	  | num_value_exp '+' term
2794 		{
2795 			$$ = SQL_NEW_RULE;
2796 			$$->append($1);
2797 			$$->append(newNode("+", SQLNodeType::Punctuation));
2798 			$$->append($3);
2799 		}
2800 	  | num_value_exp '-' term
2801 		{
2802 			$$ = SQL_NEW_RULE;
2803 			$$->append($1);
2804 			$$->append(newNode("-", SQLNodeType::Punctuation));
2805 			$$->append($3);
2806 		}
2807 	  ;
2808 datetime_primary:
2809 /*		value_exp_primary
2810 		{
2811 			$$ = SQL_NEW_RULE;
2812 			$$->append($1);
2813 		}
2814 	  |*/ datetime_value_fct
2815 		{
2816 			$$ = SQL_NEW_RULE;
2817 			$$->append($1);
2818 		}
2819 	;
2820 datetime_value_fct:
2821 		SQL_TOKEN_CURRENT_DATE
2822 		{
2823 			$$ = SQL_NEW_RULE;
2824 			$$->append($1);
2825 		}
2826 	  | SQL_TOKEN_CURRENT_TIME
2827 		{
2828 			$$ = SQL_NEW_RULE;
2829 			$$->append($1);
2830 		}
2831 	  | SQL_TOKEN_CURRENT_TIMESTAMP
2832 		{
2833 			$$ = SQL_NEW_RULE;
2834 			$$->append($1);
2835 		}
2836 	;
2837 time_zone:
2838 		SQL_TOKEN_AT time_zone_specifier
2839 		{
2840 			$$ = SQL_NEW_RULE;
2841 			$$->append($1);
2842 			$$->append($2);
2843 		}
2844 	;
2845 time_zone_specifier:
2846 		SQL_TOKEN_LOCAL
2847 		{
2848 			$$ = SQL_NEW_RULE;
2849 			$$->append($1);
2850 		}
2851 /*      | SQL_TOKEN_TIME SQL_TOKEN_ZONE interval_value_exp
2852 		{
2853 			$$ = SQL_NEW_RULE;
2854 			$$->append($1);
2855 			$$->append($2);
2856 			$$->append($3);
2857 		}*/
2858 	  ;
2859 datetime_factor:
2860 		datetime_primary
2861 		{
2862 			$$ = SQL_NEW_RULE;
2863 			$$->append($1);
2864 		}
2865 	|	datetime_primary time_zone
2866 		{
2867 			$$ = SQL_NEW_RULE;
2868 			$$->append($1);
2869 			$$->append($2);
2870 		}
2871 	;
2872 datetime_term:
2873 		datetime_factor
2874 		{
2875 			$$ = SQL_NEW_RULE;
2876 			$$->append($1);
2877 		}
2878 	;
2879 /*
2880 interval_term:
2881 		literal
2882 	  | interval_term '*' factor
2883 		{
2884 			$$ = SQL_NEW_RULE;
2885 			$$->append($1);
2886 			$$->append(newNode("*", SQLNodeType::Punctuation));
2887 			$$->append($3);
2888 		}
2889 	  | interval_term '/' factor
2890 		{
2891 			$$ = SQL_NEW_RULE;
2892 			$$->append($1);
2893 			$$->append(newNode("/", SQLNodeType::Punctuation));
2894 			$$->append($3);
2895 		}
2896 	;
2897 */
2898 datetime_value_exp:
2899 		datetime_term
2900 		{
2901 			$$ = SQL_NEW_RULE;
2902 			$$->append($1);
2903 		}
2904 /*      | interval_value_exp '+' datetime_term
2905 		{
2906 			$$ = SQL_NEW_RULE;
2907 			$$->append($1);
2908 			$$->append(newNode("+", SQLNodeType::Punctuation));
2909 			$$->append($3);
2910 		}
2911 	  | datetime_value_exp '+' interval_term
2912 		{
2913 			$$ = SQL_NEW_RULE;
2914 			$$->append($1);
2915 			$$->append(newNode("+", SQLNodeType::Punctuation));
2916 			$$->append($3);
2917 		}
2918 	  | datetime_value_exp '-' interval_term
2919 		{
2920 			$$ = SQL_NEW_RULE;
2921 			$$->append($1);
2922 			$$->append(newNode("-", SQLNodeType::Punctuation));
2923 			$$->append($3);
2924 		}
2925 */	;
2926 /*
2927 interval_value_exp:
2928 		interval_term
2929 		{
2930 			$$ = SQL_NEW_RULE;
2931 			$$->append($1);
2932 		}
2933 	  | interval_value_exp '+' interval_term
2934 		{
2935 			$$ = SQL_NEW_RULE;
2936 			$$->append($1);
2937 			$$->append(newNode("+", SQLNodeType::Punctuation));
2938 			$$->append($3);
2939 		}
2940 	  | interval_value_exp '-' interval_term
2941 		{
2942 			$$ = SQL_NEW_RULE;
2943 			$$->append($1);
2944 			$$->append(newNode("-", SQLNodeType::Punctuation));
2945 			$$->append($3);
2946 		}
2947 	  | '(' datetime_value_exp '-' datetime_term ')' interval_qualifier
2948 		{
2949 			$$ = SQL_NEW_RULE;
2950 			$$->append(newNode("(", SQLNodeType::Punctuation));
2951 			$$->append($2);
2952 			$$->append(newNode("-", SQLNodeType::Punctuation));
2953 			$$->append($4);
2954 			$$->append(newNode(")", SQLNodeType::Punctuation));
2955 			$$->append($6);
2956 		}
2957 	;
2958 */
2959 non_second_datetime_field:
2960 		SQL_TOKEN_YEAR
2961 	|	SQL_TOKEN_MONTH
2962 	|	SQL_TOKEN_DAY
2963 	|	SQL_TOKEN_HOUR
2964 	|	SQL_TOKEN_MINUTE
2965 	;
2966 start_field:
2967 		non_second_datetime_field opt_paren_precision
2968 		{
2969 			$$ = SQL_NEW_RULE;
2970 			$$->append($1);
2971 			$$->append($2);
2972 		}
2973 	;
2974 end_field:
2975 		non_second_datetime_field
2976 	|	SQL_TOKEN_SECOND opt_paren_precision
2977 		{
2978 			$$ = SQL_NEW_RULE;
2979 			$$->append($1);
2980 			$$->append($2);
2981 		}
2982 	;
2983 
2984 single_datetime_field:
2985 		non_second_datetime_field opt_paren_precision
2986 		{
2987 			$$ = SQL_NEW_RULE;
2988 			$$->append($1);
2989 			$$->append($2);
2990 		}
2991 	|	SQL_TOKEN_SECOND opt_paren_precision_scale
2992 		{
2993 			$$ = SQL_NEW_RULE;
2994 			$$->append($1);
2995 			$$->append($2);
2996 		}
2997 	;
2998 
2999 interval_qualifier:
3000 		start_field SQL_TOKEN_TO end_field
3001 		{
3002 			$$ = SQL_NEW_RULE;
3003 			$$->append($1);
3004 			$$->append($2);
3005 			$$->append($3);
3006 		}
3007 	|	single_datetime_field
3008 	;
3009 
3010 function_arg_commalist2:
3011 	    function_arg ',' function_arg
3012 			{$$ = SQL_NEW_COMMALISTRULE;
3013 			$$->append($1);
3014 			$$->append($3);}
3015 	;
3016 function_arg_commalist3:
3017 	    function_arg ',' function_arg ',' function_arg
3018 		{
3019 			$$ = SQL_NEW_COMMALISTRULE;
3020 			$$->append($1);
3021 			$$->append($3);
3022 			$$->append($5);
3023 		}
3024 	;
3025 function_arg_commalist4:
3026 	    function_arg ',' function_arg ',' function_arg ',' function_arg
3027 		{
3028 			$$ = SQL_NEW_COMMALISTRULE;
3029 			$$->append($1);
3030 			$$->append($3);
3031 			$$->append($5);
3032 			$$->append($7);
3033 		}
3034 	;
3035 value_exp_commalist:
3036 		value_exp
3037 			{$$ = SQL_NEW_COMMALISTRULE;
3038 			$$->append($1);}
3039 	|   value_exp_commalist ',' value_exp
3040 			{$1->append($3);
3041 			$$ = $1;}
3042 	/*	this rule is only valid if we check predicates */
3043 	|   value_exp_commalist ';' value_exp
3044 		{
3045 			if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
3046 			{
3047 				$1->append($3);
3048 				$$ = $1;
3049 			}
3050 			else
3051 				YYERROR;
3052 		}
3053 	;
3054 function_arg:
3055 		result
3056 	|	value_exp comparison value_exp
3057 		{
3058 			$$ = SQL_NEW_RULE;
3059 			$$->append($1);
3060 			$$->append($2);
3061 			$$->append($3);
3062 		}
3063 	|	value_exp SQL_TOKEN_USING value_exp comparison value_exp
3064 		{
3065 			$$ = SQL_NEW_RULE;
3066 			$$->append($1);
3067 			$$->append($2);
3068 			$$->append($3);
3069 			$$->append($4);
3070 		}
3071 	|	value_exp SQL_TOKEN_BY value_exp_commalist
3072 		{
3073 			$$ = SQL_NEW_RULE;
3074 			$$->append($1);
3075 			$$->append($2);
3076 			$$->append($3);
3077 		}
3078 	;
3079 function_args_commalist:
3080 		function_arg
3081 			{$$ = SQL_NEW_COMMALISTRULE;
3082 			$$->append($1);}
3083 	|   function_args_commalist ',' function_arg
3084 			{$1->append($3);
3085 			$$ = $1;}
3086 	/*	this rule is only valid if we check predicates */
3087 	|   function_args_commalist ';' function_arg
3088 		{
3089 			if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
3090 			{
3091 				$1->append($3);
3092 				$$ = $1;
3093 			}
3094 			else
3095 				YYERROR;
3096 		}
3097 	;
3098 
3099 value_exp:
3100 		num_value_exp /*[^')']*/
3101 	  | string_value_exp
3102 	  | datetime_value_exp
3103 		{
3104 			$$ = SQL_NEW_RULE;
3105 			$$->append($1);
3106 		}
3107 	;
3108 string_value_exp:
3109 		char_value_exp
3110 /*      | bit_value_exp
3111 		{
3112 			$$ = SQL_NEW_RULE;
3113 			$$->append($1);
3114 		}
3115 */	;
3116 char_value_exp:
3117 		char_factor
3118 	|	concatenation
3119 	;
3120 concatenation:
3121 		char_value_exp '+' char_factor
3122 		{
3123 			$$ = SQL_NEW_RULE;
3124 			$$->append($1);
3125 			$$->append(newNode("+", SQLNodeType::Punctuation));
3126 			$$->append($3);
3127 		}
3128 	|	value_exp SQL_CONCAT value_exp
3129 		{
3130 			$$ = SQL_NEW_RULE;
3131 			$$->append($1);
3132 			$$->append($2);
3133 			$$->append($3);
3134 		}
3135 	;
3136 
3137 char_primary:
3138 			SQL_TOKEN_STRING
3139 	  |		string_value_fct
3140 	;
3141 collate_clause:
3142 		SQL_TOKEN_COLLATE table_node
3143 		{
3144 			$$ = SQL_NEW_RULE;
3145 			$$->append($1);
3146 			$$->append($2);
3147 		}
3148 	;
3149 char_factor:
3150 		char_primary
3151 	|	char_primary collate_clause
3152 		{
3153 			$$ = SQL_NEW_RULE;
3154 			$$->append($1);
3155 			$$->append($2);
3156 		}
3157 	;
3158 string_value_fct:
3159 		char_value_fct
3160 	  | bit_value_fct
3161 	;
3162 bit_value_fct:
3163 		bit_substring_fct
3164 		{
3165 			$$ = SQL_NEW_RULE;
3166 			$$->append($1);
3167 		}
3168 	;
3169 bit_substring_fct:
3170 		SQL_TOKEN_SUBSTRING '(' bit_value_exp SQL_TOKEN_FROM string_value_exp for_length ')'
3171 		{
3172 			$$ = SQL_NEW_RULE;
3173 			$$->append($1);
3174 			$$->append(newNode("(", SQLNodeType::Punctuation));
3175 			$$->append($3);
3176 			$$->append($4);
3177 			$$->append($5);
3178 			$$->append($6);
3179 			$$->append(newNode(")", SQLNodeType::Punctuation));
3180 		}
3181 	;
3182 bit_value_exp:
3183 		bit_factor
3184 		{
3185 			$$ = SQL_NEW_RULE;
3186 			$$->append($1);
3187 		}
3188 	;
3189 /*
3190 			bit_concatenation
3191 		{
3192 			$$ = SQL_NEW_RULE;
3193 			$$->append($1);
3194 		}
3195 	  |
3196 bit_concatenation:
3197 		bit_value_exp '+' bit_factor
3198 		{
3199 			$$ = SQL_NEW_RULE;
3200 			$$->append($1);
3201 			$$->append(newNode("+", SQLNodeType::Punctuation));
3202 			$$->append($3);
3203 		}
3204 	;
3205 */
3206 bit_factor:
3207 		bit_primary
3208 		{
3209 			$$ = SQL_NEW_RULE;
3210 			$$->append($1);
3211 		}
3212 	;
3213 bit_primary:
3214 	{$$ = SQL_NEW_RULE;}
3215 /*		value_exp_primary
3216 		{
3217 			$$ = SQL_NEW_RULE;
3218 			$$->append($1);
3219 		}
3220 	  | string_value_fct
3221 		{
3222 			$$ = SQL_NEW_RULE;
3223 			$$->append($1);
3224 		}*/
3225 	;
3226 char_value_fct:
3227 		char_substring_fct
3228 	  | fold
3229 	  | form_conversion
3230 		{
3231 			$$ = SQL_NEW_RULE;
3232 			$$->append($1);
3233 		}
3234 	  | char_translation
3235 		{
3236 			$$ = SQL_NEW_RULE;
3237 			$$->append($1);
3238 		}
3239 	  | trim_fct
3240 		{
3241 			$$ = SQL_NEW_RULE;
3242 			$$->append($1);
3243 		}
3244 	;
3245 for_length:
3246 		{$$ = SQL_NEW_RULE;}
3247 	|	SQL_TOKEN_FOR value_exp
3248 		{
3249 			$$ = SQL_NEW_RULE;
3250 			$$->append($1);
3251 			$$->append($2);
3252 		}
3253 	;
3254 char_substring_fct:
3255 		SQL_TOKEN_SUBSTRING '(' value_exp SQL_TOKEN_FROM value_exp for_length ')'
3256 		{
3257 			$$ = SQL_NEW_RULE;
3258 			$$->append($1);
3259 			$$->append(newNode("(", SQLNodeType::Punctuation));
3260 			$$->append($3);
3261 			$$->append($4);
3262 			$$->append($5);
3263 			$$->append($6);
3264 			$$->append(newNode(")", SQLNodeType::Punctuation));
3265 		}
3266 	|	SQL_TOKEN_SUBSTRING '(' value_exp_commalist ')'
3267 		{
3268 			$$ = SQL_NEW_RULE;
3269 			$$->append($1);
3270 			$$->append(newNode("(", SQLNodeType::Punctuation));
3271 			$$->append($3);
3272 			$$->append(newNode(")", SQLNodeType::Punctuation));
3273 		}
3274 	;
3275 upper_lower:
3276 		SQL_TOKEN_UPPER
3277 	|	SQL_TOKEN_LOWER
3278 	;
3279 fold:
3280 		upper_lower '(' value_exp ')'
3281 		{
3282 			$$ = SQL_NEW_RULE;
3283 			$$->append($1);
3284 			$$->append(newNode("(", SQLNodeType::Punctuation));
3285 			$$->append($3);
3286 			$$->append(newNode(")", SQLNodeType::Punctuation));
3287 		}
3288 	;
3289 form_conversion:
3290 		SQL_TOKEN_CONVERT '(' string_value_exp SQL_TOKEN_USING table_node ')'
3291 		{
3292 			$$ = SQL_NEW_RULE;
3293 			$$->append($1);
3294 			$$->append(newNode("(", SQLNodeType::Punctuation));
3295 			$$->append($3);
3296 			$$->append($4);
3297 			$$->append($5);
3298 			$$->append(newNode(")", SQLNodeType::Punctuation));
3299 		}
3300 	|	SQL_TOKEN_CONVERT '(' cast_operand ',' cast_target ')'
3301 		{
3302 			$$ = SQL_NEW_RULE;
3303 			$$->append($1);
3304 			$$->append(newNode("(", SQLNodeType::Punctuation));
3305 			$$->append($3);
3306 			$$->append(newNode(",", SQLNodeType::Punctuation));
3307 			$$->append($5);
3308 			$$->append(newNode(")", SQLNodeType::Punctuation));
3309 		}
3310 	;
3311 char_translation:
3312 		SQL_TOKEN_TRANSLATE '(' string_value_exp SQL_TOKEN_USING table_node ')'
3313 		{
3314 			$$ = SQL_NEW_RULE;
3315 			$$->append($1);
3316 			$$->append(newNode("(", SQLNodeType::Punctuation));
3317 			$$->append($3);
3318 			$$->append($4);
3319 			$$->append($5);
3320 			$$->append(newNode(")", SQLNodeType::Punctuation));
3321 		}
3322 	;
3323 trim_fct:
3324 		SQL_TOKEN_TRIM  '(' trim_operands ')'
3325 		{
3326 			$$ = SQL_NEW_RULE;
3327 			$$->append($1);
3328 			$$->append(newNode("(", SQLNodeType::Punctuation));
3329 			$$->append($3);
3330 			$$->append(newNode(")", SQLNodeType::Punctuation));
3331 		}
3332 	;
3333 trim_operands:
3334     trim_spec value_exp SQL_TOKEN_FROM value_exp
3335         {
3336 			$$ = SQL_NEW_RULE;
3337 			$$->append($1);
3338 			$$->append($2);
3339 			$$->append($3);
3340 			$$->append($4);
3341 		}
3342 	| trim_spec SQL_TOKEN_FROM value_exp
3343         {
3344 			$$ = SQL_NEW_RULE;
3345 			$$->append($1);
3346 			$$->append($2);
3347 			$$->append($3);
3348 		}
3349 	| value_exp SQL_TOKEN_FROM value_exp
3350         {
3351 			$$ = SQL_NEW_RULE;
3352 			$$->append($1);
3353 			$$->append($2);
3354 			$$->append($3);
3355 		}
3356 	| SQL_TOKEN_FROM value_exp
3357 	    {
3358 			$$ = SQL_NEW_RULE;
3359 			$$->append($1);
3360 			$$->append($2);
3361 		}
3362 	| value_exp
3363 	;
3364 
3365 trim_spec:
3366         SQL_TOKEN_BOTH
3367 	|	SQL_TOKEN_LEADING
3368 	|	SQL_TOKEN_TRAILING
3369 	;
3370 
3371 derived_column:
3372 		value_exp as_clause
3373 		{
3374 			$$ = SQL_NEW_RULE;
3375 			$$->append($1);
3376 			$$->append($2);
3377 		}
3378 	;
3379 /* Tabellenname */
3380 table_node:
3381 		table_name
3382 	|	schema_name
3383 	|	catalog_name
3384 ;
3385 catalog_name:
3386 		SQL_TOKEN_NAME '.' schema_name
3387 		{
3388 			$$ = SQL_NEW_RULE;
3389 			$$->append($1);
3390 			$$->append(newNode(".", SQLNodeType::Punctuation));
3391 			$$->append($3);
3392 		}
3393 	|	SQL_TOKEN_NAME ':' schema_name
3394 		{
3395 			$$ = SQL_NEW_RULE;
3396 			$$->append($1);
3397 			$$->append(newNode(":", SQLNodeType::Punctuation));
3398 			$$->append($3);
3399 		}
3400 ;
3401 schema_name:
3402 		SQL_TOKEN_NAME '.' table_name
3403 		{
3404 			$$ = SQL_NEW_RULE;
3405 			$$->append($1);
3406 			$$->append(newNode(".", SQLNodeType::Punctuation));
3407 			$$->append($3);
3408 		}
3409 ;
3410 
3411 table_name:
3412 			SQL_TOKEN_NAME
3413 			{$$ = SQL_NEW_RULE;
3414 			$$->append($1);}
3415 ;
3416 /* Columns */
3417 column_ref:
3418 			column
3419 			{$$ = SQL_NEW_RULE;
3420 			$$->append($1);}
3421 /*	|       table_node '.' column_val %prec '.'
3422 			{$$ = SQL_NEW_RULE;
3423 			$$->append($1);
3424 			$$->append(newNode(".", SQLNodeType::Punctuation));
3425 			$$->append($3);}
3426 */
3427 	|       SQL_TOKEN_NAME '.' column_val %prec '.'
3428 			{$$ = SQL_NEW_RULE;
3429 			$$->append($1);
3430 			$$->append(newNode(".", SQLNodeType::Punctuation));
3431 			$$->append($3);
3432 			}
3433 	|       SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val %prec '.'
3434 			{$$ = SQL_NEW_RULE;
3435 			$$->append($1);
3436 			$$->append(newNode(".", SQLNodeType::Punctuation));
3437 			$$->append($3);
3438 			$$->append(newNode(".", SQLNodeType::Punctuation));
3439 			$$->append($5);}
3440 	|       SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val %prec '.'
3441 			{$$ = SQL_NEW_RULE;
3442 			$$->append($1);
3443 			$$->append(newNode(".", SQLNodeType::Punctuation));
3444 			$$->append($3);
3445 			$$->append(newNode(".", SQLNodeType::Punctuation));
3446 			$$->append($5);
3447 			$$->append(newNode(".", SQLNodeType::Punctuation));
3448 			$$->append($7);
3449 			}
3450 	|       SQL_TOKEN_NAME ':' SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val %prec '.'
3451 			{$$ = SQL_NEW_RULE;
3452 			$$->append($1);
3453 			$$->append(newNode(":", SQLNodeType::Punctuation));
3454 			$$->append($3);
3455 			$$->append(newNode(".", SQLNodeType::Punctuation));
3456 			$$->append($5);
3457 			$$->append(newNode(".", SQLNodeType::Punctuation));
3458 			$$->append($7);
3459 			}
3460 /*	|       SQL_TOKEN_NAME ';' SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val
3461 			{$$ = SQL_NEW_RULE;
3462 			$$->append($1);
3463 			$$->append(newNode(";", SQLNodeType::Punctuation));
3464 			$$->append($3);
3465 			$$->append(newNode(".", SQLNodeType::Punctuation));
3466 			$$->append($5);
3467 			$$->append(newNode(".", SQLNodeType::Punctuation));
3468 			$$->append($7);
3469 			}
3470 */	;
3471 
3472 		/* data types */
3473 column_val:
3474 		column
3475 		{$$ = SQL_NEW_RULE;
3476 			$$->append($1);}
3477 	|	'*'
3478 		{
3479 			$$ = SQL_NEW_RULE;
3480 			$$->append(newNode("*", SQLNodeType::Punctuation));
3481 		}
3482 	;
3483 data_type:
3484 	predefined_type
3485 	;
3486 opt_char_set_spec:
3487 	{$$ = SQL_NEW_RULE;}
3488 	|	SQL_TOKEN_CHARACTER SQL_TOKEN_SET SQL_TOKEN_NAME
3489 		{
3490 			$$ = SQL_NEW_RULE;
3491 			$$->append($1);
3492 			$$->append($2);
3493 			$$->append($3);
3494 		}
3495 	;
3496 opt_collate_clause:
3497 	{$$ = SQL_NEW_RULE;}
3498 	| collate_clause
3499 	;
3500 predefined_type:
3501 		character_string_type opt_char_set_spec	opt_collate_clause
3502 		{
3503 			$$ = SQL_NEW_RULE;
3504 			$$->append($1);
3505 			$$->append($2);
3506 			$$->append($3);
3507 		}
3508 	|	national_character_string_type opt_collate_clause
3509 		{
3510 			$$ = SQL_NEW_RULE;
3511 			$$->append($1);
3512 			$$->append($2);
3513 		}
3514 	|	binary_string_type
3515 	|	numeric_type
3516 	|	boolean_type
3517 	|	datetime_type
3518 	|	interval_type
3519 	;
3520 character_string_type:
3521 		SQL_TOKEN_CHARACTER opt_paren_precision
3522 		{
3523 			$$ = SQL_NEW_RULE;
3524 			$$->append($1);
3525 			$$->append($2);
3526 		}
3527 	|	SQL_TOKEN_CHAR opt_paren_precision
3528 		{
3529 			$$ = SQL_NEW_RULE;
3530 			$$->append($1);
3531 			$$->append($2);
3532 		}
3533 	|	SQL_TOKEN_CHARACTER SQL_TOKEN_VARYING paren_char_length
3534 		{
3535 			$$ = SQL_NEW_RULE;
3536 			$$->append($1);
3537 			$$->append($2);
3538 			$$->append($3);
3539 		}
3540 	|	SQL_TOKEN_CHAR SQL_TOKEN_VARYING paren_char_length
3541 		{
3542 			$$ = SQL_NEW_RULE;
3543 			$$->append($1);
3544 			$$->append($2);
3545 			$$->append($3);
3546 		}
3547 	|	SQL_TOKEN_VARCHAR paren_char_length
3548 		{
3549 			$$ = SQL_NEW_RULE;
3550 			$$->append($1);
3551 			$$->append($2);
3552 		}
3553 	| character_large_object_type
3554 	;
3555 opt_paren_precision:
3556 		{$$ = SQL_NEW_RULE;}
3557 	|	paren_char_length
3558 	;
3559 paren_char_length:
3560 	'(' SQL_TOKEN_INTNUM ')'
3561 	{
3562 		$$ = SQL_NEW_RULE;
3563 		$$->append(newNode("(", SQLNodeType::Punctuation));
3564 		$$->append($2);
3565 		$$->append(newNode(")", SQLNodeType::Punctuation));
3566 	}
3567 	;
3568 opt_paren_char_large_length:
3569 		{$$ = SQL_NEW_RULE;}
3570 	|	paren_character_large_object_length
3571 	;
3572 paren_character_large_object_length:
3573 	'(' large_object_length ')'
3574 	{
3575 		$$ = SQL_NEW_RULE;
3576 		$$->append(newNode("(", SQLNodeType::Punctuation));
3577 		$$->append($2);
3578 		$$->append(newNode(")", SQLNodeType::Punctuation));
3579 	}
3580 	;
3581 
3582 large_object_length:
3583 	SQL_TOKEN_INTNUM opt_multiplier
3584 	{
3585 		$$ = SQL_NEW_RULE;
3586 		$$->append($1);
3587 		$$->append($2);
3588 	}
3589 	;
3590 opt_multiplier:
3591 	{$$ = SQL_NEW_RULE;}
3592 	|	'K'
3593 		{
3594 			$$ = SQL_NEW_RULE;
3595 			$$->append(newNode("K", SQLNodeType::Punctuation));
3596 		}
3597 	|	'M'
3598 		{
3599 			$$ = SQL_NEW_RULE;
3600 			$$->append(newNode("M", SQLNodeType::Punctuation));
3601 		}
3602 	|	'G'
3603 		{
3604 			$$ = SQL_NEW_RULE;
3605 			$$->append(newNode("G", SQLNodeType::Punctuation));
3606 		}
3607 	|	'T'
3608 		{
3609 			$$ = SQL_NEW_RULE;
3610 			$$->append(newNode("T", SQLNodeType::Punctuation));
3611 		}
3612 	|	'P'
3613 		{
3614 			$$ = SQL_NEW_RULE;
3615 			$$->append(newNode("P", SQLNodeType::Punctuation));
3616 		}
3617 	;
3618 character_large_object_type:
3619 		SQL_TOKEN_CHARACTER SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3620 	{
3621 			$$ = SQL_NEW_RULE;
3622 			$$->append($1);
3623 			$$->append($2);
3624 			$$->append($3);
3625 			$$->append($4);
3626 		}
3627 	|	SQL_TOKEN_CHAR SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3628 		{
3629 			$$ = SQL_NEW_RULE;
3630 			$$->append($1);
3631 			$$->append($2);
3632 			$$->append($3);
3633 			$$->append($4);
3634 		}
3635 	|	SQL_TOKEN_CLOB opt_paren_char_large_length
3636 		{
3637 			$$ = SQL_NEW_RULE;
3638 			$$->append($1);
3639 			$$->append($2);
3640 		}
3641 	;
3642 national_character_string_type:
3643 		SQL_TOKEN_NATIONAL SQL_TOKEN_CHARACTER opt_paren_precision
3644 		{
3645 			$$ = SQL_NEW_RULE;
3646 			$$->append($1);
3647 			$$->append($2);
3648 			$$->append($3);
3649 		}
3650 	|	SQL_TOKEN_NATIONAL SQL_TOKEN_CHAR opt_paren_precision
3651 		{
3652 			$$ = SQL_NEW_RULE;
3653 			$$->append($1);
3654 			$$->append($2);
3655 			$$->append($3);
3656 		}
3657 	|	SQL_TOKEN_NCHAR opt_paren_precision
3658 		{
3659 			$$ = SQL_NEW_RULE;
3660 			$$->append($1);
3661 			$$->append($2);
3662 		}
3663 	|	SQL_TOKEN_NATIONAL SQL_TOKEN_CHARACTER SQL_TOKEN_VARYING paren_char_length
3664 		{
3665 			$$ = SQL_NEW_RULE;
3666 			$$->append($1);
3667 			$$->append($2);
3668 			$$->append($3);
3669 			$$->append($4);
3670 		}
3671 	|	SQL_TOKEN_NATIONAL SQL_TOKEN_CHAR SQL_TOKEN_VARYING paren_char_length
3672 		{
3673 			$$ = SQL_NEW_RULE;
3674 			$$->append($1);
3675 			$$->append($2);
3676 			$$->append($3);
3677 			$$->append($4);
3678 		}
3679 	|	SQL_TOKEN_NCHAR SQL_TOKEN_VARYING paren_char_length
3680 		{
3681 			$$ = SQL_NEW_RULE;
3682 			$$->append($1);
3683 			$$->append($2);
3684 			$$->append($3);
3685 		}
3686 	|	national_character_large_object_type
3687 	;
3688 national_character_large_object_type:
3689 		SQL_TOKEN_NATIONAL SQL_TOKEN_CHARACTER SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3690 		{
3691 			$$ = SQL_NEW_RULE;
3692 			$$->append($1);
3693 			$$->append($2);
3694 			$$->append($3);
3695 			$$->append($4);
3696 			$$->append($5);
3697 		}
3698 	|	SQL_TOKEN_NCHAR SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3699 		{
3700 			$$ = SQL_NEW_RULE;
3701 			$$->append($1);
3702 			$$->append($2);
3703 			$$->append($3);
3704 			$$->append($4);
3705 		}
3706 	|	SQL_TOKEN_NCLOB opt_paren_char_large_length
3707 		{
3708 			$$ = SQL_NEW_RULE;
3709 			$$->append($1);
3710 			$$->append($2);
3711 		}
3712 	;
3713 binary_string_type:
3714 		SQL_TOKEN_BINARY opt_paren_precision
3715 		{
3716 			$$ = SQL_NEW_RULE;
3717 			$$->append($1);
3718 			$$->append($2);
3719 		}
3720 	|	SQL_TOKEN_BINARY SQL_TOKEN_VARYING paren_char_length
3721 		{
3722 			$$ = SQL_NEW_RULE;
3723 			$$->append($1);
3724 			$$->append($2);
3725 			$$->append($3);
3726 		}
3727 	|	SQL_TOKEN_VARBINARY paren_char_length
3728 		{
3729 			$$ = SQL_NEW_RULE;
3730 			$$->append($1);
3731 			$$->append($2);
3732 		}
3733 	|	binary_large_object_string_type
3734 	;
3735 binary_large_object_string_type:
3736 		SQL_TOKEN_BINARY SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3737 		{
3738 			$$ = SQL_NEW_RULE;
3739 			$$->append($1);
3740 			$$->append($2);
3741 			$$->append($3);
3742 			$$->append($4);
3743 		}
3744 	|	SQL_TOKEN_BLOB opt_paren_char_large_length
3745 		{
3746 			$$ = SQL_NEW_RULE;
3747 			$$->append($1);
3748 			$$->append($2);
3749 		}
3750 	;
3751 numeric_type:
3752 		exact_numeric_type
3753 	|	approximate_numeric_type
3754 	;
3755 opt_paren_precision_scale:
3756 	{$$ = SQL_NEW_RULE;}
3757 	|	'(' SQL_TOKEN_INTNUM ')'
3758 		{
3759 			$$ = SQL_NEW_RULE;
3760 			$$->append(newNode("(", SQLNodeType::Punctuation));
3761 			$$->append($2);
3762 			$$->append(newNode(")", SQLNodeType::Punctuation));
3763 		}
3764 	|	'(' SQL_TOKEN_INTNUM ',' SQL_TOKEN_INTNUM ')'
3765 		{
3766 			$$ = SQL_NEW_RULE;
3767 			$$->append(newNode("(", SQLNodeType::Punctuation));
3768 			$$->append($2);
3769 			$$->append(newNode(",", SQLNodeType::Punctuation));
3770 			$$->append($4);
3771 			$$->append(newNode(")", SQLNodeType::Punctuation));
3772 		}
3773 	;
3774 exact_numeric_type:
3775 		SQL_TOKEN_NUMERIC opt_paren_precision_scale
3776 		{
3777 			$$ = SQL_NEW_RULE;
3778 			$$->append($1);
3779 			$$->append($2);
3780 		}
3781 	|	SQL_TOKEN_DECIMAL opt_paren_precision_scale
3782 		{
3783 			$$ = SQL_NEW_RULE;
3784 			$$->append($1);
3785 			$$->append($2);
3786 		}
3787 	|	SQL_TOKEN_DEC opt_paren_precision_scale
3788 		{
3789 			$$ = SQL_NEW_RULE;
3790 			$$->append($1);
3791 			$$->append($2);
3792 		}
3793 	|	SQL_TOKEN_SMALLINT
3794 	|	SQL_TOKEN_INTEGER
3795 	|	SQL_TOKEN_INT
3796 	|	SQL_TOKEN_BIGINT
3797 	;
3798 approximate_numeric_type:
3799 		SQL_TOKEN_FLOAT '(' SQL_TOKEN_INTNUM ')'
3800 		{
3801 			$$ = SQL_NEW_RULE;
3802 			$$->append($1);
3803 			$$->append(newNode("(", SQLNodeType::Punctuation));
3804 			$$->append($3);
3805 			$$->append(newNode(")", SQLNodeType::Punctuation));
3806 		}
3807 	|	SQL_TOKEN_FLOAT
3808 	|	SQL_TOKEN_REAL
3809 	|	SQL_TOKEN_DOUBLE
3810 	|	SQL_TOKEN_DOUBLE SQL_TOKEN_PRECISION
3811 		{
3812 			$$ = SQL_NEW_RULE;
3813 			$$->append($1);
3814 			$$->append($2);
3815 		}
3816 	;
3817 boolean_type:
3818 	SQL_TOKEN_BOOLEAN
3819 ;
3820 datetime_type:
3821 		SQL_TOKEN_DATE
3822 	|	SQL_TOKEN_TIME opt_paren_precision opt_with_or_without_time_zone
3823 		{
3824 			$$ = SQL_NEW_RULE;
3825 			$$->append($1);
3826 			$$->append($2);
3827 			$$->append($3);
3828 		}
3829 	|	SQL_TOKEN_TIMESTAMP opt_paren_precision opt_with_or_without_time_zone
3830 		{
3831 			$$ = SQL_NEW_RULE;
3832 			$$->append($1);
3833 			$$->append($2);
3834 			$$->append($3);
3835 		}
3836 	;
3837 opt_with_or_without_time_zone:
3838 		{$$ = SQL_NEW_RULE;}
3839 	|	SQL_TOKEN_WITH SQL_TOKEN_TIME SQL_TOKEN_ZONE
3840 		{
3841 			$$ = SQL_NEW_RULE;
3842 			$$->append($1);
3843 			$$->append($2);
3844 			$$->append($3);
3845 		}
3846 	|	SQL_TOKEN_WITHOUT SQL_TOKEN_TIME SQL_TOKEN_ZONE
3847 		{
3848 			$$ = SQL_NEW_RULE;
3849 			$$->append($1);
3850 			$$->append($2);
3851 			$$->append($3);
3852 		}
3853 	;
3854 interval_type:
3855 	SQL_TOKEN_INTERVAL interval_qualifier
3856 	{
3857 		$$ = SQL_NEW_RULE;
3858 		$$->append($1);
3859 		$$->append($2);
3860 	}
3861 	;
3862 	/* the various things you can name */
3863 
3864 column:
3865 		SQL_TOKEN_NAME
3866 	|	SQL_TOKEN_POSITION
3867 		{
3868 			sal_uInt32 nNod = $$->getRuleID();
3869 			delete $$;
3870 			$$ = newNode(OSQLParser::TokenIDToStr(nNod), SQLNodeType::Name);
3871 		}
3872 	|	SQL_TOKEN_CHAR_LENGTH
3873 		{
3874 			sal_uInt32 nNod = $$->getRuleID();
3875 			delete $$;
3876 			$$ = newNode(OSQLParser::TokenIDToStr(nNod), SQLNodeType::Name);
3877 		}
3878 	|	SQL_TOKEN_EXTRACT
3879 		{
3880 			sal_uInt32 nNod = $$->getRuleID();
3881 			delete $$;
3882 			$$ = newNode(OSQLParser::TokenIDToStr(nNod), SQLNodeType::Name);
3883 		}
3884 	;
3885 case_expression:
3886 		case_abbreviation
3887 	|	case_specification
3888 	;
3889 case_abbreviation:
3890 		SQL_TOKEN_NULLIF '(' value_exp_commalist ')'
3891 		{
3892 			$$ = SQL_NEW_RULE;
3893 			$$->append($1);
3894 			$$->append(newNode("(", SQLNodeType::Punctuation));
3895 			$$->append($3);
3896 			$$->append(newNode(")", SQLNodeType::Punctuation));
3897 		}
3898 	|	SQL_TOKEN_COALESCE '(' value_exp ')'
3899 		{
3900 			$$ = SQL_NEW_RULE;
3901 			$$->append($1);
3902 			$$->append(newNode("(", SQLNodeType::Punctuation));
3903 			$$->append($3);
3904 			$$->append(newNode(")", SQLNodeType::Punctuation));
3905 		}
3906 	|	SQL_TOKEN_COALESCE '(' value_exp_commalist ')'
3907 		{
3908 			$$ = SQL_NEW_RULE;
3909 			$$->append($1);
3910 			$$->append(newNode("(", SQLNodeType::Punctuation));
3911 			$$->append($3);
3912 			$$->append(newNode(")", SQLNodeType::Punctuation));
3913 		}
3914 	;
3915 case_specification:
3916 		simple_case
3917 	|	searched_case
3918 	;
3919 simple_case:
3920 	SQL_TOKEN_CASE case_operand simple_when_clause_list else_clause SQL_TOKEN_END
3921 		{
3922 			$$ = SQL_NEW_RULE;
3923 			$$->append($1);
3924 			$$->append($2);
3925 			$$->append($3);
3926 			$$->append($4);
3927 			$$->append($5);
3928 		}
3929 	;
3930 searched_case:
3931 	SQL_TOKEN_CASE searched_when_clause_list else_clause SQL_TOKEN_END
3932 		{
3933 			$$ = SQL_NEW_RULE;
3934 			$$->append($1);
3935 			$$->append($2);
3936 			$$->append($3);
3937 			$$->append($4);
3938 		}
3939 	;
3940 simple_when_clause_list:
3941 		simple_when_clause
3942 		{
3943 			$$ = SQL_NEW_LISTRULE;
3944 			$$->append($1);
3945 		}
3946 	|   searched_when_clause_list simple_when_clause
3947 		{
3948 			$1->append($2);
3949 			$$ = $1;
3950 		}
3951 	;
3952 simple_when_clause:
3953 	SQL_TOKEN_WHEN when_operand_list SQL_TOKEN_THEN result
3954 	{
3955 			$$ = SQL_NEW_RULE;
3956 			$$->append($1);
3957 			$$->append($2);
3958 			$$->append($3);
3959 			$$->append($4);
3960 		}
3961 	;
3962 when_operand_list:
3963 		when_operand
3964 		{$$ = SQL_NEW_COMMALISTRULE;
3965 		$$->append($1);}
3966 	|   when_operand_list ',' when_operand
3967 		{$1->append($3);
3968 		$$ = $1;}
3969 	;
3970 when_operand:
3971 		row_value_constructor_elem
3972 	|	comparison_predicate_part_2        %dprec 1
3973 	|	between_predicate_part_2
3974 	|	in_predicate_part_2
3975 	|	character_like_predicate_part_2
3976 	|	null_predicate_part_2              %dprec 2
3977 ;
3978 searched_when_clause_list:
3979 		searched_when_clause
3980 		{
3981 			$$ = SQL_NEW_LISTRULE;
3982 			$$->append($1);
3983 		}
3984 	|   searched_when_clause_list searched_when_clause
3985 		{
3986 			$1->append($2);
3987 			$$ = $1;
3988 		}
3989 	;
3990 searched_when_clause:
3991 	SQL_TOKEN_WHEN search_condition SQL_TOKEN_THEN result
3992 	{
3993 			$$ = SQL_NEW_RULE;
3994 			$$->append($1);
3995 			$$->append($2);
3996 			$$->append($3);
3997 			$$->append($4);
3998 		}
3999 	;
4000 else_clause:
4001 		{$$ = SQL_NEW_RULE;}
4002 	|	SQL_TOKEN_ELSE result
4003 		{
4004 			$$ = SQL_NEW_RULE;
4005 			$$->append($1);
4006 			$$->append($2);
4007 		}
4008 	;
4009 result:
4010 		result_expression
4011 	;
4012 result_expression:
4013 	value_exp
4014 	;
4015 case_operand:
4016 	row_value_constructor_elem
4017 	;
4018 
4019 cursor:	SQL_TOKEN_NAME
4020 			{$$ = SQL_NEW_RULE;
4021 			$$->append($1);}
4022 	;
4023 
4024 /***
4025 module:	SQL_TOKEN_NAME
4026 			{$$ = SQL_NEW_RULE;
4027 			$$->append($1);}
4028 	;
4029 ***/
4030 
4031 parameter:
4032 		':' SQL_TOKEN_NAME
4033 			{$$ = SQL_NEW_RULE;
4034 			$$->append(newNode(":", SQLNodeType::Punctuation));
4035 			$$->append($2);}
4036 	|	'?'
4037 			{$$ = SQL_NEW_RULE; // test
4038 			$$->append(newNode("?", SQLNodeType::Punctuation));}
4039 	|	'['	SQL_TOKEN_NAME ']'
4040 			{$$ = SQL_NEW_RULE;
4041 			$$->append(newNode("[", SQLNodeType::Punctuation));
4042 			$$->append($2);
4043 			$$->append(newNode("]", SQLNodeType::Punctuation));}
4044 	;
4045 
4046 /***
4047 procedure:      SQL_TOKEN_NAME
4048 			{$$ = SQL_NEW_RULE;
4049 			$$->append($1);}
4050 	;
4051 ***/
4052 
4053 range_variable:
4054         {$$ = SQL_NEW_RULE;}
4055     |   opt_as SQL_TOKEN_NAME
4056         {$$ = SQL_NEW_RULE;
4057         $$->append($1);
4058         $$->append($2);
4059         }
4060 	;
4061 
4062 user:	SQL_TOKEN_NAME
4063 	;
4064 
4065 /* PREDICATECHECK RULES */
4066 sql:
4067 		search_condition /* checking predicats */
4068 		{
4069 			if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // sql: rule 1
4070 			{
4071 				$$ = $1;
4072 				if ( SQL_ISRULE($$,search_condition) )
4073 				{
4074 					$$->insert(0,newNode("(", SQLNodeType::Punctuation));
4075 					$$->append(newNode(")", SQLNodeType::Punctuation));
4076 				}
4077 			}
4078 			else
4079 				YYERROR;
4080 		}
4081 	|   '(' sql ')' /* checking predicats */
4082     ;
4083 trigger_definition:
4084 	SQL_TOKEN_CREATE SQL_TOKEN_TRIGGER trigger_name trigger_action_time trigger_event SQL_TOKEN_ON table_name op_referencing triggered_action
4085 	{
4086 		$$ = SQL_NEW_RULE;
4087         $$->append($1);
4088         $$->append($2);
4089         $$->append($3);
4090         $$->append($4);
4091         $$->append($5);
4092         $$->append($6);
4093         $$->append($7);
4094         $$->append($8);
4095         $$->append($9);
4096     }
4097 	;
4098 op_referencing:
4099 	{
4100 		$$ = SQL_NEW_RULE;
4101 	}
4102 	|	SQL_TOKEN_REFERENCING transition_table_or_variable_list
4103 	{
4104 		$$ = SQL_NEW_RULE;
4105         $$->append($1);
4106         $$->append($2);
4107     }
4108 	;
4109 trigger_action_time:
4110 		SQL_TOKEN_BEFORE
4111 	|	SQL_TOKEN_AFTER
4112 	|	SQL_TOKEN_INSTEAD SQL_TOKEN_OF
4113 	{
4114 		$$ = SQL_NEW_RULE;
4115         $$->append($1);
4116         $$->append($2);
4117     }
4118 ;
4119 trigger_event:
4120 		SQL_TOKEN_INSERT
4121 	|	SQL_TOKEN_DELETE
4122 	|	SQL_TOKEN_UPDATE op_trigger_columnlist
4123 	{
4124 		$$ = SQL_NEW_RULE;
4125         $$->append($1);
4126         $$->append($2);
4127     }
4128 	;
4129 op_trigger_columnlist:
4130 	{
4131 		$$ = SQL_NEW_RULE;
4132 	}
4133 	|	SQL_TOKEN_OF trigger_column_list
4134 	{
4135 		$$ = SQL_NEW_RULE;
4136         $$->append($1);
4137         $$->append($2);
4138     }
4139 	;
4140 trigger_column_list:
4141 	column_commalist
4142 	;
4143 triggered_action:
4144 	op_triggered_action_for triggered_when_clause triggered_SQL_statement
4145 	{
4146 		$$ = SQL_NEW_RULE;
4147         $$->append($1);
4148         $$->append($2);
4149         $$->append($3);
4150     }
4151 	;
4152 op_triggered_action_for:
4153 		{
4154 		$$ = SQL_NEW_RULE;
4155 		}
4156 	|	SQL_TOKEN_FOR SQL_TOKEN_EACH trigger_for
4157 	{
4158 		$$ = SQL_NEW_RULE;
4159         $$->append($1);
4160         $$->append($2);
4161         $$->append($3);
4162     }
4163 	;
4164 trigger_for:
4165 		SQL_TOKEN_ROW
4166 	|	SQL_TOKEN_STATEMENT
4167 	;
4168 triggered_when_clause:
4169 	{
4170 		$$ = SQL_NEW_RULE;
4171 	}
4172 	|	SQL_TOKEN_WHEN parenthesized_boolean_value_expression
4173 	{
4174 		$$ = SQL_NEW_RULE;
4175         $$->append($1);
4176         $$->append($2);
4177     }
4178 	;
4179 triggered_SQL_statement:
4180 		SQL_procedure_statement
4181 	|	SQL_TOKEN_BEGIN SQL_TOKEN_ATOMIC SQL_procedure_statement_list ';' SQL_TOKEN_END
4182 	{
4183 		$$ = SQL_NEW_RULE;
4184         $$->append($1);
4185         $$->append($2);
4186         $$->append($3);
4187         $$->append(newNode(";", SQLNodeType::Punctuation));
4188         $$->append($5);
4189     }
4190 	;
4191 SQL_procedure_statement_list:
4192 		SQL_procedure_statement
4193 		{
4194 			$$ = SQL_NEW_LISTRULE;
4195 			$$->append($1);
4196 		}
4197 	|	SQL_procedure_statement_list ';' SQL_procedure_statement
4198 		{
4199 			$1->append($3);
4200 			$$ = $1;
4201 		}
4202 	;
4203 SQL_procedure_statement:
4204 	sql
4205 	;
4206 
4207 transition_table_or_variable_list:
4208 		transition_table_or_variable
4209 		{
4210 			$$ = SQL_NEW_LISTRULE;
4211 			$$->append($1);
4212 		}
4213 	|   transition_table_or_variable_list transition_table_or_variable
4214 		{
4215 			$1->append($2);
4216 			$$ = $1;
4217 		}
4218 	;
4219 
4220 transition_table_or_variable:
4221 		SQL_TOKEN_OLD opt_row opt_as old_transition_variable_name
4222 	{
4223 		$$ = SQL_NEW_RULE;
4224         $$->append($1);
4225         $$->append($2);
4226         $$->append($3);
4227         $$->append($4);
4228     }
4229 	|	SQL_TOKEN_NEW opt_row opt_as new_transition_variable_name
4230 	{
4231 		$$ = SQL_NEW_RULE;
4232         $$->append($1);
4233         $$->append($2);
4234         $$->append($3);
4235         $$->append($4);
4236     }
4237 	|	SQL_TOKEN_OLD SQL_TOKEN_TABLE opt_as old_transition_table_name
4238 	{
4239 		$$ = SQL_NEW_RULE;
4240         $$->append($1);
4241         $$->append($2);
4242         $$->append($3);
4243         $$->append($4);
4244     }
4245 	|	SQL_TOKEN_NEW SQL_TOKEN_TABLE opt_as new_transition_table_name
4246 	{
4247 		$$ = SQL_NEW_RULE;
4248         $$->append($1);
4249         $$->append($2);
4250         $$->append($3);
4251         $$->append($4);
4252     }
4253 ;
4254 old_transition_table_name:
4255 	transition_table_name
4256 ;
4257 new_transition_table_name:
4258 	transition_table_name
4259 ;
4260 transition_table_name:
4261 	SQL_TOKEN_NAME
4262 ;
4263 old_transition_variable_name:
4264 	SQL_TOKEN_NAME
4265 ;
4266 new_transition_variable_name:
4267 	SQL_TOKEN_NAME
4268 ;
4269 trigger_name:
4270 	SQL_TOKEN_NAME
4271 ;
4272 %%
4273 
4274 #if defined _MSC_VER
4275 #pragma warning(pop)
4276 #endif
4277 
4278 using namespace ::com::sun::star::sdbc;
4279 using namespace ::com::sun::star::beans;
4280 using namespace ::com::sun::star::uno;
4281 using namespace ::com::sun::star::i18n;
4282 using namespace ::com::sun::star::lang;
4283 using namespace ::com::sun::star::util;
4284 using namespace ::osl;
4285 using namespace ::dbtools;
4286 
4287 connectivity::OSQLParser* xxx_pGLOBAL_SQLPARSER;
4288 
newNode(const char * pNewValue,const connectivity::SQLNodeType eNodeType,const sal_uInt32 nNodeID)4289 connectivity::OSQLInternalNode* newNode(const char* pNewValue,
4290         const connectivity::SQLNodeType eNodeType,
4291         const sal_uInt32 nNodeID)
4292 {
4293     return new connectivity::OSQLInternalNode(pNewValue, eNodeType, nNodeID);
4294 }
4295 
newNode(const OString & _newValue,const connectivity::SQLNodeType eNodeType,const sal_uInt32 nNodeID)4296 connectivity::OSQLInternalNode* newNode(const OString& _newValue,
4297         const connectivity::SQLNodeType eNodeType,
4298         const sal_uInt32 nNodeID)
4299 {
4300     return new connectivity::OSQLInternalNode(_newValue, eNodeType, nNodeID);
4301 }
4302 
newNode(const OUString & _newValue,const connectivity::SQLNodeType eNodeType,const sal_uInt32 nNodeID)4303 connectivity::OSQLInternalNode* newNode(const OUString& _newValue,
4304         const connectivity::SQLNodeType eNodeType,
4305         const sal_uInt32 nNodeID)
4306 {
4307     return new connectivity::OSQLInternalNode(_newValue, eNodeType, nNodeID);
4308 }
4309 
OParseContext()4310 OParseContext::OParseContext()
4311 {
4312 }
4313 
4314 
~OParseContext()4315 OParseContext::~OParseContext()
4316 {
4317 }
4318 
4319 
getErrorMessage(ErrorCode _eCode)4320 OUString OParseContext::getErrorMessage(ErrorCode _eCode) const
4321 {
4322     OUString aMsg;
4323     switch (_eCode)
4324     {
4325         case ErrorCode::General:              aMsg = "Syntax error in SQL expression"; break;
4326         case ErrorCode::ValueNoLike:          aMsg = "The value #1 can not be used with LIKE."; break;
4327         case ErrorCode::FieldNoLike:          aMsg = "LIKE can not be used with this field."; break;
4328         case ErrorCode::InvalidCompare:       aMsg = "The entered criterion can not be compared with this field."; break;
4329         case ErrorCode::InvalidIntCompare:    aMsg = "The field can not be compared with a number."; break;
4330         case ErrorCode::InvalidDateCompare:   aMsg = "The field can not be compared with a date."; break;
4331         case ErrorCode::InvalidRealCompare:   aMsg = "The field can not be compared with a floating point number."; break;
4332         case ErrorCode::InvalidTableNosuch:   aMsg = "The database does not contain a table named \"#\"."; break;
4333         case ErrorCode::InvalidTableOrQuery:  aMsg = "The database does contain neither a table nor a query named \"#\"."; break;
4334         case ErrorCode::InvalidColumn:        aMsg = "The column \"#1\" is unknown in the table \"#2\"."; break;
4335         case ErrorCode::InvalidTableExist:    aMsg = "The database already contains a table or view with name \"#\"."; break;
4336         case ErrorCode::InvalidQueryExist:    aMsg = "The database already contains a query with name \"#\"."; break;
4337         default:
4338             OSL_FAIL( "OParseContext::getErrorMessage: unknown error code!" );
4339             break;
4340     }
4341     return aMsg;
4342 }
4343 
4344 
getIntlKeywordAscii(InternationalKeyCode _eKey)4345 OString OParseContext::getIntlKeywordAscii(InternationalKeyCode _eKey) const
4346 {
4347 	OString aKeyword;
4348 	switch (_eKey)
4349 	{
4350 		case InternationalKeyCode::Like:		aKeyword = "LIKE"; break;
4351 		case InternationalKeyCode::Not:		aKeyword = "NOT"; break;
4352 		case InternationalKeyCode::Null:		aKeyword = "NULL"; break;
4353 		case InternationalKeyCode::True:		aKeyword = "True"; break;
4354 		case InternationalKeyCode::False:		aKeyword = "False"; break;
4355 		case InternationalKeyCode::Is:		aKeyword = "IS"; break;
4356 		case InternationalKeyCode::Between:	aKeyword = "BETWEEN"; break;
4357 		case InternationalKeyCode::Or:		aKeyword = "OR"; break;
4358 		case InternationalKeyCode::And:		aKeyword = "AND"; break;
4359 		case InternationalKeyCode::Avg:		aKeyword = "AVG"; break;
4360 		case InternationalKeyCode::Count:		aKeyword = "COUNT"; break;
4361 		case InternationalKeyCode::Max:		aKeyword = "MAX"; break;
4362 		case InternationalKeyCode::Min:		aKeyword = "MIN"; break;
4363 		case InternationalKeyCode::Sum:		aKeyword = "SUM"; break;
4364         case InternationalKeyCode::Every:     aKeyword = "EVERY"; break;
4365         case InternationalKeyCode::Any:       aKeyword = "ANY"; break;
4366         case InternationalKeyCode::Some:      aKeyword = "SOME"; break;
4367         case InternationalKeyCode::StdDevPop: aKeyword = "STDDEV_POP"; break;
4368         case InternationalKeyCode::StdDevSamp: aKeyword = "STDDEV_SAMP"; break;
4369         case InternationalKeyCode::VarSamp:  aKeyword = "VAR_SAMP"; break;
4370         case InternationalKeyCode::VarPop:   aKeyword = "VAR_POP"; break;
4371         case InternationalKeyCode::Collect:   aKeyword = "COLLECT"; break;
4372         case InternationalKeyCode::Fusion:    aKeyword = "FUSION"; break;
4373         case InternationalKeyCode::Intersection:aKeyword = "INTERSECTION"; break;
4374         case InternationalKeyCode::None:      break;
4375         default:
4376             OSL_FAIL( "OParseContext::getIntlKeywordAscii: unknown key!" );
4377             break;
4378 	}
4379 	return aKeyword;
4380 }
4381 
4382 
getIntlKeyCode(const OString & rToken)4383 IParseContext::InternationalKeyCode OParseContext::getIntlKeyCode(const OString& rToken) const
4384 {
4385 	static IParseContext::InternationalKeyCode Intl_TokenID[] =
4386 	{
4387 		InternationalKeyCode::Like, InternationalKeyCode::Not, InternationalKeyCode::Null, InternationalKeyCode::True,
4388 		InternationalKeyCode::False, InternationalKeyCode::Is, InternationalKeyCode::Between, InternationalKeyCode::Or,
4389 		InternationalKeyCode::And, InternationalKeyCode::Avg, InternationalKeyCode::Count, InternationalKeyCode::Max,
4390 		InternationalKeyCode::Min, InternationalKeyCode::Sum, InternationalKeyCode::Every,InternationalKeyCode::Any,InternationalKeyCode::Some,
4391         InternationalKeyCode::StdDevPop,InternationalKeyCode::StdDevSamp,InternationalKeyCode::VarSamp,
4392         InternationalKeyCode::VarPop,InternationalKeyCode::Collect,InternationalKeyCode::Fusion,InternationalKeyCode::Intersection
4393 	};
4394 
4395 	sal_uInt32 nCount = SAL_N_ELEMENTS( Intl_TokenID );
4396 	for (sal_uInt32 i = 0; i < nCount; i++)
4397 	{
4398 		OString aKey = getIntlKeywordAscii(Intl_TokenID[i]);
4399 		if (rToken.equalsIgnoreAsciiCase(aKey))
4400 			return Intl_TokenID[i];
4401 	}
4402 
4403 	return InternationalKeyCode::None;
4404 }
4405 
4406 
impl_getLocaleInstance()4407 static Locale& impl_getLocaleInstance( )
4408 {
4409 	static Locale s_aLocale( "en", "US", "" );
4410 	return s_aLocale;
4411 }
4412 
4413 
getPreferredLocale()4414 Locale OParseContext::getPreferredLocale( ) const
4415 {
4416 	return getDefaultLocale();
4417 }
4418 
4419 
getDefaultLocale()4420 const Locale& OParseContext::getDefaultLocale()
4421 {
4422 	return impl_getLocaleInstance();
4423 }
4424 
4425 // The (unfortunately global) yylval for the handing over of
4426 // values from the Scanner to the Parser. The global variable
4427 // is only used for a short term, the Parser reads the variable
4428 // immediately after the call of the Scanner into a same named own
4429 // member variable.
4430 
4431 
ConvertLikeToken(const OSQLParseNode * pTokenNode,const OSQLParseNode * pEscapeNode,bool bInternational)4432 OUString ConvertLikeToken(const OSQLParseNode* pTokenNode, const OSQLParseNode* pEscapeNode, bool bInternational)
4433 {
4434 	OUStringBuffer aMatchStr(0);
4435 	if (pTokenNode->isToken())
4436 	{
4437 		sal_Unicode cEscape = 0;
4438 		if (pEscapeNode->count())
4439 			cEscape = pEscapeNode->getChild(1)->getTokenValue().toChar();
4440 
4441 		// Change place holder
4442 		aMatchStr = pTokenNode->getTokenValue();
4443 		const sal_Int32 nLen = aMatchStr.getLength();
4444 		OUStringBuffer sSearch,sReplace;
4445 		if ( bInternational )
4446 		{
4447 		    sSearch.append("%_");
4448 		    sReplace.append("*?");
4449 		}
4450 		else
4451 		{
4452 		    sSearch.append("*?");
4453 		    sReplace.append("%_");
4454 		}
4455 
4456 		bool wasEscape = false;
4457 		for (sal_Int32 i = 0; i < nLen; i++)
4458 		{
4459 			const sal_Unicode c = aMatchStr[i];
4460 			// SQL standard requires the escape to be followed
4461 			// by a meta-character ('%', '_' or itself), else error
4462 			// We are more lenient here and let it escape anything.
4463 			// Especially since some databases (e.g. Microsoft SQL Server)
4464 			// have more meta-characters than the standard, such as e.g. '[' and ']'
4465 			if (wasEscape)
4466 			{
4467 				wasEscape=false;
4468 				continue;
4469 			}
4470 			if (c == cEscape)
4471 			{
4472 				wasEscape=true;
4473 				continue;
4474 			}
4475 			int match = -1;
4476 			if (c == sSearch[0])
4477 				match=0;
4478 			else if (c == sSearch[1])
4479 				match=1;
4480 
4481 			if (match != -1)
4482 			{
4483 				aMatchStr[i] = sReplace[match];
4484 			}
4485 		}
4486 	}
4487 	return aMatchStr.makeStringAndClear();
4488 }
4489 
4490 sal_uInt32			    OSQLParser::s_nRuleIDs[OSQLParseNode::rule_count + 1];
4491 OSQLParser::RuleIDMap   OSQLParser::s_aReverseRuleIDLookup;
4492 OParseContext		    OSQLParser::s_aDefaultContext;
4493 
4494 sal_Int32			OSQLParser::s_nRefCount	= 0;
4495 //	::osl::Mutex		OSQLParser::s_aMutex;
4496 OSQLScanner*		OSQLParser::s_pScanner = nullptr;
4497 OSQLParseNodesGarbageCollector*		OSQLParser::s_pGarbageCollector = nullptr;
4498 css::uno::Reference< css::i18n::XLocaleData4>  OSQLParser::s_xLocaleData = nullptr;
4499 
setParser(OSQLParser * _pParser)4500 void setParser(OSQLParser* _pParser)
4501 {
4502 	xxx_pGLOBAL_SQLPARSER = _pParser;
4503 }
4504 
setParseTree(OSQLParseNode * pNewParseTree)4505 void OSQLParser::setParseTree(OSQLParseNode* pNewParseTree)
4506 {
4507 	::osl::MutexGuard aGuard(getMutex());
4508 	m_pParseTree.reset(pNewParseTree);
4509 }
4510 
4511 
4512 /** Delete all comments in a query.
4513 
4514     See also getComment()/concatComment() implementation for
4515     OQueryController::translateStatement().
4516  */
delComment(const OUString & rQuery)4517 static OUString delComment( const OUString& rQuery )
4518 {
4519     // First a quick search if there is any "--" or "//" or "/*", if not then the whole
4520     // copying loop is pointless.
4521     if (rQuery.indexOf("--") < 0 && rQuery.indexOf("//") < 0 &&
4522             rQuery.indexOf("/*") < 0)
4523         return rQuery;
4524 
4525     const sal_Unicode* pCopy = rQuery.getStr();
4526     sal_Int32 nQueryLen = rQuery.getLength();
4527     bool bIsText1  = false;     // "text"
4528     bool bIsText2  = false;     // 'text'
4529     bool bComment2 = false;     // /* comment */
4530     bool bComment  = false;     // -- or // comment
4531     OUStringBuffer aBuf(nQueryLen);
4532     for (sal_Int32 i=0; i < nQueryLen; ++i)
4533     {
4534         if (bComment2)
4535         {
4536             if ((i+1) < nQueryLen)
4537             {
4538                 if (pCopy[i]=='*' && pCopy[i+1]=='/')
4539                 {
4540                     bComment2 = false;
4541                     ++i;
4542                 }
4543             }
4544             else
4545             {
4546                 // comment can't close anymore, actually an error, but...
4547             }
4548             continue;
4549         }
4550         if (pCopy[i] == '\n')
4551             bComment = false;
4552         else if (!bComment)
4553         {
4554             if (pCopy[i] == '\"' && !bIsText2)
4555                 bIsText1 = !bIsText1;
4556             else if (pCopy[i] == '\'' && !bIsText1)
4557                 bIsText2 = !bIsText2;
4558             if (!bIsText1 && !bIsText2 && (i+1) < nQueryLen)
4559             {
4560                 if ((pCopy[i]=='-' && pCopy[i+1]=='-') || (pCopy[i]=='/' && pCopy[i+1]=='/'))
4561                     bComment = true;
4562                 else if ((pCopy[i]=='/' && pCopy[i+1]=='*'))
4563                     bComment2 = true;
4564             }
4565         }
4566         if (!bComment && !bComment2)
4567             aBuf.append( &pCopy[i], 1);
4568     }
4569     return aBuf.makeStringAndClear();
4570 }
4571 
parseTree(OUString & rErrorMessage,const OUString & rStatement,bool bInternational)4572 std::unique_ptr<OSQLParseNode> OSQLParser::parseTree(OUString& rErrorMessage,
4573                                      const OUString& rStatement,
4574                                      bool bInternational)
4575 {
4576 
4577 
4578 	// Guard the parsing
4579 	::osl::MutexGuard aGuard(getMutex());
4580 	// must be reset
4581 	setParser(this);
4582 
4583 	// delete comments before parsing
4584 	OUString sTemp = delComment(rStatement);
4585 
4586 	// defines how to scan
4587 	s_pScanner->SetRule(OSQLScanner::GetSQLRule()); // initial
4588 	s_pScanner->prepareScan(sTemp, m_pContext, bInternational);
4589 
4590 	SQLyylval.pParseNode = nullptr;
4591 	//	SQLyypvt = NULL;
4592 	m_pParseTree = nullptr;
4593 	m_sErrorMessage = "";
4594 
4595     // start parsing
4596 	if (SQLyyparse() != 0)
4597 	{
4598 		// only set the error message, if it's not already set
4599 		if (m_sErrorMessage.isEmpty())
4600 			m_sErrorMessage = s_pScanner->getErrorMessage();
4601 		if (m_sErrorMessage.isEmpty())
4602 			m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ErrorCode::General);
4603 
4604 		rErrorMessage = m_sErrorMessage;
4605 
4606 		// clear the garbage collector
4607 		(*s_pGarbageCollector)->clearAndDelete();
4608 		m_pParseTree.release(); // because the garbage collector deleted it
4609 		return nullptr;
4610 	}
4611 	else
4612 	{
4613 		(*s_pGarbageCollector)->clear();
4614 
4615         // return result:
4616         // to work around a bug in MKS YACC return the member m_pParseTree
4617         // instead of Sdbyyval.pParseNode
4618 
4619         SAL_WARN_IF(!m_pParseTree, "connectivity.parse",
4620             "OSQLParser: Parser did not create ParseTree");
4621 		return std::move(m_pParseTree);
4622 	}
4623 }
4624 
TokenIDToStr(sal_uInt32 nTokenID,const IParseContext * pContext)4625 OString OSQLParser::TokenIDToStr(sal_uInt32 nTokenID, const IParseContext* pContext)
4626 {
4627 	OString aStr;
4628 	if (pContext)
4629 	{
4630 		IParseContext::InternationalKeyCode eKeyCode = IParseContext::InternationalKeyCode::None;
4631 		switch( nTokenID )
4632 		{
4633 			case SQL_TOKEN_LIKE: eKeyCode = IParseContext::InternationalKeyCode::Like; break;
4634 			case SQL_TOKEN_NOT: eKeyCode = IParseContext::InternationalKeyCode::Not; break;
4635 			case SQL_TOKEN_NULL: eKeyCode = IParseContext::InternationalKeyCode::Null; break;
4636 			case SQL_TOKEN_TRUE: eKeyCode = IParseContext::InternationalKeyCode::True; break;
4637 			case SQL_TOKEN_FALSE: eKeyCode = IParseContext::InternationalKeyCode::False; break;
4638 			case SQL_TOKEN_IS: eKeyCode = IParseContext::InternationalKeyCode::Is; break;
4639 			case SQL_TOKEN_BETWEEN: eKeyCode = IParseContext::InternationalKeyCode::Between; break;
4640 			case SQL_TOKEN_OR: eKeyCode = IParseContext::InternationalKeyCode::Or; break;
4641 			case SQL_TOKEN_AND: eKeyCode = IParseContext::InternationalKeyCode::And; break;
4642 			case SQL_TOKEN_AVG: eKeyCode = IParseContext::InternationalKeyCode::Avg; break;
4643 			case SQL_TOKEN_COUNT: eKeyCode = IParseContext::InternationalKeyCode::Count; break;
4644 			case SQL_TOKEN_MAX: eKeyCode = IParseContext::InternationalKeyCode::Max; break;
4645 			case SQL_TOKEN_MIN: eKeyCode = IParseContext::InternationalKeyCode::Min; break;
4646 			case SQL_TOKEN_SUM: eKeyCode = IParseContext::InternationalKeyCode::Sum; break;
4647 		}
4648 		if ( eKeyCode != IParseContext::InternationalKeyCode::None )
4649 		    aStr = pContext->getIntlKeywordAscii(eKeyCode);
4650 	}
4651 
4652 	if (aStr.isEmpty())
4653 	{
4654 		aStr = yytname[YYTRANSLATE(nTokenID)];
4655 		if(aStr.startsWith("SQL_TOKEN_"))
4656 			aStr = aStr.copy(10);
4657 		switch( nTokenID )
4658 		{
4659 			case SQL_TOKEN_OJ:
4660 			case SQL_TOKEN_TS:
4661 			case SQL_TOKEN_T:
4662 			case SQL_TOKEN_D:
4663 				aStr = aStr.toAsciiLowerCase();
4664 		}
4665 	}
4666 	return aStr;
4667 }
4668 
4669 #if OSL_DEBUG_LEVEL > 0
RuleIDToStr(sal_uInt32 nRuleID)4670 OUString OSQLParser::RuleIDToStr(sal_uInt32 nRuleID)
4671 {
4672 	OSL_ENSURE(nRuleID < SAL_N_ELEMENTS(yytname), "OSQLParser::RuleIDToStr: Invalid nRuleId!");
4673 	return OUString::createFromAscii(yytname[nRuleID]);
4674 }
4675 #endif
4676 
4677 
StrToRuleID(const OString & rValue)4678 sal_uInt32 OSQLParser::StrToRuleID(const OString & rValue)
4679 {
4680 	// Search for the given name in yytname and return the index
4681 	// (or UNKNOWN_RULE, if not found)
4682 	static sal_uInt32 nLen = SAL_N_ELEMENTS(yytname);
4683 	for (sal_uInt32 i = YYTRANSLATE(SQL_TOKEN_INVALIDSYMBOL); i < (nLen-1); i++)
4684 	{
4685 		if (rValue == yytname[i])
4686 			return i;
4687 	}
4688 
4689 	// Not found
4690 	return OSQLParseNode::UNKNOWN_RULE;
4691 }
4692 
4693 
RuleIDToRule(sal_uInt32 _nRule)4694 OSQLParseNode::Rule OSQLParser::RuleIDToRule( sal_uInt32 _nRule )
4695 {
4696     OSQLParser::RuleIDMap::const_iterator i (s_aReverseRuleIDLookup.find(_nRule));
4697     if (i == s_aReverseRuleIDLookup.end())
4698     {
4699         SAL_INFO("connectivity.parse",
4700 		 "connectivity::OSQLParser::RuleIDToRule cannot reverse-lookup rule. "
4701 		 "Reverse mapping incomplete? "
4702 		 "_nRule='" << _nRule << "' "
4703 		 "yytname[_nRule]='" << yytname[_nRule] << "'");
4704         return OSQLParseNode::UNKNOWN_RULE;
4705     }
4706     else
4707         return i->second;
4708 }
4709 
4710 
RuleID(OSQLParseNode::Rule eRule)4711 sal_uInt32 OSQLParser::RuleID(OSQLParseNode::Rule eRule)
4712 {
4713 	return s_nRuleIDs[(sal_uInt16)eRule];
4714 }
4715 
buildNode(OSQLParseNode * & pAppend,OSQLParseNode * pCompare,OSQLParseNode * pLiteral,OSQLParseNode * pLiteral2)4716 sal_Int16 OSQLParser::buildNode(OSQLParseNode*& pAppend,OSQLParseNode* pCompare,OSQLParseNode* pLiteral,OSQLParseNode* pLiteral2)
4717 {
4718 	OSQLParseNode* pColumnRef = new OSQLInternalNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
4719 	pColumnRef->append(new OSQLInternalNode(m_sFieldName,SQLNodeType::Name));
4720 	OSQLParseNode* pComp = nullptr;
4721 	if ( SQL_ISTOKEN( pCompare, BETWEEN) && pLiteral2 )
4722 		pComp = new OSQLInternalNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::between_predicate_part_2));
4723 	else
4724 		pComp = new OSQLInternalNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::comparison_predicate));
4725 
4726 	pComp->append(pColumnRef);
4727 	pComp->append(pCompare);
4728 	pComp->append(pLiteral);
4729 	if ( pLiteral2 )
4730 	{
4731 		pComp->append(new OSQLInternalNode("", SQLNodeType::Keyword,SQL_TOKEN_AND));
4732 		pComp->append(pLiteral2);
4733 	}
4734 	pAppend->append(pComp);
4735 	return 1;
4736 }
4737 
buildStringNodes(OSQLParseNode * & pLiteral)4738 sal_Int16 OSQLParser::buildStringNodes(OSQLParseNode*& pLiteral)
4739 {
4740 	if(!pLiteral)
4741 		return 1;
4742 
4743 	if(SQL_ISRULE(pLiteral,set_fct_spec) || SQL_ISRULE(pLiteral,general_set_fct) || SQL_ISRULE(pLiteral,column_ref)
4744 		|| SQL_ISRULE(pLiteral,subquery))
4745 		return 1; // here I have a function that I can't transform into a string
4746 
4747 	if(pLiteral->getNodeType() == SQLNodeType::IntNum || pLiteral->getNodeType() == SQLNodeType::ApproxNum || pLiteral->getNodeType() == SQLNodeType::AccessDate)
4748 	{
4749 		OSQLParseNode* pParent = pLiteral->getParent();
4750 
4751 		OSQLParseNode* pNewNode = new OSQLInternalNode(pLiteral->getTokenValue(), SQLNodeType::String);
4752 		pParent->replace(pLiteral, pNewNode);
4753 		delete pLiteral;
4754 		pLiteral = nullptr;
4755 		return 1;
4756 	}
4757 
4758 	for(size_t i=0;i<pLiteral->count();++i)
4759 	{
4760 		OSQLParseNode* pChild = pLiteral->getChild(i);
4761 		buildStringNodes(pChild);
4762 	}
4763 	if(SQL_ISRULE(pLiteral,term) || SQL_ISRULE(pLiteral,value_exp_primary))
4764 	{
4765 		m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ErrorCode::InvalidCompare);
4766 		return 0;
4767 	}
4768 	return 1;
4769 }
4770 
buildComparisonRule(OSQLParseNode * & pAppend,OSQLParseNode * pLiteral)4771 sal_Int16 OSQLParser::buildComparisonRule(OSQLParseNode*& pAppend,OSQLParseNode* pLiteral)
4772 {
4773     OSQLParseNode* pComp = new OSQLInternalNode("=", SQLNodeType::Equal);
4774     return buildPredicateRule(pAppend,pLiteral,pComp);
4775 }
4776 
4777 
4778 
reduceLiteral(OSQLParseNode * & pLiteral,bool bAppendBlank)4779 void OSQLParser::reduceLiteral(OSQLParseNode*& pLiteral, bool bAppendBlank)
4780 {
4781 	OSL_ENSURE(pLiteral->isRule(), "This is no Rule");
4782 	OSL_ENSURE(pLiteral->count() == 2, "OSQLParser::ReduceLiteral() Invalid count");
4783 	OSQLParseNode* pTemp = pLiteral;
4784 	OUStringBuffer aValue(pLiteral->getChild(0)->getTokenValue());
4785 	if (bAppendBlank)
4786 	{
4787 		aValue.append(" ");
4788 	}
4789 
4790 	aValue.append(pLiteral->getChild(1)->getTokenValue());
4791 
4792 	pLiteral = new OSQLInternalNode(aValue.makeStringAndClear(),SQLNodeType::String);
4793 	delete pTemp;
4794 }
4795 
4796 
error(const char * fmt)4797 void OSQLParser::error(const char *fmt)
4798 {
4799 	if(m_sErrorMessage.isEmpty())
4800 	{
4801 		OUString sStr(fmt,strlen(fmt),RTL_TEXTENCODING_UTF8);
4802 		OUString sSQL_TOKEN("SQL_TOKEN_");
4803 
4804 		sal_Int32 nPos1 = sStr.indexOf(sSQL_TOKEN);
4805 		if(nPos1 != -1)
4806 		{
4807 			OUString sFirst  = sStr.copy(0,nPos1);
4808 			sal_Int32 nPos2 = sStr.indexOf(sSQL_TOKEN,nPos1+1);
4809 			if(nPos2 != -1)
4810 			{
4811 				OUString sSecond = sStr.copy(nPos1+sSQL_TOKEN.getLength(),nPos2-nPos1-sSQL_TOKEN.getLength());
4812 				sFirst  += sSecond;
4813 				sFirst  += sStr.copy(nPos2+sSQL_TOKEN.getLength());
4814 			}
4815 			else
4816 				sFirst += sStr.copy(nPos1+sSQL_TOKEN.getLength());
4817 
4818 			m_sErrorMessage = sFirst;
4819 		}
4820 		else
4821 			m_sErrorMessage = sStr;
4822 
4823 		OUString aError = s_pScanner->getErrorMessage();
4824 		if(!aError.isEmpty())
4825 		{
4826 			m_sErrorMessage += ", ";
4827 			m_sErrorMessage += aError;
4828 		}
4829 	}
4830 }
4831 
SQLlex()4832 int OSQLParser::SQLlex()
4833 {
4834 	return OSQLScanner::SQLlex();
4835 }
4836