platiumky / pymssql

Automatically exported from code.google.com/p/pymssql
GNU Lesser General Public License v2.1
0 stars 0 forks source link

Execute many with zeros #85

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
 (The attached script will reproduce)
1. create a database with a primary key of an integer
2. generate a list of integers that are unordered with a zero in the list
3. executemany to insert the list does not work (inserting one by one will)

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

Inserting should work the same with execute and executemany

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

pymssql: 2.0.0, python 2.4, connecting to sql server 2008R2, on solaris 5.10

Please provide any additional information below.

Original issue reported on code.google.com by schwar...@gmail.com on 2 Mar 2012 at 5:38

Attachments:

GoogleCodeExporter commented 8 years ago
Can you give me the exception you are getting please.  Also, Python 2.4 is not 
officially supported.  I'm not saying that is the problem, just FYI.

Original comment by rsyr...@gmail.com on 2 Mar 2012 at 7:37

GoogleCodeExporter commented 8 years ago
Hi,

I get the following:

ProgrammingError: (102, "Incorrect syntax near 'd'.")
WARNING: Failure executing file:
</home/titan/schwartz/tmp/zerosinexecmany.py>

Original comment by schwar...@gmail.com on 2 Mar 2012 at 7:55

GoogleCodeExporter commented 8 years ago
Are you sure zeros are the problem?  Looking at your code, my guess is that you 
have a problem with the way you are passing parameters to executemany().  
'data' variable in your example should be a list of tuples, not a list of 
integers.  Also, the way you are using execute() is dangerous and can result in 
SQL injection problems.  Don't use python string interpolation, let pymssql 
substitute the params.

Original comment by rsyr...@gmail.com on 6 Mar 2012 at 2:56

GoogleCodeExporter commented 8 years ago
That story checks out ... when I changed my executemany from a list of
integers to a list of tuples the problem went away.  So I this can be
safely written off as 'user error' :)

On a side note: wouldn't it have been useful if when I originally passed in
my integer list if pymssql could have risen a ValueType error and pointed
out my mistake?  The way it is now, there's no indication I am misusing the
package unless I try inserting a 0.

Original comment by schwar...@gmail.com on 6 Mar 2012 at 7:29