Re: ECPG: Automatic Storage allocation for NULL-pointing output variables

From: Michael Meskes <meskes(at)postgresql(dot)org>
To: Christof Petig <christof(at)petig-baender(dot)de>
Cc: Interfaces <pgsql-interfaces(at)postgresql(dot)org>, Michael Meskes <meskes(at)postgresql(dot)org>
Subject: Re: ECPG: Automatic Storage allocation for NULL-pointing output variables
Date: 2001-10-26 05:59:30
Message-ID: 20011026075930.A4120@feivel.fam-meskes.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

On Wed, Oct 24, 2001 at 01:27:48PM +0200, Christof Petig wrote:
> But ecpg does not accept
> char **var=0;

You mean the parser I guess. Well, I'm not even sure an array of strings
ever has been implemented.

> Is there any way to specify arbitrary strings of any length ?

char *var=NULL; declares an empty pointer which is then allocated by
libecpg.

> The code (execute.c:435) has also support for varchar - but how to
> declare such a variable length varchar?

Yes, as ecpg says:

ERROR: pointer to varchar are not implemented

But you should be able to work around this by using something like this:

exec sql type str is varchar[8];
...
str *var=NULL;
...

However, I did not try this, so I'm not sure.

> And the code (execute.c:432) multiplies the number of tuples with the
> longest string. But how to use this code in real life?

Sorry, I do not understand that. Where's the problem? The code is executed
after the result has been read using libpq. So it already knows all the
result strings and can calculate the longest one.

> PS: I'm willing to implement char**
> (allocate tuples*sizeof(char*) + sum(length(tuple[n])+1) bytes,

Or as it is now tuples*sizeof(char*)*max(length(tuple[n])+1) bytes.

> fill the array with pointers,
> fill the space behind the array with the actual data.
> This means just one free get's it all.

Which indeed is important.

> But this code cannot be portable!)

Which is exactly the problem.

Michael
--
Michael Meskes
Michael(at)Fam-Meskes(dot)De
Go SF 49ers! Go Rhein Fire!
Use Debian GNU/Linux! Use PostgreSQL!

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Christof Petig 2001-10-26 07:49:47 Re: ECPG: Automatic Storage allocation for NULL-pointing output
Previous Message Paul Tevis 2001-10-25 23:58:49 PyGreSQL and Unlinking Large Objects