lemonldap-ng/lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/RDBI.pm

60 lines
1.5 KiB
Perl
Raw Normal View History

2009-12-15 17:31:13 +01:00
package Lemonldap::NG::Common::Conf::RDBI;
use strict;
use Lemonldap::NG::Common::Conf::Serializer;
use Lemonldap::NG::Common::Conf::_DBI;
2009-12-15 17:31:13 +01:00
our $VERSION = '1.4.0';
our @ISA = qw(Lemonldap::NG::Common::Conf::_DBI);
2009-12-15 17:31:13 +01:00
sub store {
my ( $self, $fields ) = @_;
$self->{noQuotes} = 1;
$fields = $self->serialize($fields);
my $req = $self->_dbh->prepare(
"INSERT INTO $self->{dbiTable} (cfgNum,field,value) VALUES (?,?,?)"
);
unless ($req) {
$self->logError;
return UNKNOWN_ERROR;
}
$self->_dbh->{AutoCommit} = 0;
2009-12-15 17:31:13 +01:00
while ( my ( $k, $v ) = each %$fields ) {
unless ( $req->execute( $fields->{cfgNum}, $k, $v ) ) {
2009-12-15 17:31:13 +01:00
$self->logError;
$self->_dbh->do("ROLLBACK");
$self->_dbh->{AutoCommit} = 1;
return UNKNOWN_ERROR;
2009-12-15 17:31:13 +01:00
}
}
$self->_dbh->do("COMMIT");
$self->_dbh->{AutoCommit} = 1;
return $fields->{cfgNum};
2009-12-15 17:31:13 +01:00
}
sub load {
my ( $self, $cfgNum, $fields ) = @_;
$fields = $fields ? join( ",", @$fields ) : '*';
my $sth =
$self->_dbh->prepare( "SELECT cfgNum,field,value from "
2009-12-15 17:31:13 +01:00
. $self->{dbiTable}
. " WHERE cfgNum=?" );
$sth->execute($cfgNum);
2009-12-15 17:31:13 +01:00
my ( $res, @row );
while ( @row = $sth->fetchrow_array ) {
$res->{ $row[1] } = $row[2];
}
2010-03-01 21:32:28 +01:00
unless ($res) {
$Lemonldap::NG::Common::Conf::msg .=
"No configuration $cfgNum found \n";
2009-12-15 17:31:13 +01:00
return 0;
}
$res->{cfgNum} = $cfgNum;
return $self->unserialize($res);
}
1;
__END__