ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/PApp-SQL/SQL.xs
(Generate patch)

Comparing PApp-SQL/SQL.xs (file contents):
Revision 1.5 by root, Sun Apr 22 14:38:28 2001 UTC vs.
Revision 1.9 by root, Mon Dec 31 03:05:03 2001 UTC

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
169static GV *sql_exec; 163static GV *sql_exec;
170static GV *DBH; 164static GV *DBH;
171static SV *sv_prepare, *sv_execute, *sv_bind_columns, *sv_fetchrow_arrayref, *sv_finish; 165static 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
175MODULE = PApp::SQL PACKAGE = PApp::SQL 171MODULE = 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)
228 int count; 225 int count;
229 SV *dbh = ST(0); 226 SV *dbh = ST(0);
230 SV *sth; 227 SV *sth;
231 SV *sql; 228 SV *sql;
232 SV *execute; 229 SV *execute;
233 STRLEN dc; 230 STRLEN dc, dd; /* dummy */
234 231
235 /* save our arguments against destruction through function calls */ 232 /* save our arguments against destruction through function calls */
236 SP += items; 233 SP += items;
237 234
238 /* first check wether we should use an explicit db handle */ 235 /* first check wether we should use an explicit db handle */
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)
287 SPAGAIN; 284 SPAGAIN;
288 285
289 if (count != 1) 286 if (count != 1)
290 croak ("sql_exec: unable to prepare() statement '%s': %s", 287 croak ("sql_exec: unable to prepare() statement '%s': %s",
291 SvPV (sql, dc), 288 SvPV (sql, dc),
292 SvPV (get_sv ("DBI::errstr", TRUE), dc)); 289 SvPV (get_sv ("DBI::errstr", TRUE), dd));
293 290
294 sth = POPs; 291 sth = POPs;
295 292
296 lru_store (dbh, sql, sth); 293 lru_store (dbh, sql, sth);
297 } 294 }
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]));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines