validate dynamic query before opening query

webguy

Member
Occasionally i will run into dynamic query errors via web app. I would like to validate the dynamic query prior to running the query.

I know you can do a NO-ERROR on the QUERY-PREPARE. Does anyone have a sample of checking the errors this way. I would rather stop the query from opening if errors are found with the query string.

For example if I have a dynamic query:

Code:
def var qh-customer   as handle   no-undo.

create widget-pool "customer".
create query qh-customer in widget-pool "customer".

qh-customer:set-buffers(buffer customer:handle).
qh-customer:query-prepare(ip-query-str) no-error.

/* if errors do not run query and leave .*/
/* how to check the error */

qh-customer:query-open.
if qh-customer:is-open then
do:
   repeat:
      qh-customer:get-next.
      if qh-customer:query-off-end then leave.

      display customer.customer-name etc.

   end.
end.
qh-customer:query-close().
delete object qh-customer no-error.
 

lee.bourne

Member
By far the easiest would be to use the NO-ERROR and then check the error status.

Check out ERROR-STATUS:ERROR, ERROR-STATUS:NUM-MESSAGES and ERROR-STATUS:GET-MESSAGE(1)

Lee
 

Stefan

Well-Known Member
If you are at least on 10.1C you could catch the errors:

Code:
DEFINE TEMP-TABLE tt NO-UNDO
   FIELD cc AS CHAR.


DEF VAR hq AS HANDLE.


CREATE QUERY hq.
hq:ADD-BUFFER( TEMP-TABLE tt:DEFAULT-BUFFER-HANDLE ).


IF hq:QUERY-PREPARE("for each tt where oops" ) THEN DO:


   hq:QUERY-OPEN().
   DO WHILE hq:GET-NEXT():


   END.


END.


CATCH oerror AS PROGRESS.lang.ERROR:


   MESSAGE oerror:getmessage(1) VIEW-AS ALERT-BOX.


END CATCH.
 
Top