mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-02 00:48:53 +00:00
93_DbLog: removed use of perl's 'switch' feature.
git-svn-id: https://svn.fhem.de/fhem/trunk@9352 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
a843959408
commit
0166d593eb
@ -1,5 +1,6 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||||
# Do not insert empty lines here, update check depends on it.
|
# Do not insert empty lines here, update check depends on it.
|
||||||
|
- change: 93_DbLog: removed use of perl's 'switch' feature.
|
||||||
- change: 93_DbLog: removed string length limitation for SQLITE.
|
- change: 93_DbLog: removed string length limitation for SQLITE.
|
||||||
- bugfix: 93_DbLog: fixed ploteditor bug when DbLogType=History.
|
- bugfix: 93_DbLog: fixed ploteditor bug when DbLogType=History.
|
||||||
- feature: 93_DbLog: added new setter 'reduceLog' to clean up database.
|
- feature: 93_DbLog: added new setter 'reduceLog' to clean up database.
|
||||||
|
@ -17,7 +17,6 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
use DBI;
|
use DBI;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
use feature qw/say switch/;
|
|
||||||
|
|
||||||
my %columns = ("DEVICE" => 64,
|
my %columns = ("DEVICE" => 64,
|
||||||
"TYPE" => 64,
|
"TYPE" => 64,
|
||||||
@ -1497,9 +1496,7 @@ sub DbLog_Set($@) {
|
|||||||
my $dbh = $hash->{DBH};
|
my $dbh = $hash->{DBH};
|
||||||
my $ret;
|
my $ret;
|
||||||
|
|
||||||
given ($a[1]) {
|
if ($a[1] eq 'reduceLog') {
|
||||||
|
|
||||||
when ('reduceLog') {
|
|
||||||
if (defined $a[2] && $a[2] =~ /^\d+$/) {
|
if (defined $a[2] && $a[2] =~ /^\d+$/) {
|
||||||
$ret = DbLog_reduceLog($hash,@a);
|
$ret = DbLog_reduceLog($hash,@a);
|
||||||
} else {
|
} else {
|
||||||
@ -1507,16 +1504,14 @@ sub DbLog_Set($@) {
|
|||||||
$ret = "reduceLog error, no <days> given.";
|
$ret = "reduceLog error, no <days> given.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elsif ($a[1] eq 'reopen') {
|
||||||
when ('reopen') {
|
|
||||||
Log3($name, 4, "DbLog $name: Reopen requested.");
|
Log3($name, 4, "DbLog $name: Reopen requested.");
|
||||||
$dbh->commit() if(! $dbh->{AutoCommit});
|
$dbh->commit() if(! $dbh->{AutoCommit});
|
||||||
$dbh->disconnect();
|
$dbh->disconnect();
|
||||||
DbLog_Connect($hash);
|
DbLog_Connect($hash);
|
||||||
$ret = "Reopen executed.";
|
$ret = "Reopen executed.";
|
||||||
}
|
}
|
||||||
|
elsif ($a[1] eq 'rereadcfg') {
|
||||||
when ('rereadcfg') {
|
|
||||||
Log3($name, 4, "DbLog $name: Rereadcfg requested.");
|
Log3($name, 4, "DbLog $name: Rereadcfg requested.");
|
||||||
$dbh->commit() if(! $dbh->{AutoCommit});
|
$dbh->commit() if(! $dbh->{AutoCommit});
|
||||||
$dbh->disconnect();
|
$dbh->disconnect();
|
||||||
@ -1525,37 +1520,29 @@ sub DbLog_Set($@) {
|
|||||||
DbLog_Connect($hash);
|
DbLog_Connect($hash);
|
||||||
$ret = "Rereadcfg executed.";
|
$ret = "Rereadcfg executed.";
|
||||||
}
|
}
|
||||||
|
elsif ($a[1] eq 'count') {
|
||||||
when ('count') {
|
|
||||||
Log3($name, 4, "DbLog $name: Records count requested.");
|
Log3($name, 4, "DbLog $name: Records count requested.");
|
||||||
my $c = $dbh->selectrow_array('SELECT count(*) FROM history');
|
my $c = $dbh->selectrow_array('SELECT count(*) FROM history');
|
||||||
readingsSingleUpdate($hash, 'countHistory', $c ,1);
|
readingsSingleUpdate($hash, 'countHistory', $c ,1);
|
||||||
$c = $dbh->selectrow_array('SELECT count(*) FROM current');
|
$c = $dbh->selectrow_array('SELECT count(*) FROM current');
|
||||||
readingsSingleUpdate($hash, 'countCurrent', $c ,1);
|
readingsSingleUpdate($hash, 'countCurrent', $c ,1);
|
||||||
}
|
}
|
||||||
|
elsif ($a[1] eq 'deleteOldDays') {
|
||||||
when ('deleteOldDays') {
|
|
||||||
Log3($name, 4, "DbLog $name: Deletion of old records requested.");
|
Log3($name, 4, "DbLog $name: Deletion of old records requested.");
|
||||||
my ($c, $cmd);
|
my ($c, $cmd);
|
||||||
my $dbModel = InternalVal($name, 'DBMODEL', 'unknown');
|
|
||||||
$cmd = "delete from history where TIMESTAMP < ";
|
$cmd = "delete from history where TIMESTAMP < ";
|
||||||
given ($dbModel) {
|
|
||||||
when ('SQLITE') { $cmd .= "datetime('now', '-$a[2] days')"; }
|
if ($hash->{DBMODEL} eq 'SQLITE') { $cmd = "datetime('now', '-$a[2] days')"; }
|
||||||
when ('MYSQL') { $cmd .= "DATE_SUB(CURDATE(),INTERVAL $a[2] DAY)"; }
|
elsif ($hash->{DBMODEL} eq 'MYSQL') { $cmd = "DATE_SUB(CURDATE(),INTERVAL $a[2] DAY)"; }
|
||||||
when ('POSTGRESQL') { $cmd .= "NOW() - INTERVAL '$a[2] DAY"; }
|
elsif ($hash->{DBMODEL} eq 'POSTGRESQL') { $cmd = "NOW() - INTERVAL '$a[2] DAY"; }
|
||||||
default {
|
else { $cmd = undef; $ret = 'Unknown database type. Maybe you can try userCommand anyway.'; }
|
||||||
$cmd = undef;
|
|
||||||
$ret = 'Unkwon database type. Maybe you can try userCommand anyway.';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(defined($cmd)) {
|
if(defined($cmd)) {
|
||||||
$c = $dbh->do($cmd);
|
$c = $dbh->do($cmd);
|
||||||
readingsSingleUpdate($hash, 'lastRowsDeleted', $c ,1);
|
readingsSingleUpdate($hash, 'lastRowsDeleted', $c ,1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elsif ($a[1] eq 'userCommand') {
|
||||||
when ('userCommand') {
|
|
||||||
Log3($name, 4, "DbLog $name: userCommand execution requested.");
|
Log3($name, 4, "DbLog $name: userCommand execution requested.");
|
||||||
my ($c, @cmd, $sql);
|
my ($c, @cmd, $sql);
|
||||||
@cmd = @a;
|
@cmd = @a;
|
||||||
@ -1565,10 +1552,7 @@ sub DbLog_Set($@) {
|
|||||||
$c = $dbh->selectrow_array($sql);
|
$c = $dbh->selectrow_array($sql);
|
||||||
readingsSingleUpdate($hash, 'userCommandResult', $c ,1);
|
readingsSingleUpdate($hash, 'userCommandResult', $c ,1);
|
||||||
}
|
}
|
||||||
|
else { $ret = $usage; }
|
||||||
default { $ret = $usage; }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user