PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
wparser.c File Reference
#include "postgres.h"
#include "funcapi.h"
#include "catalog/namespace.h"
#include "catalog/pg_type.h"
#include "commands/defrem.h"
#include "tsearch/ts_cache.h"
#include "tsearch/ts_utils.h"
#include "utils/builtins.h"
#include "utils/varlena.h"
Include dependency graph for wparser.c:

Go to the source code of this file.

Data Structures

struct  TSTokenTypeStorage
 
struct  LexemeEntry
 
struct  PrsStorage
 

Functions

static void tt_setup_firstcall (FuncCallContext *funcctx, Oid prsid)
 
static Datum tt_process_call (FuncCallContext *funcctx)
 
Datum ts_token_type_byid (PG_FUNCTION_ARGS)
 
Datum ts_token_type_byname (PG_FUNCTION_ARGS)
 
static void prs_setup_firstcall (FuncCallContext *funcctx, Oid prsid, text *txt)
 
static Datum prs_process_call (FuncCallContext *funcctx)
 
Datum ts_parse_byid (PG_FUNCTION_ARGS)
 
Datum ts_parse_byname (PG_FUNCTION_ARGS)
 
Datum ts_headline_byid_opt (PG_FUNCTION_ARGS)
 
Datum ts_headline_byid (PG_FUNCTION_ARGS)
 
Datum ts_headline (PG_FUNCTION_ARGS)
 
Datum ts_headline_opt (PG_FUNCTION_ARGS)
 

Function Documentation

static Datum prs_process_call ( FuncCallContext funcctx)
static

Definition at line 212 of file wparser.c.

References FuncCallContext::attinmeta, BuildTupleFromCStrings(), PrsStorage::cur, HeapTupleGetDatum, PrsStorage::len, LexemeEntry::lexeme, PrsStorage::list, pfree(), result, LexemeEntry::type, FuncCallContext::user_fctx, and values.

Referenced by ts_parse_byid(), and ts_parse_byname().

213 {
214  PrsStorage *st;
215 
216  st = (PrsStorage *) funcctx->user_fctx;
217  if (st->cur < st->len)
218  {
219  Datum result;
220  char *values[2];
221  char tid[16];
222  HeapTuple tuple;
223 
224  values[0] = tid;
225  sprintf(tid, "%d", st->list[st->cur].type);
226  values[1] = st->list[st->cur].lexeme;
227  tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
228  result = HeapTupleGetDatum(tuple);
229 
230  pfree(values[1]);
231  st->cur++;
232  return result;
233  }
234  else
235  {
236  if (st->list)
237  pfree(st->list);
238  pfree(st);
239  }
240  return (Datum) 0;
241 }
int type
Definition: wparser.c:143
LexemeEntry * list
Definition: wparser.c:151
int len
Definition: wparser.c:150
return result
Definition: formatting.c:1618
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
Definition: execTuples.c:1115
void pfree(void *pointer)
Definition: mcxt.c:950
AttInMetadata * attinmeta
Definition: funcapi.h:99
char * lexeme
Definition: wparser.c:144
int cur
Definition: wparser.c:149
uintptr_t Datum
Definition: postgres.h:372
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:222
static Datum values[MAXATTR]
Definition: bootstrap.c:162
void * user_fctx
Definition: funcapi.h:90
static void prs_setup_firstcall ( FuncCallContext funcctx,
Oid  prsid,
text txt 
)
static

Definition at line 156 of file wparser.c.

References FuncCallContext::attinmeta, CreateTemplateTupleDesc(), PrsStorage::cur, DatumGetInt32, DatumGetPointer, FunctionCall1, FunctionCall2, FunctionCall3, Int32GetDatum, INT4OID, PrsStorage::len, LexemeEntry::lexeme, PrsStorage::list, lookup_ts_parser_cache(), MemoryContextSwitchTo(), FuncCallContext::multi_call_memory_ctx, NULL, palloc(), PointerGetDatum, TSParserCacheEntry::prsend, TSParserCacheEntry::prsstart, TSParserCacheEntry::prstoken, repalloc(), TEXTOID, TupleDescGetAttInMetadata(), TupleDescInitEntry(), LexemeEntry::type, FuncCallContext::user_fctx, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

