Re: [sqlalchemy] Working with a ResultProxy object
On Tue, Aug 2, 2011 at 3:07 PM, RVince rvinc...@gmail.com wrote: In my controller class, I perform a rather basic, straightforward SQL query: connection = engine.connect() trans = connection.begin() try: c.result = connection.execute(select current_disposition_code,count(*) as num from cms_input_file group by current_disposition_code;) connection.close() thus my c.result is an sqlalchemy.engine.base.ResultProxy object. When I go to render this in a mako file as: % for result in c.results: ${result.current_disposition_code}[${result.num}] % endfor I get no output. I am quite certain this is becuase I am using a ResultProxy object. How can I output such an object inthe mako files, or alternatively, how might i convert a ResultProxy objectsuch that I can output it in a mako file? Thanks! RVince Seems you missed fetching some rows from ResultProxy. http://www.sqlalchemy.org/docs/core/connections.html#sqlalchemy.engine.base.ResultProxy Hope this helps. -- 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.
Re: [sqlalchemy] Pass query with as parameter (avoid creating a method and hardcoding a query)
Sorry for late reply, but I was rather busy with real life work. I believe your code will be useful for me and for others too. Anyhow, thank you very much for it! On Thu, Jan 27, 2011 at 5:17 PM, Hector Blanco white.li...@gmail.com wrote: 2011/1/16 Tamás Bajusz gbt...@gmail.com: Is your work available, or do you plan to put it public somewhere? Mmm... maybe... contact me privately if you're interested -- 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. -- 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.
Re: [sqlalchemy] Pass query with as parameter (avoid creating a method and hardcoding a query)
Is your work available, or do you plan to put it public somewhere? On Sun, Jan 16, 2011 at 7:53 PM, Hector Blanco white.li...@gmail.com wrote: Thanks for your help! It was key knowing that I was going in the right direction. The problem was that I'm stup... erm... I mean... erm... that I made a bad mistake (beginner's one)... I was getting the comparator for the Product class: (getattr(Product, __eq__)) instead of the comparator for the field/synonym (if I wanted to check for model == 'foo', I needed to get: getattr(Product.model, __eq__). Yey!! It works! Thank you so much!! 2011/1/16 Michael Bayer mike...@zzzcomputing.com: On Jan 15, 2011, at 10:53 PM, Hector Blanco wrote: Hello list... I would like to allow the users to perform certain queries without me (or well... my server) knowing in advance what those queries are going to be (without hard-coding the query). For instance: I have a “Product” class. One of it's fields is manufacturer and another is model class Product(declarativeBase): def __init__(self): self.model = self.manufacturer = I would like the user be able to input an string with a query, such as “Product.model != 'foo' or Product.model != 'bar'” or: Product.model == 'foo' Product.manufacturer == 'bar' I have created a little Python module (queryTree) that tokenizes the string and generates a tree for that kind of queries. For the last one mentioned above, it would be something like: sqlalchemy.and_ / \ == == / \ / \ Product.model foo Product.manufacturer bar 1) The “” string can be converted to (stored as) the sqlalchemy.and_ method 2) The fields of Product are sqlalchemy.orm.synonym(s). If I pass my tree module the class I'm going to perform the query for, it can call getattr(cls, model) and get the synonym (I mean: get the Product.model synonym itself instead of the “model” string) 3) Equally, the comparators are get with getattr(Product, __eq__) or getattr(Product, __ne__) so I can store in the tree node the comparator function instead of the string “==” or “!=” But when I try to run the query: from mylibs.product import Product queryString = Product.model == 'foo' Product.manufacturer == 'bar' session.query(Product.Product).filter(queryTree.getQuery(queryString, Product.Product)) I get an exception: File /home/hbr/Documents/my-cms/backlib/product/ProductManager.py, line 62, in getByCustomFilter retval = Database.session.query(Product.Product).filter(queryTokenizer.getQuery()).all() File string, line 1, in lambda File /home/hbr/.buildout/eggs/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/query.py, line 52, in generate fn(self, *args[1:], **kw) File /home/hbr/.buildout/eggs/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/query.py, line 942, in filter filter() argument must be of type ArgumentError: filter() argument must be of type sqlalchemy.sql.ClauseElement or string Well everything I can see is correct here, so you just have to ensure getQuery() is returning the root of your tree (which, if it's an and_(), or a x == y, is in fact an instance of ClauseElement). Don't do anything with eval() or strings, keep it as a tokenized structure on your end. SQLA's job is to make it into a string. With some other tests, I've got some other exceptions that made me realize that I could possibly modify somehow the nodes of my tree until getting something that is accepted by MySQL as a valid query, but that's kind of cheating... I'd like to use pure SqlAlchemy if possible (I trust SqlAlchemy more than my programming skills) :-D the system you've built to interpret user input into a SQL expression tree should have adequate constraints such that only valid expressions are built in the first place. -- 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. -- 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. -- 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
Re: [sqlalchemy] how to graph database structure?
On Thu, Nov 11, 2010 at 12:59 PM, Nagy Viktor viktor.n...@toolpart.hu wrote: Hi, I've reflected a database, and it would like to get a graphic representation of it something like the graph_models command in django command extensions. The best would be if the tool could create the graphics without a database connection, simply using my metadata for example. I've googled for this, but couldn't find anything seemingly up-to-date. What would be your suggestion? http://www.sqlalchemy.org/trac/wiki/UsageRecipes/SchemaDisplay -- 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: sqla and firebird
On Tue, Nov 9, 2010 at 4:10 PM, Domingo Aguilera domingo.aguil...@gmail.com wrote: Werner, I am using kinterbasdb downloaded just few days ago. Also I am using sqla 0.6.5 . I worked with firebird rdbms engine several years ago but not from python. This is the first time I am using firebird from python and from sqlalchemy ( been using python since 2004 ). I have an app in which every table is created with declarative_base and in every engine I've tried, it was enough to write... id = Column( Integer, primary_key = True ) This caused every engine to use whatever is needed to have an autoincrement field. In the case of firebird+kinterbasdb it was necessary to add the Sequence in the argument of Column as ... id = Column( Integer, Sequence(whatever, optional = True ), primary_key = True ) This is documented here: http://www.sqlalchemy.org/docs/orm/tutorial.html#define-and-create-a-table -- 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] sqlalchemy and desktop apps
Hi Joel! pypapi.org is the bigest example a know. It's using pyqt4, sqlalchemy and zope interfaces/schema/etc. The only drawback for me, the code using too much italiano :) Regards, gbtami On Sat, Jul 24, 2010 at 3:21 AM, Joel Mohler goo...@kiwistrawberry.us wrote: Hello, I'm a happy user of sqlalchemy on small personal projects of my own (http://bitbucket.org/jbmohler/pyhacc is one of them which is not ready for use yet). At my day job we are in the process of evaluating platforms for a rewrite of our small business accounting system. We expect this rewrite to have 200k-300k LOC and sqlalchemy stands up well in many ways to some of the C# alternatives we are considering. The notion of writing the entire project in python is quite daunting to management who is new to opensource. I'm wondering if anyone would be kind enough to give an example of a large desktop app written in sqlalchemy (even better if it's using PyQt for the gui). We're pondering the viability of such a project in python. In particular, we do a fair bit of document logic client side with several hundred line invoice documents which we wish to edit as a whole locally and send back to the server on an explicit user save command. This is something which I wouldn't expect to typically be needful in a web application. I can certainly find examples of large websites on python via django, but desktop business applications are a bit harder to come by. I believe that eric4 is a good example but I was hoping for a largish project involving sqlalchemy as well. Thanks, Joel -- 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] Re: is sqlalchemy-migrate the right way to go?
On Mon, May 17, 2010 at 9:49 PM, Kent k...@retailarchitects.com wrote: Ideally, I agree. Practically speaking, though, we came from a company where dozens and dozens of developers worked on the system and it was structured exactly this way (a master file and a series of incremental upgrade scripts). It was always getting messed up between the two sets of schema definitions until eventually we developed a schema comparison tool and all those problems seemed to vanish. I'm obviously not saying SQLAlchemy needs to provide this, but just trying to make a case for its usefulness. Thanks for your input. I'v never tried it, but maybe miruku is what you are looking for: http://bitbucket.org/gjhiggins/miruku/wiki/Home -- 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: find the table columns
On Thu, Jan 21, 2010 at 9:08 AM, laurent FRANCOIS lau.franc...@worldonline.fr wrote: On Thu, 2010-01-14 at 05:29 -0800, Kosu wrote: try this: user.__table__.c.keys() should work Kos Rafal AttributeError: 'User' object has no attribute '__table__' from sqlalchemy import * metadata = MetaData() user = Table('user', metadata, Column('name', String)) user.c.keys() ['name'] -- 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.