2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-09 20:57:11 +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.
# 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 ",
@ -66,7 +67,7 @@ my %DbRep_vNotesIntern = (
"8.50.1" => "05.09.2022 DbRep_setLastCmd, change changeValue syntax, minor fixes ",
"8.50.0" => "20.08.2022 rework of DbRep_reduceLog - add max, max=day, min, min=day, sum, sum=day ",
"8.49.1" => "03.08.2022 fix DbRep_deleteOtherFromDB, Forum: https://forum.fhem.de/index.php/topic,128605.0.html ".
"some code changes and bug fixes ",
"some code changes and bug fixes ",
"8.49.0" => "16.05.2022 allow optionally set device / reading in the insert command ",
"8.48.4" => "16.05.2022 fix perl warning of set ... insert, Forum: topic,53584.msg1221588.html#msg1221588 ",
"8.48.3" => "09.04.2022 minor code fix in DbRep_reduceLog ",
@ -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,43 +13238,52 @@ 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;
}
$sth->finish;
$dbh->disconnect;
my $rt = tv_interval($st); # SQL-Laufzeit ermitteln
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);