agora inbox for postgres@postgres.berkeley.edu  
help / color / mirror / Atom feed
using "TEXT" in C files ..
2+ messages / 2 participants
[nested] [flat]

* using "TEXT" in C files ..
@ 1994-06-12 22:39  Bruce Taneja. <aataneja@cs.mtu.edu>
  0 siblings, 1 reply; 2+ messages in thread

From: Bruce Taneja. @ 1994-06-12 22:39 UTC (permalink / raw)
  To: legacy; +Cc: Bruce Taneja. <aataneja@cs.mtu.edu>


Greetings Netters,

What files are needed to be included to use the "TEXT"
data type of Postgres while writing code for some complex
data definition ..?

The CIRCLE example showed which file to include to use
the POINT data type .. (is any required for TEXT ?)

can we say :

typedef struct {

	CIRCLE c;
	int i;
	TEXT t;        <<<<?????

	} xyz;


Also is this TEXT of variable size .. ? >>

If so then is this xyz type to be defined as a "variable-internal
length" .. ?  (because we won't know the size of xyz till the run
time) ...

Also can we safely assume (while coding in C) that a retrieved 
glob (from disk) will have the TEXT t ending with a NULL ??

thanks in advance!
Bruce!

==============================================================================
   To add/remove yourself to/from the POSTGRES mailing list: send mail with 
   the subject line ADD or DEL to "postgres-request@postgres.Berkeley.EDU"

   If this fails, send mail to "post_questions@postgres.Berkeley.EDU" and
   a human will deal with it.  DO NOT post to the "postgres" mailing list.
==============================================================================



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: using "TEXT" in C files ..
@ 1994-06-13 17:29  Jolly Chen <jolly@postgres.Berkeley.EDU>
  parent: Bruce Taneja. <aataneja@cs.mtu.edu>
  0 siblings, 0 replies; 2+ messages in thread

From: Jolly Chen @ 1994-06-13 17:29 UTC (permalink / raw)
  To: Bruce Taneja. <aataneja@cs.mtu.edu>; +Cc: legacy



> What files are needed to be included to use the "TEXT"
> data type of Postgres while writing code for some complex
> data definition ..?
> 

text is defined in   src/backend/tmp/postgres.h

It is simply a  struct varlena.

> Also can we safely assume (while coding in C) that a retrieved 
> glob (from disk) will have the TEXT t ending with a NULL ??
> 

DON'T assume that text types are null-terminated.  In general, they
won't be.   Instead, use the macros  VARSIZE, VARDATA, and VARHDRSZ
defined in postgres.h .

To convert a text to a null-terminated char*, you can do something
like this:

/** takes a text varlena and returns a char* 
    the CALLER is responsible for freeing the memory of the char* returned **/

char* text2str(text* textarg)
{
  int len;
  char* data;
  char* result;

  len = VARSIZE(textarg) - VARHDRSZ + 1;/* don't count the bytes of the size field, but add one for the '\0' */
  data = VARDATA(textarg);
  result = (char*)palloc(len); 
  strncpy(result, data, len-1);
  result[len-1] = '\0';
  return result;
}


- Jolly Chen

==============================================================================
   To add/remove yourself to/from the POSTGRES mailing list: send mail with 
   the subject line ADD or DEL to "postgres-request@postgres.Berkeley.EDU"

   If this fails, send mail to "post_questions@postgres.Berkeley.EDU" and
   a human will deal with it.  DO NOT post to the "postgres" mailing list.
==============================================================================



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~1994-06-13 17:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1994-06-12 22:39 using "TEXT" in C files .. Bruce Taneja. <aataneja@cs.mtu.edu>
1994-06-13 17:29 ` Jolly Chen <jolly@postgres.Berkeley.EDU>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox