Обсуждение: ecpg and VARCHAR

Поиск
Список
Период
Сортировка

ecpg and VARCHAR

От
Dirk Jagdmann
Дата:
Hello developers,

I'd like to get some information on VARCHAR types with ecpg. If I 
declare a VARCHAR without any size information I get a compilation error 
from my gcc 3.4.4:

--- file z.pgc ----
int main()
{  EXEC SQL BEGIN DECLARE SECTION;  VARCHAR v;  EXEC SQL END DECLARE SECTION;  return 0;
}
-------------------
z.pgc: In function `main':
z.pgc:4: error: size of array `arr' is negative

Now I suppose this negative declaration should have initialized an empty 
array and the generated sql code then allocates the space as needed?

If I declared the VARCHAR with a size everything works fine. However I'd 
like to know if the characters in the array contain a trailing 0 or if I 
have to set this explicitely?

And then I'd like to know which is the preferred way to retrieve "text" 
columns which contain arbitrary length texts with ecpg?

-- 
---> doj / cubic
----> http://cubic.org/~doj
-----> http://llg.cubic.org


Re: ecpg and VARCHAR

От
Michael Meskes
Дата:
> I'd like to get some information on VARCHAR types with ecpg. If I 
> declare a VARCHAR without any size information I get a compilation error 
> from my gcc 3.4.4:
> ...
> Now I suppose this negative declaration should have initialized an empty 
> array and the generated sql code then allocates the space as needed?

This is definitely a bug. The negative value is used internaly but
should not make it into the generated code.

> If I declared the VARCHAR with a size everything works fine. However I'd 
> like to know if the characters in the array contain a trailing 0 or if I 
> have to set this explicitely?

No, they don't unless you set it to 0.

> And then I'd like to know which is the preferred way to retrieve "text" 
> columns which contain arbitrary length texts with ecpg?

Just use "char *ptr=NULL;" libecpg will then allocate the needed memory
for you. You just have to free it later.

But then, this should also work with varchar. :-)

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


Re: ecpg and VARCHAR

От
Michael Meskes
Дата:
On Sat, Jul 09, 2005 at 11:26:00PM +0200, Dirk Jagdmann wrote:
> I'd like to get some information on VARCHAR types with ecpg. If I 
> declare a VARCHAR without any size information I get a compilation error 
> from my gcc 3.4.4:
> ...
> Now I suppose this negative declaration should have initialized an empty 
> array and the generated sql code then allocates the space as needed?

Well, actually no. You just found a way to declare a pointer to a
varchar that wasn't tested for. I will fix this test. Unfortunately it
only means that you will get an error message from ecpg. It simply is
not implemented yet. Should be easy to do but my spare time is rare at
the moment.

> If I declared the VARCHAR with a size everything works fine. However I'd 
> like to know if the characters in the array contain a trailing 0 or if I 
> have to set this explicitely?

No. With char it may, but with varchar it does not.

> And then I'd like to know which is the preferred way to retrieve "text" 
> columns which contain arbitrary length texts with ecpg?

How about 'char *'? Just make sure the pointer is NULL and you free it
after use.

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