#coding:utf-8 """ ID: issue-5924 ISSUE: 5924 TITLE: Execute statement with excess parameters DESCRIPTION: JIRA: CORE-5658 FBTEST: bugs.core_5658 """ import pytest from firebird.qa import * db = db_factory() test_script = """ create or alter procedure sp_test as begin end; commit; recreate table test( id int generated by default as identity constraint pk_test primary key ,n int ,t timestamp ,b boolean ,s varchar(1) ); commit; insert into test(id, n ,t, b, s) values( 1, 11, '01.01.2019 01:01:01', false, 'q'); insert into test(id, n ,t, b, s) values( 2, 11, '01.01.2019 01:01:01', true, 'a'); insert into test(id, n ,t, b, s) values( 3, 22, '02.02.2019 03:03:03', true, 'z'); insert into test(id, n ,t, b, s) values( 4, 22, '04.04.2019 04:04:04', false, 'q'); insert into test(id, n ,t, b, s) values( 5, 22, '05.03.2019 05:05:05', null, 'q'); insert into test(id, n ,t, b, s) values( 6, 33, '03.03.2019 03:03:03', true, 'q'); insert into test(id, n ,t, b, s) values( 7, 33, '03.03.2019 03:03:03', true, 'q'); commit; set term ^; create or alter procedure sp_test( a_n int = null ,a_t timestamp = null ,a_b boolean = null ,a_s varchar(1) = null ,a_u varchar(9) = null ) returns( id int --,sttm varchar(255) ) as declare sttm varchar(255); begin sttm = 'select t.id from rdb$database r left join test t on'; if ( a_n is not null ) then sttm = sttm || ' t.n = :param_n and'; if ( a_t is not null ) then sttm = sttm || ' extract(month from t.t) = :param_t and'; if ( a_b is not null ) then sttm = sttm || ' t.b = :param_b and'; if ( a_s is not null ) then sttm = sttm || ' t.s = :param_s and'; sttm = sttm || ' 1=1'; --suspend; for execute statement ( sttm ) ( excess param_n := :a_n, excess param_t := extract(month from :a_t), excess param_b := :a_b, excess param_s := :a_s ) into id do suspend; end ^ set term ;^ commit; ------------------------------------------- --select * from sp_test; set list on; select 'case-1' as msg, p.* from sp_test(22) as p; select 'case-2' as msg, p.* from sp_test(22, timestamp '19.04.2011 11:12:13') as p; select 'case-3' as msg, p.* from sp_test(11, timestamp '11.01.2011 11:12:13', true) as p; select 'case-4' as msg, p.* from sp_test(null, timestamp '03.03.2003 03:13:23', null, 'q') as p; select 'case-5' as msg, p.* from sp_test(null, null, null, 'z') as p; """ act = isql_act('db', test_script) expected_stdout = """ MSG case-1 ID 3 MSG case-1 ID 4 MSG case-1 ID 5 MSG case-2 ID 4 MSG case-3 ID 2 MSG case-4 ID 5 MSG case-4 ID 6 MSG case-4 ID 7 MSG case-5 ID 3 """ @pytest.mark.version('>=4.0') def test_1(act: Action): act.expected_stdout = expected_stdout act.execute() assert act.clean_stdout == act.clean_expected_stdout