Обсуждение: ERROR: invalid datatype 'FILE'
Hi
I am trying to migrate informix Esql/C application to PostgeSQL using ecpg.
I have a structure in the code, where one of the element data type is
non-primitive. When i try to complile the code it throws following error
message.
ERROR: invalid datatype 'FILE'
Program Code
#include <stdlib.h>
#include <stdio.h>
EXEC SQL BEGIN DECLARE SECTION;
struct rid_ds
{
double de_re_rid;
double de_re_xrid;
FILE *fp;
} dbinfo_t;
dbinfo_t dbval;
EXEC SQL END DECLARE SECTION;
main()
{
printf("Test Program :\n");
}
Below is the command i use to compile the code.
ecpg -c prog1.pgc
prog1.pgc:9: ERROR: invalid datatype 'FILE'
The same code compiles using esqlc without any problem. Is there any way to
fix about error
ECPG version:
ecpg (PostgreSQL 8.2.13) 4.2.1
RHEL 5 update 3
--
View this message in context:
http://postgresql.1045698.n5.nabble.com/ERROR-invalid-datatype-FILE-tp3365733p3365733.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.
On 1 February 2011 20:03, Amish <amish.pandya@in.com> wrote:
> ERROR: invalid datatype 'FILE'
>
> Program Code
>
> #include <stdlib.h>
> #include <stdio.h>
>
> EXEC SQL BEGIN DECLARE SECTION;
> struct rid_ds
> {
> double de_re_rid;
> double de_re_xrid;
> FILE *fp;
> } dbinfo_t;
> dbinfo_t dbval;
> EXEC SQL END DECLARE SECTION;
>
> main()
> {
>
> printf("Test Program :\n");
>
> }
>
>
> Below is the command i use to compile the code.
>
> ecpg -c prog1.pgc
>
> prog1.pgc:9: ERROR: invalid datatype 'FILE'
>
> The same code compiles using esqlc without any problem. Is there any way to
> fix about error
>
> ECPG version:
>
> ecpg (PostgreSQL 8.2.13) 4.2.1
>
> RHEL 5 update 3
I have no idea what esqlc is, but I'll hazard a guess that it by
default includes
something that actually defines FILE. FILE isn't defined in stdio.h
or stdlib.h,
for that matter, so I'm not really surprised that it won't compile.
Cheers,
Andrej
Andrej wrote:
>
>
> I have no idea what esqlc is, but I'll hazard a guess that it by
> default includes
> something that actually defines FILE. FILE isn't defined in stdio.h
> or stdlib.h,
> for that matter, so I'm not really surprised that it won't compile.
>
Actually, it is defined in stdio.h:
cat ttt.c
#include <stdio.h>
main() {
FILE *fp=fopen("/tmp/aaa","w+");
fprintf(fp,"Hello World!\n");
}
[mgogala@medo tmp]$ gcc ttt.c -o ttt
[mgogala@medo tmp]$
No complaints. It even executes. This program, of course, is bug free.
--
Mladen Gogala
Sr. Oracle DBA
1500 Broadway
New York, NY 10036
(212) 329-5251
www.vmsinfo.com
On 2 February 2011 08:13, Mladen Gogala <mladen.gogala@vmsinfo.com> wrote:
> Andrej wrote:
>>
>>
>> I have no idea what esqlc is, but I'll hazard a guess that it by
>> default includes
>> something that actually defines FILE. FILE isn't defined in stdio.h
>> or stdlib.h,
>> for that matter, so I'm not really surprised that it won't compile.
>>
>
> Actually, it is defined in stdio.h:
>
> cat ttt.c
>
> #include <stdio.h>
> main() {
> FILE *fp=fopen("/tmp/aaa","w+");
> fprintf(fp,"Hello World!\n");
> }
> [mgogala@medo tmp]$ gcc ttt.c -o ttt
> [mgogala@medo tmp]$
>
> No complaints. It even executes. This program, of course, is bug free.
I'll have to object to the "bug free" comment :)
You don't check if the fopen() call succeeded.
Also, if this code is run as root (e.g. from a cron job) then a local
user could convince it to overwrite any arbitrary file just by
creating a symlink in /tmp pointing to the file to overwrite (assuming
/tmp/aaa doesn't exist before the malicious user creates the symlink,
of course.)
--
Michael Wood <esiotrot@gmail.com>
Thanks for the reply
ESQL/C is informix utility. ESQL/C is an SQL application programming
interface (API) that enables developers to embed Structured Query Language
(SQL) statements directly into a C program. This is quite similer to ECPG.
The problem i am facing is bit different. When i remove "FILE *fp" from
declare section (ie. BEGIN DECLARE and END DECLARE) and put outside of
declare section the program compiles successfully.
e.g
#include <stdlib.h>
#include <stdio.h>
EXEC SQL BEGIN DECLARE SECTION;
struct rid_ds
{
double de_re_rid;
double de_re_xrid;
} dbinfo_t;
dbinfo_t dbval;
EXEC SQL END DECLARE SECTION;
FILE *fp;
main()
{
printf("Test Program :\n");
}
--
View this message in context:
http://postgresql.1045698.n5.nabble.com/ERROR-invalid-datatype-FILE-tp3365733p3367328.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.
Michael Wood wrote: > I'll have to object to the "bug free" comment :) > > You don't check if the fopen() call succeeded. > > Also, if this code is run as root (e.g. from a cron job) then a local > user could convince it to overwrite any arbitrary file just by > creating a symlink in /tmp pointing to the file to overwrite (assuming > /tmp/aaa doesn't exist before the malicious user creates the symlink, > of course.) > > You are correct, I admit my programming sins. With two bugs in two lines of code, I am as good as Microsoft or Oracle. I'll have to start making contributions to the Postgres community. -- Mladen Gogala Sr. Oracle DBA 1500 Broadway New York, NY 10036 (212) 329-5251 www.vmsinfo.com
On 2 February 2011 15:38, Mladen Gogala <mladen.gogala@vmsinfo.com> wrote: > Michael Wood wrote: >> >> I'll have to object to the "bug free" comment :) >> >> You don't check if the fopen() call succeeded. >> >> Also, if this code is run as root (e.g. from a cron job) then a local >> user could convince it to overwrite any arbitrary file just by >> creating a symlink in /tmp pointing to the file to overwrite (assuming >> /tmp/aaa doesn't exist before the malicious user creates the symlink, >> of course.) > > You are correct, I admit my programming sins. With two bugs in two lines of > code, I am as good as Microsoft or Oracle. I'll have to start making > contributions to the Postgres community. :) I thought afterwards that perhaps you meant we got any included bugs for free. -- Michael Wood <esiotrot@gmail.com>
On 2011-02-01, Amish <amish.pandya@in.com> wrote:
>
> Hi
> EXEC SQL BEGIN DECLARE SECTION;
> struct rid_ds
> {
> double de_re_rid;
> double de_re_xrid;
> FILE *fp;
> } dbinfo_t;
> dbinfo_t dbval;
> EXEC SQL END DECLARE SECTION;
> ERROR: invalid datatype 'FILE'
it looks to me like ecpg doesn't know how to convert FILE*
into an SQL value.
I'd say try it without the "EXEC SQL BEGIN DECLARE SECTION;"
but from inspection it appears not to be valid C either.
> The same code compiles using esqlc without any problem. Is there any way to
> fix about error
start by reading the the esqlc manual to figure out how the rules
of C change inside "EXEC SQL BEGIN DECLARE SECTION;".
file:///usr/share/doc/postgresql-doc-8.4/html/ecpg-preproc.html
suggests that "EXEC SQL INCLUDE stdio.h" might help
but that's not going to fix the broken C code two lines after the
error it's finding.
--
⚂⚃ 100% natural