/*
 * This file was generated automatically by ExtUtils::ParseXS version 2.19 from the
 * contents of mysql.xs. Do not edit this file, edit mysql.xs instead.
 *
 *	ANY CHANGES MADE HERE WILL BE LOST! 
 *
 */

#line 1 "mysql.xs"
/* Hej, Emacs, this is -*- C -*- mode!

   $Id$

   Copyright (c) 2003      Rudolf Lippan
   Copyright (c) 1997-2003 Jochen Wiedmann

   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 "dbdimp.h"
#include "constants.h"

#include <errno.h>
#include <string.h>

#if MYSQL_ASYNC
#  define ASYNC_CHECK_XS(h)\
    if(imp_dbh->async_query_in_flight) {\
        do_error(h, 2000, "Calling a synchronous function on an asynchronous handle", "HY000");\
        XSRETURN_UNDEF;\
    }
#else
#  define ASYNC_CHECK_XS(h)
#endif


DBISTATE_DECLARE;


#ifndef PERL_UNUSED_VAR
#  define PERL_UNUSED_VAR(var) if (0) var = var
#endif

#line 48 "mysql.c"

/* INCLUDE:  Including 'mysql.xsi' from 'mysql.xs' */

#include "Driver_xst.h"
#ifdef dbd_discon_all
#define XSubPPtmpAAAA 1


XS(XS_DBD__mysql__dr_discon_all_); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__dr_discon_all_)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    dXSI32;
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", GvNAME(CvGV(cv)), "drh");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	drh = ST(0);
#line 42 "mysql.xsi"
    D_imp_drh(drh);
    if (0) ix = ix;	/* avoid unused variable warning */
    ST(0) = dbd_discon_all(drh, imp_drh) ? &sv_yes : &sv_no;
#line 75 "mysql.c"
    }
    XSRETURN(1);
}

#endif /* dbd_discon_all */
#ifdef dbd_dr_data_sources
#define XSubPPtmpAAAB 1


XS(XS_DBD__mysql__dr_data_sources); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__dr_data_sources)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items < 1 || items > 2)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::dr::data_sources", "drh, attr = Nullsv");
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV *	drh = ST(0);
	SV *	attr;

	if (items < 2)
	    attr = Nullsv;
	else {
	    attr = ST(1);
	}
#line 56 "mysql.xsi"
    {
	D_imp_drh(drh);
	AV *av = dbd_dr_data_sources(drh, imp_drh, attr);
	if (av) {
	    int i;
	    int n = AvFILL(av)+1;
	    EXTEND(sp, n);
	    for (i = 0; i < n; ++i) {
		PUSHs(AvARRAY(av)[i]);
	    }
	}
    }
#line 120 "mysql.c"
	PUTBACK;
	return;
    }
}

#endif

XS(XS_DBD__mysql__db__login); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db__login)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items < 4 || items > 5)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::db::_login", "dbh, dbname, username, password, attribs=Nullsv");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	dbh = ST(0);
	char *	dbname = (char *)SvPV_nolen(ST(1));
	SV *	username = ST(2);
	SV *	password = ST(3);
	SV *	attribs;

	if (items < 5)
	    attribs = Nullsv;
	else {
	    attribs = ST(4);
	}
#line 86 "mysql.xsi"
    {
    STRLEN lna;
    D_imp_dbh(dbh);
    char *u = (SvOK(username)) ? SvPV(username,lna) : "";
    char *p = (SvOK(password)) ? SvPV(password,lna) : "";
#ifdef dbd_db_login6
    ST(0) = dbd_db_login6(dbh, imp_dbh, dbname, u, p, attribs) ? &sv_yes : &sv_no;
#else
    ST(0) = dbd_db_login( dbh, imp_dbh, dbname, u, p) ? &sv_yes : &sv_no;
#endif
    }
#line 163 "mysql.c"
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__db_selectall_arrayref); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db_selectall_arrayref)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    PERL_UNUSED_VAR(cv); /* -W */
    {
#line 102 "mysql.xsi"
    SV *sth;
    SV **maxrows_svp;
    SV **tmp_svp;
    SV *attr = &PL_sv_undef;
    imp_sth_t *imp_sth;
#line 185 "mysql.c"
#line 108 "mysql.xsi"
    if (items > 2) {
	attr = ST(2);
	if (SvROK(attr) &&
		(DBD_ATTRIB_TRUE(attr,"Slice",5,tmp_svp) || DBD_ATTRIB_TRUE(attr,"Columns",7,tmp_svp))
	) {
	    /* fallback to perl implementation */
	    ST(0) = dbixst_bounce_method("DBD::mysql::db::SUPER::selectall_arrayref", items);
	    XSRETURN(1);
	}
    }
    /* --- prepare --- */
    if (SvROK(ST(1))) {
	sth = ST(1);
    }
    else {
	sth = dbixst_bounce_method("prepare", 3);
	if (!SvROK(sth))
	    XSRETURN_UNDEF;
    }
    imp_sth = (imp_sth_t*)(DBIh_COM(sth));
    /* --- bind_param --- */
    if (items > 3) {    /* need to bind params before execute */
        if (!dbdxst_bind_params(sth, imp_sth, items-2, ax+2) ) {
            XSRETURN_UNDEF;
        }
    }
    /* --- execute --- */
    DBIc_ROW_COUNT(imp_sth) = 0;
    if ( dbd_st_execute(sth, imp_sth) <= -2 ) { /* -2 == error */
        XSRETURN_UNDEF;
    }
    /* --- fetchall --- */
    maxrows_svp = DBD_ATTRIB_GET_SVP(attr, "MaxRows", 7);
    ST(0) = dbdxst_fetchall_arrayref(sth, &PL_sv_undef, (maxrows_svp) ? *maxrows_svp : &PL_sv_undef);
#line 221 "mysql.c"
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__db_selectrow_arrayref); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db_selectrow_arrayref)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    dXSI32;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 149 "mysql.xsi"
    int is_selectrow_array = (ix == 1);
    imp_sth_t *imp_sth;
    SV *sth;
    AV *row_av;
#line 245 "mysql.c"
#line 154 "mysql.xsi"
    if (SvROK(ST(1))) {
	sth = ST(1);
    }
    else {
	/* --- prepare --- */
	sth = dbixst_bounce_method("prepare", 3);
	if (!SvROK(sth)) {
	    if (is_selectrow_array) { XSRETURN_EMPTY; } else { XSRETURN_UNDEF; }
	}
    }
    imp_sth = (imp_sth_t*)(DBIh_COM(sth));
    /* --- bind_param --- */
    if (items > 3) {	/* need to bind params before execute */
	if (!dbdxst_bind_params(sth, imp_sth, items-2, ax+2) ) {
	    if (is_selectrow_array) { XSRETURN_EMPTY; } else { XSRETURN_UNDEF; }
	}
    }
    /* --- execute --- */
    DBIc_ROW_COUNT(imp_sth) = 0;
    if ( dbd_st_execute(sth, imp_sth) <= -2 ) {	/* -2 == error */
	if (is_selectrow_array) { XSRETURN_EMPTY; } else { XSRETURN_UNDEF; }
    }
    /* --- fetchrow_arrayref --- */
    row_av = dbd_st_fetch(sth, imp_sth);
    if (!row_av) {
	if (GIMME == G_SCALAR)
	    PUSHs(&PL_sv_undef);
    }
    else if (is_selectrow_array) {
	int i;
	int num_fields = AvFILL(row_av)+1;
	if (GIMME == G_SCALAR)
	    num_fields = 1; /* return just first field */
	EXTEND(sp, num_fields);
	for(i=0; i < num_fields; ++i) {
	    PUSHs(AvARRAY(row_av)[i]);
	}
    }
    else {
	PUSHs( sv_2mortal(newRV((SV *)row_av)) );
    }
    /* --- finish --- */
#ifdef dbd_st_finish3
    dbd_st_finish3(sth, imp_sth, 0);
#else
    dbd_st_finish(sth, imp_sth);
#endif
#line 294 "mysql.c"
	PUTBACK;
	return;
    }
}

#ifdef dbd_db_do4 /* deebeedee-deebee-doo, deebee-doobee-dah? */
#define XSubPPtmpAAAC 1


XS(XS_DBD__mysql__db_do); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db_do)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items < 2 || items > 3)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::db::do", "dbh, statement, params = Nullsv");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	dbh = ST(0);
	char *	statement = (char *)SvPV_nolen(ST(1));
	SV *	params;

	if (items < 3)
	    params = Nullsv;
	else {
	    params = ST(2);
	}
#line 211 "mysql.xsi"
    {
    D_imp_dbh(dbh);
    IV retval;
    retval = dbd_db_do4(dbh, imp_dbh, statement, params);
    /* remember that dbd_db_do4 must return <= -2 for error	*/
    if (retval == 0)		/* ok with no rows affected	*/
	XST_mPV(0, "0E0");	/* (true but zero)		*/
    else if (retval < -1)	/* -1 == unknown number of rows	*/
	XST_mUNDEF(0);		/* <= -2 means error   		*/
    else
	XST_mIV(0, retval);	/* typically 1, rowcount or -1	*/
    }
#line 338 "mysql.c"
    }
    XSRETURN(1);
}

#endif
#ifdef dbd_db_last_insert_id
#define XSubPPtmpAAAD 1


XS(XS_DBD__mysql__db_last_insert_id); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db_last_insert_id)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items < 5 || items > 6)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::db::last_insert_id", "dbh, catalog, schema, table, field, attr=Nullsv");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	dbh = ST(0);
	SV *	catalog = ST(1);
	SV *	schema = ST(2);
	SV *	table = ST(3);
	SV *	field = ST(4);
	SV *	attr;

	if (items < 6)
	    attr = Nullsv;
	else {
	    attr = ST(5);
	}
#line 238 "mysql.xsi"
    {
    D_imp_dbh(dbh);
    ST(0) = dbd_db_last_insert_id(dbh, imp_dbh, catalog, schema, table, field, attr);
    }
#line 377 "mysql.c"
    }
    XSRETURN(1);
}

#endif

XS(XS_DBD__mysql__db_commit); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db_commit)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::db::commit", "dbh");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	dbh = ST(0);
#line 250 "mysql.xsi"
    D_imp_dbh(dbh);
    if (DBIc_has(imp_dbh,DBIcf_AutoCommit) && DBIc_WARN(imp_dbh))
	warn("commit ineffective with AutoCommit enabled");
    ST(0) = dbd_db_commit(dbh, imp_dbh) ? &sv_yes : &sv_no;
#line 402 "mysql.c"
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__db_rollback); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db_rollback)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::db::rollback", "dbh");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	dbh = ST(0);
#line 260 "mysql.xsi"
    D_imp_dbh(dbh);
    if (DBIc_has(imp_dbh,DBIcf_AutoCommit) && DBIc_WARN(imp_dbh))
	warn("rollback ineffective with AutoCommit enabled");
    ST(0) = dbd_db_rollback(dbh, imp_dbh) ? &sv_yes : &sv_no;
#line 426 "mysql.c"
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__db_disconnect); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db_disconnect)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::db::disconnect", "dbh");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	dbh = ST(0);
#line 270 "mysql.xsi"
    D_imp_dbh(dbh);
    if ( !DBIc_ACTIVE(imp_dbh) ) {
	XSRETURN_YES;
    }
    /* pre-disconnect checks and tidy-ups */
    if (DBIc_CACHED_KIDS(imp_dbh)) {
	SvREFCNT_dec(DBIc_CACHED_KIDS(imp_dbh));      /* cast them to the winds	*/
	DBIc_CACHED_KIDS(imp_dbh) = Nullhv;
    }
    /* Check for disconnect() being called whilst refs to cursors	*/
    /* still exists. This possibly needs some more thought.		*/
    if (DBIc_ACTIVE_KIDS(imp_dbh) && DBIc_WARN(imp_dbh) && !dirty) {
	STRLEN lna;
	char *plural = (DBIc_ACTIVE_KIDS(imp_dbh)==1) ? "" : "s";
	warn("%s->disconnect invalidates %d active statement handle%s %s",
	    SvPV(dbh,lna), (int)DBIc_ACTIVE_KIDS(imp_dbh), plural,
	    "(either destroy statement handles or call finish on them before disconnecting)");
    }
    ST(0) = dbd_db_disconnect(dbh, imp_dbh) ? &sv_yes : &sv_no;
    DBIc_ACTIVE_off(imp_dbh);	/* ensure it's off, regardless */
#line 466 "mysql.c"
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__db_STORE); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db_STORE)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 3)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::db::STORE", "dbh, keysv, valuesv");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	dbh = ST(0);
	SV *	keysv = ST(1);
	SV *	valuesv = ST(2);
#line 298 "mysql.xsi"
    D_imp_dbh(dbh);
    if (SvGMAGICAL(valuesv))
	mg_get(valuesv);
    ST(0) = &sv_yes;
    if (!dbd_db_STORE_attrib(dbh, imp_dbh, keysv, valuesv))
	if (!DBIc_DBISTATE(imp_dbh)->set_attr(dbh, keysv, valuesv))
	    ST(0) = &sv_no;
#line 495 "mysql.c"
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__db_FETCH); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db_FETCH)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 2)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::db::FETCH", "dbh, keysv");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	dbh = ST(0);
	SV *	keysv = ST(1);
#line 312 "mysql.xsi"
    D_imp_dbh(dbh);
    SV *valuesv = dbd_db_FETCH_attrib(dbh, imp_dbh, keysv);
    if (!valuesv)
	valuesv = DBIc_DBISTATE(imp_dbh)->get_attr(dbh, keysv);
    ST(0) = valuesv;	/* dbd_db_FETCH_attrib did sv_2mortal	*/
#line 521 "mysql.c"
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__db_DESTROY); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db_DESTROY)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::db::DESTROY", "dbh");
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV *	dbh = ST(0);
#line 323 "mysql.xsi"
    D_imp_dbh(dbh);
    ST(0) = &sv_yes;
    if (!DBIc_IMPSET(imp_dbh)) {	/* was never fully set up	*/
	STRLEN lna;
	if (DBIc_WARN(imp_dbh) && !dirty && DBIc_DBISTATE(imp_dbh)->debug >= 2)
	     PerlIO_printf(DBIc_LOGPIO(imp_dbh),
		"         DESTROY for %s ignored - handle not initialised\n",
		    SvPV(dbh,lna));
    }
    else {
	/* pre-disconnect checks and tidy-ups */
	if (DBIc_CACHED_KIDS(imp_dbh)) {
	    SvREFCNT_dec(DBIc_CACHED_KIDS(imp_dbh));  /* cast them to the winds	*/
	    DBIc_CACHED_KIDS(imp_dbh) = Nullhv;
	}
        if (DBIc_IADESTROY(imp_dbh)) {		  /* want's ineffective destroy	*/
            DBIc_ACTIVE_off(imp_dbh);
	    if (DBIc_DBISTATE(imp_dbh)->debug)
		 PerlIO_printf(DBIc_LOGPIO(imp_dbh), "         DESTROY %s skipped due to InactiveDestroy\n", SvPV_nolen(dbh));
        }
	if (DBIc_ACTIVE(imp_dbh)) {
	    if (!DBIc_has(imp_dbh,DBIcf_AutoCommit)) {
		/* Application is using transactions and hasn't explicitly disconnected.
		    Some databases will automatically commit on graceful disconnect.
		    Since we're about to gracefully disconnect as part of the DESTROY
		    we want to be sure we're not about to implicitly commit changes
		    that are incomplete and should be rolled back. (The DESTROY may
		    be due to a RaiseError, for example.) So we rollback here.
		    This will be harmless if the application has issued a commit,
		    XXX Could add an attribute flag to indicate that the driver
		    doesn't have this problem. Patches welcome.
		    XXX or could just move the DBIc_is(imp_dbh, DBIcf_Executed) test
		    to cover the rollback as well. That just needs sanity checking
		    that DBIcf_Executed is set by any/all possible way to execute a
		    statement that might start a transaction.
		*/
		if (DBIc_WARN(imp_dbh)
		&&  DBIc_is(imp_dbh, DBIcf_Executed) /* has not just called commit/rollback */
		&& (!dirty || DBIc_DBISTATE(imp_dbh)->debug >= 3)
		)
		     warn("Issuing rollback() for database handle being DESTROY'd without explicit disconnect()");
		dbd_db_rollback(dbh, imp_dbh);			/* ROLLBACK! */
	    }
	    dbd_db_disconnect(dbh, imp_dbh);
	    DBIc_ACTIVE_off(imp_dbh);	/* ensure it's off, regardless */
	}
	dbd_db_destroy(dbh, imp_dbh);
    }
#line 591 "mysql.c"
	PUTBACK;
	return;
    }
}

#ifdef dbd_take_imp_data
#define XSubPPtmpAAAE 1


XS(XS_DBD__mysql__db_take_imp_data); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db_take_imp_data)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::db::take_imp_data", "h");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	h = ST(0);
#line 379 "mysql.xsi"
    D_imp_xxh(h);
    /* dbd_take_imp_data() returns &sv_no (or other defined but false value)
     * to indicate "preparations complete, now call SUPER::take_imp_data" for me.
     * Anything else is returned to the caller via sv_2mortal(sv), typically that
     * would be &sv_undef for error or an SV holding the imp_data.
     */
    SV *sv = dbd_take_imp_data(h, imp_xxh, NULL);
    ST(0) = (SvOK(sv) && !SvTRUE(sv))
	? dbixst_bounce_method("DBD::mysql::db::SUPER::take_imp_data", items)
	: sv_2mortal(sv);
#line 625 "mysql.c"
    }
    XSRETURN(1);
}

#endif
#ifdef dbd_db_data_sources
#define XSubPPtmpAAAF 1


XS(XS_DBD__mysql__db_data_sources); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db_data_sources)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items < 1 || items > 2)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::db::data_sources", "dbh, attr = Nullsv");
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV *	dbh = ST(0);
	SV *	attr;

	if (items < 2)
	    attr = Nullsv;
	else {
	    attr = ST(1);
	}
#line 399 "mysql.xsi"
    {
	D_imp_dbh(dbh);
	AV *av = dbd_db_data_sources(dbh, imp_dbh, attr);
	if (av) {
	    int i;
	    int n = AvFILL(av)+1;
	    EXTEND(sp, n);
	    for (i = 0; i < n; ++i) {
		PUSHs(AvARRAY(av)[i]);
	    }
	}
    }
#line 670 "mysql.c"
	PUTBACK;
	return;
    }
}

#endif

XS(XS_DBD__mysql__st__prepare); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st__prepare)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items < 2 || items > 3)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::st::_prepare", "sth, statement, attribs=Nullsv");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	sth = ST(0);
	SV *	statement = ST(1);
	SV *	attribs;

	if (items < 3)
	    attribs = Nullsv;
	else {
	    attribs = ST(2);
	}
#line 428 "mysql.xsi"
    {
    D_imp_sth(sth);
    DBD_ATTRIBS_CHECK("_prepare", sth, attribs);
#ifdef dbd_st_prepare_sv
    ST(0) = dbd_st_prepare_sv(sth, imp_sth, statement, attribs) ? &sv_yes : &sv_no;
#else
    ST(0) = dbd_st_prepare(sth, imp_sth, SvPV_nolen(statement), attribs) ? &sv_yes : &sv_no;
#endif
    }
#line 709 "mysql.c"
    }
    XSRETURN(1);
}

#ifdef dbd_st_rows
#define XSubPPtmpAAAG 1


XS(XS_DBD__mysql__st_rows); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st_rows)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::st::rows", "sth");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	sth = ST(0);
#line 445 "mysql.xsi"
    D_imp_sth(sth);
    XST_mIV(0, dbd_st_rows(sth, imp_sth));
#line 734 "mysql.c"
    }
    XSRETURN(1);
}

#endif /* dbd_st_rows */
#ifdef dbd_st_bind_col
#define XSubPPtmpAAAH 1


XS(XS_DBD__mysql__st_bind_col); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st_bind_col)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items < 3 || items > 4)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::st::bind_col", "sth, col, ref, attribs=Nullsv");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	sth = ST(0);
	SV *	col = ST(1);
	SV *	ref = ST(2);
	SV *	attribs;

	if (items < 4)
	    attribs = Nullsv;
	else {
	    attribs = ST(3);
	}
#line 460 "mysql.xsi"
    {
    IV sql_type = 0;
    D_imp_sth(sth);
    if (SvGMAGICAL(ref))
	mg_get(ref);
    if (attribs) {
	if (SvNIOK(attribs)) {
	    sql_type = SvIV(attribs);
	    attribs = Nullsv;
	}
	else {
	    SV **svp;
	    DBD_ATTRIBS_CHECK("bind_col", sth, attribs);
	    /* XXX we should perhaps complain if TYPE is not SvNIOK */
	    DBD_ATTRIB_GET_IV(attribs, "TYPE",4, svp, sql_type);
	}
    }
    switch(dbd_st_bind_col(sth, imp_sth, col, ref, sql_type, attribs)) {
    case 2:	ST(0) = &sv_yes;	/* job done completely */
		break;
    case 1:	/* fallback to DBI default */
		ST(0) = (DBIc_DBISTATE(imp_sth)->bind_col(sth, col, ref, attribs))
		    ? &sv_yes : &sv_no;
		break;
    default:	ST(0) = &sv_no;		/* dbd_st_bind_col has called set_err */
		break;
    }
    }
#line 795 "mysql.c"
    }
    XSRETURN(1);
}

#endif /* dbd_st_bind_col */

XS(XS_DBD__mysql__st_bind_param); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st_bind_param)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items < 3 || items > 4)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::st::bind_param", "sth, param, value, attribs=Nullsv");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	sth = ST(0);
	SV *	param = ST(1);
	SV *	value = ST(2);
	SV *	attribs;

	if (items < 4)
	    attribs = Nullsv;
	else {
	    attribs = ST(3);
	}
#line 498 "mysql.xsi"
    {
    IV sql_type = 0;
    D_imp_sth(sth);
    if (SvGMAGICAL(value))
	mg_get(value);
    if (attribs) {
	if (SvNIOK(attribs)) {
	    sql_type = SvIV(attribs);
	    attribs = Nullsv;
	}
	else {
	    SV **svp;
	    DBD_ATTRIBS_CHECK("bind_param", sth, attribs);
	    /* XXX we should perhaps complain if TYPE is not SvNIOK */
	    DBD_ATTRIB_GET_IV(attribs, "TYPE",4, svp, sql_type);
	}
    }
    ST(0) = dbd_bind_ph(sth, imp_sth, param, value, sql_type, attribs, FALSE, 0)
		? &sv_yes : &sv_no;
    }
#line 845 "mysql.c"
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__st_bind_param_inout); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st_bind_param_inout)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items < 4 || items > 5)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::st::bind_param_inout", "sth, param, value_ref, maxlen, attribs=Nullsv");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	sth = ST(0);
	SV *	param = ST(1);
	SV *	value_ref = ST(2);
	IV	maxlen = (IV)SvIV(ST(3));
	SV *	attribs;

	if (items < 5)
	    attribs = Nullsv;
	else {
	    attribs = ST(4);
	}
#line 528 "mysql.xsi"
    {
    IV sql_type = 0;
    D_imp_sth(sth);
    SV *value;
    if (!SvROK(value_ref) || SvTYPE(SvRV(value_ref)) > SVt_PVMG)
	croak("bind_param_inout needs a reference to a scalar value");
    value = SvRV(value_ref);
    if (SvREADONLY(value))
	croak("Modification of a read-only value attempted");
    if (SvGMAGICAL(value))
	mg_get(value);
    if (attribs) {
	if (SvNIOK(attribs)) {
	    sql_type = SvIV(attribs);
	    attribs = Nullsv;
	}
	else {
	    SV **svp;
	    DBD_ATTRIBS_CHECK("bind_param", sth, attribs);
	    DBD_ATTRIB_GET_IV(attribs, "TYPE",4, svp, sql_type);
	}
    }
    ST(0) = dbd_bind_ph(sth, imp_sth, param, value, sql_type, attribs, TRUE, maxlen)
		? &sv_yes : &sv_no;
    }
#line 900 "mysql.c"
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__st_execute); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st_execute)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items < 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::st::execute", "sth, ...");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	sth = ST(0);
#line 559 "mysql.xsi"
    D_imp_sth(sth);
    int retval;
    if (items > 1) {	/* need to bind params */
	if (!dbdxst_bind_params(sth, imp_sth, items, ax) ) {
	    XSRETURN_UNDEF;
	}
    }
    /* XXX this code is duplicated in selectrow_arrayref above	*/
    if (DBIc_ROW_COUNT(imp_sth) > 0) /* reset for re-execute */
	DBIc_ROW_COUNT(imp_sth) = 0;
    retval = dbd_st_execute(sth, imp_sth);
    /* remember that dbd_st_execute must return <= -2 for error	*/
    if (retval == 0)		/* ok with no rows affected	*/
	XST_mPV(0, "0E0");	/* (true but zero)		*/
    else if (retval < -1)	/* -1 == unknown number of rows	*/
	XST_mUNDEF(0);		/* <= -2 means error   		*/
    else
	XST_mIV(0, retval);	/* typically 1, rowcount or -1	*/
#line 938 "mysql.c"
    }
    XSRETURN(1);
}

#ifdef dbd_st_execute_for_fetch
#define XSubPPtmpAAAI 1


XS(XS_DBD__mysql__st_execute_for_fetch); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st_execute_for_fetch)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items < 2 || items > 3)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::st::execute_for_fetch", "sth, fetch_tuple_sub, tuple_status = Nullsv");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	sth = ST(0);
	SV *	fetch_tuple_sub = ST(1);
	SV *	tuple_status;

	if (items < 3)
	    tuple_status = Nullsv;
	else {
	    tuple_status = ST(2);
	}
#line 587 "mysql.xsi"
    {
    D_imp_sth(sth);
    ST(0) = dbd_st_execute_for_fetch(sth, imp_sth, fetch_tuple_sub, tuple_status);
    }
#line 973 "mysql.c"
    }
    XSRETURN(1);
}

#endif

XS(XS_DBD__mysql__st_fetchrow_arrayref); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st_fetchrow_arrayref)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    dXSI32;
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", GvNAME(CvGV(cv)), "sth");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	sth = ST(0);
#line 602 "mysql.xsi"
    D_imp_sth(sth);
    AV *av;
    if (0) ix = ix;	/* avoid unused variable warning */
    av = dbd_st_fetch(sth, imp_sth);
    ST(0) = (av) ? sv_2mortal(newRV((SV *)av)) : &PL_sv_undef;
#line 1000 "mysql.c"
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__st_fetchrow_array); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st_fetchrow_array)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    dXSI32;
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", GvNAME(CvGV(cv)), "sth");
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV *	sth = ST(0);
#line 615 "mysql.xsi"
    D_imp_sth(sth);
    AV *av;
    av = dbd_st_fetch(sth, imp_sth);
    if (av) {
	int i;
	int num_fields = AvFILL(av)+1;
	EXTEND(sp, num_fields);
	for(i=0; i < num_fields; ++i) {
	    PUSHs(AvARRAY(av)[i]);
	}
	if (0) ix = ix;	/* avoid unused variable warning */
    }
