Skip site navigation (1) Skip section navigation (2)

Re: pass date type data to PQexecparams

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: pr0v4 <josip(dot)povreslo(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: pass date type data to PQexecparams
Date: 2006-09-26 04:33:21
Message-ID: 20060926043321.GA75534@winnie.fuhr.org (view raw or flat)
Thread:
Lists: 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

In response to

Responses

pgsql-novice by date

Next:From: Michael FuhrDate: 2006-09-26 04:56:21
Subject: Re: Access to PostgreSQL database from external world
Previous:From: BobDate: 2006-09-26 02:34:45
Subject: Re: How to test a function in pgAdmin?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group