Skip site navigation (1) Skip section navigation (2)

type text in c functions

From: "Robert Wimmer" <seppwimmer(at)hotmail(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: type text in c functions
Date: 2004-12-19 01:16:44
Message-ID: BAY10-F27712116B982BAC5BEEC10D0A10@phx.gbl (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
i tried to write a simple typechecking function in c. but it does not work 

-- CODE --
#include <postgres.h>
#include <string.h>
#include <fmgr.h>


Datum text_to_card(PG_FUNCTION_ARGS)
  int i,l;
  int32 ret;

  text *t = PG_GETARG_TEXT_P(0);


  for (i = 0; i < l; i++) { if ( (t->vl_dat[i] < '0') || (t->vl_dat[i] > 
'9')) break; }

  if (i==l) ret = 0;
  else ret = i;


--END --

this function should check if it is possible to cast a TEXT in an unsigned 
INTEGER. if OK it returns 0
otherwise the position in the string where the error occured.
( so you can produce error messages like ERROR[234] text_to_card('paramete') 
failed at <3>)

i assumed - after reading the corresponding header files and docs and google 
- the type structure of a text as above.
i only get zeros and ones as result

the algorithm works fine in 'normal' c.

is there a possibilty to treat a TEXT parameter like a char array ?

thanks and regards sepp

Schaffen Sie das Platzproblem in Ihrem E-Mail-Konto für immer aus der Welt!


pgsql-interfaces by date

Next:From: Tom LaneDate: 2004-12-19 03:21:07
Subject: Re: type text in c functions
Previous:From: Jan WieckDate: 2004-12-18 21:22:15
Subject: Re: Lost updates vs resumable connections/transactions

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group