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

Started by Jackson, DeJuanabout 27 years ago2 messages
#1Jackson, DeJuan
djackson@cpsgroup.com

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

Show quoted text

-----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);
}
}

#2Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Jackson, DeJuan (#1)
Re: [GENERAL] postgresql v6.4.2 c funcs and null text pointers...

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?

As some stupid spagetti commerical used to say, "It's in there":

* redesign the function call interface to handle NULLs better(Jan)

I even assigned it to Jan. :-)

*** 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

My suggestion is that we set up time to talk on the PostgreSQL irc
channel. I will be on with Thomas tonight after 10pm EST. We can set
up a separate time for you too.

You can poke around and ask questions, and we can both look at the code
and discuss it. I will assume you have already read the backend
flowchart and developers FAQ, so we can go over other items you may
have.

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026