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 raise UnicodeDecodeError if query and params in unicode #60

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Simple code (file exec_unicode_err.py)
conn = pymssql.connect(...)
curs = conn.cursor()
curs.execute(u'select %s, %s', (u'Здравствуй', u'Мир')) #Russian 
strings

2. Exec simple code
python callproc_err.py
Traceback (most recent call last):
  File "./exec_unicode_err.py", line 12, in <module>
    curs.execute(u'select %s, %s', [u'Здравствуй', u'Мир'])
  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 1610, in _mssql._substitute_params (_mssql.c:15792)
    toformat = toformat[:match_start] + param_val + toformat[match_end:]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 2: ordinal 
not in range(128)

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:15

Attachments:

GoogleCodeExporter commented 9 years ago
I attach path for correction: exec_unicode_err.diff

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

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the report.

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

GoogleCodeExporter commented 9 years ago
Hi tonal.promsoft,

Thank you very much for reporting the issue and submitting a patch!

This patch looks good to me and I've worked up a test for this issue to commit 
with your patch. I was wondering if you would like for me to mention your name 
and/or email in a comment acknowledging your work?

Original comment by msabr...@gmail.com on 7 Jan 2013 at 2:57

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I added the patch from tonal.promsoft and a test for the issue:

http://code.google.com/p/pymssql/source/detail?r=49210c03a6cf290fa353c73e264475f
fc3a89b44

tonal.promsoft, can you verify?

Original comment by msabr...@gmail.com on 9 Jan 2013 at 5:25