Re: pass date type data to PQexecparams - Mailing list pgsql-novice

From Michael Fuhr
Subject Re: pass date type data to PQexecparams
Date
Msg-id 20060926043321.GA75534@winnie.fuhr.org
Whole thread Raw
In response to pass date type data to PQexecparams  (pr0v4 <josip.povreslo@gmail.com>)
List pgsql-novice
[Please copy the mailing list on replies so others can participate
in and learn from the discussion.]

On Mon, Sep 25, 2006 at 10:35:17AM +0200, pr0v4 wrote:
> Ok, the format is binary, value is text and destination is date, I've put
> $8::text::date for 8th parameter,
> then I've got error message "ERROR : invalid byte sequence for encoding
> "SQL-ASCII":0x00 ".

Are you sure the value is of type text?  I get this error if the
value is a date in binary format and I use $8::text::date.  Have
you tried $8::date?  If so and it didn't work then what happened
(error message, misbehavior, etc.)?

> Then I've read that paramLength must be in
> network-byte-order if the data is in binary format so I've put it in network
> byte order, well after that I'm geting segmentation fault?

Where did you read that?  The length should be in host byte order,
which should be the order returned by PQgetlength().

> To be more precise I've declared date variable as char* date, then with
> PexecParams select date from table, and then with PQgetvalue
> put the date value into date variable. This work's fine because I've print
> it with printf.

Did you request binary format or text format?  What was the last
argument to PQexecParams() for the SELECT query?  What was the exact
printf() statement and what was the output?

What values did you assign to the date column's slot in paramValues,
paramLengths, and paramFormats for the INSERT?

> Before I've put the date variable in paramValues I've cast the date into
> network byte order.

If you received the date in binary format from libpq then you
shouldn't modify it if you're going to send it back to libpq.

> After all this I'm getting Segmentation fault when the code
> reached PQexecParams wich inserts the data into table ...

Please post a simple but complete program that shows what you're
doing.  For example, create the following table:

CREATE TABLE test (d date);

Have the program connect to the database, issue "SELECT current_date"
to get a date value or "SELECT current_date::text" to get a text
value, then INSERT that value into the table.  If the INSERT returns
a PQresultStatus() of other than PGRES_COMMAND_OK then use
PQresultErrorMessage() to get an error message and include that
error in your post.

--
Michael Fuhr

pgsql-novice by date:

Previous
From: Bob
Date:
Subject: Re: How to test a function in pgAdmin?
Next
From: Michael Fuhr
Date:
Subject: Re: Access to PostgreSQL database from external world