2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
"""
|
|
|
|
ID: issue-4696
|
|
|
|
ISSUE: 4696
|
|
|
|
TITLE: Truncation error when using EXECUTE STATEMENT with a blob
|
|
|
|
DESCRIPTION:
|
|
|
|
JIRA: CORE-4374
|
2022-02-02 15:46:19 +01:00
|
|
|
FBTEST: bugs.core_4374
|
2022-01-23 20:41:55 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
import pytest
|
|
|
|
from firebird.qa import *
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
db = db_factory()
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
test_script = """
|
2021-04-26 20:07:00 +02:00
|
|
|
-- ::: NB :::
|
|
|
|
-- Memory consumption of procedural objects under 64-bit environment is much bigger than on 32-bit one.
|
|
|
|
-- This test was retyped because it was encountered that previous limit for the size of BLR is too weak:
|
|
|
|
-- test failed at runtime with error "implementation limit exceeds".
|
2021-10-21 19:29:23 +02:00
|
|
|
-- New (more rigorous) limit was found by using 64-bit FB, build LI-T3.0.0.31822: BLR can not be larger
|
2021-04-26 20:07:00 +02:00
|
|
|
-- than ~2.35 Mb (previous: ~3.21 Mb)
|
|
|
|
|
|
|
|
set list on;
|
|
|
|
set term ^;
|
|
|
|
execute block as
|
|
|
|
begin
|
|
|
|
execute statement 'drop procedure test_proc';
|
|
|
|
when any do begin end
|
|
|
|
end
|
|
|
|
^
|
|
|
|
commit
|
|
|
|
^
|
|
|
|
execute block as -- returns (proc_ddl_length int) as
|
|
|
|
declare sql blob sub_type text;
|
|
|
|
declare single_sttm varchar(10);
|
2021-10-21 19:29:23 +02:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
-- for 32 bit:
|
|
|
|
/***********************
|
|
|
|
declare sn int = 32760;
|
|
|
|
declare big_block_for_incr varchar(32760);
|
|
|
|
declare max_length_for_big_blocks int = 1048576;
|
|
|
|
declare small_incr_amount int = 2674; -- detected maximum for 3.0 Beta2 (WI-T3.0.0.31807)
|
|
|
|
***********************/
|
2021-10-21 19:29:23 +02:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
-- for 64 bit:
|
|
|
|
--/*
|
|
|
|
declare sn int = 8192;
|
|
|
|
declare big_block_for_incr varchar(8192);
|
|
|
|
declare max_length_for_big_blocks int = 794500;
|
|
|
|
declare small_incr_amount int = 19;
|
|
|
|
--*/
|
|
|
|
begin
|
|
|
|
sql = 'create or alter procedure test_proc returns(id integer) as '||ascii_char(10)||'begin ';
|
|
|
|
max_length_for_big_blocks = max_length_for_big_blocks - char_length(sql || 'end');
|
2021-10-21 19:29:23 +02:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
single_sttm = 'suspend;' || ascii_char(10);
|
|
|
|
big_block_for_incr = rpad('', trunc( sn / char_length(single_sttm) ) * char_length(single_sttm), single_sttm);
|
2021-10-21 19:29:23 +02:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
while (max_length_for_big_blocks > sn) do
|
|
|
|
begin
|
|
|
|
sql = sql || big_block_for_incr;
|
|
|
|
max_length_for_big_blocks = max_length_for_big_blocks - char_length(big_block_for_incr);
|
|
|
|
end
|
2021-10-21 19:29:23 +02:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
sql = sql || rpad('', small_incr_amount * char_length(single_sttm), single_sttm);
|
|
|
|
sql = sql ||'end';
|
2021-10-21 19:29:23 +02:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
--proc_ddl_length = octet_length(sql);
|
|
|
|
rdb$set_context('USER_SESSION', 'PROC_DDL_LENGTH', octet_length(sql));
|
|
|
|
--suspend;
|
2021-10-21 19:29:23 +02:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
execute statement :SQL;
|
2021-10-21 19:29:23 +02:00
|
|
|
|
|
|
|
end
|
2021-04-26 20:07:00 +02:00
|
|
|
^
|
|
|
|
set term ;^
|
|
|
|
commit;
|
2021-10-21 19:29:23 +02:00
|
|
|
|
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
set term ^;
|
|
|
|
execute block returns(returned_rows int, proc_ddl_length int, proc_src_length int, approx_blr_length int) as
|
|
|
|
begin
|
2021-10-21 19:29:23 +02:00
|
|
|
execute statement 'select count(*) cnt from test_proc'
|
2021-04-26 20:07:00 +02:00
|
|
|
into returned_rows;
|
2021-10-21 19:29:23 +02:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
proc_ddl_length = cast( rdb$get_context('USER_SESSION', 'PROC_DDL_LENGTH') as int);
|
2021-10-21 19:29:23 +02:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
select octet_length(rdb$procedure_source)
|
|
|
|
from rdb$procedures where rdb$procedure_name = upper('test_proc')
|
|
|
|
into proc_src_length;
|
2021-10-21 19:29:23 +02:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
select round(octet_length(rdb$procedure_blr), -3)
|
|
|
|
from rdb$procedures where rdb$procedure_name = upper('test_proc')
|
|
|
|
into approx_blr_length;
|
2021-10-21 19:29:23 +02:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
suspend;
|
2021-10-21 19:29:23 +02:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
end
|
|
|
|
^
|
|
|
|
set term ;^
|
|
|
|
commit;
|
|
|
|
|
2021-10-21 19:29:23 +02:00
|
|
|
/**************************************
|
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
32 bit, WI-T3.0.0.31824
|
|
|
|
RETURNED_ROWS 119154
|
|
|
|
PROC_DDL_LENGTH 1072455
|
|
|
|
PROC_SRC_LENGTH 1072395
|
|
|
|
APPROX_BLR_LENGTH 3217000
|
2021-10-21 19:29:23 +02:00
|
|
|
|
|
|
|
64 bit, LI-T3.0.0.31822
|
2021-04-26 20:07:00 +02:00
|
|
|
RETURNED_ROWS 87379
|
|
|
|
PROC_DDL_LENGTH 786480
|
|
|
|
PROC_SRC_LENGTH 786420
|
|
|
|
APPROX_BLR_LENGTH 2359000
|
2021-10-21 19:29:23 +02:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
**************************************/
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
act = isql_act('db', test_script)
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
expected_stdout = """
|
2021-04-26 20:07:00 +02:00
|
|
|
RETURNED_ROWS 87379
|
|
|
|
PROC_DDL_LENGTH 786480
|
|
|
|
PROC_SRC_LENGTH 786420
|
|
|
|
APPROX_BLR_LENGTH 2359000
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
|
|
|
@pytest.mark.version('>=3.0')
|
2022-01-23 20:41:55 +01:00
|
|
|
def test_1(act: Action):
|
|
|
|
act.expected_stdout = expected_stdout
|
|
|
|
act.execute()
|
|
|
|
assert act.clean_stdout == act.clean_expected_stdout
|
2021-04-26 20:07:00 +02:00
|
|
|
|