BYTEA problem - ERROR: Bad input string for type bytea - Mailing list pgsql-general

From Reid Thompson
Subject BYTEA problem - ERROR: Bad input string for type bytea
Date
Msg-id 3DC7F9E2.2050608@ateb.com
Whole thread Raw
List pgsql-general
Could someone help me with this issue.  For initial test purposes i have
created a table with a bytea field (table = transaction, field = signature).

I open the file /usr/share/pixmaps/printer.png and read it into a
buffer.  I PQescapeBytea() this buffer and then attempt to insert the
PQescapedBytea'd buffer into the table.  I get the error "sql error
'ERROR:  Bad input string for type bytea'".

my code is below, what am i missing/doing incorrectly?
I set the debug level to 5, the log file is attached also

#include    <stdio.h>

/* include SQL Communication Area code */
EXEC SQL INCLUDE sqlca;

FILE *fp;

/* shared variables */
EXEC SQL BEGIN DECLARE SECTION;
char            *name = "rthompso";
char            *pwd = "sigcap";
unsigned char buffer[5000];
unsigned char buffer1[10001];
unsigned char *buffer2Ptr;
int readsz = 0;
unsigned int esclen;
EXEC SQL END DECLARE SECTION;
unsigned char *PQunescapeBytea(unsigned char *from, size_t *to_length);

/* print all fatal errors
EXEC SQL WHENEVER NOT FOUND DO print_not_found();
*/

EXEC SQL WHENEVER SQLERROR SQLPRINT;

void print_not_found()
{
     printf("No results were returned.\n");
}

void some_error( char *val)
{
     printf("Some error occured.[%s]\n", val);
}

int main()
{
      buffer2Ptr = &buffer1[0];

      /* open a database connection
      */
     EXEC SQL CONNECT TO tcp:postgresql://192.168.100.126:5432/sigcap AS
conn USER :name USING :pwd;
     if (!ECPGstatus(__LINE__, "conn"))
     {
         fprintf(stderr, "Unable to connect to database.\n");
         return(1);
     }

     /* execute
     */
     EXEC SQL INSERT INTO transaction (signature) VALUES ( :buffer2Ptr);
     if (sqlca.sqlcode != 0)
     {
         some_error("ERROR ON INSERT");
         printf("\nERROR [%s]\n", sqlca.sqlerrm.sqlerrmc);
     }

     if (sqlca.sqlcode < 0)
     {
         some_error("LESS THAN ZERO ERROR");
     }
     else if ( sqlca.sqlcode == 100)
     {
          some_error("EQUAL TO 100/NO DATA/END OF CURSOR");
     }
     printf("sqlca.sqlcode of  %d\n", sqlca.sqlcode);

     fclose(fp);

     /* disconnect */
     EXEC SQL DISCONNECT conn;

     return(0);
}

pgsql-general by date:

Previous
From: vzebulum@yahoo.com.br (Vidal)
Date:
Subject: Hardware estimation
Next
From: Lee Tuck
Date:
Subject: Postgresql problems