| 2423 | // |
| 2424 | |
| 2425 | static act* act_declare_table( gpre_sym* symbol, gpre_dbb* db) |
| 2426 | { |
| 2427 | // create a local request block |
| 2428 | |
| 2429 | gpre_req* request = (gpre_req*) MSC_alloc(REQ_LEN); |
| 2430 | request->req_type = REQ_ddl; |
| 2431 | |
| 2432 | // create relation block |
| 2433 | |
| 2434 | gpre_rel* relation = make_relation(0, symbol->sym_string); |
| 2435 | |
| 2436 | if (!db) |
| 2437 | db = relation->rel_database; |
| 2438 | |
| 2439 | request->req_database = db; |
| 2440 | |
| 2441 | relation->rel_next = db->dbb_relations; |
| 2442 | db->dbb_relations = relation; |
| 2443 | gpre_fld* dbkey = MET_make_field("rdb$db_key", dtype_text, 8, false); |
| 2444 | relation->rel_dbkey = dbkey; |
| 2445 | dbkey->fld_flags |= FLD_dbkey | FLD_text | FLD_charset; |
| 2446 | dbkey->fld_ttype = ttype_binary; |
| 2447 | |
| 2448 | // if relation name already in incore metadata, remove it & its fields |
| 2449 | |
| 2450 | gpre_sym* old_symbol = HSH_lookup(relation->rel_symbol->sym_string); |
| 2451 | |
| 2452 | while (old_symbol) |
| 2453 | { |
| 2454 | if (old_symbol->sym_type == SYM_relation) |
| 2455 | { |
| 2456 | gpre_rel* tmp_relation = (gpre_rel*) old_symbol->sym_object; |
| 2457 | if (tmp_relation->rel_meta) |
| 2458 | PAR_error("Multiple DECLARE TABLE statements for table"); |
| 2459 | gpre_sym* tmp_symbol = old_symbol->sym_homonym; |
| 2460 | HSH_remove(old_symbol); |
| 2461 | for (gpre_fld* field = tmp_relation->rel_fields; field; field = field->fld_next) |
| 2462 | { |
| 2463 | HSH_remove(field->fld_symbol); |
| 2464 | } |
| 2465 | old_symbol = tmp_symbol; |
| 2466 | } |
| 2467 | else |
| 2468 | old_symbol = old_symbol->sym_homonym; |
| 2469 | } |
| 2470 | |
| 2471 | // add new symbol to incore metadata |
| 2472 | |
| 2473 | HSH_insert(relation->rel_symbol); |
| 2474 | |
| 2475 | // create action block |
| 2476 | |
| 2477 | act* action = (act*) MSC_alloc(ACT_LEN); |
| 2478 | action->act_type = ACT_noop; |
| 2479 | action->act_object = (ref*) relation; |
| 2480 | |
| 2481 | // parse field list and create corresponding field blocks |
| 2482 | // include size information for message length calculations |
no test coverage detected