pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Frost, Mr. Michael (contractor) <frost@nrlmry.navy.mil>
To: pgsql-interfaces@postgresql.org
Subject: PQescapeBytea & PQunescapeBytea
Date: Tue, 3 May 2005 13:51:53 -0700
Message-ID: <5188F15076BC7A4DBB705747602058C11AAB88@mailhost> (raw)

Hi.  I am running 7.4.6 of postgres.  I have some data that I desire to
store as bytea in postgres.  The data is an array of floats.  I cast the
array of floats to a unsigned char and call PQescapeBytea to prepare the
data for ingest.  I insert it into the database, and then extract it
back out.  I then call PQunescapeBytea and cast it back to float to
return it to it's original.

However, I am probably doing something incorrect, since the before /
after data is not the same.

So, I eliminate the ingest into the database, and basically just called
the PQescapeBytea & PQunescapeBytea and I get different results.

In my example, I fill an array of 10 floats with values from 0.0 to 9.0.
I then cast this to unsigned char.  I then call PQescapeBytea.

for ( i = 0; i < 10; i++ )
   prsData = ( float ) i;

pData = ( unsigned char * ) prsData;

pEscapedData = PQescapeBytea ( pData, 40, &newSize );

// newSize comes back to be 161.

Then I call PQunescapeBytea with pEscapedData.  This returns a newSize
that is different from the original.

pUnescapedData = PQunescapeBytea ( pEscapedData, &newSize );

//  newSize comes back to be 130, but I expected it to be 40.

Any insight as to what I am doing incorrectly.?

Thanks,
Michael Frost
Computer Sciences Corporation
Phone:  831-656-4723
Fax:  831-656-4769
Email:  frost@nrlmry.navy.mil

Attachments:

  [application/x-pkcs7-signature] smime.p7s (3.8K, ../5188F15076BC7A4DBB705747602058C11AAB88@mailhost/2-smime.p7s)
  download

view thread (4+ messages)  latest in thread

Message-ID: <5188F15076BC7A4DBB705747602058C11AAB88@mailhost>
Permalink:  ../5188F15076BC7A4DBB705747602058C11AAB88@mailhost/
Also on:    postgresql.org/message-id/5188F15076BC7A4DBB705747602058C11AAB88@mailhost

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: frost@nrlmry.navy.mil
  Subject: Re: PQescapeBytea & PQunescapeBytea
  In-Reply-To: <5188F15076BC7A4DBB705747602058C11AAB88@mailhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox