Debian Codegraph @

src/pl/plperl/SPI.xs

raw
1 /**********************************************************************
2 * PostgreSQL::InServer::SPI
3 *
4 * SPI interface for plperl.
5 *
6 * src/pl/plperl/SPI.xs
7 *
8 **********************************************************************/
9
10 /* this must be first: */
11 #include "postgres.h"
12
13 /* perl stuff */
14 #define PG_NEED_PERL_XSUB_H
15 #include "plperl.h"
16
17
18 MODULE = PostgreSQL::InServer::SPI PREFIX = spi_
19
20 PROTOTYPES: ENABLE
21 VERSIONCHECK: DISABLE
22
23 SV*
24 spi_spi_exec_query(sv, ...)
25 SV* sv;
26 PREINIT:
27 HV *ret_hash;
28 int limit = 0;
29 char *query;
30 CODE:
31 if (items > 2)
32 croak("Usage: spi_exec_query(query, limit) "
33 "or spi_exec_query(query)");
34 if (items == 2)
35 limit = SvIV(ST(1));
36 query = sv2cstr(sv);
37 ret_hash = plperl_spi_exec(query, limit);
38 pfree(query);
39 RETVAL = newRV_noinc((SV*) ret_hash);
40 OUTPUT:
41 RETVAL
42
43 void
44 spi_return_next(rv)
45 SV *rv;
46 CODE:
47 plperl_return_next(rv);
48
49 SV *
50 spi_spi_query(sv)
51 SV *sv;
52 CODE:
53 char* query = sv2cstr(sv);
54 RETVAL = plperl_spi_query(query);
55 pfree(query);
56 OUTPUT:
57 RETVAL
58
59 SV *
60 spi_spi_fetchrow(sv)
61 SV* sv;
62 CODE:
63 char* cursor = sv2cstr(sv);
64 RETVAL = plperl_spi_fetchrow(cursor);
65 pfree(cursor);
66 OUTPUT:
67 RETVAL
68
69 SV*
70 spi_spi_prepare(sv, ...)
71 SV* sv;
72 CODE:
73 int i;
74 SV** argv;
75 char* query = sv2cstr(sv);
76 if (items < 1)
77 Perl_croak(aTHX_ "Usage: spi_prepare(query, ...)");
78 argv = palloc_array(SV*, items - 1);
79 for ( i = 1; i < items; i++)
80 argv[i - 1] = ST(i);
81 RETVAL = plperl_spi_prepare(query, items - 1, argv);
82 pfree( argv);
83 pfree(query);
84 OUTPUT:
85 RETVAL
86
87 SV*
88 spi_spi_exec_prepared(sv, ...)
89 SV* sv;
90 PREINIT:
91 HV *ret_hash;
92 CODE:
93 HV *attr = NULL;
94 int i, offset = 1, argc;
95 SV ** argv;
96 char *query = sv2cstr(sv);
97 if ( items < 1)
98 Perl_croak(aTHX_ "Usage: spi_exec_prepared(query, [\\%%attr,] "
99 "[\\@bind_values])");
100 if ( items > 1 && SvROK( ST( 1)) && SvTYPE( SvRV( ST( 1))) == SVt_PVHV)
101 {
102 attr = ( HV*) SvRV(ST(1));
103 offset++;
104 }
105 argc = items - offset;
106 argv = palloc_array(SV*, argc);
107 for ( i = 0; offset < items; offset++, i++)
108 argv[i] = ST(offset);
109 ret_hash = plperl_spi_exec_prepared(query, attr, argc, argv);
110 RETVAL = newRV_noinc((SV*)ret_hash);
111 pfree( argv);
112 pfree(query);
113 OUTPUT:
114 RETVAL
115
116 SV*
117 spi_spi_query_prepared(sv, ...)
118 SV * sv;
119 CODE:
120 int i;
121 SV ** argv;
122 char *query = sv2cstr(sv);
123 if ( items < 1)
124 Perl_croak(aTHX_ "Usage: spi_query_prepared(query, "
125 "[\\@bind_values])");
126 argv = palloc_array(SV*, items - 1);
127 for ( i = 1; i < items; i++)
128 argv[i - 1] = ST(i);
129 RETVAL = plperl_spi_query_prepared(query, items - 1, argv);
130 pfree( argv);
131 pfree(query);
132 OUTPUT:
133 RETVAL
134
135 void
136 spi_spi_freeplan(sv)
137 SV *sv;
138 CODE:
139 char *query = sv2cstr(sv);
140 plperl_spi_freeplan(query);
141 pfree(query);
142
143 void
144 spi_spi_cursor_close(sv)
145 SV *sv;
146 CODE:
147 char *cursor = sv2cstr(sv);
148 plperl_spi_cursor_close(cursor);
149 pfree(cursor);
150
151 void
152 spi_spi_commit()
153 CODE:
154 plperl_spi_commit();
155
156 void
157 spi_spi_rollback()
158 CODE:
159 plperl_spi_rollback();
160
161 BOOT:
162 items = 0; /* avoid 'unused variable' warning */