Discussion:
0.5.3 ORM, MSSQL and FreeTDS: Invalid Cursor State exception?
Tom Wood
2009-04-27 15:01:43 UTC
Permalink
Hi all,

Am having a problem with SQLAlchemy 0.5.3 and MSSQL. Running on a
Debian stack, using FreeTDS 0.82, pyodbc 2.1.4, Python 2.5 and
(separately) SQL Server 2000 and SQL Server 2005.

The (nose) test below fails with the exception:

ProgrammingError: (ProgrammingError) ('24000', '[24000] [FreeTDS][SQL
Server]Invalid cursor state (0) (SQLExecDirectW)') 'INSERT INTO
activities (institution, application_id) VALUES (?, ?); select
scope_identity()' ['UMass', 1]

Complete stack can be found below.

I'd love to hear from anyone running under a comparable configuration--
whether you see the same results or not! :-)

FYI: The test succeeds using SQLAlchemy 0.5.0rc3, but fails with every
subsequent release. It also passes running against a sqllite db.

Thanks very much.

Tom Wood
University of Connecticut

# begin test code

import sqlalchemy as sa
from sqlalchemy import orm
conn = 'mssql://<insert your string here>'
engine = sa.create_engine(conn)
metadata = sa.MetaData(bind=engine)
applications_table = sa.Table('applications', metadata,
sa.Column('id', sa.Integer,
primary_key=True),
sa.Column('last_name', sa.types.String
(20)))
activities_table = sa.Table('activities', metadata,
sa.Column('id', sa.Integer,
primary_key=True),
sa.Column('institution', sa.types.String
(20)),
sa.Column('application_id', sa.Integer,
sa.ForeignKey('applications.id')))
Session = orm.sessionmaker()

class Application(object):
def __init__(self, last_name):
self.last_name = last_name

class Activity(object):
def __init__(self, institution):
self.institution = institution

orm.mapper(Application, applications_table, properties={'activities':
orm.relation(Activity, backref='application')})
orm.mapper(Activity, activities_table)

class Tester(object):
def setup(self):
metadata.create_all()
self.session = Session()

def teardown(self):
self.session.close()
metadata.drop_all()

def test_orm_relation(self):
app = Application(last_name='Wood')
act = Activity(institution='UConn')
act2 = Activity(institution='UMass')
app.activities.append(act)
app.activities.append(act2)

self.session.add(app)

self.session.commit()

assert act.id is not None
assert app.id is not None
assert act2.id is not None

assert act.application_id == app.id
assert act2.application_id == app.id

# begin stack crawl

ERROR: simple_test.Tester.test_orm_relation
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
nose-0.10.4-py2.5.egg/nose/case.py", line 182, in runTest
self.test(*self.arg)
File "/home/XXX/unicode_tests/simple_test.py", line 45, in
test_orm_relation
self.session.commit()
File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/orm/session.py", line 673, in
commit
self.transaction.commit()
File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/orm/session.py", line 378, in
commit
self._prepare_impl()
File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/orm/session.py", line 362, in
_prepare_impl
self.session.flush()
File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/orm/session.py", line 1351, in
flush
self._flush(objects)
File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/orm/session.py", line 1422, in
_flush
flush_context.execute()
File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/orm/unitofwork.py", line 244, in
execute
UOWExecutor().execute(self, tasks)
File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/orm/unitofwork.py", line 707, in
execute
self.execute_save_steps(trans, task)
File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/orm/unitofwork.py", line 722, in
execute_save_steps
self.save_objects(trans, task)
File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/orm/unitofwork.py", line 713, in
save_objects
task.mapper._save_obj(task.polymorphic_tosave_objects, trans)
File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/orm/mapper.py", line 1347, in
_save_obj
c = connection.execute(statement.values(value_params), params)
File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/engine/base.py", line 824, in
execute
return Connection.executors[c](self, object, multiparams, params)
File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/engine/base.py", line 874, in
_execute_clauseelement
return self.__execute_context(context)
File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/engine/base.py", line 896, in
__execute_context
self._cursor_execute(context.cursor, context.statement,
context.parameters[0], context=context)
File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/engine/base.py", line 950, in
_cursor_execute
self._handle_dbapi_exception(e, statement, parameters, cursor,
context)
File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/engine/base.py", line 931, in
_handle_dbapi_exception
raise exc.DBAPIError.instance(statement, parameters, e,
connection_invalidated=is_disconnect)
ProgrammingError: (ProgrammingError) ('24000', '[24000] [FreeTDS][SQL
Server]Invalid cursor state (0) (SQLExecDirectW)') 'INSERT INTO
activities (institution, application_id) VALUES (?, ?); select
scope_identity()' ['UMass', 1]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to sqlalchemy+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---
Lukasz Szybalski
2009-04-27 16:18:57 UTC
Permalink
Post by Tom Wood
Hi all,
Am having a problem with SQLAlchemy 0.5.3 and MSSQL.  Running on a
Debian stack, using FreeTDS 0.82, pyodbc 2.1.4, Python 2.5 and
(separately) SQL Server 2000 and SQL Server 2005.
ProgrammingError: (ProgrammingError) ('24000', '[24000] [FreeTDS][SQL
Server]Invalid cursor state (0) (SQLExecDirectW)') 'INSERT INTO
activities (institution, application_id) VALUES (?, ?); select
scope_identity()' ['UMass', 1]
Complete stack can be found below.
I'd love to hear from anyone running under a comparable configuration--
whether you see the same results or not! :-)
FYI: The test succeeds using SQLAlchemy 0.5.0rc3, but fails with every
subsequent release.  It also passes running against a sqllite db.
Thanks very much.
Tom Wood
University of Connecticut
# begin test code
import sqlalchemy as sa
from sqlalchemy import orm
conn = 'mssql://<insert your string here>'
engine = sa.create_engine(conn)
I'm not sure if I can help but if we could start with the basics and
find out what version of tds are you using and how are you connecting?

1. Are you using dsn-less or dsn connection string? @dsn ?
2. What tds version have you set in /etc/freetds/tds.dsn.template
http://lucasmanual.com/mywiki/unixODBC

Have you tried setting it to tds version 8.0?

Thanks,
Lucas
Post by Tom Wood
metadata = sa.MetaData(bind=engine)
applications_table = sa.Table('applications', metadata,
                             sa.Column('id', sa.Integer,
primary_key=True),
                             sa.Column('last_name', sa.types.String
(20)))
activities_table = sa.Table('activities', metadata,
                           sa.Column('id', sa.Integer,
primary_key=True),
                           sa.Column('institution', sa.types.String
(20)),
                           sa.Column('application_id', sa.Integer,
sa.ForeignKey('applications.id')))
Session = orm.sessionmaker()
       self.last_name = last_name
       self.institution = institution
orm.relation(Activity, backref='application')})
orm.mapper(Activity, activities_table)
       metadata.create_all()
       self.session = Session()
       self.session.close()
       metadata.drop_all()
       app = Application(last_name='Wood')
       act = Activity(institution='UConn')
       act2 = Activity(institution='UMass')
       app.activities.append(act)
       app.activities.append(act2)
       self.session.add(app)
       self.session.commit()
       assert act.id is not None
       assert app.id is not None
       assert act2.id is not None
       assert act.application_id == app.id
       assert act2.application_id == app.id
# begin stack crawl
ERROR: simple_test.Tester.test_orm_relation
----------------------------------------------------------------------
 File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
nose-0.10.4-py2.5.egg/nose/case.py", line 182, in runTest
   self.test(*self.arg)
 File "/home/XXX/unicode_tests/simple_test.py", line 45, in
test_orm_relation
   self.session.commit()
 File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/orm/session.py", line 673, in
commit
   self.transaction.commit()
 File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/orm/session.py", line 378, in
commit
   self._prepare_impl()
 File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/orm/session.py", line 362, in
_prepare_impl
   self.session.flush()
 File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/orm/session.py", line 1351, in
flush
   self._flush(objects)
 File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/orm/session.py", line 1422, in
_flush
   flush_context.execute()
 File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/orm/unitofwork.py", line 244, in
execute
   UOWExecutor().execute(self, tasks)
 File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/orm/unitofwork.py", line 707, in
execute
   self.execute_save_steps(trans, task)
 File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/orm/unitofwork.py", line 722, in
execute_save_steps
   self.save_objects(trans, task)
 File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/orm/unitofwork.py", line 713, in
save_objects
   task.mapper._save_obj(task.polymorphic_tosave_objects, trans)
 File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/orm/mapper.py", line 1347, in
_save_obj
   c = connection.execute(statement.values(value_params), params)
 File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/engine/base.py", line 824, in
