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

45 lines
1.1 KiB
Perl
Raw Normal View History

2017-01-06 13:30:41 +01:00
package Lemonldap::NG::Common::Conf::Backends::DBI;
use strict;
2016-01-07 13:34:34 +01:00
use utf8;
use Lemonldap::NG::Common::Conf::Serializer;
2017-01-06 13:30:41 +01:00
use Lemonldap::NG::Common::Conf::Backends::_DBI;
2019-02-12 18:21:38 +01:00
our $VERSION = '2.1.0';
2017-01-06 13:30:41 +01:00
our @ISA = qw(Lemonldap::NG::Common::Conf::Backends::_DBI);
sub store {
my ( $self, $fields ) = @_;
2010-01-01 13:04:26 +01:00
return DEPRECATED unless ( $self->{forceUpload} );
$fields = $self->serialize($fields);
my $tmp =
$self->_dbh->do( "insert into "
. $self->{dbiTable} . " ("
. join( ",", keys(%$fields) )
. ") values ("
. join( ",", values(%$fields) )
. ")" );
unless ($tmp) {
$self->logError;
return UNKNOWN_ERROR;
}
2009-12-15 17:31:13 +01:00
eval { $self->dbh->do("COMMIT"); };
return $fields->{cfgNum};
}
sub load {
my ( $self, $cfgNum, $fields ) = @_;
2007-03-23 21:28:28 +01:00
$fields = $fields ? join( ",", @$fields ) : '*';
my $row = $self->_dbh->selectrow_hashref(
2013-07-12 09:58:46 +02:00
"SELECT $fields from " . $self->{dbiTable} . " WHERE cfgNum=?",
{}, $cfgNum );
unless ($row) {
$self->logError;
return 0;
}
return $self->unserialize($row);
}
1;
__END__