Changes between Version 11 and Version 12 of DatabaseProgramming


Ignore:
Timestamp:
05/23/26 22:07:30 (2 days ago)
Author:
231028
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DatabaseProgramming

    v11 v12  
    3131$$;
    3232}}}
    33 
     33{{{
     34create or replace procedure finish_shift(
     35    in driver_id int4
     36)
     37    language plpgsql as
     38$$
     39declare
     40    num_of_shifts int4;
     41begin
     42    if not exists(select user_id from driver where user_id = driver_id) then
     43        raise exception 'Driver with id % does not exist', driver_id;
     44    end if;
     45
     46    num_of_shifts := (select count(*) from driver_vehicle where id_driver = driver_id and time_to is null);
     47
     48    if (num_of_shifts != 1) then
     49        raise exception 'Driver has not started a shift';
     50    end if;
     51
     52    update driver_vehicle
     53    set time_to=now()
     54    where id_driver = driver_id
     55      and time_to is null;
     56    commit;
     57end;
     58$$;
     59}}}
    3460**Процедура за вработување на возач во компанија**
    3561
     
    401427
    402428{{{
    403 create or replace procedure public_schema.finish_shift(
    404     in driver_id int4
    405 )
    406     language plpgsql as
    407 $$
    408 declare
    409     num_of_shifts int4;
    410 begin
    411     if not exists(select user_id from driver where user_id = driver_id) then
    412         raise exception 'Driver with id % does not exist', driver_id;
    413     end if;
    414 
    415     num_of_shifts := (select count(*) from driver_vehicle where id_driver = driver_id and time_to is null);
    416 
    417     if (num_of_shifts != 1) then
    418         raise exception 'Driver has not started a shift';
    419     end if;
    420 
    421     update driver_vehicle
    422     set time_to=now()
    423     where id_driver = driver_id
    424       and time_to is null;
    425     commit;
    426 end;
    427 $$;
    428 }}}
    429 
    430 {{{
    431429create or replace procedure create_offer(
    432430    request_id int4,
     
    488486$$;
    489487}}}
    490 {{{
    491 create or replace procedure public_schema.finish_shift(
    492     in driver_id int4
    493 )
    494     language plpgsql as
    495 $$
    496 declare
    497     num_of_shifts int4;
    498 begin
    499     if not exists(select user_id from driver where user_id = driver_id) then
    500         raise exception 'Driver with id % does not exist', driver_id;
    501     end if;
    502 
    503     num_of_shifts := (select count(*) from driver_vehicle where id_driver = driver_id and time_to is null);
    504 
    505     if (num_of_shifts != 1) then
    506         raise exception 'Driver has not started a shift';
    507     end if;
    508 
    509     update driver_vehicle
    510     set time_to=now()
    511     where id_driver = driver_id
    512       and time_to is null;
    513     commit;
    514 end;
    515 $$;
    516 }}}
    517488== Функции и тригери
    518489