Thread: ECPG doesn't return the correct length for an empty

ECPG doesn't return the correct length for an empty

From
"Hebert, Caroline"
Date:
I understand very well your answer, however, I would like to introduce
briefly our needs and why we decided to use the "-r no_indicator" with ECPG.

We are porting a Pro*C/Oracle 7.3.4 based application (about 4000 SQL
requests) to ECPG/PostGreSQL 7.4.2.
This application mostly uses VARCHAR variables, considering (with Oracle)
any
uninitialised varchar (NULL value) as an empty string.
If we don't use the "-r no_indicator" option with ECPG, requests containing
at least one NULL value return an "ECPG_MISSING_INDICATOR" error code.
This is normal as they don't contain "null indicator" variables in their
Oracle version.

The "-r no_indicator" option, which considers NULL VARCHARs as empty
VARCHARs, seems to corresponds to the application needs.
However, if this mechanism doesn't guarantee the length field to be coherent

with the returned strings, we'll have to test the string length with :
    strlen(myVarchar.arr)
instead of simply reading
    myVarchar.len

Is there another way to get "real" empty varchars (with a correct length
associated !) instead of NULL VARCHAR values ?

However, having a positive length associated with an empty VARCHAR still
seems incoherent to me...

Thanks a lot

Regards

Caroline Hebert

-----Message d'origine-----
De : Michael Meskes [mailto:meskes@postgresql.org]
Envoye : lundi 21 juin 2004 11:13
A : Hebert, Caroline
Cc : 'pgsql-bugs@postgresql.org'
Objet : Re: [BUGS] ECPG doesn't return the correct length for an empty


On Mon, Jun 21, 2004 at 08:18:07AM +0100, Hebert, Caroline wrote:
>   Short Description : ECPG doesn't return the correct length for an empty
> VARCHAR

I'm sorry, but this is not a bug but an incorrectly used feature.

> I compiled with :
> * /usr/local/pgsql/bin/ecpg -r no_indicator pg_empty_varchar.pgc

When using "-r no_indicator" an empty string in a varchar is considered
a NULL value.  So you essantially put a NULL value in the database and
then read it and try to use it as if it was not NULL.

If you remove this option it works fine.

As an explanation, this option came in as a compatibility option to
Informix. But it can also be used without Informix as you see. I wonder
if I should make this option only callable in compatibility mode.

Michael
--
Michael Meskes
Email: Michael at Fam-Meskes dot De
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL!

Re: ECPG doesn't return the correct length for an empty

From
Michael Meskes
Date:
On Thu, Jun 24, 2004 at 02:56:04PM +0100, Hebert, Caroline wrote:
> I understand very well your answer, however, I would like to introduce
> briefly our needs and why we decided to use the "-r no_indicator" with ECPG.
> ...

I still think that you are on a risky path by misusing this feature. On
the other hand I see no reason why setting the len to 0 in case of a
NULL could be a problem for ecpg. But please keep in mind that you are
getting NULLs from the DB, not empty varchars, even if they look that
way in C.

I will commit the patch in a few minutes.

Michael

--
Michael Meskes
Email: Michael at Fam-Meskes dot De
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL!