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