#line 1035 "mysql.c"
	PUTBACK;
	return;
    }
}


XS(XS_DBD__mysql__st_fetchall_arrayref); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st_fetchall_arrayref)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items < 1 || items > 3)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::st::fetchall_arrayref", "sth, slice=&PL_sv_undef, batch_row_count=&PL_sv_undef");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	sth = ST(0);
	SV *	slice;
	SV *	batch_row_count;

	if (items < 2)
	    slice = &PL_sv_undef;
	else {
	    slice = ST(1);
	}

	if (items < 3)
	    batch_row_count = &PL_sv_undef;
	else {
	    batch_row_count = ST(2);
	}
#line 635 "mysql.xsi"
    if (SvOK(slice)) {  /* fallback to perl implementation */
        ST(0) = dbixst_bounce_method("DBD::mysql::st::SUPER::fetchall_arrayref", 3);
    }
    else {
	ST(0) = dbdxst_fetchall_arrayref(sth, slice, batch_row_count);
    }
#line 1076 "mysql.c"
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__st_finish); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st_finish)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::st::finish", "sth");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	sth = ST(0);
#line 647 "mysql.xsi"
    D_imp_sth(sth);
    D_imp_dbh_from_sth;
    if (!DBIc_ACTIVE(imp_sth)) {
	/* No active statement to finish	*/
	XSRETURN_YES;
    }
    if (!DBIc_ACTIVE(imp_dbh)) {
	/* Either an explicit disconnect() or global destruction	*/
	/* has disconnected us from the database. Finish is meaningless	*/
	DBIc_ACTIVE_off(imp_sth);
	XSRETURN_YES;
    }
#ifdef dbd_st_finish3
    ST(0) = dbd_st_finish3(sth, imp_sth, 0) ? &sv_yes : &sv_no;
#else
    ST(0) = dbd_st_finish(sth, imp_sth) ? &sv_yes : &sv_no;
#endif
#line 1113 "mysql.c"
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__st_blob_read); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st_blob_read)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items < 4 || items > 6)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::st::blob_read", "sth, field, offset, len, destrv=Nullsv, destoffset=0");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	sth = ST(0);
	int	field = (int)SvIV(ST(1));
	long	offset = (long)SvIV(ST(2));
	long	len = (long)SvIV(ST(3));
	SV *	destrv;
	long	destoffset;

	if (items < 5)
	    destrv = Nullsv;
	else {
	    destrv = ST(4);
	}

	if (items < 6)
	    destoffset = 0;
	else {
	    destoffset = (long)SvIV(ST(5));
	}
#line 675 "mysql.xsi"
    {
    D_imp_sth(sth);
    if (!destrv)
        destrv = sv_2mortal(newRV(sv_2mortal(newSV(0))));
    if (dbd_st_blob_read(sth, imp_sth, field, offset, len, destrv, destoffset))
         ST(0) = SvRV(destrv);
    else ST(0) = &PL_sv_undef;
    }
#line 1158 "mysql.c"
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__st_STORE); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st_STORE)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 3)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::st::STORE", "sth, keysv, valuesv");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	sth = ST(0);
	SV *	keysv = ST(1);
	SV *	valuesv = ST(2);
#line 691 "mysql.xsi"
    D_imp_sth(sth);
    if (SvGMAGICAL(valuesv))
	mg_get(valuesv);
    ST(0) = &sv_yes;
    if (!dbd_st_STORE_attrib(sth, imp_sth, keysv, valuesv))
	if (!DBIc_DBISTATE(imp_sth)->set_attr(sth, keysv, valuesv))
	    ST(0) = &sv_no;
#line 1187 "mysql.c"
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__st_FETCH_attrib); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st_FETCH_attrib)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    dXSI32;
    if (items != 2)
       Perl_croak(aTHX_ "Usage: %s(%s)", GvNAME(CvGV(cv)), "sth, keysv");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	sth = ST(0);
	SV *	keysv = ST(1);
#line 708 "mysql.xsi"
    D_imp_sth(sth);
    SV *valuesv;
    if (0) ix = ix;	/* avoid unused variable warning */
    valuesv = dbd_st_FETCH_attrib(sth, imp_sth, keysv);
    if (!valuesv)
	valuesv = DBIc_DBISTATE(imp_sth)->get_attr(sth, keysv);
    ST(0) = valuesv;	/* dbd_st_FETCH_attrib did sv_2mortal	*/
#line 1216 "mysql.c"
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__st_DESTROY); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st_DESTROY)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::st::DESTROY", "sth");
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV *	sth = ST(0);
#line 721 "mysql.xsi"
    D_imp_sth(sth);
    ST(0) = &sv_yes;
    if (!DBIc_IMPSET(imp_sth)) {	/* was never fully set up	*/
	STRLEN lna;
	if (DBIc_WARN(imp_sth) && !dirty && DBIc_DBISTATE(imp_sth)->debug >= 2)
	     PerlIO_printf(DBIc_LOGPIO(imp_sth),
		"         DESTROY for %s ignored - handle not initialised\n",
		    SvPV(sth,lna));
    }
    else {
        if (DBIc_IADESTROY(imp_sth)) { /* want's ineffective destroy    */
            DBIc_ACTIVE_off(imp_sth);
	    if (DBIc_DBISTATE(imp_sth)->debug)
		 PerlIO_printf(DBIc_LOGPIO(imp_sth), "         DESTROY %s skipped due to InactiveDestroy\n", SvPV_nolen(sth));
        }
	if (DBIc_ACTIVE(imp_sth)) {
	    D_imp_dbh_from_sth;
	    if (!dirty && DBIc_ACTIVE(imp_dbh)) {
#ifdef dbd_st_finish3
		dbd_st_finish3(sth, imp_sth, 1);
#else
		dbd_st_finish(sth, imp_sth);
#endif
	    }
	    else {
		DBIc_ACTIVE_off(imp_sth);
	    }
	}
	dbd_st_destroy(sth, imp_sth);
    }
#line 1268 "mysql.c"
	PUTBACK;
	return;
    }
}


/* INCLUDE: Returning to 'mysql.xs' from 'mysql.xsi' */


XS(XS_DBD__mysql_constant); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql_constant)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 2)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::constant", "name, arg");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	char*	name = (char *)SvPV_nolen(ST(0));
	char*	arg = (char *)SvPV_nolen(ST(1));
	double	RETVAL;
	dXSTARG;
#line 45 "mysql.xs"
    RETVAL = mysql_constant(name, arg);
#line 1296 "mysql.c"
	XSprePUSH; PUSHn((double)RETVAL);
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__dr__ListDBs); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__dr__ListDBs)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items < 1 || items > 5)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::dr::_ListDBs", "drh, host=NULL, port=NULL, user=NULL, password=NULL");
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV *	drh = ST(0);
	char *	host;
	char *	port;
	char *	user;
	char *	password;

	if (items < 2)
	    host = NULL;
	else {
	    host = (char *)SvPV_nolen(ST(1));
	}

	if (items < 3)
	    port = NULL;
	else {
	    port = (char *)SvPV_nolen(ST(2));
	}

	if (items < 4)
	    user = NULL;
	else {
	    user = (char *)SvPV_nolen(ST(3));
	}

	if (items < 5)
	    password = NULL;
	else {
	    password = (char *)SvPV_nolen(ST(4));
	}
#line 60 "mysql.xs"
{
    MYSQL mysql;
    MYSQL* sock = mysql_dr_connect(drh, &mysql, NULL, host, port, user, password,
				   NULL, NULL);
    if (sock != NULL)
    {
      MYSQL_ROW cur;
      MYSQL_RES* res = mysql_list_dbs(sock, NULL);
      if (!res)
      {
        do_error(drh, mysql_errno(sock), mysql_error(sock), mysql_sqlstate(sock));
      }
      else
      {
	EXTEND(sp, mysql_num_rows(res));
	while ((cur = mysql_fetch_row(res)))
        {
	  PUSHs(sv_2mortal((SV*)newSVpv(cur[0], strlen(cur[0]))));
	}
	mysql_free_result(res);
      }
      mysql_close(sock);
    }
}
#line 1371 "mysql.c"
	PUTBACK;
	return;
    }
}


XS(XS_DBD__mysql__dr__admin_internal); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__dr__admin_internal)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items < 3 || items > 8)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::dr::_admin_internal", "drh, dbh, command, dbname=NULL, host=NULL, port=NULL, user=NULL, password=NULL");
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV*	drh = ST(0);
	SV*	dbh = ST(1);
	char*	command = (char *)SvPV_nolen(ST(2));
	char*	dbname;
	char*	host;
	char*	port;
	char*	user;
	char*	password;

	if (items < 4)
	    dbname = NULL;
	else {
	    dbname = (char *)SvPV_nolen(ST(3));
	}

	if (items < 5)
	    host = NULL;
	else {
	    host = (char *)SvPV_nolen(ST(4));
	}

	if (items < 6)
	    port = NULL;
	else {
	    port = (char *)SvPV_nolen(ST(5));
	}

	if (items < 7)
	    user = NULL;
	else {
	    user = (char *)SvPV_nolen(ST(6));
	}

	if (items < 8)
	    password = NULL;
	else {
	    password = (char *)SvPV_nolen(ST(7));
	}
#line 97 "mysql.xs"
{
  MYSQL mysql;
  int retval;
  MYSQL* sock;

  /*
   *  Connect to the database, if required.
 */
  if (SvOK(dbh)) {
    D_imp_dbh(dbh);
    sock = imp_dbh->pmysql;
  }
  else
  {
    sock = mysql_dr_connect(drh, &mysql, NULL, host, port, user,  password, NULL, NULL);
    if (sock == NULL)
    {
      do_error(drh, mysql_errno(&mysql), mysql_error(&mysql),
               mysql_sqlstate(&mysql));
      XSRETURN_NO;
    }
  }

  if (strEQ(command, "shutdown"))
#if MYSQL_VERSION_ID < 40103
    retval = mysql_shutdown(sock);
#else
    retval = mysql_shutdown(sock, SHUTDOWN_DEFAULT);
#endif
  else if (strEQ(command, "reload"))
    retval = mysql_reload(sock);
  else if (strEQ(command, "createdb"))
  {
#if MYSQL_VERSION_ID < 40000
    retval = mysql_create_db(sock, dbname);
#else
    char* buffer = malloc(strlen(dbname)+50);
    if (buffer == NULL)
    {
      do_error(drh, JW_ERR_MEM, "Out of memory" ,NULL);
      XSRETURN_NO;
    }
    else
    {
      strcpy(buffer, "CREATE DATABASE ");
      strcat(buffer, dbname);
      retval = mysql_real_query(sock, buffer, strlen(buffer));
      free(buffer);
    }
#endif
  }
  else if (strEQ(command, "dropdb"))
  {
#if MYSQL_VERSION_ID < 40000
    retval = mysql_drop_db(sock, dbname);
#else
    char* buffer = malloc(strlen(dbname)+50);
    if (buffer == NULL)
    {
      do_error(drh, JW_ERR_MEM, "Out of memory" ,NULL);
      XSRETURN_NO;
    }
    else
    {
      strcpy(buffer, "DROP DATABASE ");
      strcat(buffer, dbname);
      retval = mysql_real_query(sock, buffer, strlen(buffer));
      free(buffer);
    }
#endif
  }
  else
  {
    croak("Unknown command: %s", command);
  }
  if (retval)
  {
    do_error(SvOK(dbh) ? dbh : drh, mysql_errno(sock),
             mysql_error(sock) ,mysql_sqlstate(sock));
  }

  if (SvOK(dbh))
  {
    mysql_close(sock);
  }
  if (retval)
    XSRETURN_NO;
  else 
    XSRETURN_YES;
}
#line 1521 "mysql.c"
	PUTBACK;
	return;
    }
}


XS(XS_DBD__mysql__db_type_info_all); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db_type_info_all)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::db::type_info_all", "dbh");
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV*	dbh = ST(0);
#line 196 "mysql.xs"
{
  /* 	static AV* types = NULL; */
  /* 	if (!types) { */
  /* 	    D_imp_dbh(dbh); */
  /* 	    if (!(types = dbd_db_type_info_all(dbh, imp_dbh))) { */
  /* 	        croak("Cannot create types array (out of memory?)"); */
  /* 	    } */
  /* 	} */
  /* 	ST(0) = sv_2mortal(newRV_inc((SV*) types)); */
  D_imp_dbh(dbh);
  ASYNC_CHECK_XS(dbh);
  ST(0) = sv_2mortal(newRV_noinc((SV*) dbd_db_type_info_all(dbh,
                                                            imp_dbh)));
  XSRETURN(1);
}
#line 1559 "mysql.c"
	PUTBACK;
	return;
    }
}


XS(XS_DBD__mysql__db__ListDBs); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db__ListDBs)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::db::_ListDBs", "dbh");
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV*	dbh = ST(0);
#line 217 "mysql.xs"
  D_imp_dbh(dbh);

  ASYNC_CHECK_XS(dbh);

  MYSQL_RES* res = mysql_list_dbs(imp_dbh->pmysql, NULL);
  MYSQL_ROW cur;
  if (!res  &&
      (!mysql_db_reconnect(dbh)  ||
       !(res = mysql_list_dbs(imp_dbh->pmysql, NULL))))
{
  do_error(dbh, mysql_errno(imp_dbh->pmysql),
           mysql_error(imp_dbh->pmysql), mysql_sqlstate(imp_dbh->pmysql));
}
else
{
  EXTEND(sp, mysql_num_rows(res));
  while ((cur = mysql_fetch_row(res)))
  {
    PUSHs(sv_2mortal((SV*)newSVpv(cur[0], strlen(cur[0]))));
  }
  mysql_free_result(res);
}
#line 1604 "mysql.c"
	PUTBACK;
	return;
    }
}


XS(XS_DBD__mysql__db_do); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db_do)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items < 2)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::db::do", "dbh, statement, attr=Nullsv, ...");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	dbh = ST(0);
	SV *	statement = ST(1);
	SV *	attr;

	if (items < 3)
	    attr = Nullsv;
	else {
	    attr = ST(2);
	}
