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