pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: noreply@pgfoundry.org
To: noreply@pgfoundry.org
Subject: [ psqlodbc-Bugs-1003103 ] copy_and_convert_field(...) destroys bind info for wide char varchar columns
Date: Fri,  4 May 2007 22:01:38 +0000 (UTC)
Message-ID: <20070504220138.A5266216D0D@pgfoundry.org> (raw)

Bugs item #1003103, was opened at 2007-04-15 14:39
You can respond by visiting: 
http://pgfoundry.org/tracker/?func=detail&atid=538&aid=1003103&group_id=1000125

Category: None
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Thomas Zehbe (thomasz)
Assigned to: Nobody (None)
Summary: copy_and_convert_field(...) destroys bind info for wide char varchar columns

Initial Comment:
I'm using psqlodbc 08.02.0200 on SuSE Linux 9.3, Postgres 8.0.1 with libiodbc 3.52.5 and wxWidgets.

psqlodbcs config params are:
./configure --enable-pthreads --enable-unicode --with-iodbc CFLAGS="-ggdb -O0

The problem occured is that for varchar colums an insert is possible up to the max length, but an update only up to the count of characters of the value wich was last read.
F. E. a colum containg "12345" can't be updated to "12345aaa". It's always cut to "12345".

I found that ResolveOneParam(...) sets "used" to the number of last readed chars, instead of SQL_NTS (in fact "-3"). So on update only this number of chars is converted.

At the end of copy_and_convert_field I Found this statement:
	if (pcbValue)
		*((SQLLEN *) pcbValueBindRow) = len;
During the first read *pcbValue is "-3" for SQL_NTS columns, but the assignment sets it to the count of chars read.
I changed it to
if (pcbValue)
        if (*pcbValue >= 0)
		  *((SQLLEN *) pcbValueBindRow) = len;
so SQL_NTS is retained in *pcbValue.

Now update works

Regards,
Thomas


----------------------------------------------------------------------

>Comment By: Hiroshi Inoue (hinoue)
Date: 2007-05-04 22:01

Message:
How does your application set the column NULL ?

regards,
Hiroshi Inoue

----------------------------------------------------------------------

Comment By: Thomas Zehbe (thomasz)
Date: 2007-05-04 12:56

Message:
>You seem to be misunderstaning ODBC specs. Though wxDbTable
> shares column buffers and parameter ones, it's neither a
> requirement nor a recommendation of ODBC. 

To be honest, I never read the specs. Do I understand right:
column buffers are for data retrieval only and parameter
buffers contain the data to be used for updates/inserts?

Did a quick google search for the odbc specs, but didn't
find them. Do you have a link?

I'm wondering that wxWidgets use use dbc licke this an
doesn't at least supply the binding structures descripting
fields twice.

>Oops my mistake, what I meant was wxDbTable::SetColNull().
No PRoblem!
>You had better call SetColNull(false/true) every time
> after you changed the contents of column buffers.
>SetColNull() sets the colDef's CbValue to SQL_NTS when
> the parameter is false otherwise sets it to SQL_NULL_DATA.

>The most poper way may be to call wxDbTable::SetColumn()
>to change the content of columns because wxDbTable can
>detect all changes.
That would be hard to implement in my current code and
SetColumn() isn't an "official" call.
As all of my tables are subclasse of a single tableClass
defined by me, I used the method described in the
wxListArchive item you mentioned earlier. Setting pcbValue
to SQL_NTS for DB_DATA_TYPE_VARCHAR cols in Update() works
fine (and until now with no visible side effects).

But I will post an item on the wxList again.

Many thanks for spending your time and your help on this topic!

Regards,
Thomas



----------------------------------------------------------------------

Comment By: Hiroshi Inoue (hinoue)
Date: 2007-05-04 02:25

Message:
> WhatI don't understand is that in ResolveOneParam at line
> 3336 inteprets this parameter. The variable used is set
> in line 3231,

> where the content of apara->used is equal to the number
> of bytes last read. And apara->used in fact is a
> pointer to memory affected by the last read.

You seem to be misunderstaning ODBC specs. Though wxDbTable
 shares column buffers and parameter ones, it's neither a
 requirement nor a recommendation of ODBC. 

> I couldn't find SetNullColNull() in psqlODBC, libiodbc
> and wxWidgets. I found SetColumn() in wxWidgets,
> but it is not documented.

Oops my mistake, what I meant was wxDbTable::SetColNull().
You had better call SetColNull(false/true) every time
 after you changed the contents of column buffers.
SetColNull() sets the colDef's CbValue to SQL_NTS when
 the parameter is false otherwise sets it to SQL_NULL_DATA.

The most poper way may be to call wxDbTable::SetColumn()
to change the content of columns because wxDbTable can
detect all changes.

regards,
Hiroshi Inoue

----------------------------------------------------------------------

Comment By: Thomas Zehbe (thomasz)
Date: 2007-05-03 07:56

Message:
> Please note pcbValue(BindRow) is an output parameter not
>an i-o one.
WhatI don't understand is that in ResolveOneParam at line
3336 inteprets this parameter. The variable used is set in
line 3231, where the content of apara->used is equal to the
number of bytes last read. And apara->used in fact is a
pointer to memory affected by the last read.

>ISTM the proper way is to call SetNullColNull() when the
>column buffers are changed or change the column contents
>via SetColumn() function.

I couldn't find SetNullColNull() in psqlODBC, libiodbc and
wxWidgets. I found SetColumn() in wxWidgets, but it is not
documented.

In line 3320 of convert.c used==SQL_NTS is checked, but only
if it is in win_unicode mode. This correlates to the fact,
the as long as I didn't use unicode mode, everything works
as only the buffer pointer is copied in the SQL_C_CHAR case.



view thread (16+ messages)  latest in thread

Message-ID: <20070504220138.A5266216D0D@pgfoundry.org>
Permalink:  ../20070504220138.A5266216D0D@pgfoundry.org/
Also on:    postgresql.org/message-id/20070504220138.A5266216D0D@pgfoundry.org

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-odbc@postgresql.org
  Cc: noreply@pgfoundry.org
  Subject: Re: [ psqlodbc-Bugs-1003103 ] copy_and_convert_field(...) destroys bind info for wide char varchar columns
  In-Reply-To: <20070504220138.A5266216D0D@pgfoundry.org>
  References: <20070504220138.A5266216D0D@pgfoundry.org>

* 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