where to write small reusable functions ?

Started by Dany DeBontridderalmost 19 years ago6 messages
#1Dany DeBontridder
dany118@gmail.com

Hi,

I'm working to implement a new feature to pg_dump: the ability to dump
objects like function, indexes... And I notice that there some usefull
functions like pg_malloc, pg_calloc... So I've added pg_free to avoid the
sequence if-not-null-free-point-to-NULL, now I'd like to add a function
pg_strcat like this
char *
pg_strcat (char *dest,char *src)
{
/* pg_realloc is a safer function than realloc */
dest=pg_realloc(dest,strlen(dest)+strlen(src)+1);

strcat(dest,src);
return dest;
}

But, in that case, those functions are only usable for pg_dump, what about
the rest of code ? We don't have a central location for those small reusable
snippets of code ?

Regards,

.D.

#2Heikki Linnakangas
heikki@enterprisedb.com
In reply to: Dany DeBontridder (#1)
Re: where to write small reusable functions ?

Dany DeBontridder wrote:

I'm working to implement a new feature to pg_dump: the ability to dump
objects like function, indexes...

pg_dump already dumps functions and indexes.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

#3NikhilS
nikkhils@gmail.com
In reply to: Dany DeBontridder (#1)
Re: where to write small reusable functions ?

Hi,

char *

pg_strcat (char *dest,char *src)
{
/* pg_realloc is a safer function than realloc */
dest=pg_realloc(dest,strlen(dest)+strlen(src)+1);

strcat(dest,src);
return dest;
}

Postgres already has something for the above functionality.

See makeStringInfo, appendStringInfo.

Regards,
Nikhils
--
EnterpriseDB http://www.enterprisedb.com

#4Peter Eisentraut
peter_e@gmx.net
In reply to: Dany DeBontridder (#1)
Re: where to write small reusable functions ?

Am Freitag, 13. April 2007 14:28 schrieb Dany DeBontridder:

But, in that case, those functions are only usable for pg_dump, what about
the rest of code ? We don't have a central location for those small
reusable snippets of code ?

The main point of these functions is to catch errors and exit the program.
But that behavior is very program-dependent, so I don't think it'd be useful
to put them in a central location.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

#5Dany DeBontridder
dany118@gmail.com
In reply to: Heikki Linnakangas (#2)
Re: where to write small reusable functions ?

On 4/13/07, Heikki Linnakangas <heikki@enterprisedb.com> wrote:

Dany DeBontridder wrote:

I'm working to implement a new feature to pg_dump: the ability to dump
objects like function, indexes...

pg_dump already dumps functions and indexes.

Right but you can't dump only one or two functions or only the functions and
nothing else. (the same for index, triggers...)

D.

#6Jim C. Nasby
jim@nasby.net
In reply to: Dany DeBontridder (#5)
Re: where to write small reusable functions ?

On Fri, Apr 13, 2007 at 03:02:28PM +0200, Dany DeBontridder wrote:

On 4/13/07, Heikki Linnakangas <heikki@enterprisedb.com> wrote:

Dany DeBontridder wrote:

I'm working to implement a new feature to pg_dump: the ability to dump
objects like function, indexes...

pg_dump already dumps functions and indexes.

Right but you can't dump only one or two functions or only the functions and
nothing else. (the same for index, triggers...)

You should make sure and read past discussion about this, as well as
propose a design to the community before getting too far into a patch.
--
Jim Nasby jim@nasby.net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)