2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-19 06:36:04 +00:00

93_DbRep: write TYPE uppercase with writeToDB option

git-svn-id: https://svn.fhem.de/fhem/trunk@27026 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
nasseeder1 2023-01-11 18:55:22 +00:00
parent 404e347000
commit 84cf72774b
2 changed files with 352 additions and 335 deletions

View File

@ -1,5 +1,7 @@
# 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: write TYPE uppercase with writeToDB option,
Commandref edited
- bugfix: 59_Weather: fix DarkSky API wrong funtion call - bugfix: 59_Weather: fix DarkSky API wrong funtion call
- feature: 72_FRITZBOX: merged old 72_FRITZBOX with last Fork Version - feature: 72_FRITZBOX: merged old 72_FRITZBOX with last Fork Version
- bugfix: 59_Weather: bugfix function WeatherAsHtmlD not working - bugfix: 59_Weather: bugfix function WeatherAsHtmlD not working

View File

@ -59,6 +59,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch';
# Version History intern # Version History intern
my %DbRep_vNotesIntern = ( my %DbRep_vNotesIntern = (
"8.51.1" => "01.01.2023 write TYPE uppercase with writeToDB option, Commandref edited ",
"8.51.0" => "02.01.2023 online formatting of sqlCmd, sqlCmdHistory, sqlSpecial, Commandref edited, get dbValue removed ". "8.51.0" => "02.01.2023 online formatting of sqlCmd, sqlCmdHistory, sqlSpecial, Commandref edited, get dbValue removed ".
"sqlCmdBlocking customized like sqlCmd, bugfix avgTimeWeightMean ", "sqlCmdBlocking customized like sqlCmd, bugfix avgTimeWeightMean ",
"8.50.10" => "01.01.2023 Commandref edited ", "8.50.10" => "01.01.2023 Commandref edited ",
@ -12713,8 +12714,11 @@ sub DbRep_OutputWriteToDB {
if(!$dbloghash->{HELPER}{COLSET}) { if(!$dbloghash->{HELPER}{COLSET}) {
$err = "No result of \"$hash->{LASTCMD}\" to database written. Cause: column width in \"$hash->{DEF}\" isn't set"; $err = "No result of \"$hash->{LASTCMD}\" to database written. Cause: column width in \"$hash->{DEF}\" isn't set";
Log3 ($name, 2, "DbRep $name - ERROR - $err"); Log3 ($name, 2, "DbRep $name - ERROR - $err");
$err = encode_base64($err,""); $err = encode_base64($err,"");
return ($err,$wrt,$irowdone); return ($err,$wrt,$irowdone);
} }
@ -12723,7 +12727,7 @@ sub DbRep_OutputWriteToDB {
my $aggr = (DbRep_checktimeaggr($hash))[2]; my $aggr = (DbRep_checktimeaggr($hash))[2];
$reading = $optxt."_".$aggr."_".AttrVal($name, "readingNameMap", $reading); $reading = $optxt."_".$aggr."_".AttrVal($name, "readingNameMap", $reading);
$type = $defs{$device}{TYPE} if($defs{$device}); # $type vom Device ableiten $type = uc($defs{$device}{TYPE}) if($defs{$device}); # $type vom Device übernehmen
if($optxt =~ /avg|sum/) { if($optxt =~ /avg|sum/) {
my @arr = split("\\|", $wrstr); my @arr = split("\\|", $wrstr);
@ -12770,7 +12774,6 @@ sub DbRep_OutputWriteToDB {
} }
if (defined $value) { if (defined $value) {
# Daten auf maximale Länge beschneiden (DbLog-Funktion !)
($device,$type,$event,$reading,$value,$unit) = DbLog_cutCol($dbloghash,$device,$type,$event,$reading,$value,$unit); ($device,$type,$event,$reading,$value,$unit) = DbLog_cutCol($dbloghash,$device,$type,$event,$reading,$value,$unit);
if($i == 0) { if($i == 0) {
@ -12820,7 +12823,6 @@ sub DbRep_OutputWriteToDB {
} }
} }
if ($value) { if ($value) {
# Daten auf maximale Länge beschneiden (DbLog-Funktion !)
($device,$type,$event,$reading,$value,$unit) = DbLog_cutCol($dbloghash,$device,$type,$event,$reading,$value,$unit); ($device,$type,$event,$reading,$value,$unit) = DbLog_cutCol($dbloghash,$device,$type,$event,$reading,$value,$unit);
push(@row_array, "$date $time|$device|$type|$event|$reading|$value|$unit"); push(@row_array, "$date $time|$device|$type|$event|$reading|$value|$unit");
} }
@ -12831,8 +12833,11 @@ sub DbRep_OutputWriteToDB {
eval {$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 1, mysql_enable_utf8 => $utf8 });}; eval {$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 1, mysql_enable_utf8 => $utf8 });};
if ($@) { if ($@) {
$err = $@; $err = $@;
Log3 ($name, 2, "DbRep $name - ERROR - $@"); Log3 ($name, 2, "DbRep $name - ERROR - $@");
$err = encode_base64($err,""); $err = encode_base64($err,"");
return ($err,$wrt,$irowdone); return ($err,$wrt,$irowdone);
} }
@ -12894,8 +12899,7 @@ sub DbRep_OutputWriteToDB {
Log3($name, 2, "DbRep $name - ERROR - $@"); Log3($name, 2, "DbRep $name - ERROR - $@");
} }
# SQL-Startzeit my $wst = [gettimeofday]; # SQL-Startzeit
my $wst = [gettimeofday];
my $ihs = 0; my $ihs = 0;
my $uhs = 0; my $uhs = 0;
@ -12910,8 +12914,7 @@ sub DbRep_OutputWriteToDB {
$value = $a[5]; $value = $a[5];
$unit = $a[6]; $unit = $a[6];
eval { eval { # update oder insert history
# update oder insert history
if (lc($DbLogType) =~ m(history) ) { if (lc($DbLogType) =~ m(history) ) {
my $rv_uh = $dbh->do("UPDATE history SET TIMESTAMP=\"$timestamp\", DEVICE=\"$device\", READING=\"$reading\", TYPE=\"$type\", EVENT=\"$event\", VALUE=\"$value\", UNIT=\"$unit\" WHERE TIMESTAMP=\"$timestamp\" AND DEVICE=\"$device\" AND READING=\"$reading\""); my $rv_uh = $dbh->do("UPDATE history SET TIMESTAMP=\"$timestamp\", DEVICE=\"$device\", READING=\"$reading\", TYPE=\"$type\", EVENT=\"$event\", VALUE=\"$value\", UNIT=\"$unit\" WHERE TIMESTAMP=\"$timestamp\" AND DEVICE=\"$device\" AND READING=\"$reading\"");
$uhs += $rv_uh if($rv_uh); $uhs += $rv_uh if($rv_uh);
@ -12924,8 +12927,8 @@ sub DbRep_OutputWriteToDB {
Log3 $hash->{NAME}, 4, "DbRep $name - INSERT history: $row, RESULT: $rv_ih"; Log3 $hash->{NAME}, 4, "DbRep $name - INSERT history: $row, RESULT: $rv_ih";
} }
} }
# update oder insert current
if (lc($DbLogType) =~ m(current) ) { if (lc($DbLogType) =~ m(current) ) { # update oder insert current
my $rv_uc = $dbh->do("UPDATE current SET TIMESTAMP=\"$timestamp\", DEVICE=\"$device\", READING=\"$reading\", TYPE=\"$type\", EVENT=\"$event\", VALUE=\"$value\", UNIT=\"$unit\" WHERE DEVICE=\"$device\" AND READING=\"$reading\""); my $rv_uc = $dbh->do("UPDATE current SET TIMESTAMP=\"$timestamp\", DEVICE=\"$device\", READING=\"$reading\", TYPE=\"$type\", EVENT=\"$event\", VALUE=\"$value\", UNIT=\"$unit\" WHERE DEVICE=\"$device\" AND READING=\"$reading\"");
if ($rv_uc == 0) { if ($rv_uc == 0) {
$sth_ic->execute($timestamp,$device,$type,$event,$reading,$value,$unit); $sth_ic->execute($timestamp,$device,$type,$event,$reading,$value,$unit);
@ -12935,10 +12938,14 @@ sub DbRep_OutputWriteToDB {
if ($@) { if ($@) {
$err = $@; $err = $@;
Log3 ($name, 2, "DbRep $name - ERROR - $@"); Log3 ($name, 2, "DbRep $name - ERROR - $@");
$dbh->rollback; $dbh->rollback;
$dbh->disconnect; $dbh->disconnect;
$err = encode_base64($err,""); $err = encode_base64($err,"");
return ($err,$wrt,0); return ($err,$wrt,0);
} }
} }
@ -12951,8 +12958,7 @@ sub DbRep_OutputWriteToDB {
Log3 ($hash->{NAME}, 3, "DbRep $name - number of lines inserted into \"$dblogname\": $ihs"); Log3 ($hash->{NAME}, 3, "DbRep $name - number of lines inserted into \"$dblogname\": $ihs");
$irowdone = $ihs + $uhs; $irowdone = $ihs + $uhs;
# SQL-Laufzeit ermitteln $wrt = tv_interval($wst); # SQL-Laufzeit ermitteln
$wrt = tv_interval($wst);
} }
return ($err,$wrt,$irowdone); return ($err,$wrt,$irowdone);
@ -14223,8 +14229,9 @@ return;
</li><br> </li><br>
<li><b> dumpMySQL [clientSide | serverSide]</b> <li><b> dumpMySQL [clientSide | serverSide]</b> <br><br>
- creates a dump of the connected MySQL database. <br>
Creates a dump of the connected MySQL database. <br>
Depending from selected option the dump will be created on Client- or on Server-Side. <br> Depending from selected option the dump will be created on Client- or on Server-Side. <br>
The variants differs each other concerning the executing system, the creating location, the usage of The variants differs each other concerning the executing system, the creating location, the usage of
attributes, the function result and the needed hardware ressources. <br> attributes, the function result and the needed hardware ressources. <br>
@ -14235,7 +14242,7 @@ return;
<ul> <ul>
<b><u>Option clientSide</u></b> <br> <b><u>Option clientSide</u></b> <br>
The dump will be created by client (FHEM-Server) and will be saved in FHEM log-directory by The dump will be created by client (FHEM-Server) and will be saved in FHEM log-directory ((typical /opt/fhem/log/)) by
default. default.
The target directory can be set by attribute <a href="#DbRep-attr-dumpDirLocal">dumpDirLocal</a> and has to be The target directory can be set by attribute <a href="#DbRep-attr-dumpDirLocal">dumpDirLocal</a> and has to be
writable by the FHEM process. <br> writable by the FHEM process. <br>
@ -14386,9 +14393,10 @@ return;
</ul> </ul>
<br> <br>
<br> <br>
</ul>
</li><br> </ul>
</li>
<br>
<li><b> dumpSQLite </b> - creates a dump of the connected SQLite database. <br> <li><b> dumpSQLite </b> - creates a dump of the connected SQLite database. <br>
This function uses the SQLite Online Backup API and allow to create a consistent backup of the This function uses the SQLite Online Backup API and allow to create a consistent backup of the
@ -15923,7 +15931,8 @@ sub bdump {
new operation starts </li> <br> new operation starts </li> <br>
<a id="DbRep-attr-seqDoubletsVariance"></a> <a id="DbRep-attr-seqDoubletsVariance"></a>
<li><b>seqDoubletsVariance &lt;positive variance [negative variance] [EDGE=negative|positive]&gt; </b> <br> <li><b>seqDoubletsVariance &lt;positive variance [negative variance] [EDGE=negative|positive]&gt; </b> <br><br>
Accepted variance for the command "set &lt;name&gt; delSeqDoublets". <br> Accepted variance for the command "set &lt;name&gt; delSeqDoublets". <br>
The value of this attribute describes the variance up to consecutive numeric values (VALUE) of The value of this attribute describes the variance up to consecutive numeric values (VALUE) of
datasets are handled as identical. If only one numeric value is declared, it is used as datasets are handled as identical. If only one numeric value is declared, it is used as
@ -15944,7 +15953,8 @@ sub bdump {
<code>attr &lt;name&gt; seqDoubletsVariance 3.0 2.0 </code> <br> <code>attr &lt;name&gt; seqDoubletsVariance 3.0 2.0 </code> <br>
<code>attr &lt;name&gt; seqDoubletsVariance 1.5 EDGE=negative </code> <br> <code>attr &lt;name&gt; seqDoubletsVariance 1.5 EDGE=negative </code> <br>
</ul> </ul>
<br><br> <br>
<br>
</li> </li>
<a id="DbRep-attr-showproctime"></a> <a id="DbRep-attr-showproctime"></a>
@ -17088,8 +17098,9 @@ return;
</li> <br> </li> <br>
<li><b> dumpMySQL [clientSide | serverSide]</b> <li><b> dumpMySQL [clientSide | serverSide]</b> <br><br>
- erstellt einen Dump der angeschlossenen MySQL-Datenbank. <br>
Erstellt einen Dump der angeschlossenen MySQL-Datenbank. <br>
Abhängig von der ausgewählten Option wird der Dump auf der Client- bzw. Serverseite erstellt. <br> Abhängig von der ausgewählten Option wird der Dump auf der Client- bzw. Serverseite erstellt. <br>
Die Varianten unterscheiden sich hinsichtlich des ausführenden Systems, des Erstellungsortes, der Die Varianten unterscheiden sich hinsichtlich des ausführenden Systems, des Erstellungsortes, der
Attributverwendung, des erzielten Ergebnisses und der benötigten Hardwareressourcen. <br> Attributverwendung, des erzielten Ergebnisses und der benötigten Hardwareressourcen. <br>
@ -17101,7 +17112,7 @@ return;
<ul> <ul>
<b><u>Option clientSide</u></b> <br> <b><u>Option clientSide</u></b> <br>
Der Dump wird durch den Client (FHEM-Rechner) erstellt und per default im log-Verzeichnis des Clients Der Dump wird durch den Client (FHEM-Rechner) erstellt und per default im log-Verzeichnis des Clients
gespeichert. (typisch /opt/fhem/log/) gespeichert.
Das Zielverzeichnis kann mit dem Attribut <a href="#DbRep-attr-dumpDirLocal">dumpDirLocal</a> verändert werden und muß auf Das Zielverzeichnis kann mit dem Attribut <a href="#DbRep-attr-dumpDirLocal">dumpDirLocal</a> verändert werden und muß auf
dem Client durch FHEM beschreibbar sein. <br> dem Client durch FHEM beschreibbar sein. <br>
Vor dem Dump kann eine Tabellenoptimierung (Attribut "optimizeTablesBeforeDump") oder ein FHEM-Kommando Vor dem Dump kann eine Tabellenoptimierung (Attribut "optimizeTablesBeforeDump") oder ein FHEM-Kommando
@ -17253,7 +17264,8 @@ return;
<br> <br>
</ul> </ul>
</li><br> </li>
<br>
<li><b> dumpSQLite </b> - erstellt einen Dump der angeschlossenen SQLite-Datenbank. <br> <li><b> dumpSQLite </b> - erstellt einen Dump der angeschlossenen SQLite-Datenbank. <br>
Diese Funktion nutzt die SQLite Online Backup API und ermöglicht es konsistente Backups der SQLite-DB Diese Funktion nutzt die SQLite Online Backup API und ermöglicht es konsistente Backups der SQLite-DB
@ -18535,6 +18547,7 @@ sub dbval {
<a id="DbRep-attr-dumpDirLocal"></a> <a id="DbRep-attr-dumpDirLocal"></a>
<li><b>dumpDirLocal </b> <br><br> <li><b>dumpDirLocal </b> <br><br>
<ul> <ul>
Zielverzeichnis für die Erstellung von Dumps mit "dumpMySQL clientSide" oder "dumpSQLite". <br> Zielverzeichnis für die Erstellung von Dumps mit "dumpMySQL clientSide" oder "dumpSQLite". <br>
@ -18820,7 +18833,8 @@ sub bdump {
</li> <br> </li> <br>
<a id="DbRep-attr-seqDoubletsVariance"></a> <a id="DbRep-attr-seqDoubletsVariance"></a>
<li><b>seqDoubletsVariance &lt;positive Abweichung [negative Abweichung] [EDGE=negative|positive]&gt; </b> <br> <li><b>seqDoubletsVariance &lt;positive Abweichung [negative Abweichung] [EDGE=negative|positive]&gt; </b> <br><br>
Akzeptierte Abweichung für das Kommando "set &lt;name&gt; delSeqDoublets". <br> Akzeptierte Abweichung für das Kommando "set &lt;name&gt; delSeqDoublets". <br>
Der Wert des Attributs beschreibt die Abweichung bis zu der aufeinanderfolgende numerische Der Wert des Attributs beschreibt die Abweichung bis zu der aufeinanderfolgende numerische
Werte (VALUE) von Datensätzen als gleich angesehen werden sollen. Werte (VALUE) von Datensätzen als gleich angesehen werden sollen.
@ -18842,7 +18856,8 @@ sub bdump {
<code>attr &lt;name&gt; seqDoubletsVariance 3.0 2.0 </code> <br> <code>attr &lt;name&gt; seqDoubletsVariance 3.0 2.0 </code> <br>
<code>attr &lt;name&gt; seqDoubletsVariance 1.5 EDGE=negative </code> <br> <code>attr &lt;name&gt; seqDoubletsVariance 1.5 EDGE=negative </code> <br>
</ul> </ul>
<br><br> <br>
<br>
</li> </li>
<a id="DbRep-attr-showproctime"></a> <a id="DbRep-attr-showproctime"></a>