[sqlalchemy] Re: Bug in 0.4.6/0.5 ?
On 15 Lug, 17:07, Michael Bayer [EMAIL PROTECTED] wrote: Did you call something like select([literal('foo')]) ?If you use straight Python literals in the columns clause (i.e. select(['foo'])), they will be rendered directly, which is probably what you want here. This is fixed in r4933 / r4934 0.5 trunk/ 0.4 branch. Sorry I had (again damn) problems with my email account so there will come another post about this, just forget the next one No I wasn't using literals in the select, this happens if I just .query.get() on almost any of my mappers I have a combination of horizontal and vertical tables, and I saw with Eric IDE in debug is that the _BindParamClause was referring to some anon_column_whateverNumber, so I thought that this was a quite weird case of table mix that was not specifically tested I saw only now that this is corrected in SVN, sorry :) --~--~-~--~~~---~--~~ 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] AttributeError migrating to 0.4.6
Hello list, I recently installed 0.4.6 and I got this dump: Traceback (most recent call last): File /media/userdata/stefano/Documenti/projects/Tosi/erp/login.py, line 85, in onCheckUtente self.checkUtente(self.inputUser.GetValue().lower()) File /media/userdata/stefano/Documenti/projects/Tosi/erp/login.py, line 64, in checkUtente user = mapperFunctions.getUtente(user) File /media/userdata/stefano/Documenti/projects/Tosi/erp/dyemagic2/mapperFunctions.py, line 19, in getUtente rep = mappers.Reparto.query.first() #Per inizializzare la sessione File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/scoping.py, line 144, in __getattr__ return getattr(self.context.registry().query(class_), key) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/session.py, line 895, in query return self._query_cls(entities, self, **kwargs) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/query.py, line 97, in __init__ self.__setup_aliasizers(self._entities) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/query.py, line 111, in __setup_aliasizers mapper, selectable, is_aliased_class = _entity_info(entity, ent.entity_name) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/util.py, line 398, in _entity_info mapper = class_mapper(entity, entity_name, compile) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/util.py, line 488, in class_mapper mapper = mapper.compile() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/mapper.py, line 368, in compile mapper.__initialize_properties() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/mapper.py, line 389, in __initialize_properties prop.init(key, self) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/interfaces.py, line 378, in init self.do_init() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/properties.py, line 514, in do_init self._post_init() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/properties.py, line 750, in _post_init super(PropertyLoader, self).do_init() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/interfaces.py, line 548, in do_init self.strategy = self.__init_strategy(self.strategy_class) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/interfaces.py, line 537, in __init_strategy strategy.init() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/strategies.py, line 339, in init self.logger.info(%s lazy loading clause %s % (self, self.__lazywhere)) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/expression.py, line 1155, in __str__ return unicode(self.compile()).encode('ascii', 'backslashreplace') File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/expression.py, line 1151, in compile compiler.compile() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 175, in compile self.string = self.process(self.statement) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 183, in process return meth(obj, **kwargs) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 377, in visit_binary return self.process(binary.left) + + op + + self.process(binary.right) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 183, in process return meth(obj, **kwargs) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 227, in visit_grouping return ( + self.process(grouping.element) + ) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 183, in process return meth(obj, **kwargs) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 507, in visit_select for co in select.inner_columns File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 463, in label_select_column return column.label(column.anon_label) AttributeError: '_BindParamClause' object has no attribute 'anon_label' In my database I made a weird combination with vertical tables that maybe fired this, and I thought that not EVERY case is always tested (had a hard time in my first sqa tests few months ago trying to make the vertical example work as I wished with postgres)
[sqlalchemy] OperationalError: (OperationalError) cannot commit transaction - SQL statements in progress
Hi. I'm having problems with the exception in subject, with pysqlite (on Debian Lenny). Unfortunately, I'm unable to reproduce the problem, but basically it is an update statement in a transaction. If there is only one row in the table, all is ok; but if there are more then one rows, I get this exception. If I catch the exception and execute the transaction again, it finally succeed. This is the log of executed queries: BEGIN SELECT users.username, users.password, users.email, users.role, users.enabled, users.registration_date, users.last_login FROM users WHERE users.username = ? ['[EMAIL PROTECTED]'] UPDATE users SET last_login=? WHERE users.username = ? ['2008-07-16 11:08:25.944900', u'[EMAIL PROTECTED]'] COMMIT BEGIN SELECT contacts_info.username, contacts_info.full_name, contacts_info.telephone, contacts_info.fiscal_code FROM contacts_info WHERE contacts_info.username = ? ['[EMAIL PROTECTED]'] SELECT contacts_address.username, contacts_address.administrative_area_code, contacts_address.locality, contacts_address.address_line, contacts_address.address_line_2, contacts_address.postal_code FROM contacts_address, contacts_info WHERE contacts_info.username = ? ['[EMAIL PROTECTED]'] COMMIT BEGIN UPDATE contacts_info SET full_name=?, telephone=?, fiscal_code=? WHERE contacts_info.username = ? ['Manlio Perillo x', u'B', u'C', '[EMAIL PROTECTED]'] UPDATE contacts_address SET administrative_area_code=?, locality=?, address_line=?, address_line_2=?, postal_code=? WHERE contacts_address.username = ? [u'AV', 'X', 'Y', 'Z', u'W', '[EMAIL PROTECTED]'] COMMIT ROLLBACK Thanks Manlio Perillo --~--~-~--~~~---~--~~ 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: Injecting business objects into constructor
Hi Rick, I'm not sure where this is going with the 0.5 version, but I believe that MappedClass.__int__ is still not called when objects are loaded from the DB. If that's the case, and there isn't some alternate that SA provides like MappedClass.__onload__, You can look into Mapper Extensions to provide this. Check out the 'create_instance' method. That sounds ok to me, I'll to take a look into those options and see which best suits me. Are you aware of any IoC frameworks which have been adapted to inject/autowire things into SQLAlchemy transient business objects? Cheers Rick, 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] Ensure Get() always returns a result.
Morning Guys, I'm looking to build a uniform method for getting/creating instance of my objects from the database. At the moment I've been using query(SomeObject).get(object_id) to return the objects from the DB, however, it would be really great if there were a method which always returned a result, so, if I pass in an id of '354' to the get() method and no record with that ID exists in the database, then it just returns a new empty instance of the SomeObject class with the id set to 354. Does such a method exist on the ORM? If not then how would you go about doing so? I came about to this way of thinking when I've been having problems instantiating my own instances of classes which are decoratively mapped to the database. So if I try to create a new instance of a class like so: Import SomeObject New_insatnce = SomeObject.SomeObject(354) Then I get an error thrown about how I'm not able to assign a str value to attributes which are expecting a mapped instance, presumably a relationship. Am I thinking straight here? Or does SQLAlchemy have a separate method for creating new clean instances of its objects? Cheers, 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] Row order is not updated - session persistance problem?
Hi, I'm a PHP/SQL coder, recently moved to Python and SQLAlchemy - really enjoying it so far. However, I'm having a problem as follows: I have tables for Pages and Sections (Pages have many Sections) I have working mappers for both, and sections are ordered by a Position column I am updating the Position column using something like the following: conn.execute(sections.update(sections.c.id == id), position = new_position) If I do this, my ordering and positions are confused and not displayed correctly. If I stop my application and restart it, everything is fine. I think that I may not be dealing with my Session properly - I create a session in a module called db, and refer to is from my controllers. Do I have to close or remove this session when a controller is done in order to have it refresh on the next request? Thanks for your time Joe --~--~-~--~~~---~--~~ 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: Row order is not updated - session persistance problem?
see about session.expire() / session.refresh(), maybe that's what u need? On Wednesday 16 July 2008 16:43:06 joelanman wrote: Hi, I'm a PHP/SQL coder, recently moved to Python and SQLAlchemy - really enjoying it so far. However, I'm having a problem as follows: I have tables for Pages and Sections (Pages have many Sections) I have working mappers for both, and sections are ordered by a Position column I am updating the Position column using something like the following: conn.execute(sections.update(sections.c.id == id), position = new_position) If I do this, my ordering and positions are confused and not displayed correctly. If I stop my application and restart it, everything is fine. I think that I may not be dealing with my Session properly - I create a session in a module called db, and refer to is from my controllers. Do I have to close or remove this session when a controller is done in order to have it refresh on the next request? Thanks for your time Joe --~--~-~--~~~---~--~~ 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: Load capabilities with default pool_size and max_overflow
On Jul 16, 2008, at 1:32 AM, Fotinakis wrote: Hello SQLAlchemists, What is (or what do you think is) the load that SQLAlchemy can handle with the default engine options of pool_size=5 and max_overflow=10? The application I'm working on has the potential for bursts of thousands of requests in a few seconds, so I am concerned about load. the biggest issue on your mind then should be how many concurrent requests your system would be expected to handle. The connection pool generally needs to be sized according to this. Is it appropriate to increase these values to some arbitrary number? I see that you can set max_overflow to -1 so that it creates as many connections as needed, but do you think that would be necessary (or bad practice)? -1 is probably not a great idea since the database itself has a max number of connections configured, not to mention your app server has only a finite amount of memory in which to handle connections. you'd want to do some memory analysis and see how much memory a single connection takes up. --~--~-~--~~~---~--~~ 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: Row order is not updated - session persistance problem?
On Jul 16, 2008, at 9:43 AM, joelanman wrote: Hi, I'm a PHP/SQL coder, recently moved to Python and SQLAlchemy - really enjoying it so far. However, I'm having a problem as follows: I have tables for Pages and Sections (Pages have many Sections) I have working mappers for both, and sections are ordered by a Position column I am updating the Position column using something like the following: conn.execute(sections.update(sections.c.id == id), position = new_position) If I do this, my ordering and positions are confused and not displayed correctly. If I stop my application and restart it, everything is fine. I think that I may not be dealing with my Session properly - I create a session in a module called db, and refer to is from my controllers. Do I have to close or remove this session when a controller is done in order to have it refresh on the next request? if you execute something on a connection, the Session is not aware of those changes unless it's expired. Also, if the Session is in a transaction, and the database you're using supports transaction isolation, you also may need to rollback or commit the Session's current transaction for it to be able to see data from other transactions. One way to eliminate the latter issue is to execute your SQL statement using the Session's own transaction, which can be via Session.execute() or Session.connection().execute(). --~--~-~--~~~---~--~~ 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] Joined Query
Afternoon Chaps, I've got a query here which I've been looking to reconstruct from the standard SQL into a SQLAlchemy statement which will return a list of objects but I'm really struggling to make any headway on it, I'm hoping you'll be able to offer me some help. I have two objects in my application, 'event' and 'message' and they have a M21 relationship defined between them in the event class using declarative. Below is the standard SQL for the query in question: SELECT message.message_id FROM event INNER JOIN message ON event.message_id = message.message_id WHERE CURRENT_DATE = Date_Started AND CURRENT_DATE = COALESCE(date_ended,CURRENT_DATE) AND (Is_All_Day = 1 OR CURRENT_TIME BETWEEN Time_Started AND Time_Ended) AND ( Repeat_Type = 0 OR Repeat_Type = 1 OR Repeat_Type = 2 AND MOD( TO_DAYS(CURRENT_DATE) - TO_DAYS(Date_Started),7) = 0 OR Repeat_Type = 3 AND MOD( TO_DAYS(CURRENT_DATE) - TO_DAYS(Date_Started),14) = 0 OR Repeat_Type = 4 AND DAYOFMONTH(CURRENT_DATE) = DAYOFMONTH(Date_Started) OR Repeat_Type = 5 AND DAYOFYEAR(CURRENT_DATE) = DAYOFYEAR(Date_Started) OR Repeat_Type = 6 AND DAYOFWEEK(CURRENT_DATE) IN (2,3,4,5,6) OR Repeat_Type = 7 AND DAYOFWEEK(CURRENT_DATE) IN (1,7) ) AND NOT EXISTS (SELECT 1 FROM event_exempt WHERE event_id = event.event_ID AND event_date = CURRENT_DATE) The standard SQL there just returns the message.message_id, but obviously, now we're using an ORM I'm looking to adapt this so that it returns a list of 'message' objects to me. Can anyone offer some sound advice and help on this? I've been playing around with this using query().join() but keep hitting up against all kinds of brick walls as this is all so new to me. Thanks guys, I really appreciate the help you've been putting forward the past few days. 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: Injecting business objects into constructor
Are you aware of any IoC frameworks which have been adapted to inject/autowire things into SQLAlchemy transient business objects? There was some talk a few months ago about integration of SA with the Trellis component of PEAK, which I think was one of the primary motivators for the user defined state branch that eventually became SA 0.5.0. ...But since then I haven't heard much on the lists about it, and I don't know if that came to fruition or not. Mike can answer this best. --~--~-~--~~~---~--~~ 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: Injecting business objects into constructor
On Jul 16, 2008, at 6:48 AM, Heston James - Cold Beans wrote: Are you aware of any IoC frameworks which have been adapted to inject/autowire things into SQLAlchemy transient business objects? theres some experiments in IoC for Python if you google around for dependency injection python, but the Python way is usually focused around not really needing thick layers of abstraction like 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Injecting business objects into constructor
Hi Michael, theres some experiments in IoC for Python if you google around for dependency injection python, but the Python way is usually focused around not really needing thick layers of abstraction like that. Thanks for that. I did do some googling around a while back when first starting out with python and found it was slightly slim pickings, if this isn't really the 'pytonic' way of doing things then that would likely explain why :-) It's no great challenge to me at the moment so I'll find some other more proven methods to get my services injected. Thanks, 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: Row order is not updated - session persistance problem?
Thanks for the responses - If I create a new session for each controller and run session.close() at the end, it seem to work properly. --~--~-~--~~~---~--~~ 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: OperationalError: (OperationalError) cannot commit transaction - SQL statements in progress
On Jul 16, 2008, at 5:13 AM, Manlio Perillo wrote: Hi. I'm having problems with the exception in subject, with pysqlite (on Debian Lenny). Unfortunately, I'm unable to reproduce the problem, but basically it is an update statement in a transaction. If there is only one row in the table, all is ok; but if there are more then one rows, I get this exception. If I catch the exception and execute the transaction again, it finally succeed. mmm, im drawing a blank on this one. the error often indicates concurrent access on the cursor, or continuing on a cursor where an exception was raised and some issue was not resolved. try to get more detail out of it, perhaps check that your installed version of pysqlite is up to date. --~--~-~--~~~---~--~~ 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] Data Inheritance
Hi, I'm planning to implement Data inheritance for an os project i'm working on [1]. I have a model with a few tables and relationships between them ( not a complicated stuff ) and i was wandering if there is a way to accomplish data inheritance in an automated way ( i can eventually make a script to accomplish this ) I mind, given a Parent id, I'd like to copy it and get all child copied and modified too. Does it possible ? if not, i will be manually doing it.. just making the whole model introspection by hand.. ( grr ) Any light on it would by great ! ( I'm having problems to explain on English what I'm trying to do. sorry about it) 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] subclassing Table
Hi, I am not a professional coder; hobby-like thing. I would like to encapsulate my table definitions in a new class: class MyTable( Table): def __init__( self, metadata): Table.__init__( self, my_table_name, metadata, col1, col2...) metadata = MetaData() table = MyTable( metadata) Traceback (most recent call last): File create_tables.py, line 11, in module table = MyTable( metadata) TypeError: __call__() takes at least 3 arguments (2 given) *** I tested different things and I have the feeling that it is not possible to subclass the Table class. Is this true? If no: what is the mistake I make? If yes: why? does Table class have some special decoration or something like that? How do you avoid to define your table in every script you write to use that table with its corresponding class? Thanks for your help, tamas --~--~-~--~~~---~--~~ 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: session.dirty but not session.is_modified....
Thanks. In fact I use session.is_modified() but I thought it was just a workaround to cope with something I didnt' thoroughly understand... 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Problems with query of single column in a table
Hello, I'm using Elixir with SQLAlchemy, and I'm having trouble with querying a single column in the database. Here is my class and the error that it throws up when I access a column: import elixir from sqlalchemy import orm, create_engine, MetaData from sqlalchemy.orm import scoped_session, sessionmaker from sqlalchemy.types import * class dateTest(elixir.Entity): UserID = elixir.Field(elixir.Integer, primary_key=True, autoincrement=True) Date1 = elixir.Field(elixir.TIMESTAMP(timezone=True)) Date2 = elixir.Field(elixir.DateTime) def __init__(self, uId = None, date1 = None, date2 = None): self.UserID = uId self.Date1 = date1 self.Date2 = date2 def __repr__(self): return '%s %s %s' %(repr(self.UserID), self.Date1, self.Date2) elixir.session.query(dateTest.Date1).all() Traceback (most recent call last): File stdin, line 1, in ? File d:\python24\lib\site-packages\sqlalchemy-0.4.6-py2.4.egg \sqlalchemy\orm\scoping.py, line 98 , in do return getattr(self.registry(), name)(*args, **kwargs) File d:\python24\lib\site-packages\sqlalchemy-0.4.6-py2.4.egg \sqlalchemy\orm\session.py, line 76 0, in query q = self._query_cls(mapper_or_class, self, **kwargs) File d:\python24\lib\site-packages\sqlalchemy-0.4.6-py2.4.egg \sqlalchemy\orm\query.py, line 68, in __init__ self.__init_mapper(_class_to_mapper(class_or_mapper, entity_name=entity_name)) File d:\python24\lib\site-packages\sqlalchemy-0.4.6-py2.4.egg \sqlalchemy\orm\util.py, line 399, in _class_to_mapper return class_or_mapper.compile() AttributeError: 'InstrumentedAttribute' object has no attribute 'compile' When I query for the entire object, I can get it without any problems: elixir.session.query(dateTest).all() 2008-07-16 16:06:12,010 INFO sqlalchemy.engine.base.Engine.0x..10 SELECT datetest_datetest.UserID AS datetest_datetest_UserID, datetest_datetest.Date1 AS datetest_datetest_Date1, datetest_date test.Date2 AS datetest_datetest_Date2 FROM datetest_datetest ORDER BY datetest_datetest.oid 2008-07-16 16:06:12,010 INFO sqlalchemy.engine.base.Engine.0x..10 [] [1 2008-07-16 14:17:22 None, 2 2008-07-16 14:19:24 2008-07-16 14:19:24, 3 2008-07-16 14:19:27 2 008-07-16 14:19:27, 4 2008-07-16 14:19:29 2008-07-16 14:19:29, 5 2008-07-16 15:03:04 2008-07-16 15:03:04, 6 2008-07-16 15:03:07 2008-07-16 15:03:07, 7 2008/07/16 15:03:09.390 GMT-7 2008/07/16 15:03:09.390 GMT-7, 8 2008/07/16 15:03:11.315 GMT-7 2008/07/16 15:03:11.315 GMT-7, 100 2008-07-1 6 00:00:00 2008-07-17 15:07:10, 101 2008/07/16 16:04:28.346 GMT-7 2008/07/16 16:04:28.346 GMT-7, 102 2008/07/16 16:04:32.681 GMT-7 2008/07/16 16:04:32.681 GMT-7] Any ideas what could be wrong with a query to get a single column from the database? Your help will be appreciated. thanks, Venkatesh. --~--~-~--~~~---~--~~ 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: Problems with query of single column in a table
Venkatesh wrote: Hello, I'm using Elixir with SQLAlchemy, and I'm having trouble with querying a single column in the database. Here is my class and the error that it throws up when I access a column: import elixir from sqlalchemy import orm, create_engine, MetaData from sqlalchemy.orm import scoped_session, sessionmaker from sqlalchemy.types import * class dateTest(elixir.Entity): UserID= elixir.Field(elixir.Integer, primary_key=True, autoincrement=True) Date1 = elixir.Field(elixir.TIMESTAMP(timezone=True)) Date2 = elixir.Field(elixir.DateTime) def __init__(self, uId = None, date1 = None, date2 = None): self.UserID = uId self.Date1 = date1 self.Date2 = date2 def __repr__(self): return '%s %s %s' %(repr(self.UserID), self.Date1, self.Date2) elixir.session.query(dateTest.Date1).all() Traceback (most recent call last): File stdin, line 1, in ? File d:\python24\lib\site-packages\sqlalchemy-0.4.6-py2.4.egg \sqlalchemy\orm\scoping.py, line 98 , in do return getattr(self.registry(), name)(*args, **kwargs) File d:\python24\lib\site-packages\sqlalchemy-0.4.6-py2.4.egg \sqlalchemy\orm\session.py, line 76 0, in query q = self._query_cls(mapper_or_class, self, **kwargs) File d:\python24\lib\site-packages\sqlalchemy-0.4.6-py2.4.egg \sqlalchemy\orm\query.py, line 68, in __init__ self.__init_mapper(_class_to_mapper(class_or_mapper, entity_name=entity_name)) File d:\python24\lib\site-packages\sqlalchemy-0.4.6-py2.4.egg \sqlalchemy\orm\util.py, line 399, in _class_to_mapper return class_or_mapper.compile() AttributeError: 'InstrumentedAttribute' object has no attribute 'compile' When I query for the entire object, I can get it without any problems: elixir.session.query(dateTest).all() 2008-07-16 16:06:12,010 INFO sqlalchemy.engine.base.Engine.0x..10 SELECT datetest_datetest.UserID AS datetest_datetest_UserID, datetest_datetest.Date1 AS datetest_datetest_Date1, datetest_date test.Date2 AS datetest_datetest_Date2 FROM datetest_datetest ORDER BY datetest_datetest.oid 2008-07-16 16:06:12,010 INFO sqlalchemy.engine.base.Engine.0x..10 [] [1 2008-07-16 14:17:22 None, 2 2008-07-16 14:19:24 2008-07-16 14:19:24, 3 2008-07-16 14:19:27 2 008-07-16 14:19:27, 4 2008-07-16 14:19:29 2008-07-16 14:19:29, 5 2008-07-16 15:03:04 2008-07-16 15:03:04, 6 2008-07-16 15:03:07 2008-07-16 15:03:07, 7 2008/07/16 15:03:09.390 GMT-7 2008/07/16 15:03:09.390 GMT-7, 8 2008/07/16 15:03:11.315 GMT-7 2008/07/16 15:03:11.315 GMT-7, 100 2008-07-1 6 00:00:00 2008-07-17 15:07:10, 101 2008/07/16 16:04:28.346 GMT-7 2008/07/16 16:04:28.346 GMT-7, 102 2008/07/16 16:04:32.681 GMT-7 2008/07/16 16:04:32.681 GMT-7] Any ideas what could be wrong with a query to get a single column from the database? Columns and scalars via .query() is a SQLAlchemy 0.5 feature. 0.4 doesn't support that usage. Cheers, Jason --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---