2016-09-21 2 views
1

Firebird 1.5에서 3으로 전환하는 새로운 소프트웨어 버전을 준비 중입니다. 설치 프로그램은 1.5 데이터베이스를 백업하고 3 서버 또는 내장 서버를 통해 복원합니다. 설치 유형 (로컬/다중 사용자). 이 모든 것이 잘 작동합니다.Firebird 스트립 절차, 트러거보기 및 udf

새로운 파이어 버드 기능을 사용하여 모든 절차 트리거 및 뷰를 다시 만들고 1.5에서 사용한 UDF를 제거하려고합니다. 그러므로 나는 그 모든 것들을 지우려고했지만 내가 떨어질 수없는 문제를 발견했습니다. FB3에 존재하지 않는 UDF를 사용하는 뷰. Firebird 3에서 UDF를 사용할 수 없기 때문에 나는 막혔습니다.

이전 데이터베이스에서 해당 개체를 삭제해도이 대체 옵션을 제거하지 않을 수 없습니다. 또한 두 개의 백업/복원 라운드는 옵션이 아닙니다. 왜냐하면 우리가 아주 큰 데이터베이스에 대해 이야기하기 때문입니다.

고객 시스템에 액세스 할 수 없어 설치 프로그램에서 모든 작업을 수행해야합니다.

도움이 매우 감사합니다. 감사.

+0

당신이 (['작성 또는 변경 VIEW']를 사용 해봤 http://www.firebirdsql.org/file/documentation/reference_manuals/fblangref25-en /html/fblangref25-ddl-view.html#fblangref25-ddl-view-crtoralter)? 또는, 마이그레이션을 위해 Firebird 3에서 UDF를 사용할 수있게 할 수 있습니다. –

+0

해당 udfs를 사용하는보기에서 delete 또는 alter 명령이 잘못된 blr으로 실패합니다. 불행히도 위의 FBUD에서는 udfs를 사용할 수 없습니다. 나는 그들을 대체하고 싶지만 그들이 사용되기 때문에 아무 소용이 없습니다. – MichaSchumann

+0

필자도 Firebird 1.5와 함께 사용하는 기존 UDF를 사용할 수 있어야한다는 것을 알고 있습니다. –

답변

1

Mark 덕분에, 나는 한 번 더 시도했는데 결과적으로 "rdb $ database from test as 1 test to select"로 모든 뷰를 변경하고 삭제할 수있었습니다.

필자는 필드에 여러 가지 버전의 스키마가 있으므로 어떤 종속성이 있는지 정확히 알지 못합니다. 그래서이 PSQL Block을 작성하여 모든 객체가 오류를 무시하면서 모든 것이 정리 될 때까지 반복합니다. 따라서 이러한 객체 중 하나라도 삭제 가능하지 않으면 반복을 피하기 위해 100 회 실행 한 후에 반복을 중단합니다. 그런 다음 프로 시저, 뷰, 트리거 및 함수가 있는지 확인합니다. 그렇다면 예외를 유발합니다.

이것은 "더티"솔루션이라고 생각합니다. (예외는 대개 NoGo입니다.)하지만 더 좋은 아이디어는 없으며 무한 루프 나 감지되지 않은 오류가 발생할 수 있으므로이 방법을 사용합니다.

EXECUTE BLOCK 
as 
declare x integer; 
declare y integer; 
declare z integer; 
declare s varchar(100); 
declare s1 varchar(100); 
begin 
    x=1; 
    y=0; 
    while (x>0 and y<100) do 
    -- we break out of the loop if we have more than 100 rounds as this indicates 
    -- at least one object could not be deleted. 
     begin 
     y=y+1; 
     for SELECT distinct RDB$VIEW_NAME from RDB$VIEW_RELATIONS into :s do 
      begin 
      in autonomous transaction do 
      execute statement 'alter view ' || s || ' as select 1 as test from rdb$database'; 
      -- Ignore errors here for now 
      in autonomous transaction do 
      execute statement 'drop view ' || s; 
      -- Ignore errors here for now 
      when any do begin end 
      end 
     for SELECT RDB$PROCEDURE_NAME from RDB$PROCEDURES into :s do 
      begin 
      in autonomous transaction do 
      execute statement 'drop procedure ' || s; 
      -- Ignore errors here for now 
      when any do begin end 
      end 

     for select RDB$TRIGGER_NAME from RDB$TRIGGERS where RDB$SYSTEM_FLAG=0 into :s do 
      begin 
      in autonomous transaction do 
      execute statement 'drop trigger ' || s; 
      -- Ignore errors here for now 
      when any do begin end 
      end 
     for select RDB$FUNCTION_NAME from RDB$FUNCTIONS into :s do 
      begin 
      in autonomous transaction do 
      execute statement 'drop function ' || s; 
       -- Ignore errors here for now 
      when any do begin end 
      end 
     for select rdb$constraint_name,rdb$relation_name from RDB$RELATION_CONSTRAINTS where not rdb$relation_name containing ('$') into :s,:s1 do 
      begin 
      in autonomous transaction do 
      execute statement 'alter table ' || s1 || ' drop constraint ' || s; 
       -- Ignore errors here for now 
      when any do begin end 
      end 
     for select rdb$index_name from rdb$indices where rdb$system_flag=0 into :s do 
      begin 
      in autonomous transaction do 
      execute statement 'drop index ' || s; 
       -- Ignore errors here for now 
      when any do begin end 
      end 
     x = 0; 
     SELECT count(*) from RDB$PROCEDURES into :z; 
     x = x + z; 
     SELECT count(distinct RDB$VIEW_NAME) from RDB$VIEW_RELATIONS into :z; 
     x = x + z; 
     select count(*) from RDB$TRIGGERS where RDB$SYSTEM_FLAG=0 into :z; 
     x = x + z; 
     select count(*) from RDB$FUNCTIONS into :z; 
     x = x + z; 
     select count(*) from RDB$RELATION_CONSTRAINTS where not rdb$relation_name containing ('$') into :z; 
     x = x + z; 
     select count(*) from rdb$indices where rdb$system_flag=0 into :z; 
     x = x + z; 
    end 
    if (x>0) then 
      -- Raise an exception showing that the block failed 
      y=x/0; 
end 

업데이트 : 모든 제약 조건과 색인을 삭제하는 코드를 추가했습니다.

업데이트 2 : "null이 아닌"제약 조건은 도메인에서만 다시 작성할 수 있으므로 보존하는 것이 좋습니다. 그래서 그냥에 제약 select 문을 변경하려면 :

for select rdb$constraint_name,rdb$relation_name from RDB$RELATION_CONSTRAINTS 
      where rdb$constraint_type<>'NOT NULL' and not rdb$relation_name containing ('$') into :s,:s1 do