Re: ESQL/C: reading in to a structure
Posted in 1993
In article <1165@fedfil.UUCP> suma@fedfil.UUCP (Suma Vasudevan) writes:
>
>This must be a naive question, but I would appreciate if some one
>help me with this.
>
>How do I read a sql query response to a C lang. structure?
>
>$ struct t_rec { int x; char y[40]; char z[20] } ;
#include <stdio.h>
$include sqlca;
$ typedef struct {
int x;
char y[41]; /* needs to be 1+ size in database (i.e. char(19)=20 )*/
char z[21];
} STR;
main()
{
$ STR t_rec[1];
$database mydb;
$declare GET_REC cursor for
select *
into $t_rec
from mytable
where ... ;
$open GET_REC;
$fetch GET_REC;
if (!sqlca.sqlcode)
{
fprintf(stdout,"%d\\n",t_rec->x);
fprintf(stdout,"%s\\n",t_rec->y);
fprintf(stdout,"%s\\n",t_rec->z);
}
$close GET_REC;
}
Hope it helps!
Bob Beaulieu
--
---------------------------------------------------------------------------
|Bob Beaulieu Internet : bobb@netcom.com |
|EZ TRAVEL Internet : eztravel@netcom.com |
|4640-B Meridian Telephone: (408) 978-0808 |
|San Jose, CA 95124 Facsimile: (408) 978-7024 |
|+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++|
| Serving all your travel needs from start to finish |
| $$$ Best Fares $$$ |
| Great Service |
| Specializing in International Travel |
---------------------------------------------------------------------------