execute
   return Connection.executors[c](self, object, multiparams, params)
 File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/engine/base.py", line 874, in
_execute_clauseelement
   return self.__execute_context(context)
 File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/engine/base.py", line 896, in
__execute_context
   self._cursor_execute(context.cursor, context.statement,
context.parameters[0], context=context)
 File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/engine/base.py", line 950, in
_cursor_execute
   self._handle_dbapi_exception(e, statement, parameters, cursor,
context)
 File "/home/XXX/virtual_envs/py25-pylons/lib/python2.5/site-packages/
SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/engine/base.py", line 931, in
_handle_dbapi_exception
   raise exc.DBAPIError.instance(statement, parameters, e,
connection_invalidated=is_disconnect)
ProgrammingError: (ProgrammingError) ('24000', '[24000] [FreeTDS][SQL
Server]Invalid cursor state (0) (SQLExecDirectW)') 'INSERT INTO
activities (institution, application_id) VALUES (?, ?); select
scope_identity()' ['UMass', 1]
--
How to create python package?
http://lucasmanual.com/mywiki/PythonPaste
DataHub - create a package that gets, parses, loads, visualizes data
http://lucasmanual.com/mywiki/DataHub

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to sqlalchemy+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---
Tom Wood
2009-04-27 17:33:41 UTC
Permalink
Lucas,

Thanks for taking a peek at this!

My connection string looks like: 'mssql://user:***@server/db?
driver=FreeTDS_82&Servername=MyServer'

where FreeTDS_82 is defined in my odbcinst.ini, and MyServer is
defined in my freetds.conf.

I've tried 'tds version = 8.0' and 'tds version = 7.0' in my
freetds.conf, but still see the same behavior. I'm fairly certain
both config files are being read correctly.

Using FreeTDS 0.82, I see the exception as reported. Using FreeTDS
0.63, I see a slightly different exception:

raise exc.DBAPIError.instance(statement, parameters, e,
connection_invalidated=is_disconnect)
DBAPIError: (Error) ('HY000', 'The driver did not supply an
error!') 'INSERT INTO activities (institution, application_id) VALUES
(?, ?); select scope_identity()' ['UMass', 1]

and the FreeTDS log includes:

17:28:26.864001 tds_submit_query(): state is PENDING
17:28:26.864015 tds_client_msg: #20019: "Attempt to initiate a new
SQL Server operation with results pending.". Connection state is now
1.

which suggests to me the same problem, just being caught in a
different place.

I should also mention that simpler tests (e.g., using the ORM to save
an object with no relations) do succeed.

-Tom
Post by Lukasz Szybalski
Post by Tom Wood
Hi all,
Am having a problem with SQLAlchemy 0.5.3 and MSSQL.  Running on a
Debian stack, using FreeTDS 0.82, pyodbc 2.1.4, Python 2.5 and
(separately) SQL Server 2000 and SQL Server 2005.
ProgrammingError: (ProgrammingError) ('24000', '[24000] [FreeTDS][SQL
Server]Invalid cursor state (0) (SQLExecDirectW)') 'INSERT INTO
activities (institution, application_id) VALUES (?, ?); select
scope_identity()' ['UMass', 1]
Complete stack can be found below.
I'd love to hear from anyone running under a comparable configuration--
whether you see the same results or not! :-)
FYI: The test succeeds using SQLAlchemy 0.5.0rc3, but fails with every
subsequent release.  It also passes running against a sqllite db.
Thanks very much.
Tom Wood
University of Connecticut
# begin test code
import sqlalchemy as sa
from sqlalchemy import orm
conn = 'mssql://<insert your string here>'
engine = sa.create_engine(conn)
I'm not sure if I can help but if we could start with the basics and
find out what version of tds are you using and how are you connecting?
2. What tds version have you set in /etc/freetds/tds.dsn.templatehttp://lucasmanual.com/mywiki/unixODBC
Have you tried setting it to tds version 8.0?
Thanks,
Lucas
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to sqlalchemy+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---
Tom Wood
2009-04-29 14:08:04 UTC
Permalink
Some additional info, and a possible fix:

I can reproduce this problem running the SQLAlchemy dialect unit
tests. Using a trunk (r5930) checkout, FreeTDS 0.82 with tds protocol
version 8.0, pyodbc 2.1.4, Python 2.5 and SQL Server 2005, I see three
test failures in dialect.mssql:

