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
당신이 (['작성 또는 변경 VIEW']를 사용 해봤 http://www.firebirdsql.org/file/documentation/reference_manuals/fblangref25-en /html/fblangref25-ddl-view.html#fblangref25-ddl-view-crtoralter)? 또는, 마이그레이션을 위해 Firebird 3에서 UDF를 사용할 수있게 할 수 있습니다. –
해당 udfs를 사용하는보기에서 delete 또는 alter 명령이 잘못된 blr으로 실패합니다. 불행히도 위의 FBUD에서는 udfs를 사용할 수 없습니다. 나는 그들을 대체하고 싶지만 그들이 사용되기 때문에 아무 소용이 없습니다. – MichaSchumann
필자도 Firebird 1.5와 함께 사용하는 기존 UDF를 사용할 수 있어야한다는 것을 알고 있습니다. –