binding 64-bit integer

Started by flying2001us@yahoo.comalmost 19 years ago5 messagesgeneral
Jump to latest
#1flying2001us@yahoo.com
flying2001us@yahoo.com

Hi all,

I'm using Solaris 10 with 64-bit libpq library.

I wanted to bind a 64-bit integer, but it failed:
"ERROR: incorrect binary data format in bind
parameter 1".

The code would succeed if the type of "val" is
uint32_t.

Doe anyone know how to fix this? Thanks a lot!

-------------------------------------------------------------------------------------------------
uint64_t val;
const char *paramValues[1];
int paramLengths[1];
int paramFormats[1];
const char *sql_clause = "SELECT * FROM mytable WHERE
mykey = $1";

paramValues[0] = (char *) &val;
paramLengths[0] = sizeof(val);
paramFormats[0] = 1;

res = PQexecParams(conn, sql_clause, 1, NULL,
paramValues, paramLengths, paramFormats, 1);

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

#2Martin Gainty
mgainty@hotmail.com
In reply to: flying2001us@yahoo.com (#1)
Re: binding 64-bit integer

Flying-
reading the source displays
http://doxygen.postgresql.org/postgres_8c-source.html

/* Trouble if it didn't eat the whole buffer */
if (!isNull && pbuf.cursor != pbuf.len)
ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("incorrect binary data format in bind
parameter %d",
paramno + 1)));

the test is
StringInfoData pbuf;

http://doxygen.postgresql.org/structStringInfoData.html#42669853a3faef1df41850bfd686cb24

pbuf.cursor (plain 32 bit int) != pbuf.len(64)

i think you found a bug....

M-
This email message and any files transmitted with it contain confidential
information intended only for the person(s) to whom this email message is
addressed. If you have received this email message in error, please notify
the sender immediately by telephone or email and destroy the original
message without making a copy. Thank you.

----- Original Message -----
From: <flying2001us@yahoo.com>
To: <pgsql-general@postgresql.org>
Sent: Thursday, April 19, 2007 9:02 PM
Subject: [GENERAL] binding 64-bit integer

Show quoted text

Hi all,

I'm using Solaris 10 with 64-bit libpq library.

I wanted to bind a 64-bit integer, but it failed:
"ERROR: incorrect binary data format in bind
parameter 1".

The code would succeed if the type of "val" is
uint32_t.

Doe anyone know how to fix this? Thanks a lot!

-------------------------------------------------------------------------------------------------
uint64_t val;
const char *paramValues[1];
int paramLengths[1];
int paramFormats[1];
const char *sql_clause = "SELECT * FROM mytable WHERE
mykey = $1";

paramValues[0] = (char *) &val;
paramLengths[0] = sizeof(val);
paramFormats[0] = 1;

res = PQexecParams(conn, sql_clause, 1, NULL,
paramValues, paramLengths, paramFormats, 1);

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: flying2001us@yahoo.com (#1)
Re: binding 64-bit integer

"flying2001us@yahoo.com" <flying2001us@yahoo.com> writes:

I wanted to bind a 64-bit integer, but it failed:
"ERROR: incorrect binary data format in bind
parameter 1".

It sorta looks like you are trying to send that value to a parameter
that the server doesn't think is int8.

regards, tom lane

#4flying2001us@yahoo.com
flying2001us@yahoo.com
In reply to: Tom Lane (#3)
Re: binding 64-bit integer

After change the SQL clause to "SELECT * from mytable WHERE mykey=$1::int8", the binding passed!

Thanks for everyone's reply.

----- Original Message ----
From: Tom Lane <tgl@sss.pgh.pa.us>
To: "flying2001us@yahoo.com" <flying2001us@yahoo.com>
Cc: pgsql-general@postgresql.org
Sent: Thursday, April 19, 2007 8:41:22 PM
Subject: Re: [GENERAL] binding 64-bit integer

"flying2001us@yahoo.com" <flying2001us@yahoo.com> writes:

I wanted to bind a 64-bit integer, but it failed:
"ERROR: incorrect binary data format in bind
parameter 1".

It sorta looks like you are trying to send that value to a parameter
that the server doesn't think is int8.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: flying2001us@yahoo.com (#4)
Re: binding 64-bit integer

"flying2001us@yahoo.com" <flying2001us@yahoo.com> writes:

After change the SQL clause to "SELECT * from mytable WHERE mykey=$1::int8", the binding passed!

If you had to insert an explicit cast, it means that "mykey" isn't int8,
which makes one wonder why you are bothering.

regards, tom lane