INFORMIX ESQL/C query
Posted in 1999
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
I would like send the result of this query in a file:
select * from patient
Do you know if I can use a Informix ESQL/C function?
Thank you
Carinne
--
,,,
(o o)
--oOO--(_)--OOo--------------------------
| |
| Rumolo Carinne |
| Applied Mathematic & Computer Science |
| 9, Wellmann Street, Apt3 |
| Brookline MA, 02446 |
| e-mail: rumoloc@bwh.harvard.edu |
| Tel: (001)617-731-8731 |
| |
-----------------------------------------
Assuming you are using ESQL/C, one way is to open a cursor, and after
fetching each row write the row (in whatever format you want) to a file.
The file, if it is not standard out, must be opened in your C program.
For example (I'll use ansi non-compliant dollar signs instead of EXEC
SQL to save space, and I won't try to compile and test it):
#include <stdio.h>
main(int argc, char **argv)
{
$struct patient {
char p_id long;
char p_name[26];
} r_patient;
FILE *fp;
if ((fp = fopen(argv[1], "w")) == NULL)
exit(1);
$declare c1 cursor for select * from patient;
$open c1;
for (;;) {
$fetch c1 into :r_patient.p_id, :r_patient.p_name;
if (sqlca.sqlcode)
break;
fprintf(fp, "id=%d name=%s\\n", r_patient.p_id, r_patient.name);
}
$close c1'
close fp;
exit(0);
}
However, you can also used dbaccess to simply unload the table to a file
('$' is UNIX prompt, '>' is UNIX secondary prompt):
$dbaccess your db <<!
>unload to patient.unl select * from patient;!
$
Carinne Rumolo wrote:
> I would like send the result of this query in a file:
>
> select * from patient>
> Do you know if I can use a Informix ESQL/C function?
>
> Thank you
>
> Carinne
>
> --
> ,,,
> (o o)
>
> --oOO--(_)--OOo--------------------------
> | |
> | Rumolo Carinne |
> | Applied Mathematic & Computer Science |
> | 9, Wellmann Street, Apt3 |
> | Brookline MA, 02446 |
> | e-mail: rumoloc@bwh.harvard.edu |
> | Tel: (001)617-731-8731 |
> | |
> -----------------------------------------
Carinne Rumolo wrote:
>
> I would like send the result of this query in a file:
>
> select * from patient>
> Do you know if I can use a Informix ESQL/C function?
See Vic's message for an ESQL example but you can do this in dbaccess
if that is sufficient:
Report Format:
output to patients.out
select * from patients;
ASCII Delimited Format (4GL also includes an UNLOAD verb but not ESQL):
unload to patients.unl
select * form patients;
Art S. Kagel
Yes you can use ESQL/C or the unload SQL command.
ESQL/C will allow you to format the data where unload gives the data in
a
comma delimited file.
If you do use ESQL/C and you are a good C programmer, use the
sqlvar struct (if its still available...). It gives the best performance
if you know what you are doing.
-Mikey
Carinne Rumolo wrote:
> I would like send the result of this query in a file:
>
> select * from patient>
> Do you know if I can use a Informix ESQL/C function?
>
> Thank you
>
> Carinne
>
> --
> ,,,
> (o o)
>
> --oOO--(_)--OOo--------------------------
> | |
> | Rumolo Carinne |
> | Applied Mathematic & Computer Science |
> | 9, Wellmann Street, Apt3 |
> | Brookline MA, 02446 |
> | e-mail: rumoloc@bwh.harvard.edu |
> | Tel: (001)617-731-8731 |
> | |
> -----------------------------------------
HI Buddy,
I would recommend using system command to run dbaccess
system("dbaccess dbname query name > outputfile 2>/dev/null");
this will put the output of your query in the outputfile with pipe
character as delimiter.
Thanks,
Khem Chander
kchande@yahoo.com
Carinne Rumolo <rumoloc@bwh.harvard.edu> wrote in article
<3739F474.DB8@bwh.harvard.edu>...
> I would like send the result of this query in a file:
>
> select * from patient>
> Do you know if I can use a Informix ESQL/C function?
>
> Thank you
>
> Carinne
>
> --
> ,,,
> (o o)
>
> --oOO--(_)--OOo--------------------------
> | |
> | Rumolo Carinne |
> | Applied Mathematic & Computer Science |
> | 9, Wellmann Street, Apt3 |
> | Brookline MA, 02446 |
> | e-mail: rumoloc@bwh.harvard.edu |
> | Tel: (001)617-731-8731 |
> | |
> -----------------------------------------
>