[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 # $Id: Driver.xst 11330 2008-05-27 12:27:14Z timbo $ 2 # Copyright (c) 1997-2002 Tim Bunce Ireland 3 # Copyright (c) 2002 Jonathan Leffler 4 # 5 # You may distribute under the terms of either the GNU General Public 6 # License or the Artistic License, as specified in the Perl README file. 7 8 9 #include "Driver_xst.h" 10 11 12 MODULE = DBD::~DRIVER~ PACKAGE = DBD::~DRIVER~ 13 14 REQUIRE: 1.929 15 PROTOTYPES: DISABLE 16 17 BOOT: 18 items = 0; /* avoid 'unused variable' warning */ 19 DBISTATE_INIT; 20 /* XXX this interface will change: */ 21 DBI_IMP_SIZE("DBD::~DRIVER~::dr::imp_data_size", sizeof(imp_drh_t)); 22 DBI_IMP_SIZE("DBD::~DRIVER~::db::imp_data_size", sizeof(imp_dbh_t)); 23 DBI_IMP_SIZE("DBD::~DRIVER~::st::imp_data_size", sizeof(imp_sth_t)); 24 dbd_init(DBIS); 25 26 27 # ------------------------------------------------------------ 28 # driver level interface 29 # ------------------------------------------------------------ 30 MODULE = DBD::~DRIVER~ PACKAGE = DBD::~DRIVER~::dr 31 32 33 void 34 dbixs_revision(...) 35 PPCODE: 36 ST(0) = sv_2mortal(newSViv(DBIXS_REVISION)); 37 38 39 #ifdef dbd_discon_all 40 41 # disconnect_all renamed and ALIAS'd to avoid length clash on VMS :-( 42 void 43 discon_all_(drh) 44 SV * drh 45 ALIAS: 46 disconnect_all = 1 47 CODE: 48 D_imp_drh(drh); 49 if (0) ix = ix; /* avoid unused variable warning */ 50 ST(0) = dbd_discon_all(drh, imp_drh) ? &sv_yes : &sv_no; 51 52 #endif /* dbd_discon_all */ 53 54 55 #ifdef dbd_dr_data_sources 56 57 void 58 data_sources(drh, attr = Nullsv) 59 SV *drh 60 SV *attr 61 PPCODE: 62 { 63 D_imp_drh(drh); 64 AV *av = dbd_dr_data_sources(drh, imp_drh, attr); 65 if (av) { 66 int i; 67 int n = AvFILL(av)+1; 68 EXTEND(sp, n); 69 for (i = 0; i < n; ++i) { 70 PUSHs(AvARRAY(av)[i]); 71 } 72 } 73 } 74 75 #endif 76 77 78 # ------------------------------------------------------------ 79 # database level interface 80 # ------------------------------------------------------------ 81 MODULE = DBD::~DRIVER~ PACKAGE = DBD::~DRIVER~::db 82 83 84 void 85 _login(dbh, dbname, username, password, attribs=Nullsv) 86 SV * dbh 87 char * dbname 88 SV * username 89 SV * password 90 SV * attribs 91 CODE: 92 { 93 STRLEN lna; 94 D_imp_dbh(dbh); 95 char *u = (SvOK(username)) ? SvPV(username,lna) : ""; 96 char *p = (SvOK(password)) ? SvPV(password,lna) : ""; 97 #ifdef dbd_db_login6 98 ST(0) = dbd_db_login6(dbh, imp_dbh, dbname, u, p, attribs) ? &sv_yes : &sv_no; 99 #else 100 ST(0) = dbd_db_login( dbh, imp_dbh, dbname, u, p) ? &sv_yes : &sv_no; 101 #endif 102 } 103 104 105 void 106 selectall_arrayref(...) 107 PREINIT: 108 SV *sth; 109 SV **maxrows_svp; 110 SV **tmp_svp; 111 SV *attr = &PL_sv_undef; 112 imp_sth_t *imp_sth; 113 CODE: 114 if (items > 2) { 115 attr = ST(2); 116 if (SvROK(attr) && 117 (DBD_ATTRIB_TRUE(attr,"Slice",5,tmp_svp) || DBD_ATTRIB_TRUE(attr,"Columns",7,tmp_svp)) 118 ) { 119 /* fallback to perl implementation */ 120 SV *tmp =dbixst_bounce_method("DBD::~DRIVER~::db::SUPER::selectall_arrayref", items); 121 SPAGAIN; 122 ST(0) = tmp; 123 XSRETURN(1); 124 } 125 } 126 /* --- prepare --- */ 127 if (SvROK(ST(1))) { 128 MAGIC *mg; 129 sth = ST(1); 130 /* switch to inner handle if not already */ 131 if ( (mg = mg_find(SvRV(sth),'P')) ) 132 sth = mg->mg_obj; 133 } 134 else { 135 sth = dbixst_bounce_method("prepare", 3); 136 SPAGAIN; SP -= items; /* because stack might have been realloc'd */ 137 if (!SvROK(sth)) 138 XSRETURN_UNDEF; 139 /* switch to inner handle */ 140 sth = mg_find(SvRV(sth),'P')->mg_obj; 141 } 142 imp_sth = (imp_sth_t*)(DBIh_COM(sth)); 143 /* --- bind_param --- */ 144 if (items > 3) { /* need to bind params before execute */ 145 if (!dbdxst_bind_params(sth, imp_sth, items-2, ax+2) ) { 146 XSRETURN_UNDEF; 147 } 148 } 149 /* --- execute --- */ 150 DBIc_ROW_COUNT(imp_sth) = 0; 151 if ( dbd_st_execute(sth, imp_sth) <= -2 ) { /* -2 == error */ 152 XSRETURN_UNDEF; 153 } 154 /* --- fetchall --- */ 155 maxrows_svp = DBD_ATTRIB_GET_SVP(attr, "MaxRows", 7); 156 ST(0) = dbdxst_fetchall_arrayref(sth, &PL_sv_undef, (maxrows_svp) ? *maxrows_svp : &PL_sv_undef); 157 158 159 void 160 selectrow_arrayref(...) 161 ALIAS: 162 selectrow_array = 1 163 PREINIT: 164 int is_selectrow_array = (ix == 1); 165 imp_sth_t *imp_sth; 166 SV *sth; 167 AV *row_av; 168 PPCODE: 169 if (SvROK(ST(1))) { 170 MAGIC *mg; 171 sth = ST(1); 172 /* switch to inner handle if not already */ 173 if ( (mg = mg_find(SvRV(sth),'P')) ) 174 sth = mg->mg_obj; 175 } 176 else { 177 /* --- prepare --- */ 178 sth = dbixst_bounce_method("prepare", 3); 179 SPAGAIN; SP -= items; /* because stack might have been realloc'd */ 180 if (!SvROK(sth)) { 181 if (is_selectrow_array) { XSRETURN_EMPTY; } else { XSRETURN_UNDEF; } 182 } 183 /* switch to inner handle */ 184 sth = mg_find(SvRV(sth),'P')->mg_obj; 185 } 186 imp_sth = (imp_sth_t*)(DBIh_COM(sth)); 187 /* --- bind_param --- */ 188 if (items > 3) { /* need to bind params before execute */ 189 if (!dbdxst_bind_params(sth, imp_sth, items-2, ax+2) ) { 190 if (is_selectrow_array) { XSRETURN_EMPTY; } else { XSRETURN_UNDEF; } 191 } 192 } 193 /* --- execute --- */ 194 DBIc_ROW_COUNT(imp_sth) = 0; 195 if ( dbd_st_execute(sth, imp_sth) <= -2 ) { /* -2 == error */ 196 if (is_selectrow_array) { XSRETURN_EMPTY; } else { XSRETURN_UNDEF; } 197 } 198 /* --- fetchrow_arrayref --- */ 199 row_av = dbd_st_fetch(sth, imp_sth); 200 if (!row_av) { 201 if (GIMME == G_SCALAR) 202 PUSHs(&PL_sv_undef); 203 } 204 else if (is_selectrow_array) { 205 int i; 206 int num_fields = AvFILL(row_av)+1; 207 if (GIMME == G_SCALAR) 208 num_fields = 1; /* return just first field */ 209 EXTEND(sp, num_fields); 210 for(i=0; i < num_fields; ++i) { 211 PUSHs(AvARRAY(row_av)[i]); 212 } 213 } 214 else { 215 PUSHs( sv_2mortal(newRV((SV *)row_av)) ); 216 } 217 /* --- finish --- */ 218 #ifdef dbd_st_finish3 219 dbd_st_finish3(sth, imp_sth, 0); 220 #else 221 dbd_st_finish(sth, imp_sth); 222 #endif 223 224 225 #ifdef dbd_db_do4 /* deebeedee-deebee-doo, deebee-doobee-dah? */ 226 227 void 228 do(dbh, statement, params = Nullsv) 229 SV * dbh 230 char * statement 231 SV * params 232 CODE: 233 { 234 D_imp_dbh(dbh); 235 IV retval; 236 retval = dbd_db_do4(dbh, imp_dbh, statement, params); 237 /* remember that dbd_db_do4 must return <= -2 for error */ 238 if (retval == 0) /* ok with no rows affected */ 239 XST_mPV(0, "0E0"); /* (true but zero) */ 240 else if (retval < -1) /* -1 == unknown number of rows */ 241 XST_mUNDEF(0); /* <= -2 means error */ 242 else 243 XST_mIV(0, retval); /* typically 1, rowcount or -1 */ 244 } 245 246 #endif 247 248 249 #ifdef dbd_db_last_insert_id 250 251 void 252 last_insert_id(dbh, catalog, schema, table, field, attr=Nullsv) 253 SV * dbh 254 SV * catalog 255 SV * schema 256 SV * table 257 SV * field 258 SV * attr 259 CODE: 260 { 261 D_imp_dbh(dbh); 262 ST(0) = dbd_db_last_insert_id(dbh, imp_dbh, catalog, schema, table, field, attr); 263 } 264 265 #endif 266 267 268 void 269 commit(dbh) 270 SV * dbh 271 CODE: 272 D_imp_dbh(dbh); 273 if (DBIc_has(imp_dbh,DBIcf_AutoCommit) && DBIc_WARN(imp_dbh)) 274 warn("commit ineffective with AutoCommit enabled"); 275 ST(0) = dbd_db_commit(dbh, imp_dbh) ? &sv_yes : &sv_no; 276 277 278 void 279 rollback(dbh) 280 SV * dbh 281 CODE: 282 D_imp_dbh(dbh); 283 if (DBIc_has(imp_dbh,DBIcf_AutoCommit) && DBIc_WARN(imp_dbh)) 284 warn("rollback ineffective with AutoCommit enabled"); 285 ST(0) = dbd_db_rollback(dbh, imp_dbh) ? &sv_yes : &sv_no; 286 287 288 void 289 disconnect(dbh) 290 SV * dbh 291 CODE: 292 D_imp_dbh(dbh); 293 if ( !DBIc_ACTIVE(imp_dbh) ) { 294 XSRETURN_YES; 295 } 296 /* Check for disconnect() being called whilst refs to cursors */ 297 /* still exists. This possibly needs some more thought. */ 298 if (DBIc_ACTIVE_KIDS(imp_dbh) && DBIc_WARN(imp_dbh) && !dirty) { 299 STRLEN lna; 300 char *plural = (DBIc_ACTIVE_KIDS(imp_dbh)==1) ? "" : "s"; 301 warn("%s->disconnect invalidates %d active statement handle%s %s", 302 SvPV(dbh,lna), (int)DBIc_ACTIVE_KIDS(imp_dbh), plural, 303 "(either destroy statement handles or call finish on them before disconnecting)"); 304 } 305 ST(0) = dbd_db_disconnect(dbh, imp_dbh) ? &sv_yes : &sv_no; 306 DBIc_ACTIVE_off(imp_dbh); /* ensure it's off, regardless */ 307 308 309 void 310 STORE(dbh, keysv, valuesv) 311 SV * dbh 312 SV * keysv 313 SV * valuesv 314 CODE: 315 D_imp_dbh(dbh); 316 if (SvGMAGICAL(valuesv)) 317 mg_get(valuesv); 318 ST(0) = &sv_yes; 319 if (!dbd_db_STORE_attrib(dbh, imp_dbh, keysv, valuesv)) 320 if (!DBIc_DBISTATE(imp_dbh)->set_attr(dbh, keysv, valuesv)) 321 ST(0) = &sv_no; 322 323 324 void 325 FETCH(dbh, keysv) 326 SV * dbh 327 SV * keysv 328 CODE: 329 D_imp_dbh(dbh); 330 SV *valuesv = dbd_db_FETCH_attrib(dbh, imp_dbh, keysv); 331 if (!valuesv) 332 valuesv = DBIc_DBISTATE(imp_dbh)->get_attr(dbh, keysv); 333 ST(0) = valuesv; /* dbd_db_FETCH_attrib did sv_2mortal */ 334 335 336 void 337 DESTROY(dbh) 338 SV * dbh 339 PPCODE: 340 /* keep in sync with default DESTROY in DBI.xs */ 341 D_imp_dbh(dbh); 342 ST(0) = &sv_yes; 343 if (!DBIc_IMPSET(imp_dbh)) { /* was never fully set up */ 344 STRLEN lna; 345 if (DBIc_WARN(imp_dbh) && !dirty && DBIc_DBISTATE(imp_dbh)->debug >= 2) 346 PerlIO_printf(DBIc_LOGPIO(imp_dbh), 347 " DESTROY for %s ignored - handle not initialised\n", 348 SvPV(dbh,lna)); 349 } 350 else { 351 if (DBIc_IADESTROY(imp_dbh)) { /* want's ineffective destroy */ 352 DBIc_ACTIVE_off(imp_dbh); 353 if (DBIc_DBISTATE(imp_dbh)->debug) 354 PerlIO_printf(DBIc_LOGPIO(imp_dbh), " DESTROY %s skipped due to InactiveDestroy\n", SvPV_nolen(dbh)); 355 } 356 if (DBIc_ACTIVE(imp_dbh)) { 357 if (!DBIc_has(imp_dbh,DBIcf_AutoCommit)) { 358 /* Application is using transactions and hasn't explicitly disconnected. 359 Some databases will automatically commit on graceful disconnect. 360 Since we're about to gracefully disconnect as part of the DESTROY 361 we want to be sure we're not about to implicitly commit changes 362 that are incomplete and should be rolled back. (The DESTROY may 363 be due to a RaiseError, for example.) So we rollback here. 364 This will be harmless if the application has issued a commit, 365 XXX Could add an attribute flag to indicate that the driver 366 doesn't have this problem. Patches welcome. 367 XXX or could just move the DBIc_is(imp_dbh, DBIcf_Executed) test 368 to cover the rollback as well. That just needs sanity checking 369 that DBIcf_Executed is set by any/all possible way to execute a 370 statement that might start a transaction. 371 */ 372 if (DBIc_WARN(imp_dbh) 373 && DBIc_is(imp_dbh, DBIcf_Executed) /* has not just called commit/rollback */ 374 && (!dirty || DBIc_DBISTATE(imp_dbh)->debug >= 3) 375 ) 376 warn("Issuing rollback() for database handle being DESTROY'd without explicit disconnect()"); 377 dbd_db_rollback(dbh, imp_dbh); /* ROLLBACK! */ 378 } 379 dbd_db_disconnect(dbh, imp_dbh); 380 DBIc_ACTIVE_off(imp_dbh); /* ensure it's off, regardless */ 381 } 382 dbd_db_destroy(dbh, imp_dbh); 383 } 384 385 386 #ifdef dbd_take_imp_data 387 388 void 389 take_imp_data(h) 390 SV * h 391 CODE: 392 D_imp_xxh(h); 393 /* dbd_take_imp_data() returns &sv_no (or other defined but false value) 394 * to indicate "preparations complete, now call SUPER::take_imp_data" for me. 395 * Anything else is returned to the caller via sv_2mortal(sv), typically that 396 * would be &sv_undef for error or an SV holding the imp_data. 397 */ 398 SV *sv = dbd_take_imp_data(h, imp_xxh, NULL); 399 if (SvOK(sv) && !SvTRUE(sv)) { 400 SV *tmp = dbixst_bounce_method("DBD::~DRIVER~::db::SUPER::take_imp_data", items); 401 SPAGAIN; 402 ST(0) = tmp; 403 } else { 404 ST(0) = sv_2mortal(sv); 405 } 406 407 #endif 408 409 #ifdef dbd_db_data_sources 410 411 void 412 data_sources(dbh, attr = Nullsv) 413 SV *dbh 414 SV *attr 415 PPCODE: 416 { 417 D_imp_dbh(dbh); 418 AV *av = dbd_db_data_sources(dbh, imp_dbh, attr); 419 if (av) { 420 int i; 421 int n = AvFILL(av)+1; 422 EXTEND(sp, n); 423 for (i = 0; i < n; ++i) { 424 PUSHs(AvARRAY(av)[i]); 425 } 426 } 427 } 428 429 #endif 430 431 # -- end of DBD::~DRIVER~::db 432 433 # ------------------------------------------------------------ 434 # statement interface 435 # ------------------------------------------------------------ 436 MODULE = DBD::~DRIVER~ PACKAGE = DBD::~DRIVER~::st 437 438 439 void 440 _prepare(sth, statement, attribs=Nullsv) 441 SV * sth 442 SV * statement 443 SV * attribs 444 CODE: 445 { 446 D_imp_sth(sth); 447 DBD_ATTRIBS_CHECK("_prepare", sth, attribs); 448 #ifdef dbd_st_prepare_sv 449 ST(0) = dbd_st_prepare_sv(sth, imp_sth, statement, attribs) ? &sv_yes : &sv_no; 450 #else 451 ST(0) = dbd_st_prepare(sth, imp_sth, SvPV_nolen(statement), attribs) ? &sv_yes : &sv_no; 452 #endif 453 } 454 455 456 #ifdef dbd_st_rows 457 458 void 459 rows(sth) 460 SV * sth 461 CODE: 462 D_imp_sth(sth); 463 XST_mIV(0, dbd_st_rows(sth, imp_sth)); 464 465 #endif /* dbd_st_rows */ 466 467 468 #ifdef dbd_st_bind_col 469 470 void 471 bind_col(sth, col, ref, attribs=Nullsv) 472 SV * sth 473 SV * col 474 SV * ref 475 SV * attribs 476 CODE: 477 { 478 IV sql_type = 0; 479 D_imp_sth(sth); 480 if (SvGMAGICAL(ref)) 481 mg_get(ref); 482 if (attribs) { 483 if (SvNIOK(attribs)) { 484 sql_type = SvIV(attribs); 485 attribs = Nullsv; 486 } 487 else { 488 SV **svp; 489 DBD_ATTRIBS_CHECK("bind_col", sth, attribs); 490 /* XXX we should perhaps complain if TYPE is not SvNIOK */ 491 DBD_ATTRIB_GET_IV(attribs, "TYPE",4, svp, sql_type); 492 } 493 } 494 switch(dbd_st_bind_col(sth, imp_sth, col, ref, sql_type, attribs)) { 495 case 2: ST(0) = &sv_yes; /* job done completely */ 496 break; 497 case 1: /* fallback to DBI default */ 498 ST(0) = (DBIc_DBISTATE(imp_sth)->bind_col(sth, col, ref, attribs)) 499 ? &sv_yes : &sv_no; 500 break; 501 default: ST(0) = &sv_no; /* dbd_st_bind_col has called set_err */ 502 break; 503 } 504 } 505 506 #endif /* dbd_st_bind_col */ 507 508 void 509 bind_param(sth, param, value, attribs=Nullsv) 510 SV * sth 511 SV * param 512 SV * value 513 SV * attribs 514 CODE: 515 { 516 IV sql_type = 0; 517 D_imp_sth(sth); 518 if (SvGMAGICAL(value)) 519 mg_get(value); 520 if (attribs) { 521 if (SvNIOK(attribs)) { 522 sql_type = SvIV(attribs); 523 attribs = Nullsv; 524 } 525 else { 526 SV **svp; 527 DBD_ATTRIBS_CHECK("bind_param", sth, attribs); 528 /* XXX we should perhaps complain if TYPE is not SvNIOK */ 529 DBD_ATTRIB_GET_IV(attribs, "TYPE",4, svp, sql_type); 530 } 531 } 532 ST(0) = dbd_bind_ph(sth, imp_sth, param, value, sql_type, attribs, FALSE, 0) 533 ? &sv_yes : &sv_no; 534 } 535 536 537 void 538 bind_param_inout(sth, param, value_ref, maxlen, attribs=Nullsv) 539 SV * sth 540 SV * param 541 SV * value_ref 542 IV maxlen 543 SV * attribs 544 CODE: 545 { 546 IV sql_type = 0; 547 D_imp_sth(sth); 548 SV *value; 549 if (!SvROK(value_ref) || SvTYPE(SvRV(value_ref)) > SVt_PVMG) 550 croak("bind_param_inout needs a reference to a scalar value"); 551 value = SvRV(value_ref); 552 if (SvREADONLY(value)) 553 croak("Modification of a read-only value attempted"); 554 if (SvGMAGICAL(value)) 555 mg_get(value); 556 if (attribs) { 557 if (SvNIOK(attribs)) { 558 sql_type = SvIV(attribs); 559 attribs = Nullsv; 560 } 561 else { 562 SV **svp; 563 DBD_ATTRIBS_CHECK("bind_param", sth, attribs); 564 DBD_ATTRIB_GET_IV(attribs, "TYPE",4, svp, sql_type); 565 } 566 } 567 ST(0) = dbd_bind_ph(sth, imp_sth, param, value, sql_type, attribs, TRUE, maxlen) 568 ? &sv_yes : &sv_no; 569 } 570 571 572 void 573 execute(sth, ...) 574 SV * sth 575 CODE: 576 D_imp_sth(sth); 577 int retval; 578 if (items > 1) { /* need to bind params */ 579 if (!dbdxst_bind_params(sth, imp_sth, items, ax) ) { 580 XSRETURN_UNDEF; 581 } 582 } 583 /* XXX this code is duplicated in selectrow_arrayref above */ 584 if (DBIc_ROW_COUNT(imp_sth) > 0) /* reset for re-execute */ 585 DBIc_ROW_COUNT(imp_sth) = 0; 586 retval = dbd_st_execute(sth, imp_sth); 587 /* remember that dbd_st_execute must return <= -2 for error */ 588 if (retval == 0) /* ok with no rows affected */ 589 XST_mPV(0, "0E0"); /* (true but zero) */ 590 else if (retval < -1) /* -1 == unknown number of rows */ 591 XST_mUNDEF(0); /* <= -2 means error */ 592 else 593 XST_mIV(0, retval); /* typically 1, rowcount or -1 */ 594 595 596 #ifdef dbd_st_execute_for_fetch 597 598 void 599 execute_for_fetch(sth, fetch_tuple_sub, tuple_status = Nullsv) 600 SV * sth 601 SV * fetch_tuple_sub 602 SV * tuple_status 603 CODE: 604 { 605 D_imp_sth(sth); 606 ST(0) = dbd_st_execute_for_fetch(sth, imp_sth, fetch_tuple_sub, tuple_status); 607 } 608 609 #endif 610 611 612 613 void 614 fetchrow_arrayref(sth) 615 SV * sth 616 ALIAS: 617 fetch = 1 618 CODE: 619 D_imp_sth(sth); 620 AV *av; 621 if (0) ix = ix; /* avoid unused variable warning */ 622 av = dbd_st_fetch(sth, imp_sth); 623 ST(0) = (av) ? sv_2mortal(newRV((SV *)av)) : &PL_sv_undef; 624 625 626 void 627 fetchrow_array(sth) 628 SV * sth 629 ALIAS: 630 fetchrow = 1 631 PPCODE: 632 D_imp_sth(sth); 633 AV *av; 634 av = dbd_st_fetch(sth, imp_sth); 635 if (av) { 636 int i; 637 int num_fields = AvFILL(av)+1; 638 EXTEND(sp, num_fields); 639 for(i=0; i < num_fields; ++i) { 640 PUSHs(AvARRAY(av)[i]); 641 } 642 if (0) ix = ix; /* avoid unused variable warning */ 643 } 644 645 646 void 647 fetchall_arrayref(sth, slice=&PL_sv_undef, batch_row_count=&PL_sv_undef) 648 SV * sth 649 SV * slice 650 SV * batch_row_count 651 CODE: 652 if (SvOK(slice)) { /* fallback to perl implementation */ 653 SV *tmp = dbixst_bounce_method("DBD::~DRIVER~::st::SUPER::fetchall_arrayref", 3); 654 SPAGAIN; 655 ST(0) = tmp; 656 } 657 else { 658 ST(0) = dbdxst_fetchall_arrayref(sth, slice, batch_row_count); 659 } 660 661 662 void 663 finish(sth) 664 SV * sth 665 CODE: 666 D_imp_sth(sth); 667 D_imp_dbh_from_sth; 668 if (!DBIc_ACTIVE(imp_sth)) { 669 /* No active statement to finish */ 670 XSRETURN_YES; 671 } 672 if (!DBIc_ACTIVE(imp_dbh)) { 673 /* Either an explicit disconnect() or global destruction */ 674 /* has disconnected us from the database. Finish is meaningless */ 675 DBIc_ACTIVE_off(imp_sth); 676 XSRETURN_YES; 677 } 678 #ifdef dbd_st_finish3 679 ST(0) = dbd_st_finish3(sth, imp_sth, 0) ? &sv_yes : &sv_no; 680 #else 681 ST(0) = dbd_st_finish(sth, imp_sth) ? &sv_yes : &sv_no; 682 #endif 683 684 685 void 686 blob_read(sth, field, offset, len, destrv=Nullsv, destoffset=0) 687 SV * sth 688 int field 689 long offset 690 long len 691 SV * destrv 692 long destoffset 693 CODE: 694 { 695 D_imp_sth(sth); 696 if (!destrv) 697 destrv = sv_2mortal(newRV(sv_2mortal(newSV(0)))); 698 if (dbd_st_blob_read(sth, imp_sth, field, offset, len, destrv, destoffset)) 699 ST(0) = SvRV(destrv); 700 else ST(0) = &PL_sv_undef; 701 } 702 703 704 void 705 STORE(sth, keysv, valuesv) 706 SV * sth 707 SV * keysv 708 SV * valuesv 709 CODE: 710 D_imp_sth(sth); 711 if (SvGMAGICAL(valuesv)) 712 mg_get(valuesv); 713 ST(0) = &sv_yes; 714 if (!dbd_st_STORE_attrib(sth, imp_sth, keysv, valuesv)) 715 if (!DBIc_DBISTATE(imp_sth)->set_attr(sth, keysv, valuesv)) 716 ST(0) = &sv_no; 717 718 719 # FETCH renamed and ALIAS'd to avoid case clash on VMS :-( 720 void 721 FETCH_attrib(sth, keysv) 722 SV * sth 723 SV * keysv 724 ALIAS: 725 FETCH = 1 726 CODE: 727 D_imp_sth(sth); 728 SV *valuesv; 729 if (0) ix = ix; /* avoid unused variable warning */ 730 valuesv = dbd_st_FETCH_attrib(sth, imp_sth, keysv); 731 if (!valuesv) 732 valuesv = DBIc_DBISTATE(imp_sth)->get_attr(sth, keysv); 733 ST(0) = valuesv; /* dbd_st_FETCH_attrib did sv_2mortal */ 734 735 736 void 737 DESTROY(sth) 738 SV * sth 739 PPCODE: 740 /* keep in sync with default DESTROY in DBI.xs */ 741 D_imp_sth(sth); 742 ST(0) = &sv_yes; 743 if (!DBIc_IMPSET(imp_sth)) { /* was never fully set up */ 744 STRLEN lna; 745 if (DBIc_WARN(imp_sth) && !dirty && DBIc_DBISTATE(imp_sth)->debug >= 2) 746 PerlIO_printf(DBIc_LOGPIO(imp_sth), 747 " DESTROY for %s ignored - handle not initialised\n", 748 SvPV(sth,lna)); 749 } 750 else { 751 if (DBIc_IADESTROY(imp_sth)) { /* want's ineffective destroy */ 752 DBIc_ACTIVE_off(imp_sth); 753 if (DBIc_DBISTATE(imp_sth)->debug) 754 PerlIO_printf(DBIc_LOGPIO(imp_sth), " DESTROY %s skipped due to InactiveDestroy\n", SvPV_nolen(sth)); 755 } 756 if (DBIc_ACTIVE(imp_sth)) { 757 D_imp_dbh_from_sth; 758 if (!dirty && DBIc_ACTIVE(imp_dbh)) { 759 #ifdef dbd_st_finish3 760 dbd_st_finish3(sth, imp_sth, 1); 761 #else 762 dbd_st_finish(sth, imp_sth); 763 #endif 764 } 765 else { 766 DBIc_ACTIVE_off(imp_sth); 767 } 768 } 769 dbd_st_destroy(sth, imp_sth); 770 } 771 772 # end of ~DRIVER~.xst 773 # vim:ts=8:sw=4:et
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 17 22:47:18 2015 | Cross-referenced by PHPXref 0.7.1 |