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.12 by root, Thu Apr 11 01:02:10 2002 UTC vs.
Revision 1.15 by root, Thu Nov 7 01:57:58 2002 UTC

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 14
15#define MAX_CACHED_STATEMENT_SIZE 8192
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
19 if (SvPOK (sv)) 21 if (SvPOK (sv))
21#endif 23#endif
22 return sv; 24 return sv;
23} 25}
24 26
25static SV * 27static SV *
26sql_force_utf8 (SV *sv) 28mortalcopy_and_maybe_force_utf8(int utf8, SV *sv)
27{ 29{
30 sv = sv_mortalcopy (sv);
28#if CAN_UTF8 31#if CAN_UTF8
29 if (SvPOK (sv)) 32 if (utf8 && SvPOK (sv))
30 SvUTF8_on (sv); 33 SvUTF8_on (sv);
31#endif 34#endif
32 return sv; 35 return sv;
33} 36}
34 37
35#define maybe_upgrade_utf8(utf8,sv) ((utf8) ? sql_upgrade_utf8 (sv) : (sv)) 38#define maybe_upgrade_utf8(utf8,sv) ((utf8) ? sql_upgrade_utf8 (sv) : (sv))
36#define maybe_force_utf8(utf8,sv) ((utf8) ? sql_force_utf8 (sv) : (sv))
37 39
38#define is_dbh(sv) ((sv) && sv_isobject (sv) && sv_derived_from ((sv), "DBI::db")) 40#define is_dbh(sv) ((sv) && sv_isobject (sv) && sv_derived_from ((sv), "DBI::db"))
39 41
40typedef struct lru_node { 42typedef struct lru_node {
41 struct lru_node *next; 43 struct lru_node *next;
290 SvPV (sql, dc), 292 SvPV (sql, dc),
291 SvPV (get_sv ("DBI::errstr", TRUE), dd)); 293 SvPV (get_sv ("DBI::errstr", TRUE), dd));
292 294
293 sth = POPs; 295 sth = POPs;
294 296
297 if (SvLEN (sql) < MAX_CACHED_STATEMENT_SIZE)
295 lru_store (dbh, sql, sth); 298 lru_store (dbh, sql, sth);
296 } 299 }
297 300
298 PUSHMARK (SP); 301 PUSHMARK (SP);
299 EXTEND (SP, items - arg + 1); 302 EXTEND (SP, items - arg + 1);
300 PUSHs (sth); 303 PUSHs (sth);
301 while (items > arg) 304 while (items > arg)
302 { 305 {
306 SV *sv = ST(arg);
307 /* we sv_mortalcopy magical values since DBI seems to have a memory
308 * leak when magical values are passed into execute().
309 */
303 PUSHs (maybe_upgrade_utf8 (ix & 1, ST(arg))); 310 PUSHs (maybe_upgrade_utf8 (ix & 1, SvMAGICAL(sv) ? sv_mortalcopy(sv) : sv));
304 arg++; 311 arg++;
305 } 312 }
306 313
307 PUTBACK; 314 PUTBACK;
308 /* { static GV *execute; 315 /* { static GV *execute;
378 case G_VOID: 385 case G_VOID:
379 /* no thing */ 386 /* no thing */
380 break; 387 break;
381 case G_SCALAR: 388 case G_SCALAR:
382 /* the first element */ 389 /* the first element */
383 XPUSHs (maybe_force_utf8 (ix & 1, *av_fetch ((AV *)SvRV (row), 0, 1))); 390 XPUSHs (mortalcopy_and_maybe_force_utf8 (ix & 1, *av_fetch ((AV *)SvRV (row), 0, 1)));
384 break; 391 break;
385 case G_ARRAY: 392 case G_ARRAY:
386 av = (AV *)SvRV (row); 393 av = (AV *)SvRV (row);
387 count = AvFILL (av) + 1; 394 count = AvFILL (av) + 1;
388 EXTEND (SP, count); 395 EXTEND (SP, count);
389 for (arg = 0; arg < count; arg++) 396 for (arg = 0; arg < count; arg++)
390 PUSHs (maybe_force_utf8 (ix & 1, AvARRAY (av)[arg])); 397 PUSHs (mortalcopy_and_maybe_force_utf8 (ix & 1, AvARRAY (av)[arg]));
391 398
392 break; 399 break;
393 default: 400 default:
394 abort (); 401 abort ();
395 } 402 }
420 int columns = AvFILL ((AV *) SvRV (AvARRAY (av)[0])) + 1; /* columns? */ 427 int columns = AvFILL ((AV *) SvRV (AvARRAY (av)[0])) + 1; /* columns? */
421 428
422 EXTEND (SP, count); 429 EXTEND (SP, count);
423 if (columns == 1) 430 if (columns == 1)
424 for (arg = 0; arg < count; arg++) 431 for (arg = 0; arg < count; arg++)
425 PUSHs (maybe_force_utf8 (ix & 1, AvARRAY ((AV *)SvRV (AvARRAY (av)[arg]))[0])); 432 PUSHs (mortalcopy_and_maybe_force_utf8 (ix & 1, AvARRAY ((AV *)SvRV (AvARRAY (av)[arg]))[0]));
426 else 433 else
427 for (arg = 0; arg < count; arg++) 434 for (arg = 0; arg < count; arg++)
428 PUSHs (maybe_force_utf8 (ix & 1, AvARRAY (av)[arg])); 435 PUSHs (mortalcopy_and_maybe_force_utf8 (ix & 1, AvARRAY (av)[arg]));
429 } 436 }
430 } 437 }
431 } 438 }
432 else 439 else
433 XPUSHs (sth); 440 XPUSHs (sth);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines