home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / database / informix / 2356 < prev    next >
Encoding:
Internet Message Format  |  1992-11-09  |  3.1 KB

  1. Path: sparky!uunet!destroyer!sol.ctr.columbia.edu!emory!emory!not-for-mail
  2. From: dave.snyder@snide.com (Dave Snyder)
  3. Newsgroups: comp.databases.informix
  4. Subject: Re: defer interrupt
  5. Date: 9 Nov 1992 19:43:07 -0500
  6. Organization: Mailing List Gateway
  7. Lines: 94
  8. Sender: walt@mathcs.emory.edu
  9. Distribution: world
  10. Message-ID: <1dn0irINNnsc@emory.mathcs.emory.edu>
  11. Reply-To: dave.snyder@snide.com (Dave Snyder)
  12. NNTP-Posting-Host: emory.mathcs.emory.edu
  13. X-Informix-List-ID: <list.1578>
  14.  
  15. Quoting Kristjan Gaukur Kristjansson...
  16. } I'm currently trying to figure out how to properly use 'defer interrupt'
  17. } and 'options sql interrupt on' to stop sql queries.
  18. } I know I have to check on int_flag everywhere but when I try to use it
  19. } with 'foreach' loops then I don't seem to have much control over when
  20. } it's detected.
  21. } Are there any guidelines out there on the best use of this feature or
  22. } something that helps me better to understand this.
  23. } (F.ex. should I rather use open,fetch,close than foreach.  Shall I use it
  24. } after every possible SQL-statement or just some.)
  25. This is how I write my query functions.  It seems to work pretty good too.
  26.  
  27. Here --------- Snip Here --------- Snip Here --------- Snip Here --------- Snip
  28. FUNCTION qry_address()
  29.     DEFINE  q_txt CHAR(512)
  30.     DEFINE  w_rowid INTEGER
  31.  
  32.     DISPLAY "QUERY:  ESCAPE queries.  INTERRUPT discards query.  ARROW keys move cursor.", "" AT 1,1
  33.     DISPLAY "Searches the active database table.", "" AT 2,1
  34.     MESSAGE ""
  35.  
  36.     CLEAR FORM
  37.     LET int_flag = FALSE
  38.     CONSTRUCT BY NAME q_txt ON address.* HELP 2
  39.  
  40.     IF int_flag THEN
  41.         RETURN
  42.     END IF
  43.  
  44.     LET q_txt = "SELECT address.ROWID FROM address WHERE ", q_txt CLIPPED
  45.  
  46.     WHENEVER ERROR CONTINUE
  47.     OPTIONS SQL INTERRUPT ON
  48.     MESSAGE "Searching ..."
  49.  
  50.     PREPARE q_sid FROM q_txt
  51.     IF STATUS THEN
  52.         CALL err_print(STATUS)
  53.         OPTIONS SQL INTERRUPT OFF
  54.         RETURN
  55.     END IF
  56.  
  57.     DECLARE q_curs CURSOR FOR q_sid
  58.     IF STATUS THEN
  59.         CALL err_print(STATUS)
  60.         OPTIONS SQL INTERRUPT OFF
  61.         RETURN
  62.     END IF
  63.  
  64.     LET q_cnt = 0
  65.     FOREACH q_curs INTO w_rowid
  66.         LET q_cnt = q_cnt + 1
  67.         IF s_rowid_s(q_cnt) != 0 THEN
  68.             ERROR " Memory allocation error, out of memory  "
  69.             OPTIONS SQL INTERRUPT OFF
  70.             RETURN
  71.         END IF
  72.         CALL w_rowid_s(q_cnt, w_rowid)
  73.  
  74.         IF int_flag THEN
  75.             EXIT FOREACH
  76.         END IF
  77.     END FOREACH
  78.  
  79.     OPTIONS SQL INTERRUPT OFF
  80.     WHENEVER ERROR STOP
  81.  
  82.     MESSAGE ""
  83.     IF int_flag THEN
  84.         ERROR " Statement interrupted by user  "
  85.         SLEEP 1
  86.     END IF
  87.  
  88.     IF q_cnt = 0 THEN
  89.         ERROR " There are no rows satisfying the conditions  "
  90.         LET q_cur = 0
  91.     ELSE
  92.         MESSAGE q_cnt, " rows(s) found"
  93.         LET q_cur = 1
  94.     END IF
  95. END FUNCTION
  96.  
  97.  
  98. Here --------- Snip Here --------- Snip Here --------- Snip Here --------- Snip
  99.  
  100. DAS
  101. -- 
  102. David Snyder @ Snide Computer Services - Folcroft, PA          Current Release
  103.                                                                is db4glgen-3.7
  104. UUCP:  ..!uunet!das13!dave   INTERNET:  dave.snyder@snide.com
  105.