On Mon, Apr 27, 2009 at 10:01 AM, Tom Wood <thomas.a.w...@gmail.com> wrote:
>
> 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)

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



> 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]
>
> >
>



-- 
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 sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to