[DB-SIG] mx.ODBC.Windows - execute() parameter substitution raises Exception

M.-A. Lemburg mal@lemburg.com
Wed, 02 Oct 2002 12:18:41 +0200


Krjukov Victor wrote:
> Greetings, db-sig, I've faced with strange mx.odbc.windows execute()
> behaviour.
> 
> Can someone please explain me why the following code fails on 4th
> execute? May be I'm just missing something very simple...
> 
> I'm running
> 
> mx.ODBC.Windows 2.0.5
> Python 2.2.1c2 (#33, Mar 26 2002, 13:04:18) [MSC 32 bit (Intel)] on
> win32
> MS SQL server 2000
> Windows 2000
> 
> ====> test_sql.py
> import mx.ODBC.Windows
> 
> DB = mx.ODBC.Windows.Connect('db-companies')
> C = DB.cursor()
> 
> sql = """select newsid from news where newsid between 1 and 2"""
> C.execute(sql)
> print 'ok'
> 
> sql = """select newsid from news where newsid between ? and ?"""
> C.execute(sql, (1, 100))
> print 'ok'
> 
> sql = """select newsid from news where newsid in (select newsid from
> news
> where newsid between 1 and 100)"""
> C.execute(sql)
> print 'ok'
> 
> sql = """select newsid from news where newsid in (select newsid from
> news
> where newsid between ? and ?)"""
> C.execute(sql, (1, 100))
> print 'ok'
> <==== end of test_sql.py
> ====> result
> ok
> ok
> ok
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "c:/DOCUME~1/VKryukov/LOCALS~1/Temp/python-2320G8C", line 21, in
> ?
>     C.execute(sql, (1, 100))
> mxODBC.ProgrammingError: ('37000', 0, '[Microsoft][ODBC SQL Server
> Driver]Syntax error or access violation', 4469)
> <==== end of result

Could be a limitation of the MS SQL Server or its ODBC
driver. The SQL you are using looks strange though: why
would you want to nest identical SQL queries like the
one above ?

BTW, have you modified mxODBC in some way ? The line number
indicated in the error message doesn't map to a valid line
in the C code.

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
_______________________________________________________________________
eGenix.com -- Makers of the Python mx Extensions: mxDateTime,mxODBC,...
Python Consulting:                               http://www.egenix.com/
Python Software:                    http://www.egenix.com/files/python/