GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  DBIX::WRAPPER::REQUEST (3)

.ds Aq ’

NAME

DBIx::Wrapper::Request - Request object for database operations

CONTENTS

SYNOPSIS

Objects of the class are created by DBIx::Wrapper objects and passed to hooks. You should never have to create one yourself.



 my $db = $req->getDbObj;

 my $query = $req->getQuery;
 $req->setQuery($query);

 my $exec_args = $req->getExecArgs;
 $req->setExecArgs(\@args);

 my $rv = $req->getExecReturnValue;
 $req->setExecReturnValue($rv);

 my $rv = $req->getReturnVal;
 $req->setReturnVal($rv);

 my $sth = $req->getStatementHandle;
 $req->setStatementHandle($sth);

 my $err_str = $req->getErrorStr;
 $req->setErrorStr($err_str);



DESCRIPTION

DBIx::Wrapper::Request objects are used to encapsulate date passed between DBIx::Wrapper methods at various stages of executing a query.

METHODS

CWgetDbObj()

Returns the DBIx::Wrapper object that created the Request object.

CWgetQuery()

Returns the current query.

CWsetQuery($query)

Sets the current query.

CWgetExecArgs()

Returns a reference to the array of execute arguments passed to the DBIx::Wrapper method currently executing.

CWsetExecArgs(\@args)

Sets the current execute arguments.

CWgetExecReturnValue()

Returns the current execute() return value.

CWsetExecReturnValue($rv)

Sets the current execute() return value.

CWgetReturnVal()

Gets the current return value (from a fetch).

CWsetReturnVal($rv)

Sets the current return value (from a fetch).

CWgetStatementHandle()

Get the current statement handle being used.

CWsetStatementHandle($sth)

Set the current statement handle to use.

CW$req-getErrorStr()>

Get the error string.

CWsetErrorStr($err_str)

Set the error string.

EXAMPLES



    ##################################################
    # Pre prepare hook

    $db_obj->addPrePrepareHook(\&_db_pre_prepare_hook)

    sub _db_pre_prepare_hook {
        my $self = shift;
        my $r = shift;
        my $query = $r->getQuery;
       
        if ($query =~ /^\s*(?:update|delete|insert|replace|create|drop|alter)/i) {
            my $db = $r->getDbObj;
            unless ($db->ping) {
                # db connection has gone away, so try to reconnect
                my $msg = "UI DataProvider pre-prepare: db ping failed, reconnecting to ";
                $msg .= $db->_getDataSource;
                print STDERR $msg . "\n";
                my $tries_left = 5;
                my $connected = 0;
                my $sleep_time = 0;
                while ($tries_left) {
                    $sleep_time++;
                    sleep $sleep_time;
                    $tries_left--;
                    $connected = $db->reconnect;
                    last if $connected;
                }

                unless ($connected) {
                    die "Couldnt reconnect to db after ping failure: dsn=" . $db->_getDataSource;
                }
            }
        }
                           
        return $r->OK;
    }


    ##################################################
    # Post execute hook

    sub _db_post_exec_hook {
        my $self = shift;
        my $r = shift;

        my $exec_successful = $r->getExecReturnValue;
        unless ($exec_successful) {
            my $query = $r->getQuery;
            if ($r->getQuery =~ /^\s*(?:select|show)/i) {
                my $errstr = $r->getErrorStr;
                if ($errstr =~ /Lost connection to MySQL server during query/i) {
                    my $db = $r->getDbObj;
                    my $msg = "UI DataProvider post exec: lost connection to MySQL server ";
                    $msg .= "during query, reconnecting to " . $db->_getDataSource;
                    print STDERR $msg . "\n";
                    my $tries_left = 5;
                    my $connected = 0;
                    my $sleep_time = 0;
                    while ($tries_left) {
                        $sleep_time++;
                        sleep $sleep_time;
                        $tries_left--;
                        $connected = $db->reconnect;
                        last if $connected;
                    }
                                     
                    if ($connected) {
                        my $sth = $db->prepare_no_hooks($r->getQuery);
                        $r->setStatementHandle($sth);
                        my $exec_args = $r->getExecArgs;
                        my $rv = $sth->execute(@$exec_args);
                        $r->setExecReturnValue($rv);
                    } else {
                        die "Couldnt reconnect to db after losing connection: dsn="
                            . $db->_getDataSource;
                    }
                }
            }
        }
                         
        return $r->OK;
    }



BUGS

AUTHOR

Don Owens <don@regexguy.com>

LICENSE AND COPYRIGHT

Copyright (c) 2004-2012 Don Owens (don@regexguy.com). All rights reserved.

This free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

VERSION

$Id: Request.pm 1963 2012-01-17 15:41:53Z don $
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 DBIX::WRAPPER::REQUEST (3) 2012-01-17

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.