xcable / odbc

Automatically exported from code.google.com/p/odbc
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Error handling and api.SQL_NO_DATA #11

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
With a firebird database on windows 7 64bit (not mysql), I get an error in the 
"func (s *ODBCStmt) Exec(args []driver.Value)" if I execute an update or delete 
statement that did not affect any rows:

DELETE FROM myTable WHERE myCol = 'doesntExist';

This is because the function "IsError()" only checks for api.SQL_SUCCESS and 
api.SQL_SUCCESS_WITH_INFO). According to 

http://msdn.microsoft.com/de-de/library/windows/desktop/ms715424%28v=vs.85%29.as
px

the correct return value for the above statement is SQL_NO_DATA, so I think 
firebird is treating this properly.

Would it make sense to modify the function IsError()?

func IsError(ret api.SQLRETURN) bool {
 return !(ret == api.SQL_SUCCESS || ret == api.SQL_SUCCESS_WITH_INFO || ret == api.SQL_NO_DATA)
} 

Or in the Exec-function:

//...
ret := api.SQLExecute(s.h)
if IsError(ret) && ret != api.SQL_NO_DATA {
 return NewError("SQLExecute", s.h)
}

I don't know if this would have any side effects, but both fixes the issue for 
me. I know you don't have firebird installed, but maybe this is a general issue.

Michael

Original issue reported on code.google.com by michael....@googlemail.com on 5 Jul 2013 at 10:08

GoogleCodeExporter commented 9 years ago
Can you provide a small program to demonstrate, please? Also include that error 
message you saw. Thank you.

Alex

Original comment by alex.bra...@gmail.com on 7 Jul 2013 at 1:07

GoogleCodeExporter commented 9 years ago
I agree, it needs to be fixed. Here https://codereview.appspot.com/10988043/ is 
my fix. Please, review and let me know if it works for you. Thank you.

Alex

Original comment by alex.bra...@gmail.com on 8 Jul 2013 at 12:24

GoogleCodeExporter commented 9 years ago
Thanks for the answer! The fix looks good to me. Unfortunately I can't test it 
at the moment, because I'm not in my office this week (and therefore I don't 
have a windows machine). I will let you know if it works next Monday. Sorry for 
the delay.

Michael

Original comment by michael....@googlemail.com on 8 Jul 2013 at 7:42

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 73cbd9ce014c.

Original comment by alex.bra...@gmail.com on 9 Jul 2013 at 2:44

GoogleCodeExporter commented 9 years ago
Michael,

Thank you for review. I have submitted my change, because it fixes real bug for 
me too. Let me know if there is more to the story, but I consider the matter 
closed.

Alex

Original comment by alex.bra...@gmail.com on 9 Jul 2013 at 2:47

GoogleCodeExporter commented 9 years ago
Hi Alex,

I've tested your fix on my windows machine and it works as expected. Thanks for 
your work!

Michael

Original comment by michael....@googlemail.com on 15 Jul 2013 at 9:51