Re: HELP - Using a cursor in 4gl
Posted in 1996
I4GL is not designed to handle arbitrary databases. Your best bet is to use ESQL/C -- you could go digging around the IIUG archives (http://www.iiug.org) for SQLCMD if you don't want to code it yourself. But I'm biassed because I wrote it. If you insist on using I4GL, then (a) you won't be able to handle byte blobs without dropping into C code, (b) I'll usually be able to make life very difficult for your code, and (c) you will have to fetch all the non-blob data into character strings which are large enough. That could be messy; a table could contain 3 byte blobs, a serial number, and 2 CHAR variables each of length 16000 characters. That's enough to give your code fits. However, if you are dealing with moderate (normal) database, you could probably get away with using CHAR(512) for most columns. You simply select the data into those variables (having worked out in advance how many columns are going to be used) and report on the clipped data. It will be messy, repetitive and error-prone coding. And determining how many columns are in the result (anything from 1 to 32767 in theory) will be fun too. And you'd have to work out how to get data into blobs for blob columns. I wouldn't bother -- I4GL is the wrong language for the job. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h> >From: apardo@unica.udc.es (Alberto Pardo Fernandez) >Date: 21 Oct 1996 16:54:33 -0100 >X-Informix-List-Id: <news.29586> > >I need to recover data from a table in a 4gl program. I dont know neither the >table name nor the table structure at compile time. Although I can find it out >at run time, I cant declare a record with DEFINE my_record RECORD LIKE tabname.* >(tabname is a variable that holds the name of my table). > >How can I access to the data recovered by the cursor? Is there any way to access >the field values of the cursor? > >DEFINE tablename CHAR(20) >DEFINE my_field CHAR(20) > . >LET sql = "select * from ", tablename > >PREPARE query FROM sql >DECLARE my_cursor CURSOR FOR query > >FOREACH my_cursor ># Here I want to access the values of the fields of my_cursor ># How can I access the field whose name is the value of my_field >END FOREACH