home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / database / ingres / 2158 < prev    next >
Encoding:
Text File  |  1993-01-05  |  5.5 KB  |  125 lines

  1. Newsgroups: comp.databases.ingres
  2. Path: sparky!uunet!gatech!asuvax!ncar!uchinews!gsbacd.uchicago.edu!cs_mj
  3. From: cs_mj@gsbacd.uchicago.edu (Mark Jaeger)
  4. Subject: Re: Help - ABF/4GL questions.
  5. Message-ID: <1993Jan5.012234.1@gsbacd.uchicago.edu>
  6. Lines: 113
  7. Sender: news@uchinews.uchicago.edu (News System)
  8. Organization:     
  9. References: <921231133516.8e63@ILP.MIT.EDU>
  10. Date: Tue, 5 Jan 1993 07:22:34 GMT
  11.  
  12. In article <921231133516.8e63@ILP.MIT.EDU>, GOLD@ILP.MIT.EDU (Mark D. Gold) 
  13. writes:
  14.  
  15. > I'm having several problems writing 4GL procedures.  I was hoping 
  16. > that an INGRES expert could point me in the right direction.
  17. > 1.  One 4GL procedure does the following work:
  18. >     a.  create temporary table x
  19. >     b.  3 large, complex inserts (with selects) into table x
  20. >     c.  3 large, complex select loops which each have
  21. >             REPEATED inserts into table x within the loops
  22. >             (the select loops also call C procedures)
  23. >
  24. >    [more repeated inserts...]
  25. >
  26. >     g.  call report passing temporary table.
  27. >
  28. > [Question: how do I use repeated inserts (for performance)
  29. > with a temporary table whose name is generated at run time
  30. > so that one user can have multiple sessions running at the same time?]
  31.  
  32. You're right that repeated queries can run substantially faster than
  33. non-repeated ones, and so it may be worthwhile to expend extra energy
  34. figuring out how to use them in a situation that is not natural for
  35. them.  This points out just one of the many problems associated with
  36. temporary tables that are generated on the fly at run time.  This leads
  37. to the solution you came to, namely, that you hard code the name of the
  38. temporary table, and each user creates a private version of the temp
  39. table while the report is running.  This leads to the problem of
  40. multiple sessions by the same user trying to access the same temp table.
  41.  
  42. > Does this mean that I have to take out an exclusive table lock on the 
  43. > temporary table (set lockmode on tablename where readlock = exclusive)
  44. > to keep another user on the same account from running the 4GL 
  45. > procedure?  How can I see if the temporary table is locked 
  46. > by another user at the start of the 4GL procedure so that I can tell 
  47. > the second user to try again later?
  48.  
  49. That's one approach.  It has the advantage that it uses INGRES locking,
  50. which is automatically cleaned up after unnatural interruptions (machine
  51. crash, user hits ^C or ^Y, etc.).  However, it has the disadvantage that
  52. you have to hang on to the lock through the whole 15 minutes it takes to
  53. populate the temp table (and then run the report).  You would have to be
  54. careful that you don't lock out other users who are trying to update the
  55. tables that you read from in order to populate the temp table.
  56.  
  57. It _is_ possible to find out if another user (or another session by the
  58. same user) has an exclusive lock on the table.  Just use lock timeouts,
  59. and try to access the table:
  60.  
  61.         commit ;
  62.         set lockmode session where timeout = 10 ;
  63.         my_form := select rct = count(*) from temp_table ;
  64.         inquire_ingres ( eno = errornumber ) ;
  65.         commit ;
  66.         set lockmode session where timeout = 0 ;
  67.         if eno = ??? then
  68.             message 'Temp table is in use.' with style = popup ; 
  69.             return ;
  70.         endif ;
  71.  
  72. > One developer suggested that I DON'T use INGRES locking to prevent 
  73. > two users in the same account from using the 4GL procedure, but 
  74. > that I create my own locking table for the database that inserts a 
  75. > row for a username when the 4GL procedure is being used and deletes 
  76. > the row when the procedure finishes.  She didn't think that relying 
  77. > on INGRES locking for what I wanted to do was a good idea.  Any 
  78. > thoughts?  However, how would I delete a row in this lock table if 
  79. > the user CTRL-Y's or CTRL-C's out of the application?
  80.  
  81. ABF uses a method like this to lock ABF applications and individual
  82. frames/procedures so that multiple developers won't accidently edit the
  83. same part of an application simultaneously.  ABF offers options to
  84. override an existing lock, or to delete an existing lock.  Take a look,
  85. it's pretty slick.
  86.  
  87. > 2.  I need to be able to run a clean_up procedure specific to each 
  88. > 4GL procedure if a user CTRL-Y's, CTRL-C's, or F6's (VMS) interrupts 
  89. > out of my application.  This local clean_up procedure would include 
  90. > deleting rows from various temporary tables and setting flags on 
  91. > other tables.
  92. >
  93. > ...I don't know how to capture any of the possible interrupts 
  94. > (CTRL-Y, CTRL-C, F6) and the rollback and then run my clean_up 
  95. > procedure.  Any ideas would be greatly appreciated.
  96.  
  97. That's a tough one.  As I understand it, an ABF application under VMS
  98. installs some executive-mode exit handlers that fire upon ^C interrupts.
  99. Other exit handlers that you install (e.g., via the C "atexit" function)
  100. are installed in user or supervisor mode, and they get ignored when
  101. there is _any_ executive-mode exit handler (I'm a little fuzzy on these
  102. details).  I found that it _was_ possible to capture a ^C interrupt from
  103. a C procedure that was called from an ABF application, but the interrupt
  104. signal handler was ignored once my C function returned to the 4GL
  105. caller.
  106.  
  107. The only suggestions I have (they aren't very helpful): 
  108.  
  109. 1. Don't_ let your users hit ^C or ^Y (how am I supposed to enforce that
  110. one?).
  111.  
  112. 2. Don't use 4GL and write your application all in C (or some other
  113. language that has interrupt handlers--Ada?).
  114.  
  115. --Mark Jaeger                internet: cs_mj@gsbvax.uchicago.edu
  116. Graduate School of Business        yellnet:  (312) 702-0328
  117. University of Chicago            faxnet:   (312) 702-0233
  118. Disclaimer: My opinions are my own and not those of my employer.
  119. Je suis un virus.  Prends ton pied et copie moi a ta .signature.
  120.  
  121.