Re: Some Miscellaneous Questions on 4GL
Posted in 1991
Path: emory!europa.asd.contel.com!darwin.sura.net!jvnc.net!yale.edu!think.com!sdd.hp.com!hplabs!pyramid!infmx!jacob
From: jacob@informix.com (Jacob Salomon)
Newsgroups: comp.databases.informix
Keywords: informix scroll cursor
Message-ID: <1991Dec26.205827.14561@informix.com>
Date: 26 Dec 91 20:58:27 GMT
References: <1991Dec26.161921.9278@cbnews.cb.att.com>
Sender: news@informix.com (Usenet News)
Organization: Informix Software, Inc.
In article <1991Dec26.161921.9278@cbnews.cb.att.com>
mvctm@cbnews.cb.att.com (carl.t.mosley) writes:
|I have some questions on writing 4GL apps....I am using 2.10 for DOS:
|
|I would really like to use a scroll cursor for handling query results
|but allowing the user to "fetch previous" gets confusing if they also
|have the ability to do a delete because the delete is done on the
|table in the database and not in the temporay place where the scroll
|cursor data is kept. The manual says to not use scroll cursors for
|this reason - has anyone worked around this? It seems that in the SQL
|product, when you "run" a form, you are using some kind of ready-made
|scroll cursor for "Next" and "Previous" on the menu and yet if you
|"Remove" the current row it is gone from the active set also.
|
|Thanks
|Carl Mosley AT&T NS
|ctm@mvune.att.com
Hi Carl and all other interested eavesdroppers.
I have used the following to get around the problems you describe.
Bear in mind, however, that I am giving you a simplistic start. For
multi-table queries or ordering of data, the technique needs some
refinement.
DEFINE row_array[1000] INTEGER, lc SMALLINT
CONSTRUCT <query> ON <fields>
LET string = "SELECT rowid from <table> WHERE ", <query>
PREPARE prep_sql FROM string
DECLARE prep_curs CURSOR FOR prep_sql
LET lc = 0
FOREACH prep_curs INTO row_array[lc + 1]
LET lc = lc + 1
END FOREACH
MESSAGE lc " rows retrieved" # Just to show you a counter
LET row_num = 1
SELECT * INTO data_rec.* FROM table WHERE rowid = row_array[1]
...
down to the menu part.
...
COMMAND "Next" "Get the next record"
LET row_num = row_num + 1
SELECT * INTO data_rec.* FROM table
WHERE rowid = row_array[row_num}
DISPLAY BY NAME data_rec.*
You should get the idea; using a fixed array of rowid's, it is easy to
delete an element from the array when you delete the corresponding row
in the table.
As I said, this is a simplistic way of doing it; you can use a cursor
to fetch the record instead of a whole new SELECT. As it stands, this
will not order the retrieved data; that's for you to refine, normally
using a dummy variable to get the column you are ordering by. If it's
a view, I wash my hands of you.
Otehrwise, do try it; I have written nearly 2 dozen applications
using this technique. It works, within it's limitations.
-- Jake Salomon
---
Disclaimer: This in IMO only; not necessarily endorsed by my employer.
--
----------------Obligatory smart-$$$ remark:---------------------
| There's two kinds of people: Those who categorize people into |
| two groups and those who don't. (Aging proverb.) |
-----------------------------------------------------------------