Bug #25307 Trigger Throw Exception
Submitted: 28 Dec 2006 10:04 Modified: 28 Jan 2007 12:45
Reporter: Aftab Khan Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S3 (Non-critical)
Version:5.1.2 OS:Windows (windows)
Assigned to: CPU Architecture:Any

[28 Dec 2006 10:04] Aftab Khan
Description:
The trigger throw exception; when I do not add DML statement in the begining like  " update dumy set x=temp"; kindly see the following trigger, it should work with out any false DML statment. 

CREATE TRIGGER ProcessCDR2 before INSERT ON nextone2
FOR EACH ROW
BEGIN

DECLARE destination VARCHAR(200) DEFAULT \"\";
DECLARE id BIGINT DEFAULT 0;
DECLARE vname VARCHAR(200) ;
DECLARE temp VARCHAR(200) DEFAULT IF (NEW.CallDestRegid=\"\",'n/a',NEW.CallDestRegid);
 
 update dumy set x=temp ;
 
SELECT v1.vendorid,v1.name, ve.DestinationID INTO id, vname, destination
FROM (select name, v.VendorID, EndPoint  from vendor v natural join vendorendpoints ) v1 
RIGHT JOIN 
(
SELECT IF(`CountryCode`=`OperatorList`,length(`Prefix`),length(`Prefix`)+length(`OperatorList`)) as length,`DestinationID`,`VendorID`,`Prefix`,`OperatorList`,`CountryCode`
from vendorextraction order by length desc) 
ve 
ON (v1.VendorID=ve.VendorID)
WHERE
substr(NEW.CalledStationId , 1 ,ve.length)=substr(CONCAT(ve.Prefix,ve.OperatorList),1,ve.length) 
AND
v1.EndPoint=temp
LIMIT  1; 

IF (id IS NOT NULL AND id >0 OR destination <> \"\") then
insert into ncdr2 (`VendorID`, `name` ,`destination`, `ip`, `duration`,`errortype`,`Called-Party`,`DATE`,`EndPoint`) values( id, vname, destination, NEW.NASIPAddress, NEW.SessionTime, NEW.DisconnectErrorType,  NEW.CalledStationId, NEW.CreationDate, temp );
ELSE
insert into unknown2  (`VendorID`, `name` ,`destination`, `ip`, `duration`,`errortype`,`Called-Party`,`DATE`,`EndPoint`) values( id, vname, destination, NEW.NASIPAddress, NEW.SessionTime, NEW.DisconnectErrorType,  NEW.CalledStationId, NEW.CreationDate, temp );
END IF;

END

How to repeat:
CREATE TRIGGER ProcessCDR2 before INSERT ON nextone2
FOR EACH ROW
BEGIN

DECLARE destination VARCHAR(200) DEFAULT \"\";
DECLARE id BIGINT DEFAULT 0;
DECLARE vname VARCHAR(200) ;
DECLARE temp VARCHAR(200) DEFAULT IF (NEW.CallDestRegid=\"\",'n/a',NEW.CallDestRegid);
 
 update dumy set x=temp ;
 
SELECT v1.vendorid,v1.name, ve.DestinationID INTO id, vname, destination
FROM (select name, v.VendorID, EndPoint  from vendor v natural join vendorendpoints ) v1 
RIGHT JOIN 
(
SELECT IF(`CountryCode`=`OperatorList`,length(`Prefix`),length(`Prefix`)+length(`OperatorList`)) as length,`DestinationID`,`VendorID`,`Prefix`,`OperatorList`,`CountryCode`
from vendorextraction order by length desc) 
ve 
ON (v1.VendorID=ve.VendorID)
WHERE
substr(NEW.CalledStationId , 1 ,ve.length)=substr(CONCAT(ve.Prefix,ve.OperatorList),1,ve.length) 
AND
v1.EndPoint=temp
LIMIT  1; 

IF (id IS NOT NULL AND id >0 OR destination <> \"\") then
insert into ncdr2 (`VendorID`, `name` ,`destination`, `ip`, `duration`,`errortype`,`Called-Party`,`DATE`,`EndPoint`) values( id, vname, destination, NEW.NASIPAddress, NEW.SessionTime, NEW.DisconnectErrorType,  NEW.CalledStationId, NEW.CreationDate, temp );
ELSE
insert into unknown2  (`VendorID`, `name` ,`destination`, `ip`, `duration`,`errortype`,`Called-Party`,`DATE`,`EndPoint`) values( id, vname, destination, NEW.NASIPAddress, NEW.SessionTime, NEW.DisconnectErrorType,  NEW.CalledStationId, NEW.CreationDate, temp );
END IF;

END
[28 Dec 2006 12:45] Valeriy Kravchuk
Thasnk you for a problem report. Please, try to repeat with a newer version, 5.1.14, and, in case of same problem, send the results of SHOW CREATE TABLE for that nextone2 table, and all other statements to repeat the problem described. We need a complete, repeatable test case.
[29 Jan 2007 0:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".