[sqlalchemy] Re: correlated update across logical databases
Hi Michael 2008/7/18 Michael Bayer [EMAIL PROTECTED]: On Jul 18, 2008, at 9:37 AM, Ryan Tracey wrote: sqlalchemy.exc.NoSuchTableError: manufacturer Just to sum up: dbengine = create_engine('mysql://u:[EMAIL PROTECTED]/schema1') meta = MetaData() meta.bind = dbengine Table('tableX', meta, autoload=True) ... Table('tableA', meta, autoload=True, schema='schema2') Table('tableB', meta, autoload=True, schema='schema2') tableX is okay, and tableA loads okay too. However tableB has a FK referencing tableA. Bang! I get a NoSuchTableError for tableA. I'll try get some ipython output. Or figure out how pdb works. its likely mysql reflection doesn't yet know how to reflect cross- schema foreign keys. put up a trac ticket with a short test case. Will do. (Sorry for the late reply. Just moved house and still waiting for phone/adsl line to be installed.) Cheers, Ryan -- Ryan Tracey Citizen: The World --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Save file to FS along with object database commit.
Hello Guys, I have an object which I save to the database using SQLAlchemy, the class is defined using declarative and has a whole bunch of properties. This object has one property though which isn't saved to the database, but to the file system. It is basically a binary string of a files contents. I essentially want to write this binary content to the file system when the record is created in the database, and likewise, delete the file from the FS when the record is removed from the database. I understand all the basics of writing a file, it's just a case of how to implement this into the ORMified object. How would you handle this? Presumably it'll involve creating a couple of methods in the class which handle the file save/delete process, but how do I tie these to the save/delete methods of the ORM? And furthermore, are there any smart ways of making this transactional so if either the database write fails or the file write fails then the they are both rolledback so I don't end up with db records without files and files without dbrecords? I'd really appreciate your thoughts on the cleanest way to implement this. Heston --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Data Inheritance
Yeah thats kind of what I'm trying to do, i think it would help me a little. Thanks. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] SELECT DISTINCT at the ORM level
Hi What is the most elegant way of performing a SELECT DISTINCT on a single column at the ORM level on SQLAlchemy 0.4.6? It looks like you can do q=session.query(Order.support_manager).distinct() in the beta version. This is not supported in 0.4.6 though. Thanks in advance Best regards Jon --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: SELECT DISTINCT at the ORM level
On Jul 21, 2008, at 7:19 AM, jrpfinch wrote: Hi What is the most elegant way of performing a SELECT DISTINCT on a single column at the ORM level on SQLAlchemy 0.4.6? It looks like you can do q=session.query(Order.support_manager).distinct() in the beta version. This is not supported in 0.4.6 though. Thanks in advance 0.4's Query doesn't do just single columns so in 0.4 you'd have to use a select() construct.If you use the Session's execute() method it will execute within the context of the Session's current transaction, if any. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Error after upgrade from 0.4.3 to 0.4.6
Hi, I've done some exploring and found that if I connect to the database as the schema owner the error goes away. I had been connecting through a proxy account and this was working fine in 4.3. You can see where this is tripping up 4.6 from the sql log just after staring the app: With 4.6: C:\Documents and Settings\daystev\Desktop\asrt_trunk\srt-projectstart- srt.py dev.cfg SELECT USER FROM DUAL {} select COLUMN_NAME, DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, NULLABLE , DATA_DEFAULT from ALL_TAB_COLUMNS where TABLE_NAME = :table_name and OWNER = : owner {'owner': 'ASRT_PROXY', 'table_name': 'ACC_PROTOCOL'} Traceback (most recent call last): File C:\Documents and Settings\daystev\Desktop\asrt_trunk\srt- project\start-srt.py, line 24, in module ... With 4.3: C:\Documents and Settings\daystev\Desktop\asrt_trunk\srt-projectstart- srt.py dev.cfg SELECT USER FROM DUAL {} select COLUMN_NAME, DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, NULLABLE , DATA_DEFAULT from ALL_TAB_COLUMNS where TABLE_NAME = :table_name and OWNER = : owner {'owner': 'ASRT_PROXY', 'table_name': 'ACC_PROTOCOL'} Traceback (most recent call last): File C:\Documents and Settings\daystev\Desktop\asrt_trunk\srt- project\start-srt.py, line 24, in module ... Note that 4.6 is using ASRT_PROXY as the owner while 4.3 uses ASRT (the actual owner). To fix the problem (and continue using the proxy account) I added schema=ASRT to all my table definitions. Now everything works fine. Thanks for all your work. Congrats on the book(s)! Steve On Jul 18, 1:45 pm, Michael Bayer [EMAIL PROTECTED] wrote: On Jul 18, 2008, at 1:32 PM, shday wrote: I upgraded from 0.4.3 to 0.4.6 and now I get the error below when starting my TurboGears app. I'm using reflection and that fails on the first table. I had a look at the changelog and tried adding oracle_resolve_synonyms=True to that table's definition but I got another error (not shown here). Any help would be appreciated. what's the schema look like ? are synonyms in use ? are there cross- owner names in use ? what's the error you got with oracle_resolve_synonyms ? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: SystemError: 'finally' pops bad exception with MS SQL Server
There have been other reports of this issue, all specific to pyodbc. It doesn't appear to be an issue with SA, as other MSSQL DBAPI modules don't exhibit the problem. Please raise the issue on the pyodbc list, I'll work with you if needed to help resolve it. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: SystemError: 'finally' pops bad exception with MS SQL Server
Yes it appears to be a pyodbc problem, which is a shame because it's making debugging my project incredibly difficult (and I've had even more problems with the other MS SQL libraries like pymssql). The bug report is here: http://sourceforge.net/tracker/index.php?func=detailaid=1948657group_id=162557atid=824254 I am willing to put in a lot of time to make this work - however I have no experience in C++ so it's going to be a challenge without some help. Here is a reproduction of the problem in pyodbc: import pyodbc cnxn = pyodbc.connect(DSN=xx;UID=x;PWD=xx) cursor=cnxn.cursor() cursor.execute(select * from no_such_table) Traceback (most recent call last): File stdin, line 1, in ? type 'instance': ('42S02', [42S02] [FreeTDS][SQL Server]Invalid object name 'no_such_table'. (208) (SQLExecDirectW)) try: ... cursor.execute(select * from no_such_table) ... finally: ... print Oh dear me! ... Oh dear me! Traceback (most recent call last): File stdin, line 4, in ? SystemError: 'finally' pops bad exception I am going to try contacting the admin for pyodbc and it also looks like the bug report has some sort of patch you can apply right at the bottom in errors.diff (which I will try applying and then rebuilding pyodbc, but like I say I have no C++ experience so won't be able to do much if that doesn't work). Any more advice? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: SystemError: 'finally' pops bad exception with MS SQL Server
I read through the pyodbc forum quickly, and it looks as though this issue, first reported back in April, cannot be reproduced by the maintainer. Pick up the forum thread entitled http://sourceforge.net/forum/forum.php?thread_id=1942313forum_id=550700 pyodbc pops bad exception since 2.0.39http://sourceforge.net/forum/forum.php?thread_id=1942313forum_id=550700 and add your simple pyodbc-only testcase - see if you can get a working patch from the maintainer. A patch that fixes your testcase might prompt a new release (last release was back in April). --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: SystemError: 'finally' pops bad exception with MS SQL Server
Done - I really hope we can get this fixed because sqlalchemy and TurboGears is incredibly difficult to use with MS SQL Server at the moment. I think I may be able to improve sqlalchemy if I can get the errors propogating properly Cheers Jon --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Exception is not caught
the engine does not connect until first used, in this case when you've called all() on a Query. If you want to force a connection at a specific point, say engine.connect(). On Jul 21, 2008, at 7:13 AM, Werner F. Bruhin wrote: Can someone point out to me what I am doing wrong that I can not catch this exception: Mon Jul 21 11:56:59 2008 Version: 3.0.399.1 wxV: 2.8.8.0 (msw-unicode) * Traceback (most recent call last): File twcb.py, line 1136, in module File twcb.py, line 1132, in main File wx\_core.pyo, line 7912, in __init__ File wx\_core.pyo, line 7487, in _BootstrapApp File twcb.py, line 272, in OnInit File sqlalchemy\orm\query.pyo, line 413, in get File sqlalchemy\orm\query.pyo, line 1179, in _get File sqlalchemy\orm\query.pyo, line 973, in all File sqlalchemy\orm\query.pyo, line 1038, in __iter__ File sqlalchemy\orm\query.pyo, line 1041, in _execute_and_instances File sqlalchemy\orm\session.pyo, line 730, in execute File sqlalchemy\orm\session.pyo, line 697, in __connection File sqlalchemy\orm\session.pyo, line 317, in _connection_for_bind File sqlalchemy\engine\base.pyo, line 1243, in contextual_connect File sqlalchemy\pool.pyo, line 165, in connect File sqlalchemy\pool.pyo, line 323, in __init__ File sqlalchemy\pool.pyo, line 180, in get File sqlalchemy\pool.pyo, line 615, in do_get File sqlalchemy\pool.pyo, line 145, in create_connection File sqlalchemy\pool.pyo, line 217, in __init__ File sqlalchemy\pool.pyo, line 280, in __connect File sqlalchemy\engine\strategies.pyo, line 80, in connect OperationalError: (OperationalError) (-902, 'isc_attach_database: \n I/O error for file C:/Spiritissimo/twcb.fdb\n Error while trying to open file\n The process cannot access the file because it is being used by another process. ') None None Line 272 in twcb.py is: dbConnected = self.ConnectDB() def ConnectDB(self): Connect to the database ... removed some lines which get config information try: ... removed some lines which show passwords, which basically setup dburl variable debug = self.twcbConfig.Read('SQLLog', 'False') if debug == 'True': # twcbConfig entries are strings import logging logging.basicConfig(filename=self.sqllog.name) logger = logging.getLogger('sqlalchemy.engine') # following could be expanded # see http://www.sqlalchemy.org/docs/04/dbengine.html#dbengine_logging logger.setLevel(logging.DEBUG) self.engine = db.sa.create_engine(dburl, encoding='utf8', echo=False) self.Session = db.sao.sessionmaker() self.Session.configure(bind=self.engine) self.ds = self.Session() return True except Exception, error: wx.MessageBox(str(error), _(u'DB connection failed')) return False Do I have to wrap the call to self.ConnectDB into a try/except to make sure to catch the exception? I also tried using a more specific catch, but with no success either: except db.saexc.OperationalError, error: wx.MessageBox(str(error), _(u'DB connection failed - Operational error')) return False Thanks for any hints on this. Werner P.S. The database is Firebird SQL 2.1 with kinterbasdb 3.x --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Column metadata from mapped class
On Jul 21, 2008, at 9:45 PM, huy do wrote: Because a mapped class can have an arbitary select as it's source i.e columns from any table theoretically, it would still be nice to know exactly which columns were used to map the properties of a given class. The .c on the model class use to give us the metadata (i.e either the select or table aka relation) which was used to populate the class. Can we get an extension to get this feature back (please) ? If you just want the Table, its just class_mapper(class).mapped_table.Theres lots of ways to build your own .c. class attirbute and such, including: MyClass.c = class_mapper(MyClass).columns the .c. really had to be removedits entirely different now if you say query.filter(MyClass.c.foo=='bar') in 0.5 since no adaptation will take place. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---