FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Trigger in MySQL
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Trigger in MySQL
Posted: Fri Aug 24, 2012 07:17 PM
Hi,

I use this trigger in SQLite

Code (fw): Select all Collapse
CREATE TRIGGER planning_update UPDATE ON planning BEGIN UPDATE refresh SET nr = nr + 1 where ID = 1;END;


but it doesn't work in MySQL. Does anyone know why?
'planning' and 'refresh' are tables in my SQL-database.

Thanks,Marc
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: Trigger in MySQL
Posted: Fri Aug 24, 2012 10:01 PM

Hello

is showing some error?

Posts: 581
Joined: Tue Oct 11, 2005 11:28 AM
Re: Trigger in MySQL
Posted: Sat Aug 25, 2012 12:15 AM
Marc Vanzegbroeck wrote:Hi,

I use this trigger in SQLite

Code (fw): Select all Collapse
CREATE TRIGGER planning_update UPDATE ON planning BEGIN UPDATE refresh SET nr = nr + 1 where ID = 1;END;


but it doesn't work in MySQL. Does anyone know why?
'planning' and 'refresh' are tables in my SQL-database.

Thanks,Marc


Marc,

Try this:

Code (fw): Select all Collapse
CREATE TRIGGER planning_update AFTER UPDATE ON planning
    FOR EACH ROW BEGIN
       UPDATE planning SET nr = nr + 1 where ID = 1;
    END;


I hope this helps.
Kleyber Derick



FWH / xHb / xDevStudio / SQLLIB
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: Trigger in MySQL
Posted: Sat Aug 25, 2012 03:46 AM
Kleyber,

Thank you for the info, but how do I have to do those 4 lines?

oSQL:query('CREATE TRIGGER planning_update AFTER UPDATE ON planning')
oSQL:query('FOR EACH ROW BEGIN')
oSQL:query('UPDATE refresh SET nr = nr + 1 where ID = 1;')
oSQL:query('END;')


doesn't seems to work.
Do I put these lines on 1 line?

Thanks,
Marc
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: Trigger in MySQL
Posted: Sat Aug 25, 2012 05:05 AM

Hello

do in 1 line... what class are you using to manager mysql?

in TDolphin is:
oServer:Execute( "CREATE TRIGGER planning_update AFTER UPDATE ON planning FOR EACH ROW BEGIN UPDATE planning SET nr = nr + 1 where ID = 1; END" )

in TMysql (from harbour ) maybe is
mysql_query( oServer:nSocket, "CREATE TRIGGER planning_update AFTER UPDATE ON planning FOR EACH ROW BEGIN UPDATE planning SET nr = nr + 1 where ID = 1; END" )

Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: Trigger in MySQL
Posted: Sat Aug 25, 2012 10:34 AM

Daniel,

Until I upgrade my FWH, i use TMySQL, because by version of FWH still use xHarbour 0.99.71 which is not compatible with TDolphin.

The function mysql_query() is not in the library.
I tested it with oSQL:Query( "CREATE TRIGGER planning_update AFTER UPDATE ON planning FOR EACH ROW BEGIN UPDATE refresh SET nr = nr + 1 where ID = 1; END;;" ) , and that is working fine!!

I have still now an other question. How can I know if the trigger exist? In SQLite al always executed this command, and if it exist, it doesn't do anything, MYSQL (MariaDB) give an error multiple triggers with the same action is not supported.
Regards,
Marc

Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 581
Joined: Tue Oct 11, 2005 11:28 AM
Re: Trigger in MySQL
Posted: Sat Aug 25, 2012 11:27 AM

Marc,

The way I remember now is using the SHOW TRIGGERS command and check the resulting array.

Kleyber Derick



FWH / xHb / xDevStudio / SQLLIB
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: Trigger in MySQL
Posted: Sat Aug 25, 2012 01:56 PM
Kleyber,

It's working fine with the SHOW TRIGGERS command.

Thanks,
Marc
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite

Continue the discussion