… | |
… | |
79 | |
79 | |
80 | dbh = SvRV (dbh); |
80 | dbh = SvRV (dbh); |
81 | |
81 | |
82 | lru_hash; |
82 | lru_hash; |
83 | |
83 | |
84 | /*fprintf (stderr, "F: %08lx %s\n", hash, SvPV_nolen (sql));/*D*/ |
|
|
85 | |
|
|
86 | n = &lru_list; |
84 | n = &lru_list; |
87 | do { |
85 | do { |
88 | n = n->next; |
86 | n = n->next; |
89 | if (!n->hash) |
87 | if (!n->hash) |
90 | return 0; |
88 | return 0; |
… | |
… | |
112 | n = lru_list.prev; |
110 | n = lru_list.prev; |
113 | |
111 | |
114 | lru_list.prev = n->prev; |
112 | lru_list.prev = n->prev; |
115 | n->prev->next = &lru_list; |
113 | n->prev->next = &lru_list; |
116 | |
114 | |
117 | /*fprintf (stderr, "N: %s\n", SvPV_nolen (n->sql));/*D*/ |
|
|
118 | |
|
|
119 | SvREFCNT_dec (n->dbh); |
115 | SvREFCNT_dec (n->dbh); |
120 | SvREFCNT_dec (n->sql); |
116 | SvREFCNT_dec (n->sql); |
121 | SvREFCNT_dec (n->sth); |
117 | SvREFCNT_dec (n->sth); |
122 | Safefree (n); |
118 | Safefree (n); |
123 | |
119 | |
… | |
… | |
135 | |
131 | |
136 | dbh = SvRV (dbh); |
132 | dbh = SvRV (dbh); |
137 | |
133 | |
138 | lru_hash; |
134 | lru_hash; |
139 | |
135 | |
140 | /*fprintf (stderr, "S: %08lx %s\n", hash, SvPV_nolen (sql));/*D*/ |
|
|
141 | |
|
|
142 | lru_size++; |
136 | lru_size++; |
143 | if (lru_size > lru_maxsize) |
137 | if (lru_size > lru_maxsize) |
144 | lru_nukeone (); |
138 | lru_nukeone (); |
145 | |
139 | |
146 | New (0, n, 1, lru_node); |
140 | New (0, n, 1, lru_node); |
… | |
… | |
166 | } |
160 | } |
167 | } |
161 | } |
168 | |
162 | |
169 | static GV *sql_exec; |
163 | static GV *sql_exec; |
170 | static GV *DBH; |
164 | static GV *DBH; |
171 | static SV *sv_prepare, *sv_execute, *sv_bind_columns, *sv_fetchrow_arrayref, *sv_finish; |
165 | static SV *sv_prepare, *sv_execute, *sv_bind_columns, |
|
|
166 | *sv_fetchrow_arrayref, *sv_fetchall_arrayref, |
|
|
167 | *sv_finish; |
172 | |
168 | |
173 | #define newconstpv(str) newSVpvn ((str), sizeof (str)) |
169 | #define newconstpv(str) newSVpvn ((str), sizeof (str)) |
174 | |
170 | |
175 | MODULE = PApp::SQL PACKAGE = PApp::SQL |
171 | MODULE = PApp::SQL PACKAGE = PApp::SQL |
176 | |
172 | |
… | |
… | |
185 | { |
181 | { |
186 | sv_prepare = newconstpv ("prepare"); |
182 | sv_prepare = newconstpv ("prepare"); |
187 | sv_execute = newconstpv ("execute"); |
183 | sv_execute = newconstpv ("execute"); |
188 | sv_bind_columns = newconstpv ("bind_columns"); |
184 | sv_bind_columns = newconstpv ("bind_columns"); |
189 | sv_fetchrow_arrayref = newconstpv ("fetchrow_arrayref"); |
185 | sv_fetchrow_arrayref = newconstpv ("fetchrow_arrayref"); |
|
|
186 | sv_fetchall_arrayref = newconstpv ("fetchall_arrayref"); |
190 | sv_finish = newconstpv ("finish"); |
187 | sv_finish = newconstpv ("finish"); |
191 | } |
188 | } |
192 | |
189 | |
193 | /* apache might BOOT: twice :( */ |
190 | /* apache might BOOT: twice :( */ |
194 | if (lru_size) |
191 | if (lru_size) |
… | |
… | |
269 | { |
266 | { |
270 | SV *neu = sv_2mortal (newSVpv ("select count(*) > 0 from ", 0)); |
267 | SV *neu = sv_2mortal (newSVpv ("select count(*) > 0 from ", 0)); |
271 | sv_catsv (neu, sql); |
268 | sv_catsv (neu, sql); |
272 | sv_catpv (neu, " limit 1"); |
269 | sv_catpv (neu, " limit 1"); |
273 | sql = neu; |
270 | sql = neu; |
274 | ix -= 6; /* sql_fetch */ |
271 | ix -= 4; /* sql_fetch */ |
275 | } |
272 | } |
276 | |
273 | |
277 | /* check cache for existing statement handle */ |
274 | /* check cache for existing statement handle */ |
278 | sth = lru_fetch (dbh, sql); |
275 | sth = lru_fetch (dbh, sql); |
279 | if (!sth) |
276 | if (!sth) |
… | |
… | |
401 | SV *rows; |
398 | SV *rows; |
402 | |
399 | |
403 | PUSHMARK (SP); |
400 | PUSHMARK (SP); |
404 | XPUSHs (sth); |
401 | XPUSHs (sth); |
405 | PUTBACK; |
402 | PUTBACK; |
406 | count = call_sv (sv_fetchrow_arrayref, G_METHOD | G_SCALAR); |
403 | count = call_sv (sv_fetchall_arrayref, G_METHOD | G_SCALAR); |
407 | SPAGAIN; |
404 | SPAGAIN; |
408 | |
405 | |
409 | if (count != 1) |
406 | if (count != 1) |
410 | abort (); |
407 | abort (); |
411 | |
408 | |
… | |
… | |
416 | AV *av = (AV *)SvRV (rows); |
413 | AV *av = (AV *)SvRV (rows); |
417 | count = AvFILL (av) + 1; |
414 | count = AvFILL (av) + 1; |
418 | |
415 | |
419 | if (count) |
416 | if (count) |
420 | { |
417 | { |
421 | int columns = AvFILL ((AV *)SvRV (AvARRAY(av)[0])) + 1; /* columns? */ |
418 | int columns = AvFILL ((AV *) SvRV (AvARRAY (av)[0])) + 1; /* columns? */ |
422 | |
419 | |
423 | EXTEND (SP, count); |
420 | EXTEND (SP, count); |
424 | if (columns == 1) |
421 | if (columns == 1) |
425 | for (arg = 0; arg < count; arg++) |
422 | for (arg = 0; arg < count; arg++) |
426 | PUSHs (maybe_force_utf8 (ix & 1, AvARRAY ((AV *)SvRV (AvARRAY (av)[arg]))[0])); |
423 | PUSHs (maybe_force_utf8 (ix & 1, AvARRAY ((AV *)SvRV (AvARRAY (av)[arg]))[0])); |