Referenced by ts_parse_byid(), and ts_parse_byname().

157 {
158  TupleDesc tupdesc;
159  MemoryContext oldcontext;
160  PrsStorage *st;
162  char *lex = NULL;
163  int llen = 0,
164  type = 0;
165  void *prsdata;
166 
167  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
168 
169  st = (PrsStorage *) palloc(sizeof(PrsStorage));
170  st->cur = 0;
171  st->len = 16;
172  st->list = (LexemeEntry *) palloc(sizeof(LexemeEntry) * st->len);
173 
174  prsdata = (void *) DatumGetPointer(FunctionCall2(&prs->prsstart,
177 
178  while ((type = DatumGetInt32(FunctionCall3(&prs->prstoken,
179  PointerGetDatum(prsdata),
180  PointerGetDatum(&lex),
181  PointerGetDatum(&llen)))) != 0)
182  {
183  if (st->cur >= st->len)
184  {
185  st->len = 2 * st->len;
186  st->list = (LexemeEntry *) repalloc(st->list, sizeof(LexemeEntry) * st->len);
187  }
188  st->list[st->cur].lexeme = palloc(llen + 1);
189  memcpy(st->list[st->cur].lexeme, lex, llen);
190  st->list[st->cur].lexeme[llen] = '\0';
191  st->list[st->cur].type = type;
192  st->cur++;
193  }
194 
195  FunctionCall1(&prs->prsend, PointerGetDatum(prsdata));
196 
197  st->len = st->cur;
198  st->cur = 0;
199 
200  funcctx->user_fctx = (void *) st;
201  tupdesc = CreateTemplateTupleDesc(2, false);
202  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "tokid",
203  INT4OID, -1, 0);
204  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "token",
205  TEXTOID, -1, 0);
206 
207  funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc);
208  MemoryContextSwitchTo(oldcontext);
209 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:347
int type
Definition: wparser.c:143
#define DatumGetInt32(X)
Definition: postgres.h:478
LexemeEntry * list
Definition: wparser.c:151
#define TEXTOID
Definition: pg_type.h:324
#define PointerGetDatum(X)
Definition: postgres.h:562
int len
Definition: wparser.c:150
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define FunctionCall2(flinfo, arg1, arg2)
Definition: fmgr.h:596
#define INT4OID
Definition: pg_type.h:316
TSParserCacheEntry * lookup_ts_parser_cache(Oid prsId)
Definition: ts_cache.c:112
#define FunctionCall3(flinfo, arg1, arg2, arg3)
Definition: fmgr.h:598
FmgrInfo prsend
Definition: ts_cache.h:47
AttInMetadata * attinmeta
Definition: funcapi.h:99
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:493
char * lexeme
Definition: wparser.c:144
int cur
Definition: wparser.c:149
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
Definition: execTuples.c:1068
#define NULL
Definition: c.h:229
FmgrInfo prstoken
Definition: ts_cache.h:46
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:109
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:41
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:963
#define DatumGetPointer(X)
Definition: postgres.h:555
FmgrInfo prsstart
Definition: ts_cache.h:45
#define Int32GetDatum(X)
Definition: postgres.h:485
void * user_fctx
Definition: funcapi.h:90
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:340
void * palloc(Size size)
Definition: mcxt.c:849
#define FunctionCall1(flinfo, arg1)
Definition: fmgr.h:594
int16 AttrNumber
Definition: attnum.h:21
Datum ts_headline ( PG_FUNCTION_ARGS  )

Definition at line 349 of file wparser.c.

References DirectFunctionCall3, getTSCurrentConfig(), ObjectIdGetDatum, PG_GETARG_DATUM, PG_RETURN_DATUM, and ts_headline_byid_opt().

350 {
353  PG_GETARG_DATUM(0),
354  PG_GETARG_DATUM(1)));
355 }
Oid getTSCurrentConfig(bool emitError)
Definition: ts_cache.c:556
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:225
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
Datum ts_headline_byid_opt(PG_FUNCTION_ARGS)
Definition: wparser.c:290
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:580
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:305
Datum ts_headline_byid ( PG_FUNCTION_ARGS  )

