build fix
[LibreOffice.git] / connectivity / source / parse / sqlbison.y
blob460804bc73183a64bc0aff8d030fe4353d43f11b
1 %glr-parser
2 %token-table
3 %{
4 /*
5 * This file is part of the LibreOffice project.
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 * This file incorporates work covered by the following license notice:
13 * Licensed to the Apache Software Foundation (ASF) under one or more
14 * contributor license agreements. See the NOTICE file distributed
15 * with this work for additional information regarding copyright
16 * ownership. The ASF licenses this file to you under the Apache
17 * License, Version 2.0 (the "License"); you may not use this file
18 * except in compliance with the License. You may obtain a copy of
19 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <vector>
23 #include <string.h>
25 #include <connectivity/sqlnode.hxx>
26 #include <connectivity/sqlparse.hxx>
27 #include <connectivity/sqlbison_exports.hxx>
28 #include <connectivity/sqlscan.hxx>
29 #include <connectivity/internalnode.hxx>
30 #include <com/sun/star/lang/Locale.hpp>
31 #include <com/sun/star/sdbc/DataType.hpp>
32 #include <com/sun/star/util/Date.hpp>
33 #include <com/sun/star/util/DateTime.hpp>
34 #include <com/sun/star/util/Time.hpp>
35 #include <com/sun/star/util/XNumberFormatter.hpp>
36 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
37 #include <com/sun/star/util/XNumberFormats.hpp>
38 #include <com/sun/star/util/NumberFormat.hpp>
39 #include <com/sun/star/util/XNumberFormatTypes.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/i18n/KParseType.hpp>
42 #include <com/sun/star/i18n/KParseTokens.hpp>
44 #include <osl/diagnose.h>
45 #include "connectivity/dbconversion.hxx"
46 #include <rtl/ustrbuf.hxx>
47 #include <sal/macros.h>
49 #if defined _MSC_VER
50 #pragma warning(push, 1)
51 #pragma warning(disable:4273 4701)
52 #endif
54 #ifdef __GNUC__
55 # pragma GCC diagnostic ignored "-Wwrite-strings"
56 # pragma GCC diagnostic ignored "-Wunused-function"
57 #endif
59 inline connectivity::OSQLInternalNode* newNode(const sal_Char* pNewValue,
60 const connectivity::SQLNodeType eNodeType,
61 const sal_uInt32 nNodeID = 0);
63 inline connectivity::OSQLInternalNode* newNode(const OString& _NewValue,
64 const connectivity::SQLNodeType eNodeType,
65 const sal_uInt32 nNodeID = 0);
67 inline connectivity::OSQLInternalNode* newNode(const OUString& _NewValue,
68 const connectivity::SQLNodeType eNodeType,
69 const sal_uInt32 nNodeID = 0);
72 // yyi is the internal number of the rule that is currently being reduced
73 // This can be mapped to external rule number via the yyrmap.
74 #define SQL_NEW_RULE newNode("", SQLNodeType::Rule, yyr1[yyn])
75 #define SQL_NEW_LISTRULE newNode("", SQLNodeType::ListRule, yyr1[yyn])
76 #define SQL_NEW_COMMALISTRULE newNode("", SQLNodeType::CommaListRule, yyr1[yyn])
79 extern connectivity::OSQLParser* xxx_pGLOBAL_SQLPARSER;
81 #if !(defined MACOSX && defined PPC)
82 #define YYERROR_VERBOSE
83 #endif
85 #define SQLyyerror(s) \
86 { \
87 xxx_pGLOBAL_SQLPARSER->error(s); \
90 using namespace connectivity;
91 #define SQLyylex xxx_pGLOBAL_SQLPARSER->SQLlex
93 /* symbolic tokens */
95 %union {
96 connectivity::OSQLParseNode * pParseNode;
98 %type <pParseNode> '(' ')' ',' ':' ';' '?' '[' ']' '{' '}' '.' 'K' 'M' 'G' 'T' 'P'
100 %token <pParseNode> SQL_TOKEN_STRING SQL_TOKEN_ACCESS_DATE SQL_TOKEN_INT SQL_TOKEN_REAL_NUM
101 %token <pParseNode> SQL_TOKEN_INTNUM SQL_TOKEN_APPROXNUM SQL_TOKEN_NOT SQL_TOKEN_NAME
104 %nonassoc <pParseNode> SQL_TOKEN_UMINUS
108 /* literal keyword tokens */
110 %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
112 %token <pParseNode> SQL_TOKEN_BETWEEN SQL_TOKEN_BIT SQL_TOKEN_BOTH SQL_TOKEN_BY
114 %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
115 %token <pParseNode> SQL_TOKEN_CURRENT SQL_TOKEN_CURSOR
117 %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
118 %token <pParseNode> SQL_TOKEN_DISTINCT SQL_TOKEN_DOUBLE SQL_TOKEN_DROP
120 %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
122 %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
124 %left <pParseNode> SQL_TOKEN_JOIN
125 %token <pParseNode> SQL_TOKEN_KEY SQL_TOKEN_LEADING SQL_TOKEN_LIKE SQL_TOKEN_LOCAL SQL_TOKEN_LOWER
126 %token <pParseNode> SQL_TOKEN_MAX SQL_TOKEN_MIN SQL_TOKEN_NATURAL SQL_TOKEN_NCHAR SQL_TOKEN_NULL SQL_TOKEN_NUMERIC
128 %token <pParseNode> SQL_TOKEN_OCTET_LENGTH SQL_TOKEN_OF SQL_TOKEN_ON SQL_TOKEN_OPTION SQL_TOKEN_ORDER SQL_TOKEN_OUTER
130 %token <pParseNode> SQL_TOKEN_PRECISION SQL_TOKEN_PRIMARY SQL_TOKEN_PRIVILEGES SQL_TOKEN_PROCEDURE SQL_TOKEN_PUBLIC
131 %token <pParseNode> SQL_TOKEN_REAL SQL_TOKEN_REFERENCES SQL_TOKEN_ROLLBACK
133 %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
135 %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
136 %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
137 %token <pParseNode> SQL_TOKEN_WHERE SQL_TOKEN_WITH SQL_TOKEN_WORK SQL_TOKEN_ZONE
139 /* ODBC KEYWORDS */
140 %token <pParseNode> SQL_TOKEN_CALL SQL_TOKEN_D SQL_TOKEN_FN SQL_TOKEN_T SQL_TOKEN_TS SQL_TOKEN_OJ
141 /* string functions */
142 %token <pParseNode> SQL_TOKEN_ASCII SQL_TOKEN_BIT_LENGTH SQL_TOKEN_CHAR SQL_TOKEN_CHAR_LENGTH SQL_TOKEN_SQL_TOKEN_INTNUM
143 %token <pParseNode> SQL_TOKEN_CONCAT
144 %token <pParseNode> SQL_TOKEN_DIFFERENCE SQL_TOKEN_INSERT SQL_TOKEN_LCASE SQL_TOKEN_LEFT SQL_TOKEN_LENGTH SQL_TOKEN_LOCATE
145 %token <pParseNode> SQL_TOKEN_LOCATE_2 SQL_TOKEN_LTRIM SQL_TOKEN_POSITION SQL_TOKEN_REPEAT SQL_TOKEN_REPLACE
146 %token <pParseNode> SQL_TOKEN_RIGHT SQL_TOKEN_RTRIM SQL_TOKEN_SOUNDEX SQL_TOKEN_SPACE SQL_TOKEN_SUBSTRING SQL_TOKEN_UCASE
148 /* time and date functions */
149 %token <pParseNode> SQL_TOKEN_CURRENT_DATE SQL_TOKEN_CURRENT_TIME SQL_TOKEN_CURRENT_TIMESTAMP SQL_TOKEN_CURDATE SQL_TOKEN_CURTIME
150 %token <pParseNode> SQL_TOKEN_DAYNAME SQL_TOKEN_DAYOFMONTH SQL_TOKEN_DAYOFWEEK SQL_TOKEN_DAYOFYEAR SQL_TOKEN_EXTRACT
151 %token <pParseNode> SQL_TOKEN_HOUR SQL_TOKEN_MINUTE SQL_TOKEN_MONTH SQL_TOKEN_MONTHNAME SQL_TOKEN_NOW SQL_TOKEN_QUARTER SQL_TOKEN_DATEDIFF
152 %token <pParseNode> SQL_TOKEN_SECOND SQL_TOKEN_TIMESTAMPADD SQL_TOKEN_TIMESTAMPDIFF SQL_TOKEN_TIMEVALUE SQL_TOKEN_WEEK SQL_TOKEN_YEAR
154 /* numeric functions */
155 %token <pParseNode> SQL_TOKEN_ABS SQL_TOKEN_ACOS SQL_TOKEN_ASIN SQL_TOKEN_ATAN SQL_TOKEN_ATAN2 SQL_TOKEN_CEILING
156 %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
157 %token <pParseNode> SQL_TOKEN_LOG10 SQL_TOKEN_MOD SQL_TOKEN_PI SQL_TOKEN_POWER SQL_TOKEN_RADIANS SQL_TOKEN_RAND SQL_TOKEN_ROUNDMAGIC
158 %token <pParseNode> SQL_TOKEN_ROUND SQL_TOKEN_SIGN SQL_TOKEN_SIN SQL_TOKEN_SQRT SQL_TOKEN_TAN SQL_TOKEN_TRUNCATE
160 // computational operation
161 %token <pParseNode> SQL_TOKEN_EVERY SQL_TOKEN_INTERSECTION SQL_TOKEN_FUSION SQL_TOKEN_COLLECT SQL_TOKEN_VAR_POP SQL_TOKEN_VAR_SAMP
162 %token <pParseNode> SQL_TOKEN_STDDEV_SAMP SQL_TOKEN_STDDEV_POP
164 %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
165 %token <pParseNode> SQL_TOKEN_CASE SQL_TOKEN_THEN SQL_TOKEN_END SQL_TOKEN_NULLIF SQL_TOKEN_COALESCE SQL_TOKEN_WHEN SQL_TOKEN_ELSE
166 %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
167 %token <pParseNode> SQL_TOKEN_NEW SQL_TOKEN_OLD
168 %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
169 %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
170 %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
171 // window function
172 %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
173 %token <pParseNode> SQL_TOKEN_FIRST_VALUE SQL_TOKEN_LAST_VALUE SQL_TOKEN_NTH_VALUE SQL_TOKEN_FIRST SQL_TOKEN_LAST
174 %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
175 %token <pParseNode> SQL_TOKEN_PARTITION SQL_TOKEN_WINDOW SQL_TOKEN_NO
176 // LIMIT and OFFSEt
177 %token <pParseNode> SQL_TOKEN_LIMIT SQL_TOKEN_OFFSET SQL_TOKEN_NEXT SQL_TOKEN_ONLY
179 /* operators */
180 %left SQL_TOKEN_NAME
181 %left <pParseNode> SQL_TOKEN_OR
182 %left <pParseNode> SQL_TOKEN_AND
184 %left <pParseNode> SQL_LESSEQ SQL_GREATEQ SQL_NOTEQUAL SQL_LESS SQL_GREAT SQL_EQUAL /* '<' '>' = <> < > <= >= != */
185 %left <pParseNode> '+' '-' SQL_CONCAT
186 %left <pParseNode> '*' '/'
187 %left SQL_TOKEN_NATURAL SQL_TOKEN_CROSS SQL_TOKEN_FULL SQL_TOKEN_LEFT SQL_TOKEN_RIGHT
188 %left ')'
189 %right '='
190 %right '.'
191 %right '('
194 %token <pParseNode> SQL_TOKEN_INVALIDSYMBOL
196 /*%type <pParseNode> sql_single_statement */
198 %type <pParseNode> sql /*schema */
199 %type <pParseNode> column_def_opt_list column_def_opt table_constraint_def column_commalist
200 %type <pParseNode> view_def opt_with_check_option opt_column_commalist privilege_def
201 %type <pParseNode> opt_with_grant_option privileges operation_commalist operation
202 %type <pParseNode> grantee_commalist grantee opt_order_by_clause ordering_spec_commalist
203 %type <pParseNode> ordering_spec opt_asc_desc manipulative_statement commit_statement
204 %type <pParseNode> /*delete_statement_positioned*/ delete_statement_searched fetch_statement
205 %type <pParseNode> insert_statement values_or_query_spec
206 %type <pParseNode> rollback_statement select_statement_into opt_all_distinct
207 %type <pParseNode> /*update_statement_positioned*/ assignment_commalist assignment
208 %type <pParseNode> update_statement_searched target_commalist target opt_where_clause
209 %type <pParseNode> select_statement selection table_exp from_clause table_ref_commalist table_ref
210 %type <pParseNode> where_clause opt_group_by_clause column_ref_commalist opt_having_clause
211 %type <pParseNode> search_condition predicate comparison_predicate comparison_predicate_part_2 between_predicate between_predicate_part_2
212 %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
213 %type <pParseNode> all_or_any_predicate any_all_some existence_test subquery quantified_comparison_predicate_part_2
214 %type <pParseNode> scalar_exp_commalist parameter_ref literal parenthesized_boolean_value_expression
215 %type <pParseNode> column_ref data_type column cursor parameter range_variable user /*like_check*/
216 /* neue Regeln bei OJ */
217 %type <pParseNode> derived_column as_clause table_name num_primary term num_value_exp
218 %type <pParseNode> value_exp_primary num_value_fct unsigned_value_spec cast_spec set_fct_spec scalar_subquery
219 %type <pParseNode> position_exp extract_exp length_exp general_value_spec
220 %type <pParseNode> general_set_fct set_fct_type query_exp non_join_query_exp joined_table
221 %type <pParseNode> non_join_query_term non_join_query_primary simple_table
222 %type <pParseNode> table_value_const_list row_value_constructor /*row_value_const_list*/ row_value_constructor_elem
223 %type <pParseNode> qualified_join value_exp query_term join_type outer_join_type join_condition boolean_term
224 %type <pParseNode> boolean_factor boolean_primary named_columns_join join_spec
225 %type <pParseNode> cast_operand cast_target factor datetime_value_exp /*interval_value_exp*/ datetime_term datetime_factor
226 %type <pParseNode> datetime_primary datetime_value_fct time_zone time_zone_specifier /*interval_term*/ interval_qualifier
227 %type <pParseNode> start_field non_second_datetime_field end_field single_datetime_field extract_field datetime_field time_zone_field
228 %type <pParseNode> char_length_exp octet_length_exp bit_length_exp select_sublist string_value_exp
229 %type <pParseNode> char_value_exp concatenation char_factor char_primary string_value_fct char_substring_fct fold
230 %type <pParseNode> form_conversion char_translation trim_fct trim_operands trim_spec bit_value_fct bit_substring_fct op_column_commalist
231 %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
232 %type <pParseNode> function_arg_commalist3 string_function_3Argument function_arg_commalist4 string_function_4Argument function_arg_commalist2 string_function_1Argument string_function_2Argument
233 %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
234 %type <pParseNode> all query_primary sql_not for_length upper_lower comparison column_val cross_union /*opt_schema_element_list*/
235 %type <pParseNode> /*op_authorization op_schema*/ nil_fkt schema_element base_table_def base_table_element base_table_element_commalist
236 %type <pParseNode> column_def odbc_fct_spec odbc_call_spec odbc_fct_type op_parameter union_statement
237 %type <pParseNode> op_odbc_call_parameter odbc_parameter_commalist odbc_parameter function_args_commalist function_arg
238 %type <pParseNode> catalog_name schema_name table_node numeric_function string_function function_name date_function table_primary_as_range_column opt_as
239 %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
240 %type <pParseNode> case_expression else_clause result_expression result case_abbreviation case_specification searched_when_clause simple_when_clause searched_case simple_case
241 %type <pParseNode> when_operand_list when_operand case_operand
242 %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
243 %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
244 %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
245 %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
246 %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
247 %type <pParseNode> approximate_numeric_type exact_numeric_type opt_paren_precision_scale
248 /* window function rules */
249 %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
250 %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
251 %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
252 %type <pParseNode> new_window_name window_specification_details existing_window_name window_partition_clause window_partition_column_reference_list window_partition_column_reference window_frame_clause
253 %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
254 %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
255 %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
256 /* LIMIT and OFFSET */
257 %type <pParseNode> opt_limit_offset_clause limit_offset_clause opt_fetch_first_clause
260 /* Parse Tree an OSQLParser zurueckliefern
261 * (der Zugriff ueber yyval nach Aufruf des Parsers scheitert,
264 sql_single_statement:
266 { xxx_pGLOBAL_SQLPARSER->setParseTree( $1 ); }
267 | sql ';'
268 { xxx_pGLOBAL_SQLPARSER->setParseTree( $1 ); }
271 /* schema definition language */
272 /* Note: other ``sql:sal_Unicode() rules appear later in the grammar */
274 sql:
275 manipulative_statement
276 | schema_element
278 $$ = SQL_NEW_RULE;
279 $$->append($1);
283 /***
285 op_authorization:
286 {$$ = SQL_NEW_RULE;}
287 | SQL_TOKEN_AUTHORIZATION user
289 $$ = SQL_NEW_RULE;
290 $$->append($1);
291 $$->append($2);
294 op_schema:
295 {$$ = SQL_NEW_RULE;}
296 | SQL_TOKEN_NAME
297 | SQL_TOKEN_NAME '.' SQL_TOKEN_NAME
299 $$ = SQL_NEW_RULE;
300 $$->append($1);
301 $$->append(newNode(".", SQLNodeType::Punctuation));
302 $$->append($3);
306 schema:
307 SQL_TOKEN_CREATE SQL_TOKEN_SCHEMA op_schema op_authorization opt_schema_element_list
309 $$ = SQL_NEW_RULE;
310 $$->append($1);
311 $$->append($2);
312 $$->append($3);
313 $$->append($4);
314 $$->append($5);
318 opt_schema_element_list:
319 {$$ = SQL_NEW_RULE;}
320 | schema_glement_list
323 schema_element_list:
324 schema_element
325 {$$ = SQL_NEW_LISTRULE;
326 $$->append($1);}
327 | schema_element_list schema_element
328 {$1->append($2);
329 $$ = $1;}
333 schema_element:
334 base_table_def
335 | view_def
336 | privilege_def
337 | trigger_definition
340 base_table_def:
341 SQL_TOKEN_CREATE SQL_TOKEN_TABLE table_node '(' base_table_element_commalist ')'
342 {$$ = SQL_NEW_RULE;
343 $$->append($1);
344 $$->append($2);
345 $$->append($3);
346 $$->append(newNode("(", SQLNodeType::Punctuation));
347 $$->append($5);
348 $$->append(newNode(")", SQLNodeType::Punctuation));}
351 base_table_element_commalist:
352 base_table_element
353 {$$ = SQL_NEW_COMMALISTRULE;
354 $$->append($1);}
355 | base_table_element_commalist ',' base_table_element
356 {$1->append($3);
357 $$ = $1;}
360 base_table_element:
361 column_def
362 | table_constraint_def
365 column_def:
366 column data_type column_def_opt_list
367 {$$ = SQL_NEW_RULE;
368 $$->append($1);
369 $$->append($2);
370 $$->append($3);
374 column_def_opt_list:
375 /* empty */ {$$ = SQL_NEW_LISTRULE;}
376 | column_def_opt_list column_def_opt
377 {$1->append($2);
378 $$ = $1;}
381 nil_fkt:
382 datetime_value_fct
384 unique_spec:
385 SQL_TOKEN_UNIQUE
386 | SQL_TOKEN_PRIMARY SQL_TOKEN_KEY
388 $$ = SQL_NEW_RULE;
389 $$->append($1);
390 $$->append($2);
393 column_def_opt:
394 SQL_TOKEN_NOT SQL_TOKEN_NULL
395 {$$ = SQL_NEW_RULE;
396 $$->append($1);
397 $$->append($2);}
398 | unique_spec
399 | SQL_TOKEN_DEFAULT literal
400 {$$ = SQL_NEW_RULE;
401 $$->append($1);
402 $$->append($2);}
403 | SQL_TOKEN_DEFAULT SQL_TOKEN_NULL
404 {$$ = SQL_NEW_RULE;
405 $$->append($1);
406 $$->append($2);}
407 | SQL_TOKEN_DEFAULT SQL_TOKEN_USER
408 {$$ = SQL_NEW_RULE;
409 $$->append($1);
410 $$->append($2);}
411 | SQL_TOKEN_DEFAULT nil_fkt
413 $$ = SQL_NEW_RULE;
414 $$->append($1);
415 $$->append($2);
417 | SQL_TOKEN_CHECK
418 | SQL_TOKEN_CHECK '(' search_condition ')'
419 {$$ = SQL_NEW_RULE;
420 $$->append($1);
421 $$->append(newNode("(", SQLNodeType::Punctuation));
422 $$->append($3);
423 $$->append(newNode(")", SQLNodeType::Punctuation));}
424 | SQL_TOKEN_REFERENCES table_node
425 {$$ = SQL_NEW_RULE;
426 $$->append($1);
427 $$->append($2);}
428 | SQL_TOKEN_REFERENCES table_node '(' column_commalist ')'
429 {$$ = SQL_NEW_RULE;
430 $$->append($1);
431 $$->append($2);
432 $$->append(newNode("(", SQLNodeType::Punctuation));
433 $$->append($4);
434 $$->append(newNode(")", SQLNodeType::Punctuation));}
437 table_constraint_def:
438 unique_spec '(' column_commalist ')'
439 {$$ = SQL_NEW_RULE;
440 $$->append($1);
441 $$->append(newNode("(", SQLNodeType::Punctuation));
442 $$->append($3);
443 $$->append(newNode(")", SQLNodeType::Punctuation));}
444 | SQL_TOKEN_FOREIGN SQL_TOKEN_KEY '(' column_commalist ')' SQL_TOKEN_REFERENCES table_node
445 {$$ = SQL_NEW_RULE;
446 $$->append($1);
447 $$->append($2);
448 $$->append(newNode("(", SQLNodeType::Punctuation));
449 $$->append($4);
450 $$->append(newNode(")", SQLNodeType::Punctuation));
451 $$->append($6);
452 $$->append($7);}
453 | SQL_TOKEN_FOREIGN SQL_TOKEN_KEY '(' column_commalist ')' SQL_TOKEN_REFERENCES table_node '(' column_commalist ')'
454 {$$ = SQL_NEW_RULE;
455 $$->append($1);
456 $$->append($2);
457 $$->append(newNode("(", SQLNodeType::Punctuation));
458 $$->append($4);
459 $$->append(newNode(")", SQLNodeType::Punctuation));
460 $$->append($6);
461 $$->append($7);
462 $$->append(newNode("(", SQLNodeType::Punctuation));
463 $$->append($9);
464 $$->append(newNode(")", SQLNodeType::Punctuation));}
465 | SQL_TOKEN_CHECK '(' search_condition ')'
466 {$$ = SQL_NEW_RULE;
467 $$->append($1);
468 $$->append(newNode("(", SQLNodeType::Punctuation));
469 $$->append($3);
470 $$->append(newNode(")", SQLNodeType::Punctuation));}
472 op_column_commalist:
473 /* empty */ {$$ = SQL_NEW_RULE;}
474 | '(' column_commalist ')'
475 {$$ = SQL_NEW_RULE;
476 $$->append(newNode("(", SQLNodeType::Punctuation));
477 $$->append($2);
478 $$->append(newNode(")", SQLNodeType::Punctuation));
481 column_commalist:
482 column_commalist ',' column
483 {$1->append($3);
484 $$ = $1;}
485 | column
486 {$$ = SQL_NEW_COMMALISTRULE;
487 $$->append($1);}
490 view_def:
491 SQL_TOKEN_CREATE SQL_TOKEN_VIEW table_node opt_column_commalist SQL_TOKEN_AS select_statement opt_with_check_option
492 {$$ = SQL_NEW_RULE;
493 $$->append($1);
494 $$->append($2);
495 $$->append($3);
496 $$->append($4);
497 $$->append($5);
498 $$->append($6);
499 $$->append($7);}
502 opt_with_check_option:
503 /* empty */ {$$ = SQL_NEW_RULE;}
504 | SQL_TOKEN_WITH SQL_TOKEN_CHECK SQL_TOKEN_OPTION
505 {$$ = SQL_NEW_RULE;
506 $$->append($1);
507 $$->append($2);
508 $$->append($3);}
511 opt_column_commalist:
512 /* empty */ {$$ = SQL_NEW_RULE;}
513 | '(' column_commalist ')'
514 {$$ = SQL_NEW_RULE;
515 $$->append(newNode("(", SQLNodeType::Punctuation));
516 $$->append($2);
517 $$->append(newNode(")", SQLNodeType::Punctuation));}
520 privilege_def:
521 SQL_TOKEN_GRANT privileges SQL_TOKEN_ON table_node SQL_TOKEN_TO grantee_commalist
522 opt_with_grant_option
523 {$$ = SQL_NEW_RULE;
524 $$->append($1);
525 $$->append($2);
526 $$->append($3);
527 $$->append($4);
528 $$->append($5);
529 $$->append($6);
530 $$->append($7);}
533 opt_with_grant_option:
534 /* empty */ {$$ = SQL_NEW_RULE;}
535 | SQL_TOKEN_WITH SQL_TOKEN_GRANT SQL_TOKEN_OPTION
536 {$$ = SQL_NEW_RULE;
537 $$->append($1);
538 $$->append($2);
539 $$->append($3);}
542 privileges:
543 SQL_TOKEN_ALL SQL_TOKEN_PRIVILEGES
544 {$$ = SQL_NEW_RULE;
545 $$->append($1);
546 $$->append($2);}
547 | operation_commalist
550 operation_commalist:
551 operation
552 {$$ = SQL_NEW_COMMALISTRULE;
553 $$->append($1);}
554 | operation_commalist ',' operation
555 {$1->append($3);
556 $$ = $1;}
559 operation:
560 SQL_TOKEN_SELECT
561 | SQL_TOKEN_INSERT opt_column_commalist
562 {$$ = SQL_NEW_RULE;
563 $$->append($1);
564 $$->append($2);}
565 | SQL_TOKEN_DELETE
566 | SQL_TOKEN_UPDATE opt_column_commalist
567 {$$ = SQL_NEW_RULE;
568 $$->append($1);
569 $$->append($2);}
570 | SQL_TOKEN_REFERENCES opt_column_commalist
571 {$$ = SQL_NEW_RULE;
572 $$->append($1);
573 $$->append($2);}
574 | SQL_TOKEN_USAGE
578 grantee_commalist:
579 grantee
580 {$$ = SQL_NEW_COMMALISTRULE;
581 $$->append($1);}
582 | grantee_commalist ',' grantee
583 {$1->append($3);
584 $$ = $1;}
587 grantee:
588 SQL_TOKEN_PUBLIC
589 | user
592 /* module language */
594 opt_order_by_clause:
595 /* empty */ {$$ = SQL_NEW_RULE;}
596 | SQL_TOKEN_ORDER SQL_TOKEN_BY ordering_spec_commalist
597 {$$ = SQL_NEW_RULE;
598 $$->append($1);
599 $$->append($2);
600 $$->append($3);}
603 ordering_spec_commalist:
604 ordering_spec
605 {$$ = SQL_NEW_COMMALISTRULE;
606 $$->append($1);}
607 | ordering_spec_commalist ',' ordering_spec
608 {$1->append($3);
609 $$ = $1;}
612 ordering_spec:
613 /* SQL_TOKEN_INTNUM opt_asc_desc
614 {$$ = SQL_NEW_RULE;
615 $$->append($1);
616 $$->append($2);}
618 predicate opt_asc_desc
619 {$$ = SQL_NEW_RULE;
620 $$->append($1);
621 $$->append($2);}
623 | row_value_constructor_elem opt_asc_desc
624 {$$ = SQL_NEW_RULE;
625 $$->append($1);
626 $$->append($2);}
629 opt_asc_desc:
630 {$$ = SQL_NEW_RULE;}
631 | SQL_TOKEN_ASC
632 | SQL_TOKEN_DESC
636 /***
637 manipulative_statement_list:
638 manipulative_statement
639 {$$ = SQL_NEW_LISTRULE;
640 $$->append($1);}
641 | manipulative_statement_list manipulative_statement
642 {$1->append($2);
643 $$ = $1;}
645 ***/
647 sql_not:
648 /* vide */
649 {$$ = SQL_NEW_RULE;}
650 | SQL_TOKEN_NOT
653 /* manipulative statements */
655 manipulative_statement:
656 commit_statement
657 /* | delete_statement_positioned*/
658 | delete_statement_searched
659 | fetch_statement
660 | insert_statement
661 | rollback_statement
662 | select_statement_into
663 /* | update_statement_positioned*/
664 | update_statement_searched
665 | union_statement
666 | '{' odbc_call_spec '}'
668 $$ = SQL_NEW_RULE;
669 $$->append(newNode("{", SQLNodeType::Punctuation));
670 $$->append($2);
671 $$->append(newNode("}", SQLNodeType::Punctuation));
675 union_statement:
676 select_statement
677 | union_statement SQL_TOKEN_UNION all select_statement
679 $$ = SQL_NEW_RULE;
680 $$->append($1);
681 $$->append($2);
682 $$->append($3);
683 $$->append($4);
686 commit_statement:
687 SQL_TOKEN_COMMIT SQL_TOKEN_WORK
688 {$$ = SQL_NEW_RULE;
689 $$->append($1);
690 $$->append($2);}
693 delete_statement_positioned:
694 SQL_TOKEN_DELETE SQL_TOKEN_FROM table_node SQL_TOKEN_WHERE SQL_TOKEN_CURRENT SQL_TOKEN_OF cursor
695 {$$ = SQL_NEW_RULE;
696 $$->append($1);
697 $$->append($2);
698 $$->append($3);
699 $$->append($4);
700 $$->append($5);
701 $$->append($6);
702 $$->append($7);}
705 delete_statement_searched:
706 SQL_TOKEN_DELETE SQL_TOKEN_FROM table_node opt_where_clause
707 {$$ = SQL_NEW_RULE;
708 $$->append($1);
709 $$->append($2);
710 $$->append($3);
711 $$->append($4);}
714 fetch_statement:
715 SQL_TOKEN_FETCH cursor SQL_TOKEN_INTO target_commalist
716 {$$ = SQL_NEW_RULE;
717 $$->append($1);
718 $$->append($2);
719 $$->append($3);
720 $$->append($4);}
723 insert_statement:
724 SQL_TOKEN_INSERT SQL_TOKEN_INTO table_node opt_column_commalist query_exp
725 {$$ = SQL_NEW_RULE;
726 $$->append($1);
727 $$->append($2);
728 $$->append($3);
729 $$->append($4);
730 $$->append($5);}
732 values_or_query_spec:
733 SQL_TOKEN_VALUES '(' table_value_const_list ')'
734 {$$ = SQL_NEW_RULE;
735 $$->append($1);
736 $$->append(newNode("(", SQLNodeType::Punctuation));
737 $$->append($3);
738 $$->append(newNode(")", SQLNodeType::Punctuation));
742 table_value_const_list:
743 row_value_constructor
744 {$$ = SQL_NEW_COMMALISTRULE;
745 $$->append($1);}
746 | table_value_const_list ',' row_value_constructor
747 {$1->append($3);
748 $$ = $1;}
751 row_value_const_list:
752 row_value_constructor_elem
753 {$$ = SQL_NEW_COMMALISTRULE;
754 $$->append($1);}
755 | row_value_const_list ',' row_value_constructor_elem
756 {$1->append($3);
757 $$ = $1;}
760 row_value_constructor:
761 row_value_constructor_elem
762 /* | '(' row_value_const_list ')'
764 $$ = SQL_NEW_RULE;
765 $$->append(newNode("(", SQLNodeType::Punctuation));
766 $$->append($2);
767 $$->append(newNode(")", SQLNodeType::Punctuation));
771 row_value_constructor_elem:
772 value_exp /*[^')']*/
773 | SQL_TOKEN_DEFAULT
777 rollback_statement:
778 SQL_TOKEN_ROLLBACK SQL_TOKEN_WORK
779 {$$ = SQL_NEW_RULE;
780 $$->append($1);
781 $$->append($2);}
785 /* INTO target_commalist herausgenommen */
786 select_statement_into:
787 SQL_TOKEN_SELECT opt_all_distinct selection SQL_TOKEN_INTO target_commalist table_exp
788 {$$ = SQL_NEW_RULE;
789 $$->append($1);
790 $$->append($2);
791 $$->append($3);
792 $$->append($4);
793 $$->append($5);
794 $$->append($6); }
797 opt_all_distinct:
798 {$$ = SQL_NEW_RULE;}
799 | SQL_TOKEN_ALL
800 | SQL_TOKEN_DISTINCT
804 update_statement_positioned:
805 SQL_TOKEN_UPDATE table_node SQL_TOKEN_SET assignment_commalist
806 SQL_TOKEN_WHERE SQL_TOKEN_CURRENT SQL_TOKEN_OF cursor
807 {$$ = SQL_NEW_RULE;
808 $$->append($1);
809 $$->append($2);
810 $$->append($3);
811 $$->append($4);
812 $$->append($5);
813 $$->append($6);
814 $$->append($7);
815 $$->append($8);}
818 assignment_commalist:
819 assignment
820 {$$ = SQL_NEW_COMMALISTRULE;
821 $$->append($1);}
822 | assignment_commalist ',' assignment
823 {$1->append($3);
824 $$ = $1;}
827 assignment:
828 column SQL_EQUAL update_source
829 {$$ = SQL_NEW_RULE;
830 $$->append($1);
831 $$->append($2);
832 $$->append($3);}
834 update_source:
835 value_exp
836 | SQL_TOKEN_DEFAULT
838 update_statement_searched:
839 SQL_TOKEN_UPDATE table_node SQL_TOKEN_SET assignment_commalist opt_where_clause
840 {$$ = SQL_NEW_RULE;
841 $$->append($1);
842 $$->append($2);
843 $$->append($3);
844 $$->append($4);
845 $$->append($5);}
848 target_commalist:
849 target
850 {$$ = SQL_NEW_COMMALISTRULE;
851 $$->append($1);}
852 | target_commalist ',' target
853 {$1->append($3);
854 $$ = $1;}
857 target:
858 parameter_ref
861 opt_where_clause:
862 /* empty */ {$$ = SQL_NEW_RULE;}
863 | where_clause
866 /* query expressions */
868 query_term:
869 non_join_query_term
871 $$ = SQL_NEW_RULE;
872 $$->append($1);
875 /* SELECT STATEMENT */
876 select_statement:
877 SQL_TOKEN_SELECT opt_all_distinct selection table_exp
879 $$ = SQL_NEW_RULE;
880 $$->append($1);
881 $$->append($2);
882 $$->append($3);
883 $$->append($4);
887 selection:
890 $$ = SQL_NEW_RULE;
891 $$->append(newNode("*", SQLNodeType::Punctuation));
893 | scalar_exp_commalist
895 opt_result_offset_clause:
896 /* empty */ {$$ = SQL_NEW_RULE;}
897 | result_offset_clause
899 result_offset_clause:
900 SQL_TOKEN_OFFSET offset_row_count row_or_rows
902 $$ = SQL_NEW_RULE;
903 $$->append($1);
904 $$->append($2);
905 $$->append($3);
908 opt_fetch_first_row_count:
909 /* empty */ {$$ = SQL_NEW_RULE;}
910 | fetch_first_row_count
912 first_or_next:
913 SQL_TOKEN_FIRST
914 | SQL_TOKEN_NEXT
916 row_or_rows:
917 SQL_TOKEN_ROW
918 | SQL_TOKEN_ROWS
920 opt_fetch_first_clause:
921 /* empty */ {$$ = SQL_NEW_RULE;}
922 | fetch_first_clause
924 fetch_first_clause:
925 SQL_TOKEN_FETCH first_or_next opt_fetch_first_row_count row_or_rows SQL_TOKEN_ONLY
927 $$ = SQL_NEW_RULE;
928 $$->append($1);
929 $$->append($2);
930 $$->append($3);
931 $$->append($4);
932 $$->append($5);
935 offset_row_count:
936 literal
938 fetch_first_row_count:
939 literal
942 opt_limit_offset_clause:
943 /* empty */ {$$ = SQL_NEW_RULE;}
944 | limit_offset_clause
946 opt_offset:
947 /* empty */ {$$ = SQL_NEW_RULE;}
948 | SQL_TOKEN_OFFSET SQL_TOKEN_INTNUM
950 $$ = SQL_NEW_RULE;
951 $$->append($1);
952 $$->append($2);
955 limit_offset_clause:
956 SQL_TOKEN_LIMIT SQL_TOKEN_INTNUM opt_offset
958 $$ = SQL_NEW_RULE;
959 $$->append($1);
960 $$->append($2);
961 $$->append($3);
964 table_exp:
965 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
967 $$ = SQL_NEW_RULE;
968 $$->append($1);
969 $$->append($2);
970 $$->append($3);
971 $$->append($4);
972 $$->append($5);
973 $$->append($6);
974 $$->append($7);
975 $$->append($8);
976 $$->append($9);
980 from_clause:
981 SQL_TOKEN_FROM table_ref_commalist
982 { $$ = SQL_NEW_RULE;
983 $$->append($1);
984 $$->append($2); }
987 table_ref_commalist:
989 table_ref
990 { $$ = SQL_NEW_COMMALISTRULE;
991 $$->append($1); }
992 | table_ref_commalist ',' table_ref
993 { $1->append($3);
994 $$ = $1; }
997 opt_as:
998 /* empty */ {$$ = SQL_NEW_RULE;}
999 | SQL_TOKEN_AS
1001 opt_row:
1002 /* empty */ {$$ = SQL_NEW_RULE;}
1003 | SQL_TOKEN_ROW
1005 table_primary_as_range_column:
1006 {$$ = SQL_NEW_RULE;}
1007 | opt_as SQL_TOKEN_NAME op_column_commalist
1009 $$ = SQL_NEW_RULE;
1010 $$->append($1);
1011 $$->append($2);
1012 $$->append($3);
1015 table_ref:
1016 table_node table_primary_as_range_column
1018 $$ = SQL_NEW_RULE;
1019 $$->append($1);
1020 $$->append($2);
1022 | subquery range_variable op_column_commalist
1024 $$ = SQL_NEW_RULE;
1025 $$->append($1);
1026 $$->append($2);
1027 $$->append($3);
1029 | joined_table
1030 | '{' SQL_TOKEN_OJ joined_table '}'
1032 $$ = SQL_NEW_RULE;
1033 $$->append(newNode("{", SQLNodeType::Punctuation));
1034 $$->append($2);
1035 $$->append($3);
1036 $$->append(newNode("}", SQLNodeType::Punctuation));
1038 | '(' joined_table ')'
1040 $$ = SQL_NEW_RULE;
1041 $$->append(newNode("(", SQLNodeType::Punctuation));
1042 $$->append($2);
1043 $$->append(newNode(")", SQLNodeType::Punctuation));
1046 where_clause:
1047 SQL_TOKEN_WHERE search_condition
1048 {$$ = SQL_NEW_RULE;
1049 $$->append($1);
1050 $$->append($2);}
1053 opt_group_by_clause:
1054 /* empty */ {$$ = SQL_NEW_RULE;}
1055 | SQL_TOKEN_GROUP SQL_TOKEN_BY column_ref_commalist
1056 {$$ = SQL_NEW_RULE;
1057 $$->append($1);
1058 $$->append($2);
1059 $$->append($3);}
1062 column_ref_commalist:
1063 column_ref
1064 {$$ = SQL_NEW_COMMALISTRULE;
1065 $$->append($1);}
1066 | set_fct_spec
1067 {$$ = SQL_NEW_COMMALISTRULE;
1068 $$->append($1);}
1069 | column_ref_commalist ',' column_ref
1070 {$1->append($3);
1071 $$ = $1;}
1072 | column_ref_commalist ',' set_fct_spec
1073 {$1->append($3);
1074 $$ = $1;}
1077 opt_having_clause:
1078 /* empty */ {$$ = SQL_NEW_RULE;}
1079 | SQL_TOKEN_HAVING search_condition
1080 {$$ = SQL_NEW_RULE;
1081 $$->append($1);
1082 $$->append($2);}
1085 /* search conditions */
1086 boolean_primary:
1087 predicate
1088 | '(' search_condition ')'
1089 { // boolean_primary: rule 2
1090 $$ = SQL_NEW_RULE;
1091 $$->append(newNode("(", SQLNodeType::Punctuation));
1092 $$->append($2);
1093 $$->append(newNode(")", SQLNodeType::Punctuation));
1095 | row_value_constructor_elem /*[^')' ',']*/
1097 if(xxx_pGLOBAL_SQLPARSER->inPredicateCheck())// boolean_primary: rule 3
1099 $$ = SQL_NEW_RULE;
1100 sal_Int16 nErg = 0;
1101 if ( SQL_ISTOKEN( $1, NULL))
1103 OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1104 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1105 OSQLParseNode* pTFN = new OSQLInternalNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::test_for_null));
1106 pTFN->append(pColumnRef);
1108 OSQLParseNode* pNPP2 = new OSQLInternalNode("", SQLNodeType::Rule, OSQLParser::RuleID(OSQLParseNode::null_predicate_part_2));
1109 pNPP2->append(new OSQLInternalNode("", SQLNodeType::Keyword, SQL_TOKEN_IS));
1110 pNPP2->append(new OSQLInternalNode("", SQLNodeType::Rule, OSQLParser::RuleID(OSQLParseNode::sql_not)));
1111 pNPP2->append(new OSQLInternalNode("", SQLNodeType::Keyword, SQL_TOKEN_NULL));
1112 pTFN->append(pNPP2);
1114 $$->append(pTFN);
1116 nErg = 1;
1118 else
1120 nErg = xxx_pGLOBAL_SQLPARSER->buildComparsionRule($$,$1);
1122 if(nErg == 1)
1124 OSQLParseNode* pTemp = $$;
1125 $$ = pTemp->removeAt((sal_uInt32)0);
1126 delete pTemp;
1128 else
1130 delete $$;
1131 if(nErg)
1132 YYERROR;
1133 else
1134 YYABORT;
1137 else
1138 YYERROR;
1141 parenthesized_boolean_value_expression:
1142 '(' search_condition ')'
1143 { // boolean_primary: rule 2
1144 $$ = SQL_NEW_RULE;
1145 $$->append(newNode("(", SQLNodeType::Punctuation));
1146 $$->append($2);
1147 $$->append(newNode(")", SQLNodeType::Punctuation));
1150 boolean_factor:
1151 boolean_primary %dprec 2
1152 | SQL_TOKEN_NOT boolean_primary %dprec 1
1153 { // boolean_factor: rule 1
1154 $$ = SQL_NEW_RULE;
1155 $$->append($1);
1156 $$->append($2);
1159 boolean_term:
1160 boolean_factor
1161 | boolean_term SQL_TOKEN_AND boolean_factor
1163 $$ = SQL_NEW_RULE; // boolean_term: rule 1
1164 $$->append($1);
1165 $$->append($2);
1166 $$->append($3);
1169 search_condition:
1170 boolean_term
1171 | search_condition SQL_TOKEN_OR boolean_term
1173 $$ = SQL_NEW_RULE; // search_condition
1174 $$->append($1);
1175 $$->append($2);
1176 $$->append($3);
1179 predicate:
1180 comparison_predicate %dprec 1
1181 | between_predicate
1182 | all_or_any_predicate
1183 | existence_test
1184 | unique_test
1185 | test_for_null %dprec 2
1186 | in_predicate
1187 | like_predicate
1189 comparison_predicate_part_2:
1190 comparison row_value_constructor
1192 $$ = SQL_NEW_RULE; // comparison_predicate: rule 1
1193 $$->append($1);
1194 $$->append($2);
1196 comparison_predicate:
1197 row_value_constructor comparison row_value_constructor
1199 $$ = SQL_NEW_RULE; // comparison_predicate: rule 1
1200 $$->append($1);
1201 $$->append($2);
1202 $$->append($3);
1204 | comparison row_value_constructor
1206 if(xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // comparison_predicate: rule 2
1208 $$ = SQL_NEW_RULE;
1209 sal_Int16 nErg = xxx_pGLOBAL_SQLPARSER->buildPredicateRule($$,$2,$1);
1210 if(nErg == 1)
1212 OSQLParseNode* pTemp = $$;
1213 $$ = pTemp->removeAt((sal_uInt32)0);
1214 delete pTemp;
1216 else
1218 delete $$;
1219 YYABORT;
1222 else
1224 YYERROR;
1228 comparison:
1229 SQL_LESS
1230 | SQL_NOTEQUAL
1231 | SQL_EQUAL
1232 | SQL_GREAT
1233 | SQL_LESSEQ
1234 | SQL_GREATEQ
1235 | SQL_TOKEN_IS sql_not SQL_TOKEN_DISTINCT SQL_TOKEN_FROM
1237 $$ = SQL_NEW_RULE;
1238 $$->append($1);
1239 $$->append($2);
1240 $$->append($3);
1241 $$->append($4);
1243 | SQL_TOKEN_IS sql_not
1245 $$ = SQL_NEW_RULE;
1246 $$->append($1);
1247 $$->append($2);
1250 between_predicate_part_2:
1251 sql_not SQL_TOKEN_BETWEEN row_value_constructor SQL_TOKEN_AND row_value_constructor
1253 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // between_predicate: rule 2
1255 $$ = SQL_NEW_RULE;
1257 sal_Int16 nErg = xxx_pGLOBAL_SQLPARSER->buildPredicateRule($$,$3,$2,$5);
1258 if(nErg == 1)
1260 OSQLParseNode* pTemp = $$;
1261 $$ = pTemp->removeAt((sal_uInt32)0);
1262 OSQLParseNode* pColumnRef = $$->removeAt((sal_uInt32)0);
1263 $$->insert(0,$1);
1264 OSQLParseNode* pBetween_predicate = new OSQLInternalNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::between_predicate));
1265 pBetween_predicate->append(pColumnRef);
1266 pBetween_predicate->append($$);
1267 $$ = pBetween_predicate;
1269 delete pTemp;
1270 delete $4;
1272 else
1274 delete $$;
1275 YYABORT;
1278 else
1280 $$ = SQL_NEW_RULE; // between_predicate: rule 1
1281 $$->append($1);
1282 $$->append($2);
1283 $$->append($3);
1284 $$->append($4);
1285 $$->append($5);
1288 between_predicate:
1289 row_value_constructor between_predicate_part_2
1291 $$ = SQL_NEW_RULE; // between_predicate: rule 1
1292 $$->append($1);
1293 $$->append($2);
1295 | between_predicate_part_2
1297 character_like_predicate_part_2:
1298 sql_not SQL_TOKEN_LIKE string_value_exp opt_escape
1300 $$ = SQL_NEW_RULE; // like_predicate: rule 1
1301 $$->append($1);
1302 $$->append($2);
1303 $$->append($3);
1304 $$->append($4);
1307 other_like_predicate_part_2:
1308 sql_not SQL_TOKEN_LIKE value_exp_primary opt_escape
1310 $$ = SQL_NEW_RULE; // like_predicate: rule 1
1311 $$->append($1);
1312 $$->append($2);
1313 $$->append($3);
1314 $$->append($4);
1317 like_predicate:
1318 row_value_constructor character_like_predicate_part_2
1320 $$ = SQL_NEW_RULE; // like_predicate: rule 1
1321 $$->append($1);
1322 $$->append($2);
1324 | row_value_constructor other_like_predicate_part_2
1326 $$ = SQL_NEW_RULE; // like_predicate: rule 3
1327 $$->append($1);
1328 $$->append($2);
1330 | character_like_predicate_part_2
1332 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // like_predicate: rule 5
1334 OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1335 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1337 $$ = SQL_NEW_RULE;
1338 $$->append(pColumnRef);
1339 $$->append($1);
1340 OSQLParseNode* p2nd = $1->removeAt(2);
1341 OSQLParseNode* p3rd = $1->removeAt(2);
1342 if ( !xxx_pGLOBAL_SQLPARSER->buildLikeRule($1,p2nd,p3rd) )
1344 delete $$;
1345 YYABORT;
1347 $1->append(p3rd);
1349 else
1350 YYERROR;
1352 | other_like_predicate_part_2
1354 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // like_predicate: rule 6
1356 OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1357 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1359 $$ = SQL_NEW_RULE;
1360 $$->append(pColumnRef);
1361 $$->append($1);
1362 OSQLParseNode* p2nd = $1->removeAt(2);
1363 OSQLParseNode* p3rd = $1->removeAt(2);
1364 if ( !xxx_pGLOBAL_SQLPARSER->buildLikeRule($1,p2nd,p3rd) )
1366 delete $$;
1367 YYABORT;
1369 $1->append(p3rd);
1371 else
1372 YYERROR;
1376 opt_escape:
1377 /* empty */ {$$ = SQL_NEW_RULE;}
1378 | SQL_TOKEN_ESCAPE string_value_exp
1379 {$$ = SQL_NEW_RULE;
1380 $$->append($1);
1381 $$->append($2);}
1382 | '{' SQL_TOKEN_ESCAPE SQL_TOKEN_STRING '}'
1384 $$ = SQL_NEW_RULE;
1385 $$->append(newNode("{", SQLNodeType::Punctuation));
1386 $$->append($2);
1387 $$->append($3);
1388 $$->append(newNode("}", SQLNodeType::Punctuation));
1392 null_predicate_part_2:
1393 SQL_TOKEN_IS sql_not SQL_TOKEN_NULL
1395 $$ = SQL_NEW_RULE; // test_for_null: rule 1
1396 $$->append($1);
1397 $$->append($2);
1398 $$->append($3);
1400 | SQL_TOKEN_IS sql_not SQL_TOKEN_UNKNOWN
1402 $$ = SQL_NEW_RULE; // test_for_null: rule 1
1403 $$->append($1);
1404 $$->append($2);
1405 $$->append($3);
1408 test_for_null:
1409 row_value_constructor null_predicate_part_2
1411 $$ = SQL_NEW_RULE; // test_for_null: rule 1
1412 $$->append($1);
1413 $$->append($2);
1415 | null_predicate_part_2
1417 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())// test_for_null: rule 2
1419 OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1420 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1422 $$ = SQL_NEW_RULE;
1423 $$->append(pColumnRef);
1424 $$->append($1);
1426 else
1427 YYERROR;
1430 in_predicate_value:
1431 subquery
1432 {$$ = SQL_NEW_RULE;
1433 $$->append($1);
1435 | '(' value_exp_commalist ')'
1436 {$$ = SQL_NEW_RULE;
1437 $$->append(newNode("(", SQLNodeType::Punctuation));
1438 $$->append($2);
1439 $$->append(newNode(")", SQLNodeType::Punctuation));
1442 in_predicate_part_2:
1443 sql_not SQL_TOKEN_IN in_predicate_value
1445 $$ = SQL_NEW_RULE;// in_predicate: rule 1
1446 $$->append($1);
1447 $$->append($2);
1448 $$->append($3);
1451 in_predicate:
1452 row_value_constructor in_predicate_part_2
1454 $$ = SQL_NEW_RULE;// in_predicate: rule 1
1455 $$->append($1);
1456 $$->append($2);
1458 | in_predicate_part_2
1460 if ( xxx_pGLOBAL_SQLPARSER->inPredicateCheck() )// in_predicate: rule 2
1462 OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1463 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1465 $$ = SQL_NEW_RULE;
1466 $$->append(pColumnRef);
1467 $$->append($1);
1469 else
1470 YYERROR;
1473 quantified_comparison_predicate_part_2:
1474 comparison any_all_some subquery
1476 $$ = SQL_NEW_RULE;
1477 $$->append($1);
1478 $$->append($2);
1479 $$->append($3);
1482 all_or_any_predicate:
1483 row_value_constructor quantified_comparison_predicate_part_2
1485 $$ = SQL_NEW_RULE;
1486 $$->append($1);
1487 $$->append($2);
1489 | quantified_comparison_predicate_part_2
1491 if(xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1493 OSQLParseNode* pColumnRef = newNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
1494 pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQLNodeType::Name));
1496 $$ = SQL_NEW_RULE;
1497 $$->append(pColumnRef);
1498 $$->append($1);
1500 else
1501 YYERROR;
1505 any_all_some:
1506 SQL_TOKEN_ANY
1507 | SQL_TOKEN_ALL
1508 | SQL_TOKEN_SOME
1511 existence_test:
1512 SQL_TOKEN_EXISTS subquery
1513 {$$ = SQL_NEW_RULE;
1514 $$->append($1);
1515 $$->append($2);}
1517 unique_test:
1518 SQL_TOKEN_UNIQUE subquery
1519 {$$ = SQL_NEW_RULE;
1520 $$->append($1);
1521 $$->append($2);}
1523 subquery:
1524 '(' query_exp ')'
1525 {$$ = SQL_NEW_RULE;
1526 $$->append(newNode("(", SQLNodeType::Punctuation));
1527 $$->append($2);
1528 $$->append(newNode(")", SQLNodeType::Punctuation));}
1531 /* scalar expressions */
1532 scalar_exp_commalist:
1533 select_sublist
1535 $$ = SQL_NEW_COMMALISTRULE;
1536 $$->append($1);
1538 | scalar_exp_commalist ',' select_sublist
1540 $1->append($3);
1541 $$ = $1;
1544 select_sublist:
1545 /* table_node '.' '*'
1547 $$ = SQL_NEW_RULE;
1548 $$->append($1);
1549 $$->append(newNode(".", SQLNodeType::Punctuation));
1550 $$->append(newNode("*", SQLNodeType::Punctuation));
1553 derived_column
1557 parameter_ref:
1558 parameter
1562 op_like:
1565 $$ = newNode("*", SQLNodeType::Punctuation);
1567 | '?'
1569 $$ = newNode("?", SQLNodeType::Punctuation);
1571 | op_like '*'
1573 $$ = SQL_NEW_RULE;
1574 $$->append($1);
1575 $$->append(newNode("*", SQLNodeType::Punctuation));
1576 xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_False);
1578 | op_like '?'
1580 $$ = SQL_NEW_RULE;
1581 $$->append($1);
1582 $$->append(newNode("?", SQLNodeType::Punctuation));
1583 xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_False);
1588 literal:
1589 /* SQL_TOKEN_STRING
1590 | */SQL_TOKEN_INT
1591 | SQL_TOKEN_REAL_NUM
1592 | SQL_TOKEN_INTNUM
1593 | SQL_TOKEN_APPROXNUM
1594 | SQL_TOKEN_ACCESS_DATE
1595 /* rules for predicate check */
1596 | literal SQL_TOKEN_STRING
1598 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1600 $$ = SQL_NEW_RULE;
1601 $$->append($1);
1602 $$->append($2);
1603 xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_True);
1605 else
1606 YYERROR;
1608 | literal SQL_TOKEN_INT
1610 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1612 $$ = SQL_NEW_RULE;
1613 $$->append($1);
1614 $$->append($2);
1615 xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_True);
1617 else
1618 YYERROR;
1620 | literal SQL_TOKEN_REAL_NUM
1622 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1624 $$ = SQL_NEW_RULE;
1625 $$->append($1);
1626 $$->append($2);
1627 xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_True);
1629 else
1630 YYERROR;
1632 | literal SQL_TOKEN_APPROXNUM
1634 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
1636 $$ = SQL_NEW_RULE;
1637 $$->append($1);
1638 $$->append($2);
1639 xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_True);
1641 else
1642 YYERROR;
1646 /* miscellaneous */
1647 as_clause:
1648 /* empty */ {$$ = SQL_NEW_RULE;}
1649 | SQL_TOKEN_AS column
1651 $$ = SQL_NEW_RULE;
1652 $$->append($1);
1653 $$->append($2);
1655 | column
1657 position_exp:
1658 SQL_TOKEN_POSITION '(' value_exp SQL_TOKEN_IN value_exp ')'
1660 $$ = SQL_NEW_RULE;
1661 $$->append($1);
1662 $$->append(newNode("(", SQLNodeType::Punctuation));
1663 $$->append($3);
1664 $$->append($4);
1665 $$->append($5);
1666 $$->append(newNode(")", SQLNodeType::Punctuation));
1668 | SQL_TOKEN_POSITION '(' value_exp_commalist ')'
1670 $$ = SQL_NEW_RULE;
1671 $$->append($1);
1672 $$->append(newNode("(", SQLNodeType::Punctuation));
1673 $$->append($3);
1674 $$->append(newNode(")", SQLNodeType::Punctuation));
1677 num_value_fct:
1678 position_exp
1679 | extract_exp
1680 | length_exp
1682 char_length_exp:
1683 SQL_TOKEN_CHAR_LENGTH '(' value_exp ')'
1685 $$ = SQL_NEW_RULE;
1686 $$->append($1);
1687 $$->append(newNode("(", SQLNodeType::Punctuation));
1688 $$->append($3);
1689 $$->append(newNode(")", SQLNodeType::Punctuation));
1691 | SQL_TOKEN_SQL_TOKEN_INTNUM '(' value_exp ')'
1693 $$ = SQL_NEW_RULE;
1694 $$->append($1);
1695 $$->append(newNode("(", SQLNodeType::Punctuation));
1696 $$->append($3);
1697 $$->append(newNode(")", SQLNodeType::Punctuation));
1701 octet_length_exp:
1702 SQL_TOKEN_OCTET_LENGTH '(' value_exp ')'
1704 $$ = SQL_NEW_RULE;
1705 $$->append($1);
1706 $$->append(newNode("(", SQLNodeType::Punctuation));
1707 $$->append($3);
1708 $$->append(newNode(")", SQLNodeType::Punctuation));
1711 bit_length_exp:
1712 SQL_TOKEN_BIT_LENGTH '(' value_exp ')'
1714 $$ = SQL_NEW_RULE;
1715 $$->append($1);
1716 $$->append(newNode("(", SQLNodeType::Punctuation));
1717 $$->append($3);
1718 $$->append(newNode(")", SQLNodeType::Punctuation));
1721 length_exp:
1722 char_length_exp
1724 $$ = SQL_NEW_RULE;
1725 $$->append($1);
1727 | octet_length_exp
1729 $$ = SQL_NEW_RULE;
1730 $$->append($1);
1732 | bit_length_exp
1734 $$ = SQL_NEW_RULE;
1735 $$->append($1);
1738 datetime_field:
1739 non_second_datetime_field
1741 $$ = SQL_NEW_RULE;
1742 $$->append($1);
1744 | SQL_TOKEN_SECOND
1746 $$ = SQL_NEW_RULE;
1747 $$->append($1);
1750 extract_field:
1751 time_zone_field
1752 | datetime_field
1753 | value_exp
1755 time_zone_field:
1756 SQL_TOKEN_TIMEZONE_HOUR
1758 $$ = SQL_NEW_RULE;
1759 $$->append($1);
1761 | SQL_TOKEN_TIMEZONE_MINUTE
1763 $$ = SQL_NEW_RULE;
1764 $$->append($1);
1767 extract_exp:
1768 SQL_TOKEN_EXTRACT '(' extract_field SQL_TOKEN_FROM value_exp ')'
1770 $$ = SQL_NEW_RULE;
1771 $$->append($1);
1772 $$->append(newNode("(", SQLNodeType::Punctuation));
1773 $$->append($3);
1774 $$->append($4);
1775 $$->append($5);
1776 $$->append(newNode(")", SQLNodeType::Punctuation));
1779 unsigned_value_spec:
1780 general_value_spec
1781 | literal
1783 general_value_spec:
1784 parameter
1785 | SQL_TOKEN_USER
1786 | SQL_TOKEN_NULL
1787 | SQL_TOKEN_FALSE
1788 | SQL_TOKEN_TRUE
1789 | SQL_TOKEN_VALUE
1790 | SQL_TOKEN_CURRENT_CATALOG
1791 | SQL_TOKEN_CURRENT_DEFAULT_TRANSFORM_GROUP
1792 | SQL_TOKEN_CURRENT_PATH
1793 | SQL_TOKEN_CURRENT_ROLE
1794 | SQL_TOKEN_CURRENT_SCHEMA
1795 | SQL_TOKEN_CURRENT_USER
1796 | SQL_TOKEN_SESSION_USER
1797 | SQL_TOKEN_SYSTEM_USER
1799 set_fct_spec:
1800 general_set_fct
1801 | '{' odbc_fct_spec '}'
1803 $$ = SQL_NEW_RULE;
1804 $$->append(newNode("{", SQLNodeType::Punctuation));
1805 $$->append($2);
1806 $$->append(newNode("}", SQLNodeType::Punctuation));
1808 | function_name '(' ')'
1810 $$ = SQL_NEW_RULE;
1811 $$->append($1);
1812 $$->append(newNode("(", SQLNodeType::Punctuation));
1813 $$->append(newNode(")", SQLNodeType::Punctuation));
1815 | function_name0 '(' ')'
1817 $$ = SQL_NEW_RULE;
1818 $$->append($1);
1819 $$->append(newNode("(", SQLNodeType::Punctuation));
1820 $$->append(newNode(")", SQLNodeType::Punctuation));
1822 | function_name1 '(' function_arg ')'
1824 $$ = SQL_NEW_RULE;
1825 $$->append($1);
1826 $$->append(newNode("(", SQLNodeType::Punctuation));
1827 $$->append($3);
1828 $$->append(newNode(")", SQLNodeType::Punctuation));
1830 | function_name2 '(' function_arg_commalist2 ')'
1832 $$ = SQL_NEW_RULE;
1833 $$->append($1);
1834 $$->append(newNode("(", SQLNodeType::Punctuation));
1835 $$->append($3);
1836 $$->append(newNode(")", SQLNodeType::Punctuation));
1838 | function_name3 '(' function_arg_commalist3 ')'
1840 $$ = SQL_NEW_RULE;
1841 $$->append($1);
1842 $$->append(newNode("(", SQLNodeType::Punctuation));
1843 $$->append($3);
1844 $$->append(newNode(")", SQLNodeType::Punctuation));
1846 | string_function_4Argument '(' function_arg_commalist4 ')'
1848 $$ = SQL_NEW_RULE;
1849 $$->append($1);
1850 $$->append(newNode("(", SQLNodeType::Punctuation));
1851 $$->append($3);
1852 $$->append(newNode(")", SQLNodeType::Punctuation));
1854 | function_name '(' function_args_commalist ')'
1856 $$ = SQL_NEW_RULE;
1857 $$->append($1);
1858 $$->append(newNode("(", SQLNodeType::Punctuation));
1859 $$->append($3);
1860 $$->append(newNode(")", SQLNodeType::Punctuation));
1862 | function_name12 '(' function_args_commalist ')'
1864 if ( $3->count() == 1 || $3->count() == 2 )
1866 $$ = SQL_NEW_RULE;
1867 $$->append($1);
1868 $$->append(newNode("(", SQLNodeType::Punctuation));
1869 $$->append($3);
1870 $$->append(newNode(")", SQLNodeType::Punctuation));
1872 else
1873 YYERROR;
1875 | function_name23 '(' function_args_commalist ')'
1877 if ( $3->count() == 2 || $3->count() == 3)
1879 $$ = SQL_NEW_RULE;
1880 $$->append($1);
1881 $$->append(newNode("(", SQLNodeType::Punctuation));
1882 $$->append($3);
1883 $$->append(newNode(")", SQLNodeType::Punctuation));
1885 else
1886 YYERROR;
1889 function_name0:
1890 date_function_0Argument
1891 | numeric_function_0Argument
1893 function_name1:
1894 string_function_1Argument
1895 | date_function_1Argument
1896 | numeric_function_1Argument
1898 function_name2:
1899 string_function_2Argument
1900 | numeric_function_2Argument
1902 function_name12:
1903 SQL_TOKEN_ROUND
1904 | SQL_TOKEN_WEEK
1905 | SQL_TOKEN_LOGF
1906 | SQL_TOKEN_LOG
1908 function_name23:
1909 SQL_TOKEN_LOCATE
1910 | SQL_TOKEN_DATEDIFF
1912 function_name3:
1913 string_function_3Argument
1915 function_name:
1916 string_function
1917 | date_function
1918 | numeric_function
1919 | SQL_TOKEN_NAME
1921 string_function_1Argument:
1922 SQL_TOKEN_LENGTH
1923 | SQL_TOKEN_ASCII
1924 | SQL_TOKEN_LCASE
1925 | SQL_TOKEN_LTRIM
1926 | SQL_TOKEN_RTRIM
1927 | SQL_TOKEN_SPACE
1928 | SQL_TOKEN_UCASE
1931 string_function_2Argument:
1932 SQL_TOKEN_REPEAT
1933 | SQL_TOKEN_LEFT
1934 | SQL_TOKEN_RIGHT
1936 string_function_3Argument:
1937 SQL_TOKEN_REPLACE
1939 string_function_4Argument:
1940 SQL_TOKEN_INSERT
1943 string_function:
1944 SQL_TOKEN_CHAR
1945 | SQL_TOKEN_CONCAT
1946 | SQL_TOKEN_DIFFERENCE
1947 | SQL_TOKEN_LOCATE_2
1948 | SQL_TOKEN_SOUNDEX
1950 date_function_0Argument:
1951 SQL_TOKEN_CURDATE
1952 | SQL_TOKEN_CURTIME
1953 | SQL_TOKEN_NOW
1955 date_function_1Argument:
1956 SQL_TOKEN_DAYOFWEEK
1957 | SQL_TOKEN_DAYOFMONTH
1958 | SQL_TOKEN_DAYOFYEAR
1959 | SQL_TOKEN_MONTH
1960 | SQL_TOKEN_DAYNAME
1961 | SQL_TOKEN_MONTHNAME
1962 | SQL_TOKEN_QUARTER
1963 | SQL_TOKEN_HOUR
1964 | SQL_TOKEN_MINUTE
1965 | SQL_TOKEN_SECOND
1966 | SQL_TOKEN_YEAR
1967 | SQL_TOKEN_DAY
1968 | SQL_TOKEN_TIMEVALUE
1969 | SQL_TOKEN_DATEVALUE
1972 date_function:
1973 SQL_TOKEN_TIMESTAMPADD
1974 | SQL_TOKEN_TIMESTAMPDIFF
1976 numeric_function_0Argument:
1977 SQL_TOKEN_PI
1979 numeric_function_1Argument:
1980 SQL_TOKEN_ABS
1981 | SQL_TOKEN_ACOS
1982 | SQL_TOKEN_ASIN
1983 | SQL_TOKEN_ATAN
1984 | SQL_TOKEN_CEILING
1985 | SQL_TOKEN_COS
1986 | SQL_TOKEN_COT
1987 | SQL_TOKEN_DEGREES
1988 | SQL_TOKEN_FLOOR
1989 | SQL_TOKEN_SIGN
1990 | SQL_TOKEN_SIN
1991 | SQL_TOKEN_SQRT
1992 | SQL_TOKEN_TAN
1993 | SQL_TOKEN_EXP
1994 | SQL_TOKEN_LOG10
1995 | SQL_TOKEN_LN
1996 | SQL_TOKEN_RADIANS
1997 | SQL_TOKEN_ROUNDMAGIC
1999 numeric_function_2Argument:
2000 SQL_TOKEN_ATAN2
2001 | SQL_TOKEN_MOD
2002 | SQL_TOKEN_POWER
2004 numeric_function:
2005 SQL_TOKEN_RAND
2006 | SQL_TOKEN_TRUNCATE
2009 window_function:
2010 window_function_type SQL_TOKEN_OVER window_name_or_specification
2012 $$ = SQL_NEW_RULE;
2013 $$->append($1);
2014 $$->append($2);
2015 $$->append($3);
2018 window_function_type :
2019 rank_function_type '(' ')'
2021 $$ = SQL_NEW_RULE;
2022 $$->append($1);
2023 $$->append(newNode("(", SQLNodeType::Punctuation));
2024 $$->append(newNode(")", SQLNodeType::Punctuation));
2026 | SQL_TOKEN_ROW_NUMBER '(' ')'
2028 $$ = SQL_NEW_RULE;
2029 $$->append($1);
2030 $$->append(newNode("(", SQLNodeType::Punctuation));
2031 $$->append(newNode(")", SQLNodeType::Punctuation));
2033 | general_set_fct
2034 | ntile_function
2035 | lead_or_lag_function
2036 | first_or_last_value_function
2037 | nth_value_function
2039 ntile_function :
2040 SQL_TOKEN_NTILE '(' number_of_tiles ')'
2042 $$ = SQL_NEW_RULE;
2043 $$->append($1);
2044 $$->append(newNode("(", SQLNodeType::Punctuation));
2045 $$->append($3);
2046 $$->append(newNode(")", SQLNodeType::Punctuation));
2049 dynamic_parameter_specification:
2050 parameter
2052 simple_value_specification:
2053 literal
2055 number_of_tiles :
2056 simple_value_specification
2057 | dynamic_parameter_specification
2059 opt_lead_or_lag_function:
2060 /* empty */ {$$ = SQL_NEW_RULE;}
2061 | ',' offset
2063 $$ = SQL_NEW_RULE;
2064 $$->append(newNode(",", SQLNodeType::Punctuation));
2065 $$->append($2);
2067 | ',' offset ',' default_expression
2069 $$ = SQL_NEW_RULE;
2070 $$->append(newNode(",", SQLNodeType::Punctuation));
2071 $$->append($2);
2072 $$->append(newNode(",", SQLNodeType::Punctuation));
2073 $$->append($4);
2076 opt_null_treatment:
2077 /* empty */ {$$ = SQL_NEW_RULE;}
2078 | null_treatment
2081 lead_or_lag_function:
2082 lead_or_lag '(' lead_or_lag_extent opt_lead_or_lag_function ')' opt_null_treatment
2084 $$ = SQL_NEW_RULE;
2085 $$->append($1);
2086 $$->append(newNode("(", SQLNodeType::Punctuation));
2087 $$->append($3);
2088 $$->append($4);
2089 $$->append(newNode(")", SQLNodeType::Punctuation));
2090 $$->append($6);
2093 lead_or_lag:
2094 SQL_TOKEN_LEAD
2095 | SQL_TOKEN_LAG
2097 lead_or_lag_extent:
2098 value_exp
2100 offset:
2101 SQL_TOKEN_INTNUM
2103 default_expression:
2104 value_exp
2106 null_treatment:
2107 SQL_TOKEN_RESPECT SQL_TOKEN_NULLS
2108 | SQL_TOKEN_IGNORE SQL_TOKEN_NULLS
2110 first_or_last_value_function:
2111 first_or_last_value '(' value_exp ')' opt_null_treatment
2113 $$ = SQL_NEW_RULE;
2114 $$->append($1);
2115 $$->append(newNode("(", SQLNodeType::Punctuation));
2116 $$->append($3);
2117 $$->append(newNode(")", SQLNodeType::Punctuation));
2118 $$->append($5);
2121 first_or_last_value :
2122 SQL_TOKEN_FIRST_VALUE
2123 | SQL_TOKEN_LAST_VALUE
2125 opt_from_first_or_last:
2126 /* empty */ {$$ = SQL_NEW_RULE;}
2127 | from_first_or_last
2129 nth_value_function:
2130 SQL_TOKEN_NTH_VALUE '(' value_exp ',' nth_row ')' opt_from_first_or_last opt_null_treatment
2132 $$ = SQL_NEW_RULE;
2133 $$->append($1);
2134 $$->append(newNode("(", SQLNodeType::Punctuation));
2135 $$->append($3);
2136 $$->append(newNode(",", SQLNodeType::Punctuation));
2137 $$->append($5);
2138 $$->append(newNode(")", SQLNodeType::Punctuation));
2139 $$->append($7);
2140 $$->append($8);
2143 nth_row:
2144 simple_value_specification
2145 | dynamic_parameter_specification
2147 from_first_or_last:
2148 SQL_TOKEN_FROM SQL_TOKEN_FIRST
2150 $$ = SQL_NEW_RULE;
2151 $$->append($1);
2152 $$->append($2);
2154 | SQL_TOKEN_FROM SQL_TOKEN_LAST
2156 $$ = SQL_NEW_RULE;
2157 $$->append($1);
2158 $$->append($2);
2161 window_name:
2162 SQL_TOKEN_NAME
2164 window_name_or_specification:
2165 window_name
2166 | in_line_window_specification
2168 in_line_window_specification:
2169 window_specification
2171 opt_window_clause:
2172 /* empty */ {$$ = SQL_NEW_RULE;}
2173 | window_clause
2175 window_clause:
2176 SQL_TOKEN_WINDOW window_definition_list
2178 $$ = SQL_NEW_RULE;
2179 $$->append($1);
2180 $$->append($2);
2183 window_definition_list:
2184 window_definition_list ',' window_definition
2185 {$1->append($3);
2186 $$ = $1;}
2187 | window_definition
2188 {$$ = SQL_NEW_COMMALISTRULE;
2189 $$->append($1);}
2191 window_definition:
2192 new_window_name SQL_TOKEN_AS window_specification
2194 $$ = SQL_NEW_RULE;
2195 $$->append($1);
2196 $$->append($2);
2197 $$->append($3);
2200 new_window_name:
2201 window_name
2203 window_specification:
2204 '(' window_specification_details ')'
2206 $$ = SQL_NEW_RULE;
2207 $$->append(newNode("(", SQLNodeType::Punctuation));
2208 $$->append($2);
2209 $$->append(newNode(")", SQLNodeType::Punctuation));
2212 opt_existing_window_name:
2213 /* empty */ {$$ = SQL_NEW_RULE;}
2214 | existing_window_name
2216 opt_window_partition_clause:
2217 /* empty */ {$$ = SQL_NEW_RULE;}
2218 | window_partition_clause
2220 opt_window_frame_clause:
2221 /* empty */ {$$ = SQL_NEW_RULE;}
2222 | window_frame_clause
2224 window_specification_details:
2225 opt_existing_window_name
2226 opt_window_partition_clause
2227 opt_order_by_clause
2228 opt_window_frame_clause
2230 existing_window_name:
2231 window_name
2233 window_partition_clause:
2234 SQL_TOKEN_PARTITION SQL_TOKEN_BY window_partition_column_reference_list
2236 $$ = SQL_NEW_RULE;
2237 $$->append($1);
2238 $$->append($2);
2239 $$->append($3);
2242 window_partition_column_reference_list:
2243 window_partition_column_reference_list ',' window_partition_column_reference
2244 {$1->append($3);
2245 $$ = $1;}
2246 | window_partition_column_reference
2247 {$$ = SQL_NEW_COMMALISTRULE;
2248 $$->append($1);}
2250 window_partition_column_reference:
2251 column_ref opt_collate_clause
2253 $$ = SQL_NEW_RULE;
2254 $$->append($1);
2255 $$->append($2);
2258 opt_window_frame_exclusion:
2259 /* empty */ {$$ = SQL_NEW_RULE;}
2260 | window_frame_exclusion
2262 window_frame_clause:
2263 window_frame_units window_frame_extent opt_window_frame_exclusion
2265 $$ = SQL_NEW_RULE;
2266 $$->append($1);
2267 $$->append($2);
2268 $$->append($3);
2271 window_frame_units:
2272 SQL_TOKEN_ROWS
2273 | SQL_TOKEN_RANGE
2275 window_frame_extent:
2276 window_frame_start
2277 | window_frame_between
2279 window_frame_start:
2280 SQL_TOKEN_UNBOUNDED SQL_TOKEN_PRECEDING
2282 $$ = SQL_NEW_RULE;
2283 $$->append($1);
2284 $$->append($2);
2286 | window_frame_preceding
2287 | SQL_TOKEN_CURRENT SQL_TOKEN_ROW
2289 $$ = SQL_NEW_RULE;
2290 $$->append($1);
2291 $$->append($2);
2294 window_frame_preceding:
2295 unsigned_value_spec SQL_TOKEN_PRECEDING
2297 $$ = SQL_NEW_RULE;
2298 $$->append($1);
2299 $$->append($2);
2302 window_frame_between:
2303 SQL_TOKEN_BETWEEN window_frame_bound_1 SQL_TOKEN_AND window_frame_bound_2
2305 $$ = SQL_NEW_RULE;
2306 $$->append($1);
2307 $$->append($2);
2308 $$->append($3);
2309 $$->append($4);
2312 window_frame_bound_1:
2313 window_frame_bound
2315 window_frame_bound_2:
2316 window_frame_bound
2318 window_frame_bound:
2319 window_frame_start
2320 | SQL_TOKEN_UNBOUNDED SQL_TOKEN_FOLLOWING
2322 $$ = SQL_NEW_RULE;
2323 $$->append($1);
2324 $$->append($2);
2326 | window_frame_following
2328 window_frame_following:
2329 unsigned_value_spec SQL_TOKEN_FOLLOWING
2331 $$ = SQL_NEW_RULE;
2332 $$->append($1);
2333 $$->append($2);
2336 window_frame_exclusion:
2337 SQL_TOKEN_EXCLUDE SQL_TOKEN_CURRENT SQL_TOKEN_ROW
2339 $$ = SQL_NEW_RULE;
2340 $$->append($1);
2341 $$->append($2);
2342 $$->append($3);
2344 | SQL_TOKEN_EXCLUDE SQL_TOKEN_GROUP
2346 $$ = SQL_NEW_RULE;
2347 $$->append($1);
2348 $$->append($2);
2350 | SQL_TOKEN_EXCLUDE SQL_TOKEN_TIES
2352 $$ = SQL_NEW_RULE;
2353 $$->append($1);
2354 $$->append($2);
2356 | SQL_TOKEN_EXCLUDE SQL_TOKEN_NO SQL_TOKEN_OTHERS
2358 $$ = SQL_NEW_RULE;
2359 $$->append($1);
2360 $$->append($2);
2361 $$->append($3);
2364 op_parameter:
2365 {$$ = SQL_NEW_RULE;}
2366 | '?' SQL_EQUAL
2368 $$ = SQL_NEW_RULE;
2369 $$->append(newNode("?", SQLNodeType::Punctuation));
2370 $$->append($2);
2373 odbc_call_spec:
2374 op_parameter SQL_TOKEN_CALL table_node op_odbc_call_parameter
2376 $$ = SQL_NEW_RULE;
2377 $$->append($1);
2378 $$->append($2);
2379 $$->append($3);
2380 $$->append($4);
2384 op_odbc_call_parameter:
2385 {$$ = SQL_NEW_RULE;}
2386 | '(' odbc_parameter_commalist ')'
2388 $$ = SQL_NEW_RULE;
2389 $$->append(newNode("(", SQLNodeType::Punctuation));
2390 $$->append($2);
2391 $$->append(newNode(")", SQLNodeType::Punctuation));
2395 odbc_parameter_commalist:
2396 odbc_parameter
2397 {$$ = SQL_NEW_COMMALISTRULE;
2398 $$->append($1);}
2399 | odbc_parameter_commalist ',' odbc_parameter
2401 $1->append($3);
2402 $$ = $1;
2405 odbc_parameter:
2406 /* empty */ {$$ = SQL_NEW_RULE;}
2407 | literal
2408 | parameter
2411 odbc_fct_spec:
2412 odbc_fct_type SQL_TOKEN_STRING
2414 $$ = SQL_NEW_RULE;
2415 $$->append($1);
2416 $$->append($2);
2418 | SQL_TOKEN_FN set_fct_spec
2420 $$ = SQL_NEW_RULE;
2421 $$->append($1);
2422 $$->append($2);
2426 odbc_fct_type:
2427 SQL_TOKEN_D
2428 | SQL_TOKEN_T
2429 | SQL_TOKEN_TS
2432 general_set_fct:
2433 set_fct_type '(' opt_all_distinct function_arg ')'
2435 $$ = SQL_NEW_RULE;
2436 $$->append($1);
2437 $$->append(newNode("(", SQLNodeType::Punctuation));
2438 $$->append($3);
2439 $$->append($4);
2440 $$->append(newNode(")", SQLNodeType::Punctuation));
2442 | SQL_TOKEN_COUNT '(' '*' ')'
2444 $$ = SQL_NEW_RULE;
2445 $$->append($1);
2446 $$->append(newNode("(", SQLNodeType::Punctuation));
2447 $$->append(newNode("*", SQLNodeType::Punctuation));
2448 $$->append(newNode(")", SQLNodeType::Punctuation));
2450 | SQL_TOKEN_COUNT '(' opt_all_distinct function_arg ')'
2452 $$ = SQL_NEW_RULE;
2453 $$->append($1);
2454 $$->append(newNode("(", SQLNodeType::Punctuation));
2455 $$->append($3);
2456 $$->append($4);
2457 $$->append(newNode(")", SQLNodeType::Punctuation));
2459 | ordered_set_function
2460 | array_aggregate_function
2462 set_fct_type:
2463 SQL_TOKEN_AVG
2464 | SQL_TOKEN_MAX
2465 | SQL_TOKEN_MIN
2466 | SQL_TOKEN_SUM
2467 | SQL_TOKEN_EVERY
2468 | SQL_TOKEN_ANY
2469 | SQL_TOKEN_SOME
2470 | SQL_TOKEN_STDDEV_POP
2471 | SQL_TOKEN_STDDEV_SAMP
2472 | SQL_TOKEN_VAR_SAMP
2473 | SQL_TOKEN_VAR_POP
2474 | SQL_TOKEN_COLLECT
2475 | SQL_TOKEN_FUSION
2476 | SQL_TOKEN_INTERSECTION
2479 ordered_set_function:
2480 hypothetical_set_function
2481 | inverse_distribution_function
2483 hypothetical_set_function:
2484 rank_function_type '(' hypothetical_set_function_value_expression_list ')' within_group_specification
2486 $$ = SQL_NEW_RULE;
2487 $$->append($1);
2488 $$->append(newNode("(", SQLNodeType::Punctuation));
2489 $$->append($3);
2490 $$->append(newNode(")", SQLNodeType::Punctuation));
2491 $$->append($5);
2493 | rank_function_type '(' hypothetical_set_function_value_expression_list SQL_TOKEN_BY value_exp_commalist ')' within_group_specification
2495 $$ = SQL_NEW_RULE;
2496 $$->append($1);
2497 $$->append(newNode("(", SQLNodeType::Punctuation));
2498 $$->append($3);
2499 $$->append($4);
2500 $$->append($5);
2501 $$->append(newNode(")", SQLNodeType::Punctuation));
2502 $$->append($7);
2506 within_group_specification:
2508 $$ = SQL_NEW_RULE;
2510 | SQL_TOKEN_WITHIN SQL_TOKEN_GROUP '(' opt_order_by_clause ')'
2512 $$ = SQL_NEW_RULE;
2513 $$->append($1);
2514 $$->append($2);
2515 $$->append(newNode("(", SQLNodeType::Punctuation));
2516 $$->append($4);
2517 $$->append(newNode(")", SQLNodeType::Punctuation));
2520 hypothetical_set_function_value_expression_list:
2521 value_exp_commalist
2524 inverse_distribution_function:
2525 inverse_distribution_function_type '('inverse_distribution_function_argument ')' within_group_specification
2527 $$ = SQL_NEW_RULE;
2528 $$->append($1);
2529 $$->append(newNode("(", SQLNodeType::Punctuation));
2530 $$->append($3);
2531 $$->append(newNode(")", SQLNodeType::Punctuation));
2534 inverse_distribution_function_argument:
2535 num_value_exp
2537 inverse_distribution_function_type:
2538 SQL_TOKEN_PERCENTILE_CONT
2539 | SQL_TOKEN_PERCENTILE_DISC
2542 array_aggregate_function:
2543 SQL_TOKEN_ARRAY_AGG '(' value_exp opt_order_by_clause ')'
2545 $$ = SQL_NEW_RULE;
2546 $$->append($1);
2547 $$->append(newNode("(", SQLNodeType::Punctuation));
2548 $$->append($3);
2549 $$->append($4);
2550 $$->append(newNode(")", SQLNodeType::Punctuation));
2554 rank_function_type:
2555 SQL_TOKEN_RANK
2556 | SQL_TOKEN_DENSE_RANK
2557 | SQL_TOKEN_PERCENT_RANK
2558 | SQL_TOKEN_CUME_DIST
2560 outer_join_type:
2561 SQL_TOKEN_LEFT %prec SQL_TOKEN_LEFT
2563 $$ = SQL_NEW_RULE;
2564 $$->append($1);
2566 | SQL_TOKEN_RIGHT %prec SQL_TOKEN_RIGHT
2568 $$ = SQL_NEW_RULE;
2569 $$->append($1);
2571 | SQL_TOKEN_FULL %prec SQL_TOKEN_FULL
2573 $$ = SQL_NEW_RULE;
2574 $$->append($1);
2577 join_condition:
2578 SQL_TOKEN_ON search_condition
2580 $$ = SQL_NEW_RULE;
2581 $$->append($1);
2582 $$->append($2);
2585 join_spec:
2586 join_condition
2587 | named_columns_join
2589 join_type:
2590 /* empty */ {$$ = SQL_NEW_RULE;}
2591 | SQL_TOKEN_INNER
2593 $$ = SQL_NEW_RULE;
2594 $$->append($1);
2596 | outer_join_type
2597 | outer_join_type SQL_TOKEN_OUTER
2599 $$ = SQL_NEW_RULE;
2600 $$->append($1);
2601 $$->append($2);
2604 cross_union:
2605 table_ref SQL_TOKEN_CROSS SQL_TOKEN_JOIN table_ref
2607 $$ = SQL_NEW_RULE;
2608 $$->append($1);
2609 $$->append($2);
2610 $$->append($3);
2611 $$->append($4);
2615 qualified_join:
2616 /* wenn SQL_TOKEN_NATURAL, dann keine join_spec */
2617 table_ref SQL_TOKEN_NATURAL join_type SQL_TOKEN_JOIN table_ref
2619 $$ = SQL_NEW_RULE;
2620 $$->append($1);
2621 $$->append($2);
2622 $$->append($3);
2623 $$->append($4);
2624 $$->append($5);
2626 | table_ref join_type SQL_TOKEN_JOIN table_ref join_spec
2628 $$ = SQL_NEW_RULE;
2629 $$->append($1);
2630 $$->append($2);
2631 $$->append($3);
2632 $$->append($4);
2633 $$->append($5);
2635 | cross_union
2637 joined_table:
2638 qualified_join
2640 named_columns_join:
2641 SQL_TOKEN_USING '(' column_commalist ')'
2643 $$ = SQL_NEW_RULE;
2644 $$->append($1);
2645 $$->append(newNode("(", SQLNodeType::Punctuation));
2646 $$->append($3);
2647 $$->append(newNode(")", SQLNodeType::Punctuation));
2650 simple_table:
2651 select_statement
2652 | values_or_query_spec
2655 non_join_query_primary:
2656 simple_table
2657 | '(' non_join_query_exp ')'
2659 $$ = SQL_NEW_RULE;
2660 $$->append(newNode("(", SQLNodeType::Punctuation));
2661 $$->append($2);
2662 $$->append(newNode(")", SQLNodeType::Punctuation));
2665 non_join_query_term:
2666 non_join_query_primary
2667 | query_term SQL_TOKEN_INTERSECT all query_primary
2669 $$ = SQL_NEW_RULE;
2670 $$->append($1);
2671 $$->append($2);
2672 $$->append($3);
2673 $$->append($4);
2676 query_primary:
2677 non_join_query_primary
2679 non_join_query_exp:
2680 non_join_query_term
2681 | query_exp SQL_TOKEN_UNION all query_term
2683 $$ = SQL_NEW_RULE;
2684 $$->append($1);
2685 $$->append($2);
2686 $$->append($3);
2687 $$->append($4);
2689 | query_exp SQL_TOKEN_EXCEPT all query_term
2691 $$ = SQL_NEW_RULE;
2692 $$->append($1);
2693 $$->append($2);
2694 $$->append($3);
2695 $$->append($4);
2698 all:
2699 /* empty*/ {$$ = SQL_NEW_RULE;}
2700 | SQL_TOKEN_ALL
2702 query_exp:
2703 non_join_query_exp /*[^')']*/
2705 scalar_subquery:
2706 subquery
2708 cast_operand:
2709 value_exp
2711 cast_target:
2712 table_node
2713 | data_type
2715 cast_spec:
2716 SQL_TOKEN_CAST '(' cast_operand SQL_TOKEN_AS cast_target ')'
2718 $$ = SQL_NEW_RULE;
2719 $$->append($1);
2720 $$->append(newNode("(", SQLNodeType::Punctuation));
2721 $$->append($3);
2722 $$->append($4);
2723 $$->append($5);
2724 $$->append(newNode(")", SQLNodeType::Punctuation));
2727 value_exp_primary:
2728 unsigned_value_spec
2729 | column_ref
2730 | set_fct_spec
2731 | scalar_subquery
2732 | case_expression
2733 | window_function
2734 | '(' value_exp ')'
2736 $$ = SQL_NEW_RULE;
2737 $$->append(newNode("(", SQLNodeType::Punctuation));
2738 $$->append($2);
2739 $$->append(newNode(")", SQLNodeType::Punctuation));
2741 | cast_spec
2744 num_primary:
2745 value_exp_primary
2746 | num_value_fct
2748 factor:
2749 num_primary
2750 | '-' num_primary %prec SQL_TOKEN_UMINUS
2752 $$ = SQL_NEW_RULE;
2753 $$->append(newNode("-", SQLNodeType::Punctuation));
2754 $$->append($2);
2756 | '+' num_primary %prec SQL_TOKEN_UMINUS
2758 $$ = SQL_NEW_RULE;
2759 $$->append(newNode("+", SQLNodeType::Punctuation));
2760 $$->append($2);
2764 term:
2765 factor
2766 | term '*' factor
2768 $$ = SQL_NEW_RULE;
2769 $$->append($1);
2770 $$->append(newNode("*", SQLNodeType::Punctuation));
2771 $$->append($3);
2773 | term '/' factor
2775 $$ = SQL_NEW_RULE;
2776 $$->append($1);
2777 $$->append(newNode("/", SQLNodeType::Punctuation));
2778 $$->append($3);
2782 num_value_exp:
2783 term
2784 | num_value_exp '+' term
2786 $$ = SQL_NEW_RULE;
2787 $$->append($1);
2788 $$->append(newNode("+", SQLNodeType::Punctuation));
2789 $$->append($3);
2791 | num_value_exp '-' term
2793 $$ = SQL_NEW_RULE;
2794 $$->append($1);
2795 $$->append(newNode("-", SQLNodeType::Punctuation));
2796 $$->append($3);
2799 datetime_primary:
2800 /* value_exp_primary
2802 $$ = SQL_NEW_RULE;
2803 $$->append($1);
2805 |*/ datetime_value_fct
2807 $$ = SQL_NEW_RULE;
2808 $$->append($1);
2811 datetime_value_fct:
2812 SQL_TOKEN_CURRENT_DATE
2814 $$ = SQL_NEW_RULE;
2815 $$->append($1);
2817 | SQL_TOKEN_CURRENT_TIME
2819 $$ = SQL_NEW_RULE;
2820 $$->append($1);
2822 | SQL_TOKEN_CURRENT_TIMESTAMP
2824 $$ = SQL_NEW_RULE;
2825 $$->append($1);
2828 time_zone:
2829 SQL_TOKEN_AT time_zone_specifier
2831 $$ = SQL_NEW_RULE;
2832 $$->append($1);
2833 $$->append($2);
2836 time_zone_specifier:
2837 SQL_TOKEN_LOCAL
2839 $$ = SQL_NEW_RULE;
2840 $$->append($1);
2842 /* | SQL_TOKEN_TIME SQL_TOKEN_ZONE interval_value_exp
2844 $$ = SQL_NEW_RULE;
2845 $$->append($1);
2846 $$->append($2);
2847 $$->append($3);
2850 datetime_factor:
2851 datetime_primary
2853 $$ = SQL_NEW_RULE;
2854 $$->append($1);
2856 | datetime_primary time_zone
2858 $$ = SQL_NEW_RULE;
2859 $$->append($1);
2860 $$->append($2);
2863 datetime_term:
2864 datetime_factor
2866 $$ = SQL_NEW_RULE;
2867 $$->append($1);
2871 interval_term:
2872 literal
2873 | interval_term '*' factor
2875 $$ = SQL_NEW_RULE;
2876 $$->append($1);
2877 $$->append(newNode("*", SQLNodeType::Punctuation));
2878 $$->append($3);
2880 | interval_term '/' factor
2882 $$ = SQL_NEW_RULE;
2883 $$->append($1);
2884 $$->append(newNode("/", SQLNodeType::Punctuation));
2885 $$->append($3);
2889 datetime_value_exp:
2890 datetime_term
2892 $$ = SQL_NEW_RULE;
2893 $$->append($1);
2895 /* | interval_value_exp '+' datetime_term
2897 $$ = SQL_NEW_RULE;
2898 $$->append($1);
2899 $$->append(newNode("+", SQLNodeType::Punctuation));
2900 $$->append($3);
2902 | datetime_value_exp '+' interval_term
2904 $$ = SQL_NEW_RULE;
2905 $$->append($1);
2906 $$->append(newNode("+", SQLNodeType::Punctuation));
2907 $$->append($3);
2909 | datetime_value_exp '-' interval_term
2911 $$ = SQL_NEW_RULE;
2912 $$->append($1);
2913 $$->append(newNode("-", SQLNodeType::Punctuation));
2914 $$->append($3);
2916 */ ;
2918 interval_value_exp:
2919 interval_term
2921 $$ = SQL_NEW_RULE;
2922 $$->append($1);
2924 | interval_value_exp '+' interval_term
2926 $$ = SQL_NEW_RULE;
2927 $$->append($1);
2928 $$->append(newNode("+", SQLNodeType::Punctuation));
2929 $$->append($3);
2931 | interval_value_exp '-' interval_term
2933 $$ = SQL_NEW_RULE;
2934 $$->append($1);
2935 $$->append(newNode("-", SQLNodeType::Punctuation));
2936 $$->append($3);
2938 | '(' datetime_value_exp '-' datetime_term ')' interval_qualifier
2940 $$ = SQL_NEW_RULE;
2941 $$->append(newNode("(", SQLNodeType::Punctuation));
2942 $$->append($2);
2943 $$->append(newNode("-", SQLNodeType::Punctuation));
2944 $$->append($4);
2945 $$->append(newNode(")", SQLNodeType::Punctuation));
2946 $$->append($6);
2950 non_second_datetime_field:
2951 SQL_TOKEN_YEAR
2952 | SQL_TOKEN_MONTH
2953 | SQL_TOKEN_DAY
2954 | SQL_TOKEN_HOUR
2955 | SQL_TOKEN_MINUTE
2957 start_field:
2958 non_second_datetime_field opt_paren_precision
2960 $$ = SQL_NEW_RULE;
2961 $$->append($1);
2962 $$->append($2);
2965 end_field:
2966 non_second_datetime_field
2967 | SQL_TOKEN_SECOND opt_paren_precision
2969 $$ = SQL_NEW_RULE;
2970 $$->append($1);
2971 $$->append($2);
2975 single_datetime_field:
2976 non_second_datetime_field opt_paren_precision
2978 $$ = SQL_NEW_RULE;
2979 $$->append($1);
2980 $$->append($2);
2982 | SQL_TOKEN_SECOND opt_paren_precision_scale
2984 $$ = SQL_NEW_RULE;
2985 $$->append($1);
2986 $$->append($2);
2990 interval_qualifier:
2991 start_field SQL_TOKEN_TO end_field
2993 $$ = SQL_NEW_RULE;
2994 $$->append($1);
2995 $$->append($2);
2996 $$->append($3);
2998 | single_datetime_field
3001 function_arg_commalist2:
3002 function_arg ',' function_arg
3003 {$$ = SQL_NEW_COMMALISTRULE;
3004 $$->append($1);
3005 $$->append($3);}
3007 function_arg_commalist3:
3008 function_arg ',' function_arg ',' function_arg
3010 $$ = SQL_NEW_COMMALISTRULE;
3011 $$->append($1);
3012 $$->append($3);
3013 $$->append($5);
3016 function_arg_commalist4:
3017 function_arg ',' function_arg ',' function_arg ',' function_arg
3019 $$ = SQL_NEW_COMMALISTRULE;
3020 $$->append($1);
3021 $$->append($3);
3022 $$->append($5);
3023 $$->append($7);
3026 value_exp_commalist:
3027 value_exp
3028 {$$ = SQL_NEW_COMMALISTRULE;
3029 $$->append($1);}
3030 | value_exp_commalist ',' value_exp
3031 {$1->append($3);
3032 $$ = $1;}
3033 /* this rule is only valid if we check predicates */
3034 | value_exp_commalist ';' value_exp
3036 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
3038 $1->append($3);
3039 $$ = $1;
3041 else
3042 YYERROR;
3045 function_arg:
3046 result
3047 | value_exp comparison value_exp
3049 $$ = SQL_NEW_RULE;
3050 $$->append($1);
3051 $$->append($2);
3052 $$->append($3);
3054 | value_exp SQL_TOKEN_USING value_exp comparison value_exp
3056 $$ = SQL_NEW_RULE;
3057 $$->append($1);
3058 $$->append($2);
3059 $$->append($3);
3060 $$->append($4);
3062 | value_exp SQL_TOKEN_BY value_exp_commalist
3064 $$ = SQL_NEW_RULE;
3065 $$->append($1);
3066 $$->append($2);
3067 $$->append($3);
3070 function_args_commalist:
3071 function_arg
3072 {$$ = SQL_NEW_COMMALISTRULE;
3073 $$->append($1);}
3074 | function_args_commalist ',' function_arg
3075 {$1->append($3);
3076 $$ = $1;}
3077 /* this rule is only valid if we check predicates */
3078 | function_args_commalist ';' function_arg
3080 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
3082 $1->append($3);
3083 $$ = $1;
3085 else
3086 YYERROR;
3090 value_exp:
3091 num_value_exp /*[^')']*/
3092 | string_value_exp
3093 | datetime_value_exp
3095 $$ = SQL_NEW_RULE;
3096 $$->append($1);
3099 string_value_exp:
3100 char_value_exp
3101 /* | bit_value_exp
3103 $$ = SQL_NEW_RULE;
3104 $$->append($1);
3106 */ ;
3107 char_value_exp:
3108 char_factor
3109 | concatenation
3111 concatenation:
3112 char_value_exp '+' char_factor
3114 $$ = SQL_NEW_RULE;
3115 $$->append($1);
3116 $$->append(newNode("+", SQLNodeType::Punctuation));
3117 $$->append($3);
3119 | value_exp SQL_CONCAT value_exp
3121 $$ = SQL_NEW_RULE;
3122 $$->append($1);
3123 $$->append($2);
3124 $$->append($3);
3128 char_primary:
3129 SQL_TOKEN_STRING
3130 | string_value_fct
3132 collate_clause:
3133 SQL_TOKEN_COLLATE table_node
3135 $$ = SQL_NEW_RULE;
3136 $$->append($1);
3137 $$->append($2);
3140 char_factor:
3141 char_primary
3142 | char_primary collate_clause
3144 $$ = SQL_NEW_RULE;
3145 $$->append($1);
3146 $$->append($2);
3149 string_value_fct:
3150 char_value_fct
3151 | bit_value_fct
3153 bit_value_fct:
3154 bit_substring_fct
3156 $$ = SQL_NEW_RULE;
3157 $$->append($1);
3160 bit_substring_fct:
3161 SQL_TOKEN_SUBSTRING '(' bit_value_exp SQL_TOKEN_FROM string_value_exp for_length ')'
3163 $$ = SQL_NEW_RULE;
3164 $$->append($1);
3165 $$->append(newNode("(", SQLNodeType::Punctuation));
3166 $$->append($3);
3167 $$->append($4);
3168 $$->append($5);
3169 $$->append($6);
3170 $$->append(newNode(")", SQLNodeType::Punctuation));
3173 bit_value_exp:
3174 bit_factor
3176 $$ = SQL_NEW_RULE;
3177 $$->append($1);
3181 bit_concatenation
3183 $$ = SQL_NEW_RULE;
3184 $$->append($1);
3187 bit_concatenation:
3188 bit_value_exp '+' bit_factor
3190 $$ = SQL_NEW_RULE;
3191 $$->append($1);
3192 $$->append(newNode("+", SQLNodeType::Punctuation));
3193 $$->append($3);
3197 bit_factor:
3198 bit_primary
3200 $$ = SQL_NEW_RULE;
3201 $$->append($1);
3204 bit_primary:
3205 {$$ = SQL_NEW_RULE;}
3206 /* value_exp_primary
3208 $$ = SQL_NEW_RULE;
3209 $$->append($1);
3211 | string_value_fct
3213 $$ = SQL_NEW_RULE;
3214 $$->append($1);
3217 char_value_fct:
3218 char_substring_fct
3219 | fold
3220 | form_conversion
3222 $$ = SQL_NEW_RULE;
3223 $$->append($1);
3225 | char_translation
3227 $$ = SQL_NEW_RULE;
3228 $$->append($1);
3230 | trim_fct
3232 $$ = SQL_NEW_RULE;
3233 $$->append($1);
3236 for_length:
3237 {$$ = SQL_NEW_RULE;}
3238 | SQL_TOKEN_FOR value_exp
3240 $$ = SQL_NEW_RULE;
3241 $$->append($1);
3242 $$->append($2);
3245 char_substring_fct:
3246 SQL_TOKEN_SUBSTRING '(' value_exp SQL_TOKEN_FROM value_exp for_length ')'
3248 $$ = SQL_NEW_RULE;
3249 $$->append($1);
3250 $$->append(newNode("(", SQLNodeType::Punctuation));
3251 $$->append($3);
3252 $$->append($4);
3253 $$->append($5);
3254 $$->append($6);
3255 $$->append(newNode(")", SQLNodeType::Punctuation));
3257 | SQL_TOKEN_SUBSTRING '(' value_exp_commalist ')'
3259 $$ = SQL_NEW_RULE;
3260 $$->append($1);
3261 $$->append(newNode("(", SQLNodeType::Punctuation));
3262 $$->append($3);
3263 $$->append(newNode(")", SQLNodeType::Punctuation));
3266 upper_lower:
3267 SQL_TOKEN_UPPER
3268 | SQL_TOKEN_LOWER
3270 fold:
3271 upper_lower '(' value_exp ')'
3273 $$ = SQL_NEW_RULE;
3274 $$->append($1);
3275 $$->append(newNode("(", SQLNodeType::Punctuation));
3276 $$->append($3);
3277 $$->append(newNode(")", SQLNodeType::Punctuation));
3280 form_conversion:
3281 SQL_TOKEN_CONVERT '(' string_value_exp SQL_TOKEN_USING table_node ')'
3283 $$ = SQL_NEW_RULE;
3284 $$->append($1);
3285 $$->append(newNode("(", SQLNodeType::Punctuation));
3286 $$->append($3);
3287 $$->append($4);
3288 $$->append($5);
3289 $$->append(newNode(")", SQLNodeType::Punctuation));
3291 | SQL_TOKEN_CONVERT '(' cast_operand ',' cast_target ')'
3293 $$ = SQL_NEW_RULE;
3294 $$->append($1);
3295 $$->append(newNode("(", SQLNodeType::Punctuation));
3296 $$->append($3);
3297 $$->append(newNode(",", SQLNodeType::Punctuation));
3298 $$->append($5);
3299 $$->append(newNode(")", SQLNodeType::Punctuation));
3302 char_translation:
3303 SQL_TOKEN_TRANSLATE '(' string_value_exp SQL_TOKEN_USING table_node ')'
3305 $$ = SQL_NEW_RULE;
3306 $$->append($1);
3307 $$->append(newNode("(", SQLNodeType::Punctuation));
3308 $$->append($3);
3309 $$->append($4);
3310 $$->append($5);
3311 $$->append(newNode(")", SQLNodeType::Punctuation));
3314 trim_fct:
3315 SQL_TOKEN_TRIM '(' trim_operands ')'
3317 $$ = SQL_NEW_RULE;
3318 $$->append($1);
3319 $$->append(newNode("(", SQLNodeType::Punctuation));
3320 $$->append($3);
3321 $$->append(newNode(")", SQLNodeType::Punctuation));
3324 trim_operands:
3325 trim_spec value_exp SQL_TOKEN_FROM value_exp
3327 $$ = SQL_NEW_RULE;
3328 $$->append($1);
3329 $$->append($2);
3330 $$->append($3);
3331 $$->append($4);
3333 | trim_spec SQL_TOKEN_FROM value_exp
3335 $$ = SQL_NEW_RULE;
3336 $$->append($1);
3337 $$->append($2);
3338 $$->append($3);
3340 | value_exp SQL_TOKEN_FROM value_exp
3342 $$ = SQL_NEW_RULE;
3343 $$->append($1);
3344 $$->append($2);
3345 $$->append($3);
3347 | SQL_TOKEN_FROM value_exp
3349 $$ = SQL_NEW_RULE;
3350 $$->append($1);
3351 $$->append($2);
3353 | value_exp
3356 trim_spec:
3357 SQL_TOKEN_BOTH
3358 | SQL_TOKEN_LEADING
3359 | SQL_TOKEN_TRAILING
3362 derived_column:
3363 value_exp as_clause
3365 $$ = SQL_NEW_RULE;
3366 $$->append($1);
3367 $$->append($2);
3370 /* Tabellenname */
3371 table_node:
3372 table_name
3373 | schema_name
3374 | catalog_name
3376 catalog_name:
3377 SQL_TOKEN_NAME '.' schema_name
3379 $$ = SQL_NEW_RULE;
3380 $$->append($1);
3381 $$->append(newNode(".", SQLNodeType::Punctuation));
3382 $$->append($3);
3384 | SQL_TOKEN_NAME ':' schema_name
3386 $$ = SQL_NEW_RULE;
3387 $$->append($1);
3388 $$->append(newNode(":", SQLNodeType::Punctuation));
3389 $$->append($3);
3392 schema_name:
3393 SQL_TOKEN_NAME '.' table_name
3395 $$ = SQL_NEW_RULE;
3396 $$->append($1);
3397 $$->append(newNode(".", SQLNodeType::Punctuation));
3398 $$->append($3);
3402 table_name:
3403 SQL_TOKEN_NAME
3404 {$$ = SQL_NEW_RULE;
3405 $$->append($1);}
3407 /* Columns */
3408 column_ref:
3409 column
3410 {$$ = SQL_NEW_RULE;
3411 $$->append($1);}
3412 /* | table_node '.' column_val %prec '.'
3413 {$$ = SQL_NEW_RULE;
3414 $$->append($1);
3415 $$->append(newNode(".", SQLNodeType::Punctuation));
3416 $$->append($3);}
3418 | SQL_TOKEN_NAME '.' column_val %prec '.'
3419 {$$ = SQL_NEW_RULE;
3420 $$->append($1);
3421 $$->append(newNode(".", SQLNodeType::Punctuation));
3422 $$->append($3);
3424 | SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val %prec '.'
3425 {$$ = SQL_NEW_RULE;
3426 $$->append($1);
3427 $$->append(newNode(".", SQLNodeType::Punctuation));
3428 $$->append($3);
3429 $$->append(newNode(".", SQLNodeType::Punctuation));
3430 $$->append($5);}
3431 | SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val %prec '.'
3432 {$$ = SQL_NEW_RULE;
3433 $$->append($1);
3434 $$->append(newNode(".", SQLNodeType::Punctuation));
3435 $$->append($3);
3436 $$->append(newNode(".", SQLNodeType::Punctuation));
3437 $$->append($5);
3438 $$->append(newNode(".", SQLNodeType::Punctuation));
3439 $$->append($7);
3441 | SQL_TOKEN_NAME ':' SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val %prec '.'
3442 {$$ = SQL_NEW_RULE;
3443 $$->append($1);
3444 $$->append(newNode(":", SQLNodeType::Punctuation));
3445 $$->append($3);
3446 $$->append(newNode(".", SQLNodeType::Punctuation));
3447 $$->append($5);
3448 $$->append(newNode(".", SQLNodeType::Punctuation));
3449 $$->append($7);
3451 /* | SQL_TOKEN_NAME ';' SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val
3452 {$$ = SQL_NEW_RULE;
3453 $$->append($1);
3454 $$->append(newNode(";", SQLNodeType::Punctuation));
3455 $$->append($3);
3456 $$->append(newNode(".", SQLNodeType::Punctuation));
3457 $$->append($5);
3458 $$->append(newNode(".", SQLNodeType::Punctuation));
3459 $$->append($7);
3461 */ ;
3463 /* data types */
3464 column_val:
3465 column
3466 {$$ = SQL_NEW_RULE;
3467 $$->append($1);}
3468 | '*'
3470 $$ = SQL_NEW_RULE;
3471 $$->append(newNode("*", SQLNodeType::Punctuation));
3474 data_type:
3475 predefined_type
3477 opt_char_set_spec:
3478 {$$ = SQL_NEW_RULE;}
3479 | SQL_TOKEN_CHARACTER SQL_TOKEN_SET SQL_TOKEN_NAME
3481 $$ = SQL_NEW_RULE;
3482 $$->append($1);
3483 $$->append($2);
3484 $$->append($3);
3487 opt_collate_clause:
3488 {$$ = SQL_NEW_RULE;}
3489 | collate_clause
3491 predefined_type:
3492 character_string_type opt_char_set_spec opt_collate_clause
3494 $$ = SQL_NEW_RULE;
3495 $$->append($1);
3496 $$->append($2);
3497 $$->append($3);
3499 | national_character_string_type opt_collate_clause
3501 $$ = SQL_NEW_RULE;
3502 $$->append($1);
3503 $$->append($2);
3505 | binary_string_type
3506 | numeric_type
3507 | boolean_type
3508 | datetime_type
3509 | interval_type
3511 character_string_type:
3512 SQL_TOKEN_CHARACTER opt_paren_precision
3514 $$ = SQL_NEW_RULE;
3515 $$->append($1);
3516 $$->append($2);
3518 | SQL_TOKEN_CHAR opt_paren_precision
3520 $$ = SQL_NEW_RULE;
3521 $$->append($1);
3522 $$->append($2);
3524 | SQL_TOKEN_CHARACTER SQL_TOKEN_VARYING paren_char_length
3526 $$ = SQL_NEW_RULE;
3527 $$->append($1);
3528 $$->append($2);
3529 $$->append($3);
3531 | SQL_TOKEN_CHAR SQL_TOKEN_VARYING paren_char_length
3533 $$ = SQL_NEW_RULE;
3534 $$->append($1);
3535 $$->append($2);
3536 $$->append($3);
3538 | SQL_TOKEN_VARCHAR paren_char_length
3540 $$ = SQL_NEW_RULE;
3541 $$->append($1);
3542 $$->append($2);
3544 | character_large_object_type
3546 opt_paren_precision:
3547 {$$ = SQL_NEW_RULE;}
3548 | paren_char_length
3550 paren_char_length:
3551 '(' SQL_TOKEN_INTNUM ')'
3553 $$ = SQL_NEW_RULE;
3554 $$->append(newNode("(", SQLNodeType::Punctuation));
3555 $$->append($2);
3556 $$->append(newNode(")", SQLNodeType::Punctuation));
3559 opt_paren_char_large_length:
3560 {$$ = SQL_NEW_RULE;}
3561 | paren_character_large_object_length
3563 paren_character_large_object_length:
3564 '(' large_object_length ')'
3566 $$ = SQL_NEW_RULE;
3567 $$->append(newNode("(", SQLNodeType::Punctuation));
3568 $$->append($2);
3569 $$->append(newNode(")", SQLNodeType::Punctuation));
3573 large_object_length:
3574 SQL_TOKEN_INTNUM opt_multiplier
3576 $$ = SQL_NEW_RULE;
3577 $$->append($1);
3578 $$->append($2);
3581 opt_multiplier:
3582 {$$ = SQL_NEW_RULE;}
3583 | 'K'
3585 $$ = SQL_NEW_RULE;
3586 $$->append(newNode("K", SQLNodeType::Punctuation));
3588 | 'M'
3590 $$ = SQL_NEW_RULE;
3591 $$->append(newNode("M", SQLNodeType::Punctuation));
3593 | 'G'
3595 $$ = SQL_NEW_RULE;
3596 $$->append(newNode("G", SQLNodeType::Punctuation));
3598 | 'T'
3600 $$ = SQL_NEW_RULE;
3601 $$->append(newNode("T", SQLNodeType::Punctuation));
3603 | 'P'
3605 $$ = SQL_NEW_RULE;
3606 $$->append(newNode("P", SQLNodeType::Punctuation));
3609 character_large_object_type:
3610 SQL_TOKEN_CHARACTER SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3612 $$ = SQL_NEW_RULE;
3613 $$->append($1);
3614 $$->append($2);
3615 $$->append($3);
3616 $$->append($4);
3618 | SQL_TOKEN_CHAR SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3620 $$ = SQL_NEW_RULE;
3621 $$->append($1);
3622 $$->append($2);
3623 $$->append($3);
3624 $$->append($4);
3626 | SQL_TOKEN_CLOB opt_paren_char_large_length
3628 $$ = SQL_NEW_RULE;
3629 $$->append($1);
3630 $$->append($2);
3633 national_character_string_type:
3634 SQL_TOKEN_NATIONAL SQL_TOKEN_CHARACTER opt_paren_precision
3636 $$ = SQL_NEW_RULE;
3637 $$->append($1);
3638 $$->append($2);
3639 $$->append($3);
3641 | SQL_TOKEN_NATIONAL SQL_TOKEN_CHAR opt_paren_precision
3643 $$ = SQL_NEW_RULE;
3644 $$->append($1);
3645 $$->append($2);
3646 $$->append($3);
3648 | SQL_TOKEN_NCHAR opt_paren_precision
3650 $$ = SQL_NEW_RULE;
3651 $$->append($1);
3652 $$->append($2);
3654 | SQL_TOKEN_NATIONAL SQL_TOKEN_CHARACTER SQL_TOKEN_VARYING paren_char_length
3656 $$ = SQL_NEW_RULE;
3657 $$->append($1);
3658 $$->append($2);
3659 $$->append($3);
3660 $$->append($4);
3662 | SQL_TOKEN_NATIONAL SQL_TOKEN_CHAR SQL_TOKEN_VARYING paren_char_length
3664 $$ = SQL_NEW_RULE;
3665 $$->append($1);
3666 $$->append($2);
3667 $$->append($3);
3668 $$->append($4);
3670 | SQL_TOKEN_NCHAR SQL_TOKEN_VARYING paren_char_length
3672 $$ = SQL_NEW_RULE;
3673 $$->append($1);
3674 $$->append($2);
3675 $$->append($3);
3677 | national_character_large_object_type
3679 national_character_large_object_type:
3680 SQL_TOKEN_NATIONAL SQL_TOKEN_CHARACTER SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3682 $$ = SQL_NEW_RULE;
3683 $$->append($1);
3684 $$->append($2);
3685 $$->append($3);
3686 $$->append($4);
3687 $$->append($5);
3689 | SQL_TOKEN_NCHAR SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3691 $$ = SQL_NEW_RULE;
3692 $$->append($1);
3693 $$->append($2);
3694 $$->append($3);
3695 $$->append($4);
3697 | SQL_TOKEN_NCLOB opt_paren_char_large_length
3699 $$ = SQL_NEW_RULE;
3700 $$->append($1);
3701 $$->append($2);
3704 binary_string_type:
3705 SQL_TOKEN_BINARY opt_paren_precision
3707 $$ = SQL_NEW_RULE;
3708 $$->append($1);
3709 $$->append($2);
3711 | SQL_TOKEN_BINARY SQL_TOKEN_VARYING paren_char_length
3713 $$ = SQL_NEW_RULE;
3714 $$->append($1);
3715 $$->append($2);
3716 $$->append($3);
3718 | SQL_TOKEN_VARBINARY paren_char_length
3720 $$ = SQL_NEW_RULE;
3721 $$->append($1);
3722 $$->append($2);
3724 | binary_large_object_string_type
3726 binary_large_object_string_type:
3727 SQL_TOKEN_BINARY SQL_TOKEN_LARGE SQL_TOKEN_OBJECT opt_paren_char_large_length
3729 $$ = SQL_NEW_RULE;
3730 $$->append($1);
3731 $$->append($2);
3732 $$->append($3);
3733 $$->append($4);
3735 | SQL_TOKEN_BLOB opt_paren_char_large_length
3737 $$ = SQL_NEW_RULE;
3738 $$->append($1);
3739 $$->append($2);
3742 numeric_type:
3743 exact_numeric_type
3744 | approximate_numeric_type
3746 opt_paren_precision_scale:
3747 {$$ = SQL_NEW_RULE;}
3748 | '(' SQL_TOKEN_INTNUM ')'
3750 $$ = SQL_NEW_RULE;
3751 $$->append(newNode("(", SQLNodeType::Punctuation));
3752 $$->append($2);
3753 $$->append(newNode(")", SQLNodeType::Punctuation));
3755 | '(' SQL_TOKEN_INTNUM ',' SQL_TOKEN_INTNUM ')'
3757 $$ = SQL_NEW_RULE;
3758 $$->append(newNode("(", SQLNodeType::Punctuation));
3759 $$->append($2);
3760 $$->append(newNode(",", SQLNodeType::Punctuation));
3761 $$->append($4);
3762 $$->append(newNode(")", SQLNodeType::Punctuation));
3765 exact_numeric_type:
3766 SQL_TOKEN_NUMERIC opt_paren_precision_scale
3768 $$ = SQL_NEW_RULE;
3769 $$->append($1);
3770 $$->append($2);
3772 | SQL_TOKEN_DECIMAL opt_paren_precision_scale
3774 $$ = SQL_NEW_RULE;
3775 $$->append($1);
3776 $$->append($2);
3778 | SQL_TOKEN_DEC opt_paren_precision_scale
3780 $$ = SQL_NEW_RULE;
3781 $$->append($1);
3782 $$->append($2);
3784 | SQL_TOKEN_SMALLINT
3785 | SQL_TOKEN_INTEGER
3786 | SQL_TOKEN_INT
3787 | SQL_TOKEN_BIGINT
3789 approximate_numeric_type:
3790 SQL_TOKEN_FLOAT '(' SQL_TOKEN_INTNUM ')'
3792 $$ = SQL_NEW_RULE;
3793 $$->append($1);
3794 $$->append(newNode("(", SQLNodeType::Punctuation));
3795 $$->append($3);
3796 $$->append(newNode(")", SQLNodeType::Punctuation));
3798 | SQL_TOKEN_FLOAT
3799 | SQL_TOKEN_REAL
3800 | SQL_TOKEN_DOUBLE
3801 | SQL_TOKEN_DOUBLE SQL_TOKEN_PRECISION
3803 $$ = SQL_NEW_RULE;
3804 $$->append($1);
3805 $$->append($2);
3808 boolean_type:
3809 SQL_TOKEN_BOOLEAN
3811 datetime_type:
3812 SQL_TOKEN_DATE
3813 | SQL_TOKEN_TIME opt_paren_precision opt_with_or_without_time_zone
3815 $$ = SQL_NEW_RULE;
3816 $$->append($1);
3817 $$->append($2);
3818 $$->append($3);
3820 | SQL_TOKEN_TIMESTAMP opt_paren_precision opt_with_or_without_time_zone
3822 $$ = SQL_NEW_RULE;
3823 $$->append($1);
3824 $$->append($2);
3825 $$->append($3);
3828 opt_with_or_without_time_zone:
3829 {$$ = SQL_NEW_RULE;}
3830 | SQL_TOKEN_WITH SQL_TOKEN_TIME SQL_TOKEN_ZONE
3832 $$ = SQL_NEW_RULE;
3833 $$->append($1);
3834 $$->append($2);
3835 $$->append($3);
3837 | SQL_TOKEN_WITHOUT SQL_TOKEN_TIME SQL_TOKEN_ZONE
3839 $$ = SQL_NEW_RULE;
3840 $$->append($1);
3841 $$->append($2);
3842 $$->append($3);
3845 interval_type:
3846 SQL_TOKEN_INTERVAL interval_qualifier
3848 $$ = SQL_NEW_RULE;
3849 $$->append($1);
3850 $$->append($2);
3853 /* the various things you can name */
3855 column:
3856 SQL_TOKEN_NAME
3857 | SQL_TOKEN_POSITION
3859 sal_uInt32 nNod = $$->getRuleID();
3860 delete $$;
3861 $$ = newNode(xxx_pGLOBAL_SQLPARSER->TokenIDToStr(nNod), SQLNodeType::Name);
3863 | SQL_TOKEN_CHAR_LENGTH
3865 sal_uInt32 nNod = $$->getRuleID();
3866 delete $$;
3867 $$ = newNode(xxx_pGLOBAL_SQLPARSER->TokenIDToStr(nNod), SQLNodeType::Name);
3869 | SQL_TOKEN_EXTRACT
3871 sal_uInt32 nNod = $$->getRuleID();
3872 delete $$;
3873 $$ = newNode(xxx_pGLOBAL_SQLPARSER->TokenIDToStr(nNod), SQLNodeType::Name);
3876 case_expression:
3877 case_abbreviation
3878 | case_specification
3880 case_abbreviation:
3881 SQL_TOKEN_NULLIF '(' value_exp_commalist ')'
3883 $$ = SQL_NEW_RULE;
3884 $$->append($1);
3885 $$->append(newNode("(", SQLNodeType::Punctuation));
3886 $$->append($3);
3887 $$->append(newNode(")", SQLNodeType::Punctuation));
3889 | SQL_TOKEN_COALESCE '(' value_exp ')'
3891 $$ = SQL_NEW_RULE;
3892 $$->append($1);
3893 $$->append(newNode("(", SQLNodeType::Punctuation));
3894 $$->append($3);
3895 $$->append(newNode(")", SQLNodeType::Punctuation));
3897 | SQL_TOKEN_COALESCE '(' value_exp_commalist ')'
3899 $$ = SQL_NEW_RULE;
3900 $$->append($1);
3901 $$->append(newNode("(", SQLNodeType::Punctuation));
3902 $$->append($3);
3903 $$->append(newNode(")", SQLNodeType::Punctuation));
3906 case_specification:
3907 simple_case
3908 | searched_case
3910 simple_case:
3911 SQL_TOKEN_CASE case_operand simple_when_clause_list else_clause SQL_TOKEN_END
3913 $$ = SQL_NEW_RULE;
3914 $$->append($1);
3915 $$->append($2);
3916 $$->append($3);
3917 $$->append($4);
3918 $$->append($5);
3921 searched_case:
3922 SQL_TOKEN_CASE searched_when_clause_list else_clause SQL_TOKEN_END
3924 $$ = SQL_NEW_RULE;
3925 $$->append($1);
3926 $$->append($2);
3927 $$->append($3);
3928 $$->append($4);
3931 simple_when_clause_list:
3932 simple_when_clause
3934 $$ = SQL_NEW_LISTRULE;
3935 $$->append($1);
3937 | searched_when_clause_list simple_when_clause
3939 $1->append($2);
3940 $$ = $1;
3943 simple_when_clause:
3944 SQL_TOKEN_WHEN when_operand_list SQL_TOKEN_THEN result
3946 $$ = SQL_NEW_RULE;
3947 $$->append($1);
3948 $$->append($2);
3949 $$->append($3);
3950 $$->append($4);
3953 when_operand_list:
3954 when_operand
3955 {$$ = SQL_NEW_COMMALISTRULE;
3956 $$->append($1);}
3957 | when_operand_list ',' when_operand
3958 {$1->append($3);
3959 $$ = $1;}
3961 when_operand:
3962 row_value_constructor_elem
3963 | comparison_predicate_part_2 %dprec 1
3964 | between_predicate_part_2
3965 | in_predicate_part_2
3966 | character_like_predicate_part_2
3967 | null_predicate_part_2 %dprec 2
3969 searched_when_clause_list:
3970 searched_when_clause
3972 $$ = SQL_NEW_LISTRULE;
3973 $$->append($1);
3975 | searched_when_clause_list searched_when_clause
3977 $1->append($2);
3978 $$ = $1;
3981 searched_when_clause:
3982 SQL_TOKEN_WHEN search_condition SQL_TOKEN_THEN result
3984 $$ = SQL_NEW_RULE;
3985 $$->append($1);
3986 $$->append($2);
3987 $$->append($3);
3988 $$->append($4);
3991 else_clause:
3992 {$$ = SQL_NEW_RULE;}
3993 | SQL_TOKEN_ELSE result
3995 $$ = SQL_NEW_RULE;
3996 $$->append($1);
3997 $$->append($2);
4000 result:
4001 result_expression
4003 result_expression:
4004 value_exp
4006 case_operand:
4007 row_value_constructor_elem
4010 cursor: SQL_TOKEN_NAME
4011 {$$ = SQL_NEW_RULE;
4012 $$->append($1);}
4015 /***
4016 module: SQL_TOKEN_NAME
4017 {$$ = SQL_NEW_RULE;
4018 $$->append($1);}
4020 ***/
4022 parameter:
4023 ':' SQL_TOKEN_NAME
4024 {$$ = SQL_NEW_RULE;
4025 $$->append(newNode(":", SQLNodeType::Punctuation));
4026 $$->append($2);}
4027 | '?'
4028 {$$ = SQL_NEW_RULE; // test
4029 $$->append(newNode("?", SQLNodeType::Punctuation));}
4030 | '[' SQL_TOKEN_NAME ']'
4031 {$$ = SQL_NEW_RULE;
4032 $$->append(newNode("[", SQLNodeType::Punctuation));
4033 $$->append($2);
4034 $$->append(newNode("]", SQLNodeType::Punctuation));}
4037 /***
4038 procedure: SQL_TOKEN_NAME
4039 {$$ = SQL_NEW_RULE;
4040 $$->append($1);}
4042 ***/
4044 range_variable:
4045 {$$ = SQL_NEW_RULE;}
4046 | opt_as SQL_TOKEN_NAME
4047 {$$ = SQL_NEW_RULE;
4048 $$->append($1);
4049 $$->append($2);
4053 user: SQL_TOKEN_NAME
4056 /* PREDICATECHECK RULES */
4057 sql:
4058 search_condition /* checking predicats */
4060 if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // sql: rule 1
4062 $$ = $1;
4063 if ( SQL_ISRULE($$,search_condition) )
4065 $$->insert(0,newNode("(", SQLNodeType::Punctuation));
4066 $$->append(newNode(")", SQLNodeType::Punctuation));
4069 else
4070 YYERROR;
4072 | '(' sql ')' /* checking predicats */
4074 trigger_definition:
4075 SQL_TOKEN_CREATE SQL_TOKEN_TRIGGER trigger_name trigger_action_time trigger_event SQL_TOKEN_ON table_name op_referencing triggered_action
4077 $$ = SQL_NEW_RULE;
4078 $$->append($1);
4079 $$->append($2);
4080 $$->append($3);
4081 $$->append($4);
4082 $$->append($5);
4083 $$->append($6);
4084 $$->append($7);
4085 $$->append($8);
4086 $$->append($9);
4089 op_referencing:
4091 $$ = SQL_NEW_RULE;
4093 | SQL_TOKEN_REFERENCING transition_table_or_variable_list
4095 $$ = SQL_NEW_RULE;
4096 $$->append($1);
4097 $$->append($2);
4100 trigger_action_time:
4101 SQL_TOKEN_BEFORE
4102 | SQL_TOKEN_AFTER
4103 | SQL_TOKEN_INSTEAD SQL_TOKEN_OF
4105 $$ = SQL_NEW_RULE;
4106 $$->append($1);
4107 $$->append($2);
4110 trigger_event:
4111 SQL_TOKEN_INSERT
4112 | SQL_TOKEN_DELETE
4113 | SQL_TOKEN_UPDATE op_trigger_columnlist
4115 $$ = SQL_NEW_RULE;
4116 $$->append($1);
4117 $$->append($2);
4120 op_trigger_columnlist:
4122 $$ = SQL_NEW_RULE;
4124 | SQL_TOKEN_OF trigger_column_list
4126 $$ = SQL_NEW_RULE;
4127 $$->append($1);
4128 $$->append($2);
4131 trigger_column_list:
4132 column_commalist
4134 triggered_action:
4135 op_triggered_action_for triggered_when_clause triggered_SQL_statement
4137 $$ = SQL_NEW_RULE;
4138 $$->append($1);
4139 $$->append($2);
4140 $$->append($3);
4143 op_triggered_action_for:
4145 $$ = SQL_NEW_RULE;
4147 | SQL_TOKEN_FOR SQL_TOKEN_EACH trigger_for
4149 $$ = SQL_NEW_RULE;
4150 $$->append($1);
4151 $$->append($2);
4152 $$->append($3);
4155 trigger_for:
4156 SQL_TOKEN_ROW
4157 | SQL_TOKEN_STATEMENT
4159 triggered_when_clause:
4161 $$ = SQL_NEW_RULE;
4163 | SQL_TOKEN_WHEN parenthesized_boolean_value_expression
4165 $$ = SQL_NEW_RULE;
4166 $$->append($1);
4167 $$->append($2);
4170 triggered_SQL_statement:
4171 SQL_procedure_statement
4172 | SQL_TOKEN_BEGIN SQL_TOKEN_ATOMIC SQL_procedure_statement_list ';' SQL_TOKEN_END
4174 $$ = SQL_NEW_RULE;
4175 $$->append($1);
4176 $$->append($2);
4177 $$->append($3);
4178 $$->append(newNode(";", SQLNodeType::Punctuation));
4179 $$->append($5);
4182 SQL_procedure_statement_list:
4183 SQL_procedure_statement
4185 $$ = SQL_NEW_LISTRULE;
4186 $$->append($1);
4188 | SQL_procedure_statement_list ';' SQL_procedure_statement
4190 $1->append($3);
4191 $$ = $1;
4194 SQL_procedure_statement:
4198 transition_table_or_variable_list:
4199 transition_table_or_variable
4201 $$ = SQL_NEW_LISTRULE;
4202 $$->append($1);
4204 | transition_table_or_variable_list transition_table_or_variable
4206 $1->append($2);
4207 $$ = $1;
4211 transition_table_or_variable:
4212 SQL_TOKEN_OLD opt_row opt_as old_transition_variable_name
4214 $$ = SQL_NEW_RULE;
4215 $$->append($1);
4216 $$->append($2);
4217 $$->append($3);
4218 $$->append($4);
4220 | SQL_TOKEN_NEW opt_row opt_as new_transition_variable_name
4222 $$ = SQL_NEW_RULE;
4223 $$->append($1);
4224 $$->append($2);
4225 $$->append($3);
4226 $$->append($4);
4228 | SQL_TOKEN_OLD SQL_TOKEN_TABLE opt_as old_transition_table_name
4230 $$ = SQL_NEW_RULE;
4231 $$->append($1);
4232 $$->append($2);
4233 $$->append($3);
4234 $$->append($4);
4236 | SQL_TOKEN_NEW SQL_TOKEN_TABLE opt_as new_transition_table_name
4238 $$ = SQL_NEW_RULE;
4239 $$->append($1);
4240 $$->append($2);
4241 $$->append($3);
4242 $$->append($4);
4245 old_transition_table_name:
4246 transition_table_name
4248 new_transition_table_name:
4249 transition_table_name
4251 transition_table_name:
4252 SQL_TOKEN_NAME
4254 old_transition_variable_name:
4255 SQL_TOKEN_NAME
4257 new_transition_variable_name:
4258 SQL_TOKEN_NAME
4260 trigger_name:
4261 SQL_TOKEN_NAME
4266 using namespace ::com::sun::star::sdbc;
4267 using namespace ::com::sun::star::beans;
4268 using namespace ::com::sun::star::uno;
4269 using namespace ::com::sun::star::i18n;
4270 using namespace ::com::sun::star::lang;
4271 using namespace ::com::sun::star::util;
4272 using namespace ::osl;
4273 using namespace ::dbtools;
4275 connectivity::OSQLInternalNode* newNode(const sal_Char* pNewValue,
4276 const connectivity::SQLNodeType eNodeType,
4277 const sal_uInt32 nNodeID)
4279 return new connectivity::OSQLInternalNode(pNewValue, eNodeType, nNodeID);
4282 connectivity::OSQLInternalNode* newNode(const OString& _NewValue,
4283 const connectivity::SQLNodeType eNodeType,
4284 const sal_uInt32 nNodeID)
4286 return new connectivity::OSQLInternalNode(_NewValue, eNodeType, nNodeID);
4289 connectivity::OSQLInternalNode* newNode(const OUString& _NewValue,
4290 const connectivity::SQLNodeType eNodeType,
4291 const sal_uInt32 nNodeID)
4293 return new connectivity::OSQLInternalNode(_NewValue, eNodeType, nNodeID);
4296 OParseContext::OParseContext()
4301 OParseContext::~OParseContext()
4306 OUString OParseContext::getErrorMessage(ErrorCode _eCode) const
4308 OUString aMsg;
4309 switch (_eCode)
4311 case ErrorCode::General: aMsg = "Syntax error in SQL expression"; break;
4312 case ErrorCode::ValueNoLike: aMsg = "The value #1 can not be used with LIKE."; break;
4313 case ErrorCode::FieldNoLike: aMsg = "LIKE can not be used with this field."; break;
4314 case ErrorCode::InvalidCompare: aMsg = "The entered criterion can not be compared with this field."; break;
4315 case ErrorCode::InvalidIntCompare: aMsg = "The field can not be compared with a number."; break;
4316 case ErrorCode::InvalidDateCompare: aMsg = "The field can not be compared with a date."; break;
4317 case ErrorCode::InvalidRealCompare: aMsg = "The field can not be compared with a floating point number."; break;
4318 case ErrorCode::InvalidTableNosuch: aMsg = "The database does not contain a table named \"#\"."; break;
4319 case ErrorCode::InvalidTableOrQuery: aMsg = "The database does contain neither a table nor a query named \"#\"."; break;
4320 case ErrorCode::InvalidColumn: aMsg = "The column \"#1\" is unknown in the table \"#2\"."; break;
4321 case ErrorCode::InvalidTableExist: aMsg = "The database already contains a table or view with name \"#\"."; break;
4322 case ErrorCode::InvalidQueryExist: aMsg = "The database already contains a query with name \"#\"."; break;
4323 default:
4324 OSL_FAIL( "OParseContext::getErrorMessage: unknown error code!" );
4325 break;
4327 return aMsg;
4331 OString OParseContext::getIntlKeywordAscii(InternationalKeyCode _eKey) const
4333 OString aKeyword;
4334 switch (_eKey)
4336 case InternationalKeyCode::Like: aKeyword = "LIKE"; break;
4337 case InternationalKeyCode::Not: aKeyword = "NOT"; break;
4338 case InternationalKeyCode::Null: aKeyword = "NULL"; break;
4339 case InternationalKeyCode::True: aKeyword = "True"; break;
4340 case InternationalKeyCode::False: aKeyword = "False"; break;
4341 case InternationalKeyCode::Is: aKeyword = "IS"; break;
4342 case InternationalKeyCode::Between: aKeyword = "BETWEEN"; break;
4343 case InternationalKeyCode::Or: aKeyword = "OR"; break;
4344 case InternationalKeyCode::And: aKeyword = "AND"; break;
4345 case InternationalKeyCode::Avg: aKeyword = "AVG"; break;
4346 case InternationalKeyCode::Count: aKeyword = "COUNT"; break;
4347 case InternationalKeyCode::Max: aKeyword = "MAX"; break;
4348 case InternationalKeyCode::Min: aKeyword = "MIN"; break;
4349 case InternationalKeyCode::Sum: aKeyword = "SUM"; break;
4350 case InternationalKeyCode::Every: aKeyword = "EVERY"; break;
4351 case InternationalKeyCode::Any: aKeyword = "ANY"; break;
4352 case InternationalKeyCode::Some: aKeyword = "SOME"; break;
4353 case InternationalKeyCode::StdDevPop: aKeyword = "STDDEV_POP"; break;
4354 case InternationalKeyCode::StdDevSamp: aKeyword = "STDDEV_SAMP"; break;
4355 case InternationalKeyCode::VarSamp: aKeyword = "VAR_SAMP"; break;
4356 case InternationalKeyCode::VarPop: aKeyword = "VAR_POP"; break;
4357 case InternationalKeyCode::Collect: aKeyword = "COLLECT"; break;
4358 case InternationalKeyCode::Fusion: aKeyword = "FUSION"; break;
4359 case InternationalKeyCode::Intersection:aKeyword = "INTERSECTION"; break;
4360 case InternationalKeyCode::None: break;
4361 default:
4362 OSL_FAIL( "OParseContext::getIntlKeywordAscii: unknown key!" );
4363 break;
4365 return aKeyword;
4369 IParseContext::InternationalKeyCode OParseContext::getIntlKeyCode(const OString& rToken) const
4371 static IParseContext::InternationalKeyCode Intl_TokenID[] =
4373 InternationalKeyCode::Like, InternationalKeyCode::Not, InternationalKeyCode::Null, InternationalKeyCode::True,
4374 InternationalKeyCode::False, InternationalKeyCode::Is, InternationalKeyCode::Between, InternationalKeyCode::Or,
4375 InternationalKeyCode::And, InternationalKeyCode::Avg, InternationalKeyCode::Count, InternationalKeyCode::Max,
4376 InternationalKeyCode::Min, InternationalKeyCode::Sum, InternationalKeyCode::Every,InternationalKeyCode::Any,InternationalKeyCode::Some,
4377 InternationalKeyCode::StdDevPop,InternationalKeyCode::StdDevSamp,InternationalKeyCode::VarSamp,
4378 InternationalKeyCode::VarPop,InternationalKeyCode::Collect,InternationalKeyCode::Fusion,InternationalKeyCode::Intersection
4381 sal_uInt32 nCount = SAL_N_ELEMENTS( Intl_TokenID );
4382 for (sal_uInt32 i = 0; i < nCount; i++)
4384 OString aKey = getIntlKeywordAscii(Intl_TokenID[i]);
4385 if (rToken.equalsIgnoreAsciiCase(aKey))
4386 return Intl_TokenID[i];
4389 return InternationalKeyCode::None;
4393 static Locale& impl_getLocaleInstance( )
4395 static Locale s_aLocale( "en", "US", "" );
4396 return s_aLocale;
4400 Locale OParseContext::getPreferredLocale( ) const
4402 return getDefaultLocale();
4406 const Locale& OParseContext::getDefaultLocale()
4408 return impl_getLocaleInstance();
4411 // Der (leider globale) yylval fuer die Uebergabe von
4412 // Werten vom Scanner an den Parser. Die globale Variable
4413 // wird nur kurzzeitig verwendet, der Parser liest die Variable
4414 // sofort nach dem Scanner-Aufruf in eine gleichnamige eigene
4415 // Member-Variable.
4418 OUString ConvertLikeToken(const OSQLParseNode* pTokenNode, const OSQLParseNode* pEscapeNode, bool bInternational)
4420 OUStringBuffer aMatchStr(0);
4421 if (pTokenNode->isToken())
4423 sal_Unicode cEscape = 0;
4424 if (pEscapeNode->count())
4425 cEscape = pEscapeNode->getChild(1)->getTokenValue().toChar();
4427 // Platzhalter austauschen
4428 aMatchStr = pTokenNode->getTokenValue();
4429 const sal_Int32 nLen = aMatchStr.getLength();
4430 OUStringBuffer sSearch,sReplace;
4431 if ( bInternational )
4433 sSearch.appendAscii("%_",2);
4434 sReplace.appendAscii("*?",2);
4436 else
4438 sSearch.appendAscii("*?",2);
4439 sReplace.appendAscii("%_",2);
4442 bool wasEscape = false;
4443 for (sal_Int32 i = 0; i < nLen; i++)
4445 const sal_Unicode c = aMatchStr[i];
4446 // SQL standard requires the escape to be followed
4447 // by a meta-character ('%', '_' or itself), else error
4448 // We are more lenient here and let it escape anything.
4449 // Especially since some databases (e.g. Microsoft SQL Server)
4450 // have more meta-characters than the standard, such as e.g. '[' and ']'
4451 if (wasEscape)
4453 wasEscape=false;
4454 continue;
4456 if (c == cEscape)
4458 wasEscape=true;
4459 continue;
4461 int match = -1;
4462 if (c == sSearch[0])
4463 match=0;
4464 else if (c == sSearch[1])
4465 match=1;
4467 if (match != -1)
4469 aMatchStr[i] = sReplace[match];
4473 return aMatchStr.makeStringAndClear();
4476 sal_uInt32 OSQLParser::s_nRuleIDs[OSQLParseNode::rule_count + 1];
4477 OSQLParser::RuleIDMap OSQLParser::s_aReverseRuleIDLookup;
4478 OParseContext OSQLParser::s_aDefaultContext;
4480 sal_Int32 OSQLParser::s_nRefCount = 0;
4481 // ::osl::Mutex OSQLParser::s_aMutex;
4482 OSQLScanner* OSQLParser::s_pScanner = 0;
4483 OSQLParseNodesGarbageCollector* OSQLParser::s_pGarbageCollector = 0;
4484 css::uno::Reference< css::i18n::XLocaleData4> OSQLParser::s_xLocaleData = NULL;
4486 void setParser(OSQLParser* _pParser)
4488 xxx_pGLOBAL_SQLPARSER = _pParser;
4491 void OSQLParser::setParseTree(OSQLParseNode * pNewParseTree)
4493 ::osl::MutexGuard aGuard(getMutex());
4494 m_pParseTree = pNewParseTree;
4498 /** Delete all comments in a query.
4500 See also getComment()/concatComment() implementation for
4501 OQueryController::translateStatement().
4503 static OUString delComment( const OUString& rQuery )
4505 // First a quick search if there is any "--" or "//" or "/*", if not then the whole
4506 // copying loop is pointless.
4507 if (rQuery.indexOfAsciiL( "--", 2, 0) < 0 && rQuery.indexOfAsciiL( "//", 2, 0) < 0 &&
4508 rQuery.indexOfAsciiL( "/*", 2, 0) < 0)
4509 return rQuery;
4511 const sal_Unicode* pCopy = rQuery.getStr();
4512 sal_Int32 nQueryLen = rQuery.getLength();
4513 bool bIsText1 = false; // "text"
4514 bool bIsText2 = false; // 'text'
4515 bool bComment2 = false; // /* comment */
4516 bool bComment = false; // -- or // comment
4517 OUStringBuffer aBuf(nQueryLen);
4518 for (sal_Int32 i=0; i < nQueryLen; ++i)
4520 if (bComment2)
4522 if ((i+1) < nQueryLen)
4524 if (pCopy[i]=='*' && pCopy[i+1]=='/')
4526 bComment2 = false;
4527 ++i;
4530 else
4532 // comment can't close anymore, actually an error, but..
4534 continue;
4536 if (pCopy[i] == '\n')
4537 bComment = false;
4538 else if (!bComment)
4540 if (pCopy[i] == '\"' && !bIsText2)
4541 bIsText1 = !bIsText1;
4542 else if (pCopy[i] == '\'' && !bIsText1)
4543 bIsText2 = !bIsText2;
4544 if (!bIsText1 && !bIsText2 && (i+1) < nQueryLen)
4546 if ((pCopy[i]=='-' && pCopy[i+1]=='-') || (pCopy[i]=='/' && pCopy[i+1]=='/'))
4547 bComment = true;
4548 else if ((pCopy[i]=='/' && pCopy[i+1]=='*'))
4549 bComment2 = true;
4552 if (!bComment && !bComment2)
4553 aBuf.append( &pCopy[i], 1);
4555 return aBuf.makeStringAndClear();
4558 OSQLParseNode* OSQLParser::parseTree(OUString& rErrorMessage,
4559 const OUString& rStatement,
4560 bool bInternational)
4564 // Guard the parsing
4565 ::osl::MutexGuard aGuard(getMutex());
4566 // must be reset
4567 setParser(this);
4569 // delete comments before parsing
4570 OUString sTemp = delComment(rStatement);
4572 // defines how to scan
4573 s_pScanner->SetRule(s_pScanner->GetSQLRule()); // initial
4574 s_pScanner->prepareScan(sTemp, m_pContext, bInternational);
4576 SQLyylval.pParseNode = NULL;
4577 // SQLyypvt = NULL;
4578 m_pParseTree = NULL;
4579 m_sErrorMessage = "";
4581 // start parsing
4582 if (SQLyyparse() != 0)
4584 // only set the error message, if it's not already set
4585 if (m_sErrorMessage.isEmpty())
4586 m_sErrorMessage = s_pScanner->getErrorMessage();
4587 if (m_sErrorMessage.isEmpty())
4588 m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ErrorCode::General);
4590 rErrorMessage = m_sErrorMessage;
4592 // clear the garbage collector
4593 (*s_pGarbageCollector)->clearAndDelete();
4594 return NULL;
4596 else
4598 (*s_pGarbageCollector)->clear();
4600 // return result:
4601 // to work around a bug in MKS YACC return the member m_pParseTree
4602 // instead of Sdbyyval.pParseNode
4604 SAL_WARN_IF(!m_pParseTree, "connectivity.parse",
4605 "OSQLParser: Parser did not create ParseTree");
4606 return m_pParseTree;
4610 OString OSQLParser::TokenIDToStr(sal_uInt32 nTokenID, const IParseContext* pContext)
4612 OString aStr;
4613 if (pContext)
4615 IParseContext::InternationalKeyCode eKeyCode = IParseContext::InternationalKeyCode::None;
4616 switch( nTokenID )
4618 case SQL_TOKEN_LIKE: eKeyCode = IParseContext::InternationalKeyCode::Like; break;
4619 case SQL_TOKEN_NOT: eKeyCode = IParseContext::InternationalKeyCode::Not; break;
4620 case SQL_TOKEN_NULL: eKeyCode = IParseContext::InternationalKeyCode::Null; break;
4621 case SQL_TOKEN_TRUE: eKeyCode = IParseContext::InternationalKeyCode::True; break;
4622 case SQL_TOKEN_FALSE: eKeyCode = IParseContext::InternationalKeyCode::False; break;
4623 case SQL_TOKEN_IS: eKeyCode = IParseContext::InternationalKeyCode::Is; break;
4624 case SQL_TOKEN_BETWEEN: eKeyCode = IParseContext::InternationalKeyCode::Between; break;
4625 case SQL_TOKEN_OR: eKeyCode = IParseContext::InternationalKeyCode::Or; break;
4626 case SQL_TOKEN_AND: eKeyCode = IParseContext::InternationalKeyCode::And; break;
4627 case SQL_TOKEN_AVG: eKeyCode = IParseContext::InternationalKeyCode::Avg; break;
4628 case SQL_TOKEN_COUNT: eKeyCode = IParseContext::InternationalKeyCode::Count; break;
4629 case SQL_TOKEN_MAX: eKeyCode = IParseContext::InternationalKeyCode::Max; break;
4630 case SQL_TOKEN_MIN: eKeyCode = IParseContext::InternationalKeyCode::Min; break;
4631 case SQL_TOKEN_SUM: eKeyCode = IParseContext::InternationalKeyCode::Sum; break;
4633 if ( eKeyCode != IParseContext::InternationalKeyCode::None )
4634 aStr = pContext->getIntlKeywordAscii(eKeyCode);
4637 if (aStr.isEmpty())
4639 aStr = yytname[YYTRANSLATE(nTokenID)];
4640 if(aStr.startsWith("SQL_TOKEN_"))
4641 aStr = aStr.copy(10);
4642 switch( nTokenID )
4644 case SQL_TOKEN_OJ:
4645 case SQL_TOKEN_TS:
4646 case SQL_TOKEN_T:
4647 case SQL_TOKEN_D:
4648 aStr = aStr.toAsciiLowerCase();
4651 return aStr;
4654 #if OSL_DEBUG_LEVEL > 0
4655 OUString OSQLParser::RuleIDToStr(sal_uInt32 nRuleID)
4657 OSL_ENSURE(nRuleID < SAL_N_ELEMENTS(yytname), "OSQLParser::RuleIDToStr: Invalid nRuleId!");
4658 return OUString::createFromAscii(yytname[nRuleID]);
4660 #endif
4663 sal_uInt32 OSQLParser::StrToRuleID(const OString & rValue)
4665 // Search for the given name in yytname and return the index
4666 // (or UNKNOWN_RULE, if not found)
4667 static sal_uInt32 nLen = SAL_N_ELEMENTS(yytname);
4668 for (sal_uInt32 i = YYTRANSLATE(SQL_TOKEN_INVALIDSYMBOL); i < (nLen-1); i++)
4670 if (rValue == yytname[i])
4671 return i;
4674 // Not found
4675 return OSQLParseNode::UNKNOWN_RULE;
4679 OSQLParseNode::Rule OSQLParser::RuleIDToRule( sal_uInt32 _nRule )
4681 OSQLParser::RuleIDMap::const_iterator i (s_aReverseRuleIDLookup.find(_nRule));
4682 if (i == s_aReverseRuleIDLookup.end())
4684 SAL_INFO("connectivity.parse",
4685 "connectivity::OSQLParser::RuleIDToRule cannot reverse-lookup rule. "
4686 "Reverse mapping incomplete? "
4687 "_nRule='" << _nRule << "' "
4688 "yytname[_nRule]='" << yytname[_nRule] << "'");
4689 return OSQLParseNode::UNKNOWN_RULE;
4691 else
4692 return i->second;
4696 sal_uInt32 OSQLParser::RuleID(OSQLParseNode::Rule eRule)
4698 return s_nRuleIDs[(sal_uInt16)eRule];
4701 sal_Int16 OSQLParser::buildNode(OSQLParseNode*& pAppend,OSQLParseNode* pCompare,OSQLParseNode* pLiteral,OSQLParseNode* pLiteral2)
4703 OSQLParseNode* pColumnRef = new OSQLInternalNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::column_ref));
4704 pColumnRef->append(new OSQLInternalNode(m_sFieldName,SQLNodeType::Name));
4705 OSQLParseNode* pComp = NULL;
4706 if ( SQL_ISTOKEN( pCompare, BETWEEN) && pLiteral2 )
4707 pComp = new OSQLInternalNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::between_predicate_part_2));
4708 else
4709 pComp = new OSQLInternalNode("", SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::comparison_predicate));
4711 pComp->append(pColumnRef);
4712 pComp->append(pCompare);
4713 pComp->append(pLiteral);
4714 if ( pLiteral2 )
4716 pComp->append(new OSQLInternalNode("", SQLNodeType::Keyword,SQL_TOKEN_AND));
4717 pComp->append(pLiteral2);
4719 pAppend->append(pComp);
4720 return 1;
4723 sal_Int16 OSQLParser::buildStringNodes(OSQLParseNode*& pLiteral)
4725 if(!pLiteral)
4726 return 1;
4728 if(SQL_ISRULE(pLiteral,set_fct_spec) || SQL_ISRULE(pLiteral,general_set_fct) || SQL_ISRULE(pLiteral,column_ref)
4729 || SQL_ISRULE(pLiteral,subquery))
4730 return 1; // here I have a function that I can't transform into a string
4732 if(pLiteral->getNodeType() == SQLNodeType::IntNum || pLiteral->getNodeType() == SQLNodeType::ApproxNum || pLiteral->getNodeType() == SQLNodeType::AccessDate)
4734 OSQLParseNode* pParent = pLiteral->getParent();
4736 OSQLParseNode* pNewNode = new OSQLInternalNode(pLiteral->getTokenValue(), SQLNodeType::String);
4737 pParent->replace(pLiteral, pNewNode);
4738 delete pLiteral;
4739 pLiteral = NULL;
4740 return 1;
4743 for(sal_uInt32 i=0;i<pLiteral->count();++i)
4745 OSQLParseNode* pChild = pLiteral->getChild(i);
4746 buildStringNodes(pChild);
4748 if(SQL_ISRULE(pLiteral,term) || SQL_ISRULE(pLiteral,value_exp_primary))
4750 m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ErrorCode::InvalidCompare);
4751 return 0;
4753 return 1;
4756 sal_Int16 OSQLParser::buildComparsionRule(OSQLParseNode*& pAppend,OSQLParseNode* pLiteral)
4758 OSQLParseNode* pComp = new OSQLInternalNode("=", SQLNodeType::Equal);
4759 return buildPredicateRule(pAppend,pLiteral,pComp);
4764 void OSQLParser::reduceLiteral(OSQLParseNode*& pLiteral, bool bAppendBlank)
4766 OSL_ENSURE(pLiteral->isRule(), "This is no Rule");
4767 OSL_ENSURE(pLiteral->count() == 2, "OSQLParser::ReduceLiteral() Invalid count");
4768 OSQLParseNode* pTemp = pLiteral;
4769 OUStringBuffer aValue(pLiteral->getChild(0)->getTokenValue());
4770 if (bAppendBlank)
4772 aValue.appendAscii(" ");
4775 aValue.append(pLiteral->getChild(1)->getTokenValue());
4777 pLiteral = new OSQLInternalNode(aValue.makeStringAndClear(),SQLNodeType::String);
4778 delete pTemp;
4782 void OSQLParser::error(const sal_Char *fmt)
4784 if(m_sErrorMessage.isEmpty())
4786 OUString sStr(fmt,strlen(fmt),RTL_TEXTENCODING_UTF8);
4787 OUString sSQL_TOKEN("SQL_TOKEN_");
4789 sal_Int32 nPos1 = sStr.indexOf(sSQL_TOKEN);
4790 if(nPos1 != -1)
4792 OUString sFirst = sStr.copy(0,nPos1);
4793 sal_Int32 nPos2 = sStr.indexOf(sSQL_TOKEN,nPos1+1);
4794 if(nPos2 != -1)
4796 OUString sSecond = sStr.copy(nPos1+sSQL_TOKEN.getLength(),nPos2-nPos1-sSQL_TOKEN.getLength());
4797 sFirst += sSecond;
4798 sFirst += sStr.copy(nPos2+sSQL_TOKEN.getLength());
4800 else
4801 sFirst += sStr.copy(nPos1+sSQL_TOKEN.getLength());
4803 m_sErrorMessage = sFirst;
4805 else
4806 m_sErrorMessage = sStr;
4808 OUString aError = s_pScanner->getErrorMessage();
4809 if(!aError.isEmpty())
4811 m_sErrorMessage += ", ";
4812 m_sErrorMessage += aError;
4817 int OSQLParser::SQLlex()
4819 return s_pScanner->SQLlex();
4822 #if defined _MSC_VER
4823 #pragma warning(pop)
4824 #endif