| 2986 | |
| 2987 | |
| 2988 | bool VIO_get_current(thread_db* tdbb, |
| 2989 | record_param* rpb, |
| 2990 | jrd_tra* transaction, |
| 2991 | MemoryPool* pool, |
| 2992 | bool foreign_key, |
| 2993 | bool& rec_tx_active) |
| 2994 | { |
| 2995 | /************************************** |
| 2996 | * |
| 2997 | * V I O _ g e t _ c u r r e n t |
| 2998 | * |
| 2999 | ************************************** |
| 3000 | * |
| 3001 | * Functional description |
| 3002 | * Get the current (most recent) version of a record. This is |
| 3003 | * called by IDX to determine whether a unique index has been |
| 3004 | * duplicated. If the target record's transaction is active, |
| 3005 | * wait for it. If the record is deleted or disappeared, return |
| 3006 | * false. If the record is committed, return true. |
| 3007 | * If foreign_key is true, we are checking for a foreign key, |
| 3008 | * looking to see if a primary key/unique key exists. For a |
| 3009 | * no wait transaction, if state of transaction inserting primary key |
| 3010 | * record is tra_active, we should not see the uncommitted record |
| 3011 | * |
| 3012 | **************************************/ |
| 3013 | SET_TDBB(tdbb); |
| 3014 | |
| 3015 | #ifdef VIO_DEBUG |
| 3016 | jrd_rel* relation = rpb->rpb_relation; |
| 3017 | VIO_trace(DEBUG_TRACE, |
| 3018 | "VIO_get_current (rel_id %u, record_param %" QUADFORMAT"d, transaction %" SQUADFORMAT", pool %p)\n", |
| 3019 | relation->rel_id, rpb->rpb_number.getValue(), transaction ? transaction->tra_number : 0, |
| 3020 | (void*) pool); |
| 3021 | #endif |
| 3022 | |
| 3023 | rec_tx_active = false; |
| 3024 | |
| 3025 | bool counted = false; |
| 3026 | |
| 3027 | while (true) |
| 3028 | { |
| 3029 | // If the record doesn't exist, no problem. |
| 3030 | |
| 3031 | if (!DPM_get(tdbb, rpb, LCK_read)) |
| 3032 | return false; |
| 3033 | |
| 3034 | #ifdef VIO_DEBUG |
| 3035 | VIO_trace(DEBUG_TRACE_INFO, |
| 3036 | " record %" SLONGFORMAT":%d, rpb_trans %" SQUADFORMAT |
| 3037 | ", flags %d, back %" SLONGFORMAT":%d, fragment %" SLONGFORMAT":%d\n", |
| 3038 | rpb->rpb_page, rpb->rpb_line, rpb->rpb_transaction_nr, |
| 3039 | rpb->rpb_flags, rpb->rpb_b_page, rpb->rpb_b_line, |
| 3040 | rpb->rpb_f_page, rpb->rpb_f_line); |
| 3041 | #endif |
| 3042 | |
| 3043 | // Get data if there is data. |
| 3044 | |
| 3045 | if (rpb->rpb_flags & rpb_damaged) |
no test coverage detected