Definition at line 340 of file wparser.c.

References DirectFunctionCall3, PG_GETARG_DATUM, PG_RETURN_DATUM, and ts_headline_byid_opt().

341 {
343  PG_GETARG_DATUM(0),
344  PG_GETARG_DATUM(1),
345  PG_GETARG_DATUM(2)));
346 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:225
Datum ts_headline_byid_opt(PG_FUNCTION_ARGS)
Definition: wparser.c:290
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:580
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:305
Datum ts_headline_byid_opt ( PG_FUNCTION_ARGS  )

Definition at line 290 of file wparser.c.

References TSConfigCacheEntry::cfgId, deserialize_deflist(), ereport, errcode(), errmsg(), ERROR, FunctionCall3, generateHeadline(), TSParserCacheEntry::headlineOid, hlparsetext(), HeadlineParsedText::lenwords, lookup_ts_config_cache(), lookup_ts_parser_cache(), NIL, NULL, OidIsValid, palloc(), pfree(), PG_FREE_IF_COPY, PG_GETARG_OID, PG_GETARG_POINTER, PG_GETARG_TEXT_PP, PG_GETARG_TSQUERY, PG_NARGS, PG_RETURN_POINTER, PointerGetDatum, TSParserCacheEntry::prsheadline, TSConfigCacheEntry::prsId, HeadlineParsedText::startsel, HeadlineParsedText::stopsel, VARDATA_ANY, VARSIZE_ANY_EXHDR, and HeadlineParsedText::words.

Referenced by ts_headline(), ts_headline_byid(), and ts_headline_opt().

291 {
292  text *in = PG_GETARG_TEXT_PP(1);
293  TSQuery query = PG_GETARG_TSQUERY(2);
294  text *opt = (PG_NARGS() > 3 && PG_GETARG_POINTER(3)) ? PG_GETARG_TEXT_PP(3) : NULL;
295  HeadlineParsedText prs;
296  List *prsoptions;
297  text *out;
298  TSConfigCacheEntry *cfg;
299  TSParserCacheEntry *prsobj;
300 
302  prsobj = lookup_ts_parser_cache(cfg->prsId);
303 
304  if (!OidIsValid(prsobj->headlineOid))
305  ereport(ERROR,
306  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
307  errmsg("text search parser does not support headline creation")));
308 
309  memset(&prs, 0, sizeof(HeadlineParsedText));
310  prs.lenwords = 32;
311  prs.words = (HeadlineWordEntry *) palloc(sizeof(HeadlineWordEntry) * prs.lenwords);
312 
313  hlparsetext(cfg->cfgId, &prs, query,
314  VARDATA_ANY(in), VARSIZE_ANY_EXHDR(in));
315 
316  if (opt)
317  prsoptions = deserialize_deflist(PointerGetDatum(opt));
318  else
319  prsoptions = NIL;
320 
321  FunctionCall3(&(prsobj->prsheadline),
322  PointerGetDatum(&prs),
323  PointerGetDatum(prsoptions),
324  PointerGetDatum(query));
325 
326  out = generateHeadline(&prs);
327 
328  PG_FREE_IF_COPY(in, 1);
329  PG_FREE_IF_COPY(query, 2);
330  if (opt)
331  PG_FREE_IF_COPY(opt, 3);
332  pfree(prs.words);
333  pfree(prs.startsel);
334  pfree(prs.stopsel);
335 
336  PG_RETURN_POINTER(out);
337 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:313
#define NIL
Definition: pg_list.h:69
#define VARDATA_ANY(PTR)
Definition: postgres.h:347
#define PointerGetDatum(X)
Definition: postgres.h:562
#define PG_GETARG_TSQUERY(n)
Definition: ts_type.h:238
List * deserialize_deflist(Datum txt)
Definition: tsearchcmds.c:1562
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:233
TSParserCacheEntry * lookup_ts_parser_cache(Oid prsId)
Definition: ts_cache.c:112
#define OidIsValid(objectId)
Definition: c.h:538
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:265
#define FunctionCall3(flinfo, arg1, arg2, arg3)
Definition: fmgr.h:598
void pfree(void *pointer)
Definition: mcxt.c:950
#define ERROR
Definition: elog.h:43
TSConfigCacheEntry * lookup_ts_config_cache(Oid cfgId)
Definition: ts_cache.c:385
HeadlineWordEntry * words
Definition: ts_public.h:52
#define PG_GETARG_OID(n)
Definition: fmgr.h:232
#define ereport(elevel, rest)
Definition: elog.h:122
text * generateHeadline(HeadlineParsedText *prs)
Definition: ts_parse.c:598
#define NULL
Definition: c.h:229
void hlparsetext(Oid cfgId, HeadlineParsedText *prs, TSQuery query, char *buf, int buflen)
Definition: ts_parse.c:533
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:217
#define PG_NARGS()
Definition: fmgr.h:160
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:340
void * palloc(Size size)
Definition: mcxt.c:849
int errmsg(const char *fmt,...)
Definition: elog.c:797
Definition: c.h:439
Definition: pg_list.h:45
FmgrInfo prsheadline
Definition: ts_cache.h:48
Datum ts_headline_opt ( PG_FUNCTION_ARGS  )

Definition at line 358 of file wparser.c.

References DirectFunctionCall4, getTSCurrentConfig(), ObjectIdGetDatum, PG_GETARG_DATUM, PG_RETURN_DATUM, and ts_headline_byid_opt().

359 {
362  PG_GETARG_DATUM(0),
363  PG_GETARG_DATUM(1),
364  PG_GETARG_DATUM(2)));
365 }
Oid getTSCurrentConfig(bool emitError)
Definition: ts_cache.c:556
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:225
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
Datum ts_headline_byid_opt(PG_FUNCTION_ARGS)
Definition: wparser.c:290
#define DirectFunctionCall4(func, arg1, arg2, arg3, arg4)
Definition: fmgr.h:582
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:305
Datum ts_parse_byid ( PG_FUNCTION_ARGS  )

Definition at line 244 of file wparser.c.

References PG_FREE_IF_COPY, PG_GETARG_OID, PG_GETARG_TEXT_PP, prs_process_call(), prs_setup_firstcall(), result, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, and SRF_RETURN_NEXT.

245 {
246  FuncCallContext *funcctx;
247  Datum result;
248 
249  if (SRF_IS_FIRSTCALL())
250  {
251  text *txt = PG_GETARG_TEXT_PP(1);
252 
253  funcctx = SRF_FIRSTCALL_INIT();
254  prs_setup_firstcall(funcctx, PG_GETARG_OID(0), txt);
255  PG_FREE_IF_COPY(txt, 1);
256  }
257 
258  funcctx = SRF_PERCALL_SETUP();
259 
260  if ((result = prs_process_call(funcctx)) != (Datum) 0)
261  SRF_RETURN_NEXT(funcctx, result);
262  SRF_RETURN_DONE(funcctx);
263 }
static Datum prs_process_call(FuncCallContext *funcctx)
Definition: wparser.c:212
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:285
return result
Definition: formatting.c:1618
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:289
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:265
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:291
#define PG_GETARG_OID(n)
Definition: fmgr.h:232
uintptr_t Datum
Definition: postgres.h:372
static void prs_setup_firstcall(FuncCallContext *funcctx, Oid prsid, text *txt)
Definition: wparser.c:156
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:217
Definition: c.h:439
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:309
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:287
Datum ts_parse_byname ( PG_FUNCTION_ARGS  )

Definition at line 266 of file wparser.c.

References get_ts_parser_oid(), PG_GETARG_TEXT_PP, prs_process_call(), prs_setup_firstcall(), result, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, and textToQualifiedNameList().