#line 248 "mysql.xs"
{
  D_imp_dbh(dbh);
  int num_params= 0;
  int retval;
  struct imp_sth_ph_st* params= NULL;
  MYSQL_RES* result= NULL;
  SV* async = NULL;
#if MYSQL_VERSION_ID >= MULTIPLE_RESULT_SET_VERSION
  int next_result_rc;
#endif
#if MYSQL_VERSION_ID >= SERVER_PREPARE_VERSION
  STRLEN slen;
  char            *str_ptr, *statement_ptr, *buffer;
  int             has_binded;
  int             col_type= MYSQL_TYPE_STRING;
  int             buffer_is_null= 0;
  int             buffer_length= slen;
  int             buffer_type= 0;
  int             param_type= SQL_VARCHAR;
  int             use_server_side_prepare= 0;
  MYSQL_STMT      *stmt= NULL;
  MYSQL_BIND      *bind= NULL;
  imp_sth_phb_t   *fbind= NULL;
#endif
    ASYNC_CHECK_XS(dbh);
#if MYSQL_VERSION_ID >= MULTIPLE_RESULT_SET_VERSION
    while (mysql_next_result(imp_dbh->pmysql)==0)
    {
      MYSQL_RES* res = mysql_use_result(imp_dbh->pmysql);
      if (res)
        mysql_free_result(res);
      }
#endif
#if MYSQL_VERSION_ID >= SERVER_PREPARE_VERSION

  /*
   * Globaly enabled using of server side prepared statement
   * for dbh->do() statements. It is possible to force driver
   * to use server side prepared statement mechanism by adding
   * 'mysql_server_prepare' attribute to do() method localy:
   * $dbh->do($stmt, {mysql_server_prepared=>1});
  */

  use_server_side_prepare = imp_dbh->use_server_side_prepare;
  if (attr)
  {
    SV** svp;
    DBD_ATTRIBS_CHECK("do", dbh, attr);
    svp = DBD_ATTRIB_GET_SVP(attr, "mysql_server_prepare", 20);

    use_server_side_prepare = (svp) ?
      SvTRUE(*svp) : imp_dbh->use_server_side_prepare;

    svp   = DBD_ATTRIB_GET_SVP(attr, "async", 5);
    async = (svp) ? *svp : &PL_sv_no;
  }
  if (dbis->debug >= 2)
    PerlIO_printf(DBILOGFP,
                  "mysql.xs do() use_server_side_prepare %d, async %d\n",
                  use_server_side_prepare, async);

  hv_store((HV*)SvRV(dbh), "Statement", 9, SvREFCNT_inc(statement), 0);

  if(SvTRUE(async)) {
#if MYSQL_ASYNC
    use_server_side_prepare = FALSE; /* for now */
    imp_dbh->async_query_in_flight = imp_dbh;
#else
    do_error(dbh, 2000,
             "Async support was not built into this version of DBD::mysql", "HY000");
    XSRETURN_UNDEF;
#endif
  }

  if (use_server_side_prepare)
  {
    str_ptr= SvPV(statement, slen);

    stmt= mysql_stmt_init(imp_dbh->pmysql);

    if (mysql_stmt_prepare(stmt, str_ptr, strlen(str_ptr)))
    {
      /*
        For commands that are not supported by server side prepared
        statement mechanism lets try to pass them through regular API
      */
      if (mysql_stmt_errno(stmt) == ER_UNSUPPORTED_PS)
      {
        use_server_side_prepare= 0;
      }
      else
      {
        do_error(dbh, mysql_stmt_errno(stmt), mysql_stmt_error(stmt)
                 ,mysql_stmt_sqlstate(stmt));
        retval=-2;
      }
      mysql_stmt_close(stmt);
      stmt= NULL;
    }
    else
    {
      /*
        'items' is the number of arguments passed to XSUB, supplied
        by xsubpp compiler, as listed in manpage for perlxs
      */
      if (items > 3)
      {
        /*
          Handle binding supplied values to placeholders assume user has
          passed the correct number of parameters
        */
        int i;
        num_params= items - 3;
        /*num_params = mysql_stmt_param_count(stmt);*/
        Newz(0, params, sizeof(*params)*num_params, struct imp_sth_ph_st);
        Newz(0, bind, (unsigned int) num_params, MYSQL_BIND);
        Newz(0, fbind, (unsigned int) num_params, imp_sth_phb_t);

        for (i = 0; i < num_params; i++)
        {
          int defined= 0;
          params[i].value= ST(i+3);

          if (params[i].value)
          {
            if (SvMAGICAL(params[i].value))
              mg_get(params[i].value);
            if (SvOK(params[i].value))
              defined= 1;
          }
          if (defined)
          {
            buffer= SvPV(params[i].value, slen);
            buffer_is_null= 0;
            buffer_length= slen;
          }
          else
          {
            buffer= NULL;
            buffer_is_null= 1;
            buffer_length= 0;
          }

          /*
            if this statement has a result set, field types will be
            correctly identified. If there is no result set, such as
            with an INSERT, fields will not be defined, and all
            buffer_type will default to MYSQL_TYPE_VAR_STRING
          */
          col_type= (stmt->fields) ? stmt->fields[i].type : MYSQL_TYPE_STRING;

          switch (col_type) {
#if MYSQL_VERSION_ID > 50003
          case MYSQL_TYPE_NEWDECIMAL:
#endif
          case MYSQL_TYPE_DECIMAL:
            param_type= SQL_DECIMAL;
            buffer_type= MYSQL_TYPE_DOUBLE;
            break;

          case MYSQL_TYPE_DOUBLE:
            param_type= SQL_DOUBLE;
            buffer_type= MYSQL_TYPE_DOUBLE;
            break;

          case MYSQL_TYPE_FLOAT:
            buffer_type= MYSQL_TYPE_DOUBLE;
            param_type= SQL_FLOAT;
            break;

          case MYSQL_TYPE_SHORT:
            buffer_type= MYSQL_TYPE_DOUBLE;
            param_type= SQL_FLOAT;
            break;

          case MYSQL_TYPE_TINY:
            buffer_type= MYSQL_TYPE_DOUBLE;
            param_type= SQL_FLOAT;
            break;

          case MYSQL_TYPE_LONG:
            buffer_type= MYSQL_TYPE_LONG;
            param_type= SQL_BIGINT;
            break;

          case MYSQL_TYPE_INT24:
          case MYSQL_TYPE_YEAR:
            buffer_type= MYSQL_TYPE_LONG;
            param_type= SQL_INTEGER; 
            break;

          case MYSQL_TYPE_LONGLONG:
            /* perl handles long long as double
             * so we'll set this to string */
            buffer_type= MYSQL_TYPE_STRING;
            param_type= SQL_VARCHAR;
            break;

          case MYSQL_TYPE_NEWDATE:
          case MYSQL_TYPE_DATE:
            buffer_type= MYSQL_TYPE_STRING;
            param_type= SQL_DATE;
            break;

          case MYSQL_TYPE_TIME:
            buffer_type= MYSQL_TYPE_STRING;
            param_type= SQL_TIME;
            break;

          case MYSQL_TYPE_TIMESTAMP:
            buffer_type= MYSQL_TYPE_STRING;
            param_type= SQL_TIMESTAMP;
            break;

          case MYSQL_TYPE_VAR_STRING:
          case MYSQL_TYPE_STRING:
          case MYSQL_TYPE_DATETIME:
            buffer_type= MYSQL_TYPE_STRING;
            param_type= SQL_VARCHAR;
            break;

          case MYSQL_TYPE_BLOB:
            buffer_type= MYSQL_TYPE_BLOB;
            param_type= SQL_BINARY;
            break;

          case MYSQL_TYPE_GEOMETRY:
            buffer_type= MYSQL_TYPE_BLOB;
            param_type= SQL_BINARY;
            break;


          default:
            buffer_type= MYSQL_TYPE_STRING;
            param_type= SQL_VARCHAR;
            break;
          }

          bind[i].buffer_type = buffer_type;
          bind[i].buffer_length= buffer_length;
          bind[i].buffer= buffer;
          fbind[i].length= buffer_length;
          fbind[i].is_null= buffer_is_null;
          params[i].type= param_type;
        }
        has_binded= 0;
      }
      retval = mysql_st_internal_execute41(dbh,
                                           num_params,
                                           &result,
                                           stmt,
                                           bind,
                                           &has_binded);
      if (bind)
        Safefree(bind);
      if (fbind)
        Safefree(fbind);

      if(mysql_stmt_close(stmt))
      {
        fprintf(stderr, "\n failed while closing the statement");
        fprintf(stderr, "\n %s", mysql_stmt_error(stmt));
      }
    }
  }

  if (! use_server_side_prepare)
  {
#endif
    if (items > 3)
    {
      /*  Handle binding supplied values to placeholders	   */
      /*  Assume user has passed the correct number of parameters  */
      int i;
      num_params= items-3;
      Newz(0, params, sizeof(*params)*num_params, struct imp_sth_ph_st);
      for (i= 0;  i < num_params;  i++)
      {
        params[i].value= ST(i+3);
        params[i].type= SQL_VARCHAR;
      }
    }
    retval = mysql_st_internal_execute(dbh, statement, attr, num_params,
                                       params, &result, imp_dbh->pmysql, 0);
#if MYSQL_VERSION_ID >=SERVER_PREPARE_VERSION
  }
#endif
  if (params)
    Safefree(params);

  if (result)
  {
    mysql_free_result(result);
    result= 0;
  }
#if MYSQL_VERSION_ID >= MULTIPLE_RESULT_SET_VERSION
  if (retval != -2 && !SvTRUE(async)) /* -2 means error */
    {
      /* more results? -1 = no, >0 = error, 0 = yes (keep looping) */
      while ((next_result_rc= mysql_next_result(imp_dbh->pmysql)) == 0)
      {
        result = mysql_use_result(imp_dbh->pmysql);
          if (result)
            mysql_free_result(result);
          }
          if (next_result_rc > 0)
          {
            if (dbis->debug >= 2)
              PerlIO_printf(DBILOGFP, "\t<- do() ERROR: %s\n",
                            mysql_error(imp_dbh->pmysql));

              do_error(dbh, mysql_errno(imp_dbh->pmysql),
                       mysql_error(imp_dbh->pmysql),
                       mysql_sqlstate(imp_dbh->pmysql));
              retval= -2;
          }
    }
#endif
  /* remember that dbd_st_execute must return <= -2 for error	*/
  if (retval == 0)		/* ok with no rows affected	*/
    XST_mPV(0, "0E0");	/* (true but zero)		*/
  else if (retval < -1)	/* -1 == unknown number of rows	*/
    XST_mUNDEF(0);		/* <= -2 means error   		*/
  else
    XST_mIV(0, retval);	/* typically 1, rowcount or -1	*/
}
#line 1959 "mysql.c"
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__db_ping); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db_ping)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::db::ping", "dbh");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV*	dbh = ST(0);
	SV *	RETVAL;
#line 581 "mysql.xs"
    {
      int retval;

      D_imp_dbh(dbh);
      ASYNC_CHECK_XS(dbh);
      retval = (mysql_ping(imp_dbh->pmysql) == 0);
      if (!retval) {
	if (mysql_db_reconnect(dbh)) {
	  retval = (mysql_ping(imp_dbh->pmysql) == 0);
	}
      }
      RETVAL = boolSV(retval);
    }
#line 1993 "mysql.c"
	ST(0) = RETVAL;
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__db_quote); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db_quote)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items < 2 || items > 3)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::db::quote", "dbh, str, type=NULL");
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV*	dbh = ST(0);
	SV*	str = ST(1);
	SV*	type;

	if (items < 3)
	    type = NULL;
	else {
	    type = ST(2);
	}
#line 606 "mysql.xs"
    {
        D_imp_dbh(dbh);
        ASYNC_CHECK_XS(dbh);

        SV* quoted = dbd_db_quote(dbh, str, type);
	ST(0) = quoted ? sv_2mortal(quoted) : str;
	XSRETURN(1);
    }
#line 2033 "mysql.c"
	PUTBACK;
	return;
    }
}


XS(XS_DBD__mysql__db_mysql_fd); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db_mysql_fd)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::db::mysql_fd", "dbh");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV*	dbh = ST(0);
	int	RETVAL;
	dXSTARG;
#line 618 "mysql.xs"
    {
        D_imp_dbh(dbh);
        RETVAL = imp_dbh->pmysql->net.fd;
    }
#line 2060 "mysql.c"
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__db_mysql_async_result); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db_mysql_async_result)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::db::mysql_async_result", "dbh");
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV*	dbh = ST(0);
#line 628 "mysql.xs"
    {
#if MYSQL_ASYNC
        int retval;

        retval = mysql_db_async_result(dbh, NULL);

        if(retval > 0) {
            XSRETURN_IV(retval);
        } else if(retval == 0) {
            XSRETURN_PV("0E0");
        } else {
            XSRETURN_UNDEF;
        }
#else
        do_error(dbh, 2000, "Async support was not built into this version of DBD::mysql", "HY000");
        XSRETURN_UNDEF;
#endif
    }
