mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.92k stars 561 forks source link

"Invalid Parameter Type" when following "pyodbc objects/Row" section #1297

Closed gabrielleite751 closed 11 months ago

gabrielleite751 commented 11 months ago

Environment

Issue

When executing this insert command:

for index, row in tarefas.cronograma_df.iterrows():
    cursor.execute("INSERT INTO stage.SomeTableAPI (id,_id,Posicao,Item,Descricao,Porcentagem) values(?,?,?,?,?,?)"
                   ,row.id ,row._id ,row.posicao,row.item ,row.descricao ,row.porcentagem)

I received the following error message:
pyodbc.ProgrammingError: ('Invalid parameter type. param-index=3 param-type=method', 'HY105')
Apparently "item" is already a reserved method name for the object.

Even after reading the documentation and following the solution described therein, the problem persisted. I managed to get around the problem and I leave a suggestion below on how I resolved it.

Method present in the documentation:

row.__getattribute__('My Value')

What solved it:

row["My Value"]

But I'm wondering if there's an official way recommended by the library. Maybe adding a warning in the documentation would be good, in case you access columns with the same name as a reserved attribute.