267 {
268  FuncCallContext *funcctx;
269  Datum result;
270 
271  if (SRF_IS_FIRSTCALL())
272  {
273  text *prsname = PG_GETARG_TEXT_PP(0);
274  text *txt = PG_GETARG_TEXT_PP(1);
275  Oid prsId;
276 
277  funcctx = SRF_FIRSTCALL_INIT();
278  prsId = get_ts_parser_oid(textToQualifiedNameList(prsname), false);
279  prs_setup_firstcall(funcctx, prsId, txt);
280  }
281 
282  funcctx = SRF_PERCALL_SETUP();
283 
284  if ((result = prs_process_call(funcctx)) != (Datum) 0)
285  SRF_RETURN_NEXT(funcctx, result);
286  SRF_RETURN_DONE(funcctx);
287 }
static Datum prs_process_call(FuncCallContext *funcctx)
Definition: wparser.c:212
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:285
return result
Definition: formatting.c:1618
unsigned int Oid
Definition: postgres_ext.h:31
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:289
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:265
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:291
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3182
uintptr_t Datum
Definition: postgres.h:372
Oid get_ts_parser_oid(List *names, bool missing_ok)
Definition: namespace.c:2150
static void prs_setup_firstcall(FuncCallContext *funcctx, Oid prsid, text *txt)
Definition: wparser.c:156
Definition: c.h:439
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:309
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:287
Datum ts_token_type_byid ( PG_FUNCTION_ARGS  )

Definition at line 100 of file wparser.c.

References PG_GETARG_OID, result, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, tt_process_call(), and tt_setup_firstcall().

101 {
102  FuncCallContext *funcctx;
103  Datum result;
104 
105  if (SRF_IS_FIRSTCALL())
106  {
107  funcctx = SRF_FIRSTCALL_INIT();
108  tt_setup_firstcall(funcctx, PG_GETARG_OID(0));
109  }
110 
111  funcctx = SRF_PERCALL_SETUP();
112 
113  if ((result = tt_process_call(funcctx)) != (Datum) 0)
114  SRF_RETURN_NEXT(funcctx, result);
115  SRF_RETURN_DONE(funcctx);
116 }
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:285
return result
Definition: formatting.c:1618
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:289
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:291
static Datum tt_process_call(FuncCallContext *funcctx)
Definition: wparser.c:68
#define PG_GETARG_OID(n)
Definition: fmgr.h:232
static void tt_setup_firstcall(FuncCallContext *funcctx, Oid prsid)
Definition: wparser.c:35
uintptr_t Datum
Definition: postgres.h:372
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:309
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:287
Datum ts_token_type_byname ( PG_FUNCTION_ARGS  )

Definition at line 119 of file wparser.c.

References get_ts_parser_oid(), PG_GETARG_TEXT_PP, result, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, textToQualifiedNameList(), tt_process_call(), and tt_setup_firstcall().

120 {
121  FuncCallContext *funcctx;
122  Datum result;
123 
124  if (SRF_IS_FIRSTCALL())
125  {
126  text *prsname = PG_GETARG_TEXT_PP(0);
127  Oid prsId;
128 
129  funcctx = SRF_FIRSTCALL_INIT();
130  prsId = get_ts_parser_oid(textToQualifiedNameList(prsname), false);
131  tt_setup_firstcall(funcctx, prsId);
132  }
133 
134  funcctx = SRF_PERCALL_SETUP();
135 
136  if ((result = tt_process_call(funcctx)) != (Datum) 0)
137  SRF_RETURN_NEXT(funcctx, result);
138  SRF_RETURN_DONE(funcctx);
139 }
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:285
return result
Definition: formatting.c:1618
unsigned int Oid
Definition: postgres_ext.h:31
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:289
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:265
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:291
static Datum tt_process_call(FuncCallContext *funcctx)
Definition: wparser.c:68
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3182
static void tt_setup_firstcall(FuncCallContext *funcctx, Oid prsid)
Definition: wparser.c:35
uintptr_t Datum
Definition: postgres.h:372
Oid get_ts_parser_oid(List *names, bool missing_ok)
Definition: namespace.c:2150
Definition: c.h:439
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:309
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:287
static Datum tt_process_call ( FuncCallContext funcctx)
static

Definition at line 68 of file wparser.c.

