[sqlalchemy] Dynamic query
Hello, any idea why with # Query class BaseQuery(orm.Query): @dynamic def method_a(self): ... def method_b(self): ... class FooQuery(BaseQuery): ... class BarQuery(FooQuery): @dynamic def method_c(self): ... # Models class BaseModel(object): query = Session.query_property(BaseQuery) # myQuery = type('PolymorphicQuery, (content.BaseQuery, ), func_list)(BaseModel) where func_list containing all the functions decorated by @dynamic the following fail? : - myQuery.get(45) fails with: AttributeError: 'NoneType' object has no attribute 'identity_map' - myQuery.method_a().all() fails with: AttributeError: 'NoneType' object has no attribute '_autoflush' - etc My goal is to be able to build a custom Query object to use with the .with_polymorphic() function .. Thanks, Julien -- No trees were killed in the creation of this message. However, many electrons were terribly inconvenienced. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@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. attachment: jcigar.vcf
[sqlalchemy] Very strange behaviour in SqlAlchemy (maybe a bug)
Hello, I actually try to migrate to SqlAlchemy 0.6.4 (before i was in 0.5.2) One of my query seems to not work properly in this new version It seems to be a bug in Sql Alchemy because of this part of my query *model.Collaborateur.LesIns.any(model.or_(model.Instruction.FinValiditetime.time(), model.Instruction.FinValidite==None))* All the field which are after this part seems to be corrupted the n+1 field seems to return the result of the n field n+2 field return the result of n+1 field... s = model.session.query(model.Collaborateur.IdCollaborateur, model.Collaborateur.Nom, model.Collaborateur.Prenom, model.Collaborateur.Type, model.Collaborateur.Civilite, model.Collaborateur.Titre, model.Collaborateur.Inactif, model.Collaborateur.MotCle, model.Collaborateur.IdProfilIca , model.Collaborateur.Responsable, model.Collaborateur.LesIns.any(model.or_(model.Instruction.FinValiditetime.time(), model.Instruction.FinValidite==None)), model.Collaborateur.TypeEnvoi, model.Collaborateur.Fonction ) s = s.filter(model.Collaborateur.IdDossier==983) # On commence par extraire de la bdd les collaborateurs qui font partie du dossier for e in s: print Fonction, e.Fonction, TypeEnvoi, e.TypeEnvoi All works better when i put the green part at the end of the query (after the red part) but i wonder why it works before in 0.5.2 and not in 0.6.4??? Thx Chris -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@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] Self-referencing relation
Hi Using SQLAlchemy 0.5.8. I have the following model... class Link(DeclarativeBase): __tablename__ = 'link' linkId = Column(Integer, autoincrement=True, primary_key=True) name = Column(Unicode(50), nullable=False) parentLinkId = Column(Integer, ForeignKey('link.linkId')) url = Column(Unicode(255)) permissionId = Column(Integer, ForeignKey('tg_permission.permission_id')) description = Column(Text()) parentLink = relation(Link, primaryjoin=parentLinkId==Link.linkId) permission = relation(Permission, primaryjoin=permissionId==Permission.permission_id) The problem is with the second to the last line. I'm trying to create a relation to point to the parent link, which points back to the same table. I'm using TurboGears and when I try to start my server I get the following error: parentLink = relation(Link, primaryjoin=parentLinkId==Link.linkId) NameError: name 'Link' is not defined I'm new to SA. Can someone help me out with this relation? -Jim -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@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.
Re: [sqlalchemy] Self-referencing relation
On 10/12/2010 09:20 AM, Jim Steil wrote: Hi Using SQLAlchemy 0.5.8. I have the following model... class Link(DeclarativeBase): __tablename__ = 'link' linkId = Column(Integer, autoincrement=True, primary_key=True) name = Column(Unicode(50), nullable=False) parentLinkId = Column(Integer, ForeignKey('link.linkId')) url = Column(Unicode(255)) permissionId = Column(Integer, ForeignKey('tg_permission.permission_id')) description = Column(Text()) parentLink = relation(Link, primaryjoin=parentLinkId==Link.linkId) permission = relation(Permission, primaryjoin=permissionId==Permission.permission_id) The problem is with the second to the last line. I'm trying to create a relation to point to the parent link, which points back to the same table. I'm using TurboGears and when I try to start my server I get the following error: parentLink = relation(Link, primaryjoin=parentLinkId==Link.linkId) NameError: name 'Link' is not defined I'm new to SA. Can someone help me out with this relation? Due to Python semantics, Link is not bound to anything until the class definition is complete. The get around this, SQLAlchemy provides several options: 1. In this case, you can simply use parentLinkId==linkId as the primaryjoin. 2. You can wrap the primaryjoin in a function/lambda, e.g. primaryjoin=lambda: Link.parentLinkId==Link.LinkId. SQLAlchemy will call this function sometime after the class definition is complete, at which point Link is bound to something. 3. You can use a string as the primaryjoin, e.g. primaryjoin=Link.parentLinkId==Link.linkId. SQLAlchemy will evaluate this expression similar to option #2. In any case, you need to include a remote_side argument to the relation to indicate that this is the many-to-one side of the relationship[1], e.g. parentLink = relation(Link, primaryjoin=lambda: Link.parentLinkId==Link.linkId, remote_side=lambda: [Link.linkId]) -Conor [1]: http://www.sqlalchemy.org/docs/orm/relationships.html?highlight=remote_side#adjacency-list-relationships -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@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] Using SQLAlchemy with Oracle DRCP
Hi, I've written a connection pool for SQLAlchemy using Oracle's Database Resident Connection Pool. It has been tested with SQLAlchemy 0.5.8 and Oracle 11g. If you're interested, have a look at https://bitbucket.org/karlb/drcppool/src - Karl -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@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.
Re: [sqlalchemy] Very strange behaviour in SqlAlchemy (maybe a bug)
On Oct 12, 2010, at 7:58 AM, Christian Démolis wrote: Hello, I actually try to migrate to SqlAlchemy 0.6.4 (before i was in 0.5.2) One of my query seems to not work properly in this new version It seems to be a bug in Sql Alchemy because of this part of my query model.Collaborateur.LesIns.any(model.or_(model.Instruction.FinValiditetime.time(), model.Instruction.FinValidite==None)) All the field which are after this part seems to be corrupted the n+1 field seems to return the result of the n field n+2 field return the result of n+1 field... s = model.session.query(model.Collaborateur.IdCollaborateur, model.Collaborateur.Nom, model.Collaborateur.Prenom, model.Collaborateur.Type, model.Collaborateur.Civilite, model.Collaborateur.Titre, model.Collaborateur.Inactif, model.Collaborateur.MotCle, model.Collaborateur.IdProfilIca , model.Collaborateur.Responsable, model.Collaborateur.LesIns.any(model.or_(model.Instruction.FinValiditetime.time(), model.Instruction.FinValidite==None)), model.Collaborateur.TypeEnvoi, model.Collaborateur.Fonction ) s = s.filter(model.Collaborateur.IdDossier==983) # On commence par extraire de la bdd les collaborateurs qui font partie du dossier for e in s: print Fonction, e.Fonction, TypeEnvoi, e.TypeEnvoi All works better when i put the green part at the end of the query (after the red part) but i wonder why it works before in 0.5.2 and not in 0.6.4??? cant do much here without an illustration of the SQL that's generated, and most helpfully some runnable code that reproduces the issue. If the SQL itself is misformed, creating the offending query and calling str(q) is sufficient to demonstrate. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@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.
Re: [sqlalchemy] Dynamic query
On Oct 12, 2010, at 7:39 AM, Julien Cigar wrote: Hello, any idea why with # Query class BaseQuery(orm.Query): @dynamic def method_a(self): ... def method_b(self): ... class FooQuery(BaseQuery): ... class BarQuery(FooQuery): @dynamic def method_c(self): ... # Models class BaseModel(object): query = Session.query_property(BaseQuery) # myQuery = type('PolymorphicQuery, (content.BaseQuery, ), func_list)(BaseModel) where func_list containing all the functions decorated by @dynamic the following fail? : - myQuery.get(45) fails with: AttributeError: 'NoneType' object has no attribute 'identity_map' - myQuery.method_a().all() fails with: AttributeError: 'NoneType' object has no attribute '_autoflush' - etc My goal is to be able to build a custom Query object to use with the .with_polymorphic() function .. I've just grepped through all the source, examples and tests plus the wiki trying to find what @dynamic is. Seems like something I'd have come up with in the past but I've no clue at the moment what that is. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@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.
Re: [sqlalchemy] Dynamic query
On 10/12/2010 17:09, Michael Bayer wrote: On Oct 12, 2010, at 7:39 AM, Julien Cigar wrote: Hello, any idea why with # Query class BaseQuery(orm.Query): @dynamic def method_a(self): ... def method_b(self): ... class FooQuery(BaseQuery): ... class BarQuery(FooQuery): @dynamic def method_c(self): ... # Models class BaseModel(object): query = Session.query_property(BaseQuery) # myQuery = type('PolymorphicQuery, (content.BaseQuery, ), func_list)(BaseModel) where func_list containing all the functions decorated by @dynamic the following fail? : - myQuery.get(45) fails with: AttributeError: 'NoneType' object has no attribute 'identity_map' - myQuery.method_a().all() fails with: AttributeError: 'NoneType' object has no attribute '_autoflush' - etc My goal is to be able to build a custom Query object to use with the .with_polymorphic() function .. I've just grepped through all the source, examples and tests plus the wiki trying to find what @dynamic is. Seems like something I'd have come up with in the past but I've no clue at the moment what that is. Sorry, I forgot to mention that it's just a custom decorator of mine which add the function name to a list ... forget about it, it's just to build the third argument of type() (func_list in my case) -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@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. attachment: jcigar.vcf
Re: [sqlalchemy] Self-referencing relation
Thanks, just what I needed. -Jim On 10/12/2010 9:38 AM, Conor wrote: On 10/12/2010 09:20 AM, Jim Steil wrote: Hi Using SQLAlchemy 0.5.8. I have the following model... class Link(DeclarativeBase): __tablename__ = 'link' linkId = Column(Integer, autoincrement=True, primary_key=True) name = Column(Unicode(50), nullable=False) parentLinkId = Column(Integer, ForeignKey('link.linkId')) url = Column(Unicode(255)) permissionId = Column(Integer, ForeignKey('tg_permission.permission_id')) description = Column(Text()) parentLink = relation(Link, primaryjoin=parentLinkId==Link.linkId) permission = relation(Permission, primaryjoin=permissionId==Permission.permission_id) The problem is with the second to the last line. I'm trying to create a relation to point to the parent link, which points back to the same table. I'm using TurboGears and when I try to start my server I get the following error: parentLink = relation(Link, primaryjoin=parentLinkId==Link.linkId) NameError: name 'Link' is not defined I'm new to SA. Can someone help me out with this relation? Due to Python semantics, Link is not bound to anything until the class definition is complete. The get around this, SQLAlchemy provides several options: 1. In this case, you can simply use parentLinkId==linkId as the primaryjoin. 2. You can wrap the primaryjoin in a function/lambda, e.g. primaryjoin=lambda: Link.parentLinkId==Link.LinkId. SQLAlchemy will call this function sometime after the class definition is complete, at which point Link is bound to something. 3. You can use a string as the primaryjoin, e.g. primaryjoin=Link.parentLinkId==Link.linkId. SQLAlchemy will evaluate this expression similar to option #2. In any case, you need to include a remote_side argument to the relation to indicate that this is the many-to-one side of the relationship[1], e.g. parentLink = relation(Link, primaryjoin=lambda: Link.parentLinkId==Link.linkId, remote_side=lambda: [Link.linkId]) -Conor [1]: http://www.sqlalchemy.org/docs/orm/relationships.html?highlight=remote_side#adjacency-list-relationships -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@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. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@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] extract / PostgreSQL / Birthdays
Database: PostgreSQL 8.4.4 SQLAlchemy: 0.6 I attempting to query the database for contacts with a recent or upcoming birthday. So -- doy = datetime.today().timetuple().tm_yday floor = doy - 2 if (floor 1): floor +=365 ceiling = doy + 14 if (ceiling 365): ceiling -= 365 db.query(Contact).\ filter(func.extract('doy', Contact.birth_date) == doy).all() -- except this fails with -- sqlalchemy.exc.ProgrammingError: (ProgrammingError) syntax error at or near , LINE 3: WHERE extract(E'doy', person.birthday) = 285 ORDER BY object... -- the query should be: SELECT company_id FROM person WHERE extract('doy' from birthday)=285 I assume I'm just missing something. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@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] Reverse look-up of declarative classes
Hi, list, Given all models used the declarative syntax (and I assume they are now all somehow known to the base), and given a class name in string form, can I somehow retrieve the actual class? Regards, -- Branko Vukelić bg.bra...@gmail.com stu...@brankovukelic.com Check out my blog: http://www.brankovukelic.com/ Check out my portfolio: http://www.flickr.com/photos/foxbunny/ Registered Linux user #438078 (http://counter.li.org/) I hang out on identi.ca: http://identi.ca/foxbunny Gimp Brushmakers Guild http://bit.ly/gbg-group -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@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.
Re: [sqlalchemy] extract / PostgreSQL / Birthdays
On Oct 12, 2010, at 1:59 PM, Adam Tauno Williams wrote: Database: PostgreSQL 8.4.4 SQLAlchemy: 0.6 I attempting to query the database for contacts with a recent or upcoming birthday. So -- doy = datetime.today().timetuple().tm_yday floor = doy - 2 if (floor 1): floor +=365 ceiling = doy + 14 if (ceiling 365): ceiling -= 365 db.query(Contact).\ filter(func.extract('doy', Contact.birth_date) == doy).all() -- except this fails with -- sqlalchemy.exc.ProgrammingError: (ProgrammingError) syntax error at or near , LINE 3: WHERE extract(E'doy', person.birthday) = 285 ORDER BY object... -- the query should be: SELECT company_id FROM person WHERE extract('doy' from birthday)=285 I assume I'm just missing something. EXTRACT has a FROM in there so func. is not enough. We have an extract() function by itself that takes care of this: http://www.sqlalchemy.org/docs/core/expression_api.html?highlight=extract#sqlalchemy.sql.expression.extract -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@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. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@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] Checking the availablity of a booked Item
Hello, Here's my simple model (For simplification, consider Face as a Billboard) : +-+ +---+ +--+ |Face |.. |Campaign | ...|TimePeriod| +-+ . +---+ . +--+ |code | . |time_period| |start_time| +-+ . +---+ +--+ |faces | |end_time | +---+ +--+ One way to read this model is : A campaign can book multiple faces during a certain period of time. What I want to do is get all the available Faces for a given period of time, to see what faces can I book for a new campaign that longs for that particular period of time. I would typically have a Face.get_available(time_period) class method that does the job. This method would look for all the faces that don't have an ongoing booking. My question is : how to write such a method ? Here's how I figured it out (couldn't get it to work) : class Face(Entity): using_options(tablename=faces) @classmethod def get_available(self,time_period): Return faces that are not booked (not in any campaign) during the given time_period. # start_date_cond = TimePeriod.start_date time_period.end_date # end_date_cond = TimePeriod.end_datetime_period.start_date # available_periods = Campaign.time_period.has(or_(start_date_cond,end_date_cond)) # unavailable_periods = not(available_periods) # I am pretty sure that the time conditions are good. # Here's a good way to convince yourself (read from bottom to top) : # L1 0--- # L2 --| # L3 0[]-- # L3 represents the desired period (passed as argument) going from [ to ] # place the start date of the booked face anywhere on L2 # place the end date of the booked face anywhere on L1 # of course, end date must be after start date... # Anyway you do it, your face isn't available for the period of time in L3. start_date_cond = TimePeriod.start_date = time_period.end_date end_date_cond = TimePeriod.end_date = time_period.start_date unavailable_periods = Campaign.time_period.has(and_(start_date_cond,end_date_cond)) # I am not sure about what follows... filter_cond = not_(unavailable_periods) join_clause = Campaign.faces return Face.query.filter(filter_cond).outerjoin(join_clause).all() This code returns only faces that have already been booked before or have a future booking, and are free for the moment. But faces with no bookings at all are not returned. This may be due to an incorrect outerjoin ? (I also tried a simple join with no success) Here's the generated sql for one query : 2010-10-12 19:34:22,837 INFO sqlalchemy.engine.base.Engine.0x...f4ec SELECT faces.id AS faces_id FROM campaigns LEFT OUTER JOIN campaigns_faces__faces AS campaigns_faces__faces_1 ON campaigns.id = campaigns_faces__faces_1.campaigns_id LEFT OUTER JOIN faces ON faces.id = campaigns_faces__faces_1.faces_id WHERE NOT (EXISTS (SELECT 1 FROM time_periods WHERE campaigns.time_period_id = time_periods.id AND time_periods.start_date = %(start_date_1)s AND time_periods.end_date = %(end_date_1)s)) 2010-10-12 19:34:22,837 INFO sqlalchemy.engine.base.Engine.0x...f4ec {'start_date_1': datetime.date(2010, 10, 30), 'end_date_1': datetime.date(2010, 10, 20)} [Face id=1 at 0x932218c ] Any help would be very appreciated. Y.Chaouche PS : and please, don't give me that lame it's elixir excuse. The question is about how to construct the proper query for the desired operation in a sqlalchemy way. Elixir is only another Declarative approach + mapping, that's it. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@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. # ORM from sqlalchemy.sql.expression import * from sqlalchemy.ormimport reconstructor from elixirimport * # stdlib from datetime import date import sys class TimePeriod(Entity): using_options(tablename=time_periods) start_date = Field(Date()) end_date = Field(Date()) name = Field(Unicode()) class Campaign(Entity): using_options(tablename=campaigns) time_period = ManyToOne(TimePeriod) faces = ManyToMany(Face) class Face(Entity):
Re: [sqlalchemy] extract / PostgreSQL / Birthdays
On Tue, 2010-10-12 at 14:20 -0400, Michael Bayer wrote: On Oct 12, 2010, at 1:59 PM, Adam Tauno Williams wrote: Database: PostgreSQL 8.4.4 SQLAlchemy: 0.6 I attempting to query the database for contacts with a recent or upcoming birthday. So -- doy = datetime.today().timetuple().tm_yday floor = doy - 2 if (floor 1): floor +=365 ceiling = doy + 14 if (ceiling 365): ceiling -= 365 db.query(Contact).\ filter(func.extract('doy', Contact.birth_date) == doy).all() -- except this fails with -- sqlalchemy.exc.ProgrammingError: (ProgrammingError) syntax error at or near , LINE 3: WHERE extract(E'doy', person.birthday) = 285 ORDER BY object.. -- the query should be: SELECT company_id FROM person WHERE extract('doy' from birthday)=285 I assume I'm just missing something. EXTRACT has a FROM in there so func. is not enough. We have an extract() function by itself that takes care of this: [1] Yep, that was it; I was blurring between funcs and actual expressions. Arg! This works perfectly -- from sqlalchemy import * import sqlalchemy.sql as sql from datetime import datetime current_doy = datetime.today().timetuple().tm_yday floor = current_doy - 2 if (floor 1): floor +=365 ceiling = current_doy + 14 if (ceiling 365): ceiling -= 365 orm_doy = sql.expression.extract('doy', Contact.birth_date) db.query(Contact).\ filter(sql.expression.between(orm_doy, floor, ceiling)).all() [1] http://www.sqlalchemy.org/docs/core/expression_api.html?highlight=extract#sqlalchemy.sql.expression.extract -- Adam Tauno Williams awill...@whitemice.org LPIC-1, Novell CLA http://www.whitemiceconsulting.com OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@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: Reverse look-up of declarative classes
Failing to find any answer, and not understanding the SQLAlchemy code base very well yet, I've resorted to using table names instead of class names. On Tue, Oct 12, 2010 at 8:16 PM, Branko Vukelic bg.bra...@gmail.com wrote: Hi, list, Given all models used the declarative syntax (and I assume they are now all somehow known to the base), and given a class name in string form, can I somehow retrieve the actual class? Regards, -- Branko Vukelić bg.bra...@gmail.com stu...@brankovukelic.com Check out my blog: http://www.brankovukelic.com/ Check out my portfolio: http://www.flickr.com/photos/foxbunny/ Registered Linux user #438078 (http://counter.li.org/) I hang out on identi.ca: http://identi.ca/foxbunny Gimp Brushmakers Guild http://bit.ly/gbg-group -- Branko Vukelić bg.bra...@gmail.com stu...@brankovukelic.com Check out my blog: http://www.brankovukelic.com/ Check out my portfolio: http://www.flickr.com/photos/foxbunny/ Registered Linux user #438078 (http://counter.li.org/) I hang out on identi.ca: http://identi.ca/foxbunny Gimp Brushmakers Guild http://bit.ly/gbg-group -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@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: Reverse look-up of declarative classes
Ok, so here's what I'm trying to do: for col, msg in cols: if not f[col].value == '': stmt = tbl.select(tbl.__getattribute__(col) == f[col].value) res = stmt.execute() if res.fetchone(): f[col].note = msg return f ``cols`` is a list of 2-tuples containing column names and validation error messages. I'm trying to check tables for uniqueness. ``f`` is a subscriptable object whose each property has associated ``value`` property, which in turn contains the value I want to check. The above gives me an UnbountExecutionError exception. What do I need to do to make this work? Or is there a better way of doing this? The reason I am trying to do it like this is I need this to be generic so I can do it for all the models I have without repeating code or messing with circular import issues (Model classes reside in different modules). On Tue, Oct 12, 2010 at 10:00 PM, Branko Vukelic bg.bra...@gmail.com wrote: Failing to find any answer, and not understanding the SQLAlchemy code base very well yet, I've resorted to using table names instead of class names. On Tue, Oct 12, 2010 at 8:16 PM, Branko Vukelic bg.bra...@gmail.com wrote: Hi, list, Given all models used the declarative syntax (and I assume they are now all somehow known to the base), and given a class name in string form, can I somehow retrieve the actual class? Regards, -- Branko Vukelić bg.bra...@gmail.com stu...@brankovukelic.com Check out my blog: http://www.brankovukelic.com/ Check out my portfolio: http://www.flickr.com/photos/foxbunny/ Registered Linux user #438078 (http://counter.li.org/) I hang out on identi.ca: http://identi.ca/foxbunny Gimp Brushmakers Guild http://bit.ly/gbg-group -- Branko Vukelić bg.bra...@gmail.com stu...@brankovukelic.com Check out my blog: http://www.brankovukelic.com/ Check out my portfolio: http://www.flickr.com/photos/foxbunny/ Registered Linux user #438078 (http://counter.li.org/) I hang out on identi.ca: http://identi.ca/foxbunny Gimp Brushmakers Guild http://bit.ly/gbg-group -- Branko Vukelić bg.bra...@gmail.com stu...@brankovukelic.com Check out my blog: http://www.brankovukelic.com/ Check out my portfolio: http://www.flickr.com/photos/foxbunny/ Registered Linux user #438078 (http://counter.li.org/) I hang out on identi.ca: http://identi.ca/foxbunny Gimp Brushmakers Guild http://bit.ly/gbg-group -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@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.
Re: [sqlalchemy] Reverse look-up of declarative classes
On 10/12/2010 01:16 PM, Branko Vukelic wrote: Hi, list, Given all models used the declarative syntax (and I assume they are now all somehow known to the base), and given a class name in string form, can I somehow retrieve the actual class? Regards, The information is available in the declarative base class, via the _decl_class_registry attribute: Base = declarative_base() class MappedClass(Base): __tablename__ = mapped_class id = Column(Integer, primary_key=True) assert Base._decl_class_registry[MappedClass] is MappedClass -Conor -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@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.
Re: [sqlalchemy] Reverse look-up of declarative classes
On Tue, Oct 12, 2010 at 11:02 PM, Conor conor.edward.da...@gmail.com wrote: The information is available in the declarative base class, via the _decl_class_registry attribute: Thank you, Conor! -- Branko Vukelić bg.bra...@gmail.com stu...@brankovukelic.com Check out my blog: http://www.brankovukelic.com/ Check out my portfolio: http://www.flickr.com/photos/foxbunny/ Registered Linux user #438078 (http://counter.li.org/) I hang out on identi.ca: http://identi.ca/foxbunny Gimp Brushmakers Guild http://bit.ly/gbg-group -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@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.