Tripletail

 view release on metacpan or  search on metacpan

lib/Tripletail/DB/Sth.pm  view on Meta::CPAN

package Tripletail::DB::Sth;
use strict;
use warnings;
use Tripletail;
use Scalar::Lazy;
my $STH_ID = 0;

sub new {
	my $class = shift;
	my $db = shift;
	my $dbh = shift;
	my $sth = shift;
	my $this = bless {} => $class;

	$this->{db_center} = $db; # Tripletail::DB
	$this->{dbh} = $dbh; # Tripletail::DB::DBH
	$this->{sth} = $sth; # native sth
	$this->{ret} = undef; # last return value
	$this->{id} = $STH_ID++;

	$this;
}

sub fetchHash {
	my $this = shift;
	my $hash = $this->{sth}->fetchrow_hashref;

    if ($hash) {
        $TL->getDebug->_dbLogData(
            lazy {
                +{ group   => $this->{group},
                   set     => $this->{set}{name},
                   db      => $this->{dbh}{inigroup},
                   id      => $this->{id},
                   data    => $hash }
            });
    }
	if( $this->{dbh}{fetchconvert} )
	{
		my $sub = $this->{dbh}{fetchconvert};
		$this->{dbh}->$sub($this, fetchHash => $hash);
	}


	if(my $lim = $this->{db_center}{bufsize}) {
		my $size = 0;
		foreach(values %$hash) {
			$size += length;
		}

        if($size > $lim) {
            die __PACKAGE__."#fetchHash: buffer size exceeded: size [$size] / limit [$lim]".
              " (バッファサイズを超過しました。size [$size] / limit [$lim])\n";
        }
    }

	$hash;
}

sub fetchArray {
	my $this = shift;
	my $array = $this->{sth}->fetchrow_arrayref;

	if( $this->{dbh}{fetchconvert} )
	{
		my $sub = $this->{dbh}{fetchconvert};
		$this->{dbh}->$sub($this, fetchArray => $array);
	}
    if ($array) {
        $TL->getDebug->_dbLogData(
            lazy {
                +{ group   => $this->{group},
                   set     => $this->{set}{name},



( run in 0.996 second using v1.01-cache-2.11-cpan-98e64b0badf )