References LexDescr::alias, FuncCallContext::attinmeta, BuildTupleFromCStrings(), TSTokenTypeStorage::cur, LexDescr::descr, HeapTupleGetDatum, LexDescr::lexid, TSTokenTypeStorage::list, pfree(), result, FuncCallContext::user_fctx, and values.

Referenced by ts_token_type_byid(), and ts_token_type_byname().

69 {
71 
72  st = (TSTokenTypeStorage *) funcctx->user_fctx;
73  if (st->list && st->list[st->cur].lexid)
74  {
75  Datum result;
76  char *values[3];
77  char txtid[16];
78  HeapTuple tuple;
79 
80  sprintf(txtid, "%d", st->list[st->cur].lexid);
81  values[0] = txtid;
82  values[1] = st->list[st->cur].alias;
83  values[2] = st->list[st->cur].descr;
84 
85  tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
86  result = HeapTupleGetDatum(tuple);
87 
88  pfree(values[1]);
89  pfree(values[2]);
90  st->cur++;
91  return result;
92  }
93  if (st->list)
94  pfree(st->list);
95  pfree(st);
96  return (Datum) 0;
97 }
LexDescr * list
Definition: wparser.c:31
char * alias
Definition: ts_public.h:28
return result
Definition: formatting.c:1618
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
Definition: execTuples.c:1115
void pfree(void *pointer)
Definition: mcxt.c:950
AttInMetadata * attinmeta
Definition: funcapi.h:99
char * descr
Definition: ts_public.h:29
int lexid
Definition: ts_public.h:27
uintptr_t Datum
Definition: postgres.h:372
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:222
static Datum values[MAXATTR]
Definition: bootstrap.c:162
void * user_fctx
Definition: funcapi.h:90
static void tt_setup_firstcall ( FuncCallContext funcctx,
Oid  prsid 
)
static

Definition at line 35 of file wparser.c.

References FuncCallContext::attinmeta, CreateTemplateTupleDesc(), TSTokenTypeStorage::cur, DatumGetPointer, elog, ERROR, INT4OID, TSParserCacheEntry::lextypeOid, TSTokenTypeStorage::list, lookup_ts_parser_cache(), MemoryContextSwitchTo(), FuncCallContext::multi_call_memory_ctx, OidFunctionCall1, OidIsValid, palloc(), TEXTOID, TupleDescGetAttInMetadata(), TupleDescInitEntry(), and FuncCallContext::user_fctx.

Referenced by ts_token_type_byid(), and ts_token_type_byname().

36 {
37  TupleDesc tupdesc;
38  MemoryContext oldcontext;
41 
42  if (!OidIsValid(prs->lextypeOid))
43  elog(ERROR, "method lextype isn't defined for text search parser %u",
44  prsid);
45 
46  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
47 
49  st->cur = 0;
50  /* lextype takes one dummy argument */
52  (Datum) 0));
53  funcctx->user_fctx = (void *) st;
54 
55  tupdesc = CreateTemplateTupleDesc(3, false);
56  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "tokid",
57  INT4OID, -1, 0);
58  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "alias",
59  TEXTOID, -1, 0);
60  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
61  TEXTOID, -1, 0);
62 
63  funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc);
64  MemoryContextSwitchTo(oldcontext);
65 }
LexDescr * list
Definition: wparser.c:31
#define TEXTOID
Definition: pg_type.h:324
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define INT4OID
Definition: pg_type.h:316
TSParserCacheEntry * lookup_ts_parser_cache(Oid prsId)
Definition: ts_cache.c:112
#define OidIsValid(objectId)
Definition: c.h:538
#define ERROR
Definition: elog.h:43
#define OidFunctionCall1(functionId, arg1)
Definition: fmgr.h:614
AttInMetadata * attinmeta
Definition: funcapi.h:99
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:493
uintptr_t Datum
Definition: postgres.h:372
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
Definition: execTuples.c:1068
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:109
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:41
#define DatumGetPointer(X)
Definition: postgres.h:555
void * user_fctx
Definition: funcapi.h:90
void * palloc(Size size)
Definition: mcxt.c:849
#define elog
Definition: elog.h:219
int16 AttrNumber
Definition: attnum.h:21