mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-07 16:59:18 +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.
|
||||
# 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.
|
||||
- bugfix: 93_DbLog: fixed ploteditor bug when DbLogType=History.
|
||||
- feature: 93_DbLog: added new setter 'reduceLog' to clean up database.
|
||||
|
@ -17,7 +17,6 @@ use strict;
|
||||
use warnings;
|
||||
use DBI;
|
||||
use Data::Dumper;
|
||||
use feature qw/say switch/;
|
||||
|
||||
my %columns = ("DEVICE" => 64,
|
||||
"TYPE" => 64,
|
||||
@ -1497,9 +1496,7 @@ sub DbLog_Set($@) {
|
||||
my $dbh = $hash->{DBH};
|
||||
my $ret;
|
||||
|
||||
given ($a[1]) {
|
||||
|
||||
when ('reduceLog') {
|
||||
if ($a[1] eq 'reduceLog') {
|
||||
if (defined $a[2] && $a[2] =~ /^\d+$/) {
|
||||
$ret = DbLog_reduceLog($hash,@a);
|
||||
} else {
|
||||
@ -1507,16 +1504,14 @@ sub DbLog_Set($@) {
|
||||
$ret = "reduceLog error, no <days> given.";
|
||||
}
|
||||
}
|
||||
|
||||
when ('reopen') {
|
||||
elsif ($a[1] eq 'reopen') {
|
||||
Log3($name, 4, "DbLog $name: Reopen requested.");
|
||||
$dbh->commit() if(! $dbh->{AutoCommit});
|
||||
$dbh->disconnect();
|
||||
DbLog_Connect($hash);
|
||||
$ret = "Reopen executed.";
|
||||
}
|
||||
|
||||
when ('rereadcfg') {
|
||||
elsif ($a[1] eq 'rereadcfg') {
|
||||
Log3($name, 4, "DbLog $name: Rereadcfg requested.");
|
||||
$dbh->commit() if(! $dbh->{AutoCommit});
|
||||
$dbh->disconnect();
|
||||
@ -1525,37 +1520,29 @@ sub DbLog_Set($@) {
|
||||
DbLog_Connect($hash);
|
||||
$ret = "Rereadcfg executed.";
|
||||
}
|
||||
|
||||
when ('count') {
|
||||
elsif ($a[1] eq 'count') {
|
||||
Log3($name, 4, "DbLog $name: Records count requested.");
|
||||
my $c = $dbh->selectrow_array('SELECT count(*) FROM history');
|
||||
readingsSingleUpdate($hash, 'countHistory', $c ,1);
|
||||
$c = $dbh->selectrow_array('SELECT count(*) FROM current');
|
||||
readingsSingleUpdate($hash, 'countCurrent', $c ,1);
|
||||
}
|
||||
|
||||
when ('deleteOldDays') {
|
||||
elsif ($a[1] eq 'deleteOldDays') {
|
||||
Log3($name, 4, "DbLog $name: Deletion of old records requested.");
|
||||
my ($c, $cmd);
|
||||
my $dbModel = InternalVal($name, 'DBMODEL', 'unknown');
|
||||
$cmd = "delete from history where TIMESTAMP < ";
|
||||
given ($dbModel) {
|
||||
when ('SQLITE') { $cmd .= "datetime('now', '-$a[2] days')"; }
|
||||
when ('MYSQL') { $cmd .= "DATE_SUB(CURDATE(),INTERVAL $a[2] DAY)"; }
|
||||
when ('POSTGRESQL') { $cmd .= "NOW() - INTERVAL '$a[2] DAY"; }
|
||||
default {
|
||||
$cmd = undef;
|
||||
$ret = 'Unkwon database type. Maybe you can try userCommand anyway.';
|
||||
}
|
||||
}
|
||||
|
||||
if ($hash->{DBMODEL} eq 'SQLITE') { $cmd = "datetime('now', '-$a[2] days')"; }
|
||||
elsif ($hash->{DBMODEL} eq 'MYSQL') { $cmd = "DATE_SUB(CURDATE(),INTERVAL $a[2] DAY)"; }
|
||||
elsif ($hash->{DBMODEL} eq 'POSTGRESQL') { $cmd = "NOW() - INTERVAL '$a[2] DAY"; }
|
||||
else { $cmd = undef; $ret = 'Unknown database type. Maybe you can try userCommand anyway.'; }
|
||||
|
||||
if(defined($cmd)) {
|
||||
$c = $dbh->do($cmd);
|
||||
readingsSingleUpdate($hash, 'lastRowsDeleted', $c ,1);
|
||||
}
|
||||
}
|
||||
|
||||
when ('userCommand') {
|
||||
elsif ($a[1] eq 'userCommand') {
|
||||
Log3($name, 4, "DbLog $name: userCommand execution requested.");
|
||||
my ($c, @cmd, $sql);
|
||||
@cmd = @a;
|
||||
@ -1565,10 +1552,7 @@ sub DbLog_Set($@) {
|
||||
$c = $dbh->selectrow_array($sql);
|
||||
readingsSingleUpdate($hash, 'userCommandResult', $c ,1);
|
||||
}
|
||||
|
||||
default { $ret = $usage; }
|
||||
|
||||
}
|
||||
else { $ret = $usage; }
|
||||
|
||||
return $ret;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user