test_binary fails with:

DataError: (DataError) ('22018', '[22018] [FreeTDS][SQL Server]
Implicit conversion from data type varchar to varbinary is not
allowed. Use the CONVERT function to run this query. (257)
(SQLPrepare)') 'INSERT INTO binary_table (primary_id, data,
data_image, data_slice, misc, pickled, mypickle) VALUES
(?, ?, ?, ?, ?, ?, ?)' [1, <read-only buffer for 0x842e680, size -1,
offset 0 at 0xb75c8f80>, <read-only buffer for 0x842e680, size -1,
offset 0 at 0xb75c8f60>, <read-only buffer for 0xb75e9c20, size -1,
offset 0 at 0xb75d00a0>, 'binary_data_one.dat', <read-only buffer for
0xb75c67a0, size -1, offset 0 at 0xb75d0180>, <read-only buffer for
0xb75d9d68, size -1, offset 0 at 0xb75d0100>]

I'm going to ignore this for now, since it seems to be unrelated to my
problem.

However, test_fetchid_trigger and test_slice_mssql both fail with the
Invalid cursor state exception:

File "/home/taw00008/src/sqlalchemy-trunk/lib/sqlalchemy/engine/
base.py", line 931, in _handle_dbapi_exception
raise exc.DBAPIError.instance(statement, parameters, e,
connection_invalidated=is_disconnect)
ProgrammingError: (ProgrammingError) ('24000', '[24000] [FreeTDS][SQL
Server]Invalid cursor state (0) (SQLExecDirectW)') 'INSERT INTO foo
(bar, range) VALUES (?, ?); select scope_identity()' [1, 1]

Here's a possible fix. The following patch to mssql.py corrects my
problems, as well as the test_fetchid_trigger and test_slice_mssql
failures:

Index: lib/sqlalchemy/databases/mssql.py
===================================================================
--- lib/sqlalchemy/databases/mssql.py (revision 5930)
+++ lib/sqlalchemy/databases/mssql.py (working copy)
@@ -991,7 +991,7 @@
# We may have to skip over a number of result sets with
no data (due to triggers, etc.)
while True:
try:
- row = self.cursor.fetchone()
+ row = self.cursor.fetchall()[0]
break
except pyodbc.Error, e:
self.cursor.nextset()

I.e., calling fetchall() instead of fetchone() seems to clean up the
cursor state.

Two caveats: (1) there are many other (non dialect) test failures with
and without my patch, although the patch does reduce the number. So
maybe there is something amok with my configuration. (2) I'm only
tried this on Debian--I have no idea what would happen on Windows.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to sqlalchemy+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---
Lukasz Szybalski
2009-04-29 14:30:28 UTC
Permalink
Post by Tom Wood
I can reproduce this problem running the SQLAlchemy dialect unit
tests.  Using a trunk (r5930) checkout, FreeTDS 0.82 with tds protocol
version 8.0, pyodbc 2.1.4, Python 2.5 and SQL Server 2005, I see three
DataError: (DataError) ('22018', '[22018] [FreeTDS][SQL Server]
Implicit conversion from data type varchar to varbinary is not
allowed. Use the CONVERT function to run this query. (257)
(SQLPrepare)') 'INSERT INTO binary_table (primary_id, data,
data_image, data_slice, misc, pickled, mypickle) VALUES
(?, ?, ?, ?, ?, ?, ?)' [1, <read-only buffer for 0x842e680, size -1,
offset 0 at 0xb75c8f80>, <read-only buffer for 0x842e680, size -1,
offset 0 at 0xb75c8f60>, <read-only buffer for 0xb75e9c20, size -1,
offset 0 at 0xb75d00a0>, 'binary_data_one.dat', <read-only buffer for
0xb75c67a0, size -1, offset 0 at 0xb75d0180>, <read-only buffer for
0xb75d9d68, size -1, offset 0 at 0xb75d0100>]
I'm going to ignore this for now, since it seems to be unrelated to my
problem.
However, test_fetchid_trigger and test_slice_mssql both fail with the
 File "/home/taw00008/src/sqlalchemy-trunk/lib/sqlalchemy/engine/
