问题
To anyone that can help, thank you in advance.
I am running 64bit windows 10, 64bit office and 64bit python 3.7.2
Using pyodbc, I am trying to execute a Select statement such as this:
"SELECT * FROM EconVars WHERE Year(ValueDate) = 1999"
In order to do this, my code is as follows:
existquery = """SELECT * FROM EconVars WHERE Year(ValueDate) = ?"""
params = (1999,)
cursor.execute(existquery,params)
When I run this, I get the following error pyodbc.Error: ('HYC00', '[HYC00] [Microsoft][ODBC Microsoft Access Driver]Optional feature not implemented (106) (SQLBindParameter)')
I have read this might be because pyodbc has issues passing integer values, therefore I have attempted to convert to float, as this seemed to work for some people. Therefore, my code becomes:
existquery = """SELECT * FROM EconVars WHERE Year(ValueDate) = ?"""
params = (float(1999),)
cursor.execute(existquery,params)
When running this code, the program simply stops on the cursor.execute line with no error.
I have also tried using the pypyodbc
module instead and when running the exact same code above
existquery = """SELECT * FROM EconVars WHERE Year(ValueDate) = ?"""
params = [1999,]
cursor.execute(existquery,params)
I get the following error
OSError: exception: access violation reading 0x0000000000000000
I have confirmed that there is nothing wrong with the cursor connection because the same cursor successfully runs an INSERT command.
If anyone has any ideas they would be greatly appreciated.
Update 1
Thanks for responding, I have downgraded to 4.0.24 however the error still remains, the code below will still crash out with no error
existquery = """SELECT * FROM EconVars WHERE Year(ValueDate) = ?"""
params = (1999,)
cursor.execute(existquery,params)
existData = cursor.fetchall()
Also, passing a string, doesnt work either
existquery = """SELECT * FROM EconVars WHERE Year(ValueDate) = ?"""
params = ('1999',)
cursor.execute(existquery,params)
existData = cursor.fetchall()
I have, however got it working by passing a string date such as
existquery = """SELECT * FROM EconVars WHERE ValueDate = ?"""
params = ('#01/04/1999#',)
cursor.execute(existquery,params)
existData = cursor.fetchall()
However, clearly this doesnt help when looking for datapoints from a specific year. It also leads to UK / US date problems as the date above is actually interpreted as the 4th January.
回答1:
I was able to reproduce your issue. A change introduced in pyodbc 4.0.25 appears to cause problems with queries against an Access database when those queries use integer parameters.
The issue has been reported on GitHub here. In the meantime, downgrade to pyodbc 4.0.24.
Update
This issue was fixed in pyodbc 4.0.27.
来源:https://stackoverflow.com/questions/54220640/optional-feature-not-implemented-error-with-pyodbc-query-against-access-databa