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