DBIx-Fast
view release on metacpan or search on metacpan
lib/DBIx/Fast.pm view on Meta::CPAN
my ($sec, $min, $hour, $mday, $mon , $year) = localtime;
## MySQL / MariaDB
return sprintf("%04d-%02d-%02d %02d:%02d:%02d",$year + 1900, $mon + 1, $mday, $hour, $min, $sec);
}
sub set_error {
my $self = shift;
my $error = {
id => shift,
error => shift,
time => time()
};
my $Errors = $self->errors;
push @{$Errors} ,$error;
$self->_set_last_error(qq{$error->{time} - [$error->{id}] - $error->{error}});
$self->_set_errors($Errors);
}
sub BUILD {
my ($self,$args) = @_;
# Force all
if ( $args->{Error} ) {
$args->{RaiseError} = 1;
$args->{PrintError} = 1;
}
# SQLite
if ( $args->{SQLite} ) {
$self->Exception("No DB Found : ".$args->{SQLite}) unless -e $args->{SQLite};
$args->{db} = $args->{SQLite};
$args->{driver} = 'SQLite'
}
my $DConf = {
DBI => {
RaiseError => $args->{RaiseError} // 0,
PrintError => $args->{PrintError} // 0,
AutoCommit => $args->{AutoCommit} // 1
},
Auth => {
user => $args->{user} // '',
password => $args->{password} // '',
host => $args->{host} // ''
},
tn => $args->{tn} // 1,
db => $args->{db} // '',
dsn => $args->{dsn} // '',
driver => $args->{driver} // '',
quote => $args->{quote} // '',
trace => $args->{trace} // '',
profile => $args->{profile} // '',
abstract => $args->{abstract} // 1
};
$DConf->{DBI}->{mysql_enable_utf8} = 1 if $args->{mysql_enable_utf8};
$self->_set_args($DConf);
$self->Q( SQL::Abstract->new ) if $self->args->{abstract};
# No DSN or Host
unless ( $self->args->{dsn} || $self->args->{db} ) {
$self->Exception("Need a DSN or Host");
}
$self->_set_dsn($self->args->{dsn} ? $self->_check_dsn($self->args->{dsn}) : $self->_make_dsn($self->args));
$self->db( DBIx::Connector->new( $self->dsn,
$self->args->{Auth}->{user}, $self->args->{Auth}->{password},
$self->args->{DBI} ) );
$self->db->mode('ping');
$self->db->dbh->quote($self->args->{quote}) if $self->args->{quote};
$self->db->dbh->{HandleError} = sub {
$self->set_error($DBI::err,$DBI::errstr);
};
$self->db->dbh->trace($self->args->{trace},'dbix-fast-trace') if $self->args->{trace};
$self->_profile($self->args->{profile}) if $self->args->{profile};
## Set TablesName
#$self->_TablesName() if $self->args->{tn};
}
sub _TablesName {
my $self = shift;
return $self->all('tables'); #SHOW TABLES()');
}
sub _Driver_dbd {
my $self = shift;
my $dbd = shift;
$self->Exception("Error DBD Driver") unless $dbd;
map { $self->_set_dbd($_) if lc($dbd) eq lc($_) } qw(SQLite Pg MariaDB mysql);
$self->Exception("Error DBD Driver : $dbd") unless $self->dbd;
}
sub _dsn_dbi {
my $self = shift;
my $dsn = shift;
my ($dbi,$driver,$db,$host) = split ':', $dsn;
$self->Exception("DSN DBI: $dbi") unless $dbi eq 'dbi';
# if ( $driver eq 'SQLite' ) {
# $db =~ s/^(dbname|database)\=(.*)$/$2/;
# } elsif ( $driver eq 'Pg' ) {
( run in 0.618 second using v1.01-cache-2.11-cpan-39bf76dae61 )