preproc.y
上传用户:blenddy
上传日期:2007-01-07
资源大小:6495k
文件大小:172k
- */
- join_clause_with_union: join_clause
- { $$ = $1; }
- | table_expr UNION JOIN table_expr
- { yyerror("UNION JOIN not yet implemented"); }
- ;
- join_clause: table_expr join_list
- {
- $$ = cat2_str($1, $2);
- }
- ;
- join_list: join_list join_expr
- {
- $$ = cat2_str($1, $2);
- }
- | join_expr
- {
- $$ = $1;
- }
- ;
- /* This is everything but the left side of a join.
- * Note that a CROSS JOIN is the same as an unqualified
- * inner join, so just pass back the right-side table.
- * A NATURAL JOIN implicitly matches column names between
- * tables, so we'll collect those during the later transformation.
- */
- join_expr: join_type JOIN table_expr join_qual
- {
- $$ = cat4_str($1, make1_str("join"), $3, $4);
- }
- | NATURAL join_type JOIN table_expr
- {
- $$ = cat4_str(make1_str("natural"), $2, make1_str("join"), $4);
- }
- | CROSS JOIN table_expr
- { $$ = cat2_str(make1_str("cross join"), $3); }
- ;
- /* OUTER is just noise... */
- join_type: FULL join_outer
- {
- $$ = cat2_str(make1_str("full"), $2);
- fprintf(stderr,"FULL OUTER JOIN not yet implementedn");
- }
- | LEFT join_outer
- {
- $$ = cat2_str(make1_str("left"), $2);
- fprintf(stderr,"LEFT OUTER JOIN not yet implementedn");
- }
- | RIGHT join_outer
- {
- $$ = cat2_str(make1_str("right"), $2);
- fprintf(stderr,"RIGHT OUTER JOIN not yet implementedn");
- }
- | OUTER_P
- {
- $$ = make1_str("outer");
- fprintf(stderr,"OUTER JOIN not yet implementedn");
- }
- | INNER_P
- {
- $$ = make1_str("inner");
- }
- | /* EMPTY */
- {
- $$ = make1_str("");
- }
- join_outer: OUTER_P { $$ = make1_str("outer"); }
- | /*EMPTY*/ { $$ = make1_str(""); /* no qualifiers */ }
- ;
- /* JOIN qualification clauses
- * Possibilities are:
- * USING ( column list ) allows only unqualified column names,
- * which must match between tables.
- * ON expr allows more general qualifications.
- * - thomas 1999-01-07
- */
- join_qual: USING '(' using_list ')' { $$ = make3_str(make1_str("using ("), $3, make1_str(")")); }
- | ON a_expr { $$ = cat2_str(make1_str("on"), $2); }
- ;
- using_list: using_list ',' using_expr { $$ = make3_str($1, make1_str(","), $3); }
- | using_expr { $$ = $1; }
- ;
- using_expr: ColId
- {
- $$ = $1;
- }
- ;
- where_clause: WHERE a_expr { $$ = cat2_str(make1_str("where"), $2); }
- | /*EMPTY*/ { $$ = make1_str(""); /* no qualifiers */ }
- ;
- relation_expr: relation_name
- {
- /* normal relations */
- $$ = $1;
- }
- | relation_name '*' %prec '='
- {
- /* inheritance query */
- $$ = cat2_str($1, make1_str("*"));
- }
- opt_array_bounds: '[' ']' nest_array_bounds
- {
- $$.index1 = 0;
- $$.index2 = $3.index1;
- $$.str = cat2_str(make1_str("[]"), $3.str);
- }
- | '[' Iresult ']' nest_array_bounds
- {
- char *txt = mm_alloc(20L);
- sprintf (txt, "%d", $2);
- $$.index1 = $2;
- $$.index2 = $4.index1;
- $$.str = cat4_str(make1_str("["), txt, make1_str("]"), $4.str);
- }
- | /* EMPTY */
- {
- $$.index1 = -1;
- $$.index2 = -1;
- $$.str= make1_str("");
- }
- ;
- nest_array_bounds: '[' ']' nest_array_bounds
- {
- $$.index1 = 0;
- $$.index2 = $3.index1;
- $$.str = cat2_str(make1_str("[]"), $3.str);
- }
- | '[' Iresult ']' nest_array_bounds
- {
- char *txt = mm_alloc(20L);
- sprintf (txt, "%d", $2);
- $$.index1 = $2;
- $$.index2 = $4.index1;
- $$.str = cat4_str(make1_str("["), txt, make1_str("]"), $4.str);
- }
- | /* EMPTY */
- {
- $$.index1 = -1;
- $$.index2 = -1;
- $$.str= make1_str("");
- }
- ;
- Iresult: Iconst { $$ = atol($1); }
- | '(' Iresult ')' { $$ = $2; }
- | Iresult '+' Iresult { $$ = $1 + $3; }
- | Iresult '-' Iresult { $$ = $1 - $3; }
- | Iresult '*' Iresult { $$ = $1 * $3; }
- | Iresult '/' Iresult { $$ = $1 / $3; }
- | Iresult '%' Iresult { $$ = $1 % $3; }
- ;
- /*****************************************************************************
- *
- * Type syntax
- * SQL92 introduces a large amount of type-specific syntax.
- * Define individual clauses to handle these cases, and use
- * the generic case to handle regular type-extensible Postgres syntax.
- * - thomas 1997-10-10
- *
- *****************************************************************************/
- Typename: Array opt_array_bounds
- {
- $$ = cat2_str($1, $2.str);
- }
- | SETOF Array
- {
- $$ = cat2_str(make1_str("setof"), $2);
- }
- ;
- Array: Generic { $$ = $1; }
- | Datetime { $$ = $1; }
- | Numeric { $$ = $1; }
- | Character { $$ = $1; }
- ;
- Generic: generic
- {
- $$ = $1;
- }
- ;
- generic: ident { $$ = $1; }
- | TYPE_P { $$ = make1_str("type"); }
- | SQL_AT { $$ = make1_str("at"); }
- | SQL_AUTOCOMMIT { $$ = make1_str("autocommit"); }
- | SQL_BOOL { $$ = make1_str("bool"); }
- | SQL_BREAK { $$ = make1_str("break"); }
- | SQL_CALL { $$ = make1_str("call"); }
- | SQL_CONNECT { $$ = make1_str("connect"); }
- | SQL_CONNECTION { $$ = make1_str("connection"); }
- | SQL_CONTINUE { $$ = make1_str("continue"); }
- | SQL_DEALLOCATE { $$ = make1_str("deallocate"); }
- | SQL_DISCONNECT { $$ = make1_str("disconnect"); }
- | SQL_FOUND { $$ = make1_str("found"); }
- | SQL_GO { $$ = make1_str("go"); }
- | SQL_GOTO { $$ = make1_str("goto"); }
- | SQL_IDENTIFIED { $$ = make1_str("identified"); }
- | SQL_IMMEDIATE { $$ = make1_str("immediate"); }
- | SQL_INDICATOR { $$ = make1_str("indicator"); }
- | SQL_INT { $$ = make1_str("int"); }
- | SQL_LONG { $$ = make1_str("long"); }
- | SQL_OFF { $$ = make1_str("off"); }
- | SQL_OPEN { $$ = make1_str("open"); }
- | SQL_PREPARE { $$ = make1_str("prepare"); }
- | SQL_RELEASE { $$ = make1_str("release"); }
- | SQL_SECTION { $$ = make1_str("section"); }
- | SQL_SHORT { $$ = make1_str("short"); }
- | SQL_SIGNED { $$ = make1_str("signed"); }
- | SQL_SQLERROR { $$ = make1_str("sqlerror"); }
- | SQL_SQLPRINT { $$ = make1_str("sqlprint"); }
- | SQL_SQLWARNING { $$ = make1_str("sqlwarning"); }
- | SQL_STOP { $$ = make1_str("stop"); }
- | SQL_STRUCT { $$ = make1_str("struct"); }
- | SQL_UNSIGNED { $$ = make1_str("unsigned"); }
- | SQL_VAR { $$ = make1_str("var"); }
- | SQL_WHENEVER { $$ = make1_str("whenever"); }
- ;
- /* SQL92 numeric data types
- * Check FLOAT() precision limits assuming IEEE floating types.
- * Provide real DECIMAL() and NUMERIC() implementations now - Jan 1998-12-30
- * - thomas 1997-09-18
- */
- Numeric: FLOAT opt_float
- {
- $$ = cat2_str(make1_str("float"), $2);
- }
- | DOUBLE PRECISION
- {
- $$ = make1_str("double precision");
- }
- | DECIMAL opt_decimal
- {
- $$ = cat2_str(make1_str("decimal"), $2);
- }
- | NUMERIC opt_numeric
- {
- $$ = cat2_str(make1_str("numeric"), $2);
- }
- ;
- numeric: FLOAT
- { $$ = make1_str("float"); }
- | DOUBLE PRECISION
- { $$ = make1_str("double precision"); }
- | DECIMAL
- { $$ = make1_str("decimal"); }
- | NUMERIC
- { $$ = make1_str("numeric"); }
- ;
- opt_float: '(' Iconst ')'
- {
- if (atol($2) < 1)
- yyerror("precision for FLOAT must be at least 1");
- else if (atol($2) >= 16)
- yyerror("precision for FLOAT must be less than 16");
- $$ = make3_str(make1_str("("), $2, make1_str(")"));
- }
- | /*EMPTY*/
- {
- $$ = make1_str("");
- }
- ;
- opt_numeric: '(' Iconst ',' Iconst ')'
- {
- if (atol($2) < 1 || atol($2) > NUMERIC_MAX_PRECISION) {
- sprintf(errortext, "NUMERIC precision %s must be between 1 and %d", $2, NUMERIC_MAX_PRECISION);
- yyerror(errortext);
- }
- if (atol($4) < 0 || atol($4) > atol($2)) {
- sprintf(errortext, "NUMERIC scale %s must be between 0 and precision %s", $4, $2);
- yyerror(errortext);
- }
- $$ = cat3_str(make2_str(make1_str("("), $2), make1_str(","), make2_str($4, make1_str(")")));
- }
- | '(' Iconst ')'
- {
- if (atol($2) < 1 || atol($2) > NUMERIC_MAX_PRECISION) {
- sprintf(errortext, "NUMERIC precision %s must be between 1 and %d", $2, NUMERIC_MAX_PRECISION);
- yyerror(errortext);
- }
- $$ = make3_str(make1_str("("), $2, make1_str(")"));
- }
- | /*EMPTY*/
- {
- $$ = make1_str("");
- }
- ;
- opt_decimal: '(' Iconst ',' Iconst ')'
- {
- if (atol($2) < 1 || atol($2) > NUMERIC_MAX_PRECISION) {
- sprintf(errortext, "NUMERIC precision %s must be between 1 and %d", $2, NUMERIC_MAX_PRECISION);
- yyerror(errortext);
- }
- if (atol($4) < 0 || atol($4) > atol($2)) {
- sprintf(errortext, "NUMERIC scale %s must be between 0 and precision %s", $4, $2);
- yyerror(errortext);
- }
- $$ = cat3_str(make2_str(make1_str("("), $2), make1_str(","), make2_str($4, make1_str(")")));
- }
- | '(' Iconst ')'
- {
- if (atol($2) < 1 || atol($2) > NUMERIC_MAX_PRECISION) {
- sprintf(errortext, "NUMERIC precision %s must be between 1 and %d", $2, NUMERIC_MAX_PRECISION);
- yyerror(errortext);
- }
- $$ = make3_str(make1_str("("), $2, make1_str(")"));
- }
- | /*EMPTY*/
- {
- $$ = make1_str("");
- }
- ;
- /* SQL92 character data types
- * The following implements CHAR() and VARCHAR().
- * - ay 6/95
- */
- Character: character '(' Iconst ')'
- {
- if (strncasecmp($1, "char", strlen("char")) && strncasecmp($1, "varchar", strlen("varchar")))
- yyerror("internal parsing error; unrecognized character type");
- if (atol($3) < 1) {
- sprintf(errortext, "length for '%s' type must be at least 1",$1);
- yyerror(errortext);
- }
- else if (atol($3) > MaxAttrSize) {
- sprintf(errortext, "length for type '%s' cannot exceed %ld",$1,(long) MaxAttrSize);
- yyerror(errortext);
- }
- $$ = cat2_str($1, make3_str(make1_str("("), $3, make1_str(")")));
- }
- | character
- {
- $$ = $1;
- }
- ;
- character: CHARACTER opt_varying opt_charset opt_collate
- {
- if (strlen($4) > 0)
- fprintf(stderr, "COLLATE %s not yet implemented",$4);
- $$ = cat4_str(make1_str("character"), $2, $3, $4);
- }
- | CHAR opt_varying { $$ = cat2_str(make1_str("char"), $2); }
- | VARCHAR { $$ = make1_str("varchar"); }
- | NATIONAL CHARACTER opt_varying { $$ = cat2_str(make1_str("national character"), $3); }
- | NCHAR opt_varying { $$ = cat2_str(make1_str("nchar"), $2); }
- ;
- opt_varying: VARYING { $$ = make1_str("varying"); }
- | /*EMPTY*/ { $$ = make1_str(""); }
- ;
- opt_charset: CHARACTER SET ColId { $$ = cat2_str(make1_str("character set"), $3); }
- | /*EMPTY*/ { $$ = make1_str(""); }
- ;
- opt_collate: COLLATE ColId { $$ = cat2_str(make1_str("collate"), $2); }
- | /*EMPTY*/ { $$ = make1_str(""); }
- ;
- Datetime: datetime
- {
- $$ = $1;
- }
- | TIMESTAMP opt_timezone
- {
- $$ = cat2_str(make1_str("timestamp"), $2);
- }
- | TIME
- {
- $$ = make1_str("time");
- }
- | INTERVAL opt_interval
- {
- $$ = cat2_str(make1_str("interval"), $2);
- }
- ;
- datetime: YEAR_P { $$ = make1_str("year"); }
- | MONTH_P { $$ = make1_str("month"); }
- | DAY_P { $$ = make1_str("day"); }
- | HOUR_P { $$ = make1_str("hour"); }
- | MINUTE_P { $$ = make1_str("minute"); }
- | SECOND_P { $$ = make1_str("second"); }
- ;
- opt_timezone: WITH TIME ZONE { $$ = make1_str("with time zone"); }
- | /*EMPTY*/ { $$ = make1_str(""); }
- ;
- opt_interval: datetime { $$ = $1; }
- | YEAR_P TO MONTH_P { $$ = make1_str("year to #month"); }
- | DAY_P TO HOUR_P { $$ = make1_str("day to hour"); }
- | DAY_P TO MINUTE_P { $$ = make1_str("day to minute"); }
- | DAY_P TO SECOND_P { $$ = make1_str("day to second"); }
- | HOUR_P TO MINUTE_P { $$ = make1_str("hour to minute"); }
- | MINUTE_P TO SECOND_P { $$ = make1_str("minute to second"); }
- | HOUR_P TO SECOND_P { $$ = make1_str("hour to second"); }
- | /*EMPTY*/ { $$ = make1_str(""); }
- ;
- /*****************************************************************************
- *
- * expression grammar, still needs some cleanup
- *
- *****************************************************************************/
- a_expr_or_null: a_expr
- { $$ = $1; }
- | NULL_P
- {
- $$ = make1_str("null");
- }
- ;
- /* Expressions using row descriptors
- * Define row_descriptor to allow yacc to break the reduce/reduce conflict
- * with singleton expressions.
- * Eliminated lots of code by defining row_op and sub_type clauses.
- * However, can not consolidate EXPR_LINK case with others subselects
- * due to shift/reduce conflict with the non-subselect clause (the parser
- * would have to look ahead more than one token to resolve the conflict).
- * - thomas 1998-05-09
- */
- row_expr: '(' row_descriptor ')' IN '(' SubSelect ')'
- {
- $$ = make5_str(make1_str("("), $2, make1_str(") in ("), $6, make1_str(")"));
- }
- | '(' row_descriptor ')' NOT IN '(' SubSelect ')'
- {
- $$ = make5_str(make1_str("("), $2, make1_str(") not in ("), $7, make1_str(")"));
- }
- | '(' row_descriptor ')' row_op sub_type '(' SubSelect ')'
- {
- $$ = make4_str(make5_str(make1_str("("), $2, make1_str(")"), $4, $5), make1_str("("), $7, make1_str(")"));
- }
- | '(' row_descriptor ')' row_op '(' SubSelect ')'
- {
- $$ = make3_str(make5_str(make1_str("("), $2, make1_str(")"), $4, make1_str("(")), $6, make1_str(")"));
- }
- | '(' row_descriptor ')' row_op '(' row_descriptor ')'
- {
- $$ = cat3_str(make3_str(make1_str("("), $2, make1_str(")")), $4, make3_str(make1_str("("), $6, make1_str(")")));
- }
- ;
- row_descriptor: row_list ',' a_expr
- {
- $$ = cat3_str($1, make1_str(","), $3);
- }
- ;
- row_op: Op { $$ = $1; }
- | '<' { $$ = "<"; }
- | '=' { $$ = "="; }
- | '>' { $$ = ">"; }
- | '+' { $$ = "+"; }
- | '-' { $$ = "-"; }
- | '*' { $$ = "*"; }
- | '%' { $$ = "%"; }
- | '/' { $$ = "/"; }
- ;
- sub_type: ANY { $$ = make1_str("ANY"); }
- | ALL { $$ = make1_str("ALL"); }
- ;
- row_list: row_list ',' a_expr
- {
- $$ = cat3_str($1, make1_str(","), $3);
- }
- | a_expr
- {
- $$ = $1;
- }
- ;
- /* General expressions
- * This is the heart of the expression syntax.
- * Note that the BETWEEN clause looks similar to a boolean expression
- * and so we must define b_expr which is almost the same as a_expr
- * but without the boolean expressions.
- * All operations/expressions are allowed in a BETWEEN clause
- * if surrounded by parens.
- */
- a_expr: attr opt_indirection
- {
- $$ = cat2_str($1, $2);
- }
- | row_expr
- { $$ = $1; }
- | AexprConst
- { $$ = $1; }
- | ColId
- {
- $$ = $1;
- }
- | '-' a_expr %prec UMINUS
- { $$ = cat2_str(make1_str("-"), $2); }
- | '%' a_expr
- { $$ = cat2_str(make1_str("%"), $2); }
- | a_expr '%'
- { $$ = cat2_str($1, make1_str("%")); }
- | a_expr '+' a_expr
- { $$ = cat3_str($1, make1_str("+"), $3); }
- | a_expr '-' a_expr
- { $$ = cat3_str($1, make1_str("-"), $3); }
- | a_expr '/' a_expr
- { $$ = cat3_str($1, make1_str("/"), $3); }
- | a_expr '%' a_expr
- { $$ = cat3_str($1, make1_str("%"), $3); }
- | a_expr '*' a_expr
- { $$ = cat3_str($1, make1_str("*"), $3); }
- | a_expr '<' a_expr
- { $$ = cat3_str($1, make1_str("<"), $3); }
- | a_expr '>' a_expr
- { $$ = cat3_str($1, make1_str(">"), $3); }
- | a_expr '=' NULL_P
- { $$ = cat2_str($1, make1_str("= NULL")); }
- | NULL_P '=' a_expr
- { $$ = cat2_str(make1_str("= NULL"), $3); }
- | a_expr '=' a_expr
- { $$ = cat3_str($1, make1_str("="), $3); }
- /* not possible in embedded sql | ':' a_expr
- { $$ = cat2_str(make1_str(":"), $2); }
- */
- | ';' a_expr
- { $$ = cat2_str(make1_str(";"), $2); }
- | '|' a_expr
- { $$ = cat2_str(make1_str("|"), $2); }
- | a_expr TYPECAST Typename
- {
- $$ = cat3_str($1, make1_str("::"), $3);
- }
- | CAST '(' a_expr AS Typename ')'
- {
- $$ = cat3_str(make2_str(make1_str("cast("), $3), make1_str("as"), make2_str($5, make1_str(")")));
- }
- | '(' a_expr_or_null ')'
- { $$ = make3_str(make1_str("("), $2, make1_str(")")); }
- | a_expr Op a_expr
- { $$ = cat3_str($1, $2, $3); }
- | a_expr LIKE a_expr
- { $$ = cat3_str($1, make1_str("like"), $3); }
- | a_expr NOT LIKE a_expr
- { $$ = cat3_str($1, make1_str("not like"), $4); }
- | Op a_expr
- { $$ = cat2_str($1, $2); }
- | a_expr Op
- { $$ = cat2_str($1, $2); }
- | func_name '(' '*' ')'
- {
- $$ = cat2_str($1, make1_str("(*)"));
- }
- | func_name '(' ')'
- {
- $$ = cat2_str($1, make1_str("()"));
- }
- | func_name '(' expr_list ')'
- {
- $$ = make4_str($1, make1_str("("), $3, make1_str(")"));
- }
- | CURRENT_DATE
- {
- $$ = make1_str("current_date");
- }
- | CURRENT_TIME
- {
- $$ = make1_str("current_time");
- }
- | CURRENT_TIME '(' Iconst ')'
- {
- if (atol($3) != 0)
- fprintf(stderr,"CURRENT_TIME(%s) precision not implemented; zero used instead", $3);
- $$ = make1_str("current_time");
- }
- | CURRENT_TIMESTAMP
- {
- $$ = make1_str("current_timestamp");
- }
- | CURRENT_TIMESTAMP '(' Iconst ')'
- {
- if (atol($3) != 0)
- fprintf(stderr,"CURRENT_TIMESTAMP(%s) precision not implemented; zero used instead",$3);
- $$ = make1_str("current_timestamp");
- }
- | CURRENT_USER
- {
- $$ = make1_str("current_user");
- }
- | USER
- {
- $$ = make1_str("user");
- }
- | EXISTS '(' SubSelect ')'
- {
- $$ = make3_str(make1_str("exists("), $3, make1_str(")"));
- }
- | EXTRACT '(' extract_list ')'
- {
- $$ = make3_str(make1_str("extract("), $3, make1_str(")"));
- }
- | POSITION '(' position_list ')'
- {
- $$ = make3_str(make1_str("position("), $3, make1_str(")"));
- }
- | SUBSTRING '(' substr_list ')'
- {
- $$ = make3_str(make1_str("substring("), $3, make1_str(")"));
- }
- /* various trim expressions are defined in SQL92 - thomas 1997-07-19 */
- | TRIM '(' BOTH trim_list ')'
- {
- $$ = make3_str(make1_str("trim(both"), $4, make1_str(")"));
- }
- | TRIM '(' LEADING trim_list ')'
- {
- $$ = make3_str(make1_str("trim(leading"), $4, make1_str(")"));
- }
- | TRIM '(' TRAILING trim_list ')'
- {
- $$ = make3_str(make1_str("trim(trailing"), $4, make1_str(")"));
- }
- | TRIM '(' trim_list ')'
- {
- $$ = make3_str(make1_str("trim("), $3, make1_str(")"));
- }
- | a_expr ISNULL
- { $$ = cat2_str($1, make1_str("isnull")); }
- | a_expr IS NULL_P
- { $$ = cat2_str($1, make1_str("is null")); }
- | a_expr NOTNULL
- { $$ = cat2_str($1, make1_str("notnull")); }
- | a_expr IS NOT NULL_P
- { $$ = cat2_str($1, make1_str("is not null")); }
- /* IS TRUE, IS FALSE, etc used to be function calls
- * but let's make them expressions to allow the optimizer
- * a chance to eliminate them if a_expr is a constant string.
- * - thomas 1997-12-22
- */
- | a_expr IS TRUE_P
- {
- { $$ = cat2_str($1, make1_str("is true")); }
- }
- | a_expr IS NOT FALSE_P
- {
- { $$ = cat2_str($1, make1_str("is not false")); }
- }
- | a_expr IS FALSE_P
- {
- { $$ = cat2_str($1, make1_str("is false")); }
- }
- | a_expr IS NOT TRUE_P
- {
- { $$ = cat2_str($1, make1_str("is not true")); }
- }
- | a_expr BETWEEN b_expr AND b_expr
- {
- $$ = cat5_str($1, make1_str("between"), $3, make1_str("and"), $5);
- }
- | a_expr NOT BETWEEN b_expr AND b_expr
- {
- $$ = cat5_str($1, make1_str("not between"), $4, make1_str("and"), $6);
- }
- | a_expr IN '(' in_expr ')'
- {
- $$ = make4_str($1, make1_str(" in ("), $4, make1_str(")"));
- }
- | a_expr NOT IN '(' not_in_expr ')'
- {
- $$ = make4_str($1, make1_str(" not in ("), $5, make1_str(")"));
- }
- | a_expr Op '(' SubSelect ')'
- {
- $$ = cat3_str($1, $2, make3_str(make1_str("("), $4, make1_str(")")));
- }
- | a_expr '+' '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("+("), $4, make1_str(")"));
- }
- | a_expr '-' '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("-("), $4, make1_str(")"));
- }
- | a_expr '/' '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("/("), $4, make1_str(")"));
- }
- | a_expr '%' '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("%("), $4, make1_str(")"));
- }
- | a_expr '*' '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("*("), $4, make1_str(")"));
- }
- | a_expr '<' '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("<("), $4, make1_str(")"));
- }
- | a_expr '>' '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str(">("), $4, make1_str(")"));
- }
- | a_expr '=' '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("=("), $4, make1_str(")"));
- }
- | a_expr Op ANY '(' SubSelect ')'
- {
- $$ = cat3_str($1, $2, make3_str(make1_str("any("), $5, make1_str(")")));
- }
- | a_expr '+' ANY '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("+ any("), $5, make1_str(")"));
- }
- | a_expr '-' ANY '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("- any("), $5, make1_str(")"));
- }
- | a_expr '/' ANY '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("/ any("), $5, make1_str(")"));
- }
- | a_expr '%' ANY '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("% any("), $5, make1_str(")"));
- }
- | a_expr '*' ANY '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("* any("), $5, make1_str(")"));
- }
- | a_expr '<' ANY '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("< any("), $5, make1_str(")"));
- }
- | a_expr '>' ANY '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("> any("), $5, make1_str(")"));
- }
- | a_expr '=' ANY '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("= any("), $5, make1_str(")"));
- }
- | a_expr Op ALL '(' SubSelect ')'
- {
- $$ = cat3_str($1, $2, make3_str(make1_str("all ("), $5, make1_str(")")));
- }
- | a_expr '+' ALL '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("+ all("), $5, make1_str(")"));
- }
- | a_expr '-' ALL '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("- all("), $5, make1_str(")"));
- }
- | a_expr '/' ALL '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("/ all("), $5, make1_str(")"));
- }
- | a_expr '%' ALL '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("% all("), $5, make1_str(")"));
- }
- | a_expr '*' ALL '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("* all("), $5, make1_str(")"));
- }
- | a_expr '<' ALL '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("< all("), $5, make1_str(")"));
- }
- | a_expr '>' ALL '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("> all("), $5, make1_str(")"));
- }
- | a_expr '=' ALL '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("= all("), $5, make1_str(")"));
- }
- | a_expr AND a_expr
- { $$ = cat3_str($1, make1_str("and"), $3); }
- | a_expr OR a_expr
- { $$ = cat3_str($1, make1_str("or"), $3); }
- | NOT a_expr
- { $$ = cat2_str(make1_str("not"), $2); }
- | case_expr
- { $$ = $1; }
- | cinputvariable
- { $$ = make1_str("?"); }
- ;
- /* Restricted expressions
- * b_expr is a subset of the complete expression syntax
- * defined by a_expr. b_expr is used in BETWEEN clauses
- * to eliminate parser ambiguities stemming from the AND keyword.
- */
- b_expr: attr opt_indirection
- {
- $$ = cat2_str($1, $2);
- }
- | AexprConst
- { $$ = $1; }
- | ColId
- {
- $$ = $1;
- }
- | '-' b_expr %prec UMINUS
- { $$ = cat2_str(make1_str("-"), $2); }
- | '%' b_expr
- { $$ = cat2_str(make1_str("%"), $2); }
- | b_expr '%'
- { $$ = cat2_str($1, make1_str("%")); }
- | b_expr '+' b_expr
- { $$ = cat3_str($1, make1_str("+"), $3); }
- | b_expr '-' b_expr
- { $$ = cat3_str($1, make1_str("-"), $3); }
- | b_expr '/' b_expr
- { $$ = cat3_str($1, make1_str("/"), $3); }
- | b_expr '%' b_expr
- { $$ = cat3_str($1, make1_str("%"), $3); }
- | b_expr '*' b_expr
- { $$ = cat3_str($1, make1_str("*"), $3); }
- /* not possible in embedded sql | ':' b_expr
- { $$ = cat2_str(make1_str(":"), $2); }
- */
- | ';' b_expr
- { $$ = cat2_str(make1_str(";"), $2); }
- | '|' b_expr
- { $$ = cat2_str(make1_str("|"), $2); }
- | b_expr TYPECAST Typename
- {
- $$ = cat3_str($1, make1_str("::"), $3);
- }
- | CAST '(' b_expr AS Typename ')'
- {
- $$ = cat3_str(make2_str(make1_str("cast("), $3), make1_str("as"), make2_str($5, make1_str(")")));
- }
- | '(' a_expr ')'
- { $$ = make3_str(make1_str("("), $2, make1_str(")")); }
- | b_expr Op b_expr
- { $$ = cat3_str($1, $2, $3); }
- | Op b_expr
- { $$ = cat2_str($1, $2); }
- | b_expr Op
- { $$ = cat2_str($1, $2); }
- | func_name '(' ')'
- {
- $$ = cat2_str($1, make1_str("()"));
- }
- | func_name '(' expr_list ')'
- {
- $$ = make4_str($1, make1_str("("), $3, make1_str(")"));
- }
- | CURRENT_DATE
- {
- $$ = make1_str("current_date");
- }
- | CURRENT_TIME
- {
- $$ = make1_str("current_time");
- }
- | CURRENT_TIME '(' Iconst ')'
- {
- if ($3 != 0)
- fprintf(stderr,"CURRENT_TIME(%s) precision not implemented; zero used instead", $3);
- $$ = make1_str("current_time");
- }
- | CURRENT_TIMESTAMP
- {
- $$ = make1_str("current_timestamp");
- }
- | CURRENT_TIMESTAMP '(' Iconst ')'
- {
- if (atol($3) != 0)
- fprintf(stderr,"CURRENT_TIMESTAMP(%s) precision not implemented; zero used instead",$3);
- $$ = make1_str("current_timestamp");
- }
- | CURRENT_USER
- {
- $$ = make1_str("current_user");
- }
- | USER
- {
- $$ = make1_str("user");
- }
- | POSITION '(' position_list ')'
- {
- $$ = make3_str(make1_str("position ("), $3, make1_str(")"));
- }
- | SUBSTRING '(' substr_list ')'
- {
- $$ = make3_str(make1_str("substring ("), $3, make1_str(")"));
- }
- /* various trim expressions are defined in SQL92 - thomas 1997-07-19 */
- | TRIM '(' BOTH trim_list ')'
- {
- $$ = make3_str(make1_str("trim(both"), $4, make1_str(")"));
- }
- | TRIM '(' LEADING trim_list ')'
- {
- $$ = make3_str(make1_str("trim(leading"), $4, make1_str(")"));
- }
- | TRIM '(' TRAILING trim_list ')'
- {
- $$ = make3_str(make1_str("trim(trailing"), $4, make1_str(")"));
- }
- | TRIM '(' trim_list ')'
- {
- $$ = make3_str(make1_str("trim("), $3, make1_str(")"));
- }
- | civariableonly
- { $$ = $1; }
- ;
- opt_indirection: '[' ecpg_expr ']' opt_indirection
- {
- $$ = cat4_str(make1_str("["), $2, make1_str("]"), $4);
- }
- | '[' ecpg_expr ':' ecpg_expr ']' opt_indirection
- {
- $$ = cat2_str(cat5_str(make1_str("["), $2, make1_str(":"), $4, make1_str("]")), $6);
- }
- | /* EMPTY */
- { $$ = make1_str(""); }
- ;
- expr_list: a_expr_or_null
- { $$ = $1; }
- | expr_list ',' a_expr_or_null
- { $$ = cat3_str($1, make1_str(","), $3); }
- | expr_list USING a_expr
- { $$ = cat3_str($1, make1_str("using"), $3); }
- ;
- extract_list: extract_arg FROM a_expr
- {
- $$ = cat3_str($1, make1_str("from"), $3);
- }
- | /* EMPTY */
- { $$ = make1_str(""); }
- | cinputvariable
- { $$ = make1_str("?"); }
- ;
- extract_arg: datetime { $$ = $1; }
- | TIMEZONE_HOUR { $$ = make1_str("timezone_hour"); }
- | TIMEZONE_MINUTE { $$ = make1_str("timezone_minute"); }
- ;
- position_list: position_expr IN position_expr
- { $$ = cat3_str($1, make1_str("in"), $3); }
- | /* EMPTY */
- { $$ = make1_str(""); }
- ;
- position_expr: attr opt_indirection
- {
- $$ = cat2_str($1, $2);
- }
- | AexprConst
- { $$ = $1; }
- | '-' position_expr %prec UMINUS
- { $$ = cat2_str(make1_str("-"), $2); }
- | position_expr '+' position_expr
- { $$ = cat3_str($1, make1_str("+"), $3); }
- | position_expr '-' position_expr
- { $$ = cat3_str($1, make1_str("-"), $3); }
- | position_expr '/' position_expr
- { $$ = cat3_str($1, make1_str("/"), $3); }
- | position_expr '%' position_expr
- { $$ = cat3_str($1, make1_str("%"), $3); }
- | position_expr '*' position_expr
- { $$ = cat3_str($1, make1_str("*"), $3); }
- | '|' position_expr
- { $$ = cat2_str(make1_str("|"), $2); }
- | position_expr TYPECAST Typename
- {
- $$ = cat3_str($1, make1_str("::"), $3);
- }
- | CAST '(' position_expr AS Typename ')'
- {
- $$ = cat3_str(make2_str(make1_str("cast("), $3), make1_str("as"), make2_str($5, make1_str(")")));
- }
- | '(' position_expr ')'
- { $$ = make3_str(make1_str("("), $2, make1_str(")")); }
- | position_expr Op position_expr
- { $$ = cat3_str($1, $2, $3); }
- | Op position_expr
- { $$ = cat2_str($1, $2); }
- | position_expr Op
- { $$ = cat2_str($1, $2); }
- | ColId
- {
- $$ = $1;
- }
- | func_name '(' ')'
- {
- $$ = cat2_str($1, make1_str("()"));
- }
- | func_name '(' expr_list ')'
- {
- $$ = make4_str($1, make1_str("("), $3, make1_str(")"));
- }
- | POSITION '(' position_list ')'
- {
- $$ = make3_str(make1_str("position("), $3, make1_str(")"));
- }
- | SUBSTRING '(' substr_list ')'
- {
- $$ = make3_str(make1_str("substring("), $3, make1_str(")"));
- }
- /* various trim expressions are defined in SQL92 - thomas 1997-07-19 */
- | TRIM '(' BOTH trim_list ')'
- {
- $$ = make3_str(make1_str("trim(both"), $4, make1_str(")"));
- }
- | TRIM '(' LEADING trim_list ')'
- {
- $$ = make3_str(make1_str("trim(leading"), $4, make1_str(")"));
- }
- | TRIM '(' TRAILING trim_list ')'
- {
- $$ = make3_str(make1_str("trim(trailing"), $4, make1_str(")"));
- }
- | TRIM '(' trim_list ')'
- {
- $$ = make3_str(make1_str("trim("), $3, make1_str(")"));
- }
- ;
- substr_list: expr_list substr_from substr_for
- {
- $$ = cat3_str($1, $2, $3);
- }
- | /* EMPTY */
- { $$ = make1_str(""); }
- ;
- substr_from: FROM expr_list
- { $$ = cat2_str(make1_str("from"), $2); }
- | /* EMPTY */
- {
- $$ = make1_str("");
- }
- ;
- substr_for: FOR expr_list
- { $$ = cat2_str(make1_str("for"), $2); }
- | /* EMPTY */
- { $$ = make1_str(""); }
- ;
- trim_list: a_expr FROM expr_list
- { $$ = cat3_str($1, make1_str("from"), $3); }
- | FROM expr_list
- { $$ = cat2_str(make1_str("from"), $2); }
- | expr_list
- { $$ = $1; }
- ;
- in_expr: SubSelect
- {
- $$ = $1;
- }
- | in_expr_nodes
- { $$ = $1; }
- ;
- in_expr_nodes: AexprConst
- { $$ = $1; }
- | in_expr_nodes ',' AexprConst
- { $$ = cat3_str($1, make1_str(","), $3);}
- ;
- not_in_expr: SubSelect
- {
- $$ = $1;
- }
- | not_in_expr_nodes
- { $$ = $1; }
- ;
- not_in_expr_nodes: AexprConst
- { $$ = $1; }
- | not_in_expr_nodes ',' AexprConst
- { $$ = cat3_str($1, make1_str(","), $3);}
- ;
- /* Case clause
- * Define SQL92-style case clause.
- * Allow all four forms described in the standard:
- * - Full specification
- * CASE WHEN a = b THEN c ... ELSE d END
- * - Implicit argument
- * CASE a WHEN b THEN c ... ELSE d END
- * - Conditional NULL
- * NULLIF(x,y)
- * same as CASE WHEN x = y THEN NULL ELSE x END
- * - Conditional substitution from list, use first non-null argument
- * COALESCE(a,b,...)
- * same as CASE WHEN a IS NOT NULL THEN a WHEN b IS NOT NULL THEN b ... END
- * - thomas 1998-11-09
- */
- case_expr: CASE case_arg when_clause_list case_default END_TRANS
- { $$ = cat5_str(make1_str("case"), $2, $3, $4, make1_str("end")); }
- | NULLIF '(' a_expr ',' a_expr ')'
- {
- $$ = cat5_str(make1_str("nullif("), $3, make1_str(","), $5, make1_str(")"));
- fprintf(stderr, "NULLIF() not yet fully implemented");
- }
- | COALESCE '(' expr_list ')'
- {
- $$ = cat3_str(make1_str("coalesce("), $3, make1_str(")"));
- }
- ;
- when_clause_list: when_clause_list when_clause
- { $$ = cat2_str($1, $2); }
- | when_clause
- { $$ = $1; }
- ;
- when_clause: WHEN a_expr THEN a_expr_or_null
- {
- $$ = cat4_str(make1_str("when"), $2, make1_str("then"), $4);
- }
- ;
- case_default: ELSE a_expr_or_null { $$ = cat2_str(make1_str("else"), $2); }
- | /*EMPTY*/ { $$ = make1_str(""); }
- ;
- case_arg: attr opt_indirection
- {
- $$ = cat2_str($1, $2);
- }
- | ColId
- {
- $$ = $1;
- }
- | /*EMPTY*/
- { $$ = make1_str(""); }
- ;
- attr: relation_name '.' attrs
- {
- $$ = make3_str($1, make1_str("."), $3);
- }
- | ParamNo '.' attrs
- {
- $$ = make3_str($1, make1_str("."), $3);
- }
- ;
- attrs: attr_name
- { $$ = $1; }
- | attrs '.' attr_name
- { $$ = make3_str($1, make1_str("."), $3); }
- | attrs '.' '*'
- { $$ = make2_str($1, make1_str(".*")); }
- ;
- /*****************************************************************************
- *
- * target lists
- *
- *****************************************************************************/
- res_target_list: res_target_list ',' res_target_el
- { $$ = cat3_str($1, make1_str(","),$3); }
- | res_target_el
- { $$ = $1; }
- | '*' { $$ = make1_str("*"); }
- ;
- res_target_el: ColId opt_indirection '=' a_expr_or_null
- {
- $$ = cat4_str($1, $2, make1_str("="), $4);
- }
- | attr opt_indirection
- {
- $$ = cat2_str($1, $2);
- }
- | relation_name '.' '*'
- {
- $$ = make2_str($1, make1_str(".*"));
- }
- ;
- /*
- ** target list for select.
- ** should get rid of the other but is still needed by the defunct select into
- ** and update (uses a subset)
- */
- res_target_list2: res_target_list2 ',' res_target_el2
- { $$ = cat3_str($1, make1_str(","), $3); }
- | res_target_el2
- { $$ = $1; }
- ;
- /* AS is not optional because shift/red conflict with unary ops */
- res_target_el2: a_expr_or_null AS ColLabel
- {
- $$ = cat3_str($1, make1_str("as"), $3);
- }
- | a_expr_or_null
- {
- $$ = $1;
- }
- | relation_name '.' '*'
- {
- $$ = make2_str($1, make1_str(".*"));
- }
- | '*'
- {
- $$ = make1_str("*");
- }
- ;
- opt_id: ColId { $$ = $1; }
- | /* EMPTY */ { $$ = make1_str(""); }
- ;
- relation_name: SpecialRuleRelation
- {
- $$ = $1;
- }
- | ColId
- {
- /* disallow refs to variable system tables */
- if (strcmp(LogRelationName, $1) == 0
- || strcmp(VariableRelationName, $1) == 0) {
- sprintf(errortext, make1_str("%s cannot be accessed by users"),$1);
- yyerror(errortext);
- }
- else
- $$ = $1;
- }
- ;
- database_name: ColId { $$ = $1; };
- access_method: ident { $$ = $1; };
- attr_name: ColId { $$ = $1; };
- class: ident { $$ = $1; };
- index_name: ColId { $$ = $1; };
- /* Functions
- * Include date/time keywords as SQL92 extension.
- * Include TYPE as a SQL92 unreserved keyword. - thomas 1997-10-05
- */
- name: ColId { $$ = $1; };
- func_name: ColId { $$ = $1; };
- file_name: Sconst { $$ = $1; };
- /* NOT USED recipe_name: ident { $$ = $1; };*/
- /* Constants
- * Include TRUE/FALSE for SQL3 support. - thomas 1997-10-24
- */
- AexprConst: Iconst
- {
- $$ = $1;
- }
- | Fconst
- {
- $$ = $1;
- }
- | Sconst
- {
- $$ = $1;
- }
- | Typename Sconst
- {
- $$ = cat2_str($1, $2);
- }
- | ParamNo
- { $$ = $1; }
- | TRUE_P
- {
- $$ = make1_str("true");
- }
- | FALSE_P
- {
- $$ = make1_str("false");
- }
- ;
- ParamNo: PARAM opt_indirection
- {
- $$ = cat2_str(make_name(), $2);
- }
- ;
- Iconst: ICONST { $$ = make_name();};
- Fconst: FCONST { $$ = make_name();};
- Sconst: SCONST {
- $$ = (char *)mm_alloc(strlen($1) + 3);
- $$[0]=''';
- strcpy($$+1, $1);
- $$[strlen($1)+2]=' ';
- $$[strlen($1)+1]=''';
- free($1);
- }
- UserId: ident { $$ = $1;};
- /* Column and type identifier
- * Does not include explicit datetime types
- * since these must be decoupled in Typename syntax.
- * Use ColId for most identifiers. - thomas 1997-10-21
- */
- TypeId: ColId
- { $$ = $1; }
- | numeric
- { $$ = $1; }
- | character
- { $$ = $1; }
- ;
- /* Column identifier
- * Include date/time keywords as SQL92 extension.
- * Include TYPE as a SQL92 unreserved keyword. - thomas 1997-10-05
- * Add other keywords. Note that as the syntax expands,
- * some of these keywords will have to be removed from this
- * list due to shift/reduce conflicts in yacc. If so, move
- * down to the ColLabel entity. - thomas 1997-11-06
- */
- ColId: ident { $$ = $1; }
- | datetime { $$ = $1; }
- | ABSOLUTE { $$ = make1_str("absolute"); }
- | ACCESS { $$ = make1_str("access"); }
- | ACTION { $$ = make1_str("action"); }
- | AFTER { $$ = make1_str("after"); }
- | AGGREGATE { $$ = make1_str("aggregate"); }
- | BACKWARD { $$ = make1_str("backward"); }
- | BEFORE { $$ = make1_str("before"); }
- | CACHE { $$ = make1_str("cache"); }
- | COMMITTED { $$ = make1_str("committed"); }
- | CREATEDB { $$ = make1_str("createdb"); }
- | CREATEUSER { $$ = make1_str("createuser"); }
- | CYCLE { $$ = make1_str("cycle"); }
- | DATABASE { $$ = make1_str("database"); }
- | DELIMITERS { $$ = make1_str("delimiters"); }
- | DOUBLE { $$ = make1_str("double"); }
- | EACH { $$ = make1_str("each"); }
- | ENCODING { $$ = make1_str("encoding"); }
- | EXCLUSIVE { $$ = make1_str("exclusive"); }
- | FORWARD { $$ = make1_str("forward"); }
- | FUNCTION { $$ = make1_str("function"); }
- | HANDLER { $$ = make1_str("handler"); }
- | INCREMENT { $$ = make1_str("increment"); }
- | INDEX { $$ = make1_str("index"); }
- | INHERITS { $$ = make1_str("inherits"); }
- | INSENSITIVE { $$ = make1_str("insensitive"); }
- | INSTEAD { $$ = make1_str("instead"); }
- | ISNULL { $$ = make1_str("isnull"); }
- | KEY { $$ = make1_str("key"); }
- | LANGUAGE { $$ = make1_str("language"); }
- | LANCOMPILER { $$ = make1_str("lancompiler"); }
- | LOCATION { $$ = make1_str("location"); }
- | MATCH { $$ = make1_str("match"); }
- | MAXVALUE { $$ = make1_str("maxvalue"); }
- | MINVALUE { $$ = make1_str("minvalue"); }
- | MODE { $$ = make1_str("mode"); }
- | NEXT { $$ = make1_str("next"); }
- | NOCREATEDB { $$ = make1_str("nocreatedb"); }
- | NOCREATEUSER { $$ = make1_str("nocreateuser"); }
- | NOTHING { $$ = make1_str("nothing"); }
- | NOTNULL { $$ = make1_str("notnull"); }
- | OF { $$ = make1_str("of"); }
- | OIDS { $$ = make1_str("oids"); }
- | ONLY { $$ = make1_str("only"); }
- | OPERATOR { $$ = make1_str("operator"); }
- | OPTION { $$ = make1_str("option"); }
- | PASSWORD { $$ = make1_str("password"); }
- | PRIOR { $$ = make1_str("prior"); }
- | PRIVILEGES { $$ = make1_str("privileges"); }
- | PROCEDURAL { $$ = make1_str("procedural"); }
- | READ { $$ = make1_str("read"); }
- /* NOT USED | RECIPE { $$ = make1_str("recipe"); } */
- | RELATIVE { $$ = make1_str("relative"); }
- | RENAME { $$ = make1_str("rename"); }
- | RETURNS { $$ = make1_str("returns"); }
- | ROW { $$ = make1_str("row"); }
- | RULE { $$ = make1_str("rule"); }
- | SCROLL { $$ = make1_str("scroll"); }
- | SEQUENCE { $$ = make1_str("sequence"); }
- | SERIAL { $$ = make1_str("serial"); }
- | SERIALIZABLE { $$ = make1_str("serializable"); }
- | SHARE { $$ = make1_str("share"); }
- | START { $$ = make1_str("start"); }
- | STATEMENT { $$ = make1_str("statement"); }
- | STDIN { $$ = make1_str("stdin"); }
- | STDOUT { $$ = make1_str("stdout"); }
- | TIME { $$ = make1_str("time"); }
- | TIMESTAMP { $$ = make1_str("timestamp"); }
- | TIMEZONE_HOUR { $$ = make1_str("timezone_hour"); }
- | TIMEZONE_MINUTE { $$ = make1_str("timezone_minute"); }
- | TRIGGER { $$ = make1_str("trigger"); }
- | TRUSTED { $$ = make1_str("trusted"); }
- | TYPE_P { $$ = make1_str("type"); }
- | VALID { $$ = make1_str("valid"); }
- | VERSION { $$ = make1_str("version"); }
- | ZONE { $$ = make1_str("zone"); }
- | SQL_AT { $$ = make1_str("at"); }
- | SQL_BOOL { $$ = make1_str("bool"); }
- | SQL_BREAK { $$ = make1_str("break"); }
- | SQL_CALL { $$ = make1_str("call"); }
- | SQL_CONNECT { $$ = make1_str("connect"); }
- | SQL_CONTINUE { $$ = make1_str("continue"); }
- | SQL_DEALLOCATE { $$ = make1_str("deallocate"); }
- | SQL_DISCONNECT { $$ = make1_str("disconnect"); }
- | SQL_FOUND { $$ = make1_str("found"); }
- | SQL_GO { $$ = make1_str("go"); }
- | SQL_GOTO { $$ = make1_str("goto"); }
- | SQL_IDENTIFIED { $$ = make1_str("identified"); }
- | SQL_IMMEDIATE { $$ = make1_str("immediate"); }
- | SQL_INDICATOR { $$ = make1_str("indicator"); }
- | SQL_INT { $$ = make1_str("int"); }
- | SQL_LONG { $$ = make1_str("long"); }
- | SQL_OFF { $$ = make1_str("off"); }
- | SQL_OPEN { $$ = make1_str("open"); }
- | SQL_PREPARE { $$ = make1_str("prepare"); }
- | SQL_RELEASE { $$ = make1_str("release"); }
- | SQL_SECTION { $$ = make1_str("section"); }
- | SQL_SHORT { $$ = make1_str("short"); }
- | SQL_SIGNED { $$ = make1_str("signed"); }
- | SQL_SQLERROR { $$ = make1_str("sqlerror"); }
- | SQL_SQLPRINT { $$ = make1_str("sqlprint"); }
- | SQL_SQLWARNING { $$ = make1_str("sqlwarning"); }
- | SQL_STOP { $$ = make1_str("stop"); }
- | SQL_STRUCT { $$ = make1_str("struct"); }
- | SQL_UNSIGNED { $$ = make1_str("unsigned"); }
- | SQL_VAR { $$ = make1_str("var"); }
- | SQL_WHENEVER { $$ = make1_str("whenever"); }
- ;
- /* Column label
- * Allowed labels in "AS" clauses.
- * Include TRUE/FALSE SQL3 reserved words for Postgres backward
- * compatibility. Cannot allow this for column names since the
- * syntax would not distinguish between the constant value and
- * a column name. - thomas 1997-10-24
- * Add other keywords to this list. Note that they appear here
- * rather than in ColId if there was a shift/reduce conflict
- * when used as a full identifier. - thomas 1997-11-06
- */
- ColLabel: ColId { $$ = $1; }
- | ABORT_TRANS { $$ = make1_str("abort"); }
- | ANALYZE { $$ = make1_str("analyze"); }
- | BINARY { $$ = make1_str("binary"); }
- | CASE { $$ = make1_str("case"); }
- | CLUSTER { $$ = make1_str("cluster"); }
- | COALESCE { $$ = make1_str("coalesce"); }
- | CONSTRAINT { $$ = make1_str("constraint"); }
- | COPY { $$ = make1_str("copy"); }
- | CURRENT { $$ = make1_str("current"); }
- | DO { $$ = make1_str("do"); }
- | ELSE { $$ = make1_str("else"); }
- | END_TRANS { $$ = make1_str("end"); }
- | EXPLAIN { $$ = make1_str("explain"); }
- | EXTEND { $$ = make1_str("extend"); }
- | FALSE_P { $$ = make1_str("false"); }
- | FOREIGN { $$ = make1_str("foreign"); }
- | GROUP { $$ = make1_str("group"); }
- | LISTEN { $$ = make1_str("listen"); }
- | LOAD { $$ = make1_str("load"); }
- | LOCK_P { $$ = make1_str("lock"); }
- | MOVE { $$ = make1_str("move"); }
- | NEW { $$ = make1_str("new"); }
- | NONE { $$ = make1_str("none"); }
- | NULLIF { $$ = make1_str("nullif"); }
- | ORDER { $$ = make1_str("order"); }
- | POSITION { $$ = make1_str("position"); }
- | PRECISION { $$ = make1_str("precision"); }
- | RESET { $$ = make1_str("reset"); }
- | SETOF { $$ = make1_str("setof"); }
- | SHOW { $$ = make1_str("show"); }
- | TABLE { $$ = make1_str("table"); }
- | THEN { $$ = make1_str("then"); }
- | TRANSACTION { $$ = make1_str("transaction"); }
- | TRUE_P { $$ = make1_str("true"); }
- | VACUUM { $$ = make1_str("vacuum"); }
- | VERBOSE { $$ = make1_str("verbose"); }
- | WHEN { $$ = make1_str("when"); }
- ;
- SpecialRuleRelation: CURRENT
- {
- if (QueryIsRule)
- $$ = make1_str("current");
- else
- yyerror("CURRENT used in non-rule query");
- }
- | NEW
- {
- if (QueryIsRule)
- $$ = make1_str("new");
- else
- yyerror("NEW used in non-rule query");
- }
- ;
- /*
- * and now special embedded SQL stuff
- */
- /*
- * the exec sql connect statement: connect to the given database
- */
- ECPGConnect: SQL_CONNECT TO connection_target opt_connection_name opt_user
- {
- $$ = make5_str($3, make1_str(","), $5, make1_str(","), $4);
- }
- | SQL_CONNECT TO DEFAULT
- {
- $$ = make1_str("NULL,NULL,NULL,"DEFAULT"");
- }
- /* also allow ORACLE syntax */
- | SQL_CONNECT ora_user
- {
- $$ = make3_str(make1_str("NULL,"), $2, make1_str(",NULL"));
- }
- connection_target: database_name opt_server opt_port
- {
- /* old style: dbname[@server][:port] */
- if (strlen($2) > 0 && *($2) != '@')
- {
- sprintf(errortext, "parse error at or near '%s'", $2);
- yyerror(errortext);
- }
- $$ = make5_str(make1_str("""), $1, $2, $3, make1_str("""));
- }
- | db_prefix server opt_port '/' database_name opt_options
- {
- /* new style: <tcp|unix>:postgresql://server[:port][/dbname] */
- if (strncmp($2, "://", 3) != 0)
- {
- sprintf(errortext, "parse error at or near '%s'", $2);
- yyerror(errortext);
- }
- if (strncmp($1, "unix", 4) == 0 && strncmp($2 + 3, "localhost", 9) != 0)
- {
- sprintf(errortext, "unix domain sockets only work on 'localhost' but not on '%9.9s'", $2);
- yyerror(errortext);
- }
- if (strncmp($1, "unix", 4) != 0 && strncmp($1, "tcp", 3) != 0)
- {
- sprintf(errortext, "only protocols 'tcp' and 'unix' are supported");
- yyerror(errortext);
- }
-
- $$ = make4_str(make5_str(make1_str("""), $1, $2, $3, make1_str("/")), $5, $6, make1_str("""));
- }
- | char_variable
- {
- $$ = $1;
- }
- | Sconst
- {
- $$ = mm_strdup($1);
- $$[0] = '"';
- $$[strlen($$) - 1] = '"';
- free($1);
- }
- db_prefix: ident cvariable
- {
- if (strcmp($2, "postgresql") != 0 && strcmp($2, "postgres") != 0)
- {
- sprintf(errortext, "parse error at or near '%s'", $2);
- yyerror(errortext);
- }
- if (strcmp($1, "tcp") != 0 && strcmp($1, "unix") != 0)
- {
- sprintf(errortext, "Illegal connection type %s", $1);
- yyerror(errortext);
- }
- $$ = make3_str($1, make1_str(":"), $2);
- }
-
- server: Op server_name
- {
- if (strcmp($1, "@") != 0 && strcmp($1, "://") != 0)
- {
- sprintf(errortext, "parse error at or near '%s'", $1);
- yyerror(errortext);
- }
- $$ = make2_str($1, $2);
- }
- opt_server: server { $$ = $1; }
- | /* empty */ { $$ = make1_str(""); }
- server_name: ColId { $$ = $1; }
- | ColId '.' server_name { $$ = make3_str($1, make1_str("."), $3); }
- opt_port: ':' Iconst { $$ = make2_str(make1_str(":"), $2); }
- | /* empty */ { $$ = make1_str(""); }
- opt_connection_name: AS connection_target { $$ = $2; }
- | /* empty */ { $$ = make1_str("NULL"); }
- opt_user: USER ora_user { $$ = $2; }
- | /* empty */ { $$ = make1_str("NULL,NULL"); }
- ora_user: user_name
- {
- $$ = make2_str($1, make1_str(",NULL"));
- }
- | user_name '/' user_name
- {
- $$ = make3_str($1, make1_str(","), $3);
- }
- | user_name SQL_IDENTIFIED BY user_name
- {
- $$ = make3_str($1, make1_str(","), $4);
- }
- | user_name USING user_name
- {
- $$ = make3_str($1, make1_str(","), $3);
- }
- user_name: UserId { if ($1[0] == '"')
- $$ = $1;
- else
- $$ = make3_str(make1_str("""), $1, make1_str("""));
- }
- | char_variable { $$ = $1; }
- | SCONST { $$ = make3_str(make1_str("""), $1, make1_str(""")); }
- char_variable: cvariable
- { /* check if we have a char variable */
- struct variable *p = find_variable($1);
- enum ECPGttype typ = p->type->typ;
- /* if array see what's inside */
- if (typ == ECPGt_array)
- typ = p->type->u.element->typ;
- switch (typ)
- {
- case ECPGt_char:
- case ECPGt_unsigned_char:
- $$ = $1;
- break;
- case ECPGt_varchar:
- $$ = make2_str($1, make1_str(".arr"));
- break;
- default:
- yyerror("invalid datatype");
- break;
- }
- }
- opt_options: Op ColId
- {
- if (strlen($1) == 0)
- yyerror("parse error");
-
- if (strcmp($1, "?") != 0)
- {
- sprintf(errortext, "parse error at or near %s", $1);
- yyerror(errortext);
- }
-
- $$ = make2_str(make1_str("?"), $2);
- }
- | /* empty */ { $$ = make1_str(""); }
- /*
- * Declare a prepared cursor. The syntax is different from the standard
- * declare statement, so we create a new rule.
- */
- ECPGCursorStmt: DECLARE name opt_cursor CURSOR FOR ident
- {
- struct cursor *ptr, *this;
- struct variable *thisquery = (struct variable *)mm_alloc(sizeof(struct variable));
- for (ptr = cur; ptr != NULL; ptr = ptr->next)
- {
- if (strcmp($2, ptr->name) == 0)
- {
- /* re-definition is a bug */
- sprintf(errortext, "cursor %s already defined", $2);
- yyerror(errortext);
- }
- }
- this = (struct cursor *) mm_alloc(sizeof(struct cursor));
- /* initial definition */
- this->next = cur;
- this->name = $2;
- this->connection = connection;
- this->command = cat4_str(make1_str("declare"), mm_strdup($2), $3, make1_str("cursor for ?"));
- this->argsresult = NULL;
- thisquery->type = &ecpg_query;
- thisquery->brace_level = 0;
- thisquery->next = NULL;
- thisquery->name = (char *) mm_alloc(sizeof("ECPGprepared_statement("")") + strlen($6));
- sprintf(thisquery->name, "ECPGprepared_statement("%s")", $6);
- this->argsinsert = NULL;
- add_variable(&(this->argsinsert), thisquery, &no_indicator);
- cur = this;
-
- $$ = cat3_str(make1_str("/*"), mm_strdup(this->command), make1_str("*/"));
- }
- ;
- /*
- * the exec sql deallocate prepare command to deallocate a previously
- * prepared statement
- */
- ECPGDeallocate: SQL_DEALLOCATE SQL_PREPARE ident { $$ = make3_str(make1_str("ECPGdeallocate(__LINE__, ""), $3, make1_str("");")); }
- /*
- * variable declaration inside the exec sql declare block
- */
- ECPGDeclaration: sql_startdeclare
- {
- fputs("/* exec sql begin declare section */", yyout);
- output_line_number();
- }
- variable_declarations sql_enddeclare
- {
- fprintf(yyout, "%s/* exec sql end declare section */", $3);
- free($3);
- output_line_number();
- }
- sql_startdeclare : ecpgstart BEGIN_TRANS DECLARE SQL_SECTION ';' {}
- sql_enddeclare: ecpgstart END_TRANS DECLARE SQL_SECTION ';' {}
- variable_declarations: /* empty */
- {
- $$ = make1_str("");
- }
- | declaration variable_declarations
- {
- $$ = cat2_str($1, $2);
- }
- declaration: storage_clause
- {
- actual_storage[struct_level] = mm_strdup($1);
- }
- type
- {
- actual_type[struct_level].type_enum = $3.type_enum;
- actual_type[struct_level].type_dimension = $3.type_dimension;
- actual_type[struct_level].type_index = $3.type_index;
- }
- variable_list ';'
- {
- $$ = cat4_str($1, $3.type_str, $5, make1_str(";n"));
- }
- storage_clause : S_EXTERN { $$ = make1_str("extern"); }
- | S_STATIC { $$ = make1_str("static"); }
- | S_SIGNED { $$ = make1_str("signed"); }
- | S_CONST { $$ = make1_str("const"); }
- | S_REGISTER { $$ = make1_str("register"); }
- | S_AUTO { $$ = make1_str("auto"); }
- | /* empty */ { $$ = make1_str(""); }
- type: simple_type
- {
- $$.type_enum = $1;
- $$.type_str = mm_strdup(ECPGtype_name($1));
- $$.type_dimension = -1;
- $$.type_index = -1;
- }
- | varchar_type
- {
- $$.type_enum = ECPGt_varchar;
- $$.type_str = make1_str("");
- $$.type_dimension = -1;
- $$.type_index = -1;
- }
- | struct_type
- {
- $$.type_enum = ECPGt_struct;
- $$.type_str = $1;
- $$.type_dimension = -1;
- $$.type_index = -1;
- }
- | union_type
- {
- $$.type_enum = ECPGt_union;
- $$.type_str = $1;
- $$.type_dimension = -1;
- $$.type_index = -1;
- }
- | enum_type
- {
- $$.type_str = $1;
- $$.type_enum = ECPGt_int;
-
- $$.type_dimension = -1;
- $$.type_index = -1;
- }
- | symbol
- {
- /* this is for typedef'ed types */
- struct typedefs *this = get_typedef($1);
- $$.type_str = (this->type->type_enum == ECPGt_varchar) ? make1_str("") : mm_strdup(this->name);
- $$.type_enum = this->type->type_enum;
- $$.type_dimension = this->type->type_dimension;
- $$.type_index = this->type->type_index;
- struct_member_list[struct_level] = ECPGstruct_member_dup(this->struct_member_list);
- }
- enum_type: s_enum '{' c_line '}'
- {
- $$ = cat4_str($1, make1_str("{"), $3, make1_str("}"));
- }
-
- s_enum: S_ENUM opt_symbol { $$ = cat2_str(make1_str("enum"), $2); }
- struct_type: s_struct '{' variable_declarations '}'
- {
- ECPGfree_struct_member(struct_member_list[struct_level]);
- free(actual_storage[struct_level--]);
- $$ = cat4_str($1, make1_str("{"), $3, make1_str("}"));
- }
- union_type: s_union '{' variable_declarations '}'
- {
- ECPGfree_struct_member(struct_member_list[struct_level]);
- free(actual_storage[struct_level--]);
- $$ = cat4_str($1, make1_str("{"), $3, make1_str("}"));
- }
- s_struct : S_STRUCT opt_symbol
- {
- struct_member_list[struct_level++] = NULL;
- if (struct_level >= STRUCT_DEPTH)
- yyerror("Too many levels in nested structure definition");
- $$ = cat2_str(make1_str("struct"), $2);
- }
- s_union : S_UNION opt_symbol
- {
- struct_member_list[struct_level++] = NULL;
- if (struct_level >= STRUCT_DEPTH)
- yyerror("Too many levels in nested structure definition");
- $$ = cat2_str(make1_str("union"), $2);
- }
- opt_symbol: /* empty */ { $$ = make1_str(""); }
- | symbol { $$ = $1; }
- simple_type: S_SHORT { $$ = ECPGt_short; }
- | S_UNSIGNED S_SHORT { $$ = ECPGt_unsigned_short; }
- | S_INT { $$ = ECPGt_int; }
- | S_UNSIGNED S_INT { $$ = ECPGt_unsigned_int; }
- | S_LONG { $$ = ECPGt_long; }
- | S_UNSIGNED S_LONG { $$ = ECPGt_unsigned_long; }
- | S_FLOAT { $$ = ECPGt_float; }
- | S_DOUBLE { $$ = ECPGt_double; }
- | S_BOOL { $$ = ECPGt_bool; };
- | S_CHAR { $$ = ECPGt_char; }
- | S_UNSIGNED S_CHAR { $$ = ECPGt_unsigned_char; }
- varchar_type: S_VARCHAR { $$ = ECPGt_varchar; }
- variable_list: variable
- {
- $$ = $1;
- }
- | variable_list ',' variable
- {
- $$ = cat3_str($1, make1_str(","), $3);
- }
- variable: opt_pointer symbol opt_array_bounds opt_initializer
- {
- struct ECPGtype * type;
- int dimension = $3.index1; /* dimension of array */
- int length = $3.index2; /* lenght of string */
- char dim[14L], ascii_len[12];
- adjust_array(actual_type[struct_level].type_enum, &dimension, &length, actual_type[struct_level].type_dimension, actual_type[struct_level].type_index, strlen($1));
- switch (actual_type[struct_level].type_enum)
- {
- case ECPGt_struct:
- case ECPGt_union:
- if (dimension < 0)
- type = ECPGmake_struct_type(struct_member_list[struct_level], actual_type[struct_level].type_enum);
- else
- type = ECPGmake_array_type(ECPGmake_struct_type(struct_member_list[struct_level], actual_type[struct_level].type_enum), dimension);
- $$ = make4_str($1, mm_strdup($2), $3.str, $4);
- break;
- case ECPGt_varchar:
- if (dimension == -1)
- type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length);
- else
- type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension);
- switch(dimension)
- {
- case 0:
- case -1:
- case 1:
- *dim = ' ';
- break;
- default:
- sprintf(dim, "[%d]", dimension);
- break;
- }
- sprintf(ascii_len, "%d", length);
- if (length == 0)
- yyerror ("pointer to varchar are not implemented");
- if (dimension == 0)
- $$ = make4_str(make5_str(mm_strdup(actual_storage[struct_level]), make1_str(" struct varchar_"), mm_strdup($2), make1_str(" { int len; char arr["), mm_strdup(ascii_len)), make1_str("]; } *"), mm_strdup($2), $4);
- else
- $$ = make5_str(make5_str(mm_strdup(actual_storage[struct_level]), make1_str(" struct varchar_"), mm_strdup($2), make1_str(" { int len; char arr["), mm_strdup(ascii_len)), make1_str("]; } "), mm_strdup($2), mm_strdup(dim), $4);
- break;
- case ECPGt_char:
- case ECPGt_unsigned_char:
- if (dimension == -1)
- type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length);
- else
- type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension);
- $$ = make4_str($1, mm_strdup($2), $3.str, $4);
- break;
- default:
- if (dimension < 0)
- type = ECPGmake_simple_type(actual_type[struct_level].type_enum, 1);
- else
- type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, 1), dimension);
- $$ = make4_str($1, mm_strdup($2), $3.str, $4);
- break;
- }
- if (struct_level == 0)
- new_variable($2, type);
- else
- ECPGmake_struct_member($2, type, &(struct_member_list[struct_level - 1]));
- free($2);
- }
- opt_initializer: /* empty */ { $$ = make1_str(""); }
- | '=' vartext { $$ = make2_str(make1_str("="), $2); }
- opt_pointer: /* empty */ { $$ = make1_str(""); }
- | '*' { $$ = make1_str("*"); }
- /*
- * As long as the prepare statement is not supported by the backend, we will
- * try to simulate it here so we get dynamic SQL
- */
- ECPGDeclare: DECLARE STATEMENT ident
- {
- /* this is only supported for compatibility */
- $$ = cat3_str(make1_str("/* declare statement"), $3, make1_str("*/"));
- }
- /*
- * the exec sql disconnect statement: disconnect from the given database
- */
- ECPGDisconnect: SQL_DISCONNECT dis_name { $$ = $2; }
- dis_name: connection_object { $$ = $1; }
- | CURRENT { $$ = make1_str("CURRENT"); }
- | ALL { $$ = make1_str("ALL"); }
- | /* empty */ { $$ = make1_str("CURRENT"); }
- connection_object: connection_target { $$ = $1; }
- | DEFAULT { $$ = make1_str("DEFAULT"); }
- /*
- * execute a given string as sql command
- */
- ECPGExecute : EXECUTE SQL_IMMEDIATE execstring
- {
- struct variable *thisquery = (struct variable *)mm_alloc(sizeof(struct variable));
- thisquery->type = &ecpg_query;
- thisquery->brace_level = 0;
- thisquery->next = NULL;
- thisquery->name = $3;
- add_variable(&argsinsert, thisquery, &no_indicator);
- $$ = make1_str("?");
- }
- | EXECUTE ident
- {
- struct variable *thisquery = (struct variable *)mm_alloc(sizeof(struct variable));
- thisquery->type = &ecpg_query;
- thisquery->brace_level = 0;
- thisquery->next = NULL;
- thisquery->name = (char *) mm_alloc(sizeof("ECPGprepared_statement("")") + strlen($2));
- sprintf(thisquery->name, "ECPGprepared_statement("%s")", $2);
- add_variable(&argsinsert, thisquery, &no_indicator);
- } opt_using
- {
- $$ = make1_str("?");
- }
- execstring: char_variable |
- CSTRING { $$ = make3_str(make1_str("""), $1, make1_str(""")); };
- /*
- * the exec sql free command to deallocate a previously
- * prepared statement
- */
- ECPGFree: SQL_FREE ident { $$ = $2; }
- /*
- * open is an open cursor, at the moment this has to be removed
- */
- ECPGOpen: SQL_OPEN name opt_using {
- $$ = $2;
- };
- opt_using: /* empty */ { $$ = make1_str(""); }
- | USING variablelist {
- /* yyerror ("open cursor with variables not implemented yet"); */
- $$ = make1_str("");
- }
- variablelist: cinputvariable | cinputvariable ',' variablelist
- /*
- * As long as the prepare statement is not supported by the backend, we will
- * try to simulate it here so we get dynamic SQL
- */
- ECPGPrepare: SQL_PREPARE ident FROM execstring
- {
- $$ = make4_str(make1_str("""), $2, make1_str("", "), $4);
- }
- /*
- * for compatibility with ORACLE we will also allow the keyword RELEASE
- * after a transaction statement to disconnect from the database.
- */
- ECPGRelease: TransactionStmt SQL_RELEASE
- {
- if (strncmp($1, "begin", 5) == 0)
- yyerror("RELEASE does not make sense when beginning a transaction");
- fprintf(yyout, "ECPGtrans(__LINE__, %s, "%s");", connection, $1);
- whenever_action(0);
- fprintf(yyout, "ECPGdisconnect("");");
- whenever_action(0);
- free($1);
- }
- /*
- * set/reset the automatic transaction mode, this needs a differnet handling
- * as the other set commands
- */
- ECPGSetAutocommit: SET SQL_AUTOCOMMIT to_equal on_off
- {
- $$ = $4;
- }
- on_off: ON { $$ = make1_str("on"); }
- | SQL_OFF { $$ = make1_str("off"); }
- to_equal: TO | "=";
- /*
- * set the actual connection, this needs a differnet handling as the other
- * set commands
- */
- ECPGSetConnection: SET SQL_CONNECTION to_equal connection_object
- {
- $$ = $4;
- }
- /*
- * define a new type for embedded SQL
- */
- ECPGTypedef: TYPE_P symbol IS ctype opt_type_array_bounds opt_reference
- {
- /* add entry to list */
- struct typedefs *ptr, *this;
- int dimension = $5.index1;
- int length = $5.index2;
- for (ptr = types; ptr != NULL; ptr = ptr->next)
- {
- if (strcmp($2, ptr->name) == 0)
- {
- /* re-definition is a bug */
- sprintf(errortext, "type %s already defined", $2);
- yyerror(errortext);
- }
- }
- adjust_array($4.type_enum, &dimension, &length, $4.type_dimension, $4.type_index, strlen($6));
- this = (struct typedefs *) mm_alloc(sizeof(struct typedefs));
- /* initial definition */
- this->next = types;
- this->name = $2;
- this->type = (struct this_type *) mm_alloc(sizeof(struct this_type));
- this->type->type_enum = $4.type_enum;
- this->type->type_str = mm_strdup($2);
- this->type->type_dimension = dimension; /* dimension of array */
- this->type->type_index = length; /* lenght of string */
- this->struct_member_list = struct_member_list[struct_level];
- if ($4.type_enum != ECPGt_varchar &&
- $4.type_enum != ECPGt_char &&
- $4.type_enum != ECPGt_unsigned_char &&
- this->type->type_index >= 0)
- yyerror("No multi-dimensional array support for simple data types");
- types = this;
- $$ = cat5_str(cat3_str(make1_str("/* exec sql type"), mm_strdup($2), make1_str("is")), mm_strdup($4.type_str), mm_strdup($5.str), $6, make1_str("*/"));
- }
- opt_type_array_bounds: '[' ']' nest_type_array_bounds
- {
- $$.index1 = 0;
- $$.index2 = $3.index1;
- $$.str = cat2_str(make1_str("[]"), $3.str);
- }
- | '(' ')' nest_type_array_bounds
- {
- $$.index1 = 0;
- $$.index2 = $3.index1;
- $$.str = cat2_str(make1_str("[]"), $3.str);
- }
- | '[' Iresult ']' nest_type_array_bounds
- {
- char *txt = mm_alloc(20L);
- sprintf (txt, "%d", $2);
- $$.index1 = $2;
- $$.index2 = $4.index1;
- $$.str = cat4_str(make1_str("["), txt, make1_str("]"), $4.str);
- }
- | '(' Iresult ')' nest_type_array_bounds
- {
- char *txt = mm_alloc(20L);
- sprintf (txt, "%d", $2);
- $$.index1 = $2;
- $$.index2 = $4.index1;
- $$.str = cat4_str(make1_str("["), txt, make1_str("]"), $4.str);
- }
- | /* EMPTY */
- {
- $$.index1 = -1;
- $$.index2 = -1;
- $$.str= make1_str("");
- }
- ;
- nest_type_array_bounds: '[' ']' nest_type_array_bounds
- {
- $$.index1 = 0;
- $$.index2 = $3.index1;
- $$.str = cat2_str(make1_str("[]"), $3.str);
- }
- | '(' ')' nest_type_array_bounds
- {
- $$.index1 = 0;
- $$.index2 = $3.index1;
- $$.str = cat2_str(make1_str("[]"), $3.str);
- }
- | '[' Iresult ']' nest_type_array_bounds
- {
- char *txt = mm_alloc(20L);
- sprintf (txt, "%d", $2);
- $$.index1 = $2;
- $$.index2 = $4.index1;
- $$.str = cat4_str(make1_str("["), txt, make1_str("]"), $4.str);
- }
- | '(' Iresult ')' nest_type_array_bounds
- {
- char *txt = mm_alloc(20L);
- sprintf (txt, "%d", $2);
- $$.index1 = $2;
- $$.index2 = $4.index1;
- $$.str = cat4_str(make1_str("["), txt, make1_str("]"), $4.str);
- }
- | /* EMPTY */
- {
- $$.index1 = -1;
- $$.index2 = -1;
- $$.str= make1_str("");
- }
- ;
- opt_reference: SQL_REFERENCE { $$ = make1_str("reference"); }
- | /* empty */ { $$ = make1_str(""); }
- ctype: CHAR
- {
- $$.type_str = make1_str("char");
- $$.type_enum = ECPGt_char;
- $$.type_index = -1;
- $$.type_dimension = -1;
- }
- | VARCHAR
- {
- $$.type_str = make1_str("varchar");
- $$.type_enum = ECPGt_varchar;
- $$.type_index = -1;
- $$.type_dimension = -1;
- }
- | FLOAT
- {
- $$.type_str = make1_str("float");
- $$.type_enum = ECPGt_float;
- $$.type_index = -1;
- $$.type_dimension = -1;
- }
- | DOUBLE
- {
- $$.type_str = make1_str("double");
- $$.type_enum = ECPGt_double;
- $$.type_index = -1;
- $$.type_dimension = -1;
- }
- | opt_signed SQL_INT
- {
- $$.type_str = make1_str("int");
- $$.type_enum = ECPGt_int;
- $$.type_index = -1;
- $$.type_dimension = -1;
- }
- | SQL_ENUM
- {
- $$.type_str = make1_str("int");
- $$.type_enum = ECPGt_int;
- $$.type_index = -1;
- $$.type_dimension = -1;
- }
- | opt_signed SQL_SHORT
- {
- $$.type_str = make1_str("short");
- $$.type_enum = ECPGt_short;
- $$.type_index = -1;
- $$.type_dimension = -1;
- }
- | opt_signed SQL_LONG
- {
- $$.type_str = make1_str("long");
- $$.type_enum = ECPGt_long;
- $$.type_index = -1;
- $$.type_dimension = -1;
- }
- | SQL_BOOL
- {
- $$.type_str = make1_str("bool");
- $$.type_enum = ECPGt_bool;
- $$.type_index = -1;
- $$.type_dimension = -1;
- }
- | SQL_UNSIGNED SQL_INT
- {
- $$.type_str = make1_str("unsigned int");
- $$.type_enum = ECPGt_unsigned_int;
- $$.type_index = -1;
- $$.type_dimension = -1;
- }
- | SQL_UNSIGNED SQL_SHORT
- {
- $$.type_str = make1_str("unsigned short");
- $$.type_enum = ECPGt_unsigned_short;
- $$.type_index = -1;
- $$.type_dimension = -1;
- }
- | SQL_UNSIGNED SQL_LONG
- {
- $$.type_str = make1_str("unsigned long");
- $$.type_enum = ECPGt_unsigned_long;
- $$.type_index = -1;
- $$.type_dimension = -1;
- }
- | SQL_STRUCT
- {
- struct_member_list[struct_level++] = NULL;
- if (struct_level >= STRUCT_DEPTH)
- yyerror("Too many levels in nested structure definition");
- } '{' sql_variable_declarations '}'
- {
- ECPGfree_struct_member(struct_member_list[struct_level--]);
- $$.type_str = cat3_str(make1_str("struct {"), $4, make1_str("}"));
- $$.type_enum = ECPGt_struct;
- $$.type_index = -1;
- $$.type_dimension = -1;
- }
- | UNION
- {
- struct_member_list[struct_level++] = NULL;
- if (struct_level >= STRUCT_DEPTH)
- yyerror("Too many levels in nested structure definition");
- } '{' sql_variable_declarations '}'
- {
- ECPGfree_struct_member(struct_member_list[struct_level--]);
- $$.type_str = cat3_str(make1_str("union {"), $4, make1_str("}"));
- $$.type_enum = ECPGt_union;
- $$.type_index = -1;
- $$.type_dimension = -1;
- }
- | symbol
- {
- struct typedefs *this = get_typedef($1);
- $$.type_str = mm_strdup($1);
- $$.type_enum = this->type->type_enum;
- $$.type_dimension = this->type->type_dimension;
- $$.type_index = this->type->type_index;
- struct_member_list[struct_level] = this->struct_member_list;
- }
- opt_signed: SQL_SIGNED | /* empty */
- sql_variable_declarations: /* empty */
- {
- $$ = make1_str("");
- }
- | sql_declaration sql_variable_declarations
- {
- $$ = cat2_str($1, $2);
- }
- ;
- sql_declaration: ctype
- {
- actual_type[struct_level].type_enum = $1.type_enum;
- actual_type[struct_level].type_dimension = $1.type_dimension;
- actual_type[struct_level].type_index = $1.type_index;
- }
- sql_variable_list ';'
- {
- $$ = cat3_str($1.type_str, $3, make1_str(";"));
- }
- sql_variable_list: sql_variable
- {
- $$ = $1;
- }
- | sql_variable_list ',' sql_variable
- {
- $$ = make3_str($1, make1_str(","), $3);
- }
- sql_variable: opt_pointer symbol opt_array_bounds
- {
- int dimension = $3.index1;
- int length = $3.index2;
- struct ECPGtype * type;
- char dim[14L];
- adjust_array(actual_type[struct_level].type_enum, &dimension, &length, actual_type[struct_level].type_dimension, actual_type[struct_level].type_index, strlen($1));
- switch (actual_type[struct_level].type_enum)
- {
- case ECPGt_struct:
- case ECPGt_union:
- if (dimension < 0)
- type = ECPGmake_struct_type(struct_member_list[struct_level], actual_type[struct_level].type_enum);
- else
- type = ECPGmake_array_type(ECPGmake_struct_type(struct_member_list[struct_level], actual_type[struct_level].type_enum), dimension);
- break;
- case ECPGt_varchar:
- if (dimension == -1)
- type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length);
- else
- type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension);
- switch(dimension)
- {
- case 0:
- strcpy(dim, "[]");
- break;
- case -1:
- case 1:
- *dim = ' ';
- break;
- default:
- sprintf(dim, "[%d]", dimension);
- break;
- }
- break;
- case ECPGt_char:
- case ECPGt_unsigned_char:
- if (dimension == -1)
- type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length);
- else
- type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension);
- break;
- default:
- if (length >= 0)
- yyerror("No multi-dimensional array support for simple data types");
- if (dimension < 0)
- type = ECPGmake_simple_type(actual_type[struct_level].type_enum, 1);
- else
- type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, 1), dimension);
- break;
- }
- if (struct_level == 0)
- new_variable($2, type);
- else
- ECPGmake_struct_member($2, type, &(struct_member_list[struct_level - 1]));
- $$ = cat3_str($1, $2, $3.str);
- }
- /*
- * define the type of one variable for embedded SQL
- */
- ECPGVar: SQL_VAR symbol IS ctype opt_type_array_bounds opt_reference
- {
- struct variable *p = find_variable($2);
- int dimension = $5.index1;
- int length = $5.index2;
- struct ECPGtype * type;
- adjust_array($4.type_enum, &dimension, &length, $4.type_dimension, $4.type_index, strlen($6));
- switch ($4.type_enum)
- {
- case ECPGt_struct:
- case ECPGt_union:
- if (dimension < 0)
- type = ECPGmake_struct_type(struct_member_list[struct_level], $4.type_enum);
- else
- type = ECPGmake_array_type(ECPGmake_struct_type(struct_member_list[struct_level], $4.type_enum), dimension);
- break;
- case ECPGt_varchar:
- if (dimension == -1)
- type = ECPGmake_simple_type($4.type_enum, length);
- else
- type = ECPGmake_array_type(ECPGmake_simple_type($4.type_enum, length), dimension);
- break;
- case ECPGt_char:
- case ECPGt_unsigned_char:
- if (dimension == -1)
- type = ECPGmake_simple_type($4.type_enum, length);
- else
- type = ECPGmake_array_type(ECPGmake_simple_type($4.type_enum, length), dimension);
- break;
- default:
- if (length >= 0)
- yyerror("No multi-dimensional array support for simple data types");
- if (dimension < 0)
- type = ECPGmake_simple_type($4.type_enum, 1);
- else
- type = ECPGmake_array_type(ECPGmake_simple_type($4.type_enum, 1), dimension);
- break;
- }
- ECPGfree_type(p->type);
- p->type = type;
- $$ = cat5_str(cat3_str(make1_str("/* exec sql var"), mm_strdup($2), make1_str("is")), mm_strdup($4.type_str), mm_strdup($5.str), $6, make1_str("*/"));
- }
- /*
- * whenever statement: decide what to do in case of error/no data found
- * according to SQL standards we lack: SQLSTATE, CONSTRAINT and SQLEXCEPTION
- */
- ECPGWhenever: SQL_WHENEVER SQL_SQLERROR action {
- when_error.code = $<action>3.code;
- when_error.command = $<action>3.command;
- $$ = cat3_str(make1_str("/* exec sql whenever sqlerror "), $3.str, make1_str("; */n"));
- }
- | SQL_WHENEVER NOT SQL_FOUND action {
- when_nf.code = $<action>4.code;
- when_nf.command = $<action>4.command;
- $$ = cat3_str(make1_str("/* exec sql whenever not found "), $4.str, make1_str("; */n"));
- }
- | SQL_WHENEVER SQL_SQLWARNING action {
- when_warn.code = $<action>3.code;
- when_warn.command = $<action>3.command;
- $$ = cat3_str(make1_str("/* exec sql whenever sql_warning "), $3.str, make1_str("; */n"));
- }
- action : SQL_CONTINUE {
- $<action>$.code = W_NOTHING;
- $<action>$.command = NULL;
- $<action>$.str = make1_str("continue");
- }
- | SQL_SQLPRINT {
- $<action>$.code = W_SQLPRINT;
- $<action>$.command = NULL;
- $<action>$.str = make1_str("sqlprint");
- }
- | SQL_STOP {
- $<action>$.code = W_STOP;
- $<action>$.command = NULL;
- $<action>$.str = make1_str("stop");
- }
- | SQL_GOTO name {
- $<action>$.code = W_GOTO;
- $<action>$.command = strdup($2);
- $<action>$.str = cat2_str(make1_str("goto "), $2);
- }
- | SQL_GO TO name {
- $<action>$.code = W_GOTO;
- $<action>$.command = strdup($3);
- $<action>$.str = cat2_str(make1_str("goto "), $3);
- }
- | DO name '(' dotext ')' {
- $<action>$.code = W_DO;
- $<action>$.command = make4_str($2, make1_str("("), $4, make1_str(")"));
- $<action>$.str = cat2_str(make1_str("do"), mm_strdup($<action>$.command));
- }
- | DO SQL_BREAK {
- $<action>$.code = W_BREAK;
- $<action>$.command = NULL;
- $<action>$.str = make1_str("break");
- }
- | SQL_CALL name '(' dotext ')' {
- $<action>$.code = W_DO;
- $<action>$.command = make4_str($2, make1_str("("), $4, make1_str(")"));
- $<action>$.str = cat2_str(make1_str("call"), mm_strdup($<action>$.command));
- }
- /* some other stuff for ecpg */
- ecpg_expr: attr opt_indirection
- {
- $$ = cat2_str($1, $2);
- }
- | row_expr
- { $$ = $1; }
- | AexprConst
- { $$ = $1; }
- | ColId
- {
- $$ = $1;
- }
- | '-' ecpg_expr %prec UMINUS
- { $$ = cat2_str(make1_str("-"), $2); }
- | '%' ecpg_expr
- { $$ = cat2_str(make1_str("%"), $2); }
- | a_expr '%'
- { $$ = cat2_str($1, make1_str("%")); }
- | a_expr '+' ecpg_expr
- { $$ = cat3_str($1, make1_str("+"), $3); }
- | a_expr '-' ecpg_expr
- { $$ = cat3_str($1, make1_str("-"), $3); }
- | a_expr '/' ecpg_expr
- { $$ = cat3_str($1, make1_str("/"), $3); }
- | a_expr '%' ecpg_expr
- { $$ = cat3_str($1, make1_str("%"), $3); }
- | a_expr '*' ecpg_expr
- { $$ = cat3_str($1, make1_str("*"), $3); }
- | a_expr '<' ecpg_expr
- { $$ = cat3_str($1, make1_str("<"), $3); }
- | a_expr '>' ecpg_expr
- { $$ = cat3_str($1, make1_str(">"), $3); }
- | a_expr '=' NULL_P
- { $$ = cat2_str($1, make1_str("= NULL")); }
- | NULL_P '=' a_expr
- { $$ = cat2_str(make1_str("= NULL"), $3); }
- | a_expr '=' ecpg_expr
- { $$ = cat3_str($1, make1_str("="), $3); }
- /* | ':' ecpg_expr
- { $$ = cat2_str(make1_str(":"), $2); }*/
- | ';' ecpg_expr
- { $$ = cat2_str(make1_str(";"), $2); }
- | '|' ecpg_expr
- { $$ = cat2_str(make1_str("|"), $2); }
- | a_expr TYPECAST Typename
- {
- $$ = cat3_str($1, make1_str("::"), $3);
- }
- | CAST '(' a_expr AS Typename ')'
- {
- $$ = cat3_str(make2_str(make1_str("cast("), $3), make1_str("as"), make2_str($5, make1_str(")")));
- }
- | '(' a_expr_or_null ')'
- { $$ = make3_str(make1_str("("), $2, make1_str(")")); }
- | a_expr Op ecpg_expr
- { $$ = cat3_str($1, $2, $3); }
- | a_expr LIKE ecpg_expr
- { $$ = cat3_str($1, make1_str("like"), $3); }
- | a_expr NOT LIKE ecpg_expr
- { $$ = cat3_str($1, make1_str("not like"), $4); }
- | Op ecpg_expr
- { $$ = cat2_str($1, $2); }
- | a_expr Op
- { $$ = cat2_str($1, $2); }
- | func_name '(' '*' ')'
- {
- $$ = cat2_str($1, make1_str("(*)"));
- }
- | func_name '(' ')'
- {
- $$ = cat2_str($1, make1_str("()"));
- }
- | func_name '(' expr_list ')'
- {
- $$ = make4_str($1, make1_str("("), $3, make1_str(")"));
- }
- | CURRENT_DATE
- {
- $$ = make1_str("current_date");
- }
- | CURRENT_TIME
- {
- $$ = make1_str("current_time");
- }
- | CURRENT_TIME '(' Iconst ')'
- {
- if (atol($3) != 0)
- fprintf(stderr,"CURRENT_TIME(%s) precision not implemented; zero used instead", $3);
- $$ = make1_str("current_time");
- }
- | CURRENT_TIMESTAMP
- {
- $$ = make1_str("current_timestamp");
- }
- | CURRENT_TIMESTAMP '(' Iconst ')'
- {
- if (atol($3) != 0)
- fprintf(stderr,"CURRENT_TIMESTAMP(%s) precision not implemented; zero used instead",$3);
- $$ = make1_str("current_timestamp");
- }
- | CURRENT_USER
- {
- $$ = make1_str("current_user");
- }
- | USER
- {
- $$ = make1_str("user");
- }
- | EXISTS '(' SubSelect ')'
- {
- $$ = make3_str(make1_str("exists("), $3, make1_str(")"));
- }
- | EXTRACT '(' extract_list ')'
- {
- $$ = make3_str(make1_str("extract("), $3, make1_str(")"));
- }
- | POSITION '(' position_list ')'
- {
- $$ = make3_str(make1_str("position("), $3, make1_str(")"));
- }
- | SUBSTRING '(' substr_list ')'
- {
- $$ = make3_str(make1_str("substring("), $3, make1_str(")"));
- }
- /* various trim expressions are defined in SQL92 - thomas 1997-07-19 */
- | TRIM '(' BOTH trim_list ')'
- {
- $$ = make3_str(make1_str("trim(both"), $4, make1_str(")"));
- }
- | TRIM '(' LEADING trim_list ')'
- {
- $$ = make3_str(make1_str("trim(leading"), $4, make1_str(")"));
- }
- | TRIM '(' TRAILING trim_list ')'
- {
- $$ = make3_str(make1_str("trim(trailing"), $4, make1_str(")"));
- }
- | TRIM '(' trim_list ')'
- {
- $$ = make3_str(make1_str("trim("), $3, make1_str(")"));
- }
- | a_expr ISNULL
- { $$ = cat2_str($1, make1_str("isnull")); }
- | a_expr IS NULL_P
- { $$ = cat2_str($1, make1_str("is null")); }
- | a_expr NOTNULL
- { $$ = cat2_str($1, make1_str("notnull")); }
- | a_expr IS NOT NULL_P
- { $$ = cat2_str($1, make1_str("is not null")); }
- /* IS TRUE, IS FALSE, etc used to be function calls
- * but let's make them expressions to allow the optimizer
- * a chance to eliminate them if a_expr is a constant string.
- * - thomas 1997-12-22
- */
- | a_expr IS TRUE_P
- {
- { $$ = cat2_str($1, make1_str("is true")); }
- }
- | a_expr IS NOT FALSE_P
- {
- { $$ = cat2_str($1, make1_str("is not false")); }
- }
- | a_expr IS FALSE_P
- {
- { $$ = cat2_str($1, make1_str("is false")); }
- }
- | a_expr IS NOT TRUE_P
- {
- { $$ = cat2_str($1, make1_str("is not true")); }
- }
- | a_expr BETWEEN b_expr AND b_expr
- {
- $$ = cat5_str($1, make1_str("between"), $3, make1_str("and"), $5);
- }
- | a_expr NOT BETWEEN b_expr AND b_expr
- {
- $$ = cat5_str($1, make1_str("not between"), $4, make1_str("and"), $6);
- }
- | a_expr IN '(' in_expr ')'
- {
- $$ = make4_str($1, make1_str(" in ("), $4, make1_str(")"));
- }
- | a_expr NOT IN '(' not_in_expr ')'
- {
- $$ = make4_str($1, make1_str(" not in ("), $5, make1_str(")"));
- }
- | a_expr Op '(' SubSelect ')'
- {
- $$ = cat3_str($1, $2, make3_str(make1_str("("), $4, make1_str(")")));
- }
- | a_expr '+' '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("+("), $4, make1_str(")"));
- }
- | a_expr '-' '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("-("), $4, make1_str(")"));
- }
- | a_expr '/' '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("/("), $4, make1_str(")"));
- }
- | a_expr '%' '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("%("), $4, make1_str(")"));
- }
- | a_expr '*' '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("*("), $4, make1_str(")"));
- }
- | a_expr '<' '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("<("), $4, make1_str(")"));
- }
- | a_expr '>' '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str(">("), $4, make1_str(")"));
- }
- | a_expr '=' '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("=("), $4, make1_str(")"));
- }
- | a_expr Op ANY '(' SubSelect ')'
- {
- $$ = cat3_str($1, $2, make3_str(make1_str("any ("), $5, make1_str(")")));
- }
- | a_expr '+' ANY '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("+ any("), $5, make1_str(")"));
- }
- | a_expr '-' ANY '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("- any("), $5, make1_str(")"));
- }
- | a_expr '/' ANY '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("/ any("), $5, make1_str(")"));
- }
- | a_expr '%' ANY '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("% any("), $5, make1_str(")"));
- }
- | a_expr '*' ANY '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("* any("), $5, make1_str(")"));
- }
- | a_expr '<' ANY '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("< any("), $5, make1_str(")"));
- }
- | a_expr '>' ANY '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("> any("), $5, make1_str(")"));
- }
- | a_expr '=' ANY '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("= any("), $5, make1_str(")"));
- }
- | a_expr Op ALL '(' SubSelect ')'
- {
- $$ = cat3_str($1, $2, make3_str(make1_str("all ("), $5, make1_str(")")));
- }
- | a_expr '+' ALL '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("+ all("), $5, make1_str(")"));
- }
- | a_expr '-' ALL '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("- all("), $5, make1_str(")"));
- }
- | a_expr '/' ALL '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("/ all("), $5, make1_str(")"));
- }
- | a_expr '%' ALL '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("% all("), $5, make1_str(")"));
- }
- | a_expr '*' ALL '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("* all("), $5, make1_str(")"));
- }
- | a_expr '<' ALL '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("< all("), $5, make1_str(")"));
- }
- | a_expr '>' ALL '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("> all("), $5, make1_str(")"));
- }
- | a_expr '=' ALL '(' SubSelect ')'
- {
- $$ = make4_str($1, make1_str("=all("), $5, make1_str(")"));
- }
- | a_expr AND ecpg_expr
- { $$ = cat3_str($1, make1_str("and"), $3); }
- | a_expr OR ecpg_expr
- { $$ = cat3_str($1, make1_str("or"), $3); }
- | NOT ecpg_expr
- { $$ = cat2_str(make1_str("not"), $2); }
- | case_expr
- { $$ = $1; }
- | civariableonly
- { $$ = $1; }
- ;
- into_list : coutputvariable | into_list ',' coutputvariable;
- ecpgstart: SQL_START { reset_variables();}
- dotext: /* empty */ { $$ = make1_str(""); }
- | dotext do_anything { $$ = make2_str($1, $2); }
- vartext: var_anything { $$ = $1; }
- | vartext var_anything { $$ = make2_str($1, $2); }
- coutputvariable : cvariable indicator {
- add_variable(&argsresult, find_variable($1), ($2 == NULL) ? &no_indicator : find_variable($2));
- }
- cinputvariable : cvariable indicator {
- add_variable(&argsinsert, find_variable($1), ($2 == NULL) ? &no_indicator : find_variable($2));
- }
- civariableonly : cvariable {
- add_variable(&argsinsert, find_variable($1), &no_indicator);
- $$ = make1_str("?");
- }
- cvariable: CVARIABLE { $$ = $1; }
- indicator: /* empty */ { $$ = NULL; }
- | cvariable { check_indicator((find_variable($1))->type); $$ = $1; }
- | SQL_INDICATOR cvariable { check_indicator((find_variable($2))->type); $$ = $2; }
- | SQL_INDICATOR name { check_indicator((find_variable($2))->type); $$ = $2; }
- ident: IDENT { $$ = $1; }
- | CSTRING { $$ = $1; }
- /*
- * C stuff
- */
- symbol: IDENT { $$ = $1; }
- cpp_line: CPP_LINE { $$ = $1; }
- c_line: c_anything { $$ = $1; }
- | c_line c_anything
- {
- $$ = make2_str($1, $2);
- }
- c_thing: c_anything | ';' { $$ = make1_str(";"); }
- c_anything: IDENT { $$ = $1; }
- | CSTRING { $$ = make3_str(make1_str("""), $1, make1_str(""")); }
- | Iconst { $$ = $1; }
- | Fconst { $$ = $1; }
- | '*' { $$ = make1_str("*"); }
- | '+' { $$ = make1_str("+"); }
- | '-' { $$ = make1_str("-"); }
- | '/' { $$ = make1_str("/"); }
- | '%' { $$ = make1_str("%"); }
- | S_AUTO { $$ = make1_str("auto"); }
- | S_BOOL { $$ = make1_str("bool"); }
- | S_CHAR { $$ = make1_str("char"); }
- | S_CONST { $$ = make1_str("const"); }
- | S_DOUBLE { $$ = make1_str("double"); }
- | S_ENUM { $$ = make1_str("enum"); }
- | S_EXTERN { $$ = make1_str("extern"); }
- | S_FLOAT { $$ = make1_str("float"); }
- | S_INT { $$ = make1_str("int"); }
- | S_LONG { $$ = make1_str("long"); }
- | S_REGISTER { $$ = make1_str("register"); }
- | S_SHORT { $$ = make1_str("short"); }
- | S_SIGNED { $$ = make1_str("signed"); }
- | S_STATIC { $$ = make1_str("static"); }
- | S_STRUCT { $$ = make1_str("struct"); }
- | S_UNION { $$ = make1_str("union"); }
- | S_UNSIGNED { $$ = make1_str("unsigned"); }
- | S_VARCHAR { $$ = make1_str("varchar"); }
- | S_ANYTHING { $$ = make_name(); }
- | '[' { $$ = make1_str("["); }
- | ']' { $$ = make1_str("]"); }
- | '(' { $$ = make1_str("("); }
- | ')' { $$ = make1_str(")"); }
- | '=' { $$ = make1_str("="); }
- | ',' { $$ = make1_str(","); }
- do_anything: IDENT { $$ = $1; }
- | CSTRING { $$ = make3_str(make1_str("""), $1, make1_str("""));}
- | Iconst { $$ = $1; }
- | Fconst { $$ = $1; }
- | ',' { $$ = make1_str(","); }
- var_anything: IDENT { $$ = $1; }
- | CSTRING { $$ = make3_str(make1_str("""), $1, make1_str(""")); }
- | Iconst { $$ = $1; }
- | Fconst { $$ = $1; }
- | '{' c_line '}' { $$ = make3_str(make1_str("{"), $2, make1_str("}")); }
- blockstart : '{' {
- braces_open++;
- $$ = make1_str("{");
- }
- blockend : '}' {
- remove_variables(braces_open--);
- $$ = make1_str("}");
- }
- %%
- void yyerror(char * error)
- {
- fprintf(stderr, "%s:%d: %sn", input_filename, yylineno, error);
- exit(PARSE_ERROR);
- }