93_DbRep: the the blocking executed commands are monitored with an adjustable timeout, get dbValue is deprecated and was changed to the command sqlCmdBlocking

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@22733 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
nasseeder1 2020-09-04 19:33:12 +00:00
parent d17f030cd0
commit a4e65e762a
2 changed files with 2985 additions and 2864 deletions

View File

@ -1,5 +1,9 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # 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. # Do not insert empty lines here, update check depends on it.
- change: 93_DbRep: the the blocking executed commands are monitored with an
adjustable timeout,
NOTE: get dbValue is deprecated and was changed to
the command sqlCmdBlocking
- bugfix: 73_AutoShuttersControl: fix bug in Sunrise Drive if SelfDefense set - bugfix: 73_AutoShuttersControl: fix bug in Sunrise Drive if SelfDefense set
- change: 50_TelegramBot: channels, versionid, keyboard / favorite fixes - change: 50_TelegramBot: channels, versionid, keyboard / favorite fixes
- change: 93_DbRep: commandRef revised - change: 93_DbRep: commandRef revised

View File

@ -41,8 +41,8 @@ package main;
use strict; use strict;
use warnings; use warnings;
use POSIX qw(strftime); use POSIX qw(strftime SIGALRM);
use Time::HiRes qw(gettimeofday tv_interval); use Time::HiRes qw(gettimeofday tv_interval ualarm);
use Scalar::Util qw(looks_like_number); use Scalar::Util qw(looks_like_number);
eval "use DBI;1" or my $DbRepMMDBI = "DBI"; eval "use DBI;1" or my $DbRepMMDBI = "DBI";
eval "use FHEM::Meta;1" or my $modMetaAbsent = 1; eval "use FHEM::Meta;1" or my $modMetaAbsent = 1;
@ -57,6 +57,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch';
# Version History intern # Version History intern
our %DbRep_vNotesIntern = ( our %DbRep_vNotesIntern = (
"8.40.7" => "03.09.2020 rename getter dbValue to sqlCmdBlocking, consider attr timeout in function DbRep_sqlCmdBlocking (blocking function), commandRef revised ",
"8.40.6" => "27.08.2020 commandRef revised ", "8.40.6" => "27.08.2020 commandRef revised ",
"8.40.5" => "29.07.2020 fix crash if delEntries startet without any time limits, Forum:#113202 ", "8.40.5" => "29.07.2020 fix crash if delEntries startet without any time limits, Forum:#113202 ",
"8.40.4" => "23.07.2020 new aggregation value 'minute', some fixes ", "8.40.4" => "23.07.2020 new aggregation value 'minute', some fixes ",
@ -102,7 +103,7 @@ our %DbRep_vNotesIntern = (
"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 ". "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 ".
"sub DbRep_modAssociatedWith changed ", "sub DbRep_modAssociatedWith changed ",
"8.24.0" => "24.08.2019 devices marked as \"Associated With\" if possible, fhem.pl 20069 2019-08-27 08:36:02Z is needed ", "8.24.0" => "24.08.2019 devices marked as \"Associated With\" if possible, fhem.pl 20069 2019-08-27 08:36:02Z is needed ",
"8.23.1" => "26.08.2019 fix add newline at the end of DbRep_dbValue result, Forum: #103295 ", "8.23.1" => "26.08.2019 fix add newline at the end of DbRep_sqlCmdBlocking result, Forum: #103295 ",
"8.23.0" => "24.08.2019 prepared for devices marked as \"Associated With\" if possible ", "8.23.0" => "24.08.2019 prepared for devices marked as \"Associated With\" if possible ",
"8.22.0" => "23.08.2019 new attr fetchValueFn. When fetching the database content, manipulate the VALUE-field before create reading ", "8.22.0" => "23.08.2019 new attr fetchValueFn. When fetching the database content, manipulate the VALUE-field before create reading ",
"8.21.2" => "14.08.2019 commandRef revised ", "8.21.2" => "14.08.2019 commandRef revised ",
@ -127,7 +128,7 @@ our %DbRep_vNotesIntern = (
"8.11.1" => "25.01.2019 fix sort of versionNotes ", "8.11.1" => "25.01.2019 fix sort of versionNotes ",
"8.11.0" => "24.01.2019 command exportToFile or attribute \"expimpfile\" accepts option \"MAXLINES=\" ", "8.11.0" => "24.01.2019 command exportToFile or attribute \"expimpfile\" accepts option \"MAXLINES=\" ",
"8.10.1" => "23.01.2019 change DbRep_charfilter to eliminate \xc2", "8.10.1" => "23.01.2019 change DbRep_charfilter to eliminate \xc2",
"8.10.0" => "19.01.2019 sqlCmd, dbValue may input SQL session variables, Forum:#96082 ", "8.10.0" => "19.01.2019 sqlCmd, sqlCmdBlocking may input SQL session variables, Forum:#96082 ",
"8.9.10" => "18.01.2019 fix warnings Malformed UTF-8 character during importFromFile, Forum:#96056 ", "8.9.10" => "18.01.2019 fix warnings Malformed UTF-8 character during importFromFile, Forum:#96056 ",
"8.9.9" => "06.01.2019 diffval_DoParse: 'ORDER BY TIMESTAMP' added to statements Forum:https://forum.fhem.de/index.php/topic,53584.msg882082.html#msg882082", "8.9.9" => "06.01.2019 diffval_DoParse: 'ORDER BY TIMESTAMP' added to statements Forum:https://forum.fhem.de/index.php/topic,53584.msg882082.html#msg882082",
"1.0.0" => "19.05.2016 Initial" "1.0.0" => "19.05.2016 Initial"
@ -135,6 +136,9 @@ our %DbRep_vNotesIntern = (
# Version History extern: # Version History extern:
our %DbRep_vNotesExtern = ( our %DbRep_vNotesExtern = (
"8.40.7" => "03.09.2020 The get Command \"dbValue\" has been renamed to \"sqlCmdBlocking\. You can use \"dbValue\" furthermore in your scripts, but it is ".
"deprecated and will be removed soon. Please change your scripts to use \"sqlCmdBlocking\" instead. ",
"8.40.4" => "23.07.2020 The new aggregation type 'minute' is now available. ",
"8.40.0" => "30.03.2020 The option 'writeToDBInTime' is provided for function 'sumValue' and 'averageValue'. ". "8.40.0" => "30.03.2020 The option 'writeToDBInTime' is provided for function 'sumValue' and 'averageValue'. ".
"A new attribute 'autoForward' is implemented. Now it is possible to transfer the results from the DbRep-Device to another one. ". "A new attribute 'autoForward' is implemented. Now it is possible to transfer the results from the DbRep-Device to another one. ".
"Please see also this (german) <a href=\"https://wiki.fhem.de/wiki/DbRep_-_Reporting_und_Management_von_DbLog-Datenbankinhalten#Readingwerte_von_DbRep_in_ein_anderes_Device_.C3.BCbertragen\">Wiki article</a> ", "Please see also this (german) <a href=\"https://wiki.fhem.de/wiki/DbRep_-_Reporting_und_Management_von_DbLog-Datenbankinhalten#Readingwerte_von_DbRep_in_ein_anderes_Device_.C3.BCbertragen\">Wiki article</a> ",
@ -960,7 +964,7 @@ sub DbRep_Get {
"blockinginfo:noArg ". "blockinginfo:noArg ".
"minTimestamp:noArg ". "minTimestamp:noArg ".
(($dbmodel =~ /MYSQL/)?"storedCredentials:noArg ":""). (($dbmodel =~ /MYSQL/)?"storedCredentials:noArg ":"").
"dbValue:textField-long ". "sqlCmdBlocking:textField-long ".
(($dbmodel eq "MYSQL")?"dbstatus:noArg ":""). (($dbmodel eq "MYSQL")?"dbstatus:noArg ":"").
(($dbmodel eq "MYSQL")?"tableinfo:noArg ":""). (($dbmodel eq "MYSQL")?"tableinfo:noArg ":"").
(($dbmodel eq "MYSQL")?"procinfo:noArg ":""). (($dbmodel eq "MYSQL")?"procinfo:noArg ":"").
@ -1008,18 +1012,27 @@ sub DbRep_Get {
$prop = $prop?$prop:''; $prop = $prop?$prop:'';
DbRep_firstconnect("$name|$opt|$prop|"); DbRep_firstconnect("$name|$opt|$prop|");
} elsif ($opt =~ /dbValue/) { } elsif ($opt =~ /sqlCmdBlocking|dbValue/) {
return "get \"$opt\" needs at least an argument" if ( @a < 3 ); return qq{get "$opt" needs at least an argument} if ( @a < 3 );
if($opt eq "dbValue") {
Log3($name, 1, qq{$name - WARNING - the command "dbValue" is deprecated and will be removed soon. Please use "sqlCmdBlocking" instead.});
}
my @cmd = @a; my @cmd = @a;
shift @cmd; shift @cmd; shift @cmd; shift @cmd;
my $sqlcmd = join(" ",@cmd);
my $sqlcmd = join " ", @cmd;
$sqlcmd =~ tr/ A-Za-z0-9!"#$§%&'()*+,-.\/:;<=>?@[\\]^_`{|}~äöüÄÖÜ߀/ /cs; $sqlcmd =~ tr/ A-Za-z0-9!"#$§%&'()*+,-.\/:;<=>?@[\\]^_`{|}~äöüÄÖÜ߀/ /cs;
$hash->{LASTCMD} = $sqlcmd?"$opt $sqlcmd":"$opt"; $hash->{LASTCMD} = $sqlcmd ? "$opt $sqlcmd" : "$opt";
if ($sqlcmd =~ m/^\s*delete/is && !AttrVal($hash->{NAME}, "allowDeletion", undef)) {
if ($sqlcmd =~ m/^\s*delete/is && !AttrVal($name, "allowDeletion", undef)) {
return "Attribute 'allowDeletion = 1' is needed for command '$sqlcmd'. Use it with care !"; return "Attribute 'allowDeletion = 1' is needed for command '$sqlcmd'. Use it with care !";
} }
my ($err,$ret) = DbRep_dbValue($name,$sqlcmd);
return $err?$err:$ret; ReadingsSingleUpdateValue ($hash, "state", "running", 1);
return DbRep_sqlCmdBlocking($name,$sqlcmd);
} elsif ($opt eq "storedCredentials") { } elsif ($opt eq "storedCredentials") {
# Credentials abrufen # Credentials abrufen
@ -1094,8 +1107,7 @@ sub DbRep_Get {
$ret .= "</div>"; $ret .= "</div>";
} }
# Notes if(!$prop || $prop =~ /rel/) { # Notes
if(!$prop || $prop =~ /rel/) {
$ret .= sprintf("<div class=\"makeTable wide\"; style=\"text-align:left\">$header <br>"); $ret .= sprintf("<div class=\"makeTable wide\"; style=\"text-align:left\">$header <br>");
$ret .= "<table class=\"block wide internals\">"; $ret .= "<table class=\"block wide internals\">";
$ret .= "<tbody>"; $ret .= "<tbody>";
@ -1106,8 +1118,7 @@ sub DbRep_Get {
$ret .= sprintf("<td style=\"vertical-align:top\"><b>$key</b> </td><td style=\"vertical-align:top\">$val0 </td><td>$val1</td>" ); $ret .= sprintf("<td style=\"vertical-align:top\"><b>$key</b> </td><td style=\"vertical-align:top\">$val0 </td><td>$val1</td>" );
$ret .= "</tr>"; $ret .= "</tr>";
$i++; $i++;
if ($i & 1) { if ($i & 1) { # $i ist ungerade
# $i ist ungerade
$ret .= "<tr class=\"odd\">"; $ret .= "<tr class=\"odd\">";
} else { } else {
$ret .= "<tr class=\"even\">"; $ret .= "<tr class=\"even\">";
@ -11511,43 +11522,51 @@ return;
# blockierende DB-Abfrage # blockierende DB-Abfrage
# liefert Ergebnis sofort zurück, setzt keine Readings # liefert Ergebnis sofort zurück, setzt keine Readings
#################################################################################################### ####################################################################################################
sub DbRep_dbValue { sub DbRep_sqlCmdBlocking {
my ($name,$cmd) = @_; my $name = shift;
my $cmd = shift;
my $hash = $defs{$name}; my $hash = $defs{$name};
my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}};
my $dbconn = $dbloghash->{dbconn}; my $dbconn = $dbloghash->{dbconn};
my $dbuser = $dbloghash->{dbuser}; my $dbuser = $dbloghash->{dbuser};
my $dblogname = $dbloghash->{NAME}; my $dblogname = $dbloghash->{NAME};
my $dbpassword = $attr{"sec$dblogname"}{secret}; my $dbpassword = $attr{"sec$dblogname"}{secret};
my $utf8 = defined($hash->{UTF8})?$hash->{UTF8}:0; my $utf8 = $hash->{UTF8} // 0;
my $srs = AttrVal($name, "sqlResultFieldSep", "|");
my $srs = AttrVal($name, "sqlResultFieldSep", "|" );
my $to = AttrVal($name, "timeout", 10 );
my ($err,$ret,$dbh); my ($err,$ret,$dbh);
readingsDelete($hash, "errortext"); readingsDelete ($hash, "errortext");
ReadingsSingleUpdateValue ($hash, "state", "running", 1); ReadingsSingleUpdateValue ($hash, "state", "running", 1);
eval {$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 1, AutoInactiveDestroy => 1, mysql_enable_utf8 => $utf8 });}; eval { $dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0,
RaiseError => 1,
AutoCommit => 1,
AutoInactiveDestroy => 1,
mysql_enable_utf8 => $utf8
}
);
};
if ($@) { if ($@) {
$err = $@; $err = $@;
Log3 ($name, 2, "DbRep $name - $err"); Log3 ($name, 2, "DbRep $name - $err");
ReadingsSingleUpdateValue ($hash, "errortext", $err, 1); ReadingsSingleUpdateValue ($hash, "errortext", $err, 1);
ReadingsSingleUpdateValue ($hash, "state", "error", 1); ReadingsSingleUpdateValue ($hash, "state", "error", 1);
return ($err); return $err;
} }
my $sql = ($cmd =~ m/\;$/)?$cmd:$cmd.";"; my $sql = ($cmd =~ m/\;$/xs) ? $cmd : $cmd.";";
# Ausgaben
Log3 ($name, 4, "DbRep $name - -------- New selection --------- "); Log3 ($name, 4, "DbRep $name - -------- New selection --------- ");
Log3 ($name, 4, "DbRep $name - Command: dbValue"); Log3 ($name, 4, "DbRep $name - Command: sqlCmdBlocking");
Log3 ($name, 4, "DbRep $name - SQL execute: $sql"); Log3 ($name, 4, "DbRep $name - SQL execute: $sql");
# split SQL-Parameter Statement falls mitgegeben
# z.B. SET @open:=NULL, @closed:=NULL; Select ...
my $set; my $set;
if($cmd =~ /^SET.*;/i) { if($cmd =~ /^SET.*;/i) { # split SQL-Parameter Statement falls mitgegeben ->
$cmd =~ m/^(SET.*?;)(.*)/i; $cmd =~ m/^(SET.*?;)(.*)/i; # z.B. SET @open:=NULL, @closed:=NULL; Select ...
$set = $1; $set = $1;
$sql = $2; $sql = $2;
} }
@ -11556,6 +11575,7 @@ sub DbRep_dbValue {
Log3($name, 4, "DbRep $name - Set SQL session variables: $set"); Log3($name, 4, "DbRep $name - Set SQL session variables: $set");
eval {$dbh->do($set);}; # @\RB = Resetbit wenn neues Selektionsintervall beginnt eval {$dbh->do($set);}; # @\RB = Resetbit wenn neues Selektionsintervall beginnt
} }
if ($@) { if ($@) {
$err = $@; $err = $@;
Log3 ($name, 2, "DbRep $name - $err"); Log3 ($name, 2, "DbRep $name - $err");
@ -11564,21 +11584,45 @@ sub DbRep_dbValue {
return ($err); return ($err);
} }
# SQL-Startzeit my $st = [gettimeofday]; # SQL-Startzeit
my $st = [gettimeofday];
my ($sth,$r); my $totxt = qq{Timeout occured (limit: $to seconds). You may be able to adjust the "Timeout" attribute.};
eval {$sth = $dbh->prepare($sql);
my ($sth,$r,$failed);
eval { # outer eval fängt Alarm auf, der gerade vor diesem Alarm feuern könnte(0)
POSIX::sigaction(SIGALRM, POSIX::SigAction->new(sub {die "Timeout\n"})); # \n ist nötig !
alarm($to);
eval {
$sth = $dbh->prepare($sql);
$r = $sth->execute(); $r = $sth->execute();
1;
}; };
alarm(0); # Alarm aufheben (wenn der Code schnell lief)
if ($@) { if ($@) {
$err = $@; if($@ eq "Timeout\n") { # timeout
$failed = $totxt;
} else { # ein anderer Fehler
$failed = $@;
}
}
1;
} or $failed = $@;
alarm(0); # Schutz vor Race Condition
if ($failed) {
$err = $failed eq "Timeout\n" ? $totxt : $failed;
Log3 ($name, 2, "DbRep $name - $err"); Log3 ($name, 2, "DbRep $name - $err");
$sth->finish if($sth);
$dbh->disconnect; $dbh->disconnect;
ReadingsSingleUpdateValue ($hash, "errortext", $err, 1); ReadingsSingleUpdateValue ($hash, "errortext", $err, 1);
ReadingsSingleUpdateValue ($hash, "state", "error", 1); ReadingsSingleUpdateValue ($hash, "state", "error", 1);
return ($err); return $err;
} }
my $nrows = 0; my $nrows = 0;
@ -11587,8 +11631,7 @@ sub DbRep_dbValue {
Log3 ($name, 4, "DbRep $name - SQL result: @line"); Log3 ($name, 4, "DbRep $name - SQL result: @line");
$ret .= "\n" if($nrows); # Forum: #103295 $ret .= "\n" if($nrows); # Forum: #103295
$ret .= join("$srs", @line); $ret .= join("$srs", @line);
# Anzahl der Datensätze $nrows++; # Anzahl der Datensätze
$nrows++;
} }
} else { } else {
@ -11600,7 +11643,7 @@ sub DbRep_dbValue {
$dbh->disconnect; $dbh->disconnect;
ReadingsSingleUpdateValue ($hash, "errortext", $err, 1); ReadingsSingleUpdateValue ($hash, "errortext", $err, 1);
ReadingsSingleUpdateValue ($hash, "state", "error", 1); ReadingsSingleUpdateValue ($hash, "state", "error", 1);
return ($err); return $err;
} }
$ret = $nrows; $ret = $nrows;
} }
@ -11608,18 +11651,16 @@ sub DbRep_dbValue {
$sth->finish; $sth->finish;
$dbh->disconnect; $dbh->disconnect;
# SQL-Laufzeit ermitteln my $rt = tv_interval($st); # SQL-Laufzeit ermitteln
my $rt = tv_interval($st);
my $com = (split(" ",$sql, 2))[0]; my $com = (split " ", $sql, 2)[0];
Log3 ($name, 4, "DbRep $name - Number of entries processed in db $hash->{DATABASE}: $nrows by $com"); Log3 ($name, 4, "DbRep $name - Number of entries processed in db $hash->{DATABASE}: $nrows by $com");
# Readingaufbereitung readingsBeginUpdate ($hash);
readingsBeginUpdate($hash); ReadingsBulkUpdateTimeState ($hash,undef,$rt,"done");
ReadingsBulkUpdateTimeState($hash,undef,$rt,"done"); readingsEndUpdate ($hash, 1);
readingsEndUpdate($hash, 1);
return ($ret); return $ret;
} }
#################################################################################################### ####################################################################################################
@ -11633,8 +11674,7 @@ return ($ret);
sub CommandDbReadingsVal { sub CommandDbReadingsVal {
my ($cl, $param) = @_; my ($cl, $param) = @_;
my @a = split("[ \t][ \t]*", $param); my ($name, $devread, $ts, $default) = split m{\s+}x, $param;
my ($name, $devread, $ts, $default) = @a;
$ts =~ s/_/ /; $ts =~ s/_/ /;
my $ret = DbReadingsVal($name, $devread, $ts, $default); my $ret = DbReadingsVal($name, $devread, $ts, $default);
@ -11643,24 +11683,31 @@ return $ret;
} }
sub DbReadingsVal($$$$) { sub DbReadingsVal($$$$) {
my ($name, $devread, $ts, $default) = @_; my $name = shift // return qq{A DbRep-device must be specified};
my $hash = $defs{$name}; my $devread = shift // return qq{"device:reading" must be specified};
my $dbmodel = $defs{$hash->{HELPER}{DBLOGDEVICE}}{MODEL}; my $ts = shift // return qq{The Command needs a timestamp defined in format "YYYY-MM-DD_hh:mm:ss"};
my $default = shift // return qq{The Command needs a default value defined};
my ($err,$ret,$sql); my ($err,$ret,$sql);
unless(defined($defs{$name})) { if(!defined($defs{$name})) {
return ("DbRep-device \"$name\" doesn't exist."); return qq{DbRep-device "$name" doesn't exist.};
} }
unless($defs{$name}{TYPE} eq "DbRep") { if(!$defs{$name}{TYPE} eq "DbRep") {
return ("\"$name\" is not a DbRep-device but of type \"".$defs{$name}{TYPE}."\""); return qq{"$name" is not a DbRep-device but of type "}.$defs{$name}{TYPE}.qq{"};
} }
my $hash = $defs{$name};
my $dbmodel = $defs{$hash->{HELPER}{DBLOGDEVICE}}{MODEL};
$ts =~ s/_/ /; $ts =~ s/_/ /;
unless($ts =~ /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/) { if($ts !~ /^(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{2})$/x) {
return ("timestamp has not the valid format. Use \"YYYY-MM-DD hh:mm:ss\" as timestamp."); return qq{timestamp has not the valid format. Use "YYYY-MM-DD_hh:mm:ss" as timestamp.};
} }
my ($dev,$reading) = split(":",$devread); my ($dev,$reading) = split(":",$devread);
unless($dev && $reading) { if(!$dev || !$reading) {
return ("device:reading must be specified !"); return qq{"device:reading" must be specified};
} }
if($dbmodel eq "MYSQL") { if($dbmodel eq "MYSQL") {
@ -11693,13 +11740,14 @@ sub DbReadingsVal($$$$) {
where device='$dev' and reading='$reading' and timestamp < '$ts' where device='$dev' and reading='$reading' and timestamp < '$ts'
) )
x order by diff limit 1;"; x order by diff limit 1;";
} else { } else {
return ("DbReadingsVal is not implemented for $dbmodel"); return qq{DbReadingsVal is not implemented for $dbmodel};
} }
$hash->{LASTCMD} = "dbValue $sql"; $hash->{LASTCMD} = "sqlCmdBlocking $sql";
$ret = DbRep_dbValue($name,$sql); $ret = DbRep_sqlCmdBlocking($name,$sql);
$ret = $ret?$ret:$default; $ret = $ret ? $ret : $default;
return $ret; return $ret;
} }
@ -11850,7 +11898,7 @@ return;
<li> change of reading values in the database (changeValue) </li> <li> change of reading values in the database (changeValue) </li>
<li> automatic rename of device names in datasets and other DbRep-definitions after FHEM "rename" command (see <a href="#DbRepAutoRename">DbRep-Agent</a>) </li> <li> automatic rename of device names in datasets and other DbRep-definitions after FHEM "rename" command (see <a href="#DbRepAutoRename">DbRep-Agent</a>) </li>
<li> Execution of arbitrary user specific SQL-commands (non-blocking) </li> <li> Execution of arbitrary user specific SQL-commands (non-blocking) </li>
<li> Execution of arbitrary user specific SQL-commands (blocking) for usage in user own code (dbValue) </li> <li> Execution of arbitrary user specific SQL-commands (blocking) for usage in user own code (sqlCmdBlocking) </li>
<li> creation of backups of the database in running state non-blocking (MySQL, SQLite) </li> <li> creation of backups of the database in running state non-blocking (MySQL, SQLite) </li>
<li> transfer dumpfiles to a FTP server after backup incl. version control</li> <li> transfer dumpfiles to a FTP server after backup incl. version control</li>
<li> restore of SQLite- and MySQL-Dumps non-blocking </li> <li> restore of SQLite- and MySQL-Dumps non-blocking </li>
@ -11877,8 +11925,9 @@ return;
<br><br> <br><br>
Once a DbRep-Device is defined, the Perl function <b>DbReadingsVal</b> provided as well as and the FHEM command <b>dbReadingsVal</b>. Once a DbRep-Device is defined, the Perl function <b>DbReadingsVal</b> provided as well as and the FHEM command <b>dbReadingsVal</b>.
With this function you can, similar to the well known ReadingsVal, get a reading value from database. With this function you can, similar to the well known ReadingsVal, get a reading value from database. <br>
The function execution is carried out blocking. <br><br> The function is executed blocking with a standard timeout of 10 seconds to prevent a permanent blocking of FHEM.
The timeout is adjustable with the attribute <a href="#dbreptimeout">timeout</a>. <br><br>
<ul> <ul>
The command syntax for the Perl function is: <br><br> The command syntax for the Perl function is: <br><br>
@ -11888,7 +11937,7 @@ return;
</code> </code>
<br><br> <br><br>
<b>Examples: </b><br> <b>Example: </b><br>
<pre> <pre>
$ret = DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-01-13_08:00:00",""); $ret = DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-01-13_08:00:00","");
attr &lt;name&gt; userReadings oldtemp {DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-04-13_08:00:00","")} attr &lt;name&gt; userReadings oldtemp {DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-04-13_08:00:00","")}
@ -11910,14 +11959,16 @@ return;
<br><br> <br><br>
<b>Example: </b><br> <b>Example: </b><br>
<code>
dbReadingsVal Rep.LogDB1 MyWetter:temperature 2018-01-13_08:00:00 0 dbReadingsVal Rep.LogDB1 MyWetter:temperature 2018-01-13_08:00:00 0
</code>
<br><br> <br><br>
<table> <table>
<colgroup> <col width=5%> <col width=95%> </colgroup> <colgroup> <col width=5%> <col width=95%> </colgroup>
<tr><td> <b>&lt;name&gt;</b> </td><td>: name of the DbRep-Device to request </td></tr> <tr><td> <b>&lt;name&gt;</b> </td><td>: name of the DbRep-Device to request </td></tr>
<tr><td> <b>&lt;device:reading&gt;</b> </td><td>: device:reading whose value is to deliver </td></tr> <tr><td> <b>&lt;device:reading&gt;</b> </td><td>: device:reading whose value is to deliver </td></tr>
<tr><td> <b>&lt;timestamp&gt;</b> </td><td>: timestamp of reading whose value is to deliver (*) in the form "YYYY-MM-DD_hh:mm:ss" </td></tr> <tr><td> <b>&lt;timestamp&gt;</b> </td><td>: timestamp of reading whose value is to deliver (*) in format "YYYY-MM-DD_hh:mm:ss" </td></tr>
<tr><td> <b>&lt;default&gt;</b> </td><td>: default value if no reading value can be retrieved </td></tr> <tr><td> <b>&lt;default&gt;</b> </td><td>: default value if no reading value can be retrieved </td></tr>
</table> </table>
</ul> </ul>
@ -13376,52 +13427,60 @@ return;
<br><br> <br><br>
<ul><ul> <ul><ul>
<a name="blockinginfo"></a>
<li><b> blockinginfo </b> - list the current system wide running background processes (BlockingCalls) together with their informations. <li><b> blockinginfo </b> - list the current system wide running background processes (BlockingCalls) together with their informations.
If character string is too long (e.g. arguments) it is reported shortened. If character string is too long (e.g. arguments) it is reported shortened.
</li> </li>
<br><br> <br><br>
<li><b> dbstatus </b> - lists global informations about MySQL server status (e.g. informations related to cache, threads, bufferpools, etc. ). <a name="dbstatus"></a>
Initially all available informations are reported. Using the <a href="#DbRepattr">attribute</a> "showStatus" the quantity of <li><b> dbstatus </b> - lists global information about MySQL server status (e.g. informations related to cache, threads, bufferpools, etc. ).
Initially all available informations are reported. Using the attribute <a href="#showStatus">showStatus</a> the quantity of
results can be limited to show only the desired values. Further detailed informations of items meaning are results can be limited to show only the desired values. Further detailed informations of items meaning are
explained <a href=http://dev.mysql.com/doc/refman/5.7/en/server-status-variables.html>there</a>. <br> explained <a href="http://dev.mysql.com/doc/refman/5.7/en/server-status-variables.html">here</a>. <br><br>
<br><ul> <ul>
<b>Example</b> <br> <b>Example</b> <br>
get &lt;name&gt; dbstatus <br>
attr &lt;name&gt; showStatus %uptime%,%qcache% <br> attr &lt;name&gt; showStatus %uptime%,%qcache% <br>
get &lt;name&gt; dbstatus <br>
# Only readings containing "uptime" and "qcache" in name will be created # Only readings containing "uptime" and "qcache" in name will be created
</ul>
</li> </li>
<br><br> <br><br>
</ul>
<li><b> dbValue &lt;SQL-statement&gt;</b> - <a name="sqlCmdBlocking"></a>
Executes the specified SQL-statement in <b>blocking</b> manner. Because of its mode of operation <li><b> sqlCmdBlocking &lt;SQL-statement&gt;</b> -
this function is particular convenient for user own perl scripts. <br> Executes the specified SQL statement <b>blocking</b> with a default timeout of 10 seconds.
The timeout can be set with the attribute <a href="#dbreptimeout">timeout</a>.
<br><br>
<ul>
<b>Examples:</b> <br>
{ fhem("get &lt;name&gt; sqlCmdBlocking select device,count(*) from history where timestamp > '2018-04-01' group by device") } <br>
{ CommandGet(undef,"Rep.LogDB1 sqlCmdBlocking select device,count(*) from history where timestamp > '2018-04-01' group by device") } <br>
get &lt;name&gt; sqlCmdBlocking select device,count(*) from history where timestamp > '2018-04-01' group by device <br>
</ul>
</li>
<br>
Because of its mode of operation this function is particular convenient for user own perl scripts. <br>
The input accepts multi line commands and delivers multi line results as well. The input accepts multi line commands and delivers multi line results as well.
This command also accept the setting of SQL session variables like "SET @open:=NULL, This command also accept the setting of SQL session variables like "SET @open:=NULL,
@closed:=NULL;". <br> @closed:=NULL;". <br>
If several fields are selected and passed back, the fieds are separated by the separator defined If several fields are selected and passed back, the fieds are separated by the separator defined
by <a href="#DbRepattr">attribute</a> "sqlResultFieldSep" (default "|"). Several result lines by attribute <a href="#sqlResultFieldSep">sqlResultFieldSep</a> (default "|"). Several result lines
are separated by newline ("\n"). <br> are separated by newline ("\n"). <br>
This function only set/update status readings, the userExitFn function isn't called. This function only set/update status readings, the userExitFn function isn't called.
<br>
<br><ul>
<b>Examples for use in FHEMWEB</b> <br>
{fhem("get &lt;name&gt; dbValue select device,count(*) from history where timestamp > '2018-04-01' group by device")} <br>
get &lt;name&gt; dbValue select device,count(*) from history where timestamp > '2018-04-01' group by device <br>
{CommandGet(undef,"Rep.LogDB1 dbValue select device,count(*) from history where timestamp > '2018-04-01' group by device")} <br>
</ul>
<br><br> <br><br>
If you create a little routine in 99_myUtils, for example: If you create a little routine in 99_myUtils, for example:
<br> <br>
<pre> <pre>
sub dbval($$) { sub dbval {
my ($name,$cmd) = @_; my $name = shift;
my $ret = CommandGet(undef,"$name dbValue $cmd"); my $cmd) = shift;
return $ret; my $ret = CommandGet(undef,"$name sqlCmdBlocking $cmd");
return $ret;
} }
</pre> </pre>
it can be accessed with e.g. those calls: it can be accessed with e.g. those calls:
@ -13429,34 +13488,36 @@ return $ret;
<ul> <ul>
<b>Examples:</b> <br> <b>Examples:</b> <br>
{dbval("&lt;name&gt;","select count(*) from history")} <br> { dbval("&lt;name&gt;","select count(*) from history") } <br>
$ret = dbval("&lt;name&gt;","select count(*) from history"); <br> $ret = dbval("&lt;name&gt;","select count(*) from history"); <br>
</ul> </ul>
</li>
<br><br> <br><br>
<a name="dbvars"></a>
<li><b> dbvars </b> - lists global informations about MySQL system variables. Included are e.g. readings related to InnoDB-Home, datafile path, <li><b> dbvars </b> - lists global informations about MySQL system variables. Included are e.g. readings related to InnoDB-Home, datafile path,
memory- or cache-parameter and so on. The Output reports initially all available informations. Using the memory- or cache-parameter and so on. The Output reports initially all available informations. Using the
<a href="#DbRepattr">attribute</a> "showVariables" the quantity of results can be limited to show only the desired values. attribute <a href="#showVariables">showVariables</a> the quantity of results can be limited to show only the desired values.
Further detailed informations of items meaning are explained Further detailed informations of items meaning are explained
<a href=http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html>there</a>. <br> <a href="http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html">here</a>. <br><br>
<br><ul> <ul>
<b>Example</b> <br> <b>Example</b> <br>
get &lt;name&gt; dbvars <br>
attr &lt;name&gt; showVariables %version%,%query_cache% <br> attr &lt;name&gt; showVariables %version%,%query_cache% <br>
get &lt;name&gt; dbvars <br>
# Only readings containing "version" and "query_cache" in name will be created # Only readings containing "version" and "query_cache" in name will be created
</ul>
</li> </li>
<br><br> <br><br>
</ul>
<a name="minTimestamp"></a>
<li><b> minTimestamp </b> - Identifies the oldest timestamp in the database (will be executed implicitely at FHEM start). <li><b> minTimestamp </b> - Identifies the oldest timestamp in the database (will be executed implicitely at FHEM start).
The timestamp is used as begin of data selection if no time attribut is set to determine the The timestamp is used as begin of data selection if no time attribut is set to determine the
start date. start date.
</li> </li>
<br><br> <br><br>
<a name="procinfo"></a>
<li><b> procinfo </b> - Reports the existing database processes in a summary table (only MySQL). <br> <li><b> procinfo </b> - Reports the existing database processes in a summary table (only MySQL). <br>
Typically only the own processes of the connection user (set in DbLog configuration file) will be Typically only the own processes of the connection user (set in DbLog configuration file) will be
reported. If all precesses have to be reported, the global "PROCESS" right has to be granted to the reported. If all precesses have to be reported, the global "PROCESS" right has to be granted to the
@ -13465,50 +13526,70 @@ return $ret;
(table row "PROGRESS"). So you can track, for instance, the degree of processing during an index (table row "PROGRESS"). So you can track, for instance, the degree of processing during an index
creation. <br> creation. <br>
Further informations can be found Further informations can be found
<a href=https://mariadb.com/kb/en/mariadb/show-processlist/>there</a>. <br> <a href="https://mariadb.com/kb/en/mariadb/show-processlist/">here</a>. <br>
</li> </li>
<br><br> <br><br>
<a name="storedCredentials"></a>
<li><b> storedCredentials </b> - Reports the users / passwords stored for database access by the device. <br> <li><b> storedCredentials </b> - Reports the users / passwords stored for database access by the device. <br>
(only valid if database type is MYSQL) (only valid if database type is MYSQL)
</li> </li>
<br><br> <br><br>
<a name="svrinfo"></a>
<li><b> svrinfo </b> - Common database server informations, e.g. DBMS-version, server address and port and so on. The quantity of elements to get depends <li><b> svrinfo </b> - Common database server informations, e.g. DBMS-version, server address and port and so on. The quantity of elements to get depends
on the database type. Using the <a href="#DbRepattr">attribute</a> "showSvrInfo" the quantity of results can be limited to show only on the database type. Using the attribute <a href="#showSvrInfo">showSvrInfo</a> the quantity of results can be limited to show only
the desired values. Further detailed informations of items meaning are explained the desired values. Further detailed informations of items meaning are explained
<a href=https://msdn.microsoft.com/en-us/library/ms711681(v=vs.85).aspx>there</a>. <br> <a href="https://msdn.microsoft.com/en-us/library/ms711681(v=vs.85).aspx">here</a>. <br><br>
<br><ul> <ul>
<b>Example</b> <br> <b>Example</b> <br>
get &lt;name&gt; svrinfo <br>
attr &lt;name&gt; showSvrInfo %SQL_CATALOG_TERM%,%NAME% <br> attr &lt;name&gt; showSvrInfo %SQL_CATALOG_TERM%,%NAME% <br>
get &lt;name&gt; svrinfo <br>
# Only readings containing "SQL_CATALOG_TERM" and "NAME" in name will be created # Only readings containing "SQL_CATALOG_TERM" and "NAME" in name will be created
</ul>
</li> </li>
<br><br> <br><br>
</ul>
<a name="tableinfo"></a>
<li><b> tableinfo </b> - Access detailed informations about tables in MySQL database which is connected by the DbRep-device. <li><b> tableinfo </b> - Access detailed informations about tables in MySQL database which is connected by the DbRep-device.
All available tables in the connected database will be selected by default. All available tables in the connected database will be selected by default.
Using the<a href="#DbRepattr">attribute</a> "showTableInfo" the results can be limited to tables you want to show. Using the attribute <a href="#showTableInfo">showTableInfo</a> the results can be limited to tables you want to show.
Further detailed informations of items meaning are explained <a href=http://dev.mysql.com/doc/refman/5.7/en/show-table-status.html>there</a>. <br> Further detailed informations of items meaning are explained
<a href="http://dev.mysql.com/doc/refman/5.7/en/show-table-status.html">here</a>. <br><br>
<br><ul> <ul>
<b>Example</b> <br> <b>Example</b> <br>
get &lt;name&gt; tableinfo <br>
attr &lt;name&gt; showTableInfo current,history <br> attr &lt;name&gt; showTableInfo current,history <br>
get &lt;name&gt; tableinfo <br>
# Only informations related to tables "current" and "history" are going to be created # Only informations related to tables "current" and "history" are going to be created
</ul>
</li> </li>
<br><br> <br><br>
<a name="versionNotes"></a>
<li><b> versionNotes [hints | rel | &lt;key&gt;] </b> -
Shows realease informations and/or hints about the module.
<br><br>
<ul>
<table>
<colgroup> <col width=5%> <col width=95%> </colgroup>
<tr><td> rel </td><td>: shows only release information </td></tr>
<tr><td> hints </td><td>: shows only hints </td></tr>
<tr><td> &lt;key&gt; </td><td>: the note with the specified number is displayed </td></tr>
</table>
</ul> </ul>
<li><b> versionNotes [hints | rel | &lt;key&gt;] </b> - </li>
Shows realease informations and/or hints about the module. It contains only main release
informations for module users. <br> <br>
It contains only main release informations for module users. <br>
If no options are specified, both release informations and hints will be shown. "rel" shows If no options are specified, both release informations and hints will be shown. "rel" shows
only release informations and "hints" shows only hints. By the &lt;key&gt;-specification only only release informations and "hints" shows only hints. By the &lt;key&gt;-specification only
the hint with the specified number is shown. the hint with the specified number is shown.
</li>
<br> <br>
</ul></ul> </ul></ul>
@ -14219,7 +14300,7 @@ sub bdump {
<br><br> <br><br>
</li> </li>
<a name="timeout"></a> <a name="dbreptimeout"></a>
<li><b>timeout </b> - set the timeout-value for Blocking-Call Routines in background in seconds (default 86400) </li> <br> <li><b>timeout </b> - set the timeout-value for Blocking-Call Routines in background in seconds (default 86400) </li> <br>
<a name="useAdminCredentials"></a> <a name="useAdminCredentials"></a>
@ -14415,7 +14496,7 @@ sub bdump {
<li> automatisches Umbenennen von Device-Namen in Datenbanksätzen und DbRep-Definitionen nach FHEM "rename" <li> automatisches Umbenennen von Device-Namen in Datenbanksätzen und DbRep-Definitionen nach FHEM "rename"
Befehl (siehe <a href="#DbRepAutoRename">DbRep-Agent</a>) </li> Befehl (siehe <a href="#DbRepAutoRename">DbRep-Agent</a>) </li>
<li> Ausführen von beliebigen Benutzer spezifischen SQL-Kommandos (non-blocking) </li> <li> Ausführen von beliebigen Benutzer spezifischen SQL-Kommandos (non-blocking) </li>
<li> Ausführen von beliebigen Benutzer spezifischen SQL-Kommandos (blocking) zur Verwendung in eigenem Code (dbValue) </li> <li> Ausführen von beliebigen Benutzer spezifischen SQL-Kommandos (blocking) zur Verwendung in eigenem Code (sqlCmdBlocking) </li>
<li> Backups der FHEM-Datenbank im laufenden Betrieb erstellen (MySQL, SQLite) </li> <li> Backups der FHEM-Datenbank im laufenden Betrieb erstellen (MySQL, SQLite) </li>
<li> senden des Dumpfiles zu einem FTP-Server nach dem Backup incl. Versionsverwaltung </li> <li> senden des Dumpfiles zu einem FTP-Server nach dem Backup incl. Versionsverwaltung </li>
<li> Restore von SQLite- und MySQL-Dumps </li> <li> Restore von SQLite- und MySQL-Dumps </li>
@ -14442,8 +14523,9 @@ sub bdump {
Sobald ein DbRep-Device definiert ist, wird sowohl die Perl Funktion <b>DbReadingsVal</b> als auch das FHEM Kommando Sobald ein DbRep-Device definiert ist, wird sowohl die Perl Funktion <b>DbReadingsVal</b> als auch das FHEM Kommando
<b>dbReadingsVal</b> zur Verfügung gestellt. <b>dbReadingsVal</b> zur Verfügung gestellt.
Mit dieser Funktion läßt sich, ähnlich dem allgemeinen ReadingsVal, der Wert eines Readings aus der Datenbank abrufen. Mit dieser Funktion läßt sich, ähnlich dem allgemeinen ReadingsVal, der Wert eines Readings aus der Datenbank abrufen. <br>
Die Funktionsausführung erfolgt blockierend. <br><br> Die Funktionsausführung erfolgt blockierend mit einem Standardtimeout von 10 Sekunden um eine dauerhafte Blockierung von FHEM zu verhindern.
Der Timeout ist mit dem Attribut <a href="#dbreptimeout">timeout</a> anpassbar. <br><br>
<ul> <ul>
Die Befehlssyntax für die Perl Funktion ist: <br><br> Die Befehlssyntax für die Perl Funktion ist: <br><br>
@ -14453,7 +14535,7 @@ sub bdump {
</code> </code>
<br><br> <br><br>
<b>Beispiele: </b><br> <b>Beispiel: </b><br>
<pre> <pre>
$ret = DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-01-13_08:00:00",""); $ret = DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-01-13_08:00:00","");
attr &lt;name&gt; userReadings oldtemp {DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-04-13_08:00:00","")} attr &lt;name&gt; userReadings oldtemp {DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-04-13_08:00:00","")}
@ -14475,7 +14557,9 @@ sub bdump {
<br><br> <br><br>
<b>Beispiel: </b><br> <b>Beispiel: </b><br>
<code>
dbReadingsVal Rep.LogDB1 MyWetter:temperature 2018-01-13_08:00:00 0 dbReadingsVal Rep.LogDB1 MyWetter:temperature 2018-01-13_08:00:00 0
</code>
<br><br> <br><br>
<table> <table>
@ -14556,23 +14640,24 @@ sub bdump {
<ul><ul> <ul><ul>
<li><b> adminCredentials &lt;User&gt; &lt;Passwort&gt; </b> <li><b> adminCredentials &lt;User&gt; &lt;Passwort&gt; </b>
- Speichert einen User / Passwort für den privilegierten bzw. administrativen - Speichert einen User / Passwort für den privilegierten bzw. administrativen
Datenbankzugriff. Er wird bei Datenbankoperationen benötigt, die mit einem privilegierten User Datenbankzugriff. Er wird bei Datenbankoperationen benötigt, die mit einem privilegierten User
ausgeführt werden müssen. Siehe auch Attribut <a href="#useAdminCredentials">'useAdminCredentials'</a>. <br> ausgeführt werden müssen. Siehe auch Attribut <a href="#useAdminCredentials">'useAdminCredentials'</a>. <br>
(nur gültig bei Datenbanktyp MYSQL und DbRep-Typ "Client") (nur gültig bei Datenbanktyp MYSQL und DbRep-Typ "Client")
</li> <br> </li> <br>
<li><b> averageValue [display | writeToDB | writeToDBSingle | writeToDBInTime]</b> <li><b> averageValue [display | writeToDB | writeToDBSingle | writeToDBInTime]</b>
- berechnet einen Durchschnittswert des Datenbankfelds "VALUE" in den Zeitgrenzen - berechnet einen Durchschnittswert des Datenbankfelds "VALUE" in den Zeitgrenzen
der möglichen time.*-Attribute. <br><br> der möglichen time.*-Attribute. <br><br>
</li>
Es muss das auszuwertende Reading im Attribut <a href="#reading">reading</a> Es muss das auszuwertende Reading im Attribut <a href="#reading">reading</a>
angegeben sein. angegeben sein.
Mit dem Attribut <a href="#averageCalcForm">averageCalcForm</a> wird die Berechnungsvariante zur Mit dem Attribut <a href="#averageCalcForm">averageCalcForm</a> wird die Berechnungsvariante zur
Mittelwertermittlung definiert. <br><br> Mittelwertermittlung definiert. <br>
Ist keine oder die Option <b>display</b> angegeben, werden die Ergebnisse nur angezeigt. Mit Ist keine oder die Option <b>display</b> angegeben, werden die Ergebnisse nur angezeigt. Mit
den Optionen <b>writeToDB</b>, <b>writeToDBSingle</b> bzw. <b>writeToDBInTime</b> werden die Berechnungsergebnisse den Optionen <b>writeToDB</b>, <b>writeToDBSingle</b> bzw. <b>writeToDBInTime</b> werden die Berechnungsergebnisse
mit einem neuen Readingnamen in der Datenbank gespeichert. <br><br> mit einem neuen Readingnamen in der Datenbank gespeichert. <br><br>
@ -14620,23 +14705,25 @@ sub bdump {
<br> <br>
<br> <br>
</li> <br> <br>
<li><b> cancelDump </b> - bricht einen laufenden Datenbankdump ab. </li> <br> <li><b> cancelDump </b> - bricht einen laufenden Datenbankdump ab. </li> <br>
<li><b> changeValue </b> - ändert den gespeicherten Wert eines Readings. <li><b> changeValue </b> - ändert den gespeicherten Wert eines Readings.
Ist die Selektion auf bestimmte Device/Reading-Kombinationen durch die Ist die Selektion auf bestimmte Device/Reading-Kombinationen durch die Attribute
<a href="#DbRepattr">Attribute</a> "device" bzw. "reading" beschränkt, werden sie genauso <a href="#device">device</a> bzw. <a href="#reading">reading</a> beschränkt, werden sie genauso
berücksichtigt wie gesetzte Zeitgrenzen (Attribute time.*). <br> berücksichtigt wie gesetzte Zeitgrenzen (Attribute time.*). <br>
Fehlen diese Beschränkungen, wird die gesamte Datenbank durchsucht und der angegebene Wert Fehlen diese Beschränkungen, wird die gesamte Datenbank durchsucht und der angegebene Wert
geändert. <br><br> geändert. <br><br>
</li>
<ul> <ul>
<b>Syntax: </b> <br> <b>Syntax: </b> <br>
set &lt;name&gt; changeValue "&lt;alter String&gt;","&lt;neuer String&gt;" <br><br> set &lt;name&gt; changeValue "&lt;alter String&gt;","&lt;neuer String&gt;" <br><br>
Die Strings werden in Doppelstrich eingeschlossen und durch Komma getrennt. "String" kann sein: <br>
Dabei kann "String" sein: <br>
<table> <table>
<colgroup> <col width=15%> <col width=85%> </colgroup> <colgroup> <col width=15%> <col width=85%> </colgroup>
@ -14650,8 +14737,10 @@ sub bdump {
des Perl-Code geändert werden. Der zurückgebene Wert von $VALUE und $UNIT wird in dem Feld des Perl-Code geändert werden. Der zurückgebene Wert von $VALUE und $UNIT wird in dem Feld
VALUE bzw. UNIT des Datensatzes gespeichert. </li></td></tr> VALUE bzw. UNIT des Datensatzes gespeichert. </li></td></tr>
</table> </table>
</ul>
<br> <br>
<ul>
<b>Beispiele: </b> <br> <b>Beispiele: </b> <br>
set &lt;name&gt; changeValue "OL","12 OL" <br> set &lt;name&gt; changeValue "OL","12 OL" <br>
# der alte Feldwert "OL" wird in "12 OL" geändert. <br><br> # der alte Feldwert "OL" wird in "12 OL" geändert. <br><br>
@ -14686,15 +14775,18 @@ sub bdump {
<b>Hinweis:</b> <br> <b>Hinweis:</b> <br>
Obwohl die Funktion selbst non-blocking ausgelegt ist, sollte das zugeordnete DbLog-Device Obwohl die Funktion selbst non-blocking ausgelegt ist, sollte das zugeordnete DbLog-Device
im asynchronen Modus betrieben werden um ein Blockieren von FHEMWEB zu vermeiden (Tabellen-Lock). <br><br> im asynchronen Modus betrieben werden um ein Blockieren von FHEMWEB zu vermeiden (Tabellen-Lock). <br><br>
</li> <br> <br>
</ul> </ul>
<li><b> countEntries [history | current] </b> <li><b> countEntries [history | current] </b>
- liefert die Anzahl der Tabelleneinträge (default: history) in den gegebenen - liefert die Anzahl der Tabelleneinträge (default: history) in den gegebenen
Zeitgrenzen (siehe <a href="#DbRepattr">Attribute</a>). Zeitgrenzen (siehe <a href="#DbRepattr">Attribute</a>).
Sind die Timestamps nicht gesetzt, werden alle Einträge der Tabelle gezählt. Sind die Timestamps nicht gesetzt, werden alle Einträge der Tabelle gezählt.
Beschränkungen durch die <a href="#DbRepattr">Attribute</a> Device bzw. Reading Beschränkungen durch die Attribute <a href="#device">device</a> bzw. <a href="#reading">reading</a>
gehen in die Selektion mit ein. <br> gehen in die Selektion mit ein. <br>
</li>
Standardmäßig wird die Summe aller Datensätze, gekennzeichnet mit "ALLREADINGS", erstellt. Standardmäßig wird die Summe aller Datensätze, gekennzeichnet mit "ALLREADINGS", erstellt.
Ist das Attribut "countEntriesDetail" gesetzt, wird die Anzahl jedes einzelnen Readings Ist das Attribut "countEntriesDetail" gesetzt, wird die Anzahl jedes einzelnen Readings
zusätzlich ausgegeben. <br><br> zusätzlich ausgegeben. <br><br>
@ -14715,7 +14807,8 @@ sub bdump {
</ul> </ul>
<br> <br>
</li> <br> <br>
<li><b> delDoublets [adviceDelete | delete]</b> - zeigt bzw. löscht doppelte / mehrfach vorkommende Datensätze. <li><b> delDoublets [adviceDelete | delete]</b> - zeigt bzw. löscht doppelte / mehrfach vorkommende Datensätze.
Dazu wird Timestamp, Device,Reading und Value ausgewertet. <br> Dazu wird Timestamp, Device,Reading und Value ausgewertet. <br>
@ -14723,6 +14816,7 @@ sub bdump {
berücksichtigt. Ist das Attribut "aggregation" nicht oder auf "no" gesetzt, wird im Standard die Aggregation berücksichtigt. Ist das Attribut "aggregation" nicht oder auf "no" gesetzt, wird im Standard die Aggregation
"day" verwendet. "day" verwendet.
<br><br> <br><br>
</li>
<ul> <ul>
<table> <table>
@ -14733,15 +14827,15 @@ sub bdump {
</ul> </ul>
<br> <br>
Aus Sicherheitsgründen muss das <a href="#DbRepattr">Attribut</a> "allowDeletion" für die "delete" Option Aus Sicherheitsgründen muss das Attribut <a href="#allowDeletion">allowDeletion</a> für die "delete" Option
gesetzt sein. <br> gesetzt sein. <br>
Die Anzahl der anzuzeigenden Datensätze des Kommandos "delDoublets adviceDelete" ist zunächst Die Anzahl der anzuzeigenden Datensätze des Kommandos "delDoublets adviceDelete" ist zunächst
begrenzt (default 1000) und kann durch das <a href="#DbRepattr">Attribut</a> "limit" angepasst begrenzt (default 1000) und kann durch das Attribut <a href="#limit">limit</a> angepasst
werden. werden.
Die Einstellung von "limit" hat keinen Einfluss auf die "delDoublets delete" Funktion, sondern Die Einstellung von "limit" hat keinen Einfluss auf die "delDoublets delete" Funktion, sondern
beeinflusst <b>NUR</b> die Anzeige der Daten. <br> beeinflusst <b>NUR</b> die Anzeige der Daten. <br>
Vor und nach der Ausführung von "delDoublets" kann ein FHEM-Kommando bzw. Perl-Routine ausgeführt Vor und nach der Ausführung von "delDoublets" kann ein FHEM-Kommando bzw. Perl-Routine ausgeführt
werden. (siehe <a href="#DbRepattr">Attribute</a> "executeBeforeProc", "executeAfterProc") werden. (siehe Attribute <a href="#executeBeforeProc">executeBeforeProc</a>, <a href="#executeAfterProc">executeAfterProc</a>)
<br><br> <br><br>
<ul> <ul>
@ -14777,8 +14871,6 @@ sub bdump {
<br> <br>
<br> <br>
</li>
<li><b> delEntries [&lt;no&gt;[:&lt;nn&gt;]] </b> - löscht alle oder die durch die <a href="#DbRepattr">Attribute</a> device und/oder <li><b> delEntries [&lt;no&gt;[:&lt;nn&gt;]] </b> - löscht alle oder die durch die <a href="#DbRepattr">Attribute</a> device und/oder
reading definierten Datenbankeinträge. Die Eingrenzung über Timestamps erfolgt reading definierten Datenbankeinträge. Die Eingrenzung über Timestamps erfolgt
folgendermaßen: <br><br> folgendermaßen: <br><br>
@ -15975,84 +16067,92 @@ sub bdump {
<ul><ul> <ul><ul>
<a name="blockinginfo"></a>
<li><b> blockinginfo </b> - Listet die aktuell systemweit laufenden Hintergrundprozesse (BlockingCalls) mit ihren Informationen auf. <li><b> blockinginfo </b> - Listet die aktuell systemweit laufenden Hintergrundprozesse (BlockingCalls) mit ihren Informationen auf.
Zu lange Zeichenketten (z.B. Argumente) werden gekürzt ausgeschrieben. Zu lange Zeichenketten (z.B. Argumente) werden gekürzt ausgeschrieben.
</li> </li>
<br><br> <br><br>
<a name="dbstatus"></a>
<li><b> dbstatus </b> - Listet globale Informationen zum MySQL Serverstatus (z.B. Informationen zum Cache, Threads, Bufferpools, etc. ). <li><b> dbstatus </b> - Listet globale Informationen zum MySQL Serverstatus (z.B. Informationen zum Cache, Threads, Bufferpools, etc. ).
Es werden zunächst alle verfügbaren Informationen berichtet. Mit dem <a href="#DbRepattr">Attribut</a> "showStatus" kann die Es werden zunächst alle verfügbaren Informationen berichtet. Mit dem Attribut <a href="#showStatus">showStatus</a> kann die
Ergebnismenge eingeschränkt werden, um nur gewünschte Ergebnisse abzurufen. Detailinformationen zur Bedeutung der einzelnen Readings Ergebnismenge eingeschränkt werden, um nur gewünschte Ergebnisse abzurufen. Detailinformationen zur Bedeutung der einzelnen Readings
sind <a href=http://dev.mysql.com/doc/refman/5.7/en/server-status-variables.html>hier</a> verfügbar. <br> sind <a href="http://dev.mysql.com/doc/refman/5.7/en/server-status-variables.html">hier</a> verfügbar. <br><br>
<br><ul> <ul>
<b>Bespiel</b> <br> <b>Beispiel</b> <br>
get &lt;name&gt; dbstatus <br>
attr &lt;name&gt; showStatus %uptime%,%qcache% <br> attr &lt;name&gt; showStatus %uptime%,%qcache% <br>
# Es werden nur Readings erzeugt die im Namen "uptime" und "qcache" enthalten get &lt;name&gt; dbstatus <br>
# Es werden nur Readings erzeugt die im Namen "uptime" und "qcache" enthaltenen
</ul>
</li> </li>
<br><br> <br><br>
</ul>
<li><b> dbValue &lt;SQL-Statement&gt;</b> - <a name="sqlCmdBlocking"></a>
Führt das angegebene SQL-Statement <b>blockierend</b> aus. Diese Funktion ist durch ihre Arbeitsweise <li><b> sqlCmdBlocking &lt;SQL-Statement&gt;</b> -
speziell für den Einsatz in benutzerspezifischen Scripten geeignet. <br> Führt das angegebene SQL-Statement <b>blockierend</b> mit einem Standardtimeout von 10 Sekunden aus.
Der Timeout kann mit dem Attribut <a href="#dbreptimeout">timeout</a> eingestellt werden.
<br><br>
<ul>
<b>Beispiele:</b> <br>
{ fhem("get &lt;name&gt; sqlCmdBlocking select device,count(*) from history where timestamp > '2018-04-01' group by device") } <br>
{ CommandGet(undef,"Rep.LogDB1 sqlCmdBlocking select device,count(*) from history where timestamp > '2018-04-01' group by device") } <br>
get &lt;name&gt; sqlCmdBlocking select device,count(*) from history where timestamp > '2018-04-01' group by device <br>
</ul>
</li>
<br>
Diese Funktion ist durch ihre Arbeitsweise speziell für den Einsatz in benutzerspezifischen Scripten geeignet. <br>
Die Eingabe akzeptiert Mehrzeiler und gibt ebenso mehrzeilige Ergebisse zurück. Die Eingabe akzeptiert Mehrzeiler und gibt ebenso mehrzeilige Ergebisse zurück.
Dieses Kommando akzeptiert ebenfalls das Setzen von SQL Session Variablen wie z.B. Dieses Kommando akzeptiert ebenfalls das Setzen von SQL Session Variablen wie z.B.
"SET @open:=NULL, @closed:=NULL;". <br> "SET @open:=NULL, @closed:=NULL;". <br>
Werden mehrere Felder selektiert und zurückgegeben, erfolgt die Feldtrennung mit dem Trenner Werden mehrere Felder selektiert und zurückgegeben, erfolgt die Feldtrennung mit dem Trenner
des <a href="#DbRepattr">Attributes</a> "sqlResultFieldSep" (default "|"). Mehrere Ergebniszeilen des Attributs <a href="#sqlResultFieldSep">sqlResultFieldSep</a> (default "|"). Mehrere Ergebniszeilen
werden mit Newline ("\n") separiert. <br> werden mit Newline ("\n") separiert. <br>
Diese Funktion setzt/aktualisiert nur Statusreadings, die Funktion im Attribut "userExitFn" Diese Funktion setzt/aktualisiert nur Statusreadings, die Funktion im Attribut "userExitFn"
wird nicht aufgerufen. wird nicht aufgerufen.
<br>
<br><ul>
<b>Bespiele zur Nutzung im FHEMWEB</b> <br>
{fhem("get &lt;name&gt; dbValue select device,count(*) from history where timestamp > '2018-04-01' group by device")} <br>
get &lt;name&gt; dbValue select device,count(*) from history where timestamp > '2018-04-01' group by device <br>
{CommandGet(undef,"Rep.LogDB1 dbValue select device,count(*) from history where timestamp > '2018-04-01' group by device")} <br>
</ul>
<br><br> <br><br>
Erstellt man eine kleine Routine in 99_myUtils, wie z.B.: Erstellt man eine kleine Routine in 99_myUtils, wie z.B.:
<br> <br>
<pre> <pre>
sub dbval($$) { sub dbval {
my ($name,$cmd) = @_; my $name = shift;
my $ret = CommandGet(undef,"$name dbValue $cmd"); my $cmd = shift;
return $ret; my $ret = CommandGet(undef,"$name sqlCmdBlocking $cmd");
return $ret;
} }
</pre> </pre>
kann dbValue vereinfacht verwendet werden mit Aufrufen wie: kann sqlCmdBlocking vereinfacht verwendet werden mit Aufrufen wie:
<br><br> <br><br>
<ul> <ul>
<b>Bespiele</b> <br> <b>Beispiele:</b> <br>
{dbval("&lt;name&gt;","select count(*) from history")} <br> { dbval("&lt;name&gt;","select count(*) from history") } <br>
oder <br> oder <br>
$ret = dbval("&lt;name&gt;","select count(*) from history"); <br> $ret = dbval("&lt;name&gt;","select count(*) from history"); <br>
</ul> </ul>
</li>
<br><br> <br><br>
<a name="dbvars"></a>
<li><b> dbvars </b> - Zeigt die globalen Werte der MySQL Systemvariablen. Enthalten sind zum Beispiel Angaben zum InnoDB-Home, dem Datafile-Pfad, <li><b> dbvars </b> - Zeigt die globalen Werte der MySQL Systemvariablen. Enthalten sind zum Beispiel Angaben zum InnoDB-Home, dem Datafile-Pfad,
Memory- und Cache-Parameter, usw. Die Ausgabe listet zunächst alle verfügbaren Informationen auf. Mit dem Memory- und Cache-Parameter, usw. Die Ausgabe listet zunächst alle verfügbaren Informationen auf. Mit dem Attribut
<a href="#DbRepattr">Attribut</a> "showVariables" kann die Ergebnismenge eingeschränkt werden um nur gewünschte Ergebnisse <a href="#showVariables">showVariables</a> kann die Ergebnismenge eingeschränkt werden um nur gewünschte Ergebnisse
abzurufen. Weitere Informationen zur Bedeutung der ausgegebenen Variablen sind abzurufen. Weitere Informationen zur Bedeutung der ausgegebenen Variablen sind
<a href=http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html>hier</a> verfügbar. <br> <a href="http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html">hier</a> verfügbar. <br><br>
<br><ul> <ul>
<b>Bespiel</b> <br> <b>Beispiel</b> <br>
get &lt;name&gt; dbvars <br>
attr &lt;name&gt; showVariables %version%,%query_cache% <br> attr &lt;name&gt; showVariables %version%,%query_cache% <br>
get &lt;name&gt; dbvars <br>
# Es werden nur Readings erzeugt die im Namen "version" und "query_cache" enthalten # Es werden nur Readings erzeugt die im Namen "version" und "query_cache" enthalten
</ul>
</li> </li>
<br><br> <br><br>
</ul>
<a name="minTimestamp"></a>
<li><b> minTimestamp </b> - Ermittelt den Zeitstempel des ältesten Datensatzes in der Datenbank (wird implizit beim Start von <li><b> minTimestamp </b> - Ermittelt den Zeitstempel des ältesten Datensatzes in der Datenbank (wird implizit beim Start von
FHEM ausgeführt). FHEM ausgeführt).
Der Zeitstempel wird als Selektionsbeginn verwendet wenn kein Zeitattribut den Selektionsbeginn Der Zeitstempel wird als Selektionsbeginn verwendet wenn kein Zeitattribut den Selektionsbeginn
@ -16060,6 +16160,7 @@ return $ret;
</li> </li>
<br><br> <br><br>
<a name="procinfo"></a>
<li><b> procinfo </b> - Listet die existierenden Datenbank-Prozesse in einer Tabelle auf (nur MySQL). <br> <li><b> procinfo </b> - Listet die existierenden Datenbank-Prozesse in einer Tabelle auf (nur MySQL). <br>
Typischerweise werden nur die Prozesse des Verbindungsusers (angegeben in DbLog-Konfiguration) Typischerweise werden nur die Prozesse des Verbindungsusers (angegeben in DbLog-Konfiguration)
ausgegeben. Sollen alle Prozesse angezeigt werden, ist dem User das globale Recht "PROCESS" ausgegeben. Sollen alle Prozesse angezeigt werden, ist dem User das globale Recht "PROCESS"
@ -16067,51 +16168,67 @@ return $ret;
Für bestimmte SQL-Statements wird seit MariaDB 5.3 ein Fortschrittsreporting (Spalte "PROGRESS") Für bestimmte SQL-Statements wird seit MariaDB 5.3 ein Fortschrittsreporting (Spalte "PROGRESS")
ausgegeben. Zum Beispiel kann der Abarbeitungsgrad bei der Indexerstellung verfolgt werden. <br> ausgegeben. Zum Beispiel kann der Abarbeitungsgrad bei der Indexerstellung verfolgt werden. <br>
Weitere Informationen sind Weitere Informationen sind
<a href=https://mariadb.com/kb/en/mariadb/show-processlist/>hier</a> verfügbar. <br> <a href="https://mariadb.com/kb/en/mariadb/show-processlist/">hier</a> verfügbar. <br>
</li> </li>
<br><br> <br><br>
<a name="storedCredentials"></a>
<li><b> storedCredentials </b> - Listet die im Device gespeicherten User / Passworte für den Datenbankzugriff auf. <br> <li><b> storedCredentials </b> - Listet die im Device gespeicherten User / Passworte für den Datenbankzugriff auf. <br>
(nur gültig bei Datenbanktyp MYSQL) (nur gültig bei Datenbanktyp MYSQL)
</li> </li>
<br><br> <br><br>
<a name="svrinfo"></a>
<li><b> svrinfo </b> - allgemeine Datenbankserver-Informationen wie z.B. die DBMS-Version, Serveradresse und Port usw. Die Menge der Listenelemente <li><b> svrinfo </b> - allgemeine Datenbankserver-Informationen wie z.B. die DBMS-Version, Serveradresse und Port usw. Die Menge der Listenelemente
ist vom Datenbanktyp abhängig. Mit dem <a href="#DbRepattr">Attribut</a> "showSvrInfo" kann die Ergebnismenge eingeschränkt werden. ist vom Datenbanktyp abhängig. Mit dem Attribut <a href="#showSvrInfo">showSvrInfo</a> kann die Ergebnismenge eingeschränkt werden.
Weitere Erläuterungen zu den gelieferten Informationen sind Weitere Erläuterungen zu den gelieferten Informationen sind
<a href=https://msdn.microsoft.com/en-us/library/ms711681(v=vs.85).aspx>hier</a> zu finden. <br> <a href="https://msdn.microsoft.com/en-us/library/ms711681(v=vs.85).aspx">hier</a> zu finden. <br><br>
<br><ul> <ul>
<b>Bespiel</b> <br> <b>Beispiel</b> <br>
get &lt;name&gt; svrinfo <br>
attr &lt;name&gt; showSvrInfo %SQL_CATALOG_TERM%,%NAME% <br> attr &lt;name&gt; showSvrInfo %SQL_CATALOG_TERM%,%NAME% <br>
get &lt;name&gt; svrinfo <br>
# Es werden nur Readings erzeugt die im Namen "SQL_CATALOG_TERM" und "NAME" enthalten # Es werden nur Readings erzeugt die im Namen "SQL_CATALOG_TERM" und "NAME" enthalten
</ul>
</li> </li>
<br><br> <br><br>
</ul>
<a name="tableinfo"></a>
<li><b> tableinfo </b> - ruft Tabelleninformationen aus der mit dem DbRep-Device verbundenen Datenbank ab (MySQL). <li><b> tableinfo </b> - ruft Tabelleninformationen aus der mit dem DbRep-Device verbundenen Datenbank ab (MySQL).
Es werden per default alle in der verbundenen Datenbank angelegten Tabellen ausgewertet. Es werden per default alle in der verbundenen Datenbank angelegten Tabellen ausgewertet.
Mit dem <a href="#DbRepattr">Attribut</a> "showTableInfo" können die Ergebnisse eingeschränkt werden. Erläuterungen zu den erzeugten Mit dem Attribut <a href="#showTableInfo">showTableInfo</a> können die Ergebnisse eingeschränkt werden. Erläuterungen zu den erzeugten
Readings sind <a href=http://dev.mysql.com/doc/refman/5.7/en/show-table-status.html>hier</a> zu finden. <br> Readings sind <a href="http://dev.mysql.com/doc/refman/5.7/en/show-table-status.html">hier</a> zu finden. <br><br>
<br><ul> <ul>
<b>Bespiel</b> <br> <b>Beispiel</b> <br>
get &lt;name&gt; tableinfo <br>
attr &lt;name&gt; showTableInfo current,history <br> attr &lt;name&gt; showTableInfo current,history <br>
get &lt;name&gt; tableinfo <br>
# Es werden nur Information der Tabellen "current" und "history" angezeigt # Es werden nur Information der Tabellen "current" und "history" angezeigt
</ul>
</li> </li>
<br><br> <br><br>
<a name="versionNotes"></a>
<li><b> versionNotes [hints | rel | &lt;key&gt;] </b> -
Zeigt Release Informationen und/oder Hinweise zum Modul an.
<br><br>
<ul>
<table>
<colgroup> <col width=5%> <col width=95%> </colgroup>
<tr><td> rel </td><td>: zeigt nur Release Informationen </td></tr>
<tr><td> hints </td><td>: zeigt nur Hinweise an </td></tr>
<tr><td> &lt;key&gt; </td><td>: es wird der Hinweis mit der angegebenen Nummer angezeigt </td></tr>
</table>
</ul> </ul>
<li><b> versionNotes [hints | rel | &lt;key&gt;] </b> -
Zeigt Release Informationen und/oder Hinweise zum Modul an. Es sind nur Release Informationen mit
Bedeutung für den Modulnutzer enthalten. <br>
Sind keine Optionen angegben, werden sowohl Release Informationen als auch Hinweise angezeigt.
"rel" zeigt nur Release Informationen und "hints" nur Hinweise an. Mit der &lt;key&gt;-Angabe
wird der Hinweis mit der angegebenen Nummer angezeigt.
</li> </li>
<br>
Sind keine Optionen angegeben, werden sowohl Release Informationen als auch Hinweise angezeigt.
Es sind nur Release Informationen mit Bedeutung für den Modulnutzer enthalten. <br>
<br> <br>
</ul></ul> </ul></ul>
@ -16826,7 +16943,7 @@ sub bdump {
<br><br> <br><br>
</li> </li>
<a name="timeout"></a> <a name="dbreptimeout"></a>
<li><b>timeout </b> - das Attribut setzt den Timeout-Wert für die Blocking-Call Routinen in Sekunden <li><b>timeout </b> - das Attribut setzt den Timeout-Wert für die Blocking-Call Routinen in Sekunden
(Default: 86400) </li> <br> (Default: 86400) </li> <br>