2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 03:06:37 +00:00

93_DbRep: sqlCmd supports execute DB Procedures

git-svn-id: https://svn.fhem.de/fhem/trunk@26882 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
nasseeder1 2022-12-21 21:09:58 +00:00
parent f2e5aa40e1
commit b5c7f66b60
2 changed files with 18 additions and 7 deletions

View File

@ -1,5 +1,6 @@
# 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.
- feature: 93_DbRep: sqlCmd supports execute DB Procedures
- bugfix: 47_OBIS: Support DZG hack for power_L1/2/3 - bugfix: 47_OBIS: Support DZG hack for power_L1/2/3
- change: 93_DbRep: minor code change (ualarm removed) - change: 93_DbRep: minor code change (ualarm removed)
- feature: 70_ESCVP21net: added HC2150, added on/off as direct set commands - feature: 70_ESCVP21net: added HC2150, added on/off as direct set commands

View File

@ -57,6 +57,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch';
# Version History intern # Version History intern
my %DbRep_vNotesIntern = ( my %DbRep_vNotesIntern = (
"8.50.8" => "21.12.2022 add call to DbRep_sqlCmd, DbRep_sqlCmdBlocking ",
"8.50.7" => "17.12.2022 Commandref edited ", "8.50.7" => "17.12.2022 Commandref edited ",
"8.50.6" => "14.12.2022 remove ularm from Time::HiRes, Forum: https://forum.fhem.de/index.php/topic,53584.msg1251313.html#msg1251313 ", "8.50.6" => "14.12.2022 remove ularm from Time::HiRes, Forum: https://forum.fhem.de/index.php/topic,53584.msg1251313.html#msg1251313 ",
"8.50.5" => "05.12.2022 fix diffValue problem (DbRep_diffval) for newer MariaDB versions: https://forum.fhem.de/index.php/topic,130697.0.html ", "8.50.5" => "05.12.2022 fix diffValue problem (DbRep_diffval) for newer MariaDB versions: https://forum.fhem.de/index.php/topic,130697.0.html ",
@ -6659,7 +6660,7 @@ sub DbRep_sqlCmd {
my (@rows,$row,@head); my (@rows,$row,@head);
my $nrows = 0; my $nrows = 0;
if($sql =~ m/^\s*(explain|select|pragma|show)/is) { if($sql =~ m/^\s*(call|explain|select|pragma|show)/is) {
@head = map { uc($sth->{NAME}[$_]) } keys @{$sth->{NAME}}; # https://metacpan.org/pod/DBI#NAME1 @head = map { uc($sth->{NAME}[$_]) } keys @{$sth->{NAME}}; # https://metacpan.org/pod/DBI#NAME1
if (@head) { if (@head) {
$row = join("$srs", @head); $row = join("$srs", @head);
@ -13237,34 +13238,43 @@ sub DbRep_sqlCmdBlocking {
if ($failed) { if ($failed) {
$err = $failed eq "Timeout\n" ? $totxt : $failed; $err = $failed eq "Timeout\n" ? $totxt : $failed;
Log3 ($name, 2, "DbRep $name - $err"); Log3 ($name, 2, "DbRep $name - $err");
$sth->finish if($sth); $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;
if($sql =~ m/^\s*(select|pragma|show)/is) { if($sql =~ m/^\s*(call|explain|select|pragma|show)/is) {
while (my @line = $sth->fetchrow_array()) { while (my @line = $sth->fetchrow_array()) {
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);
$nrows++; # Anzahl der Datensätze $nrows++; # Anzahl der Datensätze
} }
}
} else { else {
$nrows = $sth->rows; $nrows = $sth->rows;
eval {$dbh->commit() if(!$dbh->{AutoCommit});}; eval {$dbh->commit() if(!$dbh->{AutoCommit});};
if ($@) { if ($@) {
$err = $@; $err = $@;
Log3 ($name, 2, "DbRep $name - $err"); Log3 ($name, 2, "DbRep $name - $err");
$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;
} }
@ -13272,8 +13282,8 @@ sub DbRep_sqlCmdBlocking {
$dbh->disconnect; $dbh->disconnect;
my $rt = tv_interval($st); # SQL-Laufzeit ermitteln 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"); Log3 ($name, 4, "DbRep $name - Number of entries processed in db $hash->{DATABASE}: $nrows by $com");
readingsBeginUpdate ($hash); readingsBeginUpdate ($hash);