1 /**********************************************************************
2 * PostgreSQL::InServer::SPI
4 * SPI interface for plperl.
8 **********************************************************************/
10 /* this must be first: */
14 #define PG_NEED_PERL_XSUB_H
16 #include "plperl_helpers.h"
19 MODULE = PostgreSQL::InServer::SPI PREFIX = spi_
25 spi_spi_exec_query(sv, ...)
33 croak("Usage: spi_exec_query(query, limit) "
34 "or spi_exec_query(query)");
38 ret_hash = plperl_spi_exec(query, limit);
40 RETVAL = newRV_noinc((SV*) ret_hash);
48 plperl_return_next(rv);
54 char* query = sv2cstr(sv);
55 RETVAL = plperl_spi_query(query);
64 char* cursor = sv2cstr(sv);
65 RETVAL = plperl_spi_fetchrow(cursor);
71 spi_spi_prepare(sv, ...)
76 char* query = sv2cstr(sv);
78 Perl_croak(aTHX_ "Usage: spi_prepare(query, ...)");
79 argv = ( SV**) palloc(( items - 1) * sizeof(SV*));
80 for ( i = 1; i < items; i++)
82 RETVAL = plperl_spi_prepare(query, items - 1, argv);
89 spi_spi_exec_prepared(sv, ...)
95 int i, offset = 1, argc;
97 char *query = sv2cstr(sv);
99 Perl_croak(aTHX_ "Usage: spi_exec_prepared(query, [\\%%attr,] "
100 "[\\@bind_values])");
101 if ( items > 1 && SvROK( ST( 1)) && SvTYPE( SvRV( ST( 1))) == SVt_PVHV)
103 attr = ( HV*) SvRV(ST(1));
106 argc = items - offset;
107 argv = ( SV**) palloc( argc * sizeof(SV*));
108 for ( i = 0; offset < items; offset++, i++)
109 argv[i] = ST(offset);
110 ret_hash = plperl_spi_exec_prepared(query, attr, argc, argv);
111 RETVAL = newRV_noinc((SV*)ret_hash);
118 spi_spi_query_prepared(sv, ...)
123 char *query = sv2cstr(sv);
125 Perl_croak(aTHX_ "Usage: spi_query_prepared(query, "
126 "[\\@bind_values])");
127 argv = ( SV**) palloc(( items - 1) * sizeof(SV*));
128 for ( i = 1; i < items; i++)
130 RETVAL = plperl_spi_query_prepared(query, items - 1, argv);
140 char *query = sv2cstr(sv);
141 plperl_spi_freeplan(query);
145 spi_spi_cursor_close(sv)
148 char *cursor = sv2cstr(sv);
149 plperl_spi_cursor_close(cursor);
160 plperl_spi_rollback();
163 items = 0; /* avoid 'unused variable' warning */