2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-05-02 13:05:12 +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 31a598ee9a
commit 891f12e4a3
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.
# 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
- change: 93_DbRep: minor code change (ualarm removed)
- 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
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.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 ",
@ -6659,7 +6660,7 @@ sub DbRep_sqlCmd {
my (@rows,$row,@head);
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
if (@head) {
$row = join("$srs", @head);
@ -13237,34 +13238,43 @@ sub DbRep_sqlCmdBlocking {
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;
}
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()) {
Log3 ($name, 4, "DbRep $name - SQL result: @line");
$ret .= "\n" if($nrows); # Forum: #103295
$ret .= join("$srs", @line);
$nrows++; # Anzahl der Datensätze
}
} else {
}
else {
$nrows = $sth->rows;
eval {$dbh->commit() if(!$dbh->{AutoCommit});};
if ($@) {
$err = $@;
Log3 ($name, 2, "DbRep $name - $err");
$dbh->disconnect;
ReadingsSingleUpdateValue ($hash, "errortext", $err, 1);
ReadingsSingleUpdateValue ($hash, "state", "error", 1);
return $err;
}
$ret = $nrows;
}
@ -13272,8 +13282,8 @@ sub DbRep_sqlCmdBlocking {
$dbh->disconnect;
my $rt = tv_interval($st); # SQL-Laufzeit ermitteln
my $com = (split " ", $sql, 2)[0];
Log3 ($name, 4, "DbRep $name - Number of entries processed in db $hash->{DATABASE}: $nrows by $com");
readingsBeginUpdate ($hash);