From cd2e937a120b5cdc053a6208d4d4724c698576b9 Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Fri, 16 Feb 2024 20:57:30 +0000 Subject: [PATCH] 93_DbRep: sqlCmd executing ckey:latest possible git-svn-id: https://svn.fhem.de/fhem/trunk@28525 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/93_DbRep.pm | 36 +++++++++++++++++++++++------------- fhem/MAINTAINER.txt | 2 +- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index ec66c7f5c..d67cde308 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -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 executing ckey:latest possible - new: 73_PRESENCE2: cover version von 73_PRESENCE.pm - change: 76_SolarForecast: fillup AI data with sun azimuth / altitude - feature: 76_SolarForecast: new command get dwdCatalog diff --git a/fhem/FHEM/93_DbRep.pm b/fhem/FHEM/93_DbRep.pm index dcc0d7df2..8fbbc6dde 100644 --- a/fhem/FHEM/93_DbRep.pm +++ b/fhem/FHEM/93_DbRep.pm @@ -59,6 +59,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch'; # Version History intern my %DbRep_vNotesIntern = ( + "8.53.1" => "16.02.2024 sqlCmd: executing ckey:latest possible ", "8.53.0" => "10.01.2024 new setter multiCmd, change DbRep_autoForward, fix reducelog problem Forum:#136581 ", "8.52.15" => "08.12.2023 fix use fhem default variables in attr executeBeforeProc/executeAfterProc ". "forum: https://forum.fhem.de/index.php?msg=1296146 ", @@ -1085,7 +1086,7 @@ sub DbRep_Set { } } - if($opt eq "sqlCmd") { + if ($opt eq "sqlCmd") { my @cmd = @a; shift @cmd; shift @cmd; @@ -1093,13 +1094,22 @@ sub DbRep_Set { $sqlcmd = join ' ', @cmd; if ($sqlcmd =~ /^ckey:/ix) { + if (!keys %{$data{DbRep}{$name}{sqlcache}{cmd}}) { + return qq{No SQL statements are cached.}; + } + my $key = (split ":", $sqlcmd)[1]; + + if ($key eq 'latest') { + my @xe = sort{$b<=>$a} keys %{$data{DbRep}{$name}{sqlcache}{cmd}}; + $key = shift @xe; + } if (exists $data{DbRep}{$name}{sqlcache}{cmd}{$key}) { $sqlcmd = $data{DbRep}{$name}{sqlcache}{cmd}{$key}; } else { - return qq{SQL statement with key "$key" doesn't exists in history}; + return qq{The SQL statement with key "$key" does not exist.}; } } @@ -13244,7 +13254,7 @@ sub DbRep_addSQLcmdCache { } } - if($doIns) { + if ($doIns) { _DbRep_insertSQLtoCache ($name, $tmpsql); } @@ -16277,16 +16287,16 @@ return; The module provides a command history once a sqlCmd command was executed successfully. To use this option, activate the attribute sqlCmdHistoryLength - with list lenght you want.
- If the command history is enabled, an indexed list of stored SQL statements is available - with ___list_sqlhistory___ within the sqlCmdHistory command.

+ with list lenght you want.

- An SQL statement can be executed by specifying its index in this form: + An SQL statement can be executed by specifying its list index:


+ + The list index "ckey:latest" executes the last statement saved in the SQL history.

Relevant attributes are:
@@ -19417,17 +19427,18 @@ return; Das Modul stellt optional eine Kommando-Historie zur Verfügung sobald ein SQL-Kommando erfolgreich ausgeführt wurde. Um diese Option zu nutzen, ist das Attribut sqlCmdHistoryLength mit der - gewünschten Listenlänge zu aktivieren.
- Ist die Kommando-Historie aktiviert, ist mit ___list_sqlhistory___ innerhalb des Kommandos - sqlCmdHistory eine indizierte Liste der gespeicherten SQL-Statements verfügbar.

+ gewünschten Listenlänge zu aktivieren. +

- Ein SQL-Statement kann durch Angabe seines Index im ausgeführt werden mit: + Ein SQL-Statement kann durch Angabe seines Listenindex ausgeführt werden:


- + + Der Listenindex "ckey:latest" führt das zuletzt in der SQL History gespeicherte Statement aus.

+ Relevante Attribute sind: