Trigger in MySQL

Trigger in MySQL

Postby Marc Vanzegbroeck » Fri Aug 24, 2012 7:17 pm

Hi,

I use this trigger in SQLite

Code: Select all  Expand view
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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Trigger in MySQL

Postby Daniel Garcia-Gil » Fri Aug 24, 2012 10:01 pm

Hello

is showing some error?
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Trigger in MySQL

Postby Kleyber » Sat Aug 25, 2012 12:15 am

Marc Vanzegbroeck wrote:Hi,

I use this trigger in SQLite

Code: Select all  Expand view
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: Select all  Expand view

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
User avatar
Kleyber
 
Posts: 581
Joined: Tue Oct 11, 2005 11:28 am
Location: São Luiz, Brasil

Re: Trigger in MySQL

Postby Marc Vanzegbroeck » Sat Aug 25, 2012 3: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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Trigger in MySQL

Postby Daniel Garcia-Gil » Sat Aug 25, 2012 5: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" )
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Trigger in MySQL

Postby Marc Vanzegbroeck » 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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Trigger in MySQL

Postby Kleyber » 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
User avatar
Kleyber
 
Posts: 581
Joined: Tue Oct 11, 2005 11:28 am
Location: São Luiz, Brasil

Re: Trigger in MySQL

Postby Marc Vanzegbroeck » Sat Aug 25, 2012 1: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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 95 guests