Talk About Network

Google




Play Stock Market Games
Fantasy Stock Picking Contest

Data Bases > Pgsql General > more custom C f...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 15463 of 16301
Post > Topic >>

more custom C function fun

by heron@[EMAIL PROTECTED] ("Dan \"Heron\" Myers") May 5, 2008 at 11:43 PM

I have a custom C function that takes two text*s and returns a text*.

My problem is with this code:


PG_FUNCTION_INFO_V1(get_agent);

PGMODULEEX****T Datum get_agent(PG_FUNCTION_ARGS)
{
	if(!PG_ARGISNULL(0))
	{
		text* calling_party = PG_GETARG_TEXT_P(0);

		char* thestr = VARDATA(calling_party);
		if(thestr[20] == ')')
		{
			PG_RETURN_TEXT_P(calling_party);
		}
	}
/* the other argument is ignored for now */
	PG_RETURN_NULL();
}

The problem is, the comparison in the inner if statement is always true. 
  If I change to compare, say, thestr[0] == 'N', then it works as 
expected (returning only those text*s whose first letter is N, returning 
null for the rest).

However if I try to compare any character inside the text* with a 
parenthesis (both '(' and ')'), then the equality is apparently always 
true (the function never returns null, always returning calling_party), 
whether or not there is any data in that column that contains a 
parenthesis in that column.

Does anyone know of any oddities or whatnot I should be accounting for 
when reading character data out of a text*?

- Dan

-- 
Sent via pgsql-general mailing list (pgsql-general@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
 




 4 Posts in Topic:
more custom C function fun
heron@[EMAIL PROTECTED]   2008-05-05 23:43:40 
Re: more custom C function fun
kleptog@[EMAIL PROTECTED]  2008-05-06 08:48:26 
Re: more custom C function fun
heron@[EMAIL PROTECTED]   2008-05-06 09:39:50 
Re: more custom C function fun
kleptog@[EMAIL PROTECTED]  2008-05-06 17:59:44 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan13V112 Fri Aug 8 12:39:53 CDT 2008.