djhenderson / pyodbc

Automatically exported from code.google.com/p/pyodbc
MIT No Attribution
0 stars 0 forks source link

Unable to insert pyodbc Rows #57

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

This example uses an SQLite3 memory databse, but I experience the same
issue with MS Access and MS SQL Server 2005:

import pyodbc

if __name__ == "__main__":
    con = pyodbc.connect(r'DRIVER=SQLite3 ODBC Driver;Database=:memory:')
    cur = con.cursor()
    cur.execute("create table t (name text, id integer)")

    params = [(u'A', 1), (u'B', 2)]
    print type(params), params

    cur.executemany("insert into t(name, id) values (?, ?)", params)
    rows = cur.execute("select * from t").fetchall()
    print type(rows), rows

    cur.executemany("insert into t(name, id) values (?, ?)", rows)

What is the expected output? What do you see instead?

I expect it to insert the data from the pyodbc Row, and give the following
output (actual output from pyodbc 2.1.3):

<type 'list'> [(u'A', 1), (u'B', 2)]
<type 'list'> [(u'A', 1), (u'B', 2)]
<type 'list'> [(u'A', 1), (u'B', 2), (u'A', 1), (u'B', 2)]

It instead produces this traceback:
Traceback (most recent call last):
  File "...\bug_maker.py", line 15, in <module>
    cur.executemany("insert into t(name, id) values (?, ?)", rows)
TypeError: ('Params must be in a list or tuple', 'HY000')

What version of the product are you using? On what operating system?

pydobc 2.1.6 with Python 2.6.2 official install on Windows XP Pro SP3 32-bit.

Please provide any additional information below.

This code works perfectly on pyodbc 2.1.3 prior to the patch for issue 45.

Original issue reported on code.google.com by isto...@gmail.com on 24 Jun 2009 at 1:42

GoogleCodeExporter commented 9 years ago
Thanks.  This is a fantastic idea, but had never designed it to work -- it just 
happened to.  I've fixed this in commit 
10ac782c60f8aa92c401963ca363d20f03de0a3e 
which will be in 2.1.7.  I've also added 2 SQL Server unit tests for this.

Original comment by mkleehammer on 8 Aug 2009 at 2:58

GoogleCodeExporter commented 9 years ago

Original comment by mkleehammer on 1 Jan 2010 at 6:36

GoogleCodeExporter commented 9 years ago

Original comment by mkleehammer on 21 Nov 2010 at 4:45