RE: [GENERAL] postgresql v6.4.2 c funcs and null text pointers...

From: "Jackson, DeJuan" <djackson(at)cpsgroup(dot)com>
To: Walt Bigelow <walt(at)stimpy(dot)com>, pgsql-general(at)postgreSQL(dot)org
Cc: PGSQL Hackers <pgsql-hackers(at)hub(dot)org>
Subject: RE: [GENERAL] postgresql v6.4.2 c funcs and null text pointers...
Date: 1999-01-08 21:07:53
Message-ID: F10BB1FAF801D111829B0060971D839F5C7E60@cpsmail
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Very observant of you. The postgres function system doesn't have a way
to tell which parameter is null, so the function just returns null.
I don't like it and we hope to get it changed for PGv6.5 (at least I
do).

Is it on the TODO guys? Jan, do you think you'll have the time to get
to it by beta?

*** Blatant flattery start ***
I'm still willing and looking for that backend mentor to truly get me
started, and I want you, Jan and Bruce, because I want the best.
BTW don't give me license to bug you unless you mean it.
*** Blatant flattery end ***
-DEJ

> -----Original Message-----
> I wrote a c func (ATTACHED BELOW) which takes 2 pointers to
> type text, and
> a bool field. When a field in a row passed to the func is
> null, espically
> the 'first' field, Postgresql does not return the value that my code
> produced.
>
> For example:
> First lastco nocompany
> ------------------------------------------
> NULL Walt Bigelow True
>
> the above data is contained in the database, and when passed
> to my c func
> like:
>
> SELECT lastfirst(first, lastco, nocompany) as name from
> tbladdress where
> agencyid = 691;
>
> I get:
> name
> ----
>
> (1 row)
>
> Not the expected output of 'Walt Bigelow, '.
>
> When I update that row with first = '', the result is correct, but the
> value is no null, so it works.
>
> What am I missing??
>
> Any help is appricated,
> Walt
>
> -------------
> name.c:
>
> #include <string.h>
> #include "postgres.h"
>
> #define COMMA ", "
>
> text *lastfirst (text *first, text *last, bool nocompany)
> {
> /* this function will take in the first name, and last name
> * and based on nocompany set the output to either return
> * 'last, first' or just the company name.
> */
>
> int32 ret_size;
> text *return_text;
>
> if (nocompany) {
>
> if (first == NULL) {
>
> ret_size = VARSIZE(last) + sizeof(COMMA);
> return_text = (text *) palloc(ret_size);
>
> memset(return_text, 0, ret_size);
>
> VARSIZE(return_text) = ret_size;
>
> strncpy (VARDATA(return_text), VARDATA(last),
> VARSIZE(last)-VARHDRSZ);
>
> strncat (VARDATA(return_text), COMMA,
> sizeof(COMMA));
>
> return (return_text);
>
> } else {
>
> ret_size = VARSIZE(first) + VARSIZE(last) +
> sizeof(COMMA) - VARHDRSZ;
>
> return_text = (text *) palloc(ret_size);
>
> memset(return_text, 0, ret_size);
>
> VARSIZE(return_text) = ret_size;
>
> strncpy (VARDATA(return_text),
> VARDATA(last), VARSIZE(last)-VARHDRSZ);
> strncat (VARDATA(return_text), COMMA,
> sizeof(COMMA));
> strncat (VARDATA(return_text),
> VARDATA(first), VARSIZE(first)-VARHDRSZ);
>
> return (return_text);
>
> }
>
> } else {
> /* Just the company name is returned here */
>
> ret_size = VARSIZE(last);
> return_text = (text *) palloc(ret_size);
>
> VARSIZE(return_text) = ret_size;
> strncpy(VARDATA(return_text), VARDATA(last),
> VARSIZE(last)-VARHDRSZ);
>
> return (return_text);
> }
> }

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jackson, DeJuan 1999-01-08 21:19:43 RE: [GENERAL] Benchmarking PGSQL against Microsoft SQL 7.0?
Previous Message Bryan Field-Elliot 1999-01-08 21:04:10 Benchmarking PGSQL against Microsoft SQL 7.0?

Browse pgsql-hackers by date

  From Date Subject
Next Message Jackson, DeJuan 1999-01-08 21:10:14 RE: [HACKERS] 6.4 lateness and CIDR
Previous Message Bruce Momjian 1999-01-08 20:12:52 Re: [HACKERS] 6.4 lateness and CIDR