diff --git a/fhem/CHANGED b/fhem/CHANGED
index dcd10558a..40f85049e 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -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.
+ - feature: 93_DbRep: V7.15.0, new command sqlSpecial
- bugfix: 74_XiaomiBTLSens: fix commandref entrys
- feature: 49_SSCam: V3.5.0, new get command listPresets
- change: 93_DbRep: V7.14.8, exportToFile,importFromFile can use file as an
diff --git a/fhem/FHEM/93_DbRep.pm b/fhem/FHEM/93_DbRep.pm
index feb205864..7e4e6149a 100644
--- a/fhem/FHEM/93_DbRep.pm
+++ b/fhem/FHEM/93_DbRep.pm
@@ -37,6 +37,7 @@
###########################################################################################################################
# Versions History:
#
+# 7.15.0 24.03.2018 new command sqlSpecial
# 7.14.8 21.03.2018 fix no save into database if value=0 (DbRep_OutputWriteToDB)
# 7.14.7 21.03.2018 exportToFile,importFromFile can use file as an argument and executeBeforeDump,
# executeAfterDump is considered
@@ -331,7 +332,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch';
sub DbRep_Main($$;$);
sub DbLog_cutCol($$$$$$$); # DbLog-Funktion nutzen um Daten auf maximale Länge beschneiden
-my $DbRepVersion = "7.14.8";
+my $DbRepVersion = "7.15.0";
my %dbrep_col = ("DEVICE" => 64,
"TYPE" => 64,
@@ -512,6 +513,7 @@ sub DbRep_Set($@) {
(($hash->{ROLE} ne "Agent")?"insert ":"").
(($hash->{ROLE} ne "Agent")?"sqlCmd ":"").
(($hash->{ROLE} ne "Agent" && $hl)?"sqlCmdHistory:".$hl." ":"").
+ (($hash->{ROLE} ne "Agent")?"sqlSpecial:50mostFreqLogsLast2days,allDevCount,allDevReadCount ":"").
(($hash->{ROLE} ne "Agent")?"syncStandby ":"").
(($hash->{ROLE} ne "Agent")?"tableCurrentFillup:noArg ":"").
(($hash->{ROLE} ne "Agent")?"tableCurrentPurge:noArg ":"").
@@ -772,10 +774,13 @@ sub DbRep_Set($@) {
}
DbRep_Main($hash,$opt,$f);
- } elsif ($opt =~ /sqlCmd|sqlCmdHistory/) {
+ } elsif ($opt =~ /sqlCmd|sqlSpecial|sqlCmdHistory/) {
return "\"set $opt\" needs at least an argument" if ( @a < 3 );
# remove arg 0, 1 to get SQL command
my $sqlcmd;
+ if($opt eq "sqlSpecial") {
+ $sqlcmd = $prop;
+ }
if($opt eq "sqlCmd") {
shift @a;
shift @a;
@@ -1552,8 +1557,19 @@ sub DbRep_Main($$;$) {
} elsif ($opt =~ /changeValue/) {
$hash->{HELPER}{RUNNING_PID} = BlockingCall("changeval_Push", "$name§$device§$reading§$runtime_string_first§$runtime_string_next§$ts", "change_Done", $to, "DbRep_ParseAborted", $hash);
- } elsif ($opt =~ /sqlCmd/ ) {
- # Execute a generic sql command
+ } elsif ($opt =~ /sqlCmd|sqlSpecial/ ) {
+ # Execute a generic sql command or special sql
+ if ($opt =~ /sqlSpecial/) {
+ if($prop eq "50mostFreqLogsLast2days") {
+ $prop = "select Device, reading, count(0) AS `countA` from history where ( TIMESTAMP > (now() - interval 2 day)) group by DEVICE, READING order by countA desc, DEVICE limit 50;" if($dbmodel =~ /MYSQL/);
+ $prop = "select Device, reading, count(0) AS `countA` from history where ( TIMESTAMP > ('now' - '2 days')) group by DEVICE, READING order by countA desc, DEVICE limit 50;" if($dbmodel =~ /SQLITE/);
+ $prop = "select Device, reading, count(0) AS countA from history where ( TIMESTAMP > (NOW() - INTERVAL '2' DAY)) group by DEVICE, READING order by countA desc, DEVICE limit 50;" if($dbmodel =~ /POSTGRESQL/);
+ } elsif ($prop eq "allDevReadCount") {
+ $prop = "select device, reading, count(*) from history group by DEVICE, READING;";
+ } elsif ($prop eq "allDevCount") {
+ $prop = "select device, count(*) from history group by DEVICE;";
+ }
+ }
$hash->{HELPER}{RUNNING_PID} = BlockingCall("sqlCmd_DoParse", "$name|$opt|$runtime_string_first|$runtime_string_next|$prop", "sqlCmd_ParseDone", $to, "DbRep_ParseAborted", $hash);
} elsif ($opt =~ /syncStandby/ ) {
@@ -9631,7 +9647,35 @@ return;
By execution of the last list entry, "__purge_historylist__", the list itself can be deleted.
If the statement contains "," this character is displayed as "<c>" in the history
list due to technical restrictions.
-
+
+
+
sqlSpecial - This function provides a drop-down list with a selection of prepared reportings.
+ The statements result is depicted in reading "SqlResult".
+ The result can be formatted by attribute "sqlResultFormat",
+ a well as the used field separator by attribute "sqlResultFieldSep".
+
+
+ The relevant attributes for this function are:
+
+
+
+ sqlResultFormat | : determines the formatting of the result |
+ sqlResultFieldSep | : determines the used field separator in statement result |
+
+
+
+
+ The following predefined reportings are selectable:
+
+
+
+ 50mostFreqLogsLast2days | : reports the 50 most occuring log entries of the last 2 days |
+ allDevCount | : all devices occuring in database and their quantity |
+ allDevReadCount | : all device/reading combinations occuring in database and their quantity |
+
+
+
+
sumValue [display | writeToDB]
- calculates the summary of database column "VALUE" between period given by
@@ -10136,7 +10180,7 @@ sub bdump {
- activates the command history of "sqlCmd" and determines the length of it
- sqlResultFieldSep - determines the used field separator (default: "|") in the result of command "set <name> sqlCmd".
+ sqlResultFieldSep - determines the used field separator (default: "|") in the result of some sql-commands.
sqlResultFormat - determines the formatting of the "set <name> sqlCmd" command result.
Possible options are:
@@ -11322,6 +11366,35 @@ sub bdump {
Falls das Statement "," enthält, wird dieses Zeichen aus technischen Gründen in der
History-Liste als "<c>" dargestellt.
+
+ sqlSpecial - Die Funktion bietet eine Drop-Downliste mit einer Auswahl vorbereiter Auswertungen
+ an.
+ Das Ergebnis des Statements wird im Reading "SqlResult" dargestellt.
+ Die Ergebnis-Formatierung kann durch das Attribut "sqlResultFormat"
+ ausgewählt, sowie der verwendete Feldtrenner durch das Attribut
+ "sqlResultFieldSep" festgelegt werden.
+
+ Die für diese Funktion relevanten Attribute sind:
+
+
+
+ sqlResultFormat | : Optionen der Ergebnisformatierung |
+ sqlResultFieldSep | : Auswahl des Trennzeichens zwischen Ergebnisfeldern |
+
+
+
+
+ Es sind die folgenden vordefinierte Auswertungen auswählbar:
+
+
+
+ 50mostFreqLogsLast2days | : ermittelt die 50 am häufigsten vorkommenden Loggingeinträge der letzten 2 Tage |
+ allDevCount | : alle in der Datenbank vorkommenden Devices und deren Anzahl |
+ allDevReadCount | : alle in der Datenbank vorkommenden Device/Reading-Kombinationen und deren Anzahl |
+
+
+
+
sumValue [display | writeToDB]
- Berechnet die Summenwerte des Datenbankfelds "VALUE" in den Zeitgrenzen