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.13 by root, Wed Jun 26 03:26:39 2002 UTC vs.
Revision 1.20 by root, Sat Jun 20 21:29:29 2009 UTC

9#endif 9#endif
10 10
11#if (PERL_VERSION > 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION >= 6)) 11#if (PERL_VERSION > 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION >= 6))
12# define CAN_UTF8 1 12# define CAN_UTF8 1
13#endif 13#endif
14
15#define MAX_CACHED_STATEMENT_SIZE 8192
14 16
15static SV * 17static SV *
16sql_upgrade_utf8 (SV *sv) 18sql_upgrade_utf8 (SV *sv)
17{ 19{
18#if CAN_UTF8 20#if CAN_UTF8
60#define lru_init lru_list.next = &lru_list; lru_list.prev = &lru_list /* other fields are zero */ 62#define lru_init lru_list.next = &lru_list; lru_list.prev = &lru_list /* other fields are zero */
61 63
62/* this is primitive, yet effective */ 64/* this is primitive, yet effective */
63/* the returned value must never be zero (or bad things will happen) */ 65/* the returned value must never be zero (or bad things will happen) */
64#define lru_hash do { \ 66#define lru_hash do { \
65 hash = (((U32)dbh)>>2); \ 67 hash = (((U32)(long)dbh)>>2); \
66 hash += *statement;\ 68 hash += *statement;\
67 hash += len; \ 69 hash += len; \
68} while (0) 70} while (0)
69 71
70/* fetch and "use" */ 72/* fetch and "use" */
237 { 239 {
238 /* the next line doesn't work - check why later maybe */ 240 /* the next line doesn't work - check why later maybe */
239 /* dbh = get_sv ("DBH", FALSE); 241 /* dbh = get_sv ("DBH", FALSE);
240 if (!is_dbh (dbh)) 242 if (!is_dbh (dbh))
241 {*/ 243 {*/
242 dbh = GvSV(DBH); 244 dbh = GvSV (DBH);
243 if (!is_dbh (dbh)) 245 if (!is_dbh (dbh))
244 croak ("sql_exec: no $DBH argument and no fallback in $PApp::SQL::DBH"); 246 croak ("sql_exec: no $DBH argument and no fallback in $PApp::SQL::DBH");
245 /*croak ("sql_exec: no $DBH found in current package or in PApp::SQL::"); 247 /*croak ("sql_exec: no $DBH found in current package or in PApp::SQL::");
246 }*/ 248 }*/
247 } 249 }
248 else 250 else
249 arg++; /* we consumed one argument */ 251 arg++; /* we consumed one argument */
252
253 /* be more Coro-friendly by keeping a copy, so different threads */
254 /* can multitask easier */
255 dbh = sv_2mortal (newSVsv (dbh));
250 256
251 /* count the remaining references (for bind_columns) */ 257 /* count the remaining references (for bind_columns) */
252 bind_first = arg; 258 bind_first = arg;
253 while (items > arg && SvROK (ST(arg))) 259 while (items > arg && SvROK (ST(arg)))
254 arg++; 260 arg++;
290 SvPV (sql, dc), 296 SvPV (sql, dc),
291 SvPV (get_sv ("DBI::errstr", TRUE), dd)); 297 SvPV (get_sv ("DBI::errstr", TRUE), dd));
292 298
293 sth = POPs; 299 sth = POPs;
294 300
301 if (SvLEN (sql) < MAX_CACHED_STATEMENT_SIZE)
295 lru_store (dbh, sql, sth); 302 lru_store (dbh, sql, sth);
296 } 303 }
297 304
298 PUSHMARK (SP); 305 PUSHMARK (SP);
299 EXTEND (SP, items - arg + 1); 306 EXTEND (SP, items - arg + 1);
300 PUSHs (sth); 307 PUSHs (sth);
301 while (items > arg) 308 while (items > arg)
302 { 309 {
310 SV *sv = ST(arg);
311 /* we sv_mortalcopy magical values since DBI seems to have a memory
312 * leak when magical values are passed into execute().
313 */
303 PUSHs (maybe_upgrade_utf8 (ix & 1, ST(arg))); 314 PUSHs (maybe_upgrade_utf8 (ix & 1, SvMAGICAL(sv) ? sv_mortalcopy(sv) : sv));
304 arg++; 315 arg++;
305 } 316 }
306 317
307 PUTBACK; 318 PUTBACK;
308 /* { static GV *execute; 319 /* { static GV *execute;
330 { 341 {
331 PUSHMARK (SP); 342 PUSHMARK (SP);
332 EXTEND (SP, bind_last - bind_first + 2); 343 EXTEND (SP, bind_last - bind_first + 2);
333 PUSHs (sth); 344 PUSHs (sth);
334 do { 345 do {
346#if CAN_UTF8
347 if (ix & 1)
348 SvUTF8_on (SvRV(ST(bind_first)));
349#endif
335 PUSHs (ST(bind_first)); 350 PUSHs (ST(bind_first));
336 bind_first++; 351 bind_first++;
337 } while (bind_first != bind_last); 352 } while (bind_first != bind_last);
338 353
339 PUTBACK; 354 PUTBACK;
343 if (count != 1) 358 if (count != 1)
344 croak ("sql_exec: bind_columns() didn't return any value ('%s'): %s", 359 croak ("sql_exec: bind_columns() didn't return any value ('%s'): %s",
345 SvPV (sql, dc), 360 SvPV (sql, dc),
346 SvPV (get_sv ("DBI::errstr", TRUE), dd)); 361 SvPV (get_sv ("DBI::errstr", TRUE), dd));
347 362
348 if (!SvOK (POPs)) 363 if (!SvOK (TOPs))
349 croak ("sql_exec: bind_columns() didn't return a true ('%s'): %s", 364 croak ("sql_exec: bind_columns() didn't return a true ('%s'): %s",
350 SvPV (sql, dc), 365 SvPV (sql, dc),
351 SvPV (get_sv ("DBI::errstr", TRUE), dd)); 366 SvPV (get_sv ("DBI::errstr", TRUE), dd));
367
352 } 368 POPs;
369 }
353 370
354 /* free our arguments from the stack */ 371 /* restore our arguments again */
355 SP -= items; 372 SP -= items;
356 373
357 if ((ix & ~1) == 2) 374 if ((ix & ~1) == 2)
358 { /* sql_fetch */ 375 { /* sql_fetch */
359 SV *row; 376 SV *row;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines