2009-05-14 08:19:25 +00:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* pgut-be.c
|
|
|
|
*
|
2011-04-29 05:06:48 +00:00
|
|
|
* Portions Copyright (c) 2008-2011, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
|
|
|
|
* Portions Copyright (c) 2011, Itagaki Takahiro
|
2009-05-14 08:19:25 +00:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "postgres.h"
|
2010-03-25 07:13:16 +00:00
|
|
|
#include "access/heapam.h"
|
2009-05-14 08:19:25 +00:00
|
|
|
#include "pgut-be.h"
|
|
|
|
|
|
|
|
#if PG_VERSION_NUM < 80400
|
|
|
|
|
|
|
|
char *
|
|
|
|
text_to_cstring(const text *t)
|
|
|
|
{
|
|
|
|
text *tunpacked = pg_detoast_datum_packed((struct varlena *) t);
|
|
|
|
int len = VARSIZE_ANY_EXHDR(tunpacked);
|
|
|
|
char *result;
|
|
|
|
|
|
|
|
result = (char *) palloc(len + 1);
|
|
|
|
memcpy(result, VARDATA_ANY(tunpacked), len);
|
|
|
|
result[len] = '\0';
|
|
|
|
|
|
|
|
if (tunpacked != t)
|
|
|
|
pfree(tunpacked);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
text *
|
|
|
|
cstring_to_text(const char *s)
|
|
|
|
{
|
|
|
|
int len = strlen(s);
|
|
|
|
text *result = palloc(len + VARHDRSZ);
|
|
|
|
|
|
|
|
SET_VARSIZE(result, len + VARHDRSZ);
|
|
|
|
memcpy(VARDATA(result), s, len);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-03-25 07:13:16 +00:00
|
|
|
void
|
|
|
|
tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc,
|
|
|
|
Datum *values, bool *isnull)
|
|
|
|
{
|
|
|
|
tuplestore_puttuple(state, heap_form_tuple(tdesc, values, isnull));
|
|
|
|
}
|
|
|
|
|
2009-05-14 08:19:25 +00:00
|
|
|
#endif
|