package caddb;

use webdb;
use Jcode;
@ISA = qw(webdb);

#------------------------------------------------------------------
sub new {
#------------------------------------------------------------------

=head2 ＤＢオープン [new]

webdb-param.plの内容でＤＢをオープンして
データベースハンドルを返す

=cut
	my $class = shift;
        my (
                $hostname,              #
                $driver,                # DBパラメータセット
                $database,              #  webdb-param.plにシステム固有
                $user,                  #  パラメータをセット
                $password) = ("192.168.220.244:3306","mysql","caddoc","sne","ssmaster");

        my $dsn = _dsn_set(-driver=>$driver,
                        -database=>$database,
                        -host=>$hostname);
        my $self ;
        eval{
                $self->{'dbh'} = DBI->connect($dsn,$user,$password)
                                        or die $DBI::errstr;
#		$self->{'dbh'}->do("set names ujis");
        };
        bless $self,$class;
	$self->{dbname} = $database;
	$self->{cons} = new myconstant;
        return  $self ;
}
sub _dsn_set{
        my %a = @_;
        if ($a{-driver} eq "mysql"){
                return "DBI:$a{-driver}:database=$a{-database};host=$a{-host}";
        }
        if ($a{-driver} eq "Pg"){
                return "DBI:$a{-driver}:dbname=$a{-database}";
        }
}
#------------------------------------------------------------------
sub latin2euc{
#------------------------------------------------------------------

=head2 latin -> euc 変換 [latin2euc]

=over 2

latin -> euc 変換

=item $euc = latin2euc($latin)

 $sjis: latin文字列
 $euc: $latin文字列をeucに変換した文字列

=back

=cut
	my $self = shift;
        my $text = shift;
        return jcode($text,"iso-latin1")->euc;
#        return encode("euc-jp",decode("shiftjis",$text));
}
#------------------------------------------------------------------
sub euc2latin{
#------------------------------------------------------------------

	my $self = shift;
        my $text = shift;
        return jcode($text,"euc")->iso_latin1;
}
1;
