postgresql v6.4.2 c funcs and null text pointers...

From: Walt Bigelow <walt(at)stimpy(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: postgresql v6.4.2 c funcs and null text pointers...
Date: 1999-01-08 12:41:10
Message-ID: Pine.LNX.3.96.990108122541.2807B-100000@alice.stimpy.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

Browse pgsql-general by date

  From Date Subject
Next Message Kevin Heflin 1999-01-08 14:52:38 Re: [GENERAL] select using date
Previous Message Jose' Soares 1999-01-08 12:37:57 Re: [GENERAL] select using date