Joachim, On Jan 14, 2014, at 12:24 AM, jtuc...@objektfabrik.de wrote:
> I cannot help with opendbx, but I can comment on the way Glorp generates SQL. > You typically write blocks of code that look like a normal Smalltalk block, > but they have limitations to what you can write in there. These blocks are > evaluated and get converted to SQL by some kind of Visitor. The SQL string is > then concatenated out of fragments. > > BUT: Glorp does not have an API to provide SQL fragments to include in a > query. So there is not an easy way to inject SQL into a Glorp genaretd query. > What you are asking for is not related to Glorp, but to the underlying DB > interface, DBXTalk in your case. Interesting. So, I guess I'm wondering, how does Glorp escape the strings? > If you want to provide the user with the ability to provide SQL clauses and > construct queries out of that, I guess you are on your own. > > So the question is: do your users write SQL fragments or are you thinking of > a tool to construct queries by example? Oh, I'm afraid I haven't been very clear. The "user" supplying the query is me, the programmer. You see, I love SQL and I love relational databases. I probably lost most of the list with that sentence. :) I'm porting this program from PHP. It's a US Census browser, if you're curious: http://census.7gf.org . Anyway, it's basically one table and a huge pile of indexes and some set queries. Each page there is just a different query or two. I got through the front page and the about page with Seaside and PostgresV3 and it works great, but now I need to handle a query with the state as a parameter. In PHP (and JDBC, and Python's DBAPI), I can say "SELECT * FROM places WHERE state = ? ORDER BY population DESC" and then supply an array with the state in it, which fills in the '?' in the query. On a project with a true object model and real behavior on the objects, this approach wouldn't scale up. But in this case, the program is just a nice frontend on a simple one-table database. Glorp is bound to be more effort than it's worth. I only brought it up thinking Glorp must be doing this kind of escaping. It sounds like you're saying it has some other mechanism though, in which there is some kind of visitor that does the escaping, and I won't be able to leverage that. > Do you provide objects to fill in some example data or do your users know the > tables? The right solution for you depends on what exactly you have in mind. > For our project we use Glorp and provide forms to enter string fragments or > number ranges or dates etc. Then we use these in Glorp's blocks. This way the > structure of the query is provided as Smalltalk-code and only user-provided > data for the right-side operand of comparisons is provided by the user. It is > extremely hard to misuse this because the query String will always be fixed > and so fragments that include SQL will always lead to SQL errors. I agree :) > I am still learning about all the powerful things Glorp can do to cunstruct > subqueries, outer joins, having clauses and stuff, but every time I find > something I am excited ;-). I have another project I am looking forward to learning Glorp for. Don't worry, I'm sure I'll need a lot of help to get that going! Thanks, — Daniel Lyons