Hi,
I'm currently trying to write a dynamic query object. So I can do something like:
dynQuery:newQuery():for("Customer"):where("name", "fred"):get().
At the moment the get method returns a handle to the dynamic temp-table which allows me to use the copy-temp-table method to dump the dynamic temp-table into a static one making it easier to work with. However this feels really untidy. I was wondering if anyone could suggest a better way of doing this?
Thanks,
I would just leave out the step that copies the dynamic to static and work dynamically. It's not too hard once you get your head round it.
One thing some people miss is that you can change
bufferhandle:buffer-field("fieldname"):buffer-value
to
bufferhandle::fieldname
It makes the code a lot easier to write and read.
Resolving the buffer field handle takes time - so one can also do:
hField = BufferHandle:BufferField("FieldName").
once and then
hField:BufferValue()
as required later on.
Maybe I'm misunderstanding, but you could overload the Get() method to accept a buffer handle. This would allow you to pass in an existing temp-table handle which you could manipulate however you choose.
Something like
Def temp-table ttCust no-undo like mydb.Customer. find first ttCust no-error. message available ttCust. /* NO */ dynQuery:newQuery() :for("Customer") :where("name", "fred") :get(input buffer ttCust:handle). /* now you can do all the static code you want */ find first ttCust no-error. message available ttCust. /* YES */
The dynQuery:Get() code can be something like
method public dynQuery Get(input phbuffer as handle): hQry:open(). do while not hQry:query-off-end transaction: phbuffer;buffer-create(). phbuffer:buffer-copy(hqry:get-buffer-handle(1)). phBuffer:buffer-release() end. return this-object. finally: hqry:close(). end. end method. method public dynQuery Get(): def var hTT as handle. create temp-table hTT. /* create like etc etc etc */ return this--object:Get(hTT:default-buffer-handle). end method.
The above code works for only a single query table. multiple tables are left as an exercise for the reader.
Thanks Peter that looks exactly like that I'm aiming for. I'll give it a try in the morning and let you know.
Update: Worked a treat thanks :) this is exactly what I was trying to achieve. Now I just need to make it useful.