尝试使用pyodbc执行查询时出现“可选功能未实现”错误

时间:2014-02-21 13:04:43

标签: python sql database ms-access pyodbc

出于某种原因,我在尝试运行以下代码时遇到错误:

  

pyodbc.Error:('HYC00','[HYC00] [Microsoft] [ODBC Microsoft Access Driver]未实现的可选功能(106)(SQLBindParameter)')

我多次使用pyodbc并且以前从未遇到过这个问题。通过在params字符串中明确包含参数,我尝试了没有sql的查询,我遇到了同样的问题。我正在使用Python 3.3并连接到MS Access .mdb文件。

record = ('1AC401', 'CAB 1', 'OTSG 1 ROOM', 5, 8, 'CD14-PT-05', 'WFB FDWTR WARMING')

cabling_id = '1AC401/CAB 1/OTSG 1 ROOM'

sql = 'UPDATE [CIOC_DATA] SET [charm_enabled] = ?, ' \
      '[device_tag] = ?, ' \
      '[charm_description] = ?, ' \
      '[charm_cabling_id] = ?, ' \
      'WHERE [charm_baseplate] = ? ' \
      'AND [charm_Address] = ?'
params = ("T", record[5], record[6], cabling_id, record[3], record[4])
cursor.execute(sql, params)
cursor.commit()

更新 - 我添加了追溯:

Traceback (most recent call last):
  File "C:\Users\*****\Documents\Projects\******_******** *** Upgrade\NoEvernote\populateBulkEdit.py", line 48, in <module>
    cursor.execute(sql, params)
pyodbc.Error: ('HYC00', '[HYC00] [Microsoft][ODBC Microsoft Access Driver]Optional feature not implemented  (106) (SQLBindParameter)')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\******\Documents\Projects\******_******** *** Upgrade\NoEvernote\populateBulkEdit.py", line 52, in <module>
    + ': ' + e.args + '\n' )
TypeError: Can't convert 'tuple' object to str implicitly

更新2

TypeError与底层问题无关。我的错误处理代码是次要的错误。请注意上面代码摘录中的pyodbc.Error。

1 个答案:

答案 0 :(得分:1)

我猜你传递的这些参数中的一个是元组而不是字符串。也许是地址。