Re: defer interrupt
Posted in 1992
Quoting Kristjan Gaukur Kristjansson... } } I'm currently trying to figure out how to properly use 'defer interrupt' } and 'options sql interrupt on' to stop sql queries. } } I know I have to check on int_flag everywhere but when I try to use it } with 'foreach' loops then I don't seem to have much control over when } it's detected. } } Are there any guidelines out there on the best use of this feature or } something that helps me better to understand this. } (F.ex. should I rather use open,fetch,close than foreach. Shall I use it } after every possible SQL-statement or just some.) } This is how I write my query functions. It seems to work pretty good too. Here --------- Snip Here --------- Snip Here --------- Snip Here --------- Snip FUNCTION qry_address() DEFINE q_txt CHAR(512) DEFINE w_rowid INTEGER DISPLAY "QUERY: ESCAPE queries. INTERRUPT discards query. ARROW keys move cursor.", "" AT 1,1 DISPLAY "Searches the active database table.", "" AT 2,1 MESSAGE "" CLEAR FORM LET int_flag = FALSE CONSTRUCT BY NAME q_txt ON address.* HELP 2 IF int_flag THEN RETURN END IF LET q_txt = "SELECT address.ROWID FROM address WHERE ", q_txt CLIPPED WHENEVER ERROR CONTINUE OPTIONS SQL INTERRUPT ON MESSAGE "Searching ..." PREPARE q_sid FROM q_txt IF STATUS THEN CALL err_print(STATUS) OPTIONS SQL INTERRUPT OFF RETURN END IF DECLARE q_curs CURSOR FOR q_sid IF STATUS THEN CALL err_print(STATUS) OPTIONS SQL INTERRUPT OFF RETURN END IF LET q_cnt = 0 FOREACH q_curs INTO w_rowid LET q_cnt = q_cnt + 1 IF s_rowid_s(q_cnt) != 0 THEN ERROR " Memory allocation error, out of memory " OPTIONS SQL INTERRUPT OFF RETURN END IF CALL w_rowid_s(q_cnt, w_rowid) IF int_flag THEN EXIT FOREACH END IF END FOREACH OPTIONS SQL INTERRUPT OFF WHENEVER ERROR STOP MESSAGE "" IF int_flag THEN ERROR " Statement interrupted by user " SLEEP 1 END IF IF q_cnt = 0 THEN ERROR " There are no rows satisfying the conditions " LET q_cur = 0 ELSE MESSAGE q_cnt, " rows(s) found" LET q_cur = 1 END IF END FUNCTION Here --------- Snip Here --------- Snip Here --------- Snip Here --------- Snip DAS -- David Snyder @ Snide Computer Services - Folcroft, PA Current Release is db4glgen-3.7 UUCP: ..!uunet!das13!dave INTERNET: dave.snyder@snide.com