base.py", line 931, in _handle_dbapi_exception
   raise exc.DBAPIError.instance(statement, parameters, e,
connection_invalidated=is_disconnect)
ProgrammingError: (ProgrammingError) ('24000', '[24000] [FreeTDS][SQL
Server]Invalid cursor state (0) (SQLExecDirectW)') 'INSERT INTO foo
(bar, range) VALUES (?, ?); select scope_identity()' [1, 1]
Here's a possible fix.  The following patch to mssql.py corrects my
problems, as well as the test_fetchid_trigger and test_slice_mssql
Index: lib/sqlalchemy/databases/mssql.py
===================================================================
--- lib/sqlalchemy/databases/mssql.py   (revision 5930)
+++ lib/sqlalchemy/databases/mssql.py   (working copy)
@@ -991,7 +991,7 @@
            # We may have to skip over a number of result sets with
no data (due to triggers, etc.)
-                    row = self.cursor.fetchone()
+                    row = self.cursor.fetchall()[0]
                    break
                    self.cursor.nextset()
I.e., calling fetchall() instead of fetchone() seems to clean up the
cursor state.
Two caveats: (1) there are many other (non dialect) test failures with
and without my patch, although the patch does reduce the number.  So
maybe there is something amok with my configuration.  (2) I'm only
tried this on Debian--I have no idea what would happen on Windows.
Can you read over this ticket and see if maybe you are affected.
http://www.sqlalchemy.org/trac/ticket/1350


If not then somebody more familiar with sa would need to look into why
these tests are failing.

Thanks,
Lucas

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to sqlalchemy+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---
Michael Trier
2009-04-29 15:39:51 UTC
Permalink
Post by Tom Wood
I can reproduce this problem running the SQLAlchemy dialect unit
tests. Using a trunk (r5930) checkout, FreeTDS 0.82 with tds protocol
version 8.0, pyodbc 2.1.4, Python 2.5 and SQL Server 2005, I see three
DataError: (DataError) ('22018', '[22018] [FreeTDS][SQL Server]
Implicit conversion from data type varchar to varbinary is not
allowed. Use the CONVERT function to run this query. (257)
(SQLPrepare)') 'INSERT INTO binary_table (primary_id, data,
data_image, data_slice, misc, pickled, mypickle) VALUES
(?, ?, ?, ?, ?, ?, ?)' [1, <read-only buffer for 0x842e680, size -1,
offset 0 at 0xb75c8f80>, <read-only buffer for 0x842e680, size -1,
offset 0 at 0xb75c8f60>, <read-only buffer for 0xb75e9c20, size -1,
offset 0 at 0xb75d00a0>, 'binary_data_one.dat', <read-only buffer for
0xb75c67a0, size -1, offset 0 at 0xb75d0180>, <read-only buffer for
0xb75d9d68, size -1, offset 0 at 0xb75d0100>]
I'm going to ignore this for now, since it seems to be unrelated to my
problem.
This failure has started about a month ago and I haven't had time to
investigate.
Post by Tom Wood
However, test_fetchid_trigger and test_slice_mssql both fail with the
File "/home/taw00008/src/sqlalchemy-trunk/lib/sqlalchemy/engine/
base.py", line 931, in _handle_dbapi_exception
raise exc.DBAPIError.instance(statement, parameters, e,
connection_invalidated=is_disconnect)
ProgrammingError: (ProgrammingError) ('24000', '[24000] [FreeTDS][SQL
Server]Invalid cursor state (0) (SQLExecDirectW)') 'INSERT INTO foo
(bar, range) VALUES (?, ?); select scope_identity()' [1, 1]
Here's a possible fix. The following patch to mssql.py corrects my
problems, as well as the test_fetchid_trigger and test_slice_mssql
Interesting fix. I'll apply and test against windows and pyodbc.
Post by Tom Wood
Index: lib/sqlalchemy/databases/mssql.py
===================================================================
--- lib/sqlalchemy/databases/mssql.py (revision 5930)
+++ lib/sqlalchemy/databases/mssql.py (working copy)
@@ -991,7 +991,7 @@
# We may have to skip over a number of result sets with
no data (due to triggers, etc.)
- row = self.cursor.fetchone()
+ row = self.cursor.fetchall()[0]
break
self.cursor.nextset()
I.e., calling fetchall() instead of fetchone() seems to clean up the
cursor state.
Two caveats: (1) there are many other (non dialect) test failures with
and without my patch, although the patch does reduce the number. So
maybe there is something amok with my configuration. (2) I'm only
tried this on Debian--I have no idea what would happen on Windows.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to sqlalchemy+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Loading...