2009-12-15 17:31:13 +01:00
|
|
|
package Lemonldap::NG::Common::Conf::RDBI;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Lemonldap::NG::Common::Conf::Serializer;
|
2010-09-17 11:26:03 +02:00
|
|
|
use Lemonldap::NG::Common::Conf::_DBI;
|
2009-12-15 17:31:13 +01:00
|
|
|
|
2010-09-17 11:26:03 +02:00
|
|
|
our $VERSION = 0.2;
|
|
|
|
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 $errors = 0;
|
|
|
|
while ( my ( $k, $v ) = each %$fields ) {
|
2010-10-23 10:00:07 +02:00
|
|
|
my $tmp =
|
|
|
|
$self->_dbh->prepare( "insert into "
|
2009-12-15 17:31:13 +01:00
|
|
|
. $self->{dbiTable}
|
2010-10-23 10:00:07 +02:00
|
|
|
. " (cfgNum,field,value) values (?,?,?)" );
|
|
|
|
unless ( $tmp and $tmp->execute( $fields->{cfgNum}, $k, $v ) ) {
|
2009-12-15 17:31:13 +01:00
|
|
|
$self->logError;
|
|
|
|
$errors++;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
2010-09-17 11:26:03 +02:00
|
|
|
eval { $errors ? $self->_dbh->do("ROLLBACK") : $self->_dbh->do("COMMIT"); };
|
2009-12-15 17:31:13 +01:00
|
|
|
unless ( $self->unlock ) {
|
|
|
|
$self->logError;
|
|
|
|
}
|
|
|
|
return $errors ? UNKNOWN_ERROR : $fields->{cfgNum};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub load {
|
|
|
|
my ( $self, $cfgNum, $fields ) = @_;
|
|
|
|
$fields = $fields ? join( ",", @$fields ) : '*';
|
|
|
|
my $sth =
|
2010-09-17 11:26:03 +02:00
|
|
|
$self->_dbh->prepare( "SELECT cfgNum,field,value from "
|
2009-12-15 17:31:13 +01:00
|
|
|
. $self->{dbiTable}
|
|
|
|
. " WHERE cfgNum=$cfgNum" );
|
|
|
|
$sth->execute();
|
|
|
|
my ( $res, @row );
|
|
|
|
while ( @row = $sth->fetchrow_array ) {
|
|
|
|
$res->{ $row[1] } = $row[2];
|
|
|
|
}
|
2010-03-01 21:32:28 +01:00
|
|
|
unless ($res) {
|
2009-12-15 17:31:13 +01:00
|
|
|
$Lemonldap::NG::Common::Conf::msg .= "No configuration $cfgNum found";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
$res->{cfgNum} = $cfgNum;
|
|
|
|
return $self->unserialize($res);
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|
|
|
|
__END__
|