[sqlalchemy] How to use regular expression in query the mysql
Dear all, I would like to search in mysql like select * from table1 where column1 regexp patten; How can I do it in alsqlchemy? Thank you Ting --~--~-~--~~~---~--~~ 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: mssql, Linux, unixODBC - Could not locate column in row for column
e = sqlalchemy.create_engine(mssql://xxx:[EMAIL PROTECTED]:1433/xx?driver=TDSodbc_options='TDS_Version=8.0') here is a patch to mssql.py that makes above line work. 805c805,808 connectors.append(keys.pop('odbc_options')) --- odbc_options=keys.pop('odbc_options') if odbc_options[0]==' and odbc_options[-1]==': odbc_options=odbc_options[1:-1] connectors.append(odbc_options) Could you guys add it in to svn. Thanks, Lucas --~--~-~--~~~---~--~~ 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] Many to many relationship problem
Hi, I've a problem to do a many to many relationship mapper declaration. I will try to explain this with an example: person_table(per_id, name, ...) per_per_table(id, per_orig_id, per_dest_id) per_orig_id = foreign key, reference to person_table.per_id per_dest_id = foreign key, reference to person_table.per_id How map this? I do... mapper(Person, person_table, properties={'dest': relation(Person, secondary=per_per_table)} I want to do: per = Person() per_dest = Person() per.dest.append(per_dest) But, sqlalchmey can't determinate how do the relationship: Error determining primary and/or secondary join for relationship How can I solve this? Thanks in advance. M. --~--~-~--~~~---~--~~ 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: Many to many relationship problem
On Apr 22, 2008, at 10:45 AM, maxi wrote: Hi, I've a problem to do a many to many relationship mapper declaration. I will try to explain this with an example: person_table(per_id, name, ...) per_per_table(id, per_orig_id, per_dest_id) per_orig_id = foreign key, reference to person_table.per_id per_dest_id = foreign key, reference to person_table.per_id How map this? I do... mapper(Person, person_table, properties={'dest': relation(Person, secondary=per_per_table)} I want to do: per = Person() per_dest = Person() per.dest.append(per_dest) But, sqlalchmey can't determinate how do the relationship: Error determining primary and/or secondary join for relationship use explicit primaryjoin/secondaryjoin: http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_relation_customjoin --~--~-~--~~~---~--~~ 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: 'Mapper' object has no attribute 'get_by'
seems like you've found a very very old tutorial on the web somewhere (and by old I mean, about two years out of date). The official SA ORM tutorial is here: http://www.sqlalchemy.org/docs/04/ormtutorial.html I'm reading too many docs at once lol :) Anyway at last I've figured out how to do (just for completness) controllers.py *** rs = session.query(model.User).filter(model.User.user_id==1) return dict(rs=rs) template * ul li py:for=r in rs Username: strong${r.name}/strong ol li py:for=e in r.addresses Address: em$ {e.address}/em/li /ol /li /ul Thanks! P. --~--~-~--~~~---~--~~ 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] multiple databases ?
Hello again, So now that I have mssql connection ready and data filtered out and processed I need to save it to a different database. mssql - process data - save to mysql I am wondering how should I create a second database connection? In second database I will create a table and populate the records. # First database e = sqlalchemy.create_engine(mssql://user:[EMAIL PROTECTED]:1433/dbname?driver=TDSodbc_options='TDS_Version=8.0') #e.echo=True metadata=sqlalchemy.MetaData(e) #session stuff from sqlalchemy.orm import sessionmaker Session = sessionmaker(bind=e, autoflush=True, transactional=True) session = Session() #table stuff class th(object): pass th_table = sqlalchemy.Table('', metadata, autoload=True) mapper(th,th_table) # database number 2. Is this the way I should create second database connection/session/mapper? e2 = sqlalchemy.create_engine('mysql://user:[EMAIL PROTECTED]/dbname') Do I create new metadata? metadata2=sqlalchemy.MetaData(e2) And then new session2? Session2 = sessionmaker(bind=e2, autoflush=True, transactional=True) What does this line do? session = Session() Is the above correct way of doing this? I would like to keep these connections separate so there will be no confusion of what I am using. Thanks, Lucas -- Automotive Recall Database. Cars, Trucks, etc. http://www.lucasmanual.com/recall/ TurboGears Manual-Howto http://lucasmanual.com/pdf/TurboGears-Manual-Howto.pdf --~--~-~--~~~---~--~~ 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: multiple databases ?
On Tuesday 22 April 2008 19:54:16 Lukasz Szybalski wrote: Hello again, So now that I have mssql connection ready and data filtered out and processed I need to save it to a different database. mssql - process data - save to mysql I am wondering how should I create a second database connection? In second database I will create a table and populate the records. # First database e = sqlalchemy.create_engine(mssql://user:[EMAIL PROTECTED]:1433/dbname?dr iver=TDSodbc_options='TDS_Version=8.0') #e.echo=True metadata=sqlalchemy.MetaData(e) #session stuff from sqlalchemy.orm import sessionmaker Session = sessionmaker(bind=e, autoflush=True, transactional=True) session = Session() #table stuff class th(object): pass th_table = sqlalchemy.Table('', metadata, autoload=True) mapper(th,th_table) # database number 2. Is this the way I should create second database connection/session/mapper? e2 = sqlalchemy.create_engine('mysql://user:[EMAIL PROTECTED]/dbname') Do I create new metadata? metadata2=sqlalchemy.MetaData(e2) And then new session2? Session2 = sessionmaker(bind=e2, autoflush=True, transactional=True) What does this line do? session = Session() Is the above correct way of doing this? I would like to keep these connections separate so there will be no confusion of what I am using. Thanks, Lucas well... u dont really need 2nd metadata, and u dont need any session/mappers/etc ORM-stuff at all. re-bind the metadata to new engine, then metadata.createall(), and then for each record in each table in metadata, tbl.select via src_engine, tbl.insert via dst_engine but u can try this way too.. --~--~-~--~~~---~--~~ 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: multiple databases ?
On Tue, Apr 22, 2008 at 6:00 PM, [EMAIL PROTECTED] wrote: On Tuesday 22 April 2008 19:54:16 Lukasz Szybalski wrote: Hello again, So now that I have mssql connection ready and data filtered out and processed I need to save it to a different database. mssql - process data - save to mysql I am wondering how should I create a second database connection? In second database I will create a table and populate the records. # First database e = sqlalchemy.create_engine(mssql://user:[EMAIL PROTECTED]:1433/dbname?dr iver=TDSodbc_options='TDS_Version=8.0') #e.echo=True metadata=sqlalchemy.MetaData(e) #session stuff from sqlalchemy.orm import sessionmaker Session = sessionmaker(bind=e, autoflush=True, transactional=True) session = Session() #table stuff class th(object): pass th_table = sqlalchemy.Table('', metadata, autoload=True) mapper(th,th_table) # database number 2. Is this the way I should create second database connection/session/mapper? e2 = sqlalchemy.create_engine('mysql://user:[EMAIL PROTECTED]/dbname') Do I create new metadata? metadata2=sqlalchemy.MetaData(e2) And then new session2? Session2 = sessionmaker(bind=e2, autoflush=True, transactional=True) What does this line do? session = Session() Is the above correct way of doing this? I would like to keep these connections separate so there will be no confusion of what I am using. Thanks, Lucas well... u dont really need 2nd metadata, and u dont need any session/mappers/etc ORM-stuff at all. re-bind the metadata to new engine, then metadata.createall(), and then for each record in each table in metadata, tbl.select via src_engine, tbl.insert via dst_engine but u can try this way too.. these are 2 different databases... one is all autoload and two is completely new and will not have any tables from 1. Lucas --~--~-~--~~~---~--~~ 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: adjacency tree question
On Apr 22, 2008, at 8:57 PM, David Gardner wrote: Thanks for your response, I ended up deciding that it was OK if leaf nodes show up as regular nodes. So I dropped my qry_node query, and kept the qry_leaf query, and it is working now. I should have mentioned as a side note, that my SA code needs to play nice with a closed source package, so I am not able to make schema level changes. just FTR, a working version of the two selects mapping: from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.orm.collections import attribute_mapped_collection m = MetaData(create_engine('sqlite://', echo=True)) node_table = Table(n, m, Column('id', Integer, primary_key=True), Column('name', String(50)), Column('type', String(50)), Column('parent_id', Integer, ForeignKey('n.id')) ) m.create_all() qry_node = select ([node_table], node_table.c.type! ='file').alias('node_query') qry_leaf = select ([node_table], node_table.c.type=='file').alias('leaf_query') class Node(object): def __init__(self, name): self.type='node' self.name = name class Leaf(object): def __init__(self, name): self.type='file' self.name = name mapper(Leaf, qry_leaf) mapper(Node, qry_node, properties = { 'Children' : relation(Node, cascade='all',collection_class=attribute_mapped_collection('name'), backref=backref('Parent', remote_side=[qry_node.c.id]) ), 'Files' : relation(Leaf,primaryjoin=(qry_node.c.id==qry_leaf.c.parent_id), order_by=qry_leaf.c.name, cascade='all,delete-orphan') }) n1 = Node('n1') n1.Parent = Node('n1parent') n1.Files.append(Leaf('file1')) n1.Files.append(Leaf('file2')) sess = create_session() sess.save(n1) sess.flush() sess.clear() files = sess.query(Node).filter_by(name='n1parent').one().Children['n1'].Files assert [f.name for f in files] == ['file1', 'file2'] --~--~-~--~~~---~--~~ 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: How to use regular expression in query the mysql
column.op('regexp')(...) i.e. table1.select(table1.c.column1.op('regexp')('pattern')) I think that should work. On Apr 22, 5:28 am, coomteng [EMAIL PROTECTED] wrote: Dear all, I would like to search in mysql like select * from table1 where column1 regexp patten; How can I do it in alsqlchemy? Thank you Ting --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---