package DBIkwas::KKWA;
use strict;
use lib qw(../../perlib);BEGIN { $ENV{DBI_PUREPERL} = 1 }
use DBI;

use vars qw/$AUTOLOAD $VERSION/;

$VERSION = "0.01";

sub new {
	my $ass = shift;
 	my $as = {};
	$as->{'drv'} = shift;
	$as->{'cons'} = {};
	bless $as, $ass;
	return $as;
}

sub kkwa {
 	my $self = shift;
	my $kkwa = shift;
	my $sql = shift;
	my @sel;
	unless ($self->{'cons'}{$kkwa}){
		unless ($self->{'drv'} ne "CSV"){
		$self->{'cons'}{$kkwa} = DBI->connect("DBI:CSV:f_dir=$kkwa");
		}
		unless ($self->{'drv'} ne "mysql"){
		my $user = shift;
		my $pass = shift;
		$self->{'cons'}{$kkwa} = DBI->connect("DBI:mysql:$kkwa", $user, $pass);
		}
 	}
	unless ($self->{'cons'}{$kkwa}){return;}
	my $kwas = $self->{'cons'}{$kkwa}->prepare($sql);
	$kwas->execute();
	if ($sql =~ m/SELEC/){
		while (my $row = $kwas->fetch){push(@sel, @$row);}
		return @sel;
	}


	return $self->{'cons'}{$kkwa};
}

sub kwas {
	my $self = shift;
	my $e;
	my %kwas = %{$self->{'cons'}};
	foreach $e (keys %kwas){
		$self->{'cons'}{$e}->disconnect;
	}
}

1;