| 1 | package Lemonldap::NG::Common::Conf::Backends::RDBI; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Lemonldap::NG::Common::Conf::Serializer; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Lemonldap::NG::Common::Conf::Backends::_DBI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | our $VERSION = '2.0.12'; | |||||||||
| 9 | 1 | our @ISA = qw(Lemonldap::NG::Common::Conf::Backends::_DBI); | |||||||||
| 10 | |||||||||||
| 11 | 3 | ▶ | sub store { | ||||||||
|
Subroutine
store: called CC=7 SCAR=21.6
Pod
undocumented
| |||||||||||
| 12 | 3 | my ( $self, $fields ) = @_; | |||||||||
| 13 | 3 | my $cfgNum = $fields->{cfgNum}; | |||||||||
| 14 | 3 | $self->{noQuotes} = 1; | |||||||||
| 15 | 3 | $fields = $self->serialize($fields); | |||||||||
| 16 | |||||||||||
| 17 | 3 | my $req; | |||||||||
| 18 | 3 | my $lastCfg = $self->lastCfg; | |||||||||
| 19 | 3 | $self->_dbh->begin_work; | |||||||||
| 20 | 3 | $req = $self->_dbh->prepare( | |||||||||
| 21 | "INSERT INTO $self->{dbiTable} (cfgNum,field,value) VALUES (?,?,?)"); | ||||||||||
| 22 | |||||||||||
| 23 | 3 | ▶ | _delete( $self, $cfgNum ) if $lastCfg == $cfgNum; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 3 | ▶ | unless ($req) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 0 | $self->logError; | |||||||||
| 26 | 0 | return UNKNOWN_ERROR; | |||||||||
| 27 | } | ||||||||||
| 28 | 3 | ▶ | while ( my ( $k, $v ) = each %$fields ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 6 | my @execValues = ( $cfgNum, $k, $v ); | |||||||||
| 30 | 6 | my $execute; | |||||||||
| 31 | 6 | eval { $execute = $req->execute(@execValues); }; | |||||||||
| 32 | 6 | ▶ | print STDERR $@ if $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 6 | ▶ | unless ($execute) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 0 | $self->logError; | |||||||||
| 35 | 0 | ▶ | _delete( $self, $cfgNum ) if $lastCfg != $cfgNum; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 0 | $self->_dbh->rollback; | |||||||||
| 37 | 0 | return UNKNOWN_ERROR; | |||||||||
| 38 | } | ||||||||||
| 39 | } | ||||||||||
| 40 | 3 | $self->_dbh->commit; | |||||||||
| 41 | 3 | return $cfgNum; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 3 | ▶ | sub load { | ||||||||
|
Subroutine
load: called CC=6 SCAR=19.1
Pod
undocumented
| |||||||||||
| 45 | 3 | my ( $self, $cfgNum, $fields ) = @_; | |||||||||
| 46 | 3 | ▶ | $fields = $fields ? join( ",", @$fields ) : '*'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | my $sth = | ||||||||||
| 48 | $self->_dbh->prepare( | ||||||||||
| 49 | 3 | ▶ | "SELECT field,value from " . $self->{dbiTable} . " WHERE cfgNum=?" ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | or $self->logError; | ||||||||||
| 51 | 3 | ▶ | $sth->execute($cfgNum) or $self->logError; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 3 | my ( $res, @row ); | |||||||||
| 53 | 3 | ▶ | while ( @row = $sth->fetchrow_array ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 6 | $res->{ $row[0] } = $row[1]; | |||||||||
| 55 | } | ||||||||||
| 56 | 3 | ▶ | unless ($res) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 0 | $Lemonldap::NG::Common::Conf::msg .= | |||||||||
| 58 | "No configuration $cfgNum found \n"; | ||||||||||
| 59 | 0 | return 0; | |||||||||
| 60 | } | ||||||||||
| 61 | 3 | $res->{cfgNum} = $cfgNum; | |||||||||
| 62 | 3 | return $self->unserialize($res); | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 0 | ▶ | sub _delete { | ||||||||
|
Subroutine
_delete: not called CC=1 SCAR=6.9
| |||||||||||
| 66 | 0 | my ( $self, $cfgNum ) = @_; | |||||||||
| 67 | 0 | my $r = | |||||||||
| 68 | $self->_dbh->prepare("DELETE FROM $self->{dbiTable} where cfgNum=?"); | ||||||||||
| 69 | 0 | $r->execute($cfgNum); | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 1 | 1; | |||||||||