Re: Help! with ESQL cursors
Posted in 1993
Quoting Scott A Mayo... } } I am writing a database server based on informix SE. I get } handed a list of field names, and an SQL selection (=WHERE) } criteria. Then my caller want to fetch records, generally } a few at a time, and see the fields he requested for each. Not } terribly complicated. He also wants to know the total number } of records his WHERE clause netted. } The way I've handled this is as follows: 1) Declare a cursor that selects just the rowid(s) based on the user's WHERE clause. 2) Declare another cursor that selects everything based on a rowid. 3) Open the first cursor and fetch all the rowid(s) into a malloc'ed array of integers and free that 1st cursor. 4) Use whatever logic you want to move back and forth through the array of rowid(s). 5) Open the second cursor with the current array element's stored rowid, fetch the data into local variables, and close the second cursor. 6) If new user criteria arrives, start the process all over again. The advantages of this technique is that you know how many rows where fetched, where you are in the list, and how many you have left to go. If the user adds a record to the database, tack the rowid for that record onto the end of your array. This is the core logic of how db4glgen functions, you may want to pick up a copy (for examples since you are using ESQL/C). DAS -- David Snyder @ Snide Computer Services - Folcroft, PA Current Release is db4glgen-3.9 UUCP: ..!uunet!das13!dave INTERNET: dave.snyder@snide.com