BYTEA problem - ERROR: Bad input string for type bytea

From: Reid Thompson <reid(dot)thompson(at)ateb(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: BYTEA problem - ERROR: Bad input string for type bytea
Date: 2002-11-05 17:03:30
Message-ID: 3DC7F9E2.2050608@ateb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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);
}

Attachment Content-Type Size
postgres.log text/plain 65.7 KB

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Marc G. Fournier 2002-11-05 17:12:51 Re: PostgreSQL IRC Channel... who's the Admin?
Previous Message Richard Huxton 2002-11-05 16:57:08 Re: log file?