| 540 | } |
| 541 | |
| 542 | void Applier::insertRecord(thread_db* tdbb, TraNumber traNum, |
| 543 | const MetaName& relName, |
| 544 | ULONG length, const UCHAR* data) |
| 545 | { |
| 546 | jrd_tra* transaction = NULL; |
| 547 | if (!m_txnMap.get(traNum, transaction)) |
| 548 | raiseError("Transaction %" SQUADFORMAT" is not found", traNum); |
| 549 | |
| 550 | LocalThreadContext context(tdbb, transaction, m_request); |
| 551 | Jrd::ContextPoolHolder context2(tdbb, m_request->req_pool); |
| 552 | |
| 553 | TRA_attach_request(transaction, m_request); |
| 554 | |
| 555 | const auto relation = MET_lookup_relation(tdbb, relName); |
| 556 | if (!relation) |
| 557 | raiseError("Table %s is not found", relName.c_str()); |
| 558 | |
| 559 | if (!(relation->rel_flags & REL_scanned)) |
| 560 | MET_scan_relation(tdbb, relation); |
| 561 | |
| 562 | const auto format = findFormat(tdbb, relation, length); |
| 563 | |
| 564 | record_param rpb; |
| 565 | rpb.rpb_relation = relation; |
| 566 | |
| 567 | rpb.rpb_record = m_record; |
| 568 | const auto record = m_record = |
| 569 | VIO_record(tdbb, &rpb, format, tdbb->getDefaultPool()); |
| 570 | |
| 571 | rpb.rpb_format_number = format->fmt_version; |
| 572 | rpb.rpb_address = record->getData(); |
| 573 | rpb.rpb_length = length; |
| 574 | record->copyDataFrom(data); |
| 575 | |
| 576 | FbLocalStatus error; |
| 577 | |
| 578 | try |
| 579 | { |
| 580 | doInsert(tdbb, &rpb, transaction); |
| 581 | return; |
| 582 | } |
| 583 | catch (const status_exception& ex) |
| 584 | { |
| 585 | // Uniqueness violation is handled below, other exceptions are re-thrown |
| 586 | if (ex.value()[1] != isc_unique_key_violation && |
| 587 | ex.value()[1] != isc_no_dup) |
| 588 | { |
| 589 | throw; |
| 590 | } |
| 591 | |
| 592 | ex.stuffException(&error); |
| 593 | fb_utils::init_status(tdbb->tdbb_status_vector); |
| 594 | |
| 595 | // The subsequent backout will delete the blobs we have stored before, |
| 596 | // so we have to copy them and adjust the references |
| 597 | for (USHORT id = 0; id < format->fmt_count; id++) |
| 598 | { |
| 599 | dsc desc; |
no test coverage detected