Commit 790cfc69 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Module Substitutions : suppression des notices inutiles (aucune clé remplacée)...

Module Substitutions : suppression des notices inutiles (aucune clé remplacée) dans la fonction pgsql substit_restore_foreign_key_value().
parent 0e501106
Loading
Loading
Loading
Loading
+38 −1
Changes for doc/release-notes/v7.1.0.md: 38 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -17,4 +17,41 @@

## 2. Dans la base de données

RAS.
```postgresql
create or replace function substit_restore_foreign_key_value(p_type varchar, p_tab_name varchar, p_col_name varchar, p_from_id bigint, p_to_id bigint) returns int
    language plpgsql
as
$$declare
    v_id record;
    v_count int = 0;
    v_message text;
    v_fkr substit_fk_replacement;
begin
    --
    -- Restauration de la valeur de la clé étrangère originale dans une table.
    --

    v_message = format('Restaurations FK %s.%s %s => %s :', upper(p_tab_name), p_col_name, p_to_id, p_from_id);

    for v_fkr in
        select * from substit_fk_replacement
                 where type = p_type and table_name = p_tab_name and column_name = p_col_name
                   and from_id = p_from_id and to_id = p_to_id
    loop
        for v_id in execute format('update %I set %I = %s where id = %s and %I = %s returning id',
            p_tab_name, p_col_name, p_from_id, v_fkr.record_id, p_col_name, p_to_id)
        loop
            v_count = v_count + 1;
            perform substit_insert_log(p_type, 'FK_RESTORE', p_from_id, p_to_id, null, v_message||' '||v_id);
        end loop;
    end loop;
    if v_count > 0 then
        delete from substit_fk_replacement
            where type = p_type and table_name = p_tab_name and column_name = p_col_name and from_id = p_from_id and to_id = p_to_id;
        raise notice '% % faites.', v_message, v_count;
    end if;

    return v_count;
end
$$;
```