Hi ///ark (et al),
The trouble with that, I think, is that you have no way to show the
user what's actually being searched for. You have to trust that the
user correctly remembers what a particular named query does. This is
more or less important depending on the accuracy of the search
results.
That's a good point. It would be a UI nicety for the user to click
on a particular saved query and have the fields in the form
populated. That would make it very easy to "clone" new queries.
But that's not what you're asking. 
No, but the thoughts are appreciated anyway. I was merely trying to
avoid getting turned too far away from the original question. Thanks
for playing along 
The logs, of course, contain the SQL that's being sent to the
database, but that's probably not very workable. Every query goes
through a connection object. Perhaps you could hook into that.
Thanks for suggesting the hook into connection. I didn't even think
about going that route. It turns out that I didn't have to go that
deep, which is good. [I was poking all the way down in the PostgreSQL
adapter trying to get a feel for how it all works!] I finally
figured out a way to do it, and it's really not that hard.
I created lib/ar_base_extend.rb, which contains
class ActiveRecord::Base
def self.find_by_and_return_sql(sql)
sanitized_sql = sanitize_sql(sql)
return find_by_sql(sql), sanitized_sql
end
end
I required the file in environment.rb. In my models, I can now call
find_by_and_return_sql instead of find_by_sql when I want the
statement returned. So if I'm doing an order query, I would do
s = <some crazy sql statement with params>
p = {hash of params and values}
results, sql = Order.find_by_and_return_sql([s, p])
# save sql
return results
Woohoo!
///ark
Peace,
Phillip