1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
|
/**
* $Id: mSQL.xs,v 1.1 1997/07/09 18:59:55 k Exp $
*
* (c)1994-1997 Alligator Descartes, based in part on work by Tim Bunce
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the Perl README file.
*
*/
#include "mSQL.h"
DBISTATE_DECLARE;
/* see dbd_init for initialisation */
SV *dbd_errnum = NULL;
SV *dbd_errstr = NULL;
MODULE = DBD::mSQL PACKAGE = DBD::mSQL
REQUIRE: 1.929
PROTOTYPES: DISABLE
BOOT:
items = 0; /* avoid 'unused variable' warning */
DBISTATE_INIT;
/* XXX tis interface will change: */
DBI_IMP_SIZE("DBD::mSQL::dr::imp_data_size", sizeof(imp_drh_t));
DBI_IMP_SIZE("DBD::mSQL::db::imp_data_size", sizeof(imp_dbh_t));
DBI_IMP_SIZE("DBD::mSQL::st::imp_data_size", sizeof(imp_sth_t));
dbd_init(DBIS);
void
errstr(h)
SV * h
CODE:
/* called from DBI::var TIESCALAR code for $DBI::errstr */
D_imp_xxh(h);
ST(0) = sv_mortalcopy(DBIc_ERRSTR(imp_xxh));
MODULE = DBD::mSQL PACKAGE = DBD::mSQL::dr
void
disconnect_all(drh)
SV * drh
CODE:
if (!dirty && !SvTRUE(perl_get_sv("DBI::PERL_ENDING",0))) {
D_imp_drh(drh);
sv_setiv(DBIc_ERR(imp_drh), (IV)1);
sv_setpv(DBIc_ERRSTR(imp_drh),
(char*)"disconnect_all not implemented");
DBIh_EVENT2(drh, ERROR_event,
DBIc_ERR(imp_drh), DBIc_ERRSTR(imp_drh));
XSRETURN(0);
}
/* perl_destruct with perl_destruct_level and $SIG{__WARN__} set */
/* to a code ref core dumps when sv_2cv triggers warn loop. */
if (perl_destruct_level)
perl_destruct_level = 0;
XST_mIV(0, 1);
void
_ListDBs(drh, host)
SV * drh
char * host
PPCODE:
m_result *res;
m_row cur;
int sock;
sock = msqlConnect( host );
if ( sock != -1 ) {
res = msqlListDBs( sock );
if ( !res ) {
do_mSQL_error( (sb2)-1, msqlErrMsg );
} else {
while ( ( cur = msqlFetchRow( res ) ) ) {
EXTEND( sp, 1);
PUSHs( sv_2mortal((SV*)newSVpv( cur[0], strlen(cur[0]))));
}
msqlFreeResult( res );
}
msqlClose( sock );
}
void
_CreateDB(drh, host, dbname)
SV * drh
char * host
char * dbname
PPCODE:
int sock;
sock = msqlConnect( host );
if ( sock != -1 ) {
if ( msqlCreateDB(sock,dbname) != -1 ) {
EXTEND( sp, 1 );
PUSHs( sv_2mortal((SV*)newSVpv( "OK", 2 )));
} else {
do_mSQL_error( -1, msqlErrMsg );
}
} else {
do_mSQL_error( -1, msqlErrMsg );
}
void
_DropDB(drh, host, dbname)
SV * drh
char * host
char * dbname
PPCODE:
int sock;
sock = msqlConnect( host );
if ( sock != -1 ) {
if ( msqlDropDB(sock,dbname) != -1 ) {
EXTEND( sp, 1 );
PUSHs( sv_2mortal((SV*)newSVpv( "OK", 2 )));
} else {
do_mSQL_error( -1, msqlErrMsg );
}
} else {
do_mSQL_error( -1, msqlErrMsg );
}
MODULE = DBD::mSQL PACKAGE = DBD::mSQL::db
void
_ListDBs(dbh)
SV * dbh
PPCODE:
D_imp_dbh(dbh);
m_result *res;
m_row cur;
int sock = imp_dbh->lda.svsock;
if ( sock != -1 ) {
res = msqlListDBs( sock );
if ( !res ) {
do_mSQL_error( (sb2)-1, msqlErrMsg );
} else {
while ( ( cur = msqlFetchRow( res ) ) ) {
EXTEND( sp, 1);
PUSHs( sv_2mortal((SV*)newSVpv( cur[0], strlen(cur[0]))));
}
msqlFreeResult( res );
}
}
void
_SelectDB(dbh, dbname)
SV * dbh
char * dbname
PPCODE:
D_imp_dbh(dbh);
if ( imp_dbh->lda.svsock != -1 ) {
if ( msqlSelectDB( imp_dbh->lda.svsock, dbname ) == -1 ) {
do_mSQL_error( (sb2)( imp_dbh->lda.rc ), msqlErrMsg );
}
}
void
_ListTables(dbh)
SV * dbh
PPCODE:
D_imp_dbh(dbh);
m_result *res;
m_row cur;
res = msqlListTables( imp_dbh->lda.svsock );
if ( !res ) {
do_mSQL_error( -1, "Error in msqlListTables!" );
} else {
while ( ( cur = msqlFetchRow( res ) ) ) {
EXTEND( sp, 1 );
PUSHs( sv_2mortal((SV*)newSVpv( cur[0], strlen( cur[0] ))));
}
msqlFreeResult( res );
}
void
_ListFields(dbh, tabname)
SV * dbh
char * tabname
PPCODE:
D_imp_dbh(dbh);
m_result *res;
if ( strlen( tabname ) == 0 ) {
do_mSQL_error( -1, "Error in msqlListFields! Table name was NULL!\n" );
return;
}
res = msqlListFields( imp_dbh->lda.svsock, tabname );
if ( !res ) {
do_mSQL_error( -1, "Error in msqlListFields!" );
} else {
SV * rv;
rv = dbd_db_fieldlist( res );
if ( !rv ) {
do_mSQL_error( -1, "fieldlist() error in msqlListFields!" );
} else {
XPUSHs( (SV*)rv );
msqlFreeResult( res );
}
}
SV *
_login(dbh, host, dbname, junk = "")
SV * dbh
char * host
char * dbname
char * junk
CODE:
ST(0) = dbd_db_login(dbh, host, dbname, junk) ? &sv_yes : &sv_no;
void
commit(dbh)
SV * dbh
CODE:
ST(0) = dbd_db_commit(dbh) ? &sv_yes : &sv_no;
void
rollback(dbh)
SV * dbh
CODE:
ST(0) = dbd_db_rollback(dbh) ? &sv_yes : &sv_no;
void
STORE(dbh, keysv, valuesv)
SV * dbh
SV * keysv
SV * valuesv
CODE:
if (!dbd_db_STORE(dbh, keysv, valuesv))
if (!DBIS->set_attr(dbh, keysv, valuesv))
ST(0) = &sv_no;
void
FETCH(dbh, keysv)
SV * dbh
SV * keysv
CODE:
SV *valuesv = dbd_db_FETCH(dbh, keysv);
if (!valuesv)
valuesv = DBIS->get_attr(dbh, keysv);
ST(0) = valuesv; /* dbd_db_FETCH did sv_2mortal */
void
disconnect(dbh)
SV * dbh
CODE:
D_imp_dbh(dbh);
if ( !DBIc_ACTIVE(imp_dbh) ) {
XSRETURN_YES;
}
/* Check for disconnect() being called whilst refs to cursors */
/* still exists. This needs some more thought. */
if (DBIc_ACTIVE_KIDS(imp_dbh) && DBIc_WARN(imp_dbh) && !dirty) {
warn("disconnect(%s) invalidates %d active cursor(s)",
SvPV(dbh,na), (int)DBIc_ACTIVE_KIDS(imp_dbh));
}
ST(0) = dbd_db_disconnect(dbh) ? &sv_yes : &sv_no;
void
DESTROY(dbh)
SV * dbh
CODE:
D_imp_dbh(dbh);
ST(0) = &sv_yes;
if (!DBIc_IMPSET(imp_dbh)) { /* was never fully set up */
if (DBIc_WARN(imp_dbh) && !dirty && dbis->debug >= 2)
warn("Database handle %s DESTROY ignored - never set up",
SvPV(dbh,na));
}
else {
if (DBIc_ACTIVE(imp_dbh)) {
if (DBIc_WARN(imp_dbh) && !dirty)
warn("Database handle destroyed without explicit disconnect");
dbd_db_disconnect(dbh);
}
dbd_db_destroy(dbh);
}
MODULE = DBD::mSQL PACKAGE = DBD::mSQL::st
void
_NumRows(sth)
SV * sth
PPCODE:
D_imp_sth(sth);
EXTEND( sp, 1 );
PUSHs( sv_2mortal((SV*)newSViv(imp_sth->row_num)));
void
_ListSelectedFields(sth)
SV * sth
PPCODE:
D_imp_sth(sth);
m_result *res;
SV * rv;
/**
* Set up an empty reference in case of error...
* I really have no idea how to do this.
*/
if ( !imp_sth->is_select ) {
do_mSQL_error( -1, "not a SELECT in msqlListSelectedFields!" );
} else {
if ( !( res = imp_sth->cda ) ) {
do_mSQL_error( -1, "missing m_result in msqlListSelectedFields!" );
} else {
if ( !( rv = dbd_db_fieldlist( res ) ) ) {
do_mSQL_error( -1, "fieldlist() error in msqlListSelectedFields!" );
} else {
XPUSHs((SV*)rv);
}
}
}
void
_prepare(sth, statement, attribs=Nullsv)
SV * sth
char * statement
SV * attribs
CODE:
DBD_ATTRIBS_CHECK("_prepare", sth, attribs);
ST(0) = dbd_st_prepare(sth, statement, attribs) ? &sv_yes : &sv_no;
void
rows(sth)
SV * sth
CODE:
XST_mIV(0, dbd_st_rows(sth));
void
bind_param( sth, param, value, attribs=Nullsv)
SV * sth
SV * param
SV * value
SV * attribs
CODE:
ST(0) = &sv_undef;
void
bind_param_inout(sth, param, value_ref, maxlen, attribs=Nullsv)
SV * sth
SV * param
SV * value_ref
IV maxlen
SV * attribs
CODE:
ST(0) = &sv_undef;
void
execute(sth, ...)
SV * sth
CODE:
D_imp_sth(sth);
int retval;
/* describe and allocate storage for results */
retval = dbd_st_execute(sth, imp_sth);
if ( retval < -1 ) {
XST_mUNDEF( 0 );
} else {
if ( retval == 0 ) {
XST_mPV( 0, "0E0" );
} else {
XST_mIV( 0, retval );
}
}
void
fetchrow(sth)
SV * sth
PPCODE:
D_imp_sth(sth);
int i;
SV *sv;
/* imp_sth->done_desc = 0; */
if ( dbis->debug >= 2 ) {
printf( "In: DBD::mSQL::fetchrow\n" );
printf( "In: DBD::mSQL::fetchrow'imp_sth->currow: %d\n",
imp_sth->currow );
printf( "In: DBD::mSQL::fetchrow'imp_sth->row_num: %d\n",
imp_sth->row_num );
}
dbd_describe( sth, imp_sth );
/* Check that execute() was executed sucessfuly. This also implies */
/* that dbd_describe() executed sucessfuly so the memory buffers */
/* are allocated and bound. */
# pif ( !(imp_sth->flags & IMP_STH_EXECUTING) ) {
# do_mSQL_error( 1, "no statement executing");
# XSRETURN(0);
# }
/* Advance through the buffer until we get to the row we want */
if ( dbis->debug >= 2 ) {
warn( "Number of fields: %d\n", imp_sth->fbh_num );
warn( "Current ROWID: %d\n", imp_sth->currow );
}
EXTEND(sp,imp_sth->fbh_num);
for ( i = 0 ; i < imp_sth->fbh_num ; i++ ) {
imp_fbh_t *fbh = &imp_sth->fbh[i];
if ( dbis->debug >=2 ) {
printf( "In: DBD::mSQL::execute'FieldBufferDump: %d\n", i );
printf( "In: DBD::mSQL::execute'FieldBufferDump->cbuf: %s\n",
fbh->cbuf );
printf( "In: DBD::mSQL::execute'FieldBufferDump->rlen: %i\n",
fbh->rlen );
}
SvCUR( fbh->sv ) = fbh->rlen;
if ( fbh->indp ) { /** Assume NULL */
sv = &sv_undef;
} else {
sv = sv_2mortal( newSVpv( (char *)fbh->cbuf, fbh->rlen ) );
}
PUSHs(sv);
}
imp_sth->currow++;
void
blob_read(sth, field, offset, len, destrv=Nullsv, destoffset=0)
SV * sth
int field
long offset
long len
SV * destrv
long destoffset
CODE:
ST(0) = &sv_undef;
void
STORE(sth, keysv, valuesv)
SV * sth
SV * keysv
SV * valuesv
CODE:
ST(0) = &sv_yes;
if (!dbd_st_STORE(sth, keysv, valuesv))
if (!DBIS->set_attr(sth, keysv, valuesv))
ST(0) = &sv_no;
void
FETCH(sth, keysv)
SV * sth
SV * keysv
CODE:
SV *valuesv = dbd_st_FETCH(sth, keysv);
if (!valuesv)
valuesv = DBIS->get_attr(sth, keysv);
ST(0) = valuesv; /* dbd_st_FETCH did sv_2mortal */
void
finish(sth)
SV * sth
CODE:
D_imp_sth(sth);
D_imp_dbh_from_sth;
if (!DBIc_ACTIVE(imp_dbh)) {
/* Either an explicit disconnect() or global destruction */
/* has disconnected us from the database. Finish is meaningless */
/* XXX warn */
XSRETURN_YES;
}
if (!DBIc_ACTIVE(imp_sth)) {
/* No active statement to finish */
XSRETURN_YES;
}
ST(0) = dbd_st_finish(sth) ? &sv_yes : &sv_no;
void
DESTROY(sth)
SV * sth
CODE:
D_imp_sth(sth);
ST(0) = &sv_yes;
if (!DBIc_IMPSET(imp_sth)) { /* was never fully set up */
if (DBIc_WARN(imp_sth) && !dirty)
warn("Statement handle %s DESTROY ignored - never set up",
SvPV(sth,na));
return;
}
if (DBIc_ACTIVE(imp_sth)) {
dbd_st_finish(sth);
}
dbd_st_destroy(sth);
# end of mSQL.xs
|