Subject | Stored procedures trigger div by 0 exceptions only on the fetch |
---|---|
Author | mariuz |
Post date | 2012-12-18T09:59:30Z |
Problem:
If I run a stored procedure which produces an error *internally*, php does *not* report this error in ibase_errmsg, but simply returns an empty result set.
For example:
create procedure phptest(id integer)
returns (status varchar(100))
as
declare i integer;
begin
i = 1/0;
status = 'ok';
suspend;
end;
call this SP:
select status from phptest(1)
from any db admin tool like flamerobin etc, it will give:
arithmetic overflow or division by zero has occured ...
call the SP from php, nothing happens. You can even call
select status from phptest('xxx')
no problems with php, all other clients report
overflow ocurred during dara type conversion ...
Me:
So it returns error on the first fetch , if you only run the query the procedure
doesn't trigger the exception (it's only prepared)
And the test
https://gist.github.com/4326672
./sapi/cli/php test_sp_div0.php
Warning: ibase_fetch_object(): arithmetic exception, numeric overflow, or string truncation Integer divide by zero. The code attempted to divide an integer value by an integer divisor of zero. At procedure 'PHPTEST' line: 8, col: 3 in /home/mariuz/work/php-src/test_sp_div0.php on line 8
arithmetic exception, numeric overflow, or string truncation Integer divide by zero. The code attempted to divide an integer value by an integer divisor of zero. At procedure 'PHPTEST' line: 8, col: 3
ps if you eliminate the fetch there is no error
I wrote this so other should know about this stored procedure by design issue
If I run a stored procedure which produces an error *internally*, php does *not* report this error in ibase_errmsg, but simply returns an empty result set.
For example:
create procedure phptest(id integer)
returns (status varchar(100))
as
declare i integer;
begin
i = 1/0;
status = 'ok';
suspend;
end;
call this SP:
select status from phptest(1)
from any db admin tool like flamerobin etc, it will give:
arithmetic overflow or division by zero has occured ...
call the SP from php, nothing happens. You can even call
select status from phptest('xxx')
no problems with php, all other clients report
overflow ocurred during dara type conversion ...
Me:
So it returns error on the first fetch , if you only run the query the procedure
doesn't trigger the exception (it's only prepared)
And the test
https://gist.github.com/4326672
./sapi/cli/php test_sp_div0.php
Warning: ibase_fetch_object(): arithmetic exception, numeric overflow, or string truncation Integer divide by zero. The code attempted to divide an integer value by an integer divisor of zero. At procedure 'PHPTEST' line: 8, col: 3 in /home/mariuz/work/php-src/test_sp_div0.php on line 8
arithmetic exception, numeric overflow, or string truncation Integer divide by zero. The code attempted to divide an integer value by an integer divisor of zero. At procedure 'PHPTEST' line: 8, col: 3
ps if you eliminate the fetch there is no error
I wrote this so other should know about this stored procedure by design issue