mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 16:56:54 +00:00
93_DbRep: contrib 8.51.0
git-svn-id: https://svn.fhem.de/fhem/trunk@26952 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
a607b38728
commit
fcd9f12ecd
@ -1086,7 +1086,7 @@ sub DbRep_Set {
|
||||
shift @cmd;
|
||||
|
||||
$sqlcmd = join ' ', @cmd;
|
||||
$sqlcmd = DbRep_trim ($sqlcmd);
|
||||
#$sqlcmd = DbRep_trim ($sqlcmd);
|
||||
|
||||
if ($sqlcmd =~ /^ckey:/ix) {
|
||||
my $key = (split ":", $sqlcmd)[1];
|
||||
@ -1138,6 +1138,7 @@ sub DbRep_Set {
|
||||
|
||||
$sqlcmd = _DbRep_sqlFormOnline ($hash, $sqlcmd); # SQL Statement online formatieren
|
||||
|
||||
$sqlcmd = DbRep_trim ($sqlcmd);
|
||||
$data{DbRep}{$name}{sqlcache}{temp} = $sqlcmd; # SQL incl. Formatierung zwischenspeichern
|
||||
|
||||
my @cmd = split /\s+/, $sqlcmd;
|
||||
@ -1197,11 +1198,20 @@ sub _DbRep_sqlFormOnline {
|
||||
my $sqlcmd = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my $fs = AttrVal($name, 'sqlFormatService', '');
|
||||
$fs = 'https://sqlformat.org';
|
||||
return $sqlcmd if(!$fs);
|
||||
|
||||
if ($fs eq 'https://sqlformat.org') {
|
||||
$fs .= '/api/v1/format';
|
||||
}
|
||||
|
||||
my @cmds = split ';', $sqlcmd;
|
||||
|
||||
my $newcmd;
|
||||
|
||||
for my $part (@cmds) {
|
||||
my ($err, $dat) = HttpUtils_BlockingGet ({ url => 'https://sqlformat.org/api/v1/format',
|
||||
my ($err, $dat) = HttpUtils_BlockingGet ({ url => $fs,
|
||||
timeout => 5,
|
||||
data => "reindent=1&sql=$part",
|
||||
method => 'POST',
|
||||
@ -1218,8 +1228,11 @@ sub _DbRep_sqlFormOnline {
|
||||
else {
|
||||
my ($success, $decoded) = evalDecodeJSON ($hash, $dat);
|
||||
|
||||
my $res = $decoded->{result};
|
||||
next if(!$res);
|
||||
|
||||
if ($success) {
|
||||
$newcmd .= Encode::encode_utf8 ($decoded->{result}).';';
|
||||
$newcmd .= Encode::encode_utf8 ($res).';';
|
||||
|
||||
}
|
||||
else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user