Changes between Version 3 and Version 4 of DatabaseProgramming


Ignore:
Timestamp:
05/31/26 00:26:50 (2 weeks ago)
Author:
231101
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DatabaseProgramming

    v3 v4  
    2626
    2727```
    28 -- Проверка дали книгата е достапна
    2928SELECT available
    3029INTO v_available
     
    3635END IF;
    3736
    38 -- Проверка дали членот е активен
    3937SELECT membership_status
    4038INTO v_membership_status
     
    4644END IF;
    4745
    48 -- Креирање borrowing
    4946INSERT INTO borrowing(
    5047    borrowing_id,
     
    6865);
    6966
    70 -- Update availability
     67
    7168UPDATE bookcopy
    7269SET available = 0
     
    112109
    113110```
    114 -- check for existing member
     111
    115112SELECT COUNT(*)
    116113INTO v_existing_member
     
    122119END IF;
    123120
    124 -- check for existing email
     121
    125122SELECT COUNT(*)
    126123INTO v_existing_email
     
    132129END IF;
    133130
    134 -- create new member
    135131INSERT INTO member(
    136132    member_id,
     
    191187
    192188```
    193 -- take info from borrowing
     189
    194190SELECT due_date, copy_id, return_date
    195191INTO v_due_date, v_copy_id, v_return_date
     
    197193WHERE borrowing_id = p_borrowing_id;
    198194
    199 -- check for existing borrow
     195
    200196IF v_copy_id IS NULL THEN
    201197    RETURN 'Borrowing record not found';
    202198END IF;
    203199
    204 -- check if book is returned
    205200IF v_return_date IS NOT NULL THEN
    206201    RETURN 'Book already returned';
    207202END IF;
    208203
    209 -- Update return date
    210204UPDATE borrowing
    211205SET return_date = CURRENT_DATE
    212206WHERE borrowing_id = p_borrowing_id;
    213207
    214 -- bookstatus
     208
    215209SELECT status_id
    216210INTO v_status_id
     
    218212WHERE copy_id = v_copy_id;
    219213
    220 -- check for dameged book
     214
    221215IF v_status_id = 5 THEN
    222216    UPDATE bookcopy
     
    227221END IF;
    228222
    229 -- book is available
     223
    230224UPDATE bookcopy
    231225SET available = 1,
     
    233227WHERE copy_id = v_copy_id;
    234228
    235 -- check for late retun
     229
    236230IF v_due_date IS NOT NULL THEN
    237231    v_late_days := CURRENT_DATE - v_due_date;
     
    280274
    281275```
    282 -- free copy
     276
    283277SELECT copy_id
    284278INTO v_copy_id
     
    288282LIMIT 1;
    289283
    290 -- doesnt have-error
     284
    291285IF v_copy_id IS NULL THEN
    292286    RAISE EXCEPTION 'No available copy for this book!';
    293287END IF;
    294288
    295 -- borrowing row
     289
    296290INSERT INTO borrowing(
    297291    book_id,
     
    319313);
    320314
    321 -- not available
     315
    322316UPDATE bookcopy
    323317SET available = 0
     
    355349
    356350```
    357 -- check for free copy
     351
    358352SELECT copy_id
    359353INTO v_copy_id
     
    363357LIMIT 1;
    364358
    365 --if doesnt have copy, make reservation
     359
    366360IF v_copy_id IS NULL THEN
    367361
     
    478472
    479473```
    480 --if membership is expiredd
     474
    481475IF NEW.membership_end_date < CURRENT_DATE THEN
    482476    NEW.membership_status := 'EXPIRED';
    483477
    484 --if doesn't
     478
    485479ELSE
    486480    NEW.membership_status := 'ACTIVE';