… | |
… | |
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 | |
… | |
… | |
134 | char *statement = SvPV (sql, len); |
130 | char *statement = SvPV (sql, len); |
135 | |
131 | |
136 | dbh = SvRV (dbh); |
132 | dbh = SvRV (dbh); |
137 | |
133 | |
138 | lru_hash; |
134 | lru_hash; |
139 | |
|
|
140 | /*fprintf (stderr, "S: %08lx %s\n", hash, SvPV_nolen (sql));/*D*/ |
|
|
141 | |
135 | |
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 | |
… | |
… | |
231 | int count; |
225 | int count; |
232 | SV *dbh = ST(0); |
226 | SV *dbh = ST(0); |
233 | SV *sth; |
227 | SV *sth; |
234 | SV *sql; |
228 | SV *sql; |
235 | SV *execute; |
229 | SV *execute; |
236 | STRLEN dc; |
230 | STRLEN dc, dd; /* dummy */ |
237 | |
231 | |
238 | /* save our arguments against destruction through function calls */ |
232 | /* save our arguments against destruction through function calls */ |
239 | SP += items; |
233 | SP += items; |
240 | |
234 | |
241 | /* first check wether we should use an explicit db handle */ |
235 | /* first check wether we should use an explicit db handle */ |
… | |
… | |
272 | { |
266 | { |
273 | SV *neu = sv_2mortal (newSVpv ("select count(*) > 0 from ", 0)); |
267 | SV *neu = sv_2mortal (newSVpv ("select count(*) > 0 from ", 0)); |
274 | sv_catsv (neu, sql); |
268 | sv_catsv (neu, sql); |
275 | sv_catpv (neu, " limit 1"); |
269 | sv_catpv (neu, " limit 1"); |
276 | sql = neu; |
270 | sql = neu; |
277 | ix -= 6; /* sql_fetch */ |
271 | ix -= 4; /* sql_fetch */ |
278 | } |
272 | } |
279 | |
273 | |
280 | /* check cache for existing statement handle */ |
274 | /* check cache for existing statement handle */ |
281 | sth = lru_fetch (dbh, sql); |
275 | sth = lru_fetch (dbh, sql); |
282 | if (!sth) |
276 | if (!sth) |
… | |
… | |
290 | SPAGAIN; |
284 | SPAGAIN; |
291 | |
285 | |
292 | if (count != 1) |
286 | if (count != 1) |
293 | croak ("sql_exec: unable to prepare() statement '%s': %s", |
287 | croak ("sql_exec: unable to prepare() statement '%s': %s", |
294 | SvPV (sql, dc), |
288 | SvPV (sql, dc), |
295 | SvPV (get_sv ("DBI::errstr", TRUE), dc)); |
289 | SvPV (get_sv ("DBI::errstr", TRUE), dd)); |
296 | |
290 | |
297 | sth = POPs; |
291 | sth = POPs; |
298 | |
292 | |
299 | lru_store (dbh, sql, sth); |
293 | lru_store (dbh, sql, sth); |
300 | } |
294 | } |