[sqlalchemy] Re: inner join and ambiguous columns
Sorry. I speak english in rare occasions. No. It is not an insert into a join. The result of a join between tables A and B is the VALUES partial set for an insert into table C. sql = A.join(B).select(A.c.id == an_id, fold_equivalents=True, use_labels=False) rec = sql.execute().fetchone() do_something(rec) sql = C.insert().values(dict(rec.items())).values(other_column_not_in_AxB=123) sql.execute() If use_labels is True then rec contains column names not recognised in C. On 19 Mar, 18:13, Michael Bayer mike...@zzzcomputing.com wrote: ... can you point me to the SQL syntax for an INSERT into a JOIN ? ... -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: 0.6 and c extensions
On 21 Mar, 21:11, Gaetan de Menten gdemen...@gmail.com wrote: On Sun, Mar 21, 2010 at 17:13, drakkan drakkan1...@gmail.com wrote: On 21 Mar, 14:31, Antoine Pitrou solip...@pitrou.net wrote: Le dimanche 21 mars 2010 à 02:10 -0700, drakkan a écrit : a really interesting feature in sa 0.6 are the c extensions, however I think they should be implemented using ctypes so if python ctypes extension is available (default in python =2.5 and available even for 2.4) the c extensions are used as default, ctypes cannot compile your own C code. Yes I know my question is why sqlalchemy wrote his own C code and not use ctypes? Correct me if I'm wrong, but AFAIK ctypes is a way to interface your Python code with external C libraries. You cannot create any new functionality with ctypes. And what I did for the C extension was rewrite in C the most speed-critical parts of *SQLAlchemy* (not of an external lib) ! You are right I misunderstood the implementation sorry I could have used cython (and I might actually rewrite what I have done thus far in cython at some point in the future), but ctypes??? -- Gaëtan de Menten -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
RE: [sqlalchemy] recommended declarative method design pattern for sessions
Daniel Robbins wrote: Hi All, One of the things that doesn't seem to be covered in the docs, and that I'm currently trying to figure out, is the recommended design pattern to use for managing sessions from declarative methods calls. Consider a declarative class User, where I want to implement a FindFriends() method: class User(Base): # declarative fields defined here def FindFriends(self): session = Session() # it's handy to use the self reference in query methods: friends = session.query(Friends).filter_by(friend=self).all() session.close() return friends Certainly, these types of methods would seem to be useful, but here's a dilemma - the above code doesn't work. Because the method uses a new session, which is guaranteed to not be the same session that was used to retrieve the original User object, the following code will fail: session = session() me = session.query(User).filter_by(name=Daniel).first() me.FindFriends() See the 'How can I get the Session for a certain object' question at http://www.sqlalchemy.org/docs/session.html#frequently-asked-questions Basically, in your FindFriends method, replace: session = Session() with: session = Session.object_session(self) 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 sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: inner join and ambiguous columns
On Mar 22, 2010, at 4:09 AM, marco vaccari wrote: Sorry. I speak english in rare occasions. No. It is not an insert into a join. The result of a join between tables A and B is the VALUES partial set for an insert into table C. sql = A.join(B).select(A.c.id == an_id, fold_equivalents=True, use_labels=False) rec = sql.execute().fetchone() do_something(rec) sql = C.insert().values(dict(rec.items())).values(other_column_not_in_AxB=123) sql.execute() If use_labels is True then rec contains column names not recognised in C. if use_labels=False/fold_equivalents=True makes the names work out perfectly then that would be the way to do it.or you can build the dict() something like dict((k.split('_')[1], v) for k, v in row.items()). We will be improving upon fold_equivalents in a future release with a similar feature. On 19 Mar, 18:13, Michael Bayer mike...@zzzcomputing.com wrote: ... can you point me to the SQL syntax for an INSERT into a JOIN ? ... -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Session user data
I have a need to pass around session-dependent application data, such as strong references to certain objects that I don't want garbage collected so they will serve as a cache for the duration of the session. For example, if the application performs a get() on a SystemParameters table, I want a strong reference to that object for the duration of the session so that subsequent get()s do not reference the database. Further, I don't wish to pass such a variable all over through-out my session to all function calls, etc. I was considering adding an attribute to the (scoped) session for this purpose at run time (I wish to avoid modifying the thirdparty source). Something that will automatically be torn down when the (scoped) session is. Can you recommend an approach or better idea? Thanks very much again. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Session user data
On Mar 22, 2010, at 9:06 AM, Kent wrote: I have a need to pass around session-dependent application data, such as strong references to certain objects that I don't want garbage collected so they will serve as a cache for the duration of the session. For example, if the application performs a get() on a SystemParameters table, I want a strong reference to that object for the duration of the session so that subsequent get()s do not reference the database. Further, I don't wish to pass such a variable all over through-out my session to all function calls, etc. I was considering adding an attribute to the (scoped) session for this purpose at run time (I wish to avoid modifying the thirdparty source). Something that will automatically be torn down when the (scoped) session is. Can you recommend an approach or better idea? subclass Query and setup caching options. There's examples in the 0.6 distro that use Beaker including one that assigns the cache to be local to the Session, but attached is a simpler version from my pycon tutorial that doesn't have any dependencies. Thanks very much again. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd; html xmlns=http://www.w3.org/1999/xhtml; xml:lang=en head title zzzeek / pycon2010 / source mdash; bitbucket.org /title meta http-equiv=Content-Type content=text/html; charset=utf-8 / meta name=description content=Mercurial hosting - we're here to serve. / meta name=keywords content=mercurial,hg,hosting,bitbucket,zzzeek,source,sourcecode,chap5/query_subclass...@191eb2c45a3a / link rel=stylesheet type=text/css href=http://bitbucket-assets.s3.amazonaws.com/css/layout.css; / meta name=google-site-verification content=GLJMpoIUjgWhrjaR6XRvBOZqe-JbiFVzUhs5iOJ1iI8 / link rel=stylesheet type=text/css href=http://bitbucket-assets.s3.amazonaws.com/css/screen.css; / link rel=stylesheet type=text/css href=http://bitbucket-assets.s3.amazonaws.com/css/print.css; media=print / link rel=search type=application/opensearchdescription+xml href=/opensearch.xml title=Bitbucket / link rel=icon href=http://bitbucket-assets.s3.amazonaws.com/img/logo_new.png; type=image/png/ script type=text/javascript src=http://bitbucket-assets.s3.amazonaws.com/js/lib/bundle.160310Mar.js;/script script type=text/javascript $(document).ready(function() { Dropdown.init(); $(.tooltip).tipsy({gravity:'s'}); }); /script noscript style type=text/css .dropdown-container-text .dropdown { position: static !important; } /style /noscript !--[if lt IE 7] style type=text/css body { behavior: url(http://bitbucket-assets.s3.amazonaws.com/css/csshover.htc); } #issues-issue pre { white-space: normal !important; } .changeset-description { white-space: normal !important; } /style script type=text/javascript $(document).ready(function(){ $('#header-wrapper').pngFix(); $('#sourcelist').pngFix(); $('.promo-signup-screenshot').pngFix(); }); /script ![endif]-- link rel=stylesheet href=http://bitbucket-assets.s3.amazonaws.com/css/highlight/trac.css; type=text/css / script type=text/javascript var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-2456069-3'], ['_trackPageview']); (function() { var ga = document.createElement('script'); ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; ga.setAttribute('async', 'true'); document.documentElement.firstChild.appendChild(ga); })(); /script /head body class= div id=main-wrapper div id=header-wrapper div id=header a href=/img src=http://bitbucket-assets.s3.amazonaws.com/img/logo_myriad.png; alt=Bitbucket id=header-wrapper-logo //a div id=header-nav div id=header-nav-login-forms form action=/account/signin/ method=post fieldset input id=id_username_header type=text class=required login name=username value=username maxlength=30 onfocus=if(this.value=='username'){this.value='';}; $(this).addClass('normaltext'); / input id=id_password_header type=password class=required login name=password value=password maxlength=128 onfocus=if(this.value=='password'){this.value='';}; $(this).addClass('normaltext'); / input type=submit name=blogin value=raquo; style=display:none; / input type=hidden name=next value=/zzzeek/pycon2010/src/tip/chap5/query_subclass.py/ /fieldset /form form name=fopenid action=/account/signin/ method=post fieldset input id=id_openid_url type=text
[sqlalchemy] @compiles: only apply in select clause, but not in where clause
Hi, I am working on the extension GeoAlchemy [1]. Currently GeoAlchemy always fetches the data for the mapped geometry attributes in the database internal format. I am trying to force GeoAlchemy to use the format WKB for the communication with the database. @compiles(MyColumn) def compile_mycolumn(element, compiler, **kw): return AsBinary(%s) % element.name I am using the compiler extension to query for the geometry in WKB. So far this works fine for loading and inserting/updating mapped objects, but it is getting a bit ugly for queries. Please consider to following query: session.query(MyPoint).filter(MyPoint.the_geom.within(polygon.the_geom)).first() After modifying the SpatialComparator, the query send to the database looks like this: SELECT AsBinary(the_geom) AS tests_the_geom, tests.id AS tests_id, tests.name AS tests_name FROM tests WHERE Within(GeomFromWKB(AsBinary(the_geom)), GeomFromWKB(%s)) LIMIT 0, 1 For this query the method compile_mycolumn(..) is called two times: one time for the select clause and one time for the where clause. The first time it is intended, but the second time I have to do this round- trip GeomFromWKB(AsBinary(the_geom)) to make it work. My question is: Is there a way to determine if the attribute is used in the select clause, so that only then the name is surrounded by the function call? Or is there another possibility to use a different format than the database internal? Thank you, Tobias [1]: http://geoalchemy.org/ -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] @compiles: only apply in select clause, but not in where clause
On Mar 22, 2010, at 12:31 PM, Tobias wrote: Hi, I am working on the extension GeoAlchemy [1]. Currently GeoAlchemy always fetches the data for the mapped geometry attributes in the database internal format. I am trying to force GeoAlchemy to use the format WKB for the communication with the database. @compiles(MyColumn) def compile_mycolumn(element, compiler, **kw): return AsBinary(%s) % element.name I am using the compiler extension to query for the geometry in WKB. So far this works fine for loading and inserting/updating mapped objects, but it is getting a bit ugly for queries. Please consider to following query: session.query(MyPoint).filter(MyPoint.the_geom.within(polygon.the_geom)).first() After modifying the SpatialComparator, the query send to the database looks like this: SELECT AsBinary(the_geom) AS tests_the_geom, tests.id AS tests_id, tests.name AS tests_name FROM tests WHERE Within(GeomFromWKB(AsBinary(the_geom)), GeomFromWKB(%s)) LIMIT 0, 1 For this query the method compile_mycolumn(..) is called two times: one time for the select clause and one time for the where clause. The first time it is intended, but the second time I have to do this round- trip GeomFromWKB(AsBinary(the_geom)) to make it work. My question is: Is there a way to determine if the attribute is used in the select clause, so that only then the name is surrounded by the function call? take a look in **kw. there should be a within_columns_clause flag. if not, try 0.6beta2. if not there, let me know. Or is there another possibility to use a different format than the database internal? Thank you, Tobias [1]: http://geoalchemy.org/ -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] callproc support
That's getting closer. Now if I could just figure out how to get it to use the parameters that I'm actually passing in engine.execute. It appears ibm_db_sa botches the sql (to CALL BILLING.subscriber_balance()) if use the commented out cursor.callproc(statement, parameters). from sqlalchemy.ext.compiler import compiles from sqlalchemy.interfaces import ConnectionProxy from sqlalchemy.sql.expression import ClauseElement from sqlalchemy import create_engine from sqlalchemy import literal class procedure(ClauseElement): supports_execution = True _autocommit = False _execution_options = {} def __init__(self, name, *args): self.name = name self.args = args @compiles(procedure) def compile_procedure(element, compiler, **kw): return %s % (element.name) class ProcedureProxy(ConnectionProxy): def cursor_execute(self, execute, cursor, statement, parameters, context, executemany): Intercept low-level cursor execute() events. if context and isinstance(context.compiled.statement, procedure): engine.logger.info(calling stored procedure: %s, statement) if hasattr(cursor, 'callproc'): subid = 1000 balance = 0 result = cursor.callproc(statement, (subid,balance)) # result = cursor.callproc(statement, parameters) context.callproc_result = result return result else: return cursor.execute(statement, parameters) else: return execute(cursor, statement, parameters, context) engine = create_engine('ibm_db_sa://db2inst1:somegreatpassw...@x.x.x.x:xxx/BILLING', proxy=ProcedureProxy(), echo=True) subid=1000 balance=0 res = engine.execute(procedure(BILLING.subscriber_balance, subid, balance)) print res.context.callproc_result Michael Bayer wrote: On Mar 21, 2010, at 9:33 PM, Kevin Wormington wrote: As a test I altered the compile_procedure and the call to cursor.callproc and do get the values back from the stored procedure from the print res before the return. I get exceptions about the cursor being close when I try to access the ResultProxy object returned though. I think it's because the callproc returns just the results and not a cursor/set. ah well, the result proxy closes the cursor when there's no cursor.description, i.e. that theres no results to fetch. The workarounds are getting uglier here, but you can do this: result = cursor.callproc(stuff) context.callproc_result = result then on the outside when you get your result, context is there: result = conn.execute(myprocedure...) print result.context.callproc_result def compile_procedure(element, compiler, **kw): return %s % (element.name) class ProcedureProxy(ConnectionProxy): def cursor_execute(self, execute, cursor, statement, parameters, context, executemany): Intercept low-level cursor execute() events. if context and isinstance(context.compiled.statement, procedure): engine.logger.info(calling stored procedure: %s, statement) if hasattr(cursor, 'callproc'): subid = 1000 balance = 0 res = cursor.callproc(statement, (subid,balance)) print res return res #return cursor.callproc(statement, parameters) else: return cursor.execute(statement, parameters) else: return execute(cursor, statement, parameters, context) Kevin Wormington wrote: I was able to get it working from just the ibm_db_dbi interface - the actual call has to be: cursor.callproc('BILLING.subscriber_balance',(subid,balance)) these both cause the sql errors: cursor.callproc('BILLING.subscriber_balance',(1000,0)) cursor.callproc('BILLING.subscriber_balance',(1000,balance)) The compiler.process(literal you suggested results in CALL BILLING.subscriber_balance(?,?)(?,?). I tried changing it to just return element.name and get just CALL BILLING.subscriber_balance( ) sent to the DB. How can I get the return cursor.callproc(statement, parameters) to actually have the (subid,balance) in the parameters? Kevin Michael Bayer wrote: On Mar 21, 2010, at 8:07 PM, Kevin Wormington wrote: I just modified the compile to return just the procedure name and the cursor.callproc to send the statement and the two parameters as a tuple and the DB2 receives the correct SQL: CALL BILLING.subscriber_balance(?,?) But I get the following back from ibm_db_dbi: return cursor.callproc(statement, (1000,0)) File /usr/local/lib/python2.6/dist-packages/ibm_db-1.0-py2.6-linux-i686.egg/ibm_db_dbi.py, line 973, in callproc result = self._callproc_helper(procname, parameters) File /usr/local/lib/python2.6/dist-packages/ibm_db-1.0-py2.6-linux-i686.egg/ibm_db_dbi.py, line 951, in _callproc_helper raise _get_exception(inst) ibm_db_dbi.DatabaseError: ibm_db_dbi::DatabaseError: Describe Param
Re: [sqlalchemy] callproc support
On Mar 22, 2010, at 3:48 PM, Kevin Wormington wrote: That's getting closer. Now if I could just figure out how to get it to use the parameters that I'm actually passing in engine.execute. It appears ibm_db_sa botches the sql (to CALL BILLING.subscriber_balance()) if use the commented out cursor.callproc(statement, parameters). well you're right there so figure out what is different about parameters versus your tuple there. a good candidate is, parameters is probably a list, not a tuple. from sqlalchemy.ext.compiler import compiles from sqlalchemy.interfaces import ConnectionProxy from sqlalchemy.sql.expression import ClauseElement from sqlalchemy import create_engine from sqlalchemy import literal class procedure(ClauseElement): supports_execution = True _autocommit = False _execution_options = {} def __init__(self, name, *args): self.name = name self.args = args @compiles(procedure) def compile_procedure(element, compiler, **kw): return %s % (element.name) class ProcedureProxy(ConnectionProxy): def cursor_execute(self, execute, cursor, statement, parameters, context, executemany): Intercept low-level cursor execute() events. if context and isinstance(context.compiled.statement, procedure): engine.logger.info(calling stored procedure: %s, statement) if hasattr(cursor, 'callproc'): subid = 1000 balance = 0 result = cursor.callproc(statement, (subid,balance)) # result = cursor.callproc(statement, parameters) context.callproc_result = result return result else: return cursor.execute(statement, parameters) else: return execute(cursor, statement, parameters, context) engine = create_engine('ibm_db_sa://db2inst1:somegreatpassw...@x.x.x.x:xxx/BILLING', proxy=ProcedureProxy(), echo=True) subid=1000 balance=0 res = engine.execute(procedure(BILLING.subscriber_balance, subid, balance)) print res.context.callproc_result Michael Bayer wrote: On Mar 21, 2010, at 9:33 PM, Kevin Wormington wrote: As a test I altered the compile_procedure and the call to cursor.callproc and do get the values back from the stored procedure from the print res before the return. I get exceptions about the cursor being close when I try to access the ResultProxy object returned though. I think it's because the callproc returns just the results and not a cursor/set. ah well, the result proxy closes the cursor when there's no cursor.description, i.e. that theres no results to fetch. The workarounds are getting uglier here, but you can do this: result = cursor.callproc(stuff) context.callproc_result = result then on the outside when you get your result, context is there: result = conn.execute(myprocedure...) print result.context.callproc_result def compile_procedure(element, compiler, **kw): return %s % (element.name) class ProcedureProxy(ConnectionProxy): def cursor_execute(self, execute, cursor, statement, parameters, context, executemany): Intercept low-level cursor execute() events. if context and isinstance(context.compiled.statement, procedure): engine.logger.info(calling stored procedure: %s, statement) if hasattr(cursor, 'callproc'): subid = 1000 balance = 0 res = cursor.callproc(statement, (subid,balance)) print res return res #return cursor.callproc(statement, parameters) else: return cursor.execute(statement, parameters) else: return execute(cursor, statement, parameters, context) Kevin Wormington wrote: I was able to get it working from just the ibm_db_dbi interface - the actual call has to be: cursor.callproc('BILLING.subscriber_balance',(subid,balance)) these both cause the sql errors: cursor.callproc('BILLING.subscriber_balance',(1000,0)) cursor.callproc('BILLING.subscriber_balance',(1000,balance)) The compiler.process(literal you suggested results in CALL BILLING.subscriber_balance(?,?)(?,?). I tried changing it to just return element.name and get just CALL BILLING.subscriber_balance( ) sent to the DB. How can I get the return cursor.callproc(statement, parameters) to actually have the (subid,balance) in the parameters? Kevin Michael Bayer wrote: On Mar 21, 2010, at 8:07 PM, Kevin Wormington wrote: I just modified the compile to return just the procedure name and the cursor.callproc to send the statement and the two parameters as a tuple and the DB2 receives the correct SQL: CALL BILLING.subscriber_balance(?,?) But I get the following back from ibm_db_dbi: return cursor.callproc(statement, (1000,0)) File /usr/local/lib/python2.6/dist-packages/ibm_db-1.0-py2.6-linux-i686.egg/ibm_db_dbi.py, line 973,
Re: [sqlalchemy] callproc support
Michael Bayer wrote: On Mar 22, 2010, at 3:48 PM, Kevin Wormington wrote: That's getting closer. Now if I could just figure out how to get it to use the parameters that I'm actually passing in engine.execute. It appears ibm_db_sa botches the sql (to CALL BILLING.subscriber_balance()) if use the commented out cursor.callproc(statement, parameters). well you're right there so figure out what is different about parameters versus your tuple there. a good candidate is, parameters is probably a list, not a tuple. parameters is an empty list coming into ProcedureProxy.cursor_execute. Somehow the parameters aren't making it from the engine execute to cursor_execute - which probably has to do with my modification of the @compile decorator but my Python skills are not that great yet to know what to change. cursor.execute accepts either a list or tuple Thanks, Kevin -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Session user data
Michael Bayer wrote: subclass Query and setup caching options. There's examples in the 0.6 distro that use Beaker including one that assigns the cache to be local to the Session, but attached is a simpler version from my pycon tutorial that doesn't have any dependencies. !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd; html xmlns=http://www.w3.org/1999/xhtml; xml:lang=en head title zzzeek / pycon2010 / source mdash; bitbucket.org /title Er, query_subclass.py, come again? ;-) Chris -- Simplistix - Content Management, Batch Processing Python Consulting - http://www.simplistix.co.uk -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] recommended declarative method design pattern for sessions
On Mar 22, 2010, at 5:10 AM, King Simon-NFHD78 wrote: See the 'How can I get the Session for a certain object' question at http://www.sqlalchemy.org/docs/session.html#frequently-asked-questions Basically, in your FindFriends method, replace: session = Session() with: session = Session.object_session(self) The reference documentation seems to indicate that Session.object_session() will return the existing session if one exists, rather than providing a new session that must be separately closed. Is this correct? If so, then FindFriends() should not close the session acquired via Session.object_session(obj), correct? Is it possible for object_session() to return None if the object's session was previously close()d? Thanks, Daniel -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Single class to use multiple identical tables
Hi, I have a somewhat unusual database schema and was wondering what would be the best way for SQLAlchemy to handle it. For simplification purposes let's call our two basic objects Widgets and Dashboards. The widgets are divided up across 100 tables which all have identical columns, including the dashboard_id. The dashboards table has a column called table_for_widgets that contains a string like widgets55 that is the name of the table containing the widgets for that dashboard. Is there an elegant way to use this database with SQLAlchemy? Ideally I would like to be able to write something like Dashboard.widgets and have the relationship fetch the data from the correct table. I have tried using polymorphism to set up the Widgets class but it doesn't seem like you can have a polymorphic identity on a column in another table, or at least I haven't been able to think of how. Cameron -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Session user data
did I attach an HTML file ? heres a link : http://bitbucket.org/zzzeek/pycon2010/src/tip/chap5/query_subclass.py On Mar 22, 2010, at 4:14 PM, Chris Withers wrote: Michael Bayer wrote: subclass Query and setup caching options. There's examples in the 0.6 distro that use Beaker including one that assigns the cache to be local to the Session, but attached is a simpler version from my pycon tutorial that doesn't have any dependencies. !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd; html xmlns=http://www.w3.org/1999/xhtml; xml:lang=en head title zzzeek / pycon2010 / source mdash; bitbucket.org /title Er, query_subclass.py, come again? ;-) Chris -- Simplistix - Content Management, Batch Processing Python Consulting - http://www.simplistix.co.uk -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] callproc support
On Mar 22, 2010, at 4:06 PM, Kevin Wormington wrote: Michael Bayer wrote: On Mar 22, 2010, at 3:48 PM, Kevin Wormington wrote: That's getting closer. Now if I could just figure out how to get it to use the parameters that I'm actually passing in engine.execute. It appears ibm_db_sa botches the sql (to CALL BILLING.subscriber_balance()) if use the commented out cursor.callproc(statement, parameters). well you're right there so figure out what is different about parameters versus your tuple there. a good candidate is, parameters is probably a list, not a tuple. parameters is an empty list coming into ProcedureProxy.cursor_execute. Somehow the parameters aren't making it from the engine execute to cursor_execute - which probably has to do with my modification of the @compile decorator but my Python skills are not that great yet to know what to change. wheres the parameters here ? res = engine.execute(procedure(BILLING.subscriber_balance, subid, balance)) should be engine.execute(procedure(...), {'param1':p1, 'param2':p2}) cursor.execute accepts either a list or tuple Thanks, Kevin -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.