Bug #24648 DBD::mysql::st execute failed: No data to FETCH at
Submitted: 28 Nov 2006 9:50 Modified: 3 Dec 2006 9:30
Reporter: Konkov Eugen Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version: OS:
Assigned to: CPU Architecture:Any

[28 Nov 2006 9:50] Konkov Eugen
Description:
While updating a table with "AFTER UPDATE" trigger using last DBD::mysql Driver
I get DBD::mysql::st execute failed: No data to FETCH 

How to repeat:
Create a trigger to update data from another table

DELIMITER $$

DROP TRIGGER `akh_test_results`.`test_group_au`$$

create trigger `test_group_au` AFTER UPDATE on `akh_test_group` 
for each row BEGIN
declare ts_detail_ID INT;
select tsd.ID
into ts_detail_ID
from akh_test_suit ts
left join akh_test_suit_detail tsd on tsd.test_suit_ID = ts.ID
where ts.suit_status_ID = 14 and tsd.test_group_ID = NEW.ID;

update akh_test_suit_detail
set
 group_label= NEW.label
where ID= ts_detail_ID;

END;
$$

DELIMITER ;
[28 Nov 2006 11:09] Konkov Eugen
When we run 'SELECT INTO' statement from trigger and this statement return nothing. I get error 'NO DATA to FETCH'

HOW TO REPEAT:
1. Create a table
2. Add row to this table
3. Create a any trigger for this table
3.a Trigger must have 'SELECT INTO some_var ' statement which must return nothing.
 If 'Select INTO' statement return some data you don't get the error
 MySQL can't assign data to 'some_var' because of no data selected
4. UPDATE/INSERT data to you table to involve trigger
[29 Nov 2006 3:27] Valeriy Kravchuk
Why do you think it is a bug? Please, read the manual:

http://dev.mysql.com/doc/refman/5.0/en/select-into-statement.html
http://dev.mysql.com/doc/refman/5.0/en/declare-handlers.html

to get some ideas on how to fix your trigger's code.
[1 Dec 2006 10:45] Konkov Eugen
I am not imagine how to declare a such handle

I want only:
select somthint into someVar ....

if( rowsAffected>0 ) {
 update
 }

I have been surprised for a such error.
May be MySQL needs more informative error message that contains 
TRIGGER NAME, LINE where error occour
not only: 'No data to FETCH'
[3 Dec 2006 9:30] Valeriy Kravchuk
SELECT ... INTO ... should always return 1 row. Otherwise error is generated (and you have to process it).

As for the following:

> May be MySQL needs more informative error message that contains 
> TRIGGER NAME, LINE where error occour
> not only: 'No data to FETCH'

It looks like a reasonable feature request for me. Please, report it separately.