ODBC MYSQL UPDATE LOGGING

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
Post Reply
ericm
Posts: 40
Joined: Tue Feb 10, 2004 6:29 am

ODBC MYSQL UPDATE LOGGING

Post by ericm »

High all
I am using the folloiwing sql to update the results of my tests to a mysql db. I wish to only update if the test exist all ready. If it doesn't exist then insert. (As you will see in my statement.) Anyways it does not update if the test exist all ready. It is always inserting.

NSERT INTO metrics (testdate,folder,testname,alive) VALUES (NOW(), '%Folder%', '%TestName%', '%AliveRatio%') ON DUPLICATE KEY UPDATE testdate=NOW(), folder='%Folder%',testname='%testname%',alive='%AliveRatio%'
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Re: ODBC MYSQL UPDATE LOGGING

Post by KS-Soft Europe »

ericm wrote:It is always inserting.
Correct.
ericm wrote:NSERT INTO metrics (testdate,folder,testname,alive) VALUES (NOW(), '%Folder%', '%TestName%', '%AliveRatio%') ON DUPLICATE KEY UPDATE testdate=NOW(), folder='%Folder%',testname='%testname%',alive='%AliveRatio%'
"AliveRatio" is changed every time the test has been performed, so DUPLICATE KEY UPDATE wil not work in such case. Try to use following syntax:

Code: Select all

INSERT INTO metrics (testdate,folder,testname,alive) VALUES (NOW(), '%Folder%', '%TestName%', '%AliveRatio%') ON DUPLICATE KEY UPDATE  testdate=NOW(), folder='%Folder%',testname='%testname%'
It might help.

Regads,
Max
Post Reply