[sqlalchemy] pyodbc issues
I am still having issues with pyodbc on Python 2.6. Platform: Windows XP SP3 32 bit Python 2.6 SQLAlchemy 0.5.3 pyodbc 2.1.3 When I use SQL-Lite, my tables are created and all my data is inserted. When I use MS SQL, the tables get created but my data will not insert. Here is my session: Session = scoped_session(sessionmaker(bind=engine, autoflush=False, autocommit=True)) Any ideas? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Attempting to flush an item of type...
the solution was to inherit setup.USER with a non-relative path fossati.models.client.User. I misinterpreted the words 'whose mapper...' and believed it was referencing Entry.user while it is referred to setup.USER. sandro --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] mapping class against arbitrary SQL expression
Hi, is there a way to map a class against an arbitrary SQL expression (read-only would be OK)? I can't find the correct way to define the selectable for the mapper. Example: this table: carside_table = Table( 'carside', metadata, Column('id', Integer, primary_key=True), Column('car_id', Integer), Column('side', Text), Column('temperature', Float), ) with a dummy class; class CarSide(object): pass And I want to use this SQL expression to map the class: SELECT left.car_id left.temperature AS left_temperature right.temperature AS right_temperature FROM carside AS left JOIN carside AS right ON left.car_id=right.car_id WHERE left.side = left AND right.side = right ; Many thanks, Jan. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: mapping class against arbitrary SQL expression
-Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalch...@googlegroups.com] On Behalf Of JanW Sent: 17 April 2009 13:18 To: sqlalchemy Subject: [sqlalchemy] mapping class against arbitrary SQL expression Hi, is there a way to map a class against an arbitrary SQL expression (read-only would be OK)? I can't find the correct way to define the selectable for the mapper. Example: this table: carside_table = Table( 'carside', metadata, Column('id', Integer, primary_key=True), Column('car_id', Integer), Column('side', Text), Column('temperature', Float), ) with a dummy class; class CarSide(object): pass And I want to use this SQL expression to map the class: SELECT left.car_id left.temperature AS left_temperature right.temperature AS right_temperature FROM carside AS left JOIN carside AS right ON left.car_id=right.car_id WHERE left.side = left AND right.side = right ; Many thanks, Jan. I think the approach should look something like this: #--- from sqlalchemy import * from sqlalchemy import orm metadata = MetaData() carside_table = Table( 'carside', metadata, Column('id', Integer, primary_key=True), Column('car_id', Integer), Column('side', Text), Column('temperature', Float), ) left = carside_table.alias('left') right = carside_table.alias('right') tables = left.join(right, left.c.car_id == right.c.car_id) s = select([left.c.car_id, left.c.temperature.label('left_temperature'), right.c.temperature.label('right_temperature')], from_obj=tables, whereclause=and_(left.c.side == 'left', right.c.side == 'right')) class CarSide(object): pass orm.mapper(CarSide, s, primary_key=[s.c.car_id]) #--- ...but it fails on the last line with the message Mapper Mapper|CarSide|%(3069523404 anon)s could not assemble any primary key columns for mapped table '%(3069523404 anon)s'. I had hoped that passing the primary_key parameter to mapper would have solved that, but it doesn't. I'm not sure why. Simon --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: mapping class against arbitrary SQL expression
OK, thanks, it does work if you make an alias on the select like this: s = select([left.c.car_id, left.c.temperature.label('left_temperature'), right.c.temperature.label('right_temperature')], from_obj=tables, whereclause=and_(left.c.side == 'left', right.c.side == 'right')).alias('carside') Thanks a lot! Now, is it really needed to translate my SQL query first to SA-speak or could I use the SQL directly in some way? (I have many old projects with SQL embedded in Perl scripts, so it would be someway easier is I can transfer the SQL directly). From session.query() there is something like from_statement (SQL_string) but that won't work here I think. Again, many thanks, Jan. On Apr 17, 2:43 pm, King Simon-NFHD78 simon.k...@motorola.com wrote: -Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalch...@googlegroups.com] On Behalf Of JanW Sent: 17 April 2009 13:18 To: sqlalchemy Subject: [sqlalchemy] mapping class against arbitrary SQL expression Hi, is there a way to map a class against an arbitrary SQL expression (read-only would be OK)? I can't find the correct way to define the selectable for the mapper. Example: this table: carside_table = Table( 'carside', metadata, Column('id', Integer, primary_key=True), Column('car_id', Integer), Column('side', Text), Column('temperature', Float), ) with a dummy class; class CarSide(object): pass And I want to use this SQL expression to map the class: SELECT left.car_id left.temperature AS left_temperature right.temperature AS right_temperature FROM carside AS left JOIN carside AS right ON left.car_id=right.car_id WHERE left.side = left AND right.side = right ; Many thanks, Jan. I think the approach should look something like this: #--- from sqlalchemy import * from sqlalchemy import orm metadata = MetaData() carside_table = Table( 'carside', metadata, Column('id', Integer, primary_key=True), Column('car_id', Integer), Column('side', Text), Column('temperature', Float), ) left = carside_table.alias('left') right = carside_table.alias('right') tables = left.join(right, left.c.car_id == right.c.car_id) s = select([left.c.car_id, left.c.temperature.label('left_temperature'), right.c.temperature.label('right_temperature')], from_obj=tables, whereclause=and_(left.c.side == 'left', right.c.side == 'right')) class CarSide(object): pass orm.mapper(CarSide, s, primary_key=[s.c.car_id]) #--- ...but it fails on the last line with the message Mapper Mapper|CarSide|%(3069523404 anon)s could not assemble any primary key columns for mapped table '%(3069523404 anon)s'. I had hoped that passing the primary_key parameter to mapper would have solved that, but it doesn't. I'm not sure why. Simon --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] SA pooling strategy and mysql has gone away
The mysql has gone away thing: mysql server timeout:60 (1 min) I read the source code of SA , and figure out the following solutions : sl1 -- set pool_size=1 and max_overflow #this will close all connections in pool,because the only conn is closed by my app with (session.close(),connection.close(), or result.close() and all overflow conn are closed and discarded when recycling to pool this solution doesn't work) sl2 -- set pool_recycle = 50 #recycle conn before mysql timeout 50-60=10 10s for recycle is needed sl3 -- set poolclass=NullPool #don't use pool strategy sl4 -- add poollistener sl5 -- set pool_recycle=1 or 0 # ensure to reclye and create new conn when check out at any time after try all these 5 solutions ,the mysql has gone away problem is still there !!! I asume the pool has succeffuly recycled the timeout connections ,all connections we use are new /fresh connection fetched from the DBAPI,and Exception comes again and again.why may be , that is because our code has used some connection and forget to close them,and these connecions are not being managed by pool any more (I think connecions not closed are out of control of pool .I find this in source code in Connection Class's close method-- then call _ConnectionFairy . close--then call fanalizeFairy -- then pool.return_conn). So we should close all session or resultpoxy object in our code . And we do this,this time the mysql has gone away '' has gone away sl6 -- write new pool implementation sl7 -- rewrite Connection class of SA These two are difficult and may introduce more problem so I don't use them. hehehe. And , one more thing to mention: Why Connection class in db backend.base alway dispose the underlying engine and pool whenever there is a DBAPI Error and e.args in (2006,2000.)? why on timeout connection will cause all other connections in pool being closed ?? why not try one more times to finish the work before raise this exception?? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: mapping class against arbitrary SQL expression
-Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalch...@googlegroups.com] On Behalf Of JanW Sent: 17 April 2009 14:45 To: sqlalchemy Subject: [sqlalchemy] Re: mapping class against arbitrary SQL expression OK, thanks, it does work if you make an alias on the select like this: s = select([left.c.car_id, left.c.temperature.label('left_temperature'), right.c.temperature.label('right_temperature')], from_obj=tables, whereclause=and_(left.c.side == 'left', right.c.side == 'right')).alias('carside') Thanks a lot! Now, is it really needed to translate my SQL query first to SA-speak or could I use the SQL directly in some way? (I have many old projects with SQL embedded in Perl scripts, so it would be someway easier is I can transfer the SQL directly). From session.query() there is something like from_statement (SQL_string) but that won't work here I think. Again, many thanks, Jan. I don't know the answer, but I suspect this will be a problem. I think SA needs to know what columns are going to be returned from the select statement so that it can set up properties on the mapped class. I don't know of any way that you can mark a text block as a Selectable. Sorry I can't be more help, Simon --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: pyodbc issues
are you using FreeTDS ? there's a known issue with FreeTDS and SQLA 0.5. Michael Mileusnich wrote: I am still having issues with pyodbc on Python 2.6. Platform: Windows XP SP3 32 bit Python 2.6 SQLAlchemy 0.5.3 pyodbc 2.1.3 When I use SQL-Lite, my tables are created and all my data is inserted. When I use MS SQL, the tables get created but my data will not insert. Here is my session: Session = scoped_session(sessionmaker(bind=engine, autoflush=False, autocommit=True)) Any ideas? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: pyodbc issues
I do not recall having installed FreeTDS. On Fri, Apr 17, 2009 at 9:56 AM, Michael Bayer mike...@zzzcomputing.comwrote: are you using FreeTDS ? there's a known issue with FreeTDS and SQLA 0.5. Michael Mileusnich wrote: I am still having issues with pyodbc on Python 2.6. Platform: Windows XP SP3 32 bit Python 2.6 SQLAlchemy 0.5.3 pyodbc 2.1.3 When I use SQL-Lite, my tables are created and all my data is inserted. When I use MS SQL, the tables get created but my data will not insert. Here is my session: Session = scoped_session(sessionmaker(bind=engine, autoflush=False, autocommit=True)) Any ideas? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: SA pooling strategy and mysql has gone away
Ubestim wrote: The mysql has gone away thing: mysql server timeout:60 (1 min) I read the source code of SA , and figure out the following solutions : sl1 -- set pool_size=1 and max_overflow #this will close all connections in pool,because the only conn is closed by my app with (session.close(),connection.close(), or result.close() and all overflow conn are closed and discarded when recycling to pool this solution doesn't work) sl2 -- set pool_recycle = 50 #recycle conn before mysql timeout 50-60=10 10s for recycle is needed sl3 -- set poolclass=NullPool #don't use pool strategy sl4 -- add poollistener sl5 -- set pool_recycle=1 or 0 # ensure to reclye and create new conn when check out at any time after try all these 5 solutions ,the mysql has gone away problem is still there !!! what might be the reason that MySQL is not listening for connections ? Are you trying to recover from restarts ?For a total non-persistent connection approach, use the NullPool and always close your Session, that way no connections will be opened at all when you aren't in the middle of an operation. The NullPool is basically not a pool at all. Also, its true that any Connection objects you have lying around will still be active, so make sure you aren't doing that. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: pyodbc issues
can you be more specific what will not insert means. Michael Mileusnich wrote: I do not recall having installed FreeTDS. On Fri, Apr 17, 2009 at 9:56 AM, Michael Bayer mike...@zzzcomputing.comwrote: are you using FreeTDS ? there's a known issue with FreeTDS and SQLA 0.5. Michael Mileusnich wrote: I am still having issues with pyodbc on Python 2.6. Platform: Windows XP SP3 32 bit Python 2.6 SQLAlchemy 0.5.3 pyodbc 2.1.3 When I use SQL-Lite, my tables are created and all my data is inserted. When I use MS SQL, the tables get created but my data will not insert. Here is my session: Session = scoped_session(sessionmaker(bind=engine, autoflush=False, autocommit=True)) Any ideas? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: pyodbc issues
I add my object to the session and flush. No insert happens. Works fine with SQL-LIte. I have have tried adding a commit also but that does not help. On Fri, Apr 17, 2009 at 10:02 AM, Michael Bayer mike...@zzzcomputing.comwrote: can you be more specific what will not insert means. Michael Mileusnich wrote: I do not recall having installed FreeTDS. On Fri, Apr 17, 2009 at 9:56 AM, Michael Bayer mike...@zzzcomputing.comwrote: are you using FreeTDS ? there's a known issue with FreeTDS and SQLA 0.5. Michael Mileusnich wrote: I am still having issues with pyodbc on Python 2.6. Platform: Windows XP SP3 32 bit Python 2.6 SQLAlchemy 0.5.3 pyodbc 2.1.3 When I use SQL-Lite, my tables are created and all my data is inserted. When I use MS SQL, the tables get created but my data will not insert. Here is my session: Session = scoped_session(sessionmaker(bind=engine, autoflush=False, autocommit=True)) Any ideas? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: pyodbc issues
Michael Mileusnich wrote: I add my object to the session and flush. No insert happens. Works fine with SQL-LIte. I have have tried adding a commit also but that does not help. turn on your SQL echoing. see if INSERT is emitted. see if COMMIT is emitted, etc. On Fri, Apr 17, 2009 at 10:02 AM, Michael Bayer mike...@zzzcomputing.comwrote: can you be more specific what will not insert means. Michael Mileusnich wrote: I do not recall having installed FreeTDS. On Fri, Apr 17, 2009 at 9:56 AM, Michael Bayer mike...@zzzcomputing.comwrote: are you using FreeTDS ? there's a known issue with FreeTDS and SQLA 0.5. Michael Mileusnich wrote: I am still having issues with pyodbc on Python 2.6. Platform: Windows XP SP3 32 bit Python 2.6 SQLAlchemy 0.5.3 pyodbc 2.1.3 When I use SQL-Lite, my tables are created and all my data is inserted. When I use MS SQL, the tables get created but my data will not insert. Here is my session: Session = scoped_session(sessionmaker(bind=engine, autoflush=False, autocommit=True)) Any ideas? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: 0.5.2 seems to always roll back with mssql
On Mar 25, 2:14 pm, Rick Morrison rickmorri...@gmail.com wrote: Yep, same here. ..on my mssql 2005, I tried this query batch: set implicit_transactions on go select 'After implicit ON', @@trancount exec sp_datatype_info go select 'After query w/implicit', @@trancount begin transaction go select 'After BEGIN', @@trancount Here's the output: - After implicit ON 0 After query w/implicit 1 After BEGIN 2 Our support team also found that calling commit() after the connect also worked. I guess this will close the outer transaction. It's a bit of a hack, but it sounds like a simple 2-cent solution. We could issue something like: IF @@TRANCOUNT 0 COMMIT on connection establishment. Joined in kind of late on thisbut, what version of TDS are you setting in your dsn setup? (Not sure if that makes a difference or not) Lucas --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: pyodbc issues
The SERVERS table doesn't exist according to the trace. Did you create your tables? Sent from mobile On Apr 17, 2009, at 7:31 PM, Michael Mileusnich justmike2...@gmail.com wrote: C:\Dev\pyschedpython createservers.py D:\Python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg\sqlalchemy \databases\ms sql.py:977: DeprecationWarning: object.__new__() takes no parameters return super(MSSQLDialect, cls).__new__(cls, *args, **kwargs) 2009-04-17 18:29:10,421 INFO sqlalchemy.engine.base.Engine.0x...0270 BEGIN 2009-04-17 18:29:10,437 INFO sqlalchemy.engine.base.Engine.0x...0270 INSERT INTO [SERVERS] ([SERVER], [IP], [PORT], [OS], [JSERVER], [STARTED], [STDIN], [LOGIN] , [CWD], [ASSIGNEDONLY]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 2009-04-17 18:29:10,437 INFO sqlalchemy.engine.base.Engine.0x...0270 ['agent1', '192.168.0.100', 2000, 0, None, 1, 1, 1, 1, 0] 2009-04-17 18:29:10,500 INFO sqlalchemy.engine.base.Engine.0x...0270 ROLLBACK Traceback (most recent call last): File createservers.py, line 9, in module session.flush() File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg \sqlalchemy\orm\ session.py, line 1351, in flush self._flush(objects) File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg \sqlalchemy\orm\ session.py, line 1422, in _flush flush_context.execute() File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg \sqlalchemy\orm\ unitofwork.py, line 244, in execute UOWExecutor().execute(self, tasks) File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg \sqlalchemy\orm\ unitofwork.py, line 707, in execute self.execute_save_steps(trans, task) File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg \sqlalchemy\orm\ unitofwork.py, line 722, in execute_save_steps self.save_objects(trans, task) File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg \sqlalchemy\orm\ unitofwork.py, line 713, in save_objects task.mapper._save_obj(task.polymorphic_tosave_objects, trans) File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg \sqlalchemy\orm\ mapper.py, line 1347, in _save_obj c = connection.execute(statement.values(value_params), params) File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg \sqlalchemy\engi ne\base.py, line 824, in execute return Connection.executors[c](self, object, multiparams, params) File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg \sqlalchemy\engi ne\base.py, line 874, in _execute_clauseelement return self.__execute_context(context) File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg \sqlalchemy\engi ne\base.py, line 896, in __execute_context self._cursor_execute(context.cursor, context.statement, context.parameters[0 ], context=context) File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg \sqlalchemy\engi ne\base.py, line 950, in _cursor_execute self._handle_dbapi_exception(e, statement, parameters, cursor, context) File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg \sqlalchemy\engi ne\base.py, line 931, in _handle_dbapi_exception raise exc.DBAPIError.instance(statement, parameters, e, connection_invalidat ed=is_disconnect) sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42S02', [42S02] [Microsof t][ODBC SQL Server Driver][SQL Server]Invalid object name 'SERVERS'. (208) (SQLE xecDirectW); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. (8180)) u'INSERT INTO [SERVERS] ([SERVER], [IP], [PORT] , [OS], [JSERVER], [STARTED], [STDIN], [LOGIN], [CWD], [ASSIGNEDONLY]) VALUES (? , ?, ?, ?, ?, ?, ?, ?, ?, ?)' ['agent1', '192.168.0.100', 2000, 0, None, 1, 1, 1 , 1, 0] C:\Dev\pysched On Fri, Apr 17, 2009 at 5:05 PM, Michael Trier mtr...@gmail.com wrote: On Apr 17, 2009, at 5:46 PM, Michael Mileusnich justmike2...@gmail.com wrote: First, thanks for being patient and assisting me. I am very thankful. MS SQL 2005 is the db I am running. part of my db.py script: try: connection = config.get(db, connection) except: print No Database Specified sys.exit(1) engine = create_engine(connection) metadata = MetaData(engine) Session = scoped_session(sessionmaker(bind=engine, autoflush=False, autocommit=True)) action_table = Table( 'ACTIONS', metadata, Column('ACTIONID', String(48), primary_key=True), Column('TITLE', String(128)), Column('CMDLINE', String(512)), Column('STDIN', Text), Column('STARTINDIR', String(512)), Column('PRIO', Integer), Column('USERID', Integer, ForeignKey('USERS.USERID'))) ... more tables here ... etc mapper(action, action_table) here is my create: new_action = action(ACTIONID = '500', CMDLINE = 'sol') session.add(new_action) session.flush() also how do I turn on echo? On Fri, Apr 17, 2009 at 3:24
[sqlalchemy] Re: pyodbc issues
Actually I made a mistake in running some of these py files manually. The tables exist now and this is what I receive: 2009-04-17 19:04:59,780 INFO sqlalchemy.engine.base.Engine.0x...1230 () 2009-04-17 19:04:59,796 INFO sqlalchemy.engine.base.Engine.0x...1230 COMMIT C:\Dev\pyschedpython createservers.py D:\Python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg\sqlalchemy\databases\ms sql.py:977: DeprecationWarning: object.__new__() takes no parameters return super(MSSQLDialect, cls).__new__(cls, *args, **kwargs) 2009-04-17 19:05:07,203 INFO sqlalchemy.engine.base.Engine.0x...0270 BEGIN 2009-04-17 19:05:07,217 INFO sqlalchemy.engine.base.Engine.0x...0270 INSERT INTO [SERVERS] ([SERVER], [IP], [PORT], [OS], [JSERVER], [STARTED], [STDIN], [LOGIN] , [CWD], [ASSIGNEDONLY]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 2009-04-17 19:05:07,217 INFO sqlalchemy.engine.base.Engine.0x...0270 ['agent1', '192.168.0.100', 2000, 0, None, 1, 1, 1, 1, 0] 2009-04-17 19:05:07,217 INFO sqlalchemy.engine.base.Engine.0x...0270 COMMIT On Fri, Apr 17, 2009 at 5:58 PM, Michael Trier mtr...@gmail.com wrote: The SERVERS table doesn't exist according to the trace. Did you create your tables? Sent from mobile On Apr 17, 2009, at 7:31 PM, Michael Mileusnich justmike2...@gmail.com wrote: C:\Dev\pyschedpython createservers.py D:\Python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg\sqlalchemy\databases\ms sql.py:977: DeprecationWarning: object.__new__() takes no parameters return super(MSSQLDialect, cls).__new__(cls, *args, **kwargs) 2009-04-17 18:29:10,421 INFO sqlalchemy.engine.base.Engine.0x...0270 BEGIN 2009-04-17 18:29:10,437 INFO sqlalchemy.engine.base.Engine.0x...0270 INSERT INTO [SERVERS] ([SERVER], [IP], [PORT], [OS], [JSERVER], [STARTED], [STDIN], [LOGIN] , [CWD], [ASSIGNEDONLY]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 2009-04-17 18:29:10,437 INFO sqlalchemy.engine.base.Engine.0x...0270 ['agent1', '192.168.0.100', 2000, 0, None, 1, 1, 1, 1, 0] 2009-04-17 18:29:10,500 INFO sqlalchemy.engine.base.Engine.0x...0270 ROLLBACK Traceback (most recent call last): File createservers.py, line 9, in module session.flush() File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg\sqlalchemy\orm\ session.py, line 1351, in flush self._flush(objects) File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg\sqlalchemy\orm\ session.py, line 1422, in _flush flush_context.execute() File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg\sqlalchemy\orm\ unitofwork.py, line 244, in execute UOWExecutor().execute(self, tasks) File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg\sqlalchemy\orm\ unitofwork.py, line 707, in execute self.execute_save_steps(trans, task) File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg\sqlalchemy\orm\ unitofwork.py, line 722, in execute_save_steps self.save_objects(trans, task) File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg\sqlalchemy\orm\ unitofwork.py, line 713, in save_objects task.mapper._save_obj(task.polymorphic_tosave_objects, trans) File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg\sqlalchemy\orm\ mapper.py, line 1347, in _save_obj c = connection.execute(statement.values(value_params), params) File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg\sqlalchemy\engi ne\base.py, line 824, in execute return Connection.executors[c](self, object, multiparams, params) File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg\sqlalchemy\engi ne\base.py, line 874, in _execute_clauseelement return self.__execute_context(context) File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg\sqlalchemy\engi ne\base.py, line 896, in __execute_context self._cursor_execute(context.cursor, context.statement, context.parameters[0 ], context=context) File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg\sqlalchemy\engi ne\base.py, line 950, in _cursor_execute self._handle_dbapi_exception(e, statement, parameters, cursor, context) File d:\python26\lib\site-packages\sqlalchemy-0.5.3-py2.6.egg\sqlalchemy\engi ne\base.py, line 931, in _handle_dbapi_exception raise exc.DBAPIError.instance(statement, parameters, e, connection_invalidat ed=is_disconnect) sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42S02', [42S02] [Microsof t][ODBC SQL Server Driver][SQL Server]Invalid object name 'SERVERS'. (208) (SQLE xecDirectW); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. (8180)) u'INSERT INTO [SERVERS] ([SERVER], [IP], [PORT] , [OS], [JSERVER], [STARTED], [STDIN], [LOGIN], [CWD], [ASSIGNEDONLY]) VALUES (? , ?, ?, ?, ?, ?, ?, ?, ?, ?)' ['agent1', '192.168.0.100', 2000, 0, None, 1, 1, 1 , 1, 0] C:\Dev\pysched On Fri, Apr 17, 2009 at 5:05 PM, Michael Trier mtr...@gmail.com mtr...@gmail.com wrote: On Apr 17, 2009, at 5:46 PM, Michael