home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!usc!elroy.jpl.nasa.gov!swrinde!emory!emory!not-for-mail
- From: johnl@obelix.informix.com (Jonathan Leffler)
- Newsgroups: comp.databases.informix
- Subject: Re: Help with structs and .ec
- Date: 12 Nov 1992 11:38:04 -0500
- Organization: Mailing List Gateway
- Lines: 91
- Sender: walt@mathcs.emory.edu
- Distribution: world
- Message-ID: <1du19cINN7dr@emory.mathcs.emory.edu>
- Reply-To: johnl@obelix.informix.com (Jonathan Leffler)
- NNTP-Posting-Host: emory.mathcs.emory.edu
- X-Informix-List-ID: <list.1593>
-
-
- I've not seen any response to this question, so I'm sending my response,
- which consists of a number of other questions, as well as one or two
- pertinent (I hope) observations.
-
- >From: uunet!turq.b8.ingr.com!randy (Randy Paries)
- >Subject: Help with structs and .ec
- >Date: Thu, 5 Nov 92 12:26:57 CST
- >X-Informix-List-Id: <list.1574>
-
- > I am having problems fetching into a structure when using a prepare.
-
- > $struct open{
- > int var1;
- > int var2;
- > char var3;
- > };
- > $struct open open_rec;
-
- > main()
- > {
- > $declare X cursor for
- > select * from table where table.var1 = 2;
- > $open;
-
- ** Open what?
-
- > $fetch X into $open_rec;
- > }
-
- > This above example works ok.
-
- As in compiles OK? Or runs OK?
-
- I don't think it should even compile, because the open statement clearly
- suffers from a syntax error (no cursor name). I could easily believe that
- the compiler would not then analyse the fetch statement. Also, you should be
- very careful about using keywords as identifiers. OPEN is a keyword. Using
- a structure type called "open" might confuse the ESQL/C preprocessor.
-
- > The following example fails on the compile with the following error:
- > line 13: RECORD objects 'open_rec' are not allowed in this list
-
- > $struct open{
- > int var1;
- > int var2;
- > char var3;
- > };
- > $struct open open_rec;
-
- > main()
- > {
- > char qvar[200];
-
- > strcpy(qvar,"select * from table where table.var1 = 2");
-
- > $prepare Y from $qvar;
- > $declare X cursor for Y;
- > $open;
-
- ** Open what?
-
- > $fetch X into $open_rec;
- > }
-
-
- > if I replace $fetch X into $open_rec; with
- > $fetch X into $open_rec.var1,$open_rec.var2,$open_rec.var2
- > it works ok.
-
- As in compiles? Or runs?
-
- > The problem is the tables that I need to fetch in real life have
- > LOTS of columns.
-
- So you have five choices (at least):
-
- (0) Fix the syntax errors in the open statements:-)
-
- (1) Redesign your tables so they have fewer columns.
-
- (2) Produce a program which lists all the columns in a table so that
- you can generate the elements of the record automatically.
-
- (3) Use I4GL and the RECORD LIKE facility.
-
- (4) Write your own preprocessor to provide you with the equivalent of
- the I4GL record.* facility.
-
- Yours,
- Jonathan Leffler (johnl@obelix.informix.com) #include <disclaimer.h>
-