Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 560 lines (500 sloc) 16.74 kb
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
1 /*
0820fa3a »
2003-02-05 Improved handling of NULLs/NAs
2 * PL/R - PostgreSQL support for R as a
3 * procedural language (PL)
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
4 *
33a90a9a »
2013-02-18 Update copyright for 2013
5 * Copyright (c) 2003-2013 by Joseph E. Conway
3553645a »
2003-02-11 Changed license to GPL per discussion on R mailing list.
6 * ALL RIGHTS RESERVED
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
7 *
8 * Joe Conway <mail@joeconway.com>
3368fdd5 »
2003-02-04 Modified attribution a bit. Changed a few function names to improve c…
9 *
10 * Based on pltcl by Jan Wieck
11 * and inspired by REmbeddedPostgres by
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
12 * Duncan Temple Lang <duncan@research.bell-labs.com>
13 * http://www.omegahat.org/RSPostgres/
14 *
3553645a »
2003-02-11 Changed license to GPL per discussion on R mailing list.
15 * License: GPL version 2 or newer. http://www.gnu.org/copyleft/gpl.html
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
30 *
31 * plr.h
32 */
33 #ifndef PLR_H
34 #define PLR_H
35
0e53b0be »
2013-08-01 Update PL/R version number
36 #define PLR_VERSION "08.03.00.15"
d550f026 »
2011-08-15 - Add plr_version() function: outputs a version string. Includes
37
85e0638f »
2010-02-01 - Updated copyright notices for 2010
38 #include "postgres.h"
39
40 #include "fmgr.h"
41 #include "funcapi.h"
42 #include "miscadmin.h"
f9b628b9 »
2011-08-15 - make WINDOW function feature safe for PostgreSQL 8.3 which does
43 #if PG_VERSION_NUM >= 80400
6a9c69f5 »
2011-08-15 - New feature: allow PL/R functions to be declared and used as WINDOW
44 #include "windowapi.h"
f9b628b9 »
2011-08-15 - make WINDOW function feature safe for PostgreSQL 8.3 which does
45 #endif
85e0638f »
2010-02-01 - Updated copyright notices for 2010
46 #include "access/heapam.h"
5d4d925e »
2013-03-30 Allow use of OUT parameters
47 #if PG_VERSION_NUM >= 90300
48 #include "access/htup_details.h"
49 #else
50 #include "access/htup.h"
51 #endif
85e0638f »
2010-02-01 - Updated copyright notices for 2010
52 #include "catalog/catversion.h"
53 #include "catalog/pg_language.h"
54 #include "catalog/pg_namespace.h"
55 #include "catalog/pg_proc.h"
56 #include "catalog/pg_type.h"
57 #include "commands/trigger.h"
58 #include "executor/spi.h"
59 #include "lib/stringinfo.h"
60 #include "nodes/makefuncs.h"
61 #include "optimizer/clauses.h"
62 #include "parser/parse_type.h"
63 #include "storage/ipc.h"
64 #include "tcop/tcopprot.h"
65 #include "utils/array.h"
66 #include "utils/builtins.h"
a0cd74f0 »
2010-02-01 - Adjust for the fact that bytea.h did not exist before PostgreSQL 9.0
67 #if PG_VERSION_NUM >= 80500
85e0638f »
2010-02-01 - Updated copyright notices for 2010
68 #include "utils/bytea.h"
a0cd74f0 »
2010-02-01 - Adjust for the fact that bytea.h did not exist before PostgreSQL 9.0
69 #endif
85e0638f »
2010-02-01 - Updated copyright notices for 2010
70 #include "utils/lsyscache.h"
71 #include "utils/memutils.h"
6a9c69f5 »
2011-08-15 - New feature: allow PL/R functions to be declared and used as WINDOW
72 #include "utils/rel.h"
85e0638f »
2010-02-01 - Updated copyright notices for 2010
73 #include "utils/syscache.h"
74 #include "utils/typcache.h"
75
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
76 #include <unistd.h>
77 #include <fcntl.h>
78 #include <setjmp.h>
089d346e »
2007-09-08 - fix for non-portable use of setenv
79 #include <stdlib.h>
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
80 #include <sys/stat.h>
81
85e0638f »
2010-02-01 - Updated copyright notices for 2010
82 /*
83 * The R headers define various symbols that are also defined by the
84 * Postgres headers, so undef them first to avoid conflicts.
85 */
86 #ifdef ERROR
87 #undef ERROR
88 #endif
89
90 #ifdef WARNING
91 #undef WARNING
92 #endif
93
2f6f75fa »
2007-06-02 - preserve callers memory context rather than assuming query memory c…
94 #include "R.h"
384893c6 »
2008-07-04 - Fix Makefile for include directory names with embedded spaces
95 #include "Rversion.h"
85e0638f »
2010-02-01 - Updated copyright notices for 2010
96
384893c6 »
2008-07-04 - Fix Makefile for include directory names with embedded spaces
97 /*
98 * R version is calculated thus:
99 * Maj * 65536 + Minor * 256 + Build * 1
100 * So:
101 * version 1.8.0 results in:
102 * (1 * 65536) + (8 * 256) + (0 * 1) == 67584
103 * version 1.9.0 results in:
104 * (1 * 65536) + (9 * 256) + (0 * 1) == 67840
105 */
d2d54957 »
2007-09-08 - Update all Copyright notices.
106 #if (R_VERSION >= 132096) /* R_VERSION >= 2.4.0 */
107 #include "Rembedded.h"
108 #endif
020c3240 »
2010-10-07 - fix for win64
109 #if !defined(WIN32) && !defined(WIN64)
d2d54957 »
2007-09-08 - Update all Copyright notices.
110 #include "Rinterface.h"
33a90a9a »
2013-02-18 Update copyright for 2013
111 #else
112 extern int R_SignalHandlers;
384893c6 »
2008-07-04 - Fix Makefile for include directory names with embedded spaces
113 #endif
2f6f75fa »
2007-06-02 - preserve callers memory context rather than assuming query memory c…
114 #include "Rinternals.h"
115 #include "Rdefines.h"
c7aa0e9e »
2009-04-19 - updated copyright statements
116 #if (R_VERSION < 133120) /* R_VERSION < 2.8.0 */
2f6f75fa »
2007-06-02 - preserve callers memory context rather than assuming query memory c…
117 #include "Rdevices.h"
2c727f30 »
2009-03-01 - Fixed "Rdevices.h" not found error related to R-2.8.x
118 #endif
384893c6 »
2008-07-04 - Fix Makefile for include directory names with embedded spaces
119
85e0638f »
2010-02-01 - Updated copyright notices for 2010
120 /* Restore the Postgres headers */
2c727f30 »
2009-03-01 - Fixed "Rdevices.h" not found error related to R-2.8.x
121
2f6f75fa »
2007-06-02 - preserve callers memory context rather than assuming query memory c…
122 #ifdef ERROR
123 #undef ERROR
124 #endif
125
126 #ifdef WARNING
127 #undef WARNING
128 #endif
129
85e0638f »
2010-02-01 - Updated copyright notices for 2010
130 #define WARNING 19
131 #define ERROR 20
132
133 /* starting in R-2.7.0 this defn was removed from Rdevices.h */
134 #ifndef KillAllDevices
135 #define KillAllDevices Rf_KillAllDevices
2f6f75fa »
2007-06-02 - preserve callers memory context rather than assuming query memory c…
136 #endif
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
137
85e0638f »
2010-02-01 - Updated copyright notices for 2010
138 /* for some reason this is not in any R header files, it is locally defined */
139 #define INTEGER_ELT(x,__i__) INTEGER(x)[__i__]
053627d1 »
2003-08-04 First pass at adding trigger support. Not well tested, but works for …
140
85e0638f »
2010-02-01 - Updated copyright notices for 2010
141 #ifndef R_HOME_DEFAULT
142 #define R_HOME_DEFAULT ""
143 #endif
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
144
30da5391 »
2003-03-19 Moved construct_md_array from pg_conversion.c to pg_backend_support.c…
145 /* working with postgres 7.3 compatible sources */
d2d54957 »
2007-09-08 - Update all Copyright notices.
146 #if !defined(PG_VERSION_NUM) || PG_VERSION_NUM < 80200
2f6f75fa »
2007-06-02 - preserve callers memory context rather than assuming query memory c…
147 #error "This version of PL/R only builds with PostgreSQL 8.2 or later"
d2d54957 »
2007-09-08 - Update all Copyright notices.
148 #elif PG_VERSION_NUM < 80300
f86bec47 »
2006-09-11 - removed support (and overhead) for PostgreSQL prior to 8.2
149 #define PG_VERSION_82_COMPAT
f9b628b9 »
2011-08-15 - make WINDOW function feature safe for PostgreSQL 8.3 which does
150 #elif PG_VERSION_NUM < 80400
2f6f75fa »
2007-06-02 - preserve callers memory context rather than assuming query memory c…
151 #define PG_VERSION_83_COMPAT
f9b628b9 »
2011-08-15 - make WINDOW function feature safe for PostgreSQL 8.3 which does
152 #else
153 #define PG_VERSION_84_COMPAT
154 #endif
155
156 #ifdef PG_VERSION_84_COMPAT
157 #define HAVE_WINDOW_FUNCTIONS
30da5391 »
2003-03-19 Moved construct_md_array from pg_conversion.c to pg_backend_support.c…
158 #endif
159
842fe785 »
2003-02-03 Fixed PROTECT/UNPROTECT related bug causing execution of prepared que…
160 #ifdef DEBUGPROTECT
161 #undef PROTECT
5b09a955 »
2007-06-12 - add DLLIMPORT to Dynamic_library_path declaration for Win32
162 extern SEXP pg_protect(SEXP s, char *fn, int ln);
163 #define PROTECT(s) pg_protect(s, __FILE__, __LINE__)
164
842fe785 »
2003-02-03 Fixed PROTECT/UNPROTECT related bug causing execution of prepared que…
165 #undef UNPROTECT
5b09a955 »
2007-06-12 - add DLLIMPORT to Dynamic_library_path declaration for Win32
166 extern void pg_unprotect(int n, char *fn, int ln);
167 #define UNPROTECT(n) pg_unprotect(n, __FILE__, __LINE__)
842fe785 »
2003-02-03 Fixed PROTECT/UNPROTECT related bug causing execution of prepared que…
168 #endif /* DEBUGPROTECT */
169
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
170 #define xpfree(var_) \
171 do { \
172 if (var_ != NULL) \
173 { \
174 pfree(var_); \
175 var_ = NULL; \
176 } \
177 } while (0)
178
179 #define freeStringInfo(mystr_) \
180 do { \
181 xpfree((mystr_)->data); \
182 xpfree(mystr_); \
183 } while (0)
184
185 #define NEXT_STR_ELEMENT " %s"
186
889f33a2 »
2004-04-05 Code fixes and features:
187 #if (R_VERSION < 67840) /* R_VERSION < 1.9.0 */
188 #define SET_COLUMN_NAMES \
189 do { \
190 int i; \
191 char *names_buf; \
192 names_buf = SPI_fname(tupdesc, j + 1); \
193 for (i = 0; i < strlen(names_buf); i++) { \
194 if (names_buf[i] == '_') \
195 names_buf[i] = '.'; \
196 } \
197 SET_STRING_ELT(names, df_colnum, mkChar(names_buf)); \
198 pfree(names_buf); \
199 } while (0)
200 #else /* R_VERSION >= 1.9.0 */
201 #define SET_COLUMN_NAMES \
202 do { \
203 char *names_buf; \
204 names_buf = SPI_fname(tupdesc, j + 1); \
205 SET_STRING_ELT(names, df_colnum, mkChar(names_buf)); \
206 pfree(names_buf); \
207 } while (0)
208 #endif
209
210 #if (R_VERSION < 67584) /* R_VERSION < 1.8.0 */
67be537b »
2003-08-30 Detect Rversion and starting with version 1.8.0 eliminate the need to
211 /*
212 * See the non-exported header file ${R_HOME}/src/include/Parse.h
81a88ef3 »
2003-03-30 Interim commit:
213 */
214 extern SEXP R_ParseVector(SEXP, int, int *);
215 #define PARSE_NULL 0
216 #define PARSE_OK 1
217 #define PARSE_INCOMPLETE 2
218 #define PARSE_ERROR 3
219 #define PARSE_EOF 4
220
67be537b »
2003-08-30 Detect Rversion and starting with version 1.8.0 eliminate the need to
221 #define R_PARSEVECTOR(a_, b_, c_) R_ParseVector(a_, b_, c_)
00c7a66e »
2003-08-24 Dept of second thoughts -- instead of recommending setting of
222
223 /*
67be537b »
2003-08-30 Detect Rversion and starting with version 1.8.0 eliminate the need to
224 * See the non-exported header file ${R_HOME}/src/include/Defn.h
00c7a66e »
2003-08-24 Dept of second thoughts -- instead of recommending setting of
225 */
67be537b »
2003-08-30 Detect Rversion and starting with version 1.8.0 eliminate the need to
226 extern void R_PreserveObject(SEXP);
227 extern void R_ReleaseObject(SEXP);
00c7a66e »
2003-08-24 Dept of second thoughts -- instead of recommending setting of
228
adca9413 »
2003-08-31 Additional clean shutdown actions added per note from Prof. B. Ripley.
229 /* in main.c */
230 extern void R_dot_Last(void);
231
232 /* in memory.c */
233 extern void R_RunExitFinalizers(void);
234
235 #else /* R_VERSION >= 1.8.0 */
00c7a66e »
2003-08-24 Dept of second thoughts -- instead of recommending setting of
236
67be537b »
2003-08-30 Detect Rversion and starting with version 1.8.0 eliminate the need to
237 #include "R_ext/Parse.h"
238
2f6f75fa »
2007-06-02 - preserve callers memory context rather than assuming query memory c…
239 #if (R_VERSION >= 132352) /* R_VERSION >= 2.5.0 */
240 #define R_PARSEVECTOR(a_, b_, c_) R_ParseVector(a_, b_, (ParseStatus *) c_, R_NilValue)
241 #else /* R_VERSION < 2.5.0 */
242 #define R_PARSEVECTOR(a_, b_, c_) R_ParseVector(a_, b_, (ParseStatus *) c_)
243 #endif /* R_VERSION >= 2.5.0 */
244 #endif /* R_VERSION >= 1.8.0 */
00c7a66e »
2003-08-24 Dept of second thoughts -- instead of recommending setting of
245
81a88ef3 »
2003-03-30 Interim commit:
246 /* convert C string to text pointer */
247 #define PG_TEXT_GET_STR(textp_) \
248 DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(textp_)))
249 #define PG_STR_GET_TEXT(str_) \
250 DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(str_)))
251 #define PG_REPLACE_STR(str_, substr_, replacestr_) \
252 PG_TEXT_GET_STR(DirectFunctionCall3(replace_text, \
253 PG_STR_GET_TEXT(str_), \
254 PG_STR_GET_TEXT(substr_), \
255 PG_STR_GET_TEXT(replacestr_)))
256
49b6a24d »
2003-07-14 Modified compiled function hash table to be keyed on function Oid and
257 /* initial number of hash table entries for compiled functions */
258 #define FUNCS_PER_USER 64
81a88ef3 »
2003-03-30 Interim commit:
259
211ae2d5 »
2003-08-02 Backport ereport support from 7.4devel for use under 7.3.
260 #define ERRORCONTEXTCALLBACK \
261 ErrorContextCallback plerrcontext
262
263 #define PUSH_PLERRCONTEXT(_error_callback_, _plr_error_funcname_) \
264 do { \
265 plerrcontext.callback = _error_callback_; \
266 plerrcontext.arg = (void *) pstrdup(_plr_error_funcname_); \
267 plerrcontext.previous = error_context_stack; \
268 error_context_stack = &plerrcontext; \
269 } while (0)
270
271 #define POP_PLERRCONTEXT \
272 do { \
d2d54957 »
2007-09-08 - Update all Copyright notices.
273 pfree(plerrcontext.arg); \
211ae2d5 »
2003-08-02 Backport ereport support from 7.4devel for use under 7.3.
274 error_context_stack = plerrcontext.previous; \
275 } while (0)
276
277 #define SAVE_PLERRCONTEXT \
278 ErrorContextCallback *ecs_save; \
279 do { \
280 ecs_save = error_context_stack; \
281 error_context_stack = NULL; \
282 } while (0)
283
284 #define RESTORE_PLERRCONTEXT \
285 do { \
286 error_context_stack = ecs_save; \
287 } while (0)
288
053627d1 »
2003-08-04 First pass at adding trigger support. Not well tested, but works for …
289 #ifndef TEXTARRAYOID
290 #define TEXTARRAYOID 1009
291 #endif
211ae2d5 »
2003-08-02 Backport ereport support from 7.4devel for use under 7.3.
292
053627d1 »
2003-08-04 First pass at adding trigger support. Not well tested, but works for …
293 #define TRIGGER_NARGS 9
81a88ef3 »
2003-03-30 Interim commit:
294
863a8208 »
2004-02-26 Adjust for the fact that SortMem is now called work_mem in 7.5.
295 #define TUPLESTORE_BEGIN_HEAP tuplestore_begin_heap(true, false, work_mem)
296
49b6a24d »
2003-07-14 Modified compiled function hash table to be keyed on function Oid and
297 #define INIT_AUX_FMGR_ATTS \
81a88ef3 »
2003-03-30 Interim commit:
298 do { \
2f6f75fa »
2007-06-02 - preserve callers memory context rather than assuming query memory c…
299 finfo->fn_mcxt = plr_caller_context; \
49b6a24d »
2003-07-14 Modified compiled function hash table to be keyed on function Oid and
300 finfo->fn_expr = (Node *) NULL; \
81a88ef3 »
2003-03-30 Interim commit:
301 } while (0)
302
0b9d999e »
2005-03-30 Adjust for Postgres 8.1devel changes to proargtypes data type (oidvector
303 #define PROARGTYPES(i) \
304 procStruct->proargtypes.values[i]
305 #define FUNCARGTYPES(_tup_) \
a9313814 »
2005-03-31 Update for 8.1devel (oidvector now varlena)
306 ((Form_pg_proc) GETSTRUCT(_tup_))->proargtypes.values
0b9d999e »
2005-03-30 Adjust for Postgres 8.1devel changes to proargtypes data type (oidvector
307
5becd0e5 »
2003-12-14 Add test for 7.4 and 7.5 catalog versions. New macro to deal with rec…
308 #define PLR_CLEANUP \
889f33a2 »
2004-04-05 Code fixes and features:
309 plr_cleanup(int code, Datum arg)
310 #define TRIGGERTUPLEVARS \
311 HeapTuple tup; \
312 HeapTupleHeader dnewtup; \
313 HeapTupleHeader dtrigtup
314 #define SET_INSERT_ARGS_567 \
315 do { \
316 arg[5] = DirectFunctionCall1(textin, CStringGetDatum("INSERT")); \
317 tup = trigdata->tg_trigtuple; \
318 dtrigtup = (HeapTupleHeader) palloc(tup->t_len); \
319 memcpy((char *) dtrigtup, (char *) tup->t_data, tup->t_len); \
320 HeapTupleHeaderSetDatumLength(dtrigtup, tup->t_len); \
321 HeapTupleHeaderSetTypeId(dtrigtup, tupdesc->tdtypeid); \
322 HeapTupleHeaderSetTypMod(dtrigtup, tupdesc->tdtypmod); \
323 arg[6] = PointerGetDatum(dtrigtup); \
324 argnull[6] = false; \
325 arg[7] = (Datum) 0; \
326 argnull[7] = true; \
327 } while (0)
328 #define SET_DELETE_ARGS_567 \
329 do { \
330 arg[5] = DirectFunctionCall1(textin, CStringGetDatum("DELETE")); \
331 arg[6] = (Datum) 0; \
332 argnull[6] = true; \
333 tup = trigdata->tg_trigtuple; \
334 dtrigtup = (HeapTupleHeader) palloc(tup->t_len); \
335 memcpy((char *) dtrigtup, (char *) tup->t_data, tup->t_len); \
336 HeapTupleHeaderSetDatumLength(dtrigtup, tup->t_len); \
337 HeapTupleHeaderSetTypeId(dtrigtup, tupdesc->tdtypeid); \
338 HeapTupleHeaderSetTypMod(dtrigtup, tupdesc->tdtypmod); \
339 arg[7] = PointerGetDatum(dtrigtup); \
340 argnull[7] = false; \
341 } while (0)
342 #define SET_UPDATE_ARGS_567 \
343 do { \
344 arg[5] = DirectFunctionCall1(textin, CStringGetDatum("UPDATE")); \
345 tup = trigdata->tg_newtuple; \
346 dnewtup = (HeapTupleHeader) palloc(tup->t_len); \
347 memcpy((char *) dnewtup, (char *) tup->t_data, tup->t_len); \
348 HeapTupleHeaderSetDatumLength(dnewtup, tup->t_len); \
349 HeapTupleHeaderSetTypeId(dnewtup, tupdesc->tdtypeid); \
350 HeapTupleHeaderSetTypMod(dnewtup, tupdesc->tdtypmod); \
351 arg[6] = PointerGetDatum(dnewtup); \
352 argnull[6] = false; \
353 tup = trigdata->tg_trigtuple; \
354 dtrigtup = (HeapTupleHeader) palloc(tup->t_len); \
355 memcpy((char *) dtrigtup, (char *) tup->t_data, tup->t_len); \
356 HeapTupleHeaderSetDatumLength(dtrigtup, tup->t_len); \
357 HeapTupleHeaderSetTypeId(dtrigtup, tupdesc->tdtypeid); \
358 HeapTupleHeaderSetTypMod(dtrigtup, tupdesc->tdtypmod); \
359 arg[7] = PointerGetDatum(dtrigtup); \
360 argnull[7] = false; \
361 } while (0)
362 #define CONVERT_TUPLE_TO_DATAFRAME \
363 do { \
364 Oid tupType; \
365 int32 tupTypmod; \
366 TupleDesc tupdesc; \
367 HeapTuple tuple = palloc(sizeof(HeapTupleData)); \
368 HeapTupleHeader tuple_hdr = DatumGetHeapTupleHeader(arg[i]); \
369 tupType = HeapTupleHeaderGetTypeId(tuple_hdr); \
370 tupTypmod = HeapTupleHeaderGetTypMod(tuple_hdr); \
371 tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod); \
372 tuple->t_len = HeapTupleHeaderGetDatumLength(tuple_hdr); \
373 ItemPointerSetInvalid(&(tuple->t_self)); \
374 tuple->t_tableOid = InvalidOid; \
375 tuple->t_data = tuple_hdr; \
376 PROTECT(el = pg_tuple_get_r_frame(1, &tuple, tupdesc)); \
f86bec47 »
2006-09-11 - removed support (and overhead) for PostgreSQL prior to 8.2
377 ReleaseTupleDesc(tupdesc); \
889f33a2 »
2004-04-05 Code fixes and features:
378 pfree(tuple); \
379 } while (0)
380 #define GET_ARG_NAMES \
381 char **argnames; \
382 argnames = fetchArgNames(procTup, procStruct->pronargs)
383 #define SET_ARG_NAME \
384 do { \
385 if (argnames && argnames[i] && argnames[i][0]) \
386 { \
387 appendStringInfo(proc_internal_args, "%s", argnames[i]); \
388 pfree(argnames[i]); \
389 } \
390 else \
391 appendStringInfo(proc_internal_args, "arg%d", i + 1); \
392 } while (0)
6a9c69f5 »
2011-08-15 - New feature: allow PL/R functions to be declared and used as WINDOW
393 #define SET_FRAME_ARG_NAME \
394 do { \
395 appendStringInfo(proc_internal_args, "farg%d", i + 1); \
396 } while (0)
d3ce7741 »
2011-08-16 - Fixed few bugs in new farg code found based on test case from Ian Gow
397 #define SET_FRAME_XARG_NAMES \
398 do { \
399 appendStringInfo(proc_internal_args, ",fnumrows,prownum"); \
400 } while (0)
889f33a2 »
2004-04-05 Code fixes and features:
401 #define FREE_ARG_NAMES \
402 do { \
403 if (argnames) \
404 pfree(argnames); \
405 } while (0)
0b0ddea1 »
2004-12-01 Adjust for PostgreSQL 8.0.0 and R-2.0.1, including docs. Specifically
406 #define PREPARE_PG_TRY \
407 ERRORCONTEXTCALLBACK
435688de »
2010-07-24 - Minor improvements to how/when SPI is connected which
408 #define SWITCHTO_PLR_SPI_CONTEXT(the_caller_context) \
7a6b8246 »
2010-09-11 - Fix crashbug where array datum is NULL under certain circumstances
409 the_caller_context = MemoryContextSwitchTo(plr_SPI_context)
435688de »
2010-07-24 - Minor improvements to how/when SPI is connected which
410 #define CLEANUP_PLR_SPI_CONTEXT(the_caller_context) \
411 MemoryContextSwitchTo(the_caller_context)
fea4ae4c »
2004-08-30 - Added pgxs makefile
412 #define PLR_PG_CATCH() \
413 PG_CATCH(); \
414 { \
435688de »
2010-07-24 - Minor improvements to how/when SPI is connected which
415 MemoryContext temp_context; \
fea4ae4c »
2004-08-30 - Added pgxs makefile
416 ErrorData *edata; \
435688de »
2010-07-24 - Minor improvements to how/when SPI is connected which
417 SWITCHTO_PLR_SPI_CONTEXT(temp_context); \
fea4ae4c »
2004-08-30 - Added pgxs makefile
418 edata = CopyErrorData(); \
6a9c69f5 »
2011-08-15 - New feature: allow PL/R functions to be declared and used as WINDOW
419 MemoryContextSwitchTo(temp_context); \
fea4ae4c »
2004-08-30 - Added pgxs makefile
420 error("error in SQL statement : %s", edata->message); \
421 }
422 #define PLR_PG_END_TRY() \
423 PG_END_TRY()
5becd0e5 »
2003-12-14 Add test for 7.4 and 7.5 catalog versions. New macro to deal with rec…
424
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
425 /*
426 * structs
427 */
428
49b6a24d »
2003-07-14 Modified compiled function hash table to be keyed on function Oid and
429 typedef struct plr_func_hashkey
430 { /* Hash lookup key for functions */
431 Oid funcOid;
f95bc0ea »
2003-08-19 Add the trigger relation oid to the function cache hashkey struct. Match
432
433 /*
434 * For a trigger function, the OID of the relation triggered on is part
435 * of the hashkey --- we want to compile the trigger separately for each
436 * relation it is used with, in case the rowtype is different. Zero if
437 * not called as a trigger.
438 */
439 Oid trigrelOid;
440
49b6a24d »
2003-07-14 Modified compiled function hash table to be keyed on function Oid and
441 /*
442 * We include actual argument types in the hash key to support
443 * polymorphic PLpgSQL functions. Be careful that extra positions
444 * are zeroed!
445 */
446 Oid argtypes[FUNC_MAX_ARGS];
447 } plr_func_hashkey;
448
449
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
450 /* The information we cache about loaded procedures */
49b6a24d »
2003-07-14 Modified compiled function hash table to be keyed on function Oid and
451 typedef struct plr_function
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
452 {
49b6a24d »
2003-07-14 Modified compiled function hash table to be keyed on function Oid and
453 char *proname;
454 TransactionId fn_xmin;
2f6f75fa »
2007-06-02 - preserve callers memory context rather than assuming query memory c…
455 ItemPointerData fn_tid;
49b6a24d »
2003-07-14 Modified compiled function hash table to be keyed on function Oid and
456 plr_func_hashkey *fn_hashkey; /* back-link to hashtable key */
457 bool lanpltrusted;
458 Oid result_typid;
459 bool result_istuple;
460 FmgrInfo result_in_func;
461 Oid result_elem;
462 FmgrInfo result_elem_in_func;
463 int result_elem_typlen;
464 bool result_elem_typbyval;
465 char result_elem_typalign;
fea4ae4c »
2004-08-30 - Added pgxs makefile
466 int result_natts;
467 Oid *result_fld_elem_typid;
468 FmgrInfo *result_fld_elem_in_func;
469 int *result_fld_elem_typlen;
470 bool *result_fld_elem_typbyval;
471 char *result_fld_elem_typalign;
49b6a24d »
2003-07-14 Modified compiled function hash table to be keyed on function Oid and
472 int nargs;
473 Oid arg_typid[FUNC_MAX_ARGS];
d3ce7741 »
2011-08-16 - Fixed few bugs in new farg code found based on test case from Ian Gow
474 bool arg_typbyval[FUNC_MAX_ARGS];
49b6a24d »
2003-07-14 Modified compiled function hash table to be keyed on function Oid and
475 FmgrInfo arg_out_func[FUNC_MAX_ARGS];
476 Oid arg_elem[FUNC_MAX_ARGS];
477 FmgrInfo arg_elem_out_func[FUNC_MAX_ARGS];
478 int arg_elem_typlen[FUNC_MAX_ARGS];
479 bool arg_elem_typbyval[FUNC_MAX_ARGS];
480 char arg_elem_typalign[FUNC_MAX_ARGS];
481 int arg_is_rel[FUNC_MAX_ARGS];
482 SEXP fun; /* compiled R function */
f9b628b9 »
2011-08-15 - make WINDOW function feature safe for PostgreSQL 8.3 which does
483 #ifdef HAVE_WINDOW_FUNCTIONS
6a9c69f5 »
2011-08-15 - New feature: allow PL/R functions to be declared and used as WINDOW
484 bool iswindow;
f9b628b9 »
2011-08-15 - make WINDOW function feature safe for PostgreSQL 8.3 which does
485 #endif
49b6a24d »
2003-07-14 Modified compiled function hash table to be keyed on function Oid and
486 } plr_function;
487
488 /* compiled function hash table */
489 typedef struct plr_hashent
490 {
491 plr_func_hashkey key;
492 plr_function *function;
493 } plr_HashEnt;
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
494
495 /*
496 * external declarations
497 */
498
499 /* libR interpreter initialization */
500 extern int Rf_initEmbeddedR(int argc, char **argv);
501
502 /* PL/R language handler */
503 extern Datum plr_call_handler(PG_FUNCTION_ARGS);
5becd0e5 »
2003-12-14 Add test for 7.4 and 7.5 catalog versions. New macro to deal with rec…
504 extern void PLR_CLEANUP;
bc31a8a4 »
2003-08-02 Reworked initialization functions to match recent changes to pltcl, e…
505 extern void plr_init(void);
435688de »
2010-07-24 - Minor improvements to how/when SPI is connected which
506 extern void plr_load_modules(void);
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
507 extern void load_r_cmd(const char *cmd);
3368fdd5 »
2003-02-04 Modified attribution a bit. Changed a few function names to improve c…
508 extern SEXP call_r_func(SEXP fun, SEXP rargs);
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
509
510 /* argument and return value conversion functions */
0820fa3a »
2003-02-05 Improved handling of NULLs/NAs
511 extern SEXP pg_scalar_get_r(Datum dvalue, Oid arg_typid, FmgrInfo arg_out_func);
512 extern SEXP pg_array_get_r(Datum dvalue, FmgrInfo out_func, int typlen, bool typbyval, char typalign);
6a9c69f5 »
2011-08-15 - New feature: allow PL/R functions to be declared and used as WINDOW
513 extern SEXP pg_datum_array_get_r(Datum *elem_values, bool *elem_nulls, int numels, bool has_nulls,
514 Oid element_type, FmgrInfo out_func, bool typbyval);
0820fa3a »
2003-02-05 Improved handling of NULLs/NAs
515 extern SEXP pg_tuple_get_r_frame(int ntuples, HeapTuple *tuples, TupleDesc tupdesc);
49b6a24d »
2003-07-14 Modified compiled function hash table to be keyed on function Oid and
516 extern Datum r_get_pg(SEXP rval, plr_function *function, FunctionCallInfo fcinfo);
37642ef7 »
2010-10-10 - allow pg.spi.prepare/pg.spi.execp to use parameters which are 1D ar…
517 extern Datum get_datum(SEXP rval, Oid typid, Oid typelem, FmgrInfo in_func, bool *isnull);
c7aa0e9e »
2009-04-19 - updated copyright statements
518 extern Datum get_scalar_datum(SEXP rval, Oid result_typ, FmgrInfo result_in_func, bool *isnull);
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
519
520 /* Postgres support functions installed into the R interpreter */
7627a7f3 »
2003-02-10 Removed conversion of non-numeric data.frame columns to factors in C …
521 extern void throw_pg_notice(const char **msg);
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
522 extern SEXP plr_quote_literal(SEXP rawstr);
523 extern SEXP plr_quote_ident(SEXP rawstr);
524 extern SEXP plr_SPI_exec(SEXP rsql);
525 extern SEXP plr_SPI_prepare(SEXP rsql, SEXP rargtypes);
526 extern SEXP plr_SPI_execp(SEXP rsaved_plan, SEXP rargvalues);
d2d54957 »
2007-09-08 - Update all Copyright notices.
527 extern SEXP plr_SPI_cursor_open(SEXP cursor_name_arg,SEXP rsaved_plan, SEXP rargvalues);
528 extern SEXP plr_SPI_cursor_fetch(SEXP cursor_in,SEXP forward_in, SEXP rows_in);
529 extern void plr_SPI_cursor_close(SEXP cursor_in);
530 extern void plr_SPI_cursor_move(SEXP cursor_in, SEXP forward_in, SEXP rows_in);
842fe785 »
2003-02-03 Fixed PROTECT/UNPROTECT related bug causing execution of prepared que…
531 extern SEXP plr_SPI_lastoid(void);
d0be9dfa »
2003-07-20 Still working of getting errors with context from within R correct. I…
532 extern void throw_r_error(const char **msg);
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
533
534 /* Postgres callable functions useful in conjunction with PL/R */
d550f026 »
2011-08-15 - Add plr_version() function: outputs a version string. Includes
535 extern Datum plr_version(PG_FUNCTION_ARGS);
acf486f5 »
2003-03-18 Move redundant 1D-to-multiD array creation code into one function, wi…
536 extern Datum reload_plr_modules(PG_FUNCTION_ARGS);
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
537 extern Datum install_rcmd(PG_FUNCTION_ARGS);
5cdb7b5f »
2003-04-30 Sync'd support for Postgres 7.4 polymorphic array types with what act…
538 extern Datum plr_array_push(PG_FUNCTION_ARGS);
539 extern Datum plr_array(PG_FUNCTION_ARGS);
540 extern Datum plr_array_accum(PG_FUNCTION_ARGS);
541 extern Datum plr_environ(PG_FUNCTION_ARGS);
d2d54957 »
2007-09-08 - Update all Copyright notices.
542 extern Datum plr_set_rhome(PG_FUNCTION_ARGS);
543 extern Datum plr_unset_rhome(PG_FUNCTION_ARGS);
c7aa0e9e »
2009-04-19 - updated copyright statements
544 extern Datum plr_set_display(PG_FUNCTION_ARGS);
545 extern Datum plr_get_raw(PG_FUNCTION_ARGS);
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
546
547 /* Postgres backend support functions */
f95bc0ea »
2003-08-19 Add the trigger relation oid to the function cache hashkey struct. Match
548 extern void compute_function_hashkey(FunctionCallInfo fcinfo,
49b6a24d »
2003-07-14 Modified compiled function hash table to be keyed on function Oid and
549 Form_pg_proc procStruct,
550 plr_func_hashkey *hashkey);
551 extern void plr_HashTableInit(void);
552 extern plr_function *plr_HashTableLookup(plr_func_hashkey *func_key);
553 extern void plr_HashTableInsert(plr_function *function,
554 plr_func_hashkey *func_key);
555 extern void plr_HashTableDelete(plr_function *function);
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
556 extern char *get_load_self_ref_cmd(Oid funcid);
557 extern void perm_fmgr_info(Oid functionId, FmgrInfo *finfo);
a1bf401c »
2003-02-07 adjusted memory contexts throughout
558
afa0b3ce »
2003-02-02 Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
559 #endif /* PLR_H */
Something went wrong with that request. Please try again.