Improve tests for LoadBlobFromFile

This commit is contained in:
Paul Reeves 2023-02-02 16:11:52 +01:00
parent cfcfa28082
commit 8aac65cc81
3 changed files with 35 additions and 9 deletions

View File

@ -21,4 +21,4 @@ insert into test_blobs( description, file_type, source_file ) values ('fb log',
insert into test_blobs( description, file_type, source_file ) values ('computer', 'bin', '/usr/share/icons/Adwaita/48x48/devices/computer.png'); insert into test_blobs( description, file_type, source_file ) values ('computer', 'bin', '/usr/share/icons/Adwaita/48x48/devices/computer.png');
insert into test_blobs( description, file_type, source_file ) values ('git gui icon', 'bin', '/usr/share/git-gui/lib/git-gui.ico'); insert into test_blobs( description, file_type, source_file ) values ('git gui icon', 'bin', '/usr/share/git-gui/lib/git-gui.ico');
commit;

View File

@ -12,3 +12,23 @@ select FLAGGED (190, 0) from rdb$database;
select FLAGGED (191, 0) from rdb$database; select FLAGGED (191, 0) from rdb$database;
commit; commit;
execute procedure load_blob(1);
execute procedure load_blob(2);
execute procedure load_blob(3);
execute procedure load_blob(4);
commit;
select cast ( description as varchar(32) ) as DESCRIPTION
, file_type
, cast (left(source_file,32) as varchar(32)) as source_file
, source_status
-- , source_bytes D_BIGINT
-- , target_file D_PATH
-- , target_status D_STATUS
-- , target_bytes D_BIGINT
-- , the_blob D_BLOB
from test_blobs;
commit;

View File

@ -30,6 +30,8 @@ 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')); 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'; comment on domain D_STATUS is 'unset, failed, loaded, written';
create exception E_BLOB_EXCEPTION '';
create table test_blobs( create table test_blobs(
test_blobs_id D_ID generated always as identity test_blobs_id D_ID generated always as identity
, description D_DESCRIPTION , description D_DESCRIPTION
@ -60,24 +62,28 @@ set term ^;
create or alter procedure load_blob ( a_test_blob_id D_ID ) sql security definer create or alter procedure load_blob ( a_test_blob_id D_ID ) sql security definer
as as
declare asource_file D_PATH; declare asource_file D_PATH;
declare ablob D_BLOB; declare oldblob D_BLOB;
declare newblob D_BLOB;
declare result D_BIGINT; declare result D_BIGINT;
declare status D_STATUS; declare status D_STATUS;
begin begin
select source_file, the_blob from test_blobs where test_blobs_id = :a_test_blob_id into asource_file, ablob; select source_file, the_blob from test_blobs where test_blobs_id = :a_test_blob_id into :asource_file, :oldblob;
select LoadBlobFromFile( :asource_file, :ablob ) from rdb$database into :result; select LoadBlobFromFile( :asource_file ) from rdb$database into :newblob;
if (result > 0 ) then
if ( newblob is not null ) then
status = 'L'; status = 'L';
else if ( result < 0 ) then else
status = 'F'; status = 'F';
update test_blobs update test_blobs
set the_blob = :ablob set the_blob = :newblob
, source_bytes = :result -- , source_bytes = :result
, source_status = :status , source_status = :status
where test_blobs_id = :a_test_blob_id; where test_blobs_id = :a_test_blob_id;
when any do begin
EXCEPTION E_BLOB_EXCEPTION 'Error updating test_blobs';
end