Webspeed Dynamic Query

yoachan

Member
Hi, I'm a newby in PROGRESS:o
Can anyone please tell me how to use a dynamic query within WebSpeed?
I'm reading code given by NOdrog82 http://www.progresstalk.com/showthread.php?t=76714&highlight=webspeed+dynamic+query, but I can't undertand it so clearly:confused: . Also what he profided is much more complicated than I ever need. I only need a variable table, variable fields to be find (WHERE clause) and also variable indexes, than display the result on my HTML page. as example

FOR EACH [myTable] WHERE [myTable.field1 = var1 AND
myTable.field2 = var2]
USE-INDEX [index1]
NO-LOCK.
PUT myTable.field1 myTable.field2 myTable.field3 myTable.field4.
END.

Every words in bracket "[]" are variables.
Thanks before:D
 
Hi there,

You use a dynamic query in webspeed the same as you use a dynamic query in any other progress code.
Maybe it looks complicating to make a dynamic quey, but the main advantage is that you only have to write once a procedure which handles the next previous, first last etc. (and some limited resultset functionality to return 1-n results). After the procedure has been written then you can use it anyway you like. and the resultset you requested is returned to whatever program calls for it. (being a normal browser or an html page).

If you have any specific questions, I'll be glad to answer them.

Casper.
 
displaying query

From MurrayH http://www.progresstalk.com/showthread.php?t=44114, I got this code:

...
qh:query-open().
qh:get-first().
do while not qh:query-off-end:
/*Do something lick check price field*/

qh:get-next().
end. /*do*/

qh:query-close()
...

I just want to display the result of my query. Can I just put a 'DISP' or a 'PUT' or an '{&Out}' above 'qh:get-next().' to display my records? If can, how can it be done. - I have tried DISP [table name], {&out} [table name], PUT [table name] and it's not working. - And will it works in WEBSPEED?

Thanks in advanced.
 
Hi yoachan,

you could try something like: /* works for the sports2000 database */
Code:
DEFINE VARIABLE h_query    AS HANDLE     NO-UNDO.
DEFINE VARIABLE h_buffer   AS HANDLE     NO-UNDO.
DEFINE VARIABLE l_ok AS LOGICAL    NO-UNDO.
 
CREATE QUERY h_query.
 
CREATE BUFFER h_buffer FOR TABLE "customer".
 
h_query:ADD-BUFFER(h_buffer).
 
l_ok = h_query:QUERY-PREPARE('for each customer').
IF l_ok
THEN DO:
    h_query:QUERY-OPEN().
    h_query:GET-FIRST().
    DO WHILE NOT h_query:QUERY-OFF-END:
         h_buffer  = h_query:GET-BUFFER-HANDLE(1).
        DISPLAY h_buffer:BUFFER-FIELD('custnum'):BUFFER-VALUE.
        h_query:GET-NEXT().
    END.
END.

This also works with webspeed, because webspeed is just plain 4GL (well, speedscript sounds fancy, but still it's 'only' 4GL. I made a dynamic query which fills a temp-table with all the desired field from the query. The temp-table is returned as a table-handle to the calling procedure.

Regards,

Casper.

P.S. don't forgot to cleanup:
Code:
/* dynamic cleanup variables */
DEFINE VARIABLE i_tel AS INTEGER    NO-UNDO.
DEFINE VARIABLE i_max AS INTEGER    NO-UNDO.
DEFINE VARIABLE c_buflst AS CHARACTER  NO-UNDO.
 
/* cleanup   */
DO i_tel = 1 TO h_query:NUM-BUFFERS:
    c_buflst = c_buflst + ',' + string(h_query:GET-BUFFER-HANDLE(i_tel)).
END.
 
ASSIGN i_max = NUM-ENTRIES(c_buflst).
DO i_tel = i_max TO 2 BY -1: 
    DELETE OBJECT WIDGET-HANDLE(ENTRY(i_tel,c_buflst)).
END.
DELETE OBJECT h_query.
 
I have tried u'r code. But why the "FOR EACH" query only displays the last record? I do copy and paste u'r code, (and change 'custnum' to 'cust-num') but the one and only record displayed is the last record.:confused:

Also I'd like to ask another questions: won't we need the 'QUERY-CLOSE' statement, and when should I call it, after the clean-up or before?

And if I'm using an entire .P or .HTML page only to display a report using dynamic query, will I still need to do some clean-up? I thought webspeed do processes each page, so when a page is done, all resources for that page will be automatically released. But I need - or perhaps MUST - do the clean-up thing if I have another processes in my page, so I can free the server's resources for my next processes. Please correct me if i'm wrong.
Thanks again for u'r help.:biggrin:

Best regards,

Chan
 
Hi,

In version 9.1D it is custnum... But anyway, it looks like you only see the last because your machine is probably too fast :-) If you put a pause in it you'll see all the records are retrieved.

I don't use the query-close() statement. it closes the query but doesn't invalidate the query-prepare. If you do a guery-close() then you have to do that before the cleanup, otherwise there is nothing more to close :-).

Cleanup is always good practice.

Regards,

Casper.
 
Whoaaaa!

The code is actually working :eek: . I put a 'PAUSE' and voilaaaaaa. I can see all of my records. :yippee:
Thanks a bunch!
I can sleep tight now :biggrin: :biggrin: :biggrin: :biggrin: :biggrin: :biggrin: :biggrin:
Thanks again, u are such a big help.
:)
 
Back
Top