Current Path : /usr/local/lib/perl5/site_perl/5.8.9/ADN/ |
FreeBSD hs32.drive.ne.jp 9.1-RELEASE FreeBSD 9.1-RELEASE #1: Wed Jan 14 12:18:08 JST 2015 root@hs32.drive.ne.jp:/sys/amd64/compile/hs32 amd64 |
Current File : //usr/local/lib/perl5/site_perl/5.8.9/ADN/DB.pm |
package ADN::DB; # # DB.pm: # #// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #// use Module #// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= use strict; use Exporter; use vars qw( @ISA @EXPORT @EXPORT_OK $VERSION ); use DBI; #// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #// Exporting #// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= @ISA = qw( Exporter ); $VERSION = 1.00; @EXPORT = qw( ); @EXPORT_OK = qw( ); #// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #// Module #// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #// ---------------------------------------------------------- #// データベース接続 #// ---------------------------------------------------------- sub conn { my $conf = shift; my $init = { driver => $conf->{DBDNAME}, host => '', port => '', dbname => $conf->{DBNAME}, user => $conf->{DBUSER}, pass => $conf->{DBPASS}, }; my $dbh = ''; my @error = (); my $driver = $init->{driver}; my $dbname = $init->{dbname}; my $user = $init->{user}; my $pass = $init->{pass}; $dbh = DBI->connect("dbi:$driver:dbname=$dbname;",$user,$pass) or push(@error, $DBI::errstr); return ($dbh, \@error); } #// ---------------------------------------------------------- #// 汎用 SQL 命令 #// ---------------------------------------------------------- sub copy { my ($dbh, $item) = @_; my $table = $item->{table}; my $dist = $item->{dist}; my $file = $item->{file}; $dbh->do("COPY $table $dist '$file';"); } sub delete { my ($dbh, $item) = @_; my $table = $item->{table}; my $where = $item->{where}; $dbh->do("DELETE FROM $table $where;"); } #// ---------------------------------------------------------- #// データベースクローズ #// ---------------------------------------------------------- sub close { my ($dbh, $sth) = @_; if ($sth) { $sth->finish(); } if ($dbh) { $dbh->disconnect(); } } 1;