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

  1. Path: sparky!uunet!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!usc!elroy.jpl.nasa.gov!swrinde!emory!emory!not-for-mail
  2. From: johnl@obelix.informix.com (Jonathan Leffler)
  3. Newsgroups: comp.databases.informix
  4. Subject: Re:  Help with structs and .ec
  5. Date: 12 Nov 1992 11:38:04 -0500
  6. Organization: Mailing List Gateway
  7. Lines: 91
  8. Sender: walt@mathcs.emory.edu
  9. Distribution: world
  10. Message-ID: <1du19cINN7dr@emory.mathcs.emory.edu>
  11. Reply-To: johnl@obelix.informix.com (Jonathan Leffler)
  12. NNTP-Posting-Host: emory.mathcs.emory.edu
  13. X-Informix-List-ID: <list.1593>
  14.  
  15.  
  16. I've not seen any response to this question, so I'm sending my response,
  17. which consists of a number of other questions, as well as one or two
  18. pertinent (I hope) observations.
  19.  
  20. >From: uunet!turq.b8.ingr.com!randy (Randy Paries)
  21. >Subject: Help with structs and .ec
  22. >Date: Thu, 5 Nov 92 12:26:57 CST
  23. >X-Informix-List-Id: <list.1574>
  24.  
  25. >    I am having problems fetching into a structure when using a prepare.
  26.  
  27. >    $struct open{
  28. >        int  var1;
  29. >        int  var2;
  30. >        char var3;
  31. >    };
  32. >    $struct open open_rec;
  33.  
  34. >    main()
  35. >    {
  36. >        $declare X cursor for
  37. >            select * from table where table.var1 = 2;
  38. >        $open;
  39.  
  40. ** Open what?
  41.  
  42. >        $fetch X into $open_rec;
  43. >    }
  44.  
  45. >    This above example works ok.
  46.  
  47. As in compiles OK? Or runs OK?
  48.  
  49. I don't think it should even compile, because the open statement clearly
  50. suffers from a syntax error (no cursor name).  I could easily believe that
  51. the compiler would not then analyse the fetch statement.  Also, you should be
  52. very careful about using keywords as identifiers.  OPEN is a keyword.  Using 
  53. a structure type called "open" might confuse the ESQL/C preprocessor.
  54.  
  55. >   The following example fails on the compile with the following error:
  56. >    line 13: RECORD objects 'open_rec' are not allowed in this list
  57.  
  58. >    $struct open{
  59. >        int  var1;
  60. >        int  var2;
  61. >        char var3;
  62. >    };
  63. >    $struct open open_rec;
  64.  
  65. >    main()
  66. >    {
  67. >        char qvar[200];
  68.  
  69. >        strcpy(qvar,"select * from table where table.var1 = 2");
  70.  
  71. >        $prepare Y from $qvar;
  72. >        $declare X cursor for Y;
  73. >        $open;
  74.  
  75. ** Open what?
  76.  
  77. >        $fetch X into $open_rec;
  78. >    }
  79.  
  80.  
  81. >    if I replace $fetch X into $open_rec; with
  82. >             $fetch X into $open_rec.var1,$open_rec.var2,$open_rec.var2
  83. >    it works ok.
  84.  
  85. As in compiles? Or runs?
  86.  
  87. >    The problem is the tables that I need to fetch in real life have
  88. >    LOTS of columns.
  89.  
  90. So you have five choices (at least):
  91.  
  92. (0) Fix the syntax errors in the open statements:-)
  93.  
  94. (1) Redesign your tables so they have fewer columns.
  95.  
  96. (2) Produce a program which lists all the columns in a table so that
  97.     you can generate the elements of the record automatically.
  98.  
  99. (3) Use I4GL and the RECORD LIKE facility.
  100.  
  101. (4) Write your own preprocessor to provide you with the equivalent of
  102.     the I4GL record.* facility.
  103.  
  104. Yours,
  105. Jonathan Leffler (johnl@obelix.informix.com) #include <disclaimer.h>
  106.