[sqlalchemy] Re: Oracle timestamp and postgres datetime compatibility
Indeed was a fault of mine. I haven't noticed that, in my code, before assigning the value I converted the datetime.datetime.now() to string. So the backend tries to assign a string, and not a date. With postgres it dosn't matter (if the client and the server has the same localization...) because of its auto-convert feature, but with oracle it matters. Now I assign the right object and it works. Sorry for the mistake. -- 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 change a database
On Dec 3, 2009, at 13:37 , Peter wrote: Lets suppose I created an engine on database 'foo' and I want to create a database 'bar' and then do my work on 'bar'. What is the recommended way to do this ? Establish a new connection to bar. -- Alex Brasetvik -- 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 change a database
chaouche yacine wrote: Why not create a different engine for that database ? --- On Thu, 12/3/09, Peter vm...@mycircuit.org wrote: Thanks a lot, I guess I still have to abstract away my standard sql behavior .. Peter -- 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: how to change a database
As far as the creation I'm no help, but I have done something similar by connecting to different schemas in oracle. By setting the schema argument on your table objects, you can bind them to a particular database(schema), by changing the value of the schema argument, you can switch from one database to another. I normally have a table initializer method that I can pass the schema argument to to handle this functionality. On Dec 3, 4:37 am, Peter vm...@mycircuit.org wrote: Hi Lets suppose I created an engine on database 'foo' and I want to create a database 'bar' and then do my work on 'bar'. What is the recommended way to do this ? connection.execute('CREATE DATABASE IF NOT EXISTS bar') connection.execute('USE bar') The former command succeeds with a warning ( already discussed on this list ) but the latter seems to be the wrong approach: ... 2009-12-03 13:28:39,221 INFO sqlalchemy.engine.base.Engine.0x...b0ec COMMIT TypeError: 'NoneType' object is not callable in function lambda at 0x8821bc4 ignored Thanks a lot for your advice Peter -- 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] FlushError: instance is in unsaved, pending instance...
Is the only solution to attach an instance (u.job = myjob) or is there another solution that doesn't require me to build the instance? if you want SQLA's delete-orphan capability, that's the only way. If you want to rely upon CASCADE rules in your DB to handle it instead, that's another way to go. thanks, and really... managing in the db is such a simple thing... Is there a why to find out the related class (that one u.job should be instance of) so that I can issue a query on that? sandro *:-) -- 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] FlushError: instance is in unsaved, pending instance...
On Dec 4, 2009, at 1:18 PM, Alessandro Dentella wrote: Is the only solution to attach an instance (u.job = myjob) or is there another solution that doesn't require me to build the instance? if you want SQLA's delete-orphan capability, that's the only way. If you want to rely upon CASCADE rules in your DB to handle it instead, that's another way to go. thanks, and really... managing in the db is such a simple thing... Is there a why to find out the related class (that one u.job should be instance of) so that I can issue a query on that? err, given what to start with ? sandro *:-) -- 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] FlushError: instance is in unsaved, pending instance...
On Fri, Dec 04, 2009 at 01:27:46PM -0500, Michael Bayer wrote: On Dec 4, 2009, at 1:18 PM, Alessandro Dentella wrote: Is the only solution to attach an instance (u.job = myjob) or is there another solution that doesn't require me to build the instance? if you want SQLA's delete-orphan capability, that's the only way. If you want to rely upon CASCADE rules in your DB to handle it instead, that's another way to go. thanks, and really... managing in the db is such a simple thing... Is there a why to find out the related class (that one u.job should be instance of) so that I can issue a query on that? err, given what to start with ? ops. Let's say starting from the class and the instance. class Project(Base): __tablename__ = project id = Column(Integer, primary_key=True) name = Column(String(30), nullable=False) class Delivery(Base): __tablename__ = 'delivery' id= Column(Integer, primary_key=True) project_id= Column(ForeignKey(Project.id), nullable=False) project = orm.relation('Project', backref=orm.backref('deliveries', cascade=all, delete-orphan, lazy=False)) sess = session() p = Project() d = Delivery() d.project_id = p.id # now I want to create automatically the instance 'p' having just * the value 'p.id' * d * the name of the attribute (that is a ForeignKey) project_id Since I need to issue: p = sess.query(Project).get(p.id) is there a way to get Project (the class) from d and 'project_id' I hope now it's a little bit clearer sandro *:-) -- Sandro Dentella *:-) http://sqlkit.argolinux.orgSQLkit home page - PyGTK/python/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.
Re: [sqlalchemy] FlushError: instance is in unsaved, pending instance...
On Dec 4, 2009, at 2:20 PM, Alessandro Dentella wrote: On Fri, Dec 04, 2009 at 01:27:46PM -0500, Michael Bayer wrote: On Dec 4, 2009, at 1:18 PM, Alessandro Dentella wrote: Is the only solution to attach an instance (u.job = myjob) or is there another solution that doesn't require me to build the instance? if you want SQLA's delete-orphan capability, that's the only way. If you want to rely upon CASCADE rules in your DB to handle it instead, that's another way to go. thanks, and really... managing in the db is such a simple thing... Is there a why to find out the related class (that one u.job should be instance of) so that I can issue a query on that? err, given what to start with ? ops. Let's say starting from the class and the instance. class Project(Base): __tablename__ = project id = Column(Integer, primary_key=True) name = Column(String(30), nullable=False) class Delivery(Base): __tablename__ = 'delivery' id= Column(Integer, primary_key=True) project_id= Column(ForeignKey(Project.id), nullable=False) project = orm.relation('Project', backref=orm.backref('deliveries', cascade=all, delete-orphan, lazy=False)) sess = session() p = Project() d = Delivery() d.project_id = p.id # now I want to create automatically the instance 'p' having just * the value 'p.id' * d * the name of the attribute (that is a ForeignKey) project_id well what you'd need here is the name project, pull that attribute off of d's mapper and figure it out from there.you see this is why SQLA doesn't know what to do with your d.project_id and why we don't get into attaching rules to foreign key identifiers. Its only a target during the flush, and a value inside a SQL expression that is populated during a lazy load. it could just as well be associated with multiple relations() attached to your Delivery class, and if the mapping is really exotic those relations could even be loading different classes based on the same column attribute - it can be in any number of primaryjoin expressions for example. So if you really only had project_id, and you want to assume its only used in one relation() on d, this is what you'd have to do: # get parent mapper mapper = object_mapper(d) # convert from attribute to actual column column = mapper.get_property('project_id').columns[0] # search through all properties for prop in mapper.iterate_properties: # search through local=remote pairs for that prop (usually just one tuple) if hasattr(prop, 'local_remote_pairs'): for local, remote in prop.local_remote_pairs: if local is column: result = remote break else: result = None if result is not None: target_class = prop.mapper.class_ # get the attribute name for the remote column. usually this # is column.key, but this is a more complete check in case # columns have been custom mapped. attr_name = prop.mapper._get_col_to_prop(result).key break else: target_class = attr_name = None if target_class: sess.query(target_class).filter_by(**{attr_name:d.project_id}) This is what comes to mind just without thinking too deeply. If I can think of a simpler way to do it, I'll let you know. You're basically looking for a specific ORM feature without actually using the ORM's normal API, which is why this isn't covered. Since I need to issue: p = sess.query(Project).get(p.id) is there a way to get Project (the class) from d and 'project_id' I hope now it's a little bit clearer sandro *:-) -- Sandro Dentella *:-) http://sqlkit.argolinux.orgSQLkit home page - PyGTK/python/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.
[sqlalchemy] pyodbc ini file
Hi All - I'm playing around with pyodbc (using unixodbc) support in trunk - I was wondering if there is any way to bypass the additional system-wide odbc.ini settings file to create connections. Is there a way to simply pass in all the connection parameters via create_engine(...) that would normally be specified with the ini file? Thanks, Bo -- 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.