On Tue, Mar 4, 2008 at 4:56 PM, Thomas Mueller
<thomasmueller76 / googlemail.com> wrote:
> Thanks for your quick reply. If I understand you correctly that would
>  result in something like this being executed:
>
>
>  bc.find_all(search_specs) do |record|
>   activate("field1")  # this is what the proxy object would do
>   record["field1"] = "some value"
>   activate("field2")  # this is what the proxy object would do
>   puts record["field2"]
>  end
>
>  That wouldn't work because the fields need to be activated before I
>  query the data, basically before or at the beginning of the find_all()
>  method.
>
>  When I query for data in Siebel it issues SQL statements to the
>  database and only includes activated fields. Activating fields just
>  before accessing them doesn't work - they need to be activated before
>  querying the database.
>
>  My find_all() looks something like this:
>
>  def find_all
>   self.clear_to_query()
>   self.set_search_spec(...) # several of those, based on arguments to find_all()
>   self.execute_query()
>
>   begin
>     yield self
>   end while self.next_record() if self.first_record()
>  end
>
>  The fields need to be activated before the execute_query() call.

Hmm. That's trickier.  You could create an method on some convenient class
(or object) from the block with define_method, and then use ParseTree to get
the parse tree of that method, and walk through the resulting s-expression to
find out which fields are called. Though if any of the fields are determined
dynamically, that won't work, because you won't have the results of the
dynamic determination, just the parse tree of the code that would get it.

(My ParseTree-fu isn't strong enough to sketch out code to demonstrate that,
but conceptually, with the caveat about dynamic determination of fields,
it seems at least possible.)