From bd33a9c7406a5d5a0406971a1283e0e4c869a107 Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Mon, 11 Feb 2019 21:10:32 +0000 Subject: [PATCH] 93_DbRep: executeBeforeProc / executeAfterProc is now available for sqlCmd,sumValue, maxValue, minValue, diffValue, averageValue git-svn-id: https://svn.fhem.de/fhem/trunk@18563 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 3 ++ fhem/FHEM/93_DbRep.pm | 116 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 107 insertions(+), 12 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 868f0bc8f..65d0c84d4 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,8 @@ # 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: executeBeforeProc / executeAfterProc is now available + for sqlCmd,sumValue, maxValue, minValue, diffValue, + averageValue - changed: 98_WeekdayTimer: remove Twilight dependency - feature: 74_AMADautomagicflowset: add support for Android 9 Pie - feature: 88_HMCCU: New commands and bug fixes diff --git a/fhem/FHEM/93_DbRep.pm b/fhem/FHEM/93_DbRep.pm index 3c4005a61..611ad029e 100644 --- a/fhem/FHEM/93_DbRep.pm +++ b/fhem/FHEM/93_DbRep.pm @@ -57,6 +57,8 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch'; # Versions History intern our %DbRep_vNotesIntern = ( + "8.13.0" => "11.02.2019 executeBeforeProc / executeAfterProc for sumValue, maxValue, minValue, diffValue, averageValue ", + "8.12.0" => "10.02.2019 executeBeforeProc / executeAfterProc for sqlCmd ", "8.11.2" => "03.02.2019 fix no running tableCurrentFillup if database is closed ", "8.11.1" => "25.01.2019 fix sort of versionNotes ", "8.11.0" => "24.01.2019 command exportToFile or attribute \"expimpfile\" accepts option \"MAXLINES=\" ", @@ -135,6 +137,7 @@ our %DbRep_vNotesIntern = ( # Versions History extern: our %DbRep_vNotesExtern = ( + "8.13.0" => "11.02.2019 executeBeforeProc / executeAfterProc is now available for sqlCmd,sumValue, maxValue, minValue, diffValue, averageValue ", "8.11.0" => "24.01.2019 command exportToFile or attribute \"expimpfile\" accepts option \"MAXLINES=\" ", "8.10.0" => "19.01.2019 In commands sqlCmd, dbValue you may now use SQL session variables like \"SET \@open:=NULL,\@closed:=NULL; SELECT ...\", Forum:#96082", "8.9.0" => "07.11.2018 new command set delDoublets added. This command allows to delete multiple occuring identical records. ", @@ -670,6 +673,7 @@ sub DbRep_Set($@) { The \"reading\" to evaluate has to be a single reading and no list."; } } + DbRep_beforeproc($hash, "$hash->{LASTCMD}"); DbRep_Main($hash,$opt,$prop); } elsif ($opt =~ m/delEntries|tableCurrentPurge/ && $hash->{ROLE} ne "Agent") { @@ -796,6 +800,7 @@ sub DbRep_Set($@) { if ($sqlcmd =~ m/^\s*delete/is && !AttrVal($hash->{NAME}, "allowDeletion", undef)) { return "Attribute 'allowDeletion = 1' is needed for command '$sqlcmd'. Use it with care !"; } + DbRep_beforeproc($hash, "sqlCmd"); DbRep_Main($hash,$opt,$sqlcmd); } elsif ($opt =~ /changeValue/) { @@ -2580,6 +2585,10 @@ sub averval_ParseDone($) { my $err = $a[5]?decode_base64($a[5]):undef; my $irowdone = $a[6]; my $reading_runtime_string; + my $erread; + + # Befehl nach Procedure ausführen + $erread = DbRep_afterproc($hash, "$hash->{LASTCMD}"); if ($err) { ReadingsSingleUpdateValue ($hash, "errortext", $err, 1); @@ -2601,6 +2610,7 @@ sub averval_ParseDone($) { } # Readingaufbereitung + my $state = $erread?$erread:"done"; readingsBeginUpdate($hash); my @arr = split("\\|", $arrstr); @@ -2625,7 +2635,7 @@ sub averval_ParseDone($) { } ReadingsBulkUpdateValue ($hash, "db_lines_processed", $irowdone) if($hash->{LASTCMD} =~ /writeToDB/); - ReadingsBulkUpdateTimeState($hash,$brt,$rt,"done"); + ReadingsBulkUpdateTimeState($hash,$brt,$rt,$state); readingsEndUpdate($hash, 1); delete($hash->{HELPER}{RUNNING_PID}); @@ -2987,6 +2997,10 @@ sub maxval_ParseDone($) { my $err = $a[5]?decode_base64($a[5]):undef; my $irowdone = $a[6]; my $reading_runtime_string; + my $erread; + + # Befehl nach Procedure ausführen + $erread = DbRep_afterproc($hash, "$hash->{LASTCMD}"); if ($err) { ReadingsSingleUpdateValue ($hash, "errortext", $err, 1); @@ -3003,6 +3017,7 @@ sub maxval_ParseDone($) { } # Readingaufbereitung + my $state = $erread?$erread:"done"; readingsBeginUpdate($hash); # only for this block because of warnings if details of readings are not set @@ -3025,7 +3040,7 @@ sub maxval_ParseDone($) { } ReadingsBulkUpdateValue ($hash, "db_lines_processed", $irowdone) if($hash->{LASTCMD} =~ /writeToDB/); - ReadingsBulkUpdateTimeState($hash,$brt,$rt,"done"); + ReadingsBulkUpdateTimeState($hash,$brt,$rt,$state); readingsEndUpdate($hash, 1); delete($hash->{HELPER}{RUNNING_PID}); @@ -3216,6 +3231,10 @@ sub minval_ParseDone($) { my $err = $a[5]?decode_base64($a[5]):undef; my $irowdone = $a[6]; my $reading_runtime_string; + my $erread; + + # Befehl nach Procedure ausführen + $erread = DbRep_afterproc($hash, "$hash->{LASTCMD}"); if ($err) { ReadingsSingleUpdateValue ($hash, "errortext", $err, 1); @@ -3232,6 +3251,7 @@ sub minval_ParseDone($) { } # Readingaufbereitung + my $state = $erread?$erread:"done"; readingsBeginUpdate($hash); # only for this block because of warnings if details of readings are not set @@ -3254,7 +3274,7 @@ sub minval_ParseDone($) { } ReadingsBulkUpdateValue ($hash, "db_lines_processed", $irowdone) if($hash->{LASTCMD} =~ /writeToDB/); - ReadingsBulkUpdateTimeState($hash,$brt,$rt,"done"); + ReadingsBulkUpdateTimeState($hash,$brt,$rt,$state); readingsEndUpdate($hash, 1); delete($hash->{HELPER}{RUNNING_PID}); @@ -3552,8 +3572,12 @@ sub diffval_ParseDone($) { my $irowdone = $a[8]; my $reading_runtime_string; my $difflimit = AttrVal($name, "diffAccept", "20"); # legt fest, bis zu welchem Wert Differenzen akzeptoert werden (Ausreißer eliminieren)AttrVal($name, "diffAccept", "20"); + my $erread; - if ($err) { + # Befehl nach Procedure ausführen + $erread = DbRep_afterproc($hash, "$hash->{LASTCMD}"); + + if ($err) { ReadingsSingleUpdateValue ($hash, "errortext", $err, 1); ReadingsSingleUpdateValue ($hash, "state", "error", 1); delete($hash->{HELPER}{RUNNING_PID}); @@ -3585,6 +3609,7 @@ sub diffval_ParseDone($) { Log3 ($name, 4, "DbRep $name - runtimestring Key: $key, value: ".$rh{$key}); } + my $state = $erread?$erread:"done"; readingsBeginUpdate($hash); foreach my $key (sort(keys(%rh))) { @@ -3608,7 +3633,7 @@ sub diffval_ParseDone($) { ReadingsBulkUpdateValue ($hash, "db_lines_processed", $irowdone) if($hash->{LASTCMD} =~ /writeToDB/); ReadingsBulkUpdateValue ($hash, "diff_overrun_limit_".$difflimit, $rowsrej) if($rowsrej); ReadingsBulkUpdateValue ($hash, "less_data_in_period", $ncpstr) if($ncpstr); - ReadingsBulkUpdateTimeState($hash,$brt,$rt,($ncpstr||$rowsrej)?"Warning":"done"); + ReadingsBulkUpdateTimeState($hash,$brt,$rt,($ncpstr||$rowsrej)?"Warning":$state); readingsEndUpdate($hash, 1); @@ -3752,6 +3777,10 @@ sub sumval_ParseDone($) { my $err = $a[5]?decode_base64($a[5]):undef; my $irowdone = $a[6]; my $reading_runtime_string; + my $erread; + + # Befehl nach Procedure ausführen + $erread = DbRep_afterproc($hash, "$hash->{LASTCMD}"); if ($err) { ReadingsSingleUpdateValue ($hash, "errortext", $err, 1); @@ -3764,6 +3793,7 @@ sub sumval_ParseDone($) { no warnings 'uninitialized'; # Readingaufbereitung + my $state = $erread?$erread:"done"; readingsBeginUpdate($hash); my @arr = split("\\|", $arrstr); @@ -3785,7 +3815,7 @@ sub sumval_ParseDone($) { } ReadingsBulkUpdateValue ($hash, "db_lines_processed", $irowdone) if($hash->{LASTCMD} =~ /writeToDB/); - ReadingsBulkUpdateTimeState($hash,$brt,$rt,"done"); + ReadingsBulkUpdateTimeState($hash,$brt,$rt,$state); readingsEndUpdate($hash, 1); delete($hash->{HELPER}{RUNNING_PID}); @@ -5715,6 +5745,10 @@ sub sqlCmd_ParseDone($) { my $err = $a[6]?decode_base64($a[6]):undef; my $srf = AttrVal($name, "sqlResultFormat", "separated"); my $srs = AttrVal($name, "sqlResultFieldSep", "|"); + my $erread; + + # Befehl nach Procedure ausführen + $erread = DbRep_afterproc($hash, "sqlCmd"); if ($err) { ReadingsSingleUpdateValue ($hash, "errortext", $err, 1); @@ -5728,6 +5762,7 @@ sub sqlCmd_ParseDone($) { no warnings 'uninitialized'; # Readingaufbereitung + my $state = $erread?$erread:"done"; readingsBeginUpdate($hash); ReadingsBulkUpdateValue ($hash, "sqlCmd", $cmd); @@ -5807,7 +5842,7 @@ sub sqlCmd_ParseDone($) { ReadingsBulkUpdateValue ($hash, "SqlResult", $json); } - ReadingsBulkUpdateTimeState($hash,$brt,$rt,"done"); + ReadingsBulkUpdateTimeState($hash,$brt,$rt,$state); readingsEndUpdate($hash, 1); delete($hash->{HELPER}{RUNNING_PID}); @@ -10425,6 +10460,8 @@ return; averageCalcForm : choose the calculation variant for average determination device : include or exclude <device> from selection + executeBeforeProc : execution of FHEM command (or perl-routine) before operation + executeAfterProc : execution of FHEM command (or perl-routine) after operation reading : include or exclude <reading> from selection time.* : a number of attributes to limit selection by time valueFilter : an additional REGEXP to control the record selection. The REGEXP is applied to the database field 'VALUE'. @@ -10778,6 +10815,8 @@ return; aggregation : choose the aggregation period diffAccept : the maximum accepted difference between sequential records device : include or exclude <device> from selection + executeBeforeProc : execution of FHEM command (or perl-routine) before operation + executeAfterProc : execution of FHEM command (or perl-routine) after operation reading : include or exclude <reading> from selection readingNameMap : rename the resulted reading name time.* : a number of attributes to limit selection by time @@ -11185,6 +11224,8 @@ return; aggregation : choose the aggregation period device : include or exclude <device> from selection + executeBeforeProc : execution of FHEM command (or perl-routine) before operation + executeAfterProc : execution of FHEM command (or perl-routine) after operation reading : include or exclude <reading> from selection readingNameMap : rename the resulted readings time.* : a number of attributes to limit selection by time @@ -11225,6 +11266,8 @@ return; aggregation : choose the aggregation period device : include or exclude <device> from selection + executeBeforeProc : execution of FHEM command (or perl-routine) before operation + executeAfterProc : execution of FHEM command (or perl-routine) after operation reading : include or exclude <reading> from selection readingNameMap : rename the resulted readings time.* : a number of attributes to limit selection by time @@ -11471,6 +11514,8 @@ return; + + @@ -11492,7 +11537,22 @@ return; successfully executed sqlCmd-command can be repeated from a drop-down list.
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.
+ list due to technical restrictions.

+ + For a better overview the relevant attributes for this command are listed in a table:

+ +
allowDeletion : activates capabilty to delete datasets
executeBeforeProc : execution of FHEM command (or perl-routine) before operation
executeAfterProc : execution of FHEM command (or perl-routine) after operation
sqlResultFormat : determines presentation style of command result
sqlResultFieldSep : choice of a useful field separator for result
sqlCmdHistoryLength : activates command history and length
+ + + + + + +
allowDeletion : activates capabilty to delete datasets
executeBeforeProc : execution of FHEM command (or perl-routine) before operation
executeAfterProc : execution of FHEM command (or perl-routine) after operation
sqlResultFormat : determines presentation style of command result
sqlResultFieldSep : choice of a useful field separator for result
+ +
+

  • sqlSpecial - This function provides a drop-down list with a selection of prepared reportings.
    @@ -11505,6 +11565,8 @@ return; +
    +
    +

  • sqlSpecial - Die Funktion bietet eine Drop-Downliste mit einer Auswahl vorbereiter Auswertungen @@ -13851,6 +13940,8 @@ sub bdump {