[sqlalchemy] Re: Separating session and db/models definitions
-Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalch...@googlegroups.com] On Behalf Of bsdemon Sent: 24 February 2009 20:22 To: sqlalchemy Subject: [sqlalchemy] Separating session and db/models definitions Hello. I have the following states of things: 1) I need to place some common database metadata description and models in one package 2) There are at least to applications, which will use this models: first app uses scoped session with their own scope_func, second app uses session from sessionmaker 3) I have some logic in models' methods that need session object to present (delete relations or etc.) I have no idea how to do it... Is there need for some kind of proxy to session, which will appear later, when app decide to instantiate it? Or I must define session in place with models? You can find out which session an object is loaded in using the sqlalchemy.orm.object_session function. So inside your methods, you should be able to say something like: session = orm.object_session(self) I think that should work no matter what session strategy you are using. Hope that helps, Simon --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Separating session and db/models definitions
Yes, it is really what I need. Thanks! I must read docs more careful. On Wed, Feb 25, 2009 at 12:40 PM, King Simon-NFHD78 simon.k...@motorola.com wrote: -Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalch...@googlegroups.com] On Behalf Of bsdemon Sent: 24 February 2009 20:22 To: sqlalchemy Subject: [sqlalchemy] Separating session and db/models definitions Hello. I have the following states of things: 1) I need to place some common database metadata description and models in one package 2) There are at least to applications, which will use this models: first app uses scoped session with their own scope_func, second app uses session from sessionmaker 3) I have some logic in models' methods that need session object to present (delete relations or etc.) I have no idea how to do it... Is there need for some kind of proxy to session, which will appear later, when app decide to instantiate it? Or I must define session in place with models? You can find out which session an object is loaded in using the sqlalchemy.orm.object_session function. So inside your methods, you should be able to say something like: session = orm.object_session(self) I think that should work no matter what session strategy you are using. Hope that helps, Simon -- С уважением, Андрей Попп. +7 911 740 24 91 --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Self Join via Join Table ?
u mean, the Bar is an association table of Foo to Foo? u have to use secondary_table and/or secondary_join in the relation setup. And probably specify remote_side or it may not know which Foo is what. On Wednesday 25 February 2009 03:39:20 Stef wrote: Hello Everyone, First of all, kudos on SQLAlchemy.. the speed is pretty amazing - I am coming from the SQLObject world and there is a definite difference. Excellent work. I am also getting to grips with it pretty quickly, using object_session and all that good stuff. This said, I have hit that 20% problem, and am hoping someone can shine a light on it. I have a table, lets call it Foo and another table Bar. Foo should be able to get a list of it's parents via Bar or it's children via Bar. I am also using the declarative_base system rather than table/ mapper defined seperately. class Foo(Base): id = Column(Integer, primary_key=True) class Bar(Base): parent_id = Column(Integer, default=0) child_id = Column(Integer, default=0) So, I thought something like ; children = relation(Foo, backref=backref('parents'), primaryjoin=and_(Foo.id==Bar.parent_id) But that's where I hit the 'wall' as it were, is there a way to setup a synonym for Foo in the primaryjoin clause ? Am I missing something stupid ? (I am okay with that ;) Regards Stef --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Problems with cursor, don't know what to do.
More info: I have MacOSX and use iODBC with FreeTDS driver. And looks like everything is OK: FreeTDS: [tu...@2kan-2:~/bigur]% tsql -S libra -p 1433 -U user locale is ru_RU.KOI8-R/UTF-8/ru_RU.KOI8-R/ru_RU.KOI8-R/ru_RU.KOI8-R/ ru_RU.KOI8-R locale charset is Password: 1 select * from tax 2 go ... (4 rows affected) ODBC: iodbctest DSN=libra;UID=user;PWD=password iODBC Demonstration program This program shows an interactive SQL processor Driver Manager: 03.52.0406.1211 Driver: 0.82 (libtdsodbc.so) SQL... And also I tried to connect with pyodbc: tu...@2kan-2:~/bigur/calculation]% py Python 2.5.2 (r252:60911, Feb 23 2009, 21:22:55) [GCC 4.0.1 (Apple Inc. build 5488)] on darwin Type help, copyright, credits or license for more information. import pyodbc pyodbc.connect(DSN=libra;UID=gik;PWD=123) pyodbc.connection object=object at=at 0x57620=0x57620 c = _.cursor() c.execute(SELECT * from tax).fetchall() ... On Feb 24, 9:04 pm, Timothy N. Tsvetkov timothy.tsvet...@gmail.com wrote: Hi all, I'm new to SQLAlchemy, and I've a problem using it. [tu...@2kan-2:~/bigur/calculation]% python Python 2.5.2 (r252:60911, Feb 23 2009, 21:22:55) [GCC 4.0.1 (Apple Inc. build 5488)] on darwin Type help, copyright, credits or license for more information. from sqlalchemy import * db = create_engine('mssql://some_name:some_passwpod@/?dsn=Libradriver=FreeTDS') metadata = MetaData() metadata.bind = db metadata.bind.echo = True users_table = Table('tax', metadata, autoload=True) 2009-02-24 20:54:55,261 INFO sqlalchemy.engine.base.Engine.0x...2850 SELECT user_name() as user_name; 2009-02-24 20:54:55,261 INFO sqlalchemy.engine.base.Engine.0x...2850 [] 2009-02-24 20:54:55,280 WARNING sqlalchemy.pool.QueuePool.0x...27b0 Error closing cursor: Attempt to use a closed cursor. 2009-02-24 20:54:55,280 INFO sqlalchemy.engine.base.Engine.0x...2850 ROLLBACK Traceback (most recent call last): File stdin, line 1, in module File /opt/local/lib/python2.5/site-packages/ SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/schema.py, line 113, in __call__ return type.__call__(self, name, metadata, *args, **kwargs) File /opt/local/lib/python2.5/site-packages/ SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/schema.py, line 241, in __init__ _bind_or_error(metadata).reflecttable(self, include_columns=include_columns) File /opt/local/lib/python2.5/site-packages/ SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/engine/base.py, line 1265, in reflecttable self.dialect.reflecttable(conn, table, include_columns) File /opt/local/lib/python2.5/site-packages/ SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/databases/mssql.py, line 1123, in reflecttable current_schema = self.get_default_schema_name(connection) File string, line 1, in lambda File /opt/local/lib/python2.5/site-packages/ SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/engine/base.py, line 1894, in decorated connection.info[key] = val = fn(self, connection) File /opt/local/lib/python2.5/site-packages/ SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/databases/mssql.py, line 1070, in get_default_schema_name user_name = connection.scalar(sql.text(query)) File /opt/local/lib/python2.5/site-packages/ SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/engine/base.py, line 814, in scalar return self.execute(object, *multiparams, **params).scalar() File /opt/local/lib/python2.5/site-packages/ SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/engine/base.py, line 1676, in scalar self.connection._handle_dbapi_exception(e, None, None, self.cursor, self.context) File /opt/local/lib/python2.5/site-packages/ SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/engine/base.py, line 931, in _handle_dbapi_exception raise exc.DBAPIError.instance(statement, parameters, e, connection_invalidated=is_disconnect) sqlalchemy.exc.ProgrammingError: (ProgrammingError) Attempt to use a closed cursor. None None What I'm doing wrong? --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Creating SQL Expression
sorry its resolved and working On Feb 25, 12:20 pm, Ash ashishsinghbha...@gmail.com wrote: Hello , I am trying to make query like select (a+b) from xyz; to do this xyz = sqlalchemy.Table('xyz',metadata) a = sqlalchemy.Column('a', sqlalchemy.Integer) xyz.append_column(a) b = sqlalchemy.Column('b', sqlalchemy.Integer) xyz.append_column(b) column = [(a + b)] select = sqlalchemy.select(from_obj=xyz, columns=column,distinct=True) This works fine for me. Now when the columns a and b are dynamic (Enter by the user in form of string) and the operator too comes from user columns_list = ['a','b'] operator = ['+'] like this i get the input so i make the loop and make for both the columns something like this columns = [] for x in column_list : t = sqlalchemy.Column(x, sqlalchemy.Integer) xyz.append_column(a) columns.append(t) so now how to add + to make the quer run Thanks in the advance. --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: using relation in non-declarative table and class definitions (newbie problem)
You add the relation to the propoties on mapper. Look at http://www.sqlalchemy.org/docs/05/mappers.html#basic-relational-patterns On Feb 24, 4:10 pm, Marcin Krol mrk...@gmail.com wrote: Hello everyone, I've been following tutorialhttp://www.sqlalchemy.org/docs/05/ormtutorial.htmlwhich explains how to use 'relation' function using declarative extension. However, in my app I define classes and tables for classes separately, and tutorial does not cover how to use relation in such context (googling for it does not return much info either) . All it says is this: When declarative is not in use, you typically define your mapper() well after the target classes and Table objects have been defined, so string expressions are not needed. Does that mean that I need to define relation in mapper(UserClass, usertable) call somehow? I have: hosts_table = Table('hosts',md, Column('id',Integer,primary_key=True), Column('IP',String), Column('HostName',String), Column('Location',String), Column('Architecture_id',Integer,ForeignKey('architecture.id')), Column('OS_Kind_id',Integer,ForeignKey('os_kind.id')), Column('OS_version_id',Integer,ForeignKey('os_version.id')), Column('Additional_info__visible_for_all_users',String), Column('End_Date',SLDate), ... mapper(Host, hosts_table) architecture_table = Table('architecture',md, Column('id',Integer,primary_key=True), Column('Architecture',String)) mapper(Architecture, architecture_table) os_kind_table = Table('os_kind',md, Column('id',Integer,primary_key=True), Column('OS_Kind',String)) mapper(OS_Kind, os_kind_table) os_version_table = Table('os_version',md, Column('id',Integer,primary_key=True), Column('OS_version',String)) mapper(OS_version, os_version_table) email_table = Table('email',md, Column('id',Integer,primary_key=True), Column('Email',String)) mapper(Email,email_table) Now, md.create_all() does create proper db structure (I know bc I examined sqlite db after session.commit()). However, if I do not use the relation() somewhere, does that mean that foreign keys may not work properly or there will be some other adverse effects? How do I use relation() with above? I'd love to see such info added to the tutorial.. Regards, mk --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Creating SQL Expression
The problem is still their. The two seprate list of columns = List of sqlalchem object operator = ['+'','-'] using join to join them will convert the columns object to string which is not desirable. Any way to fix this. On Feb 25, 3:54 pm, Ashish Bhatia ashishsinghbha...@gmail.com wrote: sorry its resolved and working On Feb 25, 12:20 pm, Ash ashishsinghbha...@gmail.com wrote: Hello , I am trying to make query like select (a+b) from xyz; to do this xyz = sqlalchemy.Table('xyz',metadata) a = sqlalchemy.Column('a', sqlalchemy.Integer) xyz.append_column(a) b = sqlalchemy.Column('b', sqlalchemy.Integer) xyz.append_column(b) column = [(a + b)] select = sqlalchemy.select(from_obj=xyz, columns=column,distinct=True) This works fine for me. Now when the columns a and b are dynamic (Enter by the user in form of string) and the operator too comes from user columns_list = ['a','b'] operator = ['+'] like this i get the input so i make the loop and make for both the columns something like this columns = [] for x in column_list : t = sqlalchemy.Column(x, sqlalchemy.Integer) xyz.append_column(a) columns.append(t) so now how to add + to make the quer run Thanks in the advance. --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Creating SQL Expression
Could you use the python 'operator' module (http://docs.python.org/library/operator.html)? Eg. (untested): import operator operations = { '+': operator.add, '-': operator.sub, # etc. } def combine_columns(op, *cols): return operations[op](*cols) sum_column = combine_columns('+', a, b) I think that should work. Simon -Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalch...@googlegroups.com] On Behalf Of Ashish Bhatia Sent: 25 February 2009 13:26 To: sqlalchemy Subject: [sqlalchemy] Re: Creating SQL Expression The problem is still their. The two seprate list of columns = List of sqlalchem object operator = ['+'','-'] using join to join them will convert the columns object to string which is not desirable. Any way to fix this. On Feb 25, 3:54 pm, Ashish Bhatia ashishsinghbha...@gmail.com wrote: sorry its resolved and working On Feb 25, 12:20 pm, Ash ashishsinghbha...@gmail.com wrote: Hello , I am trying to make query like select (a+b) from xyz; to do this xyz = sqlalchemy.Table('xyz',metadata) a = sqlalchemy.Column('a', sqlalchemy.Integer) xyz.append_column(a) b = sqlalchemy.Column('b', sqlalchemy.Integer) xyz.append_column(b) column = [(a + b)] select = sqlalchemy.select(from_obj=xyz, columns=column,distinct=True) This works fine for me. Now when the columns a and b are dynamic (Enter by the user in form of string) and the operator too comes from user columns_list = ['a','b'] operator = ['+'] like this i get the input so i make the loop and make for both the columns something like this columns = [] for x in column_list : t = sqlalchemy.Column(x, sqlalchemy.Integer) xyz.append_column(a) columns.append(t) so now how to add + to make the quer run Thanks in the advance. --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] dynamic relation filtering
hi, how can i filter dynamic relation's query to instances of a given class, including the subclasses ? i tried something like part.documents.filter(Part.documents.of_type(CADDocument)) but i'm getting ArgumentError: filter() argument must be of type sqlalchemy.sql.ClauseElement or string 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 sqlalchemy@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: Creating SQL Expression
Whoops, premature send, sorry. For an arbitrary list of columns, such as t.c (the column collection) or other SQL selectables, such as the above binary expressions, you can use sum(columns). E.g.: t = Table('bobloblaw', MetaData(), Column('a', Integer), Column('b', Integer), Column('c', Integer)) e = create_engine('sqlite:///:memory:') e.execute(t.insert(), [{'a':1, 'b':2, 'c':4}]) e.execute(select([sum(t.c)])).fetchall() # equiv. to SELECT a+b+c FROM t # [(7,)] Regards, - Gulli On Wed, Feb 25, 2009 at 1:40 PM, Gunnlaugur Thor Briem gunnlau...@gmail.com wrote: You can sum the column objects directly, a+b, producing a sqlalchemy.sql.expression._BinaryExpression object. t = Table('bobloblaw', MetaData(), Column('a', Integer), Column('b', Integer), Column('c', Integer)) t.c.a + t.c.b # evaluates to sqlalchemy.sql.expression._BinaryExpression object at 0x1ec9ff0 print t.c.a + t.c.b # bobloblaw.a + bobloblaw.b On Wed, Feb 25, 2009 at 1:25 PM, Ashish Bhatia ashishsinghbha...@gmail.com wrote: The problem is still their. The two seprate list of columns = List of sqlalchem object operator = ['+'','-'] using join to join them will convert the columns object to string which is not desirable. Any way to fix this. On Feb 25, 3:54 pm, Ashish Bhatia ashishsinghbha...@gmail.com wrote: sorry its resolved and working On Feb 25, 12:20 pm, Ash ashishsinghbha...@gmail.com wrote: Hello , I am trying to make query like select (a+b) from xyz; to do this xyz = sqlalchemy.Table('xyz',metadata) a = sqlalchemy.Column('a', sqlalchemy.Integer) xyz.append_column(a) b = sqlalchemy.Column('b', sqlalchemy.Integer) xyz.append_column(b) column = [(a + b)] select = sqlalchemy.select(from_obj=xyz, columns=column,distinct=True) This works fine for me. Now when the columns a and b are dynamic (Enter by the user in form of string) and the operator too comes from user columns_list = ['a','b'] operator = ['+'] like this i get the input so i make the loop and make for both the columns something like this columns = [] for x in column_list : t = sqlalchemy.Column(x, sqlalchemy.Integer) xyz.append_column(a) columns.append(t) so now how to add + to make the quer run Thanks in the advance. --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Use with multiple Processes
Hi, your suggestion sounds really reasonable but the point is that these processes are running on different machines and I don't want to put a lot of effort in synchronizing these threads. Isn't there any easy solution for having multiple processes working on the same database table? Thanks. Cheers Am Dienstag, den 24.02.2009, 07:46 -0800 schrieb Michael Bayer: I would select out the total set of rows and then hand off groups of those rows, converted into serializable objects first, using the imap function of a multiprocessing.Pool object. It would be best if the rows are returned via a ResultProxy so that work can begin on results before all results are fetched. See http://docs.python.org/library/multiprocessing.html#module-multiprocessing.pool . Its critical that you call create_engine() within each subprocess if additional queries are to be issued in workers, and don't pass any other database resources like connections or cursors across. Pool allows initialization activities via the initializer argument. On Feb 24, 7:05 am, dagooglaa danielso...@gmx.de wrote: Hi, I am using SQLAlchemy 0.4.8 with Python 2.4. I have a process which is selecting some rows, doing something with the data of these rows and then writes a result into the database. How can I achieve a solution where multiple of these processes are running without having them selecting the same rows and doing the same stuff? Normally I would suggest s.th. like Select for update or an trigger which sets a timestamp after a select... Do you have any suggestions for having multiple processes working on the same table but not on the same rows? Thanks --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: dynamic relation filtering
thequery().with_polymorphic( list of classes ) ? On Wednesday 25 February 2009 15:43:54 Vladimir Iliev wrote: hi, how can i filter dynamic relation's query to instances of a given class, including the subclasses ? i tried something like part.documents.filter(Part.documents.of_type(CADDocument)) but i'm getting ArgumentError: filter() argument must be of type sqlalchemy.sql.ClauseElement or string 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 sqlalchemy@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] export and import JSON from database (JSON type)
How does one create a TypeDecorator to export and import JSON to a database using SA? --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: dynamic relation filtering
InvalidRequestError: Query.with_polymorphic() being called on a Query with existing criterion a...@svilendobrev.com написа: thequery().with_polymorphic( list of classes ) ? On Wednesday 25 February 2009 15:43:54 Vladimir Iliev wrote: hi, how can i filter dynamic relation's query to instances of a given class, including the subclasses ? i tried something like part.documents.filter(Part.documents.of_type(CADDocument)) but i'm getting ArgumentError: filter() argument must be of type sqlalchemy.sql.ClauseElement or string 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 sqlalchemy@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: Problems with cursor, don't know what to do.
what happens if you try your stuff without using freeTDS at all ? lots of problems are reported with FreeTDS and I had my own negative experience with it recently. On Feb 25, 2009, at 5:35 AM, Timothy N. Tsvetkov wrote: More info: I have MacOSX and use iODBC with FreeTDS driver. And looks like everything is OK: FreeTDS: [tu...@2kan-2:~/bigur]% tsql -S libra -p 1433 -U user locale is ru_RU.KOI8-R/UTF-8/ru_RU.KOI8-R/ru_RU.KOI8-R/ru_RU.KOI8-R/ ru_RU.KOI8-R locale charset is Password: 1 select * from tax 2 go ... (4 rows affected) ODBC: iodbctest DSN=libra;UID=user;PWD=password iODBC Demonstration program This program shows an interactive SQL processor Driver Manager: 03.52.0406.1211 Driver: 0.82 (libtdsodbc.so) SQL... And also I tried to connect with pyodbc: tu...@2kan-2:~/bigur/calculation]% py Python 2.5.2 (r252:60911, Feb 23 2009, 21:22:55) [GCC 4.0.1 (Apple Inc. build 5488)] on darwin Type help, copyright, credits or license for more information. import pyodbc pyodbc.connect(DSN=libra;UID=gik;PWD=123) pyodbc.connection object=object at=at 0x57620=0x57620 c = _.cursor() c.execute(SELECT * from tax).fetchall() ... On Feb 24, 9:04 pm, Timothy N. Tsvetkov timothy.tsvet...@gmail.com wrote: Hi all, I'm new to SQLAlchemy, and I've a problem using it. [tu...@2kan-2:~/bigur/calculation]% python Python 2.5.2 (r252:60911, Feb 23 2009, 21:22:55) [GCC 4.0.1 (Apple Inc. build 5488)] on darwin Type help, copyright, credits or license for more information. from sqlalchemy import * db = create_engine('mssql://some_name:some_passwpod@/? dsn=Libradriver=FreeTDS') metadata = MetaData() metadata.bind = db metadata.bind.echo = True users_table = Table('tax', metadata, autoload=True) 2009-02-24 20:54:55,261 INFO sqlalchemy.engine.base.Engine.0x...2850 SELECT user_name() as user_name; 2009-02-24 20:54:55,261 INFO sqlalchemy.engine.base.Engine.0x...2850 [] 2009-02-24 20:54:55,280 WARNING sqlalchemy.pool.QueuePool.0x...27b0 Error closing cursor: Attempt to use a closed cursor. 2009-02-24 20:54:55,280 INFO sqlalchemy.engine.base.Engine.0x...2850 ROLLBACK Traceback (most recent call last): File stdin, line 1, in module File /opt/local/lib/python2.5/site-packages/ SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/schema.py, line 113, in __call__ return type.__call__(self, name, metadata, *args, **kwargs) File /opt/local/lib/python2.5/site-packages/ SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/schema.py, line 241, in __init__ _bind_or_error(metadata).reflecttable(self, include_columns=include_columns) File /opt/local/lib/python2.5/site-packages/ SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/engine/base.py, line 1265, in reflecttable self.dialect.reflecttable(conn, table, include_columns) File /opt/local/lib/python2.5/site-packages/ SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/databases/mssql.py, line 1123, in reflecttable current_schema = self.get_default_schema_name(connection) File string, line 1, in lambda File /opt/local/lib/python2.5/site-packages/ SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/engine/base.py, line 1894, in decorated connection.info[key] = val = fn(self, connection) File /opt/local/lib/python2.5/site-packages/ SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/databases/mssql.py, line 1070, in get_default_schema_name user_name = connection.scalar(sql.text(query)) File /opt/local/lib/python2.5/site-packages/ SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/engine/base.py, line 814, in scalar return self.execute(object, *multiparams, **params).scalar() File /opt/local/lib/python2.5/site-packages/ SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/engine/base.py, line 1676, in scalar self.connection._handle_dbapi_exception(e, None, None, self.cursor, self.context) File /opt/local/lib/python2.5/site-packages/ SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/engine/base.py, line 931, in _handle_dbapi_exception raise exc.DBAPIError.instance(statement, parameters, e, connection_invalidated=is_disconnect) sqlalchemy.exc.ProgrammingError: (ProgrammingError) Attempt to use a closed cursor. None None What I'm doing wrong? --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Use with multiple Processes
entirely different machines, then youd have to partition out rows from the table yourself. you'd select some range of rows using LIMIT/ OFFSET on each machine to be processed. the exact count would depend on the total rows in the table and the total number of machines. On Feb 25, 2009, at 8:50 AM, Daniel wrote: Hi, your suggestion sounds really reasonable but the point is that these processes are running on different machines and I don't want to put a lot of effort in synchronizing these threads. Isn't there any easy solution for having multiple processes working on the same database table? Thanks. Cheers Am Dienstag, den 24.02.2009, 07:46 -0800 schrieb Michael Bayer: I would select out the total set of rows and then hand off groups of those rows, converted into serializable objects first, using the imap function of a multiprocessing.Pool object. It would be best if the rows are returned via a ResultProxy so that work can begin on results before all results are fetched. See http://docs.python.org/library/multiprocessing.html#module-multiprocessing.pool . Its critical that you call create_engine() within each subprocess if additional queries are to be issued in workers, and don't pass any other database resources like connections or cursors across. Pool allows initialization activities via the initializer argument. On Feb 24, 7:05 am, dagooglaa danielso...@gmx.de wrote: Hi, I am using SQLAlchemy 0.4.8 with Python 2.4. I have a process which is selecting some rows, doing something with the data of these rows and then writes a result into the database. How can I achieve a solution where multiple of these processes are running without having them selecting the same rows and doing the same stuff? Normally I would suggest s.th. like Select for update or an trigger which sets a timestamp after a select... Do you have any suggestions for having multiple processes working on the same table but not on the same rows? Thanks --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: dynamic relation filtering
with_polymorphic() needs to be called first. On Feb 25, 2009, at 9:54 AM, Vladimir Iliev wrote: InvalidRequestError: Query.with_polymorphic() being called on a Query with existing criterion a...@svilendobrev.com написа: thequery().with_polymorphic( list of classes ) ? On Wednesday 25 February 2009 15:43:54 Vladimir Iliev wrote: hi, how can i filter dynamic relation's query to instances of a given class, including the subclasses ? i tried something like part.documents.filter(Part.documents.of_type(CADDocument)) but i'm getting ArgumentError: filter() argument must be of type sqlalchemy.sql.ClauseElement or string 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 sqlalchemy@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: dynamic relation filtering
so it's not possible to reuse relation's query definition ? Michael Bayer написа: with_polymorphic() needs to be called first. On Feb 25, 2009, at 9:54 AM, Vladimir Iliev wrote: InvalidRequestError: Query.with_polymorphic() being called on a Query with existing criterion a...@svilendobrev.com написа: thequery().with_polymorphic( list of classes ) ? On Wednesday 25 February 2009 15:43:54 Vladimir Iliev wrote: hi, how can i filter dynamic relation's query to instances of a given class, including the subclasses ? i tried something like part.documents.filter(Part.documents.of_type(CADDocument)) but i'm getting ArgumentError: filter() argument must be of type sqlalchemy.sql.ClauseElement or string 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 sqlalchemy@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] Ordering results of a WHERE x in y query by y
Hi all, having a x IN y query, with y supplied as input to the query: session.query(C).filter(C.someattr.in_(valuelist)) is there a way to tell SQLAlchemy to order the results according to valuelist? I.e. not by the natural order of someattr, but by the arbitrary order seen in valuelist? E.g.: session.add(C(someattr='Abigail')) session.add(C(someattr='Benjamin')) session.add(C(someattr='Carl')) valuelist = ['Benjamin', 'Abigail'] q = session.query(C).filter(C.someattr.in_(valuelist)).order_by(clever (valuelist)) q.all() # returns [C('Benjamin'), C('Abigail')] The solution I can think of is to create a temporary table with sess.execute('create temp table ...'), insert the valuelist into that temp table along with a sequence index, join to that temporary table and order by its index. Is there a less kludgy way? Regards, - Gulli --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Connecting with Windows Auth?
Is it possible to connect to a server using Windows Authentication using sqlalchemy? I have a MSSQL server database where my Windows account is needed to create tables. I didn’t turn up anything on the connection syntax for this when I searched. Thanks in advance. - Adam --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: dynamic relation filtering
not currently no On Feb 25, 2009, at 10:46 AM, Vladimir Iliev wrote: so it's not possible to reuse relation's query definition ? Michael Bayer написа: with_polymorphic() needs to be called first. On Feb 25, 2009, at 9:54 AM, Vladimir Iliev wrote: InvalidRequestError: Query.with_polymorphic() being called on a Query with existing criterion a...@svilendobrev.com написа: thequery().with_polymorphic( list of classes ) ? On Wednesday 25 February 2009 15:43:54 Vladimir Iliev wrote: hi, how can i filter dynamic relation's query to instances of a given class, including the subclasses ? i tried something like part.documents.filter(Part.documents.of_type(CADDocument)) but i'm getting ArgumentError: filter() argument must be of type sqlalchemy.sql.ClauseElement or string 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 sqlalchemy@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: export and import JSON from database (JSON type)
On Wed, Feb 25, 2009 at 11:39, Gregg Lind gregg.l...@gmail.com wrote: How does one create a TypeDecorator to export and import JSON to a database using SA? I did something like that recently: - from sqlalchemy import types import simplejson class JsonString(types.TypeDecorator): impl = types.String def process_result_value(self, value, dialect): if value is None: return None else: return simplejson.loads(value) def process_bind_param(self, value, dialect): if value is None: return None else: return simplejson.dumps(value) - []s Roger --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: export and import JSON from database (JSON type)
Thank you, that's simpler than my attempts, for sure! On Wed, Feb 25, 2009 at 10:27 AM, Roger Demetrescu roger.demetre...@gmail.com wrote: On Wed, Feb 25, 2009 at 11:39, Gregg Lind gregg.l...@gmail.com wrote: How does one create a TypeDecorator to export and import JSON to a database using SA? I did something like that recently: - from sqlalchemy import types import simplejson class JsonString(types.TypeDecorator): impl = types.String def process_result_value(self, value, dialect): if value is None: return None else: return simplejson.loads(value) def process_bind_param(self, value, dialect): if value is None: return None else: return simplejson.dumps(value) - []s Roger --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: dynamic relation filtering
so...workaround, use a new query against the target object and call with_parent(), given the parent object. I didnt realize earlier this was with a dynamic relation. this is something we should try to support. with_polymorphic() is tricky since it implies a potential filtering to be applied to all criterion, and in the case of dynamic a criterion is already present. On Feb 25, 2009, at 11:19 AM, Michael Bayer wrote: not currently no On Feb 25, 2009, at 10:46 AM, Vladimir Iliev wrote: so it's not possible to reuse relation's query definition ? Michael Bayer написа: with_polymorphic() needs to be called first. On Feb 25, 2009, at 9:54 AM, Vladimir Iliev wrote: InvalidRequestError: Query.with_polymorphic() being called on a Query with existing criterion a...@svilendobrev.com написа: thequery().with_polymorphic( list of classes ) ? On Wednesday 25 February 2009 15:43:54 Vladimir Iliev wrote: hi, how can i filter dynamic relation's query to instances of a given class, including the subclasses ? i tried something like part.documents.filter(Part.documents.of_type(CADDocument)) but i'm getting ArgumentError: filter() argument must be of type sqlalchemy.sql.ClauseElement or string 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 sqlalchemy@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: dynamic relation filtering
ok, thanks Michael Bayer написа: not currently no On Feb 25, 2009, at 10:46 AM, Vladimir Iliev wrote: so it's not possible to reuse relation's query definition ? Michael Bayer написа: with_polymorphic() needs to be called first. On Feb 25, 2009, at 9:54 AM, Vladimir Iliev wrote: InvalidRequestError: Query.with_polymorphic() being called on a Query with existing criterion a...@svilendobrev.com написа: thequery().with_polymorphic( list of classes ) ? On Wednesday 25 February 2009 15:43:54 Vladimir Iliev wrote: hi, how can i filter dynamic relation's query to instances of a given class, including the subclasses ? i tried something like part.documents.filter(Part.documents.of_type(CADDocument)) but i'm getting ArgumentError: filter() argument must be of type sqlalchemy.sql.ClauseElement or string 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 sqlalchemy@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] single table inheritance and changing object's type
how can i change the type of mapped object using single table inheritance? thanks --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: export and import JSON from database (JSON type)
On Wed, Feb 25, 2009 at 13:40, Gregg Lind gregg.l...@gmail.com wrote: Thank you, that's simpler than my attempts, for sure! You're welcome. Note that this implementation is very simple. Depending of your use case, you probably should take a look at MutableType [1] and types.TypeEngine.is_mutable(). [1] - http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/types.html#sqlalchemy.types.MutableType On Wed, Feb 25, 2009 at 10:27 AM, Roger Demetrescu roger.demetre...@gmail.com wrote: On Wed, Feb 25, 2009 at 11:39, Gregg Lind gregg.l...@gmail.com wrote: How does one create a TypeDecorator to export and import JSON to a database using SA? I did something like that recently: - from sqlalchemy import types import simplejson class JsonString(types.TypeDecorator): impl = types.String def process_result_value(self, value, dialect): if value is None: return None else: return simplejson.loads(value) def process_bind_param(self, value, dialect): if value is None: return None else: return simplejson.dumps(value) - []s Roger --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: single table inheritance and changing object's type
update the type column directly , expunge the old object and then reload - or use merge() in a similar way if that suits the use case better. the ORM doesn't support in place type changes currently. On Feb 25, 2009, at 11:55 AM, Vladimir Iliev wrote: how can i change the type of mapped object using single table inheritance? thanks --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: dynamic relation filtering
also if you're using single table inheritance, you should be able to get away without needing with_polymorphic to query on subclasses. On Feb 25, 2009, at 11:41 AM, Vladimir Iliev wrote: ok, thanks Michael Bayer написа: not currently no On Feb 25, 2009, at 10:46 AM, Vladimir Iliev wrote: so it's not possible to reuse relation's query definition ? Michael Bayer написа: with_polymorphic() needs to be called first. On Feb 25, 2009, at 9:54 AM, Vladimir Iliev wrote: InvalidRequestError: Query.with_polymorphic() being called on a Query with existing criterion a...@svilendobrev.com написа: thequery().with_polymorphic( list of classes ) ? On Wednesday 25 February 2009 15:43:54 Vladimir Iliev wrote: hi, how can i filter dynamic relation's query to instances of a given class, including the subclasses ? i tried something like part.documents.filter(Part.documents.of_type(CADDocument)) but i'm getting ArgumentError: filter() argument must be of type sqlalchemy.sql.ClauseElement or string 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 sqlalchemy@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: Self Join via Join Table ?
Hello Az, Yes, Bar is the association table of Foo to Foo. In essence, this is a self join through a join table.. I have tried and hit my head on this for (quite literally) hours. In the end, and for the record, I ended up creating a method on the model itself such as ; def children(self): childFoo=Foo.__table__.alias() return object_session(self).query(Foo).filter(and_(childFoo.c.deleted == 0, childFoo.id self.id, self.id == Bar.parent_id)) Not the prettiest way, nor what I would expect, but in lieu of an actual example, and to help anyone who ends up treading the same path as me, I hope this helps. Regards Stef On Wed, Feb 25, 2009 at 4:29 AM, a...@svilendobrev.com wrote: u mean, the Bar is an association table of Foo to Foo? u have to use secondary_table and/or secondary_join in the relation setup. And probably specify remote_side or it may not know which Foo is what. On Wednesday 25 February 2009 03:39:20 Stef wrote: Hello Everyone, First of all, kudos on SQLAlchemy.. the speed is pretty amazing - I am coming from the SQLObject world and there is a definite difference. Excellent work. I am also getting to grips with it pretty quickly, using object_session and all that good stuff. This said, I have hit that 20% problem, and am hoping someone can shine a light on it. I have a table, lets call it Foo and another table Bar. Foo should be able to get a list of it's parents via Bar or it's children via Bar. I am also using the declarative_base system rather than table/ mapper defined seperately. class Foo(Base): id = Column(Integer, primary_key=True) class Bar(Base): parent_id = Column(Integer, default=0) child_id = Column(Integer, default=0) So, I thought something like ; children = relation(Foo, backref=backref('parents'), primaryjoin=and_(Foo.id==Bar.parent_id) But that's where I hit the 'wall' as it were, is there a way to setup a synonym for Foo in the primaryjoin clause ? Am I missing something stupid ? (I am okay with that ;) Regards Stef --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Self Join via Join Table ?
check out the association proxy extension if you're looking to have Bar be hidden as an association object. it will ultimately use Foo/Bar for querying but attribute access would be proxied through the names you confgure. On Feb 25, 2009, at 4:11 PM, Stephen Telford wrote: Hello Az, Yes, Bar is the association table of Foo to Foo. In essence, this is a self join through a join table.. I have tried and hit my head on this for (quite literally) hours. In the end, and for the record, I ended up creating a method on the model itself such as ; def children(self): childFoo=Foo.__table__.alias() return object_session(self).query(Foo).filter(and_(childFoo.c.deleted == 0, childFoo.id self.id, self.id == Bar.parent_id)) Not the prettiest way, nor what I would expect, but in lieu of an actual example, and to help anyone who ends up treading the same path as me, I hope this helps. Regards Stef On Wed, Feb 25, 2009 at 4:29 AM, a...@svilendobrev.com wrote: u mean, the Bar is an association table of Foo to Foo? u have to use secondary_table and/or secondary_join in the relation setup. And probably specify remote_side or it may not know which Foo is what. On Wednesday 25 February 2009 03:39:20 Stef wrote: Hello Everyone, First of all, kudos on SQLAlchemy.. the speed is pretty amazing - I am coming from the SQLObject world and there is a definite difference. Excellent work. I am also getting to grips with it pretty quickly, using object_session and all that good stuff. This said, I have hit that 20% problem, and am hoping someone can shine a light on it. I have a table, lets call it Foo and another table Bar. Foo should be able to get a list of it's parents via Bar or it's children via Bar. I am also using the declarative_base system rather than table/ mapper defined seperately. class Foo(Base): id = Column(Integer, primary_key=True) class Bar(Base): parent_id = Column(Integer, default=0) child_id = Column(Integer, default=0) So, I thought something like ; children = relation(Foo, backref=backref('parents'), primaryjoin=and_(Foo.id==Bar.parent_id) But that's where I hit the 'wall' as it were, is there a way to setup a synonym for Foo in the primaryjoin clause ? Am I missing something stupid ? (I am okay with that ;) Regards Stef --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Self Join via Join Table ?
Okay, that sounds like a plan but., not to sound too much like a broken record, does anyone have an -actual- example ? looking at pages with a lot of API's is not really going to help me too much :( This maybe slightly off-topic and it's really NOT meant as flamebait but.. I remember a while ago playing around with DBIx (the perl ORM) and one of the things that -really- made it easy to get to grips with as the DBIx::Cookbook. It maybe a good idea to fling something similiar into the sqlalchemy documentation... if I had more experience I would write it but.. yes. It definitely is the quickest ORM I have seen/used, but, all the speed is for naught if you hit the 20% wall. Regards Stef On Wed, Feb 25, 2009 at 4:21 PM, Michael Bayer mike...@zzzcomputing.comwrote: check out the association proxy extension if you're looking to have Bar be hidden as an association object. it will ultimately use Foo/Bar for querying but attribute access would be proxied through the names you confgure. On Feb 25, 2009, at 4:11 PM, Stephen Telford wrote: Hello Az, Yes, Bar is the association table of Foo to Foo. In essence, this is a self join through a join table.. I have tried and hit my head on this for (quite literally) hours. In the end, and for the record, I ended up creating a method on the model itself such as ; def children(self): childFoo=Foo.__table__.alias() return object_session(self).query(Foo).filter(and_(childFoo.c.deleted == 0, childFoo.id self.id, self.id == Bar.parent_id)) Not the prettiest way, nor what I would expect, but in lieu of an actual example, and to help anyone who ends up treading the same path as me, I hope this helps. Regards Stef On Wed, Feb 25, 2009 at 4:29 AM, a...@svilendobrev.com wrote: u mean, the Bar is an association table of Foo to Foo? u have to use secondary_table and/or secondary_join in the relation setup. And probably specify remote_side or it may not know which Foo is what. On Wednesday 25 February 2009 03:39:20 Stef wrote: Hello Everyone, First of all, kudos on SQLAlchemy.. the speed is pretty amazing - I am coming from the SQLObject world and there is a definite difference. Excellent work. I am also getting to grips with it pretty quickly, using object_session and all that good stuff. This said, I have hit that 20% problem, and am hoping someone can shine a light on it. I have a table, lets call it Foo and another table Bar. Foo should be able to get a list of it's parents via Bar or it's children via Bar. I am also using the declarative_base system rather than table/ mapper defined seperately. class Foo(Base): id = Column(Integer, primary_key=True) class Bar(Base): parent_id = Column(Integer, default=0) child_id = Column(Integer, default=0) So, I thought something like ; children = relation(Foo, backref=backref('parents'), primaryjoin=and_(Foo.id==Bar.parent_id) But that's where I hit the 'wall' as it were, is there a way to setup a synonym for Foo in the primaryjoin clause ? Am I missing something stupid ? (I am okay with that ;) Regards Stef --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Self Join via Join Table ?
I am doing something similar. The following code works for me in SQLA .4.8 class Foo(Base): __tablename__ = 'foo' id = Column(Integer, primary_key=True) bar_table = Table('bar', Base.metadata, Column('parent_id', Integer, ForeignKey('foo.id'), nullable=False), Column('child_id', Integer, ForeignKey('foo.id'), nullable=False)) Foo.children = relation(Foo, secondary = bar_table, primaryjoin = bar_table.c.parent_id == Foo.id, secondaryjoin=bar_table.c.child_id == Foo.id, backref='parents') On Wed, Feb 25, 2009 at 3:12 PM, Stephen Telford stelford1...@gmail.com wrote: Okay, that sounds like a plan but., not to sound too much like a broken record, does anyone have an -actual- example ? looking at pages with a lot of API's is not really going to help me too much :( This maybe slightly off-topic and it's really NOT meant as flamebait but.. I remember a while ago playing around with DBIx (the perl ORM) and one of the things that -really- made it easy to get to grips with as the DBIx::Cookbook. It maybe a good idea to fling something similiar into the sqlalchemy documentation... if I had more experience I would write it but.. yes. It definitely is the quickest ORM I have seen/used, but, all the speed is for naught if you hit the 20% wall. Regards Stef On Wed, Feb 25, 2009 at 4:21 PM, Michael Bayer mike...@zzzcomputing.com wrote: check out the association proxy extension if you're looking to have Bar be hidden as an association object. it will ultimately use Foo/Bar for querying but attribute access would be proxied through the names you confgure. On Feb 25, 2009, at 4:11 PM, Stephen Telford wrote: Hello Az, Yes, Bar is the association table of Foo to Foo. In essence, this is a self join through a join table.. I have tried and hit my head on this for (quite literally) hours. In the end, and for the record, I ended up creating a method on the model itself such as ; def children(self): childFoo=Foo.__table__.alias() return object_session(self).query(Foo).filter(and_(childFoo.c.deleted == 0, childFoo.id self.id, self.id == Bar.parent_id)) Not the prettiest way, nor what I would expect, but in lieu of an actual example, and to help anyone who ends up treading the same path as me, I hope this helps. Regards Stef On Wed, Feb 25, 2009 at 4:29 AM, a...@svilendobrev.com wrote: u mean, the Bar is an association table of Foo to Foo? u have to use secondary_table and/or secondary_join in the relation setup. And probably specify remote_side or it may not know which Foo is what. On Wednesday 25 February 2009 03:39:20 Stef wrote: Hello Everyone, First of all, kudos on SQLAlchemy.. the speed is pretty amazing - I am coming from the SQLObject world and there is a definite difference. Excellent work. I am also getting to grips with it pretty quickly, using object_session and all that good stuff. This said, I have hit that 20% problem, and am hoping someone can shine a light on it. I have a table, lets call it Foo and another table Bar. Foo should be able to get a list of it's parents via Bar or it's children via Bar. I am also using the declarative_base system rather than table/ mapper defined seperately. class Foo(Base): id = Column(Integer, primary_key=True) class Bar(Base): parent_id = Column(Integer, default=0) child_id = Column(Integer, default=0) So, I thought something like ; children = relation(Foo, backref=backref('parents'), primaryjoin=and_(Foo.id==Bar.parent_id) But that's where I hit the 'wall' as it were, is there a way to setup a synonym for Foo in the primaryjoin clause ? Am I missing something stupid ? (I am okay with that ;) Regards Stef --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Self Join via Join Table ?
Thank you Bobby!! That does make things more easier, and it shows then that I am being a -real- moron here.. from sqlalchemy import * from sqlalchemy.orm import sessionmaker, mapper, relation meta = MetaData() meta.bind = 'postgres://root:sxta...@192.168.2.198/compass_master' engine = create_engine('postgres:// root:mypassw...@192.168.2.198/compass_master', echo=True) Session = sessionmaker(bind=engine) session = Session() trip_table = Table('trip', meta, autoload=True) class Trip(object): id = Column(Integer, primary_key=True) trip = mapper(Trip, trip_table) trip_pc_table = Table('trip_parent_child', meta, autoload=True) class TripParentChild(object): parent_id = Column(Integer, ForeignKey('Trip.id'), nullable=False) parent = relation(Trip) child_id = Column(Integer, ForeignKey('Trip.id'), nullable=False) child = relation(Trip) trip_pc = mapper(TripParentChild, trip_pc_table) Trip.children = relation(Trip, secondary = trip_table, primaryjoin = TripParentChild.parent_id == Trip.id, secondaryjoin=TripParentChild.child_id == Trip.id) Trip.parent = relation(Trip, secondary = trip_table, primaryjoin = TripParentChild.child_id == Trip.id, secondaryjoin=TripParentChild.parent_id == Trip.id) s = session.query(Trip).get(194143) print s.children results in a very nice stack trace; Traceback (most recent call last): File ./s.py, line 37, in module print s.children File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/properties.py, line 628, in __str__ return str(self.parent.class_.__name__) + . + self.key AttributeError: 'RelationProperty' object has no attribute 'parent' Any thoughts ? I suspect some attempt at 'black magic' in regards to the parent_id Regards Stef On Wed, Feb 25, 2009 at 7:05 PM, Bobby Impollonia bob...@gmail.com wrote: I am doing something similar. The following code works for me in SQLA .4.8 class Foo(Base): __tablename__ = 'foo' id = Column(Integer, primary_key=True) bar_table = Table('bar', Base.metadata, Column('parent_id', Integer, ForeignKey('foo.id'), nullable=False), Column('child_id', Integer, ForeignKey('foo.id'), nullable=False)) Foo.children = relation(Foo, secondary = bar_table, primaryjoin = bar_table.c.parent_id == Foo.id, secondaryjoin=bar_table.c.child_id == Foo.id, backref='parents') On Wed, Feb 25, 2009 at 3:12 PM, Stephen Telford stelford1...@gmail.com wrote: Okay, that sounds like a plan but., not to sound too much like a broken record, does anyone have an -actual- example ? looking at pages with a lot of API's is not really going to help me too much :( This maybe slightly off-topic and it's really NOT meant as flamebait but.. I remember a while ago playing around with DBIx (the perl ORM) and one of the things that -really- made it easy to get to grips with as the DBIx::Cookbook. It maybe a good idea to fling something similiar into the sqlalchemy documentation... if I had more experience I would write it but.. yes. It definitely is the quickest ORM I have seen/used, but, all the speed is for naught if you hit the 20% wall. Regards Stef On Wed, Feb 25, 2009 at 4:21 PM, Michael Bayer mike...@zzzcomputing.com wrote: check out the association proxy extension if you're looking to have Bar be hidden as an association object. it will ultimately use Foo/Bar for querying but attribute access would be proxied through the names you confgure. On Feb 25, 2009, at 4:11 PM, Stephen Telford wrote: Hello Az, Yes, Bar is the association table of Foo to Foo. In essence, this is a self join through a join table.. I have tried and hit my head on this for (quite literally) hours. In the end, and for the record, I ended up creating a method on the model itself such as ; def children(self): childFoo=Foo.__table__.alias() return object_session(self).query(Foo).filter(and_(childFoo.c.deleted == 0, childFoo.id self.id, self.id == Bar.parent_id)) Not the prettiest way, nor what I would expect, but in lieu of an actual example, and to help anyone who ends up treading the same path as me, I hope this helps. Regards Stef On Wed, Feb 25, 2009 at 4:29 AM, a...@svilendobrev.com wrote: u mean, the Bar is an association table of Foo to Foo? u have to use secondary_table and/or secondary_join in the relation setup. And probably specify remote_side or it may not know which Foo is what. On Wednesday 25 February 2009 03:39:20 Stef wrote: Hello Everyone, First of all, kudos on SQLAlchemy.. the speed is pretty amazing - I am coming from the SQLObject world and there is a definite difference. Excellent work. I am also getting to grips with it pretty quickly, using object_session and all that good stuff. This said, I have hit that 20% problem, and am hoping someone can shine a light on it. I have a table, lets call it Foo and
[sqlalchemy] Re: Self Join via Join Table ?
and of course, both the passwords -are- the same (duh ;) .. the 'get()' works fine (obviously ;) Regards Stef On Wed, Feb 25, 2009 at 7:53 PM, Stephen Telford stelford1...@gmail.comwrote: Thank you Bobby!! That does make things more easier, and it shows then that I am being a -real- moron here.. from sqlalchemy import * from sqlalchemy.orm import sessionmaker, mapper, relation meta = MetaData() meta.bind = 'postgres://root:sxta...@192.168.2.198/compass_master' engine = create_engine('postgres:// root:mypassw...@192.168.2.198/compass_master', echo=True) Session = sessionmaker(bind=engine) session = Session() trip_table = Table('trip', meta, autoload=True) class Trip(object): id = Column(Integer, primary_key=True) trip = mapper(Trip, trip_table) trip_pc_table = Table('trip_parent_child', meta, autoload=True) class TripParentChild(object): parent_id = Column(Integer, ForeignKey('Trip.id'), nullable=False) parent = relation(Trip) child_id = Column(Integer, ForeignKey('Trip.id'), nullable=False) child = relation(Trip) trip_pc = mapper(TripParentChild, trip_pc_table) Trip.children = relation(Trip, secondary = trip_table, primaryjoin = TripParentChild.parent_id == Trip.id, secondaryjoin=TripParentChild.child_id == Trip.id) Trip.parent = relation(Trip, secondary = trip_table, primaryjoin = TripParentChild.child_id == Trip.id, secondaryjoin=TripParentChild.parent_id == Trip.id) s = session.query(Trip).get(194143) print s.children results in a very nice stack trace; Traceback (most recent call last): File ./s.py, line 37, in module print s.children File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/properties.py, line 628, in __str__ return str(self.parent.class_.__name__) + . + self.key AttributeError: 'RelationProperty' object has no attribute 'parent' Any thoughts ? I suspect some attempt at 'black magic' in regards to the parent_id Regards Stef On Wed, Feb 25, 2009 at 7:05 PM, Bobby Impollonia bob...@gmail.comwrote: I am doing something similar. The following code works for me in SQLA .4.8 class Foo(Base): __tablename__ = 'foo' id = Column(Integer, primary_key=True) bar_table = Table('bar', Base.metadata, Column('parent_id', Integer, ForeignKey('foo.id'), nullable=False), Column('child_id', Integer, ForeignKey('foo.id'), nullable=False)) Foo.children = relation(Foo, secondary = bar_table, primaryjoin = bar_table.c.parent_id == Foo.id, secondaryjoin=bar_table.c.child_id == Foo.id, backref='parents') On Wed, Feb 25, 2009 at 3:12 PM, Stephen Telford stelford1...@gmail.com wrote: Okay, that sounds like a plan but., not to sound too much like a broken record, does anyone have an -actual- example ? looking at pages with a lot of API's is not really going to help me too much :( This maybe slightly off-topic and it's really NOT meant as flamebait but.. I remember a while ago playing around with DBIx (the perl ORM) and one of the things that -really- made it easy to get to grips with as the DBIx::Cookbook. It maybe a good idea to fling something similiar into the sqlalchemy documentation... if I had more experience I would write it but.. yes. It definitely is the quickest ORM I have seen/used, but, all the speed is for naught if you hit the 20% wall. Regards Stef On Wed, Feb 25, 2009 at 4:21 PM, Michael Bayer mike...@zzzcomputing.com wrote: check out the association proxy extension if you're looking to have Bar be hidden as an association object. it will ultimately use Foo/Bar for querying but attribute access would be proxied through the names you confgure. On Feb 25, 2009, at 4:11 PM, Stephen Telford wrote: Hello Az, Yes, Bar is the association table of Foo to Foo. In essence, this is a self join through a join table.. I have tried and hit my head on this for (quite literally) hours. In the end, and for the record, I ended up creating a method on the model itself such as ; def children(self): childFoo=Foo.__table__.alias() return object_session(self).query(Foo).filter(and_(childFoo.c.deleted == 0, childFoo.id self.id, self.id == Bar.parent_id)) Not the prettiest way, nor what I would expect, but in lieu of an actual example, and to help anyone who ends up treading the same path as me, I hope this helps. Regards Stef On Wed, Feb 25, 2009 at 4:29 AM, a...@svilendobrev.com wrote: u mean, the Bar is an association table of Foo to Foo? u have to use secondary_table and/or secondary_join in the relation setup. And probably specify remote_side or it may not know which Foo is what. On Wednesday 25 February 2009 03:39:20 Stef wrote: Hello Everyone, First of all, kudos on SQLAlchemy.. the speed is pretty amazing - I am coming from the SQLObject world and there is a definite difference. Excellent work. I am
[sqlalchemy] Re: app memory leak - execute() with SA 0.5.2, PG 8.3, Psycopg2
Allen Bierbaum wrote: On Tue, Feb 24, 2009 at 4:44 AM, Chris Miles miles.ch...@gmail.com wrote: On Feb 22, 6:08 am, Allen Bierbaum abierb...@gmail.com wrote: Python 2.5 and later will free up garbage collected memory, handing it back to the system. Previous versions of Python would never free up memory (hence never shrink in size). Are you using Python 2.4? I am using Python 2.5. But now that I understand the issue better I have come up with a workaround. The biggest issue was that I didn't understand what I should be seeing as far as memory usage. Although your workaround may not be generally useful, it would still be nice for posterity (i.e. those searching through this thread in future) if you could summarize how you've actually addressed this issue to your satisfaction, however crude or unusual that might be. Thanks. :) -- Peter Hansen --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Self Join via Join Table ?
page 199 of the SQLAlchemy oreilly book talks about association proxy ;) On Feb 25, 2009, at 6:12 PM, Stephen Telford wrote: Okay, that sounds like a plan but., not to sound too much like a broken record, does anyone have an -actual- example ? looking at pages with a lot of API's is not really going to help me too much :( This maybe slightly off-topic and it's really NOT meant as flamebait but.. I remember a while ago playing around with DBIx (the perl ORM) and one of the things that -really- made it easy to get to grips with as the DBIx::Cookbook. It maybe a good idea to fling something similiar into the sqlalchemy documentation... if I had more experience I would write it but.. yes. It definitely is the quickest ORM I have seen/used, but, all the speed is for naught if you hit the 20% wall. Regards Stef On Wed, Feb 25, 2009 at 4:21 PM, Michael Bayer mike...@zzzcomputing.com wrote: check out the association proxy extension if you're looking to have Bar be hidden as an association object. it will ultimately use Foo/Bar for querying but attribute access would be proxied through the names you confgure. On Feb 25, 2009, at 4:11 PM, Stephen Telford wrote: Hello Az, Yes, Bar is the association table of Foo to Foo. In essence, this is a self join through a join table.. I have tried and hit my head on this for (quite literally) hours. In the end, and for the record, I ended up creating a method on the model itself such as ; def children(self): childFoo=Foo.__table__.alias() return object_session(self).query(Foo).filter(and_(childFoo.c.deleted == 0, childFoo.id self.id, self.id == Bar.parent_id)) Not the prettiest way, nor what I would expect, but in lieu of an actual example, and to help anyone who ends up treading the same path as me, I hope this helps. Regards Stef On Wed, Feb 25, 2009 at 4:29 AM, a...@svilendobrev.com wrote: u mean, the Bar is an association table of Foo to Foo? u have to use secondary_table and/or secondary_join in the relation setup. And probably specify remote_side or it may not know which Foo is what. On Wednesday 25 February 2009 03:39:20 Stef wrote: Hello Everyone, First of all, kudos on SQLAlchemy.. the speed is pretty amazing - I am coming from the SQLObject world and there is a definite difference. Excellent work. I am also getting to grips with it pretty quickly, using object_session and all that good stuff. This said, I have hit that 20% problem, and am hoping someone can shine a light on it. I have a table, lets call it Foo and another table Bar. Foo should be able to get a list of it's parents via Bar or it's children via Bar. I am also using the declarative_base system rather than table/ mapper defined seperately. class Foo(Base): id = Column(Integer, primary_key=True) class Bar(Base): parent_id = Column(Integer, default=0) child_id = Column(Integer, default=0) So, I thought something like ; children = relation(Foo, backref=backref('parents'), primaryjoin=and_(Foo.id==Bar.parent_id) But that's where I hit the 'wall' as it were, is there a way to setup a synonym for Foo in the primaryjoin clause ? Am I missing something stupid ? (I am okay with that ;) Regards Stef --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: app memory leak - execute() with SA 0.5.2, PG 8.3, Psycopg2
I hadn't described the details be there is not much to the work around and pretty application specific. The summary is that I moved some application level filtering that was being done in python code on the results into the query so less results are returned. This saves a great deal of memory in my cases and speeds up the system dramatically. Once I understood that there wasn't really a memory leak, I just optimized what was already there to use less memory. -Allen On Wed, Feb 25, 2009 at 6:59 PM, Peter Hansen pe...@engcorp.com wrote: Allen Bierbaum wrote: On Tue, Feb 24, 2009 at 4:44 AM, Chris Miles miles.ch...@gmail.com wrote: On Feb 22, 6:08 am, Allen Bierbaum abierb...@gmail.com wrote: Python 2.5 and later will free up garbage collected memory, handing it back to the system. Previous versions of Python would never free up memory (hence never shrink in size). Are you using Python 2.4? I am using Python 2.5. But now that I understand the issue better I have come up with a workaround. The biggest issue was that I didn't understand what I should be seeing as far as memory usage. Although your workaround may not be generally useful, it would still be nice for posterity (i.e. those searching through this thread in future) if you could summarize how you've actually addressed this issue to your satisfaction, however crude or unusual that might be. Thanks. :) -- Peter Hansen --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Creating SQL Expression
This works fine But in the mine case columns = [a,b,c] operator = ['+','-'] comes in the list And it can go to n number. So while adding it creates a problem My approach looping on columns i append it in to the table and hence making the object i can join them with operator to form the a+b-c but in this a b c becomes string which is not desirable i want object here i hope this will clear the picture On Feb 25, 6:40 pm, Gunnlaugur Thor Briem gunnlau...@gmail.com wrote: You can sum the column objects directly, a+b, producing a sqlalchemy.sql.expression._BinaryExpression object. t = Table('bobloblaw', MetaData(), Column('a', Integer), Column('b', Integer), Column('c', Integer)) t.c.a + t.c.b # evaluates to sqlalchemy.sql.expression._BinaryExpression object at 0x1ec9ff0 print t.c.a + t.c.b # bobloblaw.a + bobloblaw.b On Wed, Feb 25, 2009 at 1:25 PM, Ashish Bhatia ashishsinghbha...@gmail.comwrote: The problem is still their. The two seprate list of columns = List of sqlalchem object operator = ['+'','-'] using join to join them will convert the columns object to string which is not desirable. Any way to fix this. On Feb 25, 3:54 pm, Ashish Bhatia ashishsinghbha...@gmail.com wrote: sorry its resolved and working On Feb 25, 12:20 pm, Ash ashishsinghbha...@gmail.com wrote: Hello , I am trying to make query like select (a+b) from xyz; to do this xyz = sqlalchemy.Table('xyz',metadata) a = sqlalchemy.Column('a', sqlalchemy.Integer) xyz.append_column(a) b = sqlalchemy.Column('b', sqlalchemy.Integer) xyz.append_column(b) column = [(a + b)] select = sqlalchemy.select(from_obj=xyz, columns=column,distinct=True) This works fine for me. Now when the columns a and b are dynamic (Enter by the user in form of string) and the operator too comes from user columns_list = ['a','b'] operator = ['+'] like this i get the input so i make the loop and make for both the columns something like this columns = [] for x in column_list : t = sqlalchemy.Column(x, sqlalchemy.Integer) xyz.append_column(a) columns.append(t) so now how to add + to make the quer run Thanks in the advance. --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Creating SQL Expression
This works fine Thanks for the idea i will try it for the case and get back to here in the case of problem On Feb 25, 6:32 pm, King Simon-NFHD78 simon.k...@motorola.com wrote: Could you use the python 'operator' module (http://docs.python.org/library/operator.html)? Eg. (untested): import operator operations = { '+': operator.add, '-': operator.sub, # etc. } def combine_columns(op, *cols): return operations[op](*cols) sum_column = combine_columns('+', a, b) I think that should work. Simon -Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalch...@googlegroups.com] On Behalf Of Ashish Bhatia Sent: 25 February 2009 13:26 To: sqlalchemy Subject: [sqlalchemy] Re: Creating SQL Expression The problem is still their. The two seprate list of columns = List of sqlalchem object operator = ['+'','-'] using join to join them will convert the columns object to string which is not desirable. Any way to fix this. On Feb 25, 3:54 pm, Ashish Bhatia ashishsinghbha...@gmail.com wrote: sorry its resolved and working On Feb 25, 12:20 pm, Ash ashishsinghbha...@gmail.com wrote: Hello , I am trying to make query like select (a+b) from xyz; to do this xyz = sqlalchemy.Table('xyz',metadata) a = sqlalchemy.Column('a', sqlalchemy.Integer) xyz.append_column(a) b = sqlalchemy.Column('b', sqlalchemy.Integer) xyz.append_column(b) column = [(a + b)] select = sqlalchemy.select(from_obj=xyz, columns=column,distinct=True) This works fine for me. Now when the columns a and b are dynamic (Enter by the user in form of string) and the operator too comes from user columns_list = ['a','b'] operator = ['+'] like this i get the input so i make the loop and make for both the columns something like this columns = [] for x in column_list : t = sqlalchemy.Column(x, sqlalchemy.Integer) xyz.append_column(a) columns.append(t) so now how to add + to make the quer run Thanks in the advance. --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] An instance's attributes lost while the other updated.
Hi all, I have 2 user instance in a session and after I have update one of it like this --- u = session.merge(u) session.commit session.refresh(u) --- Later, I found that another instance of the same class type in the session's attributes was cleared, and triggered a database query. (I found this because I am using sqlite, which forbids access the same database in more than one thread) I will make some debug to find out what happened. --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] What's the use of expunge?
The document says: Expunge removes an object from the Session, sending persistent instances to the detached state, and pending instances to the transient state: I hoped that if an instance was expunged from a session, I might use it safely as a container of some temp data without fearing trigger any database query. But I found that if an object is 'expunge'd , it's properties will not be accessible anymore. So, when should we use expunge? Or it is kept for sqlalchemy inner use only? --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: An instance's attributes lost while the other updated.
A little more code to explain: Before commit, print u2 doesn't do trigger query. After commit, print u2 trigger a query, even if it has different primary key with u1. So this means : when u update one instance, the other instance of the same type will be in expired state. ## u1 = session.merge(u1) print -- print u2 session.commit() print -- print us ## On Feb 26, 2:17 pm, 一首诗 newpt...@gmail.com wrote: Hi all, I have 2 user instance in a session and after I have update one of it like this --- u = session.merge(u) session.commit session.refresh(u) --- Later, I found that another instance of the same class type in the session's attributes was cleared, and triggered a database query. (I found this because I am using sqlite, which forbids access the same database in more than one thread) I will make some debug to find out what happened. --~--~-~--~~~---~--~~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---