google-code-export / pymssql

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

cursor.execute do not accept list params #59

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Simple code (file exec_list_err.py)
conn = pymssql.connect(...)
curs = conn.cursor()
curs.execute('select %d, %d', [1, 2])

2. Exec simple code
python callproc_err.py
Traceback (most recent call last):
  File "./exec_list_err.py", line 12, in <module>
    curs.execute('select %d, %d', [1, 2])
  File "pymssql.pyx", line 399, in pymssql.Cursor.execute (pymssql.c:4408)
    self._source._conn.execute_query(operation, params)
  File "_mssql.pyx", line 803, in _mssql.MSSQLConnection.execute_query (_mssql.c:8098)
    cpdef execute_query(self, query_string, params=None):
  File "_mssql.pyx", line 834, in _mssql.MSSQLConnection.execute_query (_mssql.c:7996)
    self.format_and_run_query(query_string, params)
  File "_mssql.pyx", line 965, in _mssql.MSSQLConnection.format_and_run_query (_mssql.c:9103)
    query_string = self.format_sql_command(query_string, params)
  File "_mssql.pyx", line 980, in _mssql.MSSQLConnection.format_sql_command (_mssql.c:9237)
    return _substitute_params(format, params, self._charset)
  File "_mssql.pyx", line 1549, in _mssql._substitute_params (_mssql.c:15154)
    raise ValueError("'params' arg can be only a tuple or a dictionary.")
ValueError: 'params' arg can be only a tuple or a dictionary.

My environment:
Os Kubuntu 11.04 with all latest updates
Python 2.7.1+ (2.7.1-0ubuntu5)
cython 0.13-1build1
gcc (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2
pymssql source from hg (hg summary: parent: 214:66579aff6824 tip)

Original issue reported on code.google.com by tonal.pr...@gmail.com on 28 Jun 2011 at 9:02

GoogleCodeExporter commented 9 years ago
I attach example script: exec_list_err.py
And path for correction: exec_list_err.diff

Original comment by tonal.pr...@gmail.com on 28 Jun 2011 at 9:05

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by rsyr...@gmail.com on 4 Oct 2011 at 4:59

GoogleCodeExporter commented 9 years ago
I'm looking at this and thinking that I don't really want to change anything.  
The reason is that what the user is expecting can become ambiguous.  For 
example:

curs.execute('select %d', [1, 2])

Should this be an error because there are not enough substitution params or 
should it become:

'select (1,2)'

Its easy enough to do this instead:

curs.execute('select %d, %d', *[1, 2])

and then nothing is ambiguous.  

Original comment by rsyr...@gmail.com on 3 Apr 2012 at 6:00