#line 2101 "mysql.c"
	PUTBACK;
	return;
    }
}


XS(XS_DBD__mysql__db_mysql_async_ready); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db_mysql_async_ready)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::db::mysql_async_ready", "dbh");
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV*	dbh = ST(0);
#line 650 "mysql.xs"
    {
#if MYSQL_ASYNC
        int retval;

        retval = mysql_db_async_ready(dbh);
        if(retval > 0) {
            XSRETURN_YES;
        } else if(retval == 0) {
            XSRETURN_NO;
        } else {
            XSRETURN_UNDEF;
        }
#else
        do_error(dbh, 2000, "Async support was not built into this version of DBD::mysql", "HY000");
        XSRETURN_UNDEF;
#endif
    }
#line 2141 "mysql.c"
	PUTBACK;
	return;
    }
}


XS(XS_DBD__mysql__db__async_check); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__db__async_check)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::db::_async_check", "dbh");
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV*	dbh = ST(0);
#line 671 "mysql.xs"
    {
        D_imp_dbh(dbh);
        ASYNC_CHECK_XS(dbh);
        XSRETURN_YES;
    }
#line 2169 "mysql.c"
	PUTBACK;
	return;
    }
}


XS(XS_DBD__mysql__st_more_results); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st_more_results)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::st::more_results", "sth");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV *	sth = ST(0);
	int	RETVAL;
	dXSTARG;
#line 683 "mysql.xs"
{
#if (MYSQL_VERSION_ID >= MULTIPLE_RESULT_SET_VERSION)
  D_imp_sth(sth);
  int retval;
  if (dbd_st_more_results(sth, imp_sth))
  {
    RETVAL=1;
  }
  else
  {
    RETVAL=0;
  }
#endif
}
#line 2206 "mysql.c"
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__st_dataseek); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st_dataseek)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 2)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::st::dataseek", "sth, pos");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV*	sth = ST(0);
	int	pos = (int)SvIV(ST(1));
	int	RETVAL;
	dXSTARG;
#line 706 "mysql.xs"
{
  D_imp_sth(sth);
#if (MYSQL_VERSION_ID >=SERVER_PREPARE_VERSION)
  if (imp_sth->use_server_side_prepare)
  {
    if (imp_sth->use_mysql_use_result || 1)
    {
      if (imp_sth->result && imp_sth->stmt)
      {
        mysql_stmt_data_seek(imp_sth->stmt, pos);
        imp_sth->fetch_done=0;
        RETVAL = 1;
      }
      else
      {
        RETVAL = 0;
        do_error(sth, JW_ERR_NOT_ACTIVE, "Statement not active" ,NULL);
      }
    }
    else
    {
      RETVAL = 0;
      do_error(sth, JW_ERR_NOT_ACTIVE, "No result set" ,NULL);
    }
  }
  else
  {
#endif
  if (imp_sth->result) {
    mysql_data_seek(imp_sth->result, pos);
    RETVAL = 1;
  } else {
    RETVAL = 0;
    do_error(sth, JW_ERR_NOT_ACTIVE, "Statement not active" ,NULL);
  }
#if (MYSQL_VERSION_ID >=SERVER_PREPARE_VERSION) 
  }
#endif
}
#line 2269 "mysql.c"
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__st_rows); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st_rows)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::st::rows", "sth");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV*	sth = ST(0);
#line 752 "mysql.xs"
    D_imp_sth(sth);
    char buf[64];
#if MYSQL_ASYNC
    D_imp_dbh_from_sth;
    if(imp_dbh->async_query_in_flight) {
        if(mysql_db_async_result(sth, &imp_sth->result) < 0) {
            XSRETURN_UNDEF;
        }
    }
#endif

  /* fix to make rows able to handle errors and handle max value from 
     affected rows.
     if mysql_affected_row returns an error, it's value is 18446744073709551614,
     while a (my_ulonglong)-1 is  18446744073709551615, so we have to add 1 to
     imp_sth->row_num to know if there's an error
  */
  if (imp_sth->row_num+1 ==  (my_ulonglong) -1)
    sprintf(buf, "%d", -1);
  else
    sprintf(buf, "%llu", imp_sth->row_num);

  ST(0) = sv_2mortal(newSVpvn(buf, strlen(buf)));
#line 2313 "mysql.c"
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__st_mysql_async_result); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st_mysql_async_result)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::st::mysql_async_result", "sth");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV*	sth = ST(0);
	int	RETVAL;
	dXSTARG;
#line 779 "mysql.xs"
    {
#if MYSQL_ASYNC
        D_imp_sth(sth);
        int retval;

        retval= mysql_db_async_result(sth, &imp_sth->result);

        if(retval > 0) {
            imp_sth->row_num = retval;
            XSRETURN_IV(retval);
        } else if(retval == 0) {
            imp_sth->row_num = retval;
            XSRETURN_PV("0E0");
        } else {
            XSRETURN_UNDEF;
        }
#else
        do_error(sth, 2000,
                 "Async support was not built into this version of DBD::mysql", "HY000");
        XSRETURN_UNDEF;
#endif
    }
#line 2357 "mysql.c"
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS(XS_DBD__mysql__st_mysql_async_ready); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st_mysql_async_ready)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::st::mysql_async_ready", "sth");
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV*	sth = ST(0);
#line 807 "mysql.xs"
    {
#if MYSQL_ASYNC
        int retval;

        retval = mysql_db_async_ready(sth);
        if(retval > 0) {
            XSRETURN_YES;
        } else if(retval == 0) {
            XSRETURN_NO;
        } else {
            XSRETURN_UNDEF;
        }
#else
        do_error(sth, 2000,
                 "Async support was not built into this version of DBD::mysql", "HY000");
        XSRETURN_UNDEF;
#endif
    }
#line 2398 "mysql.c"
	PUTBACK;
	return;
    }
}


XS(XS_DBD__mysql__st__async_check); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__st__async_check)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 1)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::st::_async_check", "sth");
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV*	sth = ST(0);
#line 829 "mysql.xs"
    {
        D_imp_sth(sth);
        D_imp_dbh_from_sth;
        ASYNC_CHECK_XS(sth);
        XSRETURN_YES;
    }
#line 2427 "mysql.c"
	PUTBACK;
	return;
    }
}

#define SQL_CATALOG_NAME_SEPARATOR 41
#define SQL_CATALOG_TERM 42
#define SQL_DBMS_VER 18
#define SQL_IDENTIFIER_QUOTE_CHAR 29
#define SQL_MAXIMUM_STATEMENT_LENGTH 105
#define SQL_MAXIMUM_TABLES_IN_SELECT 106
#define SQL_MAX_TABLE_NAME_LEN 35
#define SQL_SERVER_NAME 13
#define SQL_ASYNC_MODE 10021
#define SQL_MAX_ASYNC_CONCURRENT_STATEMENTS 10022
#define SQL_AM_NONE       0
#define SQL_AM_CONNECTION 1
#define SQL_AM_STATEMENT  2

XS(XS_DBD__mysql__GetInfo_dbd_mysql_get_info); /* prototype to pass -Wmissing-prototypes */
XS(XS_DBD__mysql__GetInfo_dbd_mysql_get_info)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    if (items != 2)
       Perl_croak(aTHX_ "Usage: %s(%s)", "DBD::mysql::GetInfo::dbd_mysql_get_info", "dbh, sql_info_type");
    PERL_UNUSED_VAR(cv); /* -W */
    {
	SV*	dbh = ST(0);
	SV*	sql_info_type = ST(1);
#line 866 "mysql.xs"
    D_imp_dbh(dbh);
    IV type = 0;
    SV* retsv=NULL;
    bool using_322=0;

    if (SvMAGICAL(sql_info_type))
        mg_get(sql_info_type);

    if (SvOK(sql_info_type))
    	type = SvIV(sql_info_type);
    else
    	croak("get_info called with an invalied parameter");

    switch(type) {
    	case SQL_CATALOG_NAME_SEPARATOR:
	    /* (dbc->flag & FLAG_NO_CATALOG) ? WTF is in flag ? */
	    retsv = newSVpv(".",1);
	    break;
	case SQL_CATALOG_TERM:
	    /* (dbc->flag & FLAG_NO_CATALOG) ? WTF is in flag ? */
	    retsv = newSVpv("database",8);
	    break;
	case SQL_DBMS_VER:
	    retsv = newSVpv(
	        imp_dbh->pmysql->server_version,
		strlen(imp_dbh->pmysql->server_version)
	    );
	    break;
	case SQL_IDENTIFIER_QUOTE_CHAR:
	    /*XXX What about a DB started in ANSI mode? */
	    /* Swiped from MyODBC's get_info.c */
	    using_322=is_prefix(mysql_get_server_info(imp_dbh->pmysql),"3.22");
	    retsv = newSVpv(!using_322 ? "`" : " ", 1);
	    break;
	case SQL_MAXIMUM_STATEMENT_LENGTH:
	    retsv = newSViv(net_buffer_length);
	    break;
	case SQL_MAXIMUM_TABLES_IN_SELECT:
	    /* newSViv((sizeof(int) > 32) ? sizeof(int)-1 : 31 ); in general? */
	    retsv= newSViv((sizeof(int) == 64 ) ? 63 : 31 );
	    break;
	case SQL_MAX_TABLE_NAME_LEN:
	    retsv= newSViv(NAME_LEN);
	    break;
	case SQL_SERVER_NAME:
	    retsv= newSVpv(imp_dbh->pmysql->host_info,strlen(imp_dbh->pmysql->host_info));
	    break;
        case SQL_ASYNC_MODE:
#if MYSQL_ASYNC
            retsv = newSViv(SQL_AM_STATEMENT);
#else
            retsv = newSViv(SQL_AM_NONE);
#endif
            break;
        case SQL_MAX_ASYNC_CONCURRENT_STATEMENTS:
#if MYSQL_ASYNC
            retsv = newSViv(1);
#else
            retsv = newSViv(0);
#endif
            break;
    	default:
 		croak("Unknown SQL Info type: %i",dbh);
    }
    ST(0) = sv_2mortal(retsv);
#line 2527 "mysql.c"
    }
    XSRETURN(1);
}

