> If order to use a struct across namespaces, the module that > defines the struct must be required into each namespace that uses the > struct.
Yes, I suspect there's some weird interaction between namespaces too, hence the topic, but that's still pretty vague. After all, the thing defining the structs is the sql package, and my modules/namespaces are importing that. > Eval almost always is the wrong answer. I wanted to pass a list to select, but select is a macro, and I didn't get how to define a macro on top of that to do what I wanted, since the macro doesn't know that one of the things being passed into it evaluates to a list, so it can't splice that list into select, hence, eval. > And thanks, Ryan, for racket-izing SQL! Maybe I can stop stapling together all of those long horrible strings now. Yes, I was quite pleasantly surprised at how comprehensive this library is! I was thinking "surely it wouldn't support arrays as they're not standard" but nope, they're covered too :) > I recommend that you take a look at section 3.7 of the documentation, "Dynamic Statement Composition and SQL Injection”, which I believe does exactly what you want. Specifically, you want to dynamically construct a select statement. I did look at that. And up until yesterday I thought "this isn't helping, I need to inject multiple select-expr's!". And today, I had a look again and thought, hey, what if I use a string that has a comma in it, and, hey, that works! i.e. the following works: #lang racket (require sql) (select (ScalarExpr:INJECT (unquote "mew, two")) #:from pokemon) It gives me `(sql-statement "SELECT mew, two FROM pokemon")` So now I know all I have to do is comma-join my list to form a string, and inject that. What I do _not_ know if that's how INJECT was meant to be used, or whether I should build a separate inject macro that uses unquote-splice instead that comma-joins the list and does some form of escaping on the columns. My first guess is that properly verifying the items in the list to be single expressions is pretty difficult, so it sounds like a bad idea, and since one select-expr is allowed to yield multiple columns (because the "db" library that will actually get the results doesn't need any info from the query, I think), my approach should be fine. As an aside, I really like python's sqlalchemy library. It makes composing sql really easy. But I think sqlalchemy would complain if a single expression yielded multiple results on the wire. Is that coupling between query and result a good thing or bad? It seems to have its pros and cons, but right now I'm depending on the lack of coupling, so that's cool on "sql"'s part. But anyway in sqlalchemy it's just all functions. In this one, it's all macros, and I'm a bit slow with Racket, trying to compose macros trips me up a bit. So I guess my goal's reachable (I should now be able to insert a list of columns into a select using a function, without needing eval or namespaces). Thanks, all, for the input. I do wish to find out how to get around the predicate thing and why it's throwing an error, in case anyone knows. PS There's also a racket package called plisqin which seemed closer to what I was looking for. Maybe in a few months or so if it clicks I'll see if I can add to that package everything I need (things like limit and distinct) and it might work out. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.