Re: unload in esql
Posted in 1993
>I am using Informix v. 4.0 and the esql features.
>
>I have a database which has about 20 odd tables in it.
>I wanted to have a script which would load/unload to any
>(from) table of this database, so thought of writing an esql/c
>program.
>
>
>The problem is, the unload/load sql commands available with the
>isql are not available with esql/c.
>
>Thanks in advance,
>Please post answers on the net, as it may be difficult reaching me
>directly.
>
>Ramesh Phatak
How about declaring a cursor, open it, and fetch thru the records and output
the data to an outfile while you going thru the table?
#include <stdio.h>
$include sqlca;
$typedef struct {
char col1[10];
int col2;
} MYTAB;
void main()
FILE *fp_out;
$MYTAB b[1];
if ((fo_out=fopen("table.unl","write"))==NULL){
fprintf(stderr,"Cannot open file table.unl.\\n");
exit(1);
}
$ database mydb;
$ declare cursor GET_DATA for
select name1, name2
into $b->col1,$b->col2
from tablename
where condition exists;
$ open GET_DATA;
$ fetch GET_DATA;
while(!sqlca.sqlcode)
{
fprintf(fp_out,"%s %d\\n",b->col1,b->col2);
$fetch GET_DATA;
}
$close GET_DATA;
fclose(fp_out);
}
Bob
--
---------------------------------------------------------------------------
|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 |
---------------------------------------------------------------------------
--
---------------------------------------------------------------------------
|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 |
---------------------------------------------------------------------------