agora inbox for postgres@postgres.berkeley.edu
help / color / mirror / Atom feedFrom: Jolly Chen <jolly@postgres.Berkeley.EDU>
To: Bruce Taneja. <aataneja@cs.mtu.edu>
Cc: postgres@postgres.Berkeley.EDU
Subject: Re: using "TEXT" in C files ..
Date: Mon, 13 Jun 1994 10:29:27 -0700
Message-ID: <199406131729.KAA11943@arcadia.CS.Berkeley.EDU> (raw)
In-Reply-To: <9406122239.AA26597@cs.mtu.edu>
> 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.
==============================================================================
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: postgres@postgres.berkeley.edu
Cc: jolly@postgres.Berkeley.EDU, aataneja@cs.mtu.edu
Subject: Re: using "TEXT" in C files ..
In-Reply-To: <199406131729.KAA11943@arcadia.CS.Berkeley.EDU>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox