[sqlalchemy] 0.5.3 ORM, MSSQL and FreeTDS: Invalid Cursor State exception?

2009-04-27 Thread 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.

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

[sqlalchemy] 0.5.3 and mssql

2009-04-07 Thread Lukasz Szybalski

Hello,

Is this still proper connection string for mssql where I specify the
tds version and a connection driver name?

 e = 
sqlalchemy.create_engine(mssql://user:p...@server:1433/db_name?driver=TDSodbc_options='TDS_Version=8.0')

What is the syntax for driver, and how can I pass TDS_Version=8.0 to
the end of connection string?

Thanks,
Lucas


File 
/home/lucas/tmp/saENV/lib/python2.5/site-packages/SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/pool.py,
line 198, in __init__
self.connection = self.__connect()
  File 
/home/lucas/tmp/saENV/lib/python2.5/site-packages/SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/pool.py,
line 261, in __connect
connection = self.__pool._creator()
  File 
/home/lucas/tmp/saENV/lib/python2.5/site-packages/SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/engine/strategies.py,
line 80, in connect
raise exc.DBAPIError.instance(None, None, e)
sqlalchemy.exc.DBAPIError: (Error) ('08001', '[08001]
[unixODBC][FreeTDS][SQL Server]Unable to connect to data source (0)
(SQLDriverConnectW)') None None




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