[sqlalchemy] sqlalchemy check select query execution time
How check select query execution time using sqlalchemy. -- 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] How can I change manually the value of field with onupdate option ? I would like override onupdate mechanism
Hi, in my project, I use onupdate attribute : foobar_table = Table(FooBar, meta.metadata, ... Column(created, DateTime(), default=datetime.datetime.now), Column(modified, DateTime(), default=datetime.datetime.now, onupdate=datetime.datetime.now), ... ) All work great. However, my project have an importation feature and I need to set original modified field value. To do that, I've try this solution : my_foobar_obj.modifield = datetime.datetime.strptime(source_date_value, '%Y-%m-%d %H:%M:%S') session.commit() = not success, modified field not contain source_date_value but current date Other solution : foobar_table.update().\ where(foobar_table.c.id==my_foobar_obj.id).\ values(modified=datetime.datetime.strptime(source_date_value, '%Y-%m- %d %H:%M:%S')) = not success, modified field not contain source_date_value but current date Have you a tips to manually change modified field value ? Thanks for your help, Stephane -- 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] Storing lists of simple strings
Hi Michael, Am Mittwoch, den 27.10.2010, 13:37 -0400 schrieb Michael Bayer: Configuration is too unwieldy ? Since you're using declarative , just using @declared_attr would give you access to the class: Nice one. I missed classproperty and declared_attr so far. def make_ordered_list(key, pk, type_): @declared_attr def go(cls): class Name(Base): __tablename__ = %s_names % key rel_id = Column(related_id, Integer, ForeignKey(pk), primary_key=True, index=True) position = Column(position, Integer) value = Column(value, type_, primary_key=True) def __init__(self, value): self.value = value private_key = _ + key setattr(cls, key, association_proxy(private_key, value)) Now that's a hefty trick, updating the class when reading the property. I think this should be protected against running twice!? Or does the ORM mapper do this for us? if you wanted to get rid of saying _names, you need to create something that is added after the fact: Yep, or add a placeholder into the class and have the mapper replace it by the real thing. I'll look into that! Thanks for all you support wrt. SQLAlchemy, I am always impressed how you can come up with helpful answers in virtually no time. I tried the Donate button on SA.org so you can have a beer on my expenses :-) Greetings, Torsten -- DYNAmore Gesellschaft fuer Ingenieurdienstleistungen mbH Torsten Landschoff Office Dresden Tel: +49-(0)351-4519587 Fax: +49-(0)351-4519561 mailto:torsten.landsch...@dynamore.de http://www.dynamore.de Registration court: Mannheim, HRB: 109659, based in Karlsruhe, Managing director: Prof. Dr. K. Schweizerhof, Dipl.-Math. U. Franz -- 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] Can't adapt type on a Foreign key
I got a problem with PostGreSQL 8.4 and tables reflection. My metadata object seems to be ok (it has foreign keys, primary keys, every columns and tables). But when I try to associate an object to an another one through a Foreign key, I get : sqlalchemy.exc.ProgrammingError: (ProgrammingError) can't adapt type 'EventParameters' 'INSERT INTO event (. Here, my code : http://nopaste.info/d3d74b436e.html And my database schema : http://nopaste.info/8798dcf247.html What's wrong ? :/ Thank you in advance Fabien -- 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] Can't adapt type on a Foreign key
On 10/28/2010 06:57 AM, Fabien wrote: I got a problem with PostGreSQL 8.4 and tables reflection. My metadata object seems to be ok (it has foreign keys, primary keys, every columns and tables). But when I try to associate an object to an another one through a Foreign key, I get : sqlalchemy.exc.ProgrammingError: (ProgrammingError) can't adapt type 'EventParameters' 'INSERT INTO event (. Here, my code : http://nopaste.info/d3d74b436e.html And my database schema : http://nopaste.info/8798dcf247.html What's wrong ? :/ Thank you in advance Fabien In this line: e.eventparametersid=ep you are assigning an object instance to a column, which is invalid. You need to add a relationship Event.eventparameters that will allow you to assign object instances: mapper(Event, metadata.tables['event'], properties={'eventparameters': relationship(EventParameters)}) [...] e.eventparameters = ep -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] How can I change manually the value of field with onupdate option ? I would like override onupdate mechanism
Not sure on this one, but are you passing a formatted date string? Maybe you should set a datetime object directly and let SA do the string conversion during flush. Alex Sent from my fantastic HTC Hero On Oct 28, 2010 1:41 AM, KLEIN Stéphane klein.steph...@gmail.com wrote: Hi, in my project, I use onupdate attribute : foobar_table = Table(FooBar, meta.metadata, ... Column(created, DateTime(), default=datetime.datetime.now), Column(modified, DateTime(), default=datetime.datetime.now, onupdate=datetime.datetime.now), ... ) All work great. However, my project have an importation feature and I need to set original modified field value. To do that, I've try this solution : my_foobar_obj.modifield = datetime.datetime.strptime(source_date_value, '%Y-%m-%d %H:%M:%S') session.commit() = not success, modified field not contain source_date_value but current date Other solution : foobar_table.update().\ where(foobar_table.c.id==my_foobar_obj.id).\ values(modified=datetime.datetime.strptime(source_date_value, '%Y-%m- %d %H:%M:%S')) = not success, modified field not contain source_date_value but current date Have you a tips to manually change modified field value ? Thanks for your help, Stephane -- 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.comsqlalchemy%2bunsubscr...@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.
Re: [sqlalchemy] sqlalchemy check select query execution time
Easiest way is to turn on logging using timestamps. A more integrative approach: http://www.sqlalchemy.org/trac/wiki/UsageRecipes/Profiling Also see: http://stackoverflow.com/questions/1171166/how-can-i-profile-a-sqlalchemy-powered-application/1175677#1175677 On Oct 28, 2010, at 3:38 AM, sajuptpm wrote: How check select query execution time using sqlalchemy. -- 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.
Re: [sqlalchemy] Storing lists of simple strings
On Oct 28, 2010, at 5:20 AM, Torsten Landschoff wrote: Hi Michael, Am Mittwoch, den 27.10.2010, 13:37 -0400 schrieb Michael Bayer: Configuration is too unwieldy ? Since you're using declarative , just using @declared_attr would give you access to the class: Nice one. I missed classproperty and declared_attr so far. def make_ordered_list(key, pk, type_): @declared_attr def go(cls): class Name(Base): __tablename__ = %s_names % key rel_id = Column(related_id, Integer, ForeignKey(pk), primary_key=True, index=True) position = Column(position, Integer) value = Column(value, type_, primary_key=True) def __init__(self, value): self.value = value private_key = _ + key setattr(cls, key, association_proxy(private_key, value)) Now that's a hefty trick, updating the class when reading the property. I think this should be protected against running twice!? Or does the ORM mapper do this for us? the interpretation of @declared_attr is done by the declarative module, so the metaclass fires up when you create the class, the attributes are scanned including those that are of @declared_attr, at which point they are invoked, and the result is put into the mapping. Then the mapper is constructed which immediately replaces your function with an ORM instrumented attribute. So basically yes its a one shot. -- 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] Storing lists of simple strings
Hi Michael, Am Donnerstag, den 28.10.2010, 11:36 -0400 schrieb Michael Bayer: Then the mapper is constructed which immediately replaces your function with an ORM instrumented attribute. So basically yes its a one shot. Thanks for the clarification. Greetings, Torsten -- DYNAmore Gesellschaft fuer Ingenieurdienstleistungen mbH Torsten Landschoff Office Dresden Tel: +49-(0)351-4519587 Fax: +49-(0)351-4519561 mailto:torsten.landsch...@dynamore.de http://www.dynamore.de Registration court: Mannheim, HRB: 109659, based in Karlsruhe, Managing director: Prof. Dr. K. Schweizerhof, Dipl.-Math. U. Franz -- 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] How can I change manually the value of field with onupdate option ? I would like override onupdate mechanism
I actually have this same issue as well.. I have a field that means the record has been tested. Any updates to the field make tested = False, all except for one other field. However when I updated that field and this field it still gets reset to false.. record.approved=True record.tested=True db.session.commit() record.approved is True record.tested is False -- Thadeus On Thu, Oct 28, 2010 at 10:15 AM, Alexandre Conrad alexandre.con...@gmail.com wrote: Not sure on this one, but are you passing a formatted date string? Maybe you should set a datetime object directly and let SA do the string conversion during flush. Alex Sent from my fantastic HTC Hero On Oct 28, 2010 1:41 AM, KLEIN Stéphane klein.steph...@gmail.com wrote: Hi, in my project, I use onupdate attribute : foobar_table = Table(FooBar, meta.metadata, ... Column(created, DateTime(), default=datetime.datetime.now), Column(modified, DateTime(), default=datetime.datetime.now, onupdate=datetime.datetime.now), ... ) All work great. However, my project have an importation feature and I need to set original modified field value. To do that, I've try this solution : my_foobar_obj.modifield = datetime.datetime.strptime(source_date_value, '%Y-%m-%d %H:%M:%S') session.commit() = not success, modified field not contain source_date_value but current date Other solution : foobar_table.update().\ where(foobar_table.c.id==my_foobar_obj.id).\ values(modified=datetime.datetime.strptime(source_date_value, '%Y-%m- %d %H:%M:%S')) = not success, modified field not contain source_date_value but current date Have you a tips to manually change modified field value ? Thanks for your help, Stephane -- 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.comsqlalchemy%2bunsubscr...@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.comsqlalchemy%2bunsubscr...@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.
Re: [sqlalchemy] How can I change manually the value of field with onupdate option ? I would like override onupdate mechanism
The only way around this is to do two separate commits record.approved = True db.session.commit() record.tested = True db.session.commit() record.approved is True record.tested is True -- Thadeus On Thu, Oct 28, 2010 at 2:22 PM, Thadeus Burgess thade...@thadeusb.comwrote: I actually have this same issue as well.. I have a field that means the record has been tested. Any updates to the field make tested = False, all except for one other field. However when I updated that field and this field it still gets reset to false.. record.approved=True record.tested=True db.session.commit() record.approved is True record.tested is False -- Thadeus On Thu, Oct 28, 2010 at 10:15 AM, Alexandre Conrad alexandre.con...@gmail.com wrote: Not sure on this one, but are you passing a formatted date string? Maybe you should set a datetime object directly and let SA do the string conversion during flush. Alex Sent from my fantastic HTC Hero On Oct 28, 2010 1:41 AM, KLEIN Stéphane klein.steph...@gmail.com wrote: Hi, in my project, I use onupdate attribute : foobar_table = Table(FooBar, meta.metadata, ... Column(created, DateTime(), default=datetime.datetime.now), Column(modified, DateTime(), default=datetime.datetime.now, onupdate=datetime.datetime.now), ... ) All work great. However, my project have an importation feature and I need to set original modified field value. To do that, I've try this solution : my_foobar_obj.modifield = datetime.datetime.strptime(source_date_value, '%Y-%m-%d %H:%M:%S') session.commit() = not success, modified field not contain source_date_value but current date Other solution : foobar_table.update().\ where(foobar_table.c.id==my_foobar_obj.id).\ values(modified=datetime.datetime.strptime(source_date_value, '%Y-%m- %d %H:%M:%S')) = not success, modified field not contain source_date_value but current date Have you a tips to manually change modified field value ? Thanks for your help, Stephane -- 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.comsqlalchemy%2bunsubscr...@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.comsqlalchemy%2bunsubscr...@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.
Re: [sqlalchemy] How can I change manually the value of field with onupdate option ? I would like override onupdate mechanism
again, no reason why that should be the case from an ORM perspective, please provide a succinct and full working test case and I can evaluate what you're doing. On Oct 28, 2010, at 3:24 PM, Thadeus Burgess wrote: The only way around this is to do two separate commits record.approved = True db.session.commit() record.tested = True db.session.commit() record.approved is True record.tested is True -- Thadeus On Thu, Oct 28, 2010 at 2:22 PM, Thadeus Burgess thade...@thadeusb.com wrote: I actually have this same issue as well.. I have a field that means the record has been tested. Any updates to the field make tested = False, all except for one other field. However when I updated that field and this field it still gets reset to false.. record.approved=True record.tested=True db.session.commit() record.approved is True record.tested is False -- Thadeus On Thu, Oct 28, 2010 at 10:15 AM, Alexandre Conrad alexandre.con...@gmail.com wrote: Not sure on this one, but are you passing a formatted date string? Maybe you should set a datetime object directly and let SA do the string conversion during flush. Alex Sent from my fantastic HTC Hero On Oct 28, 2010 1:41 AM, KLEIN Stéphane klein.steph...@gmail.com wrote: Hi, in my project, I use onupdate attribute : foobar_table = Table(FooBar, meta.metadata, ... Column(created, DateTime(), default=datetime.datetime.now), Column(modified, DateTime(), default=datetime.datetime.now, onupdate=datetime.datetime.now), ... ) All work great. However, my project have an importation feature and I need to set original modified field value. To do that, I've try this solution : my_foobar_obj.modifield = datetime.datetime.strptime(source_date_value, '%Y-%m-%d %H:%M:%S') session.commit() = not success, modified field not contain source_date_value but current date Other solution : foobar_table.update().\ where(foobar_table.c.id==my_foobar_obj.id).\ values(modified=datetime.datetime.strptime(source_date_value, '%Y-%m- %d %H:%M:%S')) = not success, modified field not contain source_date_value but current date Have you a tips to manually change modified field value ? Thanks for your help, Stephane -- 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. -- 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] Best way to get data from database
Hey guys, I have a doubt. I need to get the data from the sever twice every time when I load a page, one to render the HTML and another one to get the data for client side (javascript). So I don't know exactly what it's the best way and fastest. I was trying to implement a session object and store the data once using joinedload loading technique. When the data is in the client side, to kill the session object. Another one it's to call the database twice. I don't know which one is faster and better because I don't know if the database or server stores the first call in memory. If so it's not like to call the database twice, right? And if the second choice is better which loading technique (joinedload, eagerload or subqueryload) is better to use. Every call could be a bunch of data. Any help could be really useful. Thanks in advance! -- 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] how to use object_session properly
hello all I want to know how to create Session with object_session which can be used to add data to the database i.e using Session.add_all().So i can pass a list as parameter to add_all as my length of list is of variable length. When i am trying to do that i was not able to associate instance properly and getting Session as None. I already gone through the below link but left with no clue. So please help me with this. http://www.sqlalchemy.org/docs/orm/session.html#sqlalchemy.orm.session.object_session -- 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] how to use object_session properly
On 10/28/2010 08:16 PM, anusha k wrote: hello all I want to know how to create Session with object_session which can be used to add data to the database i.e using Session.add_all().So i can pass a list as parameter to add_all as my length of list is of variable length. When i am trying to do that i was not able to associate instance properly and getting Session as None. I already gone through the below link but left with no clue. So please help me with this. http://www.sqlalchemy.org/docs/orm/session.html#sqlalchemy.orm.session.object_session object_session only works for objects that have already been attached to a session. To add objects to a session, you need to have the session object available beforehand. Usually people do this using a global Session variable that is created from a call to scoped_session(): Session = scoped_session(sessionmaker(some_engine)) [...] Session.add_all([obj1, obj2, obj3]) -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.