mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
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:
parent
d17f030cd0
commit
a4e65e762a
4
CHANGED
4
CHANGED
@ -1,5 +1,9 @@
|
||||
# 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.
|
||||
- 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
|
||||
- change: 50_TelegramBot: channels, versionid, keyboard / favorite fixes
|
||||
- change: 93_DbRep: commandRef revised
|
||||
|
495
FHEM/93_DbRep.pm
495
FHEM/93_DbRep.pm
@ -41,8 +41,8 @@ package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use POSIX qw(strftime);
|
||||
use Time::HiRes qw(gettimeofday tv_interval);
|
||||
use POSIX qw(strftime SIGALRM);
|
||||
use Time::HiRes qw(gettimeofday tv_interval ualarm);
|
||||
use Scalar::Util qw(looks_like_number);
|
||||
eval "use DBI;1" or my $DbRepMMDBI = "DBI";
|
||||
eval "use FHEM::Meta;1" or my $modMetaAbsent = 1;
|
||||
@ -57,6 +57,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch';
|
||||
|
||||
# Version History intern
|
||||
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.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 ",
|
||||
@ -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 ".
|
||||
"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.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.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 ",
|
||||
@ -127,7 +128,7 @@ our %DbRep_vNotesIntern = (
|
||||
"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.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.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"
|
||||
@ -135,6 +136,9 @@ our %DbRep_vNotesIntern = (
|
||||
|
||||
# Version History extern:
|
||||
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'. ".
|
||||
"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> ",
|
||||
@ -960,7 +964,7 @@ sub DbRep_Get {
|
||||
"blockinginfo:noArg ".
|
||||
"minTimestamp:noArg ".
|
||||
(($dbmodel =~ /MYSQL/)?"storedCredentials:noArg ":"").
|
||||
"dbValue:textField-long ".
|
||||
"sqlCmdBlocking:textField-long ".
|
||||
(($dbmodel eq "MYSQL")?"dbstatus:noArg ":"").
|
||||
(($dbmodel eq "MYSQL")?"tableinfo:noArg ":"").
|
||||
(($dbmodel eq "MYSQL")?"procinfo:noArg ":"").
|
||||
@ -1008,18 +1012,27 @@ sub DbRep_Get {
|
||||
$prop = $prop?$prop:'';
|
||||
DbRep_firstconnect("$name|$opt|$prop|");
|
||||
|
||||
} elsif ($opt =~ /dbValue/) {
|
||||
return "get \"$opt\" needs at least an argument" if ( @a < 3 );
|
||||
} elsif ($opt =~ /sqlCmdBlocking|dbValue/) {
|
||||
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;
|
||||
shift @cmd; shift @cmd;
|
||||
my $sqlcmd = join(" ",@cmd);
|
||||
|
||||
my $sqlcmd = join " ", @cmd;
|
||||
$sqlcmd =~ tr/ A-Za-z0-9!"#$§%&'()*+,-.\/:;<=>?@[\\]^_`{|}~äöüÄÖÜ߀/ /cs;
|
||||
$hash->{LASTCMD} = $sqlcmd?"$opt $sqlcmd":"$opt";
|
||||
if ($sqlcmd =~ m/^\s*delete/is && !AttrVal($hash->{NAME}, "allowDeletion", undef)) {
|
||||
$hash->{LASTCMD} = $sqlcmd ? "$opt $sqlcmd" : "$opt";
|
||||
|
||||
if ($sqlcmd =~ m/^\s*delete/is && !AttrVal($name, "allowDeletion", undef)) {
|
||||
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") {
|
||||
# Credentials abrufen
|
||||
@ -1094,8 +1107,7 @@ sub DbRep_Get {
|
||||
$ret .= "</div>";
|
||||
}
|
||||
|
||||
# Notes
|
||||
if(!$prop || $prop =~ /rel/) {
|
||||
if(!$prop || $prop =~ /rel/) { # Notes
|
||||
$ret .= sprintf("<div class=\"makeTable wide\"; style=\"text-align:left\">$header <br>");
|
||||
$ret .= "<table class=\"block wide internals\">";
|
||||
$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 .= "</tr>";
|
||||
$i++;
|
||||
if ($i & 1) {
|
||||
# $i ist ungerade
|
||||
if ($i & 1) { # $i ist ungerade
|
||||
$ret .= "<tr class=\"odd\">";
|
||||
} else {
|
||||
$ret .= "<tr class=\"even\">";
|
||||
@ -11511,43 +11522,51 @@ return;
|
||||
# blockierende DB-Abfrage
|
||||
# liefert Ergebnis sofort zurück, setzt keine Readings
|
||||
####################################################################################################
|
||||
sub DbRep_dbValue {
|
||||
my ($name,$cmd) = @_;
|
||||
sub DbRep_sqlCmdBlocking {
|
||||
my $name = shift;
|
||||
my $cmd = shift;
|
||||
my $hash = $defs{$name};
|
||||
my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}};
|
||||
my $dbconn = $dbloghash->{dbconn};
|
||||
my $dbuser = $dbloghash->{dbuser};
|
||||
my $dblogname = $dbloghash->{NAME};
|
||||
my $dbpassword = $attr{"sec$dblogname"}{secret};
|
||||
my $utf8 = defined($hash->{UTF8})?$hash->{UTF8}:0;
|
||||
my $srs = AttrVal($name, "sqlResultFieldSep", "|");
|
||||
my $utf8 = $hash->{UTF8} // 0;
|
||||
|
||||
my $srs = AttrVal($name, "sqlResultFieldSep", "|" );
|
||||
my $to = AttrVal($name, "timeout", 10 );
|
||||
|
||||
my ($err,$ret,$dbh);
|
||||
|
||||
readingsDelete($hash, "errortext");
|
||||
readingsDelete ($hash, "errortext");
|
||||
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 ($@) {
|
||||
$err = $@;
|
||||
Log3 ($name, 2, "DbRep $name - $err");
|
||||
ReadingsSingleUpdateValue ($hash, "errortext", $err, 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 - Command: dbValue");
|
||||
Log3 ($name, 4, "DbRep $name - Command: sqlCmdBlocking");
|
||||
Log3 ($name, 4, "DbRep $name - SQL execute: $sql");
|
||||
|
||||
# split SQL-Parameter Statement falls mitgegeben
|
||||
# z.B. SET @open:=NULL, @closed:=NULL; Select ...
|
||||
my $set;
|
||||
if($cmd =~ /^SET.*;/i) {
|
||||
$cmd =~ m/^(SET.*?;)(.*)/i;
|
||||
if($cmd =~ /^SET.*;/i) { # split SQL-Parameter Statement falls mitgegeben ->
|
||||
$cmd =~ m/^(SET.*?;)(.*)/i; # z.B. SET @open:=NULL, @closed:=NULL; Select ...
|
||||
$set = $1;
|
||||
$sql = $2;
|
||||
}
|
||||
@ -11556,6 +11575,7 @@ sub DbRep_dbValue {
|
||||
Log3($name, 4, "DbRep $name - Set SQL session variables: $set");
|
||||
eval {$dbh->do($set);}; # @\RB = Resetbit wenn neues Selektionsintervall beginnt
|
||||
}
|
||||
|
||||
if ($@) {
|
||||
$err = $@;
|
||||
Log3 ($name, 2, "DbRep $name - $err");
|
||||
@ -11564,21 +11584,45 @@ sub DbRep_dbValue {
|
||||
return ($err);
|
||||
}
|
||||
|
||||
# SQL-Startzeit
|
||||
my $st = [gettimeofday];
|
||||
my $st = [gettimeofday]; # SQL-Startzeit
|
||||
|
||||
my ($sth,$r);
|
||||
eval {$sth = $dbh->prepare($sql);
|
||||
my $totxt = qq{Timeout occured (limit: $to seconds). You may be able to adjust the "Timeout" attribute.};
|
||||
|
||||
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();
|
||||
1;
|
||||
};
|
||||
alarm(0); # Alarm aufheben (wenn der Code schnell lief)
|
||||
|
||||
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");
|
||||
$sth->finish if($sth);
|
||||
$dbh->disconnect;
|
||||
ReadingsSingleUpdateValue ($hash, "errortext", $err, 1);
|
||||
ReadingsSingleUpdateValue ($hash, "state", "error", 1);
|
||||
return ($err);
|
||||
return $err;
|
||||
}
|
||||
|
||||
my $nrows = 0;
|
||||
@ -11587,8 +11631,7 @@ sub DbRep_dbValue {
|
||||
Log3 ($name, 4, "DbRep $name - SQL result: @line");
|
||||
$ret .= "\n" if($nrows); # Forum: #103295
|
||||
$ret .= join("$srs", @line);
|
||||
# Anzahl der Datensätze
|
||||
$nrows++;
|
||||
$nrows++; # Anzahl der Datensätze
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -11600,7 +11643,7 @@ sub DbRep_dbValue {
|
||||
$dbh->disconnect;
|
||||
ReadingsSingleUpdateValue ($hash, "errortext", $err, 1);
|
||||
ReadingsSingleUpdateValue ($hash, "state", "error", 1);
|
||||
return ($err);
|
||||
return $err;
|
||||
}
|
||||
$ret = $nrows;
|
||||
}
|
||||
@ -11608,18 +11651,16 @@ sub DbRep_dbValue {
|
||||
$sth->finish;
|
||||
$dbh->disconnect;
|
||||
|
||||
# SQL-Laufzeit ermitteln
|
||||
my $rt = tv_interval($st);
|
||||
my $rt = tv_interval($st); # SQL-Laufzeit ermitteln
|
||||
|
||||
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");
|
||||
|
||||
# Readingaufbereitung
|
||||
readingsBeginUpdate($hash);
|
||||
ReadingsBulkUpdateTimeState($hash,undef,$rt,"done");
|
||||
readingsEndUpdate($hash, 1);
|
||||
readingsBeginUpdate ($hash);
|
||||
ReadingsBulkUpdateTimeState ($hash,undef,$rt,"done");
|
||||
readingsEndUpdate ($hash, 1);
|
||||
|
||||
return ($ret);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
####################################################################################################
|
||||
@ -11633,8 +11674,7 @@ return ($ret);
|
||||
sub CommandDbReadingsVal {
|
||||
my ($cl, $param) = @_;
|
||||
|
||||
my @a = split("[ \t][ \t]*", $param);
|
||||
my ($name, $devread, $ts, $default) = @a;
|
||||
my ($name, $devread, $ts, $default) = split m{\s+}x, $param;
|
||||
$ts =~ s/_/ /;
|
||||
|
||||
my $ret = DbReadingsVal($name, $devread, $ts, $default);
|
||||
@ -11643,24 +11683,31 @@ return $ret;
|
||||
}
|
||||
|
||||
sub DbReadingsVal($$$$) {
|
||||
my ($name, $devread, $ts, $default) = @_;
|
||||
my $hash = $defs{$name};
|
||||
my $dbmodel = $defs{$hash->{HELPER}{DBLOGDEVICE}}{MODEL};
|
||||
my $name = shift // return qq{A DbRep-device must be specified};
|
||||
my $devread = shift // return qq{"device:reading" must be specified};
|
||||
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);
|
||||
|
||||
unless(defined($defs{$name})) {
|
||||
return ("DbRep-device \"$name\" doesn't exist.");
|
||||
if(!defined($defs{$name})) {
|
||||
return qq{DbRep-device "$name" doesn't exist.};
|
||||
}
|
||||
unless($defs{$name}{TYPE} eq "DbRep") {
|
||||
return ("\"$name\" is not a DbRep-device but of type \"".$defs{$name}{TYPE}."\"");
|
||||
if(!$defs{$name}{TYPE} eq "DbRep") {
|
||||
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/_/ /;
|
||||
unless($ts =~ /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/) {
|
||||
return ("timestamp has not the valid format. Use \"YYYY-MM-DD hh:mm:ss\" as timestamp.");
|
||||
if($ts !~ /^(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{2})$/x) {
|
||||
return qq{timestamp has not the valid format. Use "YYYY-MM-DD_hh:mm:ss" as timestamp.};
|
||||
}
|
||||
|
||||
my ($dev,$reading) = split(":",$devread);
|
||||
unless($dev && $reading) {
|
||||
return ("device:reading must be specified !");
|
||||
if(!$dev || !$reading) {
|
||||
return qq{"device:reading" must be specified};
|
||||
}
|
||||
|
||||
if($dbmodel eq "MYSQL") {
|
||||
@ -11693,13 +11740,14 @@ sub DbReadingsVal($$$$) {
|
||||
where device='$dev' and reading='$reading' and timestamp < '$ts'
|
||||
)
|
||||
x order by diff limit 1;";
|
||||
|
||||
} else {
|
||||
return ("DbReadingsVal is not implemented for $dbmodel");
|
||||
return qq{DbReadingsVal is not implemented for $dbmodel};
|
||||
}
|
||||
|
||||
$hash->{LASTCMD} = "dbValue $sql";
|
||||
$ret = DbRep_dbValue($name,$sql);
|
||||
$ret = $ret?$ret:$default;
|
||||
$hash->{LASTCMD} = "sqlCmdBlocking $sql";
|
||||
$ret = DbRep_sqlCmdBlocking($name,$sql);
|
||||
$ret = $ret ? $ret : $default;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
@ -11850,7 +11898,7 @@ return;
|
||||
<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> 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> transfer dumpfiles to a FTP server after backup incl. version control</li>
|
||||
<li> restore of SQLite- and MySQL-Dumps non-blocking </li>
|
||||
@ -11877,8 +11925,9 @@ return;
|
||||
<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>.
|
||||
With this function you can, similar to the well known ReadingsVal, get a reading value from database.
|
||||
The function execution is carried out blocking. <br><br>
|
||||
With this function you can, similar to the well known ReadingsVal, get a reading value from database. <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>
|
||||
The command syntax for the Perl function is: <br><br>
|
||||
@ -11888,7 +11937,7 @@ return;
|
||||
</code>
|
||||
<br><br>
|
||||
|
||||
<b>Examples: </b><br>
|
||||
<b>Example: </b><br>
|
||||
<pre>
|
||||
$ret = DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-01-13_08:00:00","");
|
||||
attr <name> userReadings oldtemp {DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-04-13_08:00:00","")}
|
||||
@ -11910,14 +11959,16 @@ return;
|
||||
<br><br>
|
||||
|
||||
<b>Example: </b><br>
|
||||
<code>
|
||||
dbReadingsVal Rep.LogDB1 MyWetter:temperature 2018-01-13_08:00:00 0
|
||||
</code>
|
||||
<br><br>
|
||||
|
||||
<table>
|
||||
<colgroup> <col width=5%> <col width=95%> </colgroup>
|
||||
<tr><td> <b><name></b> </td><td>: name of the DbRep-Device to request </td></tr>
|
||||
<tr><td> <b><device:reading></b> </td><td>: device:reading whose value is to deliver </td></tr>
|
||||
<tr><td> <b><timestamp></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><timestamp></b> </td><td>: timestamp of reading whose value is to deliver (*) in format "YYYY-MM-DD_hh:mm:ss" </td></tr>
|
||||
<tr><td> <b><default></b> </td><td>: default value if no reading value can be retrieved </td></tr>
|
||||
</table>
|
||||
</ul>
|
||||
@ -13376,52 +13427,60 @@ return;
|
||||
<br><br>
|
||||
|
||||
<ul><ul>
|
||||
<a name="blockinginfo"></a>
|
||||
<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.
|
||||
</li>
|
||||
<br><br>
|
||||
|
||||
<li><b> dbstatus </b> - lists global informations about MySQL server status (e.g. informations related to cache, threads, bufferpools, etc. ).
|
||||
Initially all available informations are reported. Using the <a href="#DbRepattr">attribute</a> "showStatus" the quantity of
|
||||
<a name="dbstatus"></a>
|
||||
<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
|
||||
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>
|
||||
get <name> dbstatus <br>
|
||||
attr <name> showStatus %uptime%,%qcache% <br>
|
||||
get <name> dbstatus <br>
|
||||
# Only readings containing "uptime" and "qcache" in name will be created
|
||||
</ul>
|
||||
</li>
|
||||
<br><br>
|
||||
</ul>
|
||||
|
||||
<li><b> dbValue <SQL-statement></b> -
|
||||
Executes the specified SQL-statement in <b>blocking</b> manner. Because of its mode of operation
|
||||
this function is particular convenient for user own perl scripts. <br>
|
||||
<a name="sqlCmdBlocking"></a>
|
||||
<li><b> sqlCmdBlocking <SQL-statement></b> -
|
||||
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 <name> 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 <name> 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.
|
||||
This command also accept the setting of SQL session variables like "SET @open:=NULL,
|
||||
@closed:=NULL;". <br>
|
||||
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>
|
||||
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 <name> dbValue select device,count(*) from history where timestamp > '2018-04-01' group by device")} <br>
|
||||
get <name> 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>
|
||||
|
||||
If you create a little routine in 99_myUtils, for example:
|
||||
<br>
|
||||
<pre>
|
||||
sub dbval($$) {
|
||||
my ($name,$cmd) = @_;
|
||||
my $ret = CommandGet(undef,"$name dbValue $cmd");
|
||||
return $ret;
|
||||
sub dbval {
|
||||
my $name = shift;
|
||||
my $cmd) = shift;
|
||||
my $ret = CommandGet(undef,"$name sqlCmdBlocking $cmd");
|
||||
return $ret;
|
||||
}
|
||||
</pre>
|
||||
it can be accessed with e.g. those calls:
|
||||
@ -13429,34 +13488,36 @@ return $ret;
|
||||
|
||||
<ul>
|
||||
<b>Examples:</b> <br>
|
||||
{dbval("<name>","select count(*) from history")} <br>
|
||||
{ dbval("<name>","select count(*) from history") } <br>
|
||||
$ret = dbval("<name>","select count(*) from history"); <br>
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
<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,
|
||||
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
|
||||
<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>
|
||||
get <name> dbvars <br>
|
||||
attr <name> showVariables %version%,%query_cache% <br>
|
||||
get <name> dbvars <br>
|
||||
# Only readings containing "version" and "query_cache" in name will be created
|
||||
</ul>
|
||||
</li>
|
||||
<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).
|
||||
The timestamp is used as begin of data selection if no time attribut is set to determine the
|
||||
start date.
|
||||
</li>
|
||||
<br><br>
|
||||
|
||||
<a name="procinfo"></a>
|
||||
<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
|
||||
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
|
||||
creation. <br>
|
||||
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>
|
||||
<br><br>
|
||||
|
||||
<a name="storedCredentials"></a>
|
||||
<li><b> storedCredentials </b> - Reports the users / passwords stored for database access by the device. <br>
|
||||
(only valid if database type is MYSQL)
|
||||
</li>
|
||||
<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
|
||||
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
|
||||
<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>
|
||||
get <name> svrinfo <br>
|
||||
attr <name> showSvrInfo %SQL_CATALOG_TERM%,%NAME% <br>
|
||||
get <name> svrinfo <br>
|
||||
# Only readings containing "SQL_CATALOG_TERM" and "NAME" in name will be created
|
||||
</ul>
|
||||
</li>
|
||||
<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.
|
||||
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.
|
||||
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>
|
||||
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">here</a>. <br><br>
|
||||
|
||||
<br><ul>
|
||||
<ul>
|
||||
<b>Example</b> <br>
|
||||
get <name> tableinfo <br>
|
||||
attr <name> showTableInfo current,history <br>
|
||||
get <name> tableinfo <br>
|
||||
# Only informations related to tables "current" and "history" are going to be created
|
||||
</ul>
|
||||
</li>
|
||||
<br><br>
|
||||
|
||||
<a name="versionNotes"></a>
|
||||
<li><b> versionNotes [hints | rel | <key>] </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> <key> </td><td>: the note with the specified number is displayed </td></tr>
|
||||
</table>
|
||||
</ul>
|
||||
|
||||
<li><b> versionNotes [hints | rel | <key>] </b> -
|
||||
Shows realease informations and/or hints about the module. It contains only main release
|
||||
informations for module users. <br>
|
||||
</li>
|
||||
|
||||
<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
|
||||
only release informations and "hints" shows only hints. By the <key>-specification only
|
||||
the hint with the specified number is shown.
|
||||
</li>
|
||||
<br>
|
||||
|
||||
</ul></ul>
|
||||
@ -14219,7 +14300,7 @@ sub bdump {
|
||||
<br><br>
|
||||
</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>
|
||||
|
||||
<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"
|
||||
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 (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> senden des Dumpfiles zu einem FTP-Server nach dem Backup incl. Versionsverwaltung </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
|
||||
<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.
|
||||
Die Funktionsausführung erfolgt blockierend. <br><br>
|
||||
Mit dieser Funktion läßt sich, ähnlich dem allgemeinen ReadingsVal, der Wert eines Readings aus der Datenbank abrufen. <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>
|
||||
Die Befehlssyntax für die Perl Funktion ist: <br><br>
|
||||
@ -14453,7 +14535,7 @@ sub bdump {
|
||||
</code>
|
||||
<br><br>
|
||||
|
||||
<b>Beispiele: </b><br>
|
||||
<b>Beispiel: </b><br>
|
||||
<pre>
|
||||
$ret = DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-01-13_08:00:00","");
|
||||
attr <name> userReadings oldtemp {DbReadingsVal("Rep.LogDB1","MyWetter:temperature","2018-04-13_08:00:00","")}
|
||||
@ -14475,7 +14557,9 @@ sub bdump {
|
||||
<br><br>
|
||||
|
||||
<b>Beispiel: </b><br>
|
||||
<code>
|
||||
dbReadingsVal Rep.LogDB1 MyWetter:temperature 2018-01-13_08:00:00 0
|
||||
</code>
|
||||
<br><br>
|
||||
|
||||
<table>
|
||||
@ -14556,23 +14640,24 @@ sub bdump {
|
||||
|
||||
<ul><ul>
|
||||
|
||||
|
||||
<li><b> adminCredentials <User> <Passwort> </b>
|
||||
- Speichert einen User / Passwort für den privilegierten bzw. administrativen
|
||||
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>
|
||||
(nur gültig bei Datenbanktyp MYSQL und DbRep-Typ "Client")
|
||||
|
||||
</li> <br>
|
||||
|
||||
|
||||
<li><b> averageValue [display | writeToDB | writeToDBSingle | writeToDBInTime]</b>
|
||||
- berechnet einen Durchschnittswert des Datenbankfelds "VALUE" in den Zeitgrenzen
|
||||
der möglichen time.*-Attribute. <br><br>
|
||||
</li>
|
||||
|
||||
Es muss das auszuwertende Reading im Attribut <a href="#reading">reading</a>
|
||||
angegeben sein.
|
||||
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
|
||||
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>
|
||||
@ -14620,23 +14705,25 @@ sub bdump {
|
||||
<br>
|
||||
<br>
|
||||
|
||||
</li> <br>
|
||||
<br>
|
||||
|
||||
|
||||
<li><b> cancelDump </b> - bricht einen laufenden Datenbankdump ab. </li> <br>
|
||||
|
||||
|
||||
<li><b> changeValue </b> - ändert den gespeicherten Wert eines Readings.
|
||||
Ist die Selektion auf bestimmte Device/Reading-Kombinationen durch die
|
||||
<a href="#DbRepattr">Attribute</a> "device" bzw. "reading" beschränkt, werden sie genauso
|
||||
Ist die Selektion auf bestimmte Device/Reading-Kombinationen durch die Attribute
|
||||
<a href="#device">device</a> bzw. <a href="#reading">reading</a> beschränkt, werden sie genauso
|
||||
berücksichtigt wie gesetzte Zeitgrenzen (Attribute time.*). <br>
|
||||
Fehlen diese Beschränkungen, wird die gesamte Datenbank durchsucht und der angegebene Wert
|
||||
geändert. <br><br>
|
||||
</li>
|
||||
|
||||
<ul>
|
||||
<b>Syntax: </b> <br>
|
||||
set <name> changeValue "<alter String>","<neuer String>" <br><br>
|
||||
|
||||
Die Strings werden in Doppelstrich eingeschlossen und durch Komma getrennt.
|
||||
Dabei kann "String" sein: <br>
|
||||
"String" kann sein: <br>
|
||||
|
||||
<table>
|
||||
<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
|
||||
VALUE bzw. UNIT des Datensatzes gespeichert. </li></td></tr>
|
||||
</table>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<ul>
|
||||
<b>Beispiele: </b> <br>
|
||||
set <name> changeValue "OL","12 OL" <br>
|
||||
# der alte Feldwert "OL" wird in "12 OL" geändert. <br><br>
|
||||
@ -14686,15 +14775,18 @@ sub bdump {
|
||||
<b>Hinweis:</b> <br>
|
||||
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>
|
||||
</li> <br>
|
||||
<br>
|
||||
</ul>
|
||||
|
||||
|
||||
<li><b> countEntries [history | current] </b>
|
||||
- liefert die Anzahl der Tabelleneinträge (default: history) in den gegebenen
|
||||
Zeitgrenzen (siehe <a href="#DbRepattr">Attribute</a>).
|
||||
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>
|
||||
</li>
|
||||
|
||||
Standardmäßig wird die Summe aller Datensätze, gekennzeichnet mit "ALLREADINGS", erstellt.
|
||||
Ist das Attribut "countEntriesDetail" gesetzt, wird die Anzahl jedes einzelnen Readings
|
||||
zusätzlich ausgegeben. <br><br>
|
||||
@ -14715,7 +14807,8 @@ sub bdump {
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
</li> <br>
|
||||
<br>
|
||||
|
||||
|
||||
<li><b> delDoublets [adviceDelete | delete]</b> - zeigt bzw. löscht doppelte / mehrfach vorkommende Datensätze.
|
||||
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
|
||||
"day" verwendet.
|
||||
<br><br>
|
||||
</li>
|
||||
|
||||
<ul>
|
||||
<table>
|
||||
@ -14733,15 +14827,15 @@ sub bdump {
|
||||
</ul>
|
||||
<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>
|
||||
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.
|
||||
Die Einstellung von "limit" hat keinen Einfluss auf die "delDoublets delete" Funktion, sondern
|
||||
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
|
||||
werden. (siehe <a href="#DbRepattr">Attribute</a> "executeBeforeProc", "executeAfterProc")
|
||||
werden. (siehe Attribute <a href="#executeBeforeProc">executeBeforeProc</a>, <a href="#executeAfterProc">executeAfterProc</a>)
|
||||
<br><br>
|
||||
|
||||
<ul>
|
||||
@ -14777,8 +14871,6 @@ sub bdump {
|
||||
<br>
|
||||
<br>
|
||||
|
||||
</li>
|
||||
|
||||
<li><b> delEntries [<no>[:<nn>]] </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
|
||||
folgendermaßen: <br><br>
|
||||
@ -15975,84 +16067,92 @@ sub bdump {
|
||||
|
||||
|
||||
<ul><ul>
|
||||
<a name="blockinginfo"></a>
|
||||
<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.
|
||||
</li>
|
||||
<br><br>
|
||||
|
||||
<a name="dbstatus"></a>
|
||||
<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
|
||||
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>
|
||||
<b>Bespiel</b> <br>
|
||||
get <name> dbstatus <br>
|
||||
<ul>
|
||||
<b>Beispiel</b> <br>
|
||||
attr <name> showStatus %uptime%,%qcache% <br>
|
||||
# Es werden nur Readings erzeugt die im Namen "uptime" und "qcache" enthalten
|
||||
get <name> dbstatus <br>
|
||||
# Es werden nur Readings erzeugt die im Namen "uptime" und "qcache" enthaltenen
|
||||
</ul>
|
||||
</li>
|
||||
<br><br>
|
||||
</ul>
|
||||
|
||||
<li><b> dbValue <SQL-Statement></b> -
|
||||
Führt das angegebene SQL-Statement <b>blockierend</b> aus. Diese Funktion ist durch ihre Arbeitsweise
|
||||
speziell für den Einsatz in benutzerspezifischen Scripten geeignet. <br>
|
||||
<a name="sqlCmdBlocking"></a>
|
||||
<li><b> sqlCmdBlocking <SQL-Statement></b> -
|
||||
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 <name> 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 <name> 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.
|
||||
Dieses Kommando akzeptiert ebenfalls das Setzen von SQL Session Variablen wie z.B.
|
||||
"SET @open:=NULL, @closed:=NULL;". <br>
|
||||
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>
|
||||
Diese Funktion setzt/aktualisiert nur Statusreadings, die Funktion im Attribut "userExitFn"
|
||||
wird nicht aufgerufen.
|
||||
<br>
|
||||
|
||||
<br><ul>
|
||||
<b>Bespiele zur Nutzung im FHEMWEB</b> <br>
|
||||
{fhem("get <name> dbValue select device,count(*) from history where timestamp > '2018-04-01' group by device")} <br>
|
||||
get <name> 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>
|
||||
|
||||
Erstellt man eine kleine Routine in 99_myUtils, wie z.B.:
|
||||
<br>
|
||||
<pre>
|
||||
sub dbval($$) {
|
||||
my ($name,$cmd) = @_;
|
||||
my $ret = CommandGet(undef,"$name dbValue $cmd");
|
||||
return $ret;
|
||||
sub dbval {
|
||||
my $name = shift;
|
||||
my $cmd = shift;
|
||||
my $ret = CommandGet(undef,"$name sqlCmdBlocking $cmd");
|
||||
return $ret;
|
||||
}
|
||||
</pre>
|
||||
kann dbValue vereinfacht verwendet werden mit Aufrufen wie:
|
||||
kann sqlCmdBlocking vereinfacht verwendet werden mit Aufrufen wie:
|
||||
<br><br>
|
||||
|
||||
<ul>
|
||||
<b>Bespiele</b> <br>
|
||||
{dbval("<name>","select count(*) from history")} <br>
|
||||
<b>Beispiele:</b> <br>
|
||||
{ dbval("<name>","select count(*) from history") } <br>
|
||||
oder <br>
|
||||
$ret = dbval("<name>","select count(*) from history"); <br>
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
<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,
|
||||
Memory- und Cache-Parameter, usw. Die Ausgabe listet zunächst alle verfügbaren Informationen auf. Mit dem
|
||||
<a href="#DbRepattr">Attribut</a> "showVariables" kann die Ergebnismenge eingeschränkt werden um nur gewünschte Ergebnisse
|
||||
Memory- und Cache-Parameter, usw. Die Ausgabe listet zunächst alle verfügbaren Informationen auf. Mit dem Attribut
|
||||
<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
|
||||
<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>
|
||||
<b>Bespiel</b> <br>
|
||||
get <name> dbvars <br>
|
||||
<ul>
|
||||
<b>Beispiel</b> <br>
|
||||
attr <name> showVariables %version%,%query_cache% <br>
|
||||
get <name> dbvars <br>
|
||||
# Es werden nur Readings erzeugt die im Namen "version" und "query_cache" enthalten
|
||||
</ul>
|
||||
</li>
|
||||
<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
|
||||
FHEM ausgeführt).
|
||||
Der Zeitstempel wird als Selektionsbeginn verwendet wenn kein Zeitattribut den Selektionsbeginn
|
||||
@ -16060,6 +16160,7 @@ return $ret;
|
||||
</li>
|
||||
<br><br>
|
||||
|
||||
<a name="procinfo"></a>
|
||||
<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)
|
||||
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")
|
||||
ausgegeben. Zum Beispiel kann der Abarbeitungsgrad bei der Indexerstellung verfolgt werden. <br>
|
||||
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>
|
||||
<br><br>
|
||||
|
||||
<a name="storedCredentials"></a>
|
||||
<li><b> storedCredentials </b> - Listet die im Device gespeicherten User / Passworte für den Datenbankzugriff auf. <br>
|
||||
(nur gültig bei Datenbanktyp MYSQL)
|
||||
</li>
|
||||
<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
|
||||
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
|
||||
<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>
|
||||
<b>Bespiel</b> <br>
|
||||
get <name> svrinfo <br>
|
||||
<ul>
|
||||
<b>Beispiel</b> <br>
|
||||
attr <name> showSvrInfo %SQL_CATALOG_TERM%,%NAME% <br>
|
||||
get <name> svrinfo <br>
|
||||
# Es werden nur Readings erzeugt die im Namen "SQL_CATALOG_TERM" und "NAME" enthalten
|
||||
</ul>
|
||||
</li>
|
||||
<br><br>
|
||||
</ul>
|
||||
|
||||
<a name="tableinfo"></a>
|
||||
<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.
|
||||
Mit dem <a href="#DbRepattr">Attribut</a> "showTableInfo" 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>
|
||||
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><br>
|
||||
|
||||
<br><ul>
|
||||
<b>Bespiel</b> <br>
|
||||
get <name> tableinfo <br>
|
||||
<ul>
|
||||
<b>Beispiel</b> <br>
|
||||
attr <name> showTableInfo current,history <br>
|
||||
get <name> tableinfo <br>
|
||||
# Es werden nur Information der Tabellen "current" und "history" angezeigt
|
||||
</ul>
|
||||
</li>
|
||||
<br><br>
|
||||
|
||||
<a name="versionNotes"></a>
|
||||
<li><b> versionNotes [hints | rel | <key>] </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> <key> </td><td>: es wird der Hinweis mit der angegebenen Nummer angezeigt </td></tr>
|
||||
</table>
|
||||
</ul>
|
||||
|
||||
<li><b> versionNotes [hints | rel | <key>] </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 <key>-Angabe
|
||||
wird der Hinweis mit der angegebenen Nummer angezeigt.
|
||||
</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>
|
||||
</ul></ul>
|
||||
|
||||
@ -16826,7 +16943,7 @@ sub bdump {
|
||||
<br><br>
|
||||
</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
|
||||
(Default: 86400) </li> <br>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user