1 /* this must be first: */
11 * Implementation of plperl's elog() function
13 * If the error level is less than ERROR, we'll just emit the message and
14 * return. When it is ERROR, elog() will longjmp, which we catch and
15 * turn into a Perl croak(). Note we are assuming that elog() can't have
16 * any internal failures that are so bad as to require a transaction abort.
18 * This is out-of-line to suppress "might be clobbered by longjmp" warnings.
21 do_spi_elog(int level, char *message)
23 MemoryContext oldcontext = CurrentMemoryContext;
27 elog(level, "%s", message);
33 /* Must reset elog.c's state */
34 MemoryContextSwitchTo(oldcontext);
35 edata = CopyErrorData();
38 /* Punt the error to Perl */
39 croak("%s", edata->message);
45 * Interface routine to catch ereports and punt them to Perl
48 do_plperl_return_next(SV *sv)
50 MemoryContext oldcontext = CurrentMemoryContext;
54 plperl_return_next(sv);
60 /* Must reset elog.c's state */
61 MemoryContextSwitchTo(oldcontext);
62 edata = CopyErrorData();
65 /* Punt the error to Perl */
66 croak("%s", edata->message);
72 MODULE = SPI PREFIX = spi_
78 spi_elog(level, message)
82 if (level > ERROR) /* no PANIC allowed thanks */
86 do_spi_elog(level, message);
107 spi_spi_exec_query(query, ...)
114 croak("Usage: spi_exec_query(query, limit) "
115 "or spi_exec_query(query)");
118 ret_hash = plperl_spi_exec(query, limit);
119 RETVAL = newRV_noinc((SV*) ret_hash);
127 do_plperl_return_next(rv);
133 RETVAL = plperl_spi_query(query);
138 spi_spi_fetchrow(cursor)
141 RETVAL = plperl_spi_fetchrow(cursor);
146 spi_spi_prepare(query, ...)
152 Perl_croak(aTHX_ "Usage: spi_prepare(query, ...)");
153 argv = ( SV**) palloc(( items - 1) * sizeof(SV*));
154 for ( i = 1; i < items; i++)
156 RETVAL = plperl_spi_prepare(query, items - 1, argv);
162 spi_spi_exec_prepared(query, ...)
168 int i, offset = 1, argc;
171 Perl_croak(aTHX_ "Usage: spi_exec_prepared(query, [\\%%attr,] "
172 "[\\@bind_values])");
173 if ( items > 1 && SvROK( ST( 1)) && SvTYPE( SvRV( ST( 1))) == SVt_PVHV)
175 attr = ( HV*) SvRV(ST(1));
178 argc = items - offset;
179 argv = ( SV**) palloc( argc * sizeof(SV*));
180 for ( i = 0; offset < items; offset++, i++)
181 argv[i] = ST(offset);
182 ret_hash = plperl_spi_exec_prepared(query, attr, argc, argv);
183 RETVAL = newRV_noinc((SV*)ret_hash);
189 spi_spi_query_prepared(query, ...)
195 Perl_croak(aTHX_ "Usage: spi_query_prepared(query, "
196 "[\\@bind_values])");
197 argv = ( SV**) palloc(( items - 1) * sizeof(SV*));
198 for ( i = 1; i < items; i++)
200 RETVAL = plperl_spi_query_prepared(query, items - 1, argv);
206 spi_spi_freeplan(query)
209 plperl_spi_freeplan(query);
212 spi_spi_cursor_close(cursor)
215 plperl_spi_cursor_close(cursor);
219 items = 0; /* avoid 'unused variable' warning */