| 2594 | // |
| 2595 | |
| 2596 | static act* act_delete() |
| 2597 | { |
| 2598 | const TEXT* transaction; |
| 2599 | |
| 2600 | par_options(&transaction); |
| 2601 | |
| 2602 | if (!MSC_match(KW_FROM)) |
| 2603 | CPR_s_error("FROM"); |
| 2604 | |
| 2605 | // First comes the relation. Unfortunately, there is no way to identify |
| 2606 | // its database until the cursor is known. Sigh. Save the token. |
| 2607 | |
| 2608 | TEXT r_name[NAME_SIZE], db_name[NAME_SIZE], owner_name[NAME_SIZE]; |
| 2609 | SQL_relation_name(r_name, db_name, owner_name); |
| 2610 | |
| 2611 | // Parse the optional alias (context variable) |
| 2612 | |
| 2613 | gpre_sym* alias = gpreGlob.token_global.tok_symbol ? NULL : PAR_symbol(SYM_dummy); |
| 2614 | |
| 2615 | // Now the moment of truth. If the next few tokens are WHERE CURRENT OF |
| 2616 | // then this is a sub-action of an existing request. If not, then it is |
| 2617 | // a free standing request |
| 2618 | |
| 2619 | gpre_req* request = MSC_request(REQ_mass_update); |
| 2620 | upd* update = (upd*) MSC_alloc(UPD_LEN); |
| 2621 | |
| 2622 | const bool where = MSC_match(KW_WITH); |
| 2623 | if (where && MSC_match(KW_CURRENT)) |
| 2624 | { |
| 2625 | if (!MSC_match(KW_OF)) |
| 2626 | CPR_s_error("OF <cursor>"); |
| 2627 | gpreGlob.requests = request->req_next; |
| 2628 | gpreGlob.cur_routine->act_object = (ref*) request->req_routine; // Beware global var |
| 2629 | MSC_free(request); |
| 2630 | request = par_cursor(NULL); |
| 2631 | if ((transaction || request->req_trans) && |
| 2632 | (!transaction || !request->req_trans || strcmp(transaction, request->req_trans))) |
| 2633 | { |
| 2634 | if (transaction) |
| 2635 | PAR_error("different transaction for select and delete"); |
| 2636 | else |
| 2637 | { |
| 2638 | // does not specify transaction clause in |
| 2639 | // "delete ... where current of cursor" stmt |
| 2640 | const int trans_nm_len = static_cast<int>(strlen(request->req_trans)); |
| 2641 | char* str_2 = (char*) MSC_alloc(trans_nm_len + 1); |
| 2642 | memcpy(str_2, request->req_trans, trans_nm_len); |
| 2643 | transaction = str_2; |
| 2644 | } |
| 2645 | } |
| 2646 | request->req_trans = transaction; |
| 2647 | gpre_rel* relation = SQL_relation(request, r_name, db_name, owner_name, true); |
| 2648 | gpre_rse* selection = request->req_rse; |
| 2649 | gpre_ctx* context = NULL; |
| 2650 | SSHORT i; |
| 2651 | for (i = 0; i < selection->rse_count; i++) |
| 2652 | { |
| 2653 | context = selection->rse_context[i]; |
no test coverage detected