/* ===================================================================== Source: sql_4gl.rule ===================================================================== */ fetch_cmd : opt_use2_p FETCH fetch_part_f opt_into_fetch_part { $$=new_fetch_cmd($1, $3, $4); } ; declare_cursor_name_and_clr_p : ident_or_var_sql_p { $$=$1; doing_declare=1; A4GL_cursor_defined($1,0); //start_bind('i',0); //start_bind('o',0); } ; fetch_part_f: fetch_place_fp fetch_cursor_name_p { A4GL_cursor_fetch($2,$1); ADDMAP_P("Fetch Cursor",$2); $$=acl_malloc2(sizeof(struct s_fetch)); $$->cursorname=$2; $$->fp=$1; } | fetch_cursor_name_p { struct s_fetch_place *fp; fp=acl_malloc2(sizeof(struct s_fetch_place)); fp->ab_rel=FETCH_RELATIVE; fp->fetch_expr=chk_expr(A4GL_new_literal_long_long(1)); A4GL_cursor_fetch($1,fp); ADDMAP_P("Fetch Cursor",$1); $$=acl_malloc2(sizeof(struct s_fetch)); $$->cursorname=$1; $$->fp=fp; } ; opt_into_fetch_part: { $$=0;} | INTO expanded_obind_var_list { $$=$2; } ; opt_foreach_into_fetch_part: { #ifdef DEBUG A4GL_debug("no into\n"); #endif $$=0; } | INTO expanded_obind_var_list { $$=$2; } ; fetch_place_fp : KW_FIRST { $$=acl_malloc2(sizeof(struct s_fetch_place)); $$->ab_rel=FETCH_ABSOLUTE; $$->fetch_expr=chk_expr(A4GL_new_literal_long_long(1)); add_feature("FETCH_FIRST"); } | KW_LAST { $$=acl_malloc2(sizeof(struct s_fetch_place)); $$->ab_rel=FETCH_ABSOLUTE; $$->fetch_expr=chk_expr(A4GL_new_literal_long_long(-1)); add_feature("FETCH_LAST"); } | KW_NEXT { $$=acl_malloc2(sizeof(struct s_fetch_place)); $$->ab_rel=FETCH_RELATIVE; $$->fetch_expr=chk_expr(A4GL_new_literal_long_long(1)); add_feature("FETCH_NEXT"); } | KW_PREVIOUS { $$=acl_malloc2(sizeof(struct s_fetch_place)); $$->ab_rel=FETCH_RELATIVE; $$->fetch_expr=chk_expr(A4GL_new_literal_long_long(-1)); add_feature("FETCH_PREVIOUS"); } | KW_PRIOR { $$=acl_malloc2(sizeof(struct s_fetch_place)); $$->ab_rel=FETCH_RELATIVE; $$->fetch_expr=chk_expr(A4GL_new_literal_long_long(-1)); add_feature("FETCH_PREVIOUS"); } | KW_CURRENT { $$=acl_malloc2(sizeof(struct s_fetch_place)); $$->ab_rel=FETCH_RELATIVE; $$->fetch_expr=chk_expr(A4GL_new_literal_long_long(0)); add_feature("FETCH_CURRENT"); } | KW_RELATIVE fgl_expr_c { $$=acl_malloc2(sizeof(struct s_fetch_place)); $$->ab_rel=FETCH_RELATIVE; $$->fetch_expr=chk_expr($2); add_feature("FETCH_RELATIVE"); } | KW_ABSOLUTE fgl_expr_c { $$=acl_malloc2(sizeof(struct s_fetch_place)); $$->ab_rel=FETCH_ABSOLUTE; $$->fetch_expr=chk_expr($2); add_feature("FETCH_ABSOLUTE"); } ; sql_cmd : opt_use2_p {insql=1;} sql_commands { $$=new_sql_cmd($1,$3); insql=0; } ; sql_bound_cmd : opt_use2_p insert_statement_c { $$=new_command (E_CMD_INSERT_CMD); memcpy(&$$->cmd_data.command_data_u.insert_cmd, $2, sizeof($$->cmd_data.command_data_u.insert_cmd)); $$->cmd_data.command_data_u.insert_cmd.connid=$1; } | opt_use2_p update_statement_c { $$=new_command (E_CMD_UPDATE_CMD); memcpy(&$$->cmd_data.command_data_u.update_cmd, $2, sizeof($$->cmd_data.command_data_u.update_cmd)); $$->cmd_data.command_data_u.update_cmd.connid=$1; } | opt_use2_p delete_statement_c { $$=new_command (E_CMD_DELETE_CMD); memcpy(&$$->cmd_data.command_data_u.delete_cmd, $2, sizeof($$->cmd_data.command_data_u.delete_cmd)); $$->cmd_data.command_data_u.delete_cmd.connid=$1; } ; sql_transact_cmd : opt_use2_p {insql=1;} sql_transact_commands { $$=new_sql_transact_cmd($1, $3); insql=0; } ; sql_create_procedure_cmd : opt_use2_p {insql=1;} create_procedure { $$=new_create_procedure_cmd($1, $3); insql=0; } ; flush_cmd : opt_use2_p FLUSH fetch_cursor_name_p { $$=new_flush_cmd($1,$3); A4GL_cursor_flush($3); ADDMAP_P("Flush Cursor",$3); add_feature("FLUSH"); } ; declare_cmd : opt_use2_p DECLARE declare_cursor_name_and_clr_p CURSOR KW_FOR cursor_specification1_all_ss {insql=0;chk4var=0; add_feature("CURSOR_SELECT"); check_cursor_name($3); $$=new_declare_cmd($1,$3,&$6, 0,0,EB_TRUE); ADDMAP("Declare Cursor",getcursorName($3)); doing_declare=0; } | opt_use2_p DECLARE declare_cursor_name_and_clr_p CURSOR KW_FOR cursor_specification1_ins_ss {insql=0;chk4var=0; add_feature("CURSOR_SELECT"); check_cursor_name($3); $$=new_declare_cmd($1,$3,&$6, 0,0,EB_FALSE); ADDMAP("Declare Cursor",getcursorName($3)); doing_declare=0; } | opt_use2_p DECLARE declare_cursor_name_and_clr_p CURSOR WITH_HOLD KW_FOR cursor_specification1_ins_ss {insql=0;chk4var=0; add_feature("CURSOR_SELECT"); check_cursor_name($3); $$=new_declare_cmd($1,$3,&$7, 1,0,EB_FALSE); ADDMAP("Declare Cursor",getcursorName($3)); doing_declare=0; } | opt_use2_p DECLARE declare_cursor_name_and_clr_p CURSOR WITH_HOLD KW_FOR cursor_specification1_all_ss {insql=0;chk4var=0; add_feature("CURSOR_SELECT"); add_feature("HOLD_CURSOR"); check_cursor_name($3); $$=new_declare_cmd($1,$3, &$7,1,0,EB_TRUE); ADDMAP("Declare Cursor",getcursorName($3)); doing_declare=0; } | opt_use2_p DECLARE declare_cursor_name_and_clr_p SCROLL_CURSOR_FOR cursor_specification_sel_ss {insql=0;chk4var=0; add_feature("CURSOR_SELECT"); add_feature("SCROLL_CURSOR"); check_cursor_name($3); $$=new_declare_cmd($1,$3, &$5, 0,1,EB_FALSE); ADDMAP("Declare Cursor",$3); doing_declare=0; } | opt_use2_p DECLARE declare_cursor_name_and_clr_p SCROLL_CURSOR WITH_HOLD KW_FOR cursor_specification_sel_ss {insql=0;chk4var=0; add_feature("CURSOR_SELECT"); add_feature("SCROLL_CURSOR"); add_feature("HOLD_CURSOR"); check_cursor_name($3); $$=new_declare_cmd($1,$3, &$7, 1,1,EB_FALSE); ADDMAP("Declare Cursor",$3); doing_declare=0; } ; curs_forupdate : {strcpy($$,"");} | FOR_UPDATE { if ( A4GLSQLCV_check_requirement("NO_FOR_UPDATE") || A4GLSQLCV_check_requirement("EMULATE_FOR_UPDATE")) { strcpy($$,""); } else { strcpy($$," FOR UPDATE"); } add_feature("CURSOR_SELECT_FOR_UPDATE"); } | FOR_UPDATE_OF cur_update_list { if ( A4GLSQLCV_check_requirement("NO_FOR_UPDATE") ||A4GLSQLCV_check_requirement("EMULATE_FOR_UPDATE")) { strcpy($$,""); } else { SPRINTF1($$," FOR UPDATE OF %s",$2); } add_feature("CURSOR_SELECT_FOR_UPDATE"); } ; cursor_specification1_all_ss: cursor_specification_sel_ss { memcpy(&$$, &$1,sizeof($1)); } ; cursor_specification1_ins_ss: insert_statement_c { A4GL_cursor_is_insert(); if (A4GLSQLCV_check_requirement("NO_INSERT_CURSOR")) { a4gl_yyerror("Insert cursors are not supported for this rdbms"); } $$.insert_cmd=$1; $$.select=NULL; $$.ident=NULL; $$.forUpdate=0; //start_bind('i',0); //start_bind('o',0); } ; cursor_specification_sel_ss: stmt_id_p { $$.insert_cmd=NULL; $$.ident=$1; $$.select=NULL; $$.forUpdate=0; } | select_statement_ss_select curs_forupdate { //char *ptr; A4GL_set_sql_lineno(yylineno); A4GL_cursor_is_select(); $$.insert_cmd=NULL; $$.ident=NULL; $$.select=$1; /* acl_strdup(A4GL_CV_print_select_all(ptr,$$.inbind, $$.outbind,1)); */ $$.forUpdate=strdup($2); map_select_stmt("SELECT",$1); } ; value_expression_initial_sli: value_expression_initial_sli_nocast { $$=$1; } | value_expression_initial_sli_nocast DOUBLE_COLON data_type { $$=new_select_list_item_cast($1, $3); } ; value_expression_initial_sli_nocast : subquery_sli { $$=new_select_list_item_sq(E_SQE_DONT_CARE,$1); } | value_expression_complex_sli { $1=$1; } | var_ident_ibind_sli { $1=$1; } | ALL subquery_sli { $$=new_select_list_item_sq(E_SQE_ALL,$2); } | ANY subquery_sli { $$=new_select_list_item_sq(E_SQE_ANY,$2); } | SOME subquery_sli { $$=new_select_list_item_sq(E_SQE_SOME,$2); } | ATSIGN identifier op_col_arr { $$=new_select_list_item_col(0,$2,&$3); } | ATSIGN identifier KW_DOT identifier op_col_arr { $$=new_select_list_item_col($2,$4,&$5); } | identifier COLON identifier KW_DOT identifier op_col_arr { char buff[2000];SPRINTF2(buff,"%s:%s",$1,$3); $$=new_select_list_item_col(buff,$5,&$6); } ; select_cmd : opt_use2_p select_statement_ss_select curs_forupdate { /* SQL HAS ALREADY BEEN CONVERTED */ //char *ptr; //lo=copy_togenbind('o'); //li=copy_togenbind('i'); if (strstr($3,"FOR UPDATE")) { PRINTF("Warning SELECT ... FOR UPDATE when not declaring a cursor currently has no locking effect\n"); } //ptr=make_select_stmt(current_upd_table, $2); $$=new_select_cmd($1,$2,$3); map_select_stmt("SELECT",$2); //free(ptr); //start_bind('i',0); //start_bind('o',0); } ; dbase_name : identifier {strcpy($$,$1);} | identifier ATSIGN identifier {SPRINTF2($$,"%s@%s",$1,$3);} | identifier ATSIGN identifier COLON identifier {SPRINTF3($$,"%s@%s:%s",$1,$3,$5);} | identifier ATSIGN identifier COLON INT_VALUE {SPRINTF3($$,"%s@%s:%s",$1,$3,$5);} | CHAR_VALUE {strcpy($$, A4GL_strip_quotes ($1));} ; cur_update_list : colident {strcpy($$,$1);} | cur_update_list KW_COMMA colident {SPRINTF2($$,"%s,%s",$1,$3);} ; colident: identifier | identifier KW_DOT identifier {SPRINTF2($$,"%s.%s",$1,$3);} | CHAR_VALUE KW_DOT identifier KW_DOT identifier { SPRINTF2($$,"%s.%s", A4GLSQLCV_ownerize_tablename($1, $3), $5); } ; in_select_statement: select_statement_ss_select { $$=$1; } ; set_database_cmd : DATABASE var_ident_qchar_e op_db_exclusive op_using_sqltype { add_feature("DATABASE_USED"); $$=new_set_database_cmd(chk_expr($2),$3,$4); } ; load_cmd : opt_use2_p LOAD_FROM ufile opt_delim_load INSERT_INTO table_name_not_for_column_prefix opt_col_list { //A4GL_add_crud("INSERT",$6); add_feature("LOAD_FROM_INSERT_INTO"); $$=new_load_cmd($1,$3, $4,NULL,$6,$7); } | opt_use2_p LOAD_FROM ufile opt_delim_load ensured_variable_usage_expression { add_feature("LOAD_FROM_VARIABLE"); $$=new_load_cmd($1,$3, $4,$5,NULL,NULL); } ; unload_cmd : opt_use2_p UNLOAD_TO ufile opt_delim_unload uselect_statement2_p { add_feature("UNLOAD_TO"); /* if (strcasecmp($5," WHERE ")==0) { add_feature("UNLOAD_TO_SELECT_WHERE"); } */ /* @FIXME - add this back in... */ add_feature("UNLOAD_TO"); $$=new_unload_cmd($1,$5, $3, $4); } ; opt_col_list: { $$=0; } | OPEN_BRACKET col_list CLOSE_BRACKET { $$=$2;} ; col_list : simple_column_name { $$=acl_malloc2(sizeof(struct str_list)); $$->str_list_entry.str_list_entry_len=1; $$->str_list_entry.str_list_entry_val=acl_malloc2(sizeof($$->str_list_entry.str_list_entry_val[0]) * $$->str_list_entry.str_list_entry_len); $$->str_list_entry.str_list_entry_val[$$->str_list_entry.str_list_entry_len-1]=strdup($1); } | col_list KW_COMMA simple_column_name { $$= $1; $$->str_list_entry.str_list_entry_len=$1->str_list_entry.str_list_entry_len+1; $$->str_list_entry.str_list_entry_val=realloc($1->str_list_entry.str_list_entry_val, sizeof($$->str_list_entry.str_list_entry_val[0]) * $$->str_list_entry.str_list_entry_len); $$->str_list_entry.str_list_entry_val[$$->str_list_entry.str_list_entry_len-1]=strdup($3); } ; ufile : char_or_var_vl { $$=$1; } ; uselect_statement2_p: uu_select_statement21_select { $$=$1; } | char_or_var_vl { $$=$1; } ; opt_into_sel : { //start_bind('o',0); $$=0; } | INTO expanded_obind_var_list { $$=$2; } ; callback_function: identifier { $$=A4GL_new_expr_funcdef($1,get_namespace($1)); } ; opt_delim_load : { $$=0; } | DELIMITER char_or_var_vl { $$=$2; } | KW_USING_FILTER callback_function { $$=$2; } ; opt_delim_unload : { $$=0; } | DELIMITER char_or_var_vl { $$=$2; } ; /* ========================= sql_4gl.rule ================================ */