mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-24 15:24:51 +00:00
93_DbLog: insertmode 0 - improved output of errors in Logfile
git-svn-id: https://svn.fhem.de/fhem/trunk@29401 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
7aa89259be
commit
355601fb40
@ -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
|
||||||
|
- change: 93_DbLog: insertmode 0 - improved output of errors in Logfile
|
||||||
- change: 57_Calendar: remove smartmatch replacement as it is now
|
- change: 57_Calendar: remove smartmatch replacement as it is now
|
||||||
officially in fhem.pl
|
officially in fhem.pl
|
||||||
- feature: 93_DbLog: check valid Event Time limit, Forum: #139847
|
- feature: 93_DbLog: check valid Event Time limit, Forum: #139847
|
||||||
|
@ -58,6 +58,7 @@ use vars qw($FW_ME $FW_subdir); # predeclar
|
|||||||
|
|
||||||
# Version History intern by DS_Starter:
|
# Version History intern by DS_Starter:
|
||||||
my %DbLog_vNotesIntern = (
|
my %DbLog_vNotesIntern = (
|
||||||
|
"5.11.0" => "02.12.2024 sub _DbLog_SBP_onRun_LogArray revised: insertmode Array - not saved data are print out in Logfile ",
|
||||||
"5.10.3" => "01.12.2024 check valid Time limit 1970-01-01 00:00:00 of Event time, Forum: #139847 ",
|
"5.10.3" => "01.12.2024 check valid Time limit 1970-01-01 00:00:00 of Event time, Forum: #139847 ",
|
||||||
"5.10.2" => "21.07.2024 _DbLog_copyCache: Copy process changed to minimize memory usage after reopen ",
|
"5.10.2" => "21.07.2024 _DbLog_copyCache: Copy process changed to minimize memory usage after reopen ",
|
||||||
"5.10.1" => "01.04.2024 _DbLog_plotData: avoid possible uninitialized value \$out_value (SVG: Argument '' isn't numeric) ".
|
"5.10.1" => "01.04.2024 _DbLog_plotData: avoid possible uninitialized value \$out_value (SVG: Argument '' isn't numeric) ".
|
||||||
@ -2914,7 +2915,7 @@ sub _DbLog_SBP_onRun_LogSequential {
|
|||||||
|
|
||||||
$error = __DbLog_SBP_beginTransaction ($name, $dbh, $useta, $subprocess);
|
$error = __DbLog_SBP_beginTransaction ($name, $dbh, $useta, $subprocess);
|
||||||
|
|
||||||
if(!$useta) { # keine Transaktion: generate errstr, keine Ausnahme
|
if (!$useta) { # keine Transaktion: generate errstr, keine Ausnahme
|
||||||
_DbLog_SBP_dbhPrintError ($dbh);
|
_DbLog_SBP_dbhPrintError ($dbh);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3146,8 +3147,7 @@ sub _DbLog_SBP_onRun_LogArray {
|
|||||||
my $faref = __DbLog_SBP_fieldArrays ($name, $cdata, $subprocess);
|
my $faref = __DbLog_SBP_fieldArrays ($name, $cdata, $subprocess);
|
||||||
my $ceti = scalar keys %{$cdata};
|
my $ceti = scalar keys %{$cdata};
|
||||||
|
|
||||||
my ($st,$sth_ih,$sth_ic,$sth_uc,$sqlins,$ins_hist);
|
my ($st, $sth_ih, $sth_ic, $sth_uc ,$sqlins, $ins_hist, $tuples);
|
||||||
my ($tuples, $rows);
|
|
||||||
my @tuple_status;
|
my @tuple_status;
|
||||||
|
|
||||||
my @timestamp = @{$faref->{timestamp}};
|
my @timestamp = @{$faref->{timestamp}};
|
||||||
@ -3189,7 +3189,8 @@ sub _DbLog_SBP_onRun_LogArray {
|
|||||||
};
|
};
|
||||||
|
|
||||||
__DbLog_SBP_sendToParent ($subprocess, $ret);
|
__DbLog_SBP_sendToParent ($subprocess, $ret);
|
||||||
return;
|
|
||||||
|
return $error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($tl) { # Tracelevel setzen
|
if ($tl) { # Tracelevel setzen
|
||||||
@ -3216,92 +3217,40 @@ sub _DbLog_SBP_onRun_LogArray {
|
|||||||
_DbLog_SBP_dbhPrintError ($dbh);
|
_DbLog_SBP_dbhPrintError ($dbh);
|
||||||
}
|
}
|
||||||
|
|
||||||
eval { ($tuples, $rows) = $sth_ih->execute_array( { ArrayTupleStatus => \@tuple_status } );
|
eval { $tuples = $sth_ih->execute_array ( { ArrayTupleStatus => \@tuple_status } ) };
|
||||||
1;
|
|
||||||
}
|
|
||||||
or do {
|
|
||||||
$error = $@;
|
|
||||||
$nins_hist = $ceti;
|
|
||||||
|
|
||||||
_DbLog_SBP_Log3Parent ( { name => $name,
|
if (!$tuples) {
|
||||||
level => 2,
|
no warnings 'uninitialized';
|
||||||
msg => "Error table $history - $error",
|
|
||||||
oper => 'log3parent',
|
|
||||||
subprocess => $subprocess
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($useta) {
|
for my $tuple (0..$ceti-1) {
|
||||||
$rowlback = $cdata; # nicht gespeicherte Datensätze nur zurück geben wenn Transaktion ein
|
my $status = $tuple_status[$tuple];
|
||||||
|
$status = [0, "Skipped"] unless defined $status; # $status ist "1" wenn insert ok
|
||||||
|
|
||||||
_DbLog_SBP_Log3Parent ( { name => $name,
|
next unless ref $status;
|
||||||
level => 4,
|
|
||||||
msg => "Transaction is switched on. Transferred data is returned to the cache.",
|
|
||||||
oper => 'log3parent',
|
|
||||||
subprocess => $subprocess
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
_DbLog_SBP_Log3Parent ( { name => $name,
|
|
||||||
level => 4,
|
|
||||||
msg => "Transaction is switched off. Some or all of the transferred data will be lost. Note the following information.",
|
|
||||||
oper => 'log3parent',
|
|
||||||
subprocess => $subprocess
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
_DbLog_SBP_dbhRaiseError ($dbh);
|
_DbLog_SBP_Log3Parent ( { name => $name,
|
||||||
__DbLog_SBP_rollbackOnly ($name, $dbh, $history, $subprocess);
|
level => 4,
|
||||||
|
msg => "Insert into $history rejected".($usepkh ? " (possible PK violation) " : " ")."->\nTS: $timestamp[$tuple], Device: $device[$tuple], Reading: $reading[$tuple]",
|
||||||
|
oper => 'log3parent',
|
||||||
|
subprocess => $subprocess
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
$ret = {
|
$event[$tuple] =~ s/\|/_ESC_/gxs; # escape Pipe "|"
|
||||||
name => $name,
|
$reading[$tuple] =~ s/\|/_ESC_/gxs;
|
||||||
msg => $error,
|
$value[$tuple] =~ s/\|/_ESC_/gxs;
|
||||||
ot => 0,
|
$unit[$tuple] =~ s/\|/_ESC_/gxs;
|
||||||
oper => $operation,
|
|
||||||
rowlback => $rowlback
|
|
||||||
};
|
|
||||||
|
|
||||||
__DbLog_SBP_sendToParent ($subprocess, $ret);
|
my $nlh = $timestamp[$tuple]."|".$device[$tuple]."|".$type[$tuple]."|".$event[$tuple]."|".$reading[$tuple]."|".$value[$tuple]."|".$unit[$tuple];
|
||||||
|
|
||||||
return $error;
|
push @n2hist, $nlh; # Liste der nicht eingefügten Zeilen
|
||||||
};
|
$nins_hist++; # Anzahl der nicht eingefügten Zeilen
|
||||||
|
}
|
||||||
|
|
||||||
_DbLog_SBP_dbhRaiseError ($dbh);
|
use warnings;
|
||||||
__DbLog_SBP_commitOnly ($name, $dbh, $history, $subprocess);
|
|
||||||
|
|
||||||
no warnings 'uninitialized';
|
|
||||||
|
|
||||||
for my $tuple (0..$ceti-1) {
|
|
||||||
my $status = $tuple_status[$tuple];
|
|
||||||
$status = 0 if($status eq "0E0");
|
|
||||||
|
|
||||||
next if($status); # $status ist "1" wenn insert ok
|
|
||||||
|
|
||||||
_DbLog_SBP_Log3Parent ( { name => $name,
|
|
||||||
level => 4,
|
|
||||||
msg => "Insert into $history rejected".($usepkh ? " (possible PK violation) " : " ")."->\nTS: $timestamp[$tuple], Device: $device[$tuple], Reading: $reading[$tuple]",
|
|
||||||
oper => 'log3parent',
|
|
||||||
subprocess => $subprocess
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
$event[$tuple] =~ s/\|/_ESC_/gxs; # escape Pipe "|"
|
|
||||||
$reading[$tuple] =~ s/\|/_ESC_/gxs;
|
|
||||||
$value[$tuple] =~ s/\|/_ESC_/gxs;
|
|
||||||
$unit[$tuple] =~ s/\|/_ESC_/gxs;
|
|
||||||
|
|
||||||
my $nlh = $timestamp[$tuple]."|".$device[$tuple]."|".$type[$tuple]."|".$event[$tuple]."|".$reading[$tuple]."|".$value[$tuple]."|".$unit[$tuple];
|
|
||||||
|
|
||||||
push @n2hist, $nlh;
|
|
||||||
|
|
||||||
$nins_hist++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
use warnings;
|
if (!$nins_hist) { # alle Inserts ok
|
||||||
|
|
||||||
if (!$nins_hist) {
|
|
||||||
_DbLog_SBP_Log3Parent ( { name => $name,
|
_DbLog_SBP_Log3Parent ( { name => $name,
|
||||||
level => 4,
|
level => 4,
|
||||||
msg => "$ceti of $ceti events inserted into table $history".($usepkh ? " using PK on columns $pkh" : ""),
|
msg => "$ceti of $ceti events inserted into table $history".($usepkh ? " using PK on columns $pkh" : ""),
|
||||||
@ -3309,45 +3258,75 @@ sub _DbLog_SBP_onRun_LogArray {
|
|||||||
subprocess => $subprocess
|
subprocess => $subprocess
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
_DbLog_SBP_dbhRaiseError ($dbh);
|
||||||
|
__DbLog_SBP_commitOnly ($name, $dbh, $history, $subprocess);
|
||||||
}
|
}
|
||||||
else {
|
else { # Fehler sind aufgetreten
|
||||||
if($usepkh) {
|
my $bkey = 1;
|
||||||
|
|
||||||
|
for my $line (@n2hist) {
|
||||||
|
$rowhref->{$bkey} = $line;
|
||||||
|
$bkey++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($useta) {
|
||||||
|
$rowlback = $cdata; # Transaktion ein -> alle Daten zurückgeben und Rollback
|
||||||
|
|
||||||
_DbLog_SBP_Log3Parent ( { name => $name,
|
_DbLog_SBP_Log3Parent ( { name => $name,
|
||||||
level => 3,
|
level => 3,
|
||||||
msg => "INFO - ".($ceti-$nins_hist)." of $ceti events inserted into table history due to PK on columns $pkh",
|
msg => "Transaction mode is activated. No data was saved in table $history, but all data was returned to the cache.",
|
||||||
oper => 'log3parent',
|
oper => 'log3parent',
|
||||||
subprocess => $subprocess
|
subprocess => $subprocess
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
_DbLog_SBP_dbhRaiseError ($dbh);
|
||||||
|
__DbLog_SBP_rollbackOnly ($name, $dbh, $history, $subprocess);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if ($usepkh) {
|
||||||
|
_DbLog_SBP_Log3Parent ( { name => $name,
|
||||||
|
level => 3,
|
||||||
|
msg => "INFO - ".($ceti-$nins_hist)." of $ceti events inserted into table history. PK on columns $pkh is set.",
|
||||||
|
oper => 'log3parent',
|
||||||
|
subprocess => $subprocess
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_DbLog_SBP_Log3Parent ( { name => $name,
|
||||||
|
level => 3,
|
||||||
|
msg => "WARNING - only ".($ceti-$nins_hist)." of $ceti events inserted into table '$history'",
|
||||||
|
oper => 'log3parent',
|
||||||
|
subprocess => $subprocess
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
_DbLog_SBP_Log3Parent ( { name => $name,
|
_DbLog_SBP_Log3Parent ( { name => $name,
|
||||||
level => 2,
|
level => 3,
|
||||||
msg => "WARNING - only ".($ceti-$nins_hist)." of $ceti events inserted into table $history",
|
msg => "The transaction is disabled.",
|
||||||
oper => 'log3parent',
|
oper => 'log3parent',
|
||||||
subprocess => $subprocess
|
subprocess => $subprocess
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
my $bkey = 1;
|
_DbLog_SBP_dbhRaiseError ($dbh);
|
||||||
|
__DbLog_SBP_commitOnly ($name, $dbh, $history, $subprocess);
|
||||||
for my $line (@n2hist) {
|
|
||||||
$rowhref->{$bkey} = $line;
|
|
||||||
$bkey++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined $rowhref) { # nicht gespeicherte Datensätze ausgeben
|
if (defined $rowhref) { # nicht gespeicherte Datensätze ausgeben
|
||||||
_DbLog_SBP_Log3Parent ( { name => $name,
|
_DbLog_SBP_Log3Parent ( { name => $name,
|
||||||
level => 2,
|
level => 3,
|
||||||
msg => "The following data was not saved due to causes that may have been previously displayed:",
|
msg => "The following data were faulty and are not saved in database table '$history':",
|
||||||
oper => 'log3parent',
|
oper => 'log3parent',
|
||||||
subprocess => $subprocess
|
subprocess => $subprocess
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
DbLog_logHashContent ( {name => $name, href => $rowhref, level => 2, subprocess => $subprocess} );
|
DbLog_logHashContent ( {name => $name, href => $rowhref, level => 3, subprocess => $subprocess} );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user