2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-04 05:16:45 +00:00

93_DbLog: contrib 3.12.0

git-svn-id: https://svn.fhem.de/fhem/trunk@17269 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
nasseeder1 2018-09-04 15:40:16 +00:00
parent bda7b4fcef
commit 13dbe158de

View File

@ -16,7 +16,7 @@
############################################################################################################################################ ############################################################################################################################################
# Versions History done by DS_Starter & DeeSPe: # Versions History done by DS_Starter & DeeSPe:
# #
# 3.12.0 03.09.2018 corrected SVG-select (https://forum.fhem.de/index.php/topic,65860.msg815640.html#msg815640) # 3.12.0 04.09.2018 corrected SVG-select (https://forum.fhem.de/index.php/topic,65860.msg815640.html#msg815640)
# 3.11.0 02.09.2018 reduceLog, reduceLogNbl - optional "days newer than" part added # 3.11.0 02.09.2018 reduceLog, reduceLogNbl - optional "days newer than" part added
# 3.10.10 05.08.2018 commandref revised reducelogNbl # 3.10.10 05.08.2018 commandref revised reducelogNbl
# 3.10.9 23.06.2018 commandref added hint about special characters in passwords # 3.10.9 23.06.2018 commandref added hint about special characters in passwords
@ -2264,6 +2264,7 @@ sub DbLog_explode_datetime($%) {
@datetime = split(" ", $t); #Datum und Zeit auftrennen @datetime = split(" ", $t); #Datum und Zeit auftrennen
@date = split("-", $datetime[0]); @date = split("-", $datetime[0]);
@time = split(":", $datetime[1]) if ($datetime[1]); @time = split(":", $datetime[1]) if ($datetime[1]);
if ($date[0]) {$retv{year} = $date[0];} else {$retv{year} = $def{year};} if ($date[0]) {$retv{year} = $date[0];} else {$retv{year} = $def{year};}
if ($date[1]) {$retv{month} = $date[1];} else {$retv{month} = $def{month};} if ($date[1]) {$retv{month} = $date[1];} else {$retv{month} = $def{month};}
if ($date[2]) {$retv{day} = $date[2];} else {$retv{day} = $def{day};} if ($date[2]) {$retv{day} = $date[2];} else {$retv{day} = $def{day};}
@ -2546,7 +2547,14 @@ sub DbLog_Get($@) {
%to_datetime = DbLog_explode_datetime($to, DbLog_explode_datetime("2099-01-01 00:00:00", ())); %to_datetime = DbLog_explode_datetime($to, DbLog_explode_datetime("2099-01-01 00:00:00", ()));
$from = $from_datetime{datetime}; $from = $from_datetime{datetime};
$to = $to_datetime{datetime}; $to = $to_datetime{datetime};
# Log 1, Dumper(%to_datetime);
if($to =~ /(\d{4})-(\d{2})-(\d{2}) 23:59:59/) {
# 03.09.2018 : https://forum.fhem.de/index.php/topic,65860.msg815640.html#msg815640
$to =~ /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/;
my $tc = timelocal($6, $5, $4, $3, $2-1, $1-1900);
$tc++;
$to = strftime "%Y-%m-%d %H:%M:%S", localtime($tc);
}
my ($retval,$retvaldummy,$hour,$sql_timestamp, $sql_device, $sql_reading, $sql_value, $type, $event, $unit) = ""; my ($retval,$retvaldummy,$hour,$sql_timestamp, $sql_device, $sql_reading, $sql_value, $type, $event, $unit) = "";
my @ReturnArray; my @ReturnArray;
@ -2693,12 +2701,12 @@ sub DbLog_Get($@) {
$stm2 .= "AND READING LIKE '".$readings[$i]->[1]."' " if(($readings[$i]->[1] !~ m(^%$)) && ($readings[$i]->[1] =~ m(\%))); $stm2 .= "AND READING LIKE '".$readings[$i]->[1]."' " if(($readings[$i]->[1] !~ m(^%$)) && ($readings[$i]->[1] =~ m(\%)));
$stm2 .= "AND TIMESTAMP >= $sqlspec{from_timestamp} "; $stm2 .= "AND TIMESTAMP >= $sqlspec{from_timestamp} ";
$stm2 .= "AND TIMESTAMP <= $sqlspec{to_timestamp} "; # 03.09.2018 -> https://forum.fhem.de/index.php/topic,65860.msg815640.html#msg815640 $stm2 .= "AND TIMESTAMP <= $sqlspec{to_timestamp} "; # 03.09.2018 : https://forum.fhem.de/index.php/topic,65860.msg815640.html#msg815640
$stm2 .= "ORDER BY TIMESTAMP"; $stm2 .= "ORDER BY TIMESTAMP";
if($deltacalc) { if($deltacalc) {
$stmdelta .= "AND TIMESTAMP >= $sqlspec{from_timestamp} "; $stmdelta .= "AND TIMESTAMP >= $sqlspec{from_timestamp} ";
$stmdelta .= "AND TIMESTAMP <= $sqlspec{to_timestamp} "; # 03.09.2018 -> https://forum.fhem.de/index.php/topic,65860.msg815640.html#msg815640 $stmdelta .= "AND TIMESTAMP <= $sqlspec{to_timestamp} "; # 03.09.2018 : https://forum.fhem.de/index.php/topic,65860.msg815640.html#msg815640
$stmdelta .= "GROUP BY $sqlspec{order_by_hour} " if($deltacalc); $stmdelta .= "GROUP BY $sqlspec{order_by_hour} " if($deltacalc);
$stmdelta .= "ORDER BY TIMESTAMP"; $stmdelta .= "ORDER BY TIMESTAMP";
@ -2707,7 +2715,6 @@ sub DbLog_Get($@) {
$stm = $stm2; $stm = $stm2;
} }
Log3 $hash->{NAME}, 4, "Processing Statement: $stm"; Log3 $hash->{NAME}, 4, "Processing Statement: $stm";
my $sth= $dbh->prepare($stm) || my $sth= $dbh->prepare($stm) ||