[python-win32] adodbapi: paramstyle 'named' doesn't work as expected
Sibylle Koczian
nulla.epistola at web.de
Wed Feb 20 11:22:16 EST 2019
Hello,
I'm trying to write a small application to work with a Microsoft Access
database. This application will have to insert and update records, and
I'd like to use paramstyle='named'. With INSERT commands this seems to
work, with UPDATE I get an exception I can't explain.
Example: The database table called tblHaupt contains the fields id
(integer, primary key, autoincrement), item (varchar), ort (integer,
foreign key into another table). There are more fields, but the UPDATE
command I've been trying out only uses these three.
Code to try it:
########################################################################
import adodbapi
CONNFORM = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};"
DBLOKAL = r"X:\Path\to\database\db.accdb" # or db.mdb
UPCMD = "UPDATE tblHaupt SET item = :item, ort = :ort_id WHERE id = :h_id"
updata = {"item": "Testkeks D", "ort_id": 12, "h_id": 745}
connstr = CONNFORM.format(DBLOKAL)
conn = adodbapi.connect(connstr, paramstyle='named')
curs = conn.cursor()
curs.execute(UPCMD, updata)
Result:
Traceback (most recent call last):
Python Shell, prompt 62, line 1
# Used internally for debug sandbox under external interpreter
File "C:\Program
Files\Python37\Lib\site-packages\adodbapi\adodbapi.py", line 867, in execute
operation = self._reformat_operation(operation, parameters) # if
'named' will set self._parameter_names
File "C:\Program
Files\Python37\Lib\site-packages\adodbapi\adodbapi.py", line 751, in
_reformat_operation
operation, self._parameter_names =
api.changeNamedToQmark(operation) # convert :name to ?
File "C:\Program
Files\Python37\Lib\site-packages\adodbapi\apibase.py", line 598, in
changeNamedToQmark
c = chunk[i]
builtins.IndexError: string index out of range
##########################################################################
What's the matter here? INSERT into the same table works. The same
UPDATE command using paramstyle 'pyformat' works. Why not UPDATE with
'named'? Is something wrong with my parameter dictionary and I don't see it?
Python version is 3.7.2 (64bit), adodbapi.__version__ = 2.6.0.6, Windows
10 Home, Version 1809 (64bit).
Thank you for explanations,
Sibylle
More information about the python-win32
mailing list