[sqlalchemy] MemoryError in unitofwork.py
I'm doing a fair number of session flushes as I update my data in the database. After about 53 of them (or so) I am getting the following exception: File build\bdist.win32\egg\sqlalchemy\orm\session.py, line 294, in flush File build\bdist.win32\egg\sqlalchemy\orm\unitofwork.py, line 181, in flush MemoryError Anyone have any ideas: My code is simply adding new entries and every 1000 entries flushing the objectstore. Thanks, Brandon Goldfedder --~--~-~--~~~---~--~~ 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: Generated slow JOIN sql statement/specifying a left JOIN
On Apr 25, 2007, at 12:25 AM, Andreas Jung wrote: hmm..Why has this to do with self-referential mappers? Wouldn't the generated SQL be same if it wasn't a self-referential mapper but just mapper with a property for a one-to-many relationship? well no, the eager load paradigm is: select table1.*, table2.* from table1 LEFT OUTER JOIN table2 on table1.someid=table2.someid if table1 and table2 are the same table, you have to alias table2, but also the single LEFT OUTER JOIN only gets you the first level of joins. if your recursive structure is 4 levels deep you dont get much. theres other recursive issues involved there which I prefer not to get involved in, in favor over forcing the user to come up with an exact query that loads the self-referred rows in a way thats tailored to the application. And it's not about eager loading. I am perfectly fine with lazy loading. I am just saying that the generated SQL for lazy-loading the 'tools' property isn't perfect. A left join would be much faster but I don't know if it is possible to influence that on the configuration level?! well i just noticed youre sticking an external table into your primaryjoinbut i see nothing there that implies the usage of a LEFT OUTER JOIN ? are you saying that you dont need the rows from AMH_View to be present ? how could SA possibly know that ? (if not, please send me the exact query being produced, and the exact query you think should be produced) --~--~-~--~~~---~--~~ 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: MemoryError in unitofwork.py
On Apr 24, 2007, at 10:59 AM, Brandon Goldfedder wrote: I'm doing a fair number of session flushes as I update my data in the database. After about 53 of them (or so) I am getting the following exception: File build\bdist.win32\egg\sqlalchemy\orm\session.py, line 294, in flush File build\bdist.win32\egg\sqlalchemy\orm\unitofwork.py, line 181, in flush MemoryError Anyone have any ideas: My code is simply adding new entries and every 1000 entries flushing the objectstore. the session doesnt clear itself out after a flush, so with each successive save() of objects memory will grow. --~--~-~--~~~---~--~~ 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] Problems Inserting into Oracle using Bind Variables from Turbo Gears Controller
Hi, I have configured Turbogears and created a quick-start web site with SQL Alchemy as the database modeler. The kid template pages where I showed some data from the database are working perfectly. But the part of the controller where I am trying to do an INSERT into a table of my oracle database using the values of the bind variables of a remote form that I have shown, is not working. Apparently there is some problem with the UNICODE data that sqlAlchemy sends to oracle from the turbo gears framework. But I have tried the same from the python command line with named parameters and its works without any issues. I furnish below all the code parts related to the issue and any kind help is appreciated. Regards Ravi --- FROM TURBOGEARS --- The method in the controller which is in-charge of doing the INSERT into the database using the received parameters def add(self, _name, _email, _text, _somedate, *args): #ins_comment = model.comments_table.insert().execute(name=Ravi, email=[EMAIL PROTECTED], text=Some Text) --- This worked 100% inserting the row into the table. print _name, _email, _text, _somedate --- This prints the values correclty ins_comment = model.comments_table.insert().execute(email=_email, name=_name, text=_text) --- This is not doing the insert into the oracle table correctly but throwing the following error. SQLError: (NotSupportedError) Variable_TypeByValue(): unhandled data type unicode 'INSERT INTO comments (email, name, text) VALUES (:email, :name, :text)' {'text': u'This is a comment', 'email': u'[EMAIL PROTECTED]', 'name': u'Ravi'} --- FROM PYTHON CLI --- Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. from sqlalchemy import * db = create_engine('oracle://scott:[EMAIL PROTECTED]') metadata = BoundMetaData(db) comments_table = Table(comments, metadata, autoload=True) v_email='[EMAIL PROTECTED]' v_name='Ravi Kasibhatla' v_text='This is a comment from Python CLI' ins = comments_table.insert() ins.execute(email=v_email, name=v_name, text=v_text) sqlalchemy.engine.base.ResultProxy object at 0x00D503D0 sel = comments_table.select() rows = sel.execute() print rows.fetchall() [('[EMAIL PROTECTED]', 'Ravi Kasibhatla', 'This is a comment from Python CLI', datetime.datetime(2007, 4, 25, 11, 24, 13))] AS YOU CAN SEE, THE INSERT WAS SUCCESSFUL --~--~-~--~~~---~--~~ 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: Selectable/subquery for a (scalar) column?
Ok, I'm quite a bit stubborn at times, so I implemented this the way I thought because I think it makes much more sense this way. Attached is an experimental (as usual) patch to add a StatementProperty, so that you can define stuff like: mapper(Tag, tags_table, properties={ 'query_score': StatementProperty((tags_table.c.score1 * tags_table.c.score2).label('tag_score'), Float()), }) or even: user_score = select([func.sum(tags_table.c.score1 * tags_table.c.score2)], tags_table.c.user_id == users_table.c.id, scalar=True).label('user_score') mapper(User, users_table, properties={ 'tags': relation(Tag, backref='user', lazy=False), 'query_score': StatementProperty(user_score, Float()), }) I don't see what's wrong with this approach so far. As always, I might not see the big picture... I just hope this will be useful in some way, even if it's not what you envisioned. Some random remarks: - the statement you give must have a label (that seem pretty logical this way though) - you need to manually provide the type of the property you create (seem logical too). In a final patch, we'd probably want to also accept types in their class form (Float and Float()). - it works both for lazy and eagerloads (I struggled quite a bit to get those to work) - subselects pulled from a lazyload don't work though. But I think it should be quite easily fixable. - As always, I'm not attached to the names I've given. On 4/24/07, Michael Bayer [EMAIL PROTECTED] wrote: On Apr 24, 2007, at 4:44 AM, Gaetan de Menten wrote: the next way is to do it almost the same as Jonathan's blog says to do it, except youd map the relation to some intermediary class like Score, and then use AssociationProxy to apply the scalar property to the class. I thought about something like this but it felt sooo hacky I disregarded it quickly. this is probably the least hacky as like i said im probably going to implement a feature that works just like this. -- Gaƫtan de Menten http://openhex.org --~--~-~--~~~---~--~~ 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] Problem with clear_mapper
Hi everyone, I have a problem using the following code (with sqlalchemy 0.3.6 and python2.5): mapperA = mapper(MyClass, self.tables['report_ia'], entity_name = 'REPIA', primary_key=[self.tables['report_ia'].c.id]) mapperB = mapper(MyClass, self.tables['report_ib'], entity_name = 'REPIB', primary_key=[self.tables['report_ib'].c.id]) customSelect = select( [ mapperA.c.id, mapperA.c.uid, func.count(mapperA.c.itemcount).label(itemcount), ], mapperA.c.owner.in_( 'User' ) ), group_by=[mapperA.c.uid, mapperA.c.id] ).alias(totals) customMapper = mapper(MyClass, customSelect, entity_name = temporary, primary_key = [ customSelect.c.id ], ) result = self.session.query(customMapper).select() clear_mapper(customMapper) Running that I get: Processing Failure c /usr/lib/python2.5/site-packages/sqlalchemy/orm/__init__.py:110:clear_mapper] What am I doing wrong here? Any help would be appreciated. Thanks, Kevin --~--~-~--~~~---~--~~ 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: Problem with clear_mapper
On Apr 25, 2007, at 6:06 PM, Kevin Schmidt wrote: clear_mapper(customMapper) Running that I get: Processing Failure c /usr/lib/python2.5/site-packages/sqlalchemy/orm/__init__.py: 110:clear_mapper] im not sure what that error means, or if thats a full stack trace (if not, a full stack would be helpful). but the clear_mapper() function is going to be generally pretty unreliable since the mapper can be involved in relationships with other mappers. (favor clear_mappers() ) --~--~-~--~~~---~--~~ 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: MySQL schema and character_Set_results
On Apr 25, 2007, at 10:03 PM, Daniel Holth wrote: I need schema support and it works at all support in MySQL, so I had to change these things. It was'n't character_Set_results it was character_set_results. The older MySQL 4? doesn't have this value at all. Hopefully I will be fully upgraded in a few weeks. MySQL 4.0.24: show variables like 'char%'; | character_set | latin1 | character_sets | latin1 big5 cp1251 cp1257 croat czech danish dec8 dos estonia euc_kr gb2312 gbk german1 greek hebrew hp8 hungarian koi8_ru koi8_ukr latin1_de latin2 latin5 sjis swe7 tis620 ujis usa7 win1250 win1251ukr win1251 | The table exists function sucks. Is raising an error necessarily catastrophic here? what, just doing the catch ? i dunno. the thing about catching the error, the error should be checked also that its the table doesnt exist error (and not some other error...like connection lost or something). so sure send me a patch for that. the USE version below is kind of ugly (not a fan of changing state on pooled objects). --~--~-~--~~~---~--~~ 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: MySQL schema and character_Set_results
P.S. My application uses reflection. For MySQL it would make so much sense to combine table exists with show me the table, since they are the same request. We should cache the result. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---