[sqlalchemy] Re: guessing sql joins from object level
Hi, Michael Bayer написа: SA can form joins between tables automatically if the tables express the proper foreign key relationship between each other, and if there is no ambiguity in that relationship; i.e. table A and table B have only one ForeignKeyConstraint (or single ForeignKey) between each other. if you have table A and table B, a join is just: My questions was about the case when you have more then 2 tables (A-B-C-D) related, is this possible too? A.join(B) with regards to integrating those joins with mapper queries, see http://www.sqlalchemy.org/docs/datamapping.myt#datamapping_selectrelations_queryjoins . the main keyword argument to select() here is the from_obj parameter. regards, StefanB --~--~-~--~~~---~--~~ 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: guessing sql joins from object level
a.join(b).join(c).join(d).join(e). just do a little experimentation, it'll reveal a lot. --~--~-~--~~~---~--~~ 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: SA ORM delete efficiency
This is a duplicate mail (due to a recent SMTP problems). Don't reply. DS ml píše v Po 11. 12. 2006 v 23:13 +0100: Hi! I have a little questions about how does the SA work: Example: I borrowed a model from SA documentation example User/Address. My mapper is mapper(Address, addresses_table) mapper(User, users_table, properties = { 'addresses' : relation(Address, cascade=all, delete-orphan) } ) My example code: u = User(a, b) u.addresses.append(Address(1,2,3,4)) u.addresses.append(Address(1,2,3,4)) session.save(u) session.flush() session.clear() print ** u = session.query(User).get_by_user_name(a) session.delete(u) session.flush() Output: --- BEGIN INSERT INTO users (user_name, password) VALUES (?, ?) ['a', 'b'] INSERT INTO addresses (user_id, street, city, state, zip) VALUES (?, ?, ?, ?, ?) [1, '1', '2', '3', '4'] INSERT INTO addresses (user_id, street, city, state, zip) VALUES (?, ?, ?, ?, ?) [1, '1', '2', '3', '4'] COMMIT ** SELECT users.user_name AS users_user_name, users.password AS users_password, users.user_id AS users_user_id FROM users WHERE users.user_name = ? ORDER BY users.oid LIMIT 1 OFFSET 0 ['a'] BEGIN SELECT addresses.city AS addresses_city, addresses.address_id AS addresses_address_id, addresses.user_id AS addresses_user_id, addresses.zip AS addresses_zip, addresses.state AS addresses_state, addresses.street AS addresses_street FROM addresses WHERE ? = addresses.user_id ORDER BY addresses.oid [1] DELETE FROM addresses WHERE addresses.address_id = ? [[1], [2]] DELETE FROM users WHERE users.user_id = ? [1] COMMIT Question about deleting: 1) Why does the SA the second SELECT for addresses to obtain primary keys? Why there is not a direct DELETE FROM addresses WHERE user_id=?? 2) If it is neccessary to do this SELECT, why is the SA selecting all columns? E.g. I will have 1 user with 10 addresses - an idea of selecting all 10 addresses to get their id's is spooky :-) Why is it so or em I missing something? Thank you. David --~--~-~--~~~---~--~~ 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: Again MySQL/unicode - roundtrip failed
On 2006-12-13 22:38, Shannon -jj Behrens wrote: My memory is that MySQLdb recently changed a bunch of stuff and that it was a simple logic bug. You mean, that just the entire logic is reversed? This would explain, why reading is working (from Mike's Mail): def convert_result_value(self, value, dialect): if value is not None and not isinstance(value, unicode): return value.decode(dialect.encoding) else: return value If value is already unicode, then the value is simply handed over (else-part). However, writing goes wrong, because MySQLdb (wrongly) expects an unicode object but gets an utf8 encoded string (if-part): def convert_bind_param(self, value, dialect): if value is not None and isinstance(value, unicode): return value.encode(dialect.encoding) else: return value Am I right? Here's the bug I filed: http://sourceforge.net/tracker/index.php?func=detailaid=1592353grou p_id=22307atid=374932 If I am right, I would add a note to the bug you already filed. Thanks, Stefan -- Start here: www.meretz.de --~--~-~--~~~---~--~~ 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] dump sqlalchemy-mapped object to xml
Greetings, I need to dump a sqlalchemy-mapped object to XML, like it implemented in pyxslt for SQLObject. So, the questions are: 1) how to separate columns and properties from the other mapped object's attributes properly - I need columns, properties and backrefs (surprised, but backrefs work not like mapper's properties). Is there any recommended way to do it, without fear that it will be broken in the future versions of sqlachemy ? 2) how to avoid to load lazy properties of an object? I mean, if in xml dumping code I call something like this: ... return tag + the_mapped_object.lazy_property + /tag ... it potentially may cause to produce tons of selects... --- Thanks, Dmitry --~--~-~--~~~---~--~~ 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: PGBigInteger behaving like Integer
the INTEGER column coming out is a bug, i just checked in 2167 for that. for the SERIAL column i just checked the pg docs and noticed that youre expecting BIGSERIAL, so I put a little conditional in for that in rev 2168. you should now get CREATE TABLE company ( company_id BIGSERIAL NOT NULL, another_bigint BIGINT, PRIMARY KEY (company_id) ) --~--~-~--~~~---~--~~ 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: dump sqlalchemy-mapped object to xml
youd have to map it back to the mapper's list of props. PropertyLoader, which is a certain type of MapperProperty, has a flag is_backref indicating this. getattr(class_mapper(someclass).props[attributename], 'is_backref', False) --~--~-~--~~~---~--~~ 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: Again MySQL/unicode - roundtrip failed
On 12/15/06, Stefan Meretz [EMAIL PROTECTED] wrote: On 2006-12-13 22:38, Shannon -jj Behrens wrote: My memory is that MySQLdb recently changed a bunch of stuff and that it was a simple logic bug. You mean, that just the entire logic is reversed? This would explain, why reading is working (from Mike's Mail): def convert_result_value(self, value, dialect): if value is not None and not isinstance(value, unicode): return value.decode(dialect.encoding) else: return value If value is already unicode, then the value is simply handed over (else-part). However, writing goes wrong, because MySQLdb (wrongly) expects an unicode object but gets an utf8 encoded string (if-part): def convert_bind_param(self, value, dialect): if value is not None and isinstance(value, unicode): return value.encode(dialect.encoding) else: return value Am I right? I can't say with certainty exactly how the code is broken. If you can write a simple, stand-alone test to prove your point, that would indeed be a useful addition to the bug. Remember to use the MySQL client and the hex function to see what's *actually* stored in the database. Here's the bug I filed: http://sourceforge.net/tracker/index.php?func=detailaid=1592353grou p_id=22307atid=374932 If I am right, I would add a note to the bug you already filed. Best Regards, -jj -- http://jjinux.blogspot.com/ --~--~-~--~~~---~--~~ 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: PGBigInteger behaving like Integer
Thanks! Again I am overwhelmed by the excellant response!! sanjay --~--~-~--~~~---~--~~ 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] error on insert multi record
Hi: I'm using SA 2.8. I met a strange error. following is a piece of code: flight.insert().execute(*(_insdict.values())) it run without error. but after runing, some data in flight table is wrong, another is right. So I change the code: for d in _insdict.itervalues(): _flight.insert().execute(d) now, it work well, but it cost too much time. Anyone know what happen about it?? and it would occour in lastest SA version? --~--~-~--~~~---~--~~ 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: error on insert multi record
never seen this issue before. if it persists, post a full test case to the list. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---