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.8 by root, Sat Aug 11 02:46:16 2001 UTC vs.
Revision 1.14 by root, Fri Aug 2 03:30:01 2002 UTC

6# define get_sv perl_get_sv 6# define get_sv perl_get_sv
7# define call_method perl_call_method 7# define call_method perl_call_method
8# define call_sv perl_call_sv 8# define call_sv perl_call_sv
9#endif 9#endif
10 10
11#if (PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION <= 5)) 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
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;
225 int count; 227 int count;
226 SV *dbh = ST(0); 228 SV *dbh = ST(0);
227 SV *sth; 229 SV *sth;
228 SV *sql; 230 SV *sql;
229 SV *execute; 231 SV *execute;
230 STRLEN dc; 232 STRLEN dc, dd; /* dummy */
231 233
232 /* save our arguments against destruction through function calls */ 234 /* save our arguments against destruction through function calls */
233 SP += items; 235 SP += items;
234 236
235 /* first check wether we should use an explicit db handle */ 237 /* first check wether we should use an explicit db handle */
236 if (!is_dbh (dbh)) 238 if (!is_dbh (dbh))
237 { 239 {
240 /* the next line doesn't work - check why later maybe */
238 dbh = get_sv ("DBH", FALSE); 241 /* dbh = get_sv ("DBH", FALSE);
239 if (!is_dbh (dbh)) 242 if (!is_dbh (dbh))
240 { 243 {*/
241 dbh = GvSV(DBH); 244 dbh = GvSV(DBH);
242 if (!is_dbh (dbh)) 245 if (!is_dbh (dbh))
246 croak ("sql_exec: no $DBH argument and no fallback in $PApp::SQL::DBH");
243 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::");
244 } 248 }*/
245 } 249 }
246 else 250 else
247 arg++; /* we consumed one argument */ 251 arg++; /* we consumed one argument */
248 252
249 /* count the remaining references (for bind_columns) */ 253 /* count the remaining references (for bind_columns) */
284 SPAGAIN; 288 SPAGAIN;
285 289
286 if (count != 1) 290 if (count != 1)
287 croak ("sql_exec: unable to prepare() statement '%s': %s", 291 croak ("sql_exec: unable to prepare() statement '%s': %s",
288 SvPV (sql, dc), 292 SvPV (sql, dc),
289 SvPV (get_sv ("DBI::errstr", TRUE), dc)); 293 SvPV (get_sv ("DBI::errstr", TRUE), dd));
290 294
291 sth = POPs; 295 sth = POPs;
292 296
297 if (SvLEN (sql) < MAX_CACHED_STATEMENT_SIZE)
293 lru_store (dbh, sql, sth); 298 lru_store (dbh, sql, sth);
294 } 299 }
295 300
296 PUSHMARK (SP); 301 PUSHMARK (SP);
297 EXTEND (SP, items - arg + 1); 302 EXTEND (SP, items - arg + 1);
298 PUSHs (sth); 303 PUSHs (sth);
311 SPAGAIN; 316 SPAGAIN;
312 317
313 if (count != 1) 318 if (count != 1)
314 croak ("sql_exec: execute() didn't return any value ('%s'): %s", 319 croak ("sql_exec: execute() didn't return any value ('%s'): %s",
315 SvPV (sql, dc), 320 SvPV (sql, dc),
316 SvPV (get_sv ("DBI::errstr", TRUE), dc)); 321 SvPV (get_sv ("DBI::errstr", TRUE), dd));
317 322
318 execute = POPs; 323 execute = POPs;
319 324
320 if (!SvTRUE (execute)) 325 if (!SvTRUE (execute))
321 croak ("sql_exec: unable to execute statement '%s' (%s)", 326 croak ("sql_exec: unable to execute statement '%s' (%s)",
322 SvPV (sql, dc), 327 SvPV (sql, dc),
323 SvPV (get_sv ("DBI::errstr", TRUE), dc)); 328 SvPV (get_sv ("DBI::errstr", TRUE), dd));
324 329
325 sv_setsv (GvSV(sql_exec), execute); 330 sv_setsv (GvSV(sql_exec), execute);
326 331
327 if (bind_first != bind_last) 332 if (bind_first != bind_last)
328 { 333 {
339 SPAGAIN; 344 SPAGAIN;
340 345
341 if (count != 1) 346 if (count != 1)
342 croak ("sql_exec: bind_columns() didn't return any value ('%s'): %s", 347 croak ("sql_exec: bind_columns() didn't return any value ('%s'): %s",
343 SvPV (sql, dc), 348 SvPV (sql, dc),
344 SvPV (get_sv ("DBI::errstr", TRUE), dc)); 349 SvPV (get_sv ("DBI::errstr", TRUE), dd));
345 350
346 if (!SvOK (POPs)) 351 if (!SvOK (POPs))
347 croak ("sql_exec: bind_columns() didn't return a true ('%s'): %s", 352 croak ("sql_exec: bind_columns() didn't return a true ('%s'): %s",
348 SvPV (sql, dc), 353 SvPV (sql, dc),
349 SvPV (get_sv ("DBI::errstr", TRUE), dc)); 354 SvPV (get_sv ("DBI::errstr", TRUE), dd));
350 } 355 }
351 356
352 /* free our arguments from the stack */ 357 /* free our arguments from the stack */
353 SP -= items; 358 SP -= items;
354 359
376 case G_VOID: 381 case G_VOID:
377 /* no thing */ 382 /* no thing */
378 break; 383 break;
379 case G_SCALAR: 384 case G_SCALAR:
380 /* the first element */ 385 /* the first element */
381 XPUSHs (maybe_force_utf8 (ix & 1, *av_fetch ((AV *)SvRV (row), 0, 1))); 386 XPUSHs (mortalcopy_and_maybe_force_utf8 (ix & 1, *av_fetch ((AV *)SvRV (row), 0, 1)));
382 break; 387 break;
383 case G_ARRAY: 388 case G_ARRAY:
384 av = (AV *)SvRV (row); 389 av = (AV *)SvRV (row);
385 count = AvFILL (av) + 1; 390 count = AvFILL (av) + 1;
386 EXTEND (SP, count); 391 EXTEND (SP, count);
387 for (arg = 0; arg < count; arg++) 392 for (arg = 0; arg < count; arg++)
388 PUSHs (maybe_force_utf8 (ix & 1, AvARRAY (av)[arg])); 393 PUSHs (mortalcopy_and_maybe_force_utf8 (ix & 1, AvARRAY (av)[arg]));
389 394
390 break; 395 break;
391 default: 396 default:
392 abort (); 397 abort ();
393 } 398 }
418 int columns = AvFILL ((AV *) SvRV (AvARRAY (av)[0])) + 1; /* columns? */ 423 int columns = AvFILL ((AV *) SvRV (AvARRAY (av)[0])) + 1; /* columns? */
419 424
420 EXTEND (SP, count); 425 EXTEND (SP, count);
421 if (columns == 1) 426 if (columns == 1)
422 for (arg = 0; arg < count; arg++) 427 for (arg = 0; arg < count; arg++)
423 PUSHs (maybe_force_utf8 (ix & 1, AvARRAY ((AV *)SvRV (AvARRAY (av)[arg]))[0])); 428 PUSHs (mortalcopy_and_maybe_force_utf8 (ix & 1, AvARRAY ((AV *)SvRV (AvARRAY (av)[arg]))[0]));
424 else 429 else
425 for (arg = 0; arg < count; arg++) 430 for (arg = 0; arg < count; arg++)
426 PUSHs (maybe_force_utf8 (ix & 1, AvARRAY (av)[arg])); 431 PUSHs (mortalcopy_and_maybe_force_utf8 (ix & 1, AvARRAY (av)[arg]));
427 } 432 }
428 } 433 }
429 } 434 }
430 else 435 else
431 XPUSHs (sth); 436 XPUSHs (sth);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines