I cannot get parametrized query working with pyodbc and 4D. Here an example of simple and basic code (working on mySQL database). The table B has two columns without any constraint.
import pyodbc
con2 = pyodbc.connect('dsn=odbc_source');
cur2 = con2.cursor();
KeyMap = {
1: ('Aaaahaa',datetime.date(1990,1,1)),
2: ('Bcdefgh',datetime.date(1990,2,1)),
3: ("Aaaah'aa",datetime.date(1990,3,1))
};
for k in KeyMap:
v = (k,KeyMap[k][0]);
cur2.execute("INSERT INTO B(Num,Text) VALUES(?,?);",v);
I always get this error message:
Traceback (most recent call last):
File "D:\jlandercy\src\python\cripi\transfert\000_TestInsertParam.py", line 33, in <module>
cur2.execute("INSERT INTO B(Num,Text) VALUES(?,?);",v);
pyodbc.ProgrammingError: ('The SQL contains 1 parameter markers, but 2 parameters were supplied', 'HY000')
Or, that the connection failed, but if I issue a SELECT
it works. What am I doing wrong.