#ifdef __cplusplus
extern "C"
#endif
XS(boot_DBD__mysql); /* prototype to pass -Wmissing-prototypes */
XS(boot_DBD__mysql)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    char* file = __FILE__;

    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    XS_VERSION_BOOTCHECK ;

    {
        CV * cv ;

#if XSubPPtmpAAAA
        cv = newXS("DBD::mysql::dr::discon_all_", XS_DBD__mysql__dr_discon_all_, file);
        XSANY.any_i32 = 0 ;
        cv = newXS("DBD::mysql::dr::disconnect_all", XS_DBD__mysql__dr_discon_all_, file);
        XSANY.any_i32 = 1 ;
#endif
#if XSubPPtmpAAAB
        newXS("DBD::mysql::dr::data_sources", XS_DBD__mysql__dr_data_sources, file);
#endif
        newXS("DBD::mysql::db::_login", XS_DBD__mysql__db__login, file);
        newXS("DBD::mysql::db::selectall_arrayref", XS_DBD__mysql__db_selectall_arrayref, file);
        cv = newXS("DBD::mysql::db::selectrow_arrayref", XS_DBD__mysql__db_selectrow_arrayref, file);
        XSANY.any_i32 = 0 ;
        cv = newXS("DBD::mysql::db::selectrow_array", XS_DBD__mysql__db_selectrow_arrayref, file);
        XSANY.any_i32 = 1 ;
#if XSubPPtmpAAAC
        newXS("DBD::mysql::db::do", XS_DBD__mysql__db_do, file);
#endif
#if XSubPPtmpAAAD
        newXS("DBD::mysql::db::last_insert_id", XS_DBD__mysql__db_last_insert_id, file);
#endif
        newXS("DBD::mysql::db::commit", XS_DBD__mysql__db_commit, file);
        newXS("DBD::mysql::db::rollback", XS_DBD__mysql__db_rollback, file);
        newXS("DBD::mysql::db::disconnect", XS_DBD__mysql__db_disconnect, file);
        newXS("DBD::mysql::db::STORE", XS_DBD__mysql__db_STORE, file);
        newXS("DBD::mysql::db::FETCH", XS_DBD__mysql__db_FETCH, file);
        newXS("DBD::mysql::db::DESTROY", XS_DBD__mysql__db_DESTROY, file);
#if XSubPPtmpAAAE
        newXS("DBD::mysql::db::take_imp_data", XS_DBD__mysql__db_take_imp_data, file);
#endif
#if XSubPPtmpAAAF
        newXS("DBD::mysql::db::data_sources", XS_DBD__mysql__db_data_sources, file);
#endif
        newXS("DBD::mysql::st::_prepare", XS_DBD__mysql__st__prepare, file);
#if XSubPPtmpAAAG
        newXS("DBD::mysql::st::rows", XS_DBD__mysql__st_rows, file);
#endif
#if XSubPPtmpAAAH
        newXS("DBD::mysql::st::bind_col", XS_DBD__mysql__st_bind_col, file);
#endif
        newXS("DBD::mysql::st::bind_param", XS_DBD__mysql__st_bind_param, file);
        newXS("DBD::mysql::st::bind_param_inout", XS_DBD__mysql__st_bind_param_inout, file);
        newXS("DBD::mysql::st::execute", XS_DBD__mysql__st_execute, file);
#if XSubPPtmpAAAI
        newXS("DBD::mysql::st::execute_for_fetch", XS_DBD__mysql__st_execute_for_fetch, file);
#endif
        cv = newXS("DBD::mysql::st::fetchrow_arrayref", XS_DBD__mysql__st_fetchrow_arrayref, file);
        XSANY.any_i32 = 0 ;
        cv = newXS("DBD::mysql::st::fetch", XS_DBD__mysql__st_fetchrow_arrayref, file);
        XSANY.any_i32 = 1 ;
        cv = newXS("DBD::mysql::st::fetchrow", XS_DBD__mysql__st_fetchrow_array, file);
        XSANY.any_i32 = 1 ;
        cv = newXS("DBD::mysql::st::fetchrow_array", XS_DBD__mysql__st_fetchrow_array, file);
        XSANY.any_i32 = 0 ;
        newXS("DBD::mysql::st::fetchall_arrayref", XS_DBD__mysql__st_fetchall_arrayref, file);
        newXS("DBD::mysql::st::finish", XS_DBD__mysql__st_finish, file);
        newXS("DBD::mysql::st::blob_read", XS_DBD__mysql__st_blob_read, file);
        newXS("DBD::mysql::st::STORE", XS_DBD__mysql__st_STORE, file);
        cv = newXS("DBD::mysql::st::FETCH_attrib", XS_DBD__mysql__st_FETCH_attrib, file);
        XSANY.any_i32 = 0 ;
        cv = newXS("DBD::mysql::st::FETCH", XS_DBD__mysql__st_FETCH_attrib, file);
        XSANY.any_i32 = 1 ;
        newXS("DBD::mysql::st::DESTROY", XS_DBD__mysql__st_DESTROY, file);
        newXS("DBD::mysql::constant", XS_DBD__mysql_constant, file);
        newXS("DBD::mysql::dr::_ListDBs", XS_DBD__mysql__dr__ListDBs, file);
        newXS("DBD::mysql::dr::_admin_internal", XS_DBD__mysql__dr__admin_internal, file);
        newXS("DBD::mysql::db::type_info_all", XS_DBD__mysql__db_type_info_all, file);
        newXS("DBD::mysql::db::_ListDBs", XS_DBD__mysql__db__ListDBs, file);
        newXSproto("DBD::mysql::db::do", XS_DBD__mysql__db_do, file, "$$;$@");
        newXSproto("DBD::mysql::db::ping", XS_DBD__mysql__db_ping, file, "$");
        newXSproto("DBD::mysql::db::quote", XS_DBD__mysql__db_quote, file, "$$;$");
        newXS("DBD::mysql::db::mysql_fd", XS_DBD__mysql__db_mysql_fd, file);
        newXS("DBD::mysql::db::mysql_async_result", XS_DBD__mysql__db_mysql_async_result, file);
        newXS("DBD::mysql::db::mysql_async_ready", XS_DBD__mysql__db_mysql_async_ready, file);
        newXS("DBD::mysql::db::_async_check", XS_DBD__mysql__db__async_check, file);
        newXS("DBD::mysql::st::more_results", XS_DBD__mysql__st_more_results, file);
        newXSproto("DBD::mysql::st::dataseek", XS_DBD__mysql__st_dataseek, file, "$$");
        newXS("DBD::mysql::st::rows", XS_DBD__mysql__st_rows, file);
        newXS("DBD::mysql::st::mysql_async_result", XS_DBD__mysql__st_mysql_async_result, file);
        newXS("DBD::mysql::st::mysql_async_ready", XS_DBD__mysql__st_mysql_async_ready, file);
        newXS("DBD::mysql::st::_async_check", XS_DBD__mysql__st__async_check, file);
        newXS("DBD::mysql::GetInfo::dbd_mysql_get_info", XS_DBD__mysql__GetInfo_dbd_mysql_get_info, file);
    }

    /* Initialisation Section */

#line 18 "mysql.xsi"
    items = 0;  /* avoid 'unused variable' warning */
    DBISTATE_INIT;
    /* XXX this interface will change: */
    DBI_IMP_SIZE("DBD::mysql::dr::imp_data_size", sizeof(imp_drh_t));
    DBI_IMP_SIZE("DBD::mysql::db::imp_data_size", sizeof(imp_dbh_t));
    DBI_IMP_SIZE("DBD::mysql::st::imp_data_size", sizeof(imp_sth_t));
    dbd_init(DBIS);

#if XSubPPtmpAAAA
#endif
#if XSubPPtmpAAAB
#endif
#if XSubPPtmpAAAC
#endif
#if XSubPPtmpAAAD
#endif
#if XSubPPtmpAAAE
#endif
#if XSubPPtmpAAAF
#endif
#if XSubPPtmpAAAG
#endif
#if XSubPPtmpAAAH
#endif
#if XSubPPtmpAAAI
#endif
#line 2665 "mysql.c"

    /* End of Initialisation Section */

    XSRETURN_YES;
}

