2023-01-25 14:54:48 +01:00
|
|
|
/*
|
|
|
|
create tables for test db
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2023-01-26 20:48:31 +01:00
|
|
|
--create sequence test_div_seq;
|
2023-01-25 14:54:48 +01:00
|
|
|
commit;
|
|
|
|
create domain D_ID as BIGINT;
|
2023-01-25 15:58:16 +01:00
|
|
|
create domain D_BIGINT as BIGINT;
|
2023-01-25 14:54:48 +01:00
|
|
|
|
|
|
|
create table test_div(
|
2023-01-28 10:40:15 +01:00
|
|
|
test_div_id D_ID generated always as identity
|
2023-01-25 15:58:16 +01:00
|
|
|
, numerator D_BIGINT
|
|
|
|
, denominator D_BIGINT
|
2023-01-26 16:38:04 +01:00
|
|
|
, result COMPUTED BY ( DIV(numerator, denominator) )
|
2023-01-26 20:48:31 +01:00
|
|
|
, constraint pk_test_div_id primary key (test_div_id) using index idx_test_div_id
|
|
|
|
|
2023-01-26 16:38:04 +01:00
|
|
|
|
2023-01-25 14:54:48 +01:00
|
|
|
);
|
2023-01-25 15:58:16 +01:00
|
|
|
|
2023-01-26 16:38:04 +01:00
|
|
|
commit;
|
|
|
|
|
2023-01-25 15:58:16 +01:00
|
|
|
|
2023-01-26 20:48:31 +01:00
|
|
|
-- create sequence test_blobs_seq;
|
|
|
|
|
|
|
|
create domain D_BLOB as BLOB;
|
|
|
|
create domain D_DESCRIPTION varchar(255) default 'No description entered' not null ;
|
|
|
|
create domain D_FILETYPE char(3) default 'BIN' not null check (value in ( 'BIN', 'TXT') );
|
|
|
|
create domain D_PATH as varchar(8189) default '' not null ;
|
|
|
|
create domain D_STATUS as CHAR(1) default 'U' not null check (VALUE IN ('U', 'F', 'L', 'W'));
|
|
|
|
comment on domain D_STATUS is 'unset, failed, loaded, written';
|
|
|
|
|
|
|
|
create table test_blobs(
|
2023-01-28 10:40:15 +01:00
|
|
|
test_blobs_id D_ID generated always as identity
|
2023-01-26 20:48:31 +01:00
|
|
|
, description D_DESCRIPTION
|
|
|
|
, file_type D_FILETYPE
|
|
|
|
, source_file D_PATH
|
|
|
|
, source_status D_STATUS
|
2023-01-28 10:40:15 +01:00
|
|
|
, source_bytes D_BIGINT
|
2023-01-26 20:48:31 +01:00
|
|
|
, target_file D_PATH
|
|
|
|
, target_status D_STATUS
|
2023-01-28 10:40:15 +01:00
|
|
|
, target_bytes D_BIGINT
|
2023-01-26 20:48:31 +01:00
|
|
|
, the_blob D_BLOB
|
|
|
|
, constraint pk_test_blobs_id primary key (test_blobs_id) using index idx_test_blobs_id
|
|
|
|
);
|
|
|
|
|
|
|
|
set term ^;
|
2023-01-28 10:40:15 +01:00
|
|
|
create or alter trigger t_iub_test_blobs for test_blobs before insert or update
|
2023-01-26 20:48:31 +01:00
|
|
|
as begin
|
|
|
|
|
|
|
|
new.file_type = upper(new.file_type);
|
|
|
|
new.source_status = upper(new.source_status);
|
|
|
|
new.target_status = upper(new.target_status);
|
|
|
|
|
|
|
|
end ^
|
2023-01-28 10:40:15 +01:00
|
|
|
set term ;^
|
|
|
|
|
|
|
|
|
|
|
|
set term ^;
|
|
|
|
create or alter procedure load_blob ( a_test_blob_id D_ID ) sql security definer
|
|
|
|
as
|
|
|
|
declare asource_file D_PATH;
|
|
|
|
declare ablob D_BLOB;
|
|
|
|
declare result D_BIGINT;
|
|
|
|
declare status D_STATUS;
|
|
|
|
begin
|
|
|
|
|
|
|
|
select source_file, the_blob from test_blobs where test_blobs_id = :a_test_blob_id into asource_file, ablob;
|
|
|
|
select LoadBlobFromFile( :asource_file, :ablob ) from rdb$database into :result;
|
|
|
|
if (result > 0 ) then
|
|
|
|
status = 'L';
|
|
|
|
else if ( result < 0 ) then
|
|
|
|
status = 'F';
|
2023-01-26 20:48:31 +01:00
|
|
|
|
|
|
|
|
2023-01-28 10:40:15 +01:00
|
|
|
update test_blobs
|
|
|
|
set the_blob = :ablob
|
|
|
|
, source_bytes = :result
|
|
|
|
, source_status = :status
|
|
|
|
where test_blobs_id = :a_test_blob_id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end ^
|
2023-01-26 20:48:31 +01:00
|
|
|
|
|
|
|
set term ;^
|
|
|
|
|
|
|
|
|