MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / check_foreign_key

Function check_foreign_key

src/jrd/idx.cpp:1777–1865  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1775
1776
1777static idx_e check_foreign_key(thread_db* tdbb,
1778 Record* record,
1779 jrd_rel* relation,
1780 jrd_tra* transaction,
1781 index_desc* idx,
1782 IndexErrorContext& context)
1783{
1784/**************************************
1785 *
1786 * c h e c k _ f o r e i g n _ k e y
1787 *
1788 **************************************
1789 *
1790 * Functional description
1791 * The passed index participates in a foreign key.
1792 * Check the passed record to see if a corresponding
1793 * record appears in the partner index.
1794 *
1795 **************************************/
1796 SET_TDBB(tdbb);
1797
1798 idx_e result = idx_e_ok;
1799
1800 if (!MET_lookup_partner(tdbb, relation, idx, 0))
1801 return result;
1802
1803 jrd_rel* partner_relation = NULL;
1804 USHORT index_id = 0;
1805
1806 if (idx->idx_flags & idx_foreign)
1807 {
1808 partner_relation = MET_relation(tdbb, idx->idx_primary_relation);
1809 index_id = idx->idx_primary_index;
1810 result = check_partner_index(tdbb, relation, record, transaction, idx,
1811 partner_relation, index_id);
1812 }
1813 else if (idx->idx_flags & (idx_primary | idx_unique))
1814 {
1815 for (int index_number = 0;
1816 index_number < (int) idx->idx_foreign_primaries->count();
1817 index_number++)
1818 {
1819 if (idx->idx_id != (*idx->idx_foreign_primaries)[index_number])
1820 continue;
1821
1822 partner_relation = MET_relation(tdbb, (*idx->idx_foreign_relations)[index_number]);
1823 index_id = (*idx->idx_foreign_indexes)[index_number];
1824
1825 if ((relation->rel_flags & REL_temp_conn) && (partner_relation->rel_flags & REL_temp_tran))
1826 {
1827 jrd_rel::RelPagesSnapshot pagesSnapshot(tdbb, partner_relation);
1828 partner_relation->fillPagesSnapshot(pagesSnapshot, true);
1829
1830 for (FB_SIZE_T i = 0; i < pagesSnapshot.getCount(); i++)
1831 {
1832 RelationPages* partnerPages = pagesSnapshot[i];
1833 tdbb->tdbb_temp_traid = partnerPages->rel_instance_id;
1834 if ( (result = check_partner_index(tdbb, relation, record,

Callers 3

IDX_eraseFunction · 0.85
insert_keyFunction · 0.85

Calls 6

SET_TDBBFunction · 0.85
check_partner_indexFunction · 0.85
fillPagesSnapshotMethod · 0.80
setErrorLocationMethod · 0.80
countMethod · 0.45
getCountMethod · 0.45

Tested by

no test coverage detected