Re: SQL problem
Posted in 1998
Siebe de Klaver wrote: > > Hello All, > > I'm using informix-esql/c. > > problem : I want to know the number of rows a select statement returns. > > 'source' : EXEC SQL prepare exec from "SELECT FROM WHERE "; > EXEC SQL declare curs for exec; > EXEC SQL open curs; > > for > { > EXEC SQL fetch curs into ... > } > > I use sqlca.sqlerrd[2] to get the number of rows. > > This value is properly filled after all the rows are fetched. > Is it possible to get the number of rows before all the fetch's? > > I'd tried fetch last followed by fetch next but that doesn`t work. > > Any suggestions ? > > Thanks in advance for the responce, > > Siebe de Klaver > > s.w.deklaver@interedge.nl No, it isn't. The database may not have actually found all the rows when you fetch the first row. You can find out how many rows there are by forcing the database to put them in a temporary table and then counting the rows in that. For many queries, this will be less efficient. A scroll cursor also puts the rows in a temporary table (as a side effect) and you can fetch the last row from that. Could you change your program logic so it does not need this information at the start of the fetch loop? If all you are doing is trying to prevent an array overflowing, why not test before each fetch? Alternatively, use a dynamically-allocated linked list, although you'll still need to test but this time for memory allocation failure. That you can't do in advance! -- Peter Lancashire Information Systems Specialist, Bayer plc Eastern Way, Bury St Edmunds, Suffolk, IP32 7AH, UK Tel: +44-1635-562258, Fax: +44-1635-562281 --- If all else fails, read the instructions. All opinions are my own and not those of Bayer plc. My Internet plumbing does not allow me to mail and post news together. Sorry. --- Join Infuse, the UK Informix User Group at http://www.infuse.org.uk/