djhenderson / pypyodbc

Automatically exported from code.google.com/p/pypyodbc
0 stars 0 forks source link

check_status fails if driver doesn't provide details #42

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

It's a bit tricky - it depends on the driver you're using.
1. I've been using solidDB (IBM)
2. Connect to the DB with readonly=True (or do any activity for which the 
driver reports an error but doesn't return info)
3. Inner exception occurs (list index out of range)

What is the expected output? What do you see instead?

    Using the same parameters, pyodbc raise pyodbc.Error('HY000', 'The driver did not supply an error!')
    (I expect them act similarly, or at list report that there is no error supplied)

What version of the product are you using? On what operating system?

    pypyodbc-1.3.1 to connect to SolidDB with unixODBC

Please provide any additional information below.

I think that solidDB doesn't support readonly attribute. In pyodbc the 
SQLSetConnectAttr for readonly is only called when readonly=True, so it's not a 
problem. In pyodbc it's always called, which is why trying to connect to solid 
fails.

The state that SQLGetDiagRec returns in ctrl_err is 00000, and the message is 
empty. The return code is SQL_NO_DATA_FOUND, but since it's the first time it 
is called, it fails.

Traceback for the error:

pypyodbc.py in connect(self, connectString, autocommit, ansi, timeout, 
unicode_results, readonly)
   2480 
   2481         ret = ODBC_API.SQLSetConnectAttr(self.dbc_h, SQL_ATTR_ACCESS_MODE, self.readonly and SQL_MODE_READ_ONLY or SQL_MODE_READ_WRITE, SQL_IS_UINTEGER)
-> 2482         check_success(self, ret)
   2483 
   2484         self.unicode_results = unicode_results

pypyodbc.py in check_success(ODBC_obj, ret)
    986             ctrl_err(SQL_HANDLE_STMT, ODBC_obj.stmt_h, ret, ODBC_obj.ansi)
    987         elif isinstance(ODBC_obj, Connection):
--> 988             ctrl_err(SQL_HANDLE_DBC, ODBC_obj.dbc_h, ret, ODBC_obj.ansi)
    989         else:
    990             ctrl_err(SQL_HANDLE_ENV, ODBC_obj, ret, False)

pypyodbc.py in ctrl_err(ht, h, val_ret, ansi)
    948             #No more data, I can raise
    949             #print(err_list[0][1])
--> 950             state = err_list[0][0]
    951             err_text = raw_s('[')+state+raw_s('] ')+err_list[0][1]
    952             if state[:2] in (raw_s('24'),raw_s('25'),raw_s('42')):

IndexError: list index out of range

Original issue reported on code.google.com by tmr...@gmail.com on 28 Apr 2014 at 7:55

GoogleCodeExporter commented 9 years ago
Thanks for reporting. It now has been fixed in 1.3.3

Original comment by jiangwen...@gmail.com on 25 May 2014 at 8:29