From b75a1f60851477b9fcec13079aa2f073007e41cc Mon Sep 17 00:00:00 2001 From: DS_Starter Date: Fri, 27 Sep 2019 06:51:37 +0000 Subject: [PATCH] 93_DbRep: contrib 8.27.2 git-svn-id: https://svn.fhem.de/fhem/trunk@20256 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/DS_Starter/93_DbRep.pm | 230 ++++++++++++++-------------- 1 file changed, 116 insertions(+), 114 deletions(-) diff --git a/fhem/contrib/DS_Starter/93_DbRep.pm b/fhem/contrib/DS_Starter/93_DbRep.pm index 7cb7da2b9..ede85748c 100644 --- a/fhem/contrib/DS_Starter/93_DbRep.pm +++ b/fhem/contrib/DS_Starter/93_DbRep.pm @@ -1,5 +1,5 @@ ########################################################################################################## -# $Id: 93_DbRep.pm 20074 2019-08-27 21:39:26Z DS_Starter $ +# $Id: 93_DbRep.pm 20228 2019-09-22 13:55:54Z DS_Starter $ ########################################################################################################## # 93_DbRep.pm # @@ -58,6 +58,9 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch'; # Version History intern our %DbRep_vNotesIntern = ( + "8.27.2" => "26.09.2019 fix log of export data to file ", + "8.27.1" => "22.09.2019 comma are shown in sqlCmdHistory, Forum: #103908 ", + "8.27.0" => "15.09.2019 save memory usage by eliminating \$hash -> {dbloghash}, fix warning uninitialized value \$idevice in split ", "8.26.0" => "07.09.2019 make SQL Wildcard (\%) possible as placeholder in a reading list: https://forum.fhem.de/index.php/topic,101756.0.html ". "sub DbRep_createUpdateSql deleted, new sub DbRep_createCommonSql ", "8.25.0" => "01.09.2019 make SQL Wildcard (\%) possible as placeholder in a device list: https://forum.fhem.de/index.php/topic,101756.0.html ". @@ -477,8 +480,8 @@ sub DbRep_Set($@) { my $prop1 = $a[3]; my $dbh = $hash->{DBH}; my $dblogdevice = $hash->{HELPER}{DBLOGDEVICE}; - $hash->{dbloghash} = $defs{$dblogdevice}; - my $dbmodel = $hash->{dbloghash}{MODEL}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; + my $dbmodel = $dbloghash->{MODEL}; my $dbname = $hash->{DATABASE}; my $sd =""; @@ -590,7 +593,6 @@ sub DbRep_Set($@) { Log3 ($name, 3, "DbRep $name - ################################################################"); Log3 ($name, 3, "DbRep $name - start repair attempt of database ".$hash->{DATABASE}); # closetime Datenbank - my $dbloghash = $hash->{dbloghash}; my $dbl = $dbloghash->{NAME}; CommandSet(undef,"$dbl reopen $prop"); @@ -710,8 +712,8 @@ sub DbRep_Set($@) { ####################################################################################################### ## keine Aktionen außer die über diesem Eintrag solange Reopen xxxx im DbLog-Device läuft ####################################################################################################### - if ($hash->{dbloghash}{HELPER}{REOPEN_RUNS} && $opt !~ /\?/) { - my $ro = $hash->{dbloghash}{HELPER}{REOPEN_RUNS_UNTIL}; + if ($dbloghash->{HELPER}{REOPEN_RUNS} && $opt !~ /\?/) { + my $ro = $dbloghash->{HELPER}{REOPEN_RUNS_UNTIL}; Log3 ($name, 3, "DbRep $name - connection $dblogdevice to db $dbname is closed until $ro - $opt postponed"); ReadingsSingleUpdateValue ($hash, "state", "connection $dblogdevice to $dbname is closed until $ro - $opt postponed", 1); return; @@ -855,7 +857,8 @@ sub DbRep_Set($@) { } if($opt eq "sqlCmdHistory") { $prop =~ tr/ A-Za-z0-9!"#$%&'()*+,-.\/:;<=>?@[\\]^_`{|}~äöüÄÖÜ߀/ /cs; - $prop =~ s//,/g; + $prop =~ s//,/g; # noch aus Kompatibilitätsgründen enthalten + $prop =~ s/(\x20)*\xbc/,/g; # Forum: https://forum.fhem.de/index.php/topic,103908.0.html $sqlcmd = $prop; if($sqlcmd eq "___purge_historylist___") { delete($hash->{HELPER}{SQLHIST}); @@ -921,15 +924,15 @@ return undef; sub DbRep_Get($@) { my ($hash, @a) = @_; return "\"get X\" needs at least an argument" if ( @a < 2 ); - my $name = $a[0]; - my $opt = $a[1]; - my $prop = $a[2]; - my $dbh = $hash->{DBH}; - my $dblogdevice = $hash->{HELPER}{DBLOGDEVICE}; - $hash->{dbloghash} = $defs{$dblogdevice}; - my $dbmodel = $hash->{dbloghash}{MODEL}; - my $dbname = $hash->{DATABASE}; - my $to = AttrVal($name, "timeout", "86400"); + my $name = $a[0]; + my $opt = $a[1]; + my $prop = $a[2]; + my $dbh = $hash->{DBH}; + my $dblogdevice = $hash->{HELPER}{DBLOGDEVICE}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; + my $dbmodel = $dbloghash->{MODEL}; + my $dbname = $hash->{DATABASE}; + my $to = AttrVal($name, "timeout", "86400"); my $getlist = "Unknown argument $opt, choose one of ". "svrinfo:noArg ". @@ -945,8 +948,8 @@ sub DbRep_Get($@) { return if(IsDisabled($name)); - if ($hash->{dbloghash}{HELPER}{REOPEN_RUNS} && $opt !~ /\?|procinfo|blockinginfo/) { - my $ro = $hash->{dbloghash}{HELPER}{REOPEN_RUNS_UNTIL}; + if ($dbloghash->{HELPER}{REOPEN_RUNS} && $opt !~ /\?|procinfo|blockinginfo/) { + my $ro = $dbloghash->{HELPER}{REOPEN_RUNS_UNTIL}; Log3 ($name, 3, "DbRep $name - connection $dblogdevice to db $dbname is closed until $ro - $opt postponed"); ReadingsSingleUpdateValue ($hash, "state", "connection $dblogdevice to $dbname is closed until $ro - $opt postponed", 1); return; @@ -1087,9 +1090,9 @@ return undef; ################################################################################### sub DbRep_Attr($$$$) { my ($cmd,$name,$aName,$aVal) = @_; - my $hash = $defs{$name}; - $hash->{dbloghash} = $defs{$hash->{HELPER}{DBLOGDEVICE}}; - my $dbmodel = $hash->{dbloghash}{MODEL}; + my $hash = $defs{$name}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; + my $dbmodel = $dbloghash->{MODEL}; my $do; # $cmd can be "del" or "set" @@ -1456,12 +1459,11 @@ return undef; sub DbRep_firstconnect(@) { my ($string) = @_; my ($name,$opt,$prop,$fret) = split("\\|", $string); - my $hash = $defs{$name}; - my $to = AttrVal($name, "timeout", "86400"); - $hash->{dbloghash} = $defs{$hash->{HELPER}{DBLOGDEVICE}}; - my $dbloghash = $hash->{dbloghash}; - my $dbconn = $dbloghash->{dbconn}; - my $dbuser = $dbloghash->{dbuser}; + my $hash = $defs{$name}; + my $to = AttrVal($name, "timeout", "86400"); + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; + my $dbconn = $dbloghash->{dbconn}; + my $dbuser = $dbloghash->{dbuser}; RemoveInternalTimer($hash, "DbRep_firstconnect"); return if(IsDisabled($name)); @@ -1498,7 +1500,7 @@ sub DbRep_getInitData($) { my ($string) = @_; my ($name,$opt,$prop,$fret) = split("\\|", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -1585,9 +1587,8 @@ sub DbRep_getInitDataDone($) { my $prop = $a[5]; my $fret = \&{$a[6]} if($a[6]); my $idxstate = $a[7]?decode_base64($a[7]):""; - my $dblogdevice = $hash->{HELPER}{DBLOGDEVICE}; - $hash->{dbloghash} = $defs{$dblogdevice}; - my $dbconn = $hash->{dbloghash}{dbconn}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; + my $dbconn = $dbloghash->{dbconn}; if ($err) { readingsBeginUpdate($hash); @@ -1642,14 +1643,12 @@ return; ################################################################################################################ sub DbRep_Main($$;$) { my ($hash,$opt,$prop) = @_; - my $name = $hash->{NAME}; - my $to = AttrVal($name, "timeout", "86400"); - my $reading = AttrVal($name, "reading", "%"); - my $device = AttrVal($name, "device", "%"); - my $dblogdevice = $hash->{HELPER}{DBLOGDEVICE}; - $hash->{dbloghash} = $defs{$dblogdevice}; - my $dbloghash = $hash->{dbloghash}; - my $dbmodel = $dbloghash->{MODEL}; + my $name = $hash->{NAME}; + my $to = AttrVal($name, "timeout", "86400"); + my $reading = AttrVal($name, "reading", "%"); + my $device = AttrVal($name, "device", "%"); + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; + my $dbmodel = $dbloghash->{MODEL}; # Entkommentieren für Testroutine im Vordergrund # testexit($hash); @@ -2475,7 +2474,7 @@ sub averval_DoParse($) { my ($string) = @_; my ($name,$device,$reading,$prop,$ts) = split("\\§", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -2828,7 +2827,7 @@ sub count_DoParse($) { my ($string) = @_; my ($name,$table,$device,$reading,$ts) = split("\\§", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -3003,7 +3002,7 @@ sub maxval_DoParse($) { my ($string) = @_; my ($name,$device,$reading,$prop,$ts) = split("\\§", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -3234,7 +3233,7 @@ sub minval_DoParse($) { my ($string) = @_; my ($name,$device,$reading,$prop,$ts) = split("\\§", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -3468,7 +3467,7 @@ sub diffval_DoParse($) { my ($string) = @_; my ($name,$device,$reading,$prop,$ts) = split("\\§", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -3828,7 +3827,7 @@ sub sumval_DoParse($) { my ($string) = @_; my ($name,$device,$reading,$prop,$ts) = split("\\§", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -4009,7 +4008,7 @@ sub del_DoParse($) { my ($string) = @_; my ($name,$table,$device,$reading,$runtime_string_first,$runtime_string_next) = split("\\|", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -4134,7 +4133,7 @@ return; sub insert_Push($) { my ($name) = @_; my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -4269,7 +4268,7 @@ sub currentfillup_Push($) { my ($string) = @_; my ($name,$device,$reading,$runtime_string_first,$runtime_string_next) = split("\\|", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -4424,7 +4423,7 @@ sub change_Push($) { my ($string) = @_; my ($name,$device,$reading,$runtime_string_first,$runtime_string_next) = split("\\|", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -4526,7 +4525,7 @@ sub changeval_Push($) { my ($string) = @_; my ($name,$device,$reading,$runtime_string_first,$runtime_string_next,$ts) = split("\\§", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -4657,7 +4656,7 @@ sub changeval_Push($) { $value = $VALUE if(defined $VALUE); $unit = $UNIT if(defined $UNIT); # Daten auf maximale Länge beschneiden (DbLog-Funktion !) - (undef,undef,undef,undef,$value,$unit) = DbLog_cutCol($hash->{dbloghash},"1","1","1","1",$value,$unit); + (undef,undef,undef,undef,$value,$unit) = DbLog_cutCol($dbloghash,"1","1","1","1",$value,$unit); $value =~ s/'/''/g; # escape ' with '' $unit =~ s/'/''/g; # escape ' with '' @@ -4772,7 +4771,7 @@ sub fetchrows_DoParse($) { my ($string) = @_; my ($name,$table,$device,$reading,$runtime_string_first,$runtime_string_next) = split("\\|", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -4973,7 +4972,7 @@ sub deldoublets_DoParse($) { my ($string) = @_; my ($name,$opt,$device,$reading,$ts) = split("\\§", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -5133,7 +5132,7 @@ sub delseqdoubl_DoParse($) { my ($string) = @_; my ($name,$opt,$device,$reading,$ts) = split("\\§", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -5381,7 +5380,7 @@ sub expfile_DoParse($) { my ($string) = @_; my ($name, $device, $reading, $rsf, $file, $ts) = split("\\§", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -5422,8 +5421,6 @@ sub expfile_DoParse($) { } } - Log3 ($name, 4, "DbRep $name - Export data to file: $file ".($ml?"splitted to parts of $ml lines":"") ); - $rsf =~ s/[:\s]/_/g; my ($f,$e) = split(/\./,$file); $e = $e?$e:""; @@ -5431,6 +5428,9 @@ sub expfile_DoParse($) { my @t = localtime; $f = ResolveDateWildcards($f, @t); my $outfile = $f.$part.$e; + + Log3 ($name, 4, "DbRep $name - Export data to file: $outfile ".($ml?"splitted to parts of $ml lines":"") ); + if (open(FH, ">", $outfile)) { binmode (FH); } else { @@ -5570,11 +5570,11 @@ sub impfile_Push($) { my ($string) = @_; my ($name, $rsf, $file) = split("\\|", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; - my $dbmodel = $hash->{dbloghash}{MODEL}; + my $dbmodel = $dbloghash->{MODEL}; my $dbpassword = $attr{"sec$dblogname"}{secret}; my $utf8 = defined($hash->{UTF8})?$hash->{UTF8}:0; my $err=0; @@ -5771,7 +5771,7 @@ sub sqlCmd_DoParse($) { my ($string) = @_; my ($name, $opt, $runtime_string_first, $runtime_string_next, $cmd) = split("\\|", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -5972,8 +5972,9 @@ sub sqlCmd_ParseDone($) { # Drop-Down Liste bisherige sqlCmd-Befehle füllen und in Key-File sichern # my $hl = $hash->{HELPER}{SQLHIST}; my @sqlhist = split(",",$hash->{HELPER}{SQLHIST}); - $cmd =~ s/\s/ /g; - $cmd =~ s/,//g; + $cmd =~ s/\s+/ /g; + $cmd =~ s/,/,/g; # Forum: https://forum.fhem.de/index.php/topic,103908.0.html + $cmd =~ s/, /,/g; my $hlc = AttrVal($name, "sqlCmdHistoryLength", 0); # Anzahl der Einträge in Drop-Down Liste if(!@sqlhist || (@sqlhist && !($cmd ~~ @sqlhist))) { unshift @sqlhist,$cmd; @@ -6060,7 +6061,7 @@ sub dbmeta_DoParse($) { my $name = $a[0]; my $hash = $defs{$name}; my $opt = $a[1]; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $db = $hash->{DATABASE}; my $dbuser = $dbloghash->{dbuser}; @@ -6320,7 +6321,7 @@ sub DbRep_Index($) { my ($string) = @_; my ($name,$cmdidx) = split("\\|", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $database = $hash->{DATABASE}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; @@ -6549,7 +6550,7 @@ return; sub DbRep_optimizeTables($) { my ($name) = @_; my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -6776,7 +6777,7 @@ return; sub mysql_DoDumpClientSide($) { my ($name) = @_; my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -7250,7 +7251,7 @@ return "$name|$rt|''|$dump_path$backupfile|$drc|$drh|$fsize|$ftp|$bfd|$ffd"; sub mysql_DoDumpServerSide($) { my ($name) = @_; my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -7425,7 +7426,7 @@ return "$name|$rt|''|$dump_path_rem$bfile|n.a.|$drh|$fsize|$ftp|$bfd|$ffd"; sub DbRep_sqliteDoDump($) { my ($name) = @_; my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbname = $hash->{DATABASE}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; @@ -7605,7 +7606,7 @@ return; sub DbRep_sqliteRepair($) { my ($name) = @_; my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $db = $hash->{DATABASE}; my $dbname = (split /[\/]/, $db)[-1]; my $dbpath = (split /$dbname/, $db)[0]; @@ -7675,7 +7676,7 @@ sub DbRep_RepairDone($) { my $hash = $defs{$a[0]}; my $brt = $a[1]; my $err = $a[2]?decode_base64($a[2]):undef; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $name = $hash->{NAME}; my $erread; @@ -7718,7 +7719,7 @@ sub DbRep_sqliteRestore ($) { my ($string) = @_; my ($name,$bfile) = split("\\|", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -7796,7 +7797,7 @@ sub mysql_RestoreServerSide($) { my ($string) = @_; my ($name, $bfile) = split("\\|", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -7870,7 +7871,7 @@ sub mysql_RestoreClientSide($) { my ($string) = @_; my ($name, $bfile) = split("\\|", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -8105,7 +8106,7 @@ sub DbRep_syncStandby($) { my $utf8 = defined($hash->{UTF8})?$hash->{UTF8}:0; my ($dbh,$dbhstby,$err,$sql,$irows,$irowdone); # Quell-DB - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -8260,7 +8261,7 @@ sub DbRep_reduceLog($) { my ($string) = @_; my ($name,$d,$r,$nts,$ots) = split("\\|", $string); my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -8617,7 +8618,7 @@ sub DbRep_reduceLogDone($) { my $ret = decode_base64($a[1]); my $err = decode_base64($a[2]) if ($a[2]); my $brt = $a[3]; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $erread; delete $hash->{HELPER}{RUNNING_REDUCELOG}; @@ -8795,7 +8796,7 @@ sub DbRep_RepairAborted(@) { my ($hash,$cause) = @_; my $name = $hash->{NAME}; my $dbh = $hash->{DBH}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $erread; $cause = $cause?$cause:"Timeout: process terminated"; @@ -8823,7 +8824,8 @@ return; sub DbRep_createCommonSql ($$$$$$$) { my ($hash,$selspec,$device,$reading,$tf,$tn,$addon) = @_; my $name = $hash->{NAME}; - my $dbmodel = $hash->{dbloghash}{MODEL}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; + my $dbmodel = $dbloghash->{MODEL}; my $valfilter = AttrVal($name, "valueFilter", undef); # Wertefilter my $tnfull = 0; my ($sql,$vf,@dwc,@rwc); @@ -8928,7 +8930,8 @@ return $sql; sub DbRep_createSelectSql($$$$$$$$) { my ($hash,$table,$selspec,$device,$reading,$tf,$tn,$addon) = @_; my $name = $hash->{NAME}; - my $dbmodel = $hash->{dbloghash}{MODEL}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; + my $dbmodel = $dbloghash->{MODEL}; my $valfilter = AttrVal($name, "valueFilter", undef); # Wertefilter my $tnfull = 0; my ($sql,$vf,@dwc,@rwc); @@ -9033,7 +9036,8 @@ return $sql; sub DbRep_createDeleteSql($$$$$$$) { my ($hash,$table,$device,$reading,$tf,$tn,$addon) = @_; my $name = $hash->{NAME}; - my $dbmodel = $hash->{dbloghash}{MODEL}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; + my $dbmodel = $dbloghash->{MODEL}; my $valfilter = AttrVal($name, "valueFilter", undef); # Wertefilter my $tnfull = 0; my ($sql,$vf,@dwc,@rwc); @@ -10031,7 +10035,7 @@ return (undef,$db_MB_start,$db_MB_end); sub DbRep_deldumpfiles ($$) { my ($hash,$bfile) = @_; my $name = $hash->{NAME}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dump_path_def = $attr{global}{modpath}."/log/"; my $dump_path_loc = AttrVal($name,"dumpDirLocal", $dump_path_def); $dump_path_loc = $dump_path_loc."/" unless($dump_path_loc =~ m/\/$/); @@ -10313,13 +10317,13 @@ return \%ncp; sub DbRep_OutputWriteToDB($$$$$) { my ($name,$device,$reading,$arrstr,$optxt) = @_; my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; - my $dbmodel = $hash->{dbloghash}{MODEL}; - my $DbLogType = AttrVal($hash->{dbloghash}{NAME}, "DbLogType", "History"); - my $supk = AttrVal($hash->{dbloghash}{NAME}, "noSupportPK", 0); + my $dbmodel = $dbloghash->{MODEL}; + my $DbLogType = AttrVal($dblogname, "DbLogType", "History"); + my $supk = AttrVal($dblogname, "noSupportPK", 0); my $dbpassword = $attr{"sec$dblogname"}{secret}; my $utf8 = defined($hash->{UTF8})?$hash->{UTF8}:0; $device =~ s/[^A-Za-z\/\d_\.-]/\//g; @@ -10331,7 +10335,7 @@ sub DbRep_OutputWriteToDB($$$$$) { my $irowdone = 0; my ($dbh,$sth_ih,$sth_uh,$sth_ic,$sth_uc,$err,$timestamp,$value,$date,$time,$rsf,$aggr,@row_array); - if(!$hash->{dbloghash}{HELPER}{COLSET}) { + if(!$dbloghash->{HELPER}{COLSET}) { $err = "No result of \"$hash->{LASTCMD}\" to database written. Cause: column width in \"$hash->{DEF}\" isn't set"; return ($wrt,$irowdone,$err); } @@ -10361,7 +10365,7 @@ sub DbRep_OutputWriteToDB($$$$$) { } if ($value) { # Daten auf maximale Länge beschneiden (DbLog-Funktion !) - ($device,$type,$event,$reading,$value,$unit) = DbLog_cutCol($hash->{dbloghash},$device,$type,$event,$reading,$value,$unit); + ($device,$type,$event,$reading,$value,$unit) = DbLog_cutCol($dbloghash,$device,$type,$event,$reading,$value,$unit); push(@row_array, "$date $time|$device|$type|$event|$reading|$value|$unit"); } } @@ -10385,7 +10389,7 @@ sub DbRep_OutputWriteToDB($$$$$) { } if ($value) { # Daten auf maximale Länge beschneiden (DbLog-Funktion !) - ($device,$type,$event,$reading,$value,$unit) = DbLog_cutCol($hash->{dbloghash},$device,$type,$event,$reading,$value,$unit); + ($device,$type,$event,$reading,$value,$unit) = DbLog_cutCol($dbloghash,$device,$type,$event,$reading,$value,$unit); push(@row_array, "$date $time|$device|$type|$event|$reading|$value|$unit"); } } @@ -10548,8 +10552,8 @@ sub DbRep_WriteToDB($$$@) { my ($name,$dbh,$dbloghash,$histupd,@row_array) = @_; my $hash = $defs{$name}; my $dblogname = $dbloghash->{NAME}; - my $DbLogType = AttrVal($dbloghash->{NAME}, "DbLogType", "History"); - my $supk = AttrVal($dbloghash->{NAME}, "noSupportPK", 0); + my $DbLogType = AttrVal($dblogname, "DbLogType", "History"); + my $supk = AttrVal($dblogname, "noSupportPK", 0); my $wrt = 0; my $irowdone = 0; my ($sth_ih,$sth_uh,$sth_ic,$sth_uc,$err); @@ -10691,10 +10695,10 @@ return ($wrt,$irowdone,$err); ################################################################ sub DbRep_checkUsePK ($$$){ my ($hash,$dbloghash,$dbh) = @_; - my $name = $hash->{NAME}; - my $dbconn = $dbloghash->{dbconn}; - my $upkh = 0; - my $upkc = 0; + my $name = $hash->{NAME}; + my $dbconn = $dbloghash->{dbconn}; + my $upkh = 0; + my $upkc = 0; my (@pkh,@pkc); my $db = (split("=",(split(";",$dbconn))[0]))[1]; @@ -10762,12 +10766,12 @@ sub DbRep_setVersionInfo($) { if($modules{$type}{META}{x_prereqs_src} && !$hash->{HELPER}{MODMETAABSENT}) { # META-Daten sind vorhanden $modules{$type}{META}{version} = "v".$v; # Version aus META.json überschreiben, Anzeige mit {Dumper $modules{SMAPortal}{META}} - if($modules{$type}{META}{x_version}) { # {x_version} ( nur gesetzt wenn $Id: 93_DbRep.pm 20074 2019-08-27 21:39:26Z DS_Starter $ im Kopf komplett! vorhanden ) + if($modules{$type}{META}{x_version}) { # {x_version} ( nur gesetzt wenn $Id: 93_DbRep.pm 20228 2019-09-22 13:55:54Z DS_Starter $ im Kopf komplett! vorhanden ) $modules{$type}{META}{x_version} =~ s/1.1.1/$v/g; } else { $modules{$type}{META}{x_version} = $v; } - return $@ unless (FHEM::Meta::SetInternals($hash)); # FVERSION wird gesetzt ( nur gesetzt wenn $Id: 93_DbRep.pm 20074 2019-08-27 21:39:26Z DS_Starter $ im Kopf komplett! vorhanden ) + return $@ unless (FHEM::Meta::SetInternals($hash)); # FVERSION wird gesetzt ( nur gesetzt wenn $Id: 93_DbRep.pm 20228 2019-09-22 13:55:54Z DS_Starter $ im Kopf komplett! vorhanden ) if(__PACKAGE__ eq "FHEM::$type" || __PACKAGE__ eq $type) { # es wird mit Packages gearbeitet -> Perl übliche Modulversion setzen # mit {->VERSION()} im FHEMWEB kann Modulversion abgefragt werden @@ -10788,7 +10792,7 @@ return; sub DbRep_dbValue($$) { my ($name,$cmd) = @_; my $hash = $defs{$name}; - my $dbloghash = $hash->{dbloghash}; + my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbconn = $dbloghash->{dbconn}; my $dbuser = $dbloghash->{dbuser}; my $dblogname = $dbloghash->{NAME}; @@ -10996,14 +11000,14 @@ sub DbRep_modAssociatedWith ($$$) { my ($hash,$cmd,$awdev) = @_; my $name = $hash->{NAME}; my (@naw,@edvs,@edvspcs,$edevswc); - my $edevs = ''; + my ($edevs,$idevice,$edevice) = ('','',''); if($cmd eq "del") { readingsDelete($hash,".associatedWith"); return; } - my ($idevice,$edevice) = split(/EXCLUDE=/i,$awdev); + ($idevice,$edevice) = split(/EXCLUDE=/i,$awdev); if($edevice) { @edvs = split(",",$edevice); @@ -11021,14 +11025,15 @@ sub DbRep_modAssociatedWith ($$$) { } } - my @nadev = split("[, ]", $idevice); - - foreach my $d (@nadev) { - $d =~ s/%/\.*/g if($d !~ /^%$/); # SQL Wildcard % in Regex - my @a = devspec2array($d); - foreach(@a) { - next if(!$defs{$_}); - push(@naw, $_) if($_ !~ /$edevs/); + if($idevice) { + my @nadev = split("[, ]", $idevice); + foreach my $d (@nadev) { + $d =~ s/%/\.*/g if($d !~ /^%$/); # SQL Wildcard % in Regex + my @a = devspec2array($d); + foreach(@a) { + next if(!$defs{$_}); + push(@naw, $_) if($_ !~ /$edevs/); + } } } @@ -12394,9 +12399,8 @@ return;
  • sqlCmdHistory - If history is activated by attribute "sqlCmdHistoryLength", an already 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.

    + By execution of the last list entry, "__purge_historylist__", the list itself can be + deleted.

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

    @@ -14833,7 +14837,7 @@ sub bdump { executeBeforeProc : FHEM Kommando (oder Perl-Routine) vor der Operation ausführen executeAfterProc : FHEM Kommando (oder Perl-Routine) nach der Operation ausführen allowDeletion : aktiviert Löschmöglichkeit - sqlResultFormat : legt die Darstellung des Kommandoergebnis fest + sqlResultFormat : legt die Darstellung des Kommandoergebnisses fest sqlResultFieldSep : Auswahl Feldtrenner im Ergebnis sqlCmdHistoryLength : Aktivierung Kommando-Historie und deren Umfang sqlCmdVars : setzt SQL Session Variablen oder PRAGMA vor jeder Ausführung des SQL-Statements @@ -14853,9 +14857,7 @@ sub bdump {
  • sqlCmdHistory - Wenn mit dem Attribut "sqlCmdHistoryLength" aktiviert, kann aus einer Liste ein bereits erfolgreich ausgeführtes sqlCmd-Kommando wiederholt werden.
    Mit Ausführung des letzten Eintrags der Liste, "__purge_historylist__", kann die Liste gelöscht - werden.
    - Falls das Statement "," enthält, wird dieses Zeichen aus technischen Gründen in der - History-Liste als "<c>" dargestellt.

    + werden.

    Zur besseren Übersicht sind die zur Steuerung dieser Funktion von relevanten Attribute hier noch einmal zusammenstellt: