database trigger instead of auto-increment
Posted: Wed 04 Feb 2009 16:27
We going to use a trigger instead of auto-increment. How are the MyDAC-componments working with this trigger?
Discussion forums for open issues and questions concerning database tools, data access components and developer tools from Devart
https://forums.devart.com/
Code: Select all
CREATE
DEFINER = 'john'@'%'
TRIGGER test.trigger1
BEFORE INSERT
ON test.testtable
FOR EACH ROW
BEGIN
DECLARE volgnummer int;
SELECT MAX(ID)
FROM testtable
INTO volgnummer;
SET NEW.ID = volgnummer + 1;
ENDCode: Select all
log DBMonitor
-----------------
C:\Users\john\Documents\RAD Studio\Projects\triggertest\Project5.exe
05-02-2009 16:44:24 n/a MyDAC monitoring is started. Complete
05-02-2009 16:44:24 0:0.141 Connect: john@localhost Complete
05-02-2009 16:44:25 0:0.0 SQL Execute: select * from testtable
Complete
05-02-2009 16:44:44 0:0.31 SQL Execute: INSERT INTO testtable
(name, telephone)
VALUES
(?, ?)
:name(String[13],IN)='refreshrecord'
:telephone(String[7],IN)='3433444' Complete
05-02-2009 16:44:44 0:0.0 SQL Execute: select * from testtable
WHERE
testtable.ID IS NULL
Complete
I don't use SQLInsert, but I know when record will be posted, MyQuery creates internally SQL statements. Are these SQL's using SQLInsert? If it is, it should return a new value. As far as I know the trigger will be executed before the actual insert goes to the table.Syntax
property ReturnParams: boolean;
Remarks
Use the ReturnParams property to return the new value of the fields to dataset after insert or update. Actual value of field after insert or update may be different from the value stored in local memory if the table has a trigger. When ReturnParams is True, OUT parameters of SQLInsert and SQLUpdate statements is assigned to corresponding fields. The default value is False.