up vote 2 down vote favorite

I have a table in mysql like this

Name              Result  
T1_09_03_2010     fail  
T2_09_03_2010     pass  
T3_09_03_2010     pass  
T4_09_03_2010     fail  
T5_09_03_2010     fail  
T6_09_03_2010     pass  
T7_09_03_2010     fail

Well, T1_09_03_2010 is testcase name. If for some reason the developer wants to test the same testcase again in the same day, using the same name then, I need a way to update the already existing row based on the result. Say , for example T1_09_03_2010 has failed in this context and if this is run again and the result is pass, it should update the row, but if the result if fail, then it should leave the result as it is I mean ignore the new insert and carry on with others.

Thanks.

flag

73% accept rate

2 Answers

up vote 2 down vote accepted

here is an example syntax for mysql:

INSERT INTO users (username, email) VALUES ('Jo', '[email protected]')
ON DUPLICATE KEY UPDATE email = '[email protected]'
link|flag
up vote 0 down vote

You should use the INSERT... ON DUPLICATE KEY UPDATE .. syntax.

link|flag
Yes, I though of using thr on duplciate. But I want the condition only if the testcase fails and later passes. Will this be sufficient? – JPro Mar 9 at 15:13
Do you really want to not know if a test case fails a second time, even if it passed the first? – Chris Ridenour Mar 9 at 15:33
@Chris Ridenour : if the testcase is passed the first time, I want to leave the row as it is . But if it passes the second time then? – JPro Mar 9 at 16:14
and moreover Name is not a primary key nor unique – JPro Mar 9 at 16:18
From your comment, it sounds as if you want to Update the status form Fail to Pass but not from Pass to Fail. I'm just not sure why. You should be tracking the last case from all tests or recording the status of all cases (multiple rows with name, timestamp, status). Sorry if I'm not answering your specific MySQL question but I fear it is misguided as I don't understand the specific reasoning for this update logic. – Chris Ridenour Mar 10 at 5:24
show 1 more comment

Your Answer

get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.