Lemonldap-NG-Common
view release on metacpan or search on metacpan
lib/Lemonldap/NG/Common/Notifications/DBI.pm view on Meta::CPAN
$t[0] );
};
if ($@) {
$self->logger->warn("Bad date: $h->{date}");
return {};
}
$result->{"$h->{date}#$h->{uid}#$h->{ref}"} = {
notified => $done,
uid => $h->{uid},
ref => $h->{ref},
condition => $h->{cond}
};
}
$self->logger->warn( $self->sth->err() ) if ( $self->sth->err() );
return $result;
}
## @method private object _execute(string query, array args)
# Execute a query and catch errors
# @return number of lines touched or 1 if select succeed
sub _execute {
my ( $self, $query, @args ) = @_;
my $dbh = $self->_dbh or die "DB connection unavailable";
$self->logger->debug("Notification DBI proccessing query: $query");
unless ( $self->sth( $dbh->prepare($query) ) ) {
$self->logger->warn( $dbh->errstr() );
return 0;
}
my $tmp;
unless ( $tmp = $self->sth->execute(@args) ) {
$self->logger->warn( $self->sth->errstr() );
return 0;
}
return $tmp;
}
## @method string getIdentifier(string uid, string ref, string date)
# Get notification identifier
# @param $uid uid
# @param $ref ref
# @param $date date
# @return the notification identifier
sub getIdentifier {
my ( $self, $uid, $ref, $date ) = @_;
return $date . "#" . $uid . "#" . $ref;
}
sub _dbh {
my $self = shift;
my $dbh = check_dbh( $self->{_dbh} );
return $dbh if $dbh;
delete $self->{_dbh};
$self->logger->debug("Notification DBI connection lost, getting a new one");
$self->{_dbh} = DBI->connect_cached( $self->{dbiChain}, $self->{dbiUser},
$self->{dbiPassword}, { RaiseError => 1, AutoCommit => 1, } );
if ( $self->{dbiChain} =~ /^dbi:sqlite/i ) {
$self->{_dbh}->{sqlite_unicode} = 1;
}
elsif ( $self->{dbiChain} =~ /^dbi:mysql/i ) {
eval {
$self->{_dbh}->{mysql_enable_utf8} = 1;
$self->{_dbh}->do("set names 'utf8'");
};
}
elsif ( $self->{dbiChain} =~ /^dbi:pg/i ) {
$self->{_dbh}->{pg_enable_utf8} = 1;
}
return $self->{_dbh};
}
1;
( run in 1.032 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )