C Function Problem for bytea output

Поиск
Список
Период
Сортировка
От vishal saberwal
Тема C Function Problem for bytea output
Дата
Msg-id 3e74dc250512281134v21f0501fg31223dd58058e004@mail.gmail.com
обсуждение исходный текст
Ответы Re: C Function Problem for bytea output
Список pgsql-general
hi all,

I am trying to read a file from the File System.
The function compiles fine, the function is created fine in postgres but the output is NULL/BLANK.
The file does exists and has chmod 777 permission.

PG_FUNCTION_INFO_V1(file_export);

Datum file_export(PG_FUNCTION_ARGS)
{
    char *FilePath = PG_GETARG_CSTRING(0);
    int32 FileLength = PG_GETARG_INT32(1);
    FILE *fptr;
    bytea *imdata;
    char *rp;

    imdata = (bytea *) palloc(FileLength+VARHDRSZ);
    VARATT_SIZEP(imdata) = FileLength+VARHDRSZ;
    rp = VARDATA(imdata);
    if ((fptr = fopen(FilePath, "r")) == NULL)
            PG_RETURN_NULL();
    while (!feof(fptr))
    {
        fgets(rp,1024,fptr);
        rp+=1024;
    }
    fclose(fptr);
   
    PG_RETURN_BYTEA_P(imdata);
}

select * from file_export('/ResourceFS/Alarm_Arm.gif',1219);
 file_export
-------------
 
(1 row)

I believe its something in the function but i can't spot the error.

thanks,
vish

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: POSTGRES DB 3 800 000 rows table, speed up?
Следующее
От: "Ted Byers"
Дата:
Сообщение: Re: Final stored procedure question, for now anyway