\" ";}
if(!exists($defs{$prop}) || $defs{$prop}->{TYPE} ne "DbLog") {
return "The device \"$prop\" doesn't exist or is not a DbLog-device. ";
}
$hash->{LASTCMD} = $prop?"$opt $prop":"$opt";
- DbRep_beforeproc($hash, "syncStandby");
+ DbRep_beforeproc($hash, "syncStandby");
DbRep_Main($hash,$opt,$prop);
} else {
@@ -958,13 +961,13 @@ sub DbRep_Get {
my $getlist = "Unknown argument $opt, choose one of ".
"svrinfo:noArg ".
- "blockinginfo:noArg ".
+ "blockinginfo:noArg ".
"minTimestamp:noArg ".
(($dbmodel =~ /MYSQL/)?"storedCredentials:noArg ":"").
- "dbValue:textField-long ".
+ "sqlCmdBlocking:textField-long ".
(($dbmodel eq "MYSQL")?"dbstatus:noArg ":"").
(($dbmodel eq "MYSQL")?"tableinfo:noArg ":"").
- (($dbmodel eq "MYSQL")?"procinfo:noArg ":"").
+ (($dbmodel eq "MYSQL")?"procinfo:noArg ":"").
(($dbmodel eq "MYSQL")?"dbvars:noArg ":"").
"versionNotes "
;
@@ -974,15 +977,15 @@ sub DbRep_Get {
if ($dbloghash->{HELPER}{REOPEN_RUNS} && $opt !~ /\?|procinfo|blockinginfo/) {
my $ro = $dbloghash->{HELPER}{REOPEN_RUNS_UNTIL};
Log3 ($name, 3, "DbRep $name - connection $dblogdevice to db $dbname is closed until $ro - $opt postponed");
- ReadingsSingleUpdateValue ($hash, "state", "connection $dblogdevice to $dbname is closed until $ro - $opt postponed", 1);
- return;
+ ReadingsSingleUpdateValue ($hash, "state", "connection $dblogdevice to $dbname is closed until $ro - $opt postponed", 1);
+ return;
}
if ($opt =~ /dbvars|dbstatus|tableinfo|procinfo/) {
return "Dump is running - try again later !" if($hash->{HELPER}{RUNNING_BACKUP_CLIENT});
$hash->{LASTCMD} = $prop?"$opt $prop":"$opt";
return "The operation \"$opt\" isn't available with database type $dbmodel" if ($dbmodel ne 'MYSQL');
- ReadingsSingleUpdateValue ($hash, "state", "running", 1);
+ ReadingsSingleUpdateValue ($hash, "state", "running", 1);
DbRep_delread($hash); # Readings löschen die nicht in der Ausnahmeliste (Attr readingPreventFromDel) stehen
$hash->{HELPER}{RUNNING_PID} = BlockingCall("dbmeta_DoParse", "$name|$opt", "dbmeta_ParseDone", $to, "DbRep_ParseAborted", $hash);
@@ -998,7 +1001,7 @@ sub DbRep_Get {
$hash->{LASTCMD} = $prop?"$opt $prop":"$opt";
DbRep_delread($hash);
ReadingsSingleUpdateValue ($hash, "state", "running", 1);
- DbRep_getblockinginfo($hash);
+ DbRep_getblockinginfo($hash);
} elsif ($opt eq "minTimestamp") {
return "Dump is running - try again later !" if($hash->{HELPER}{RUNNING_BACKUP_CLIENT});
@@ -1006,21 +1009,30 @@ sub DbRep_Get {
DbRep_delread($hash);
ReadingsSingleUpdateValue ($hash, "state", "running", 1);
$hash->{HELPER}{IDRETRIES} = 3; # Anzahl wie oft versucht wird initiale Daten zu holen
- $prop = $prop?$prop:'';
- DbRep_firstconnect("$name|$opt|$prop|");
+ $prop = $prop?$prop:'';
+ DbRep_firstconnect("$name|$opt|$prop|");
- } elsif ($opt =~ /dbValue/) {
- return "get \"$opt\" needs at least an argument" if ( @a < 3 );
- my @cmd = @a;
+ } elsif ($opt =~ /sqlCmdBlocking|dbValue/) {
+ return qq{get "$opt" needs at least an argument} if ( @a < 3 );
+
+ if($opt eq "dbValue") {
+ Log3($name, 1, qq{$name - WARNING - the command "dbValue" is deprecated and will be removed soon. Please use "sqlCmdBlocking" instead.});
+ }
+
+ my @cmd = @a;
shift @cmd; shift @cmd;
- my $sqlcmd = join(" ",@cmd);
- $sqlcmd =~ tr/ A-Za-z0-9!"#$§%&'()*+,-.\/:;<=>?@[\\]^_`{|}~äöüÄÖÜ߀/ /cs;
- $hash->{LASTCMD} = $sqlcmd?"$opt $sqlcmd":"$opt";
- if ($sqlcmd =~ m/^\s*delete/is && !AttrVal($hash->{NAME}, "allowDeletion", undef)) {
+
+ my $sqlcmd = join " ", @cmd;
+ $sqlcmd =~ tr/ A-Za-z0-9!"#$§%&'()*+,-.\/:;<=>?@[\\]^_`{|}~äöüÄÖÜ߀/ /cs;
+ $hash->{LASTCMD} = $sqlcmd ? "$opt $sqlcmd" : "$opt";
+
+ if ($sqlcmd =~ m/^\s*delete/is && !AttrVal($name, "allowDeletion", undef)) {
return "Attribute 'allowDeletion = 1' is needed for command '$sqlcmd'. Use it with care !";
}
- my ($err,$ret) = DbRep_dbValue($name,$sqlcmd);
- return $err?$err:$ret;
+
+ ReadingsSingleUpdateValue ($hash, "state", "running", 1);
+
+ return DbRep_sqlCmdBlocking($name,$sqlcmd);
} elsif ($opt eq "storedCredentials") {
# Credentials abrufen
@@ -1047,14 +1059,14 @@ sub DbRep_Get {
;
} elsif ($opt =~ /versionNotes/) {
- my $header = "Module release information
";
+ my $header = "Module release information
";
my $header1 = "Helpful hints
";
- my %hs;
+ my %hs;
- # Ausgabetabelle erstellen
- my ($ret,$val0,$val1);
+ # Ausgabetabelle erstellen
+ my ($ret,$val0,$val1);
my $i = 0;
-
+
$ret = "";
# Hints
@@ -1094,7 +1106,7 @@ sub DbRep_Get {
$ret .= "";
$ret .= "";
}
-
+
# Notes
if(!$prop || $prop =~ /rel/) {
$ret .= sprintf("$header
");
@@ -1119,10 +1131,10 @@ sub DbRep_Get {
$ret .= "";
$ret .= "
";
}
-
+
$ret .= "";
-
- return $ret;
+
+ return $ret;
} else {
return "$getlist";
@@ -1149,38 +1161,38 @@ sub DbRep_Attr {
my @agentnoattr = qw(aggregation
allowDeletion
autoForward
- dumpDirLocal
+ dumpDirLocal
reading
readingNameMap
readingPreventFromDel
device
- diffAccept
- executeBeforeProc
- executeAfterProc
+ diffAccept
+ executeBeforeProc
+ executeAfterProc
expimpfile
fastStart
- ftpUse
- ftpUser
- ftpUseSSL
- ftpDebug
- ftpDir
- ftpPassive
- ftpPort
- ftpPwd
- ftpServer
- ftpTimeout
- dumpMemlimit
- dumpComment
- dumpSpeed
- optimizeTablesBeforeDump
+ ftpUse
+ ftpUser
+ ftpUseSSL
+ ftpDebug
+ ftpDir
+ ftpPassive
+ ftpPort
+ ftpPwd
+ ftpServer
+ ftpTimeout
+ dumpMemlimit
+ dumpComment
+ dumpSpeed
+ optimizeTablesBeforeDump
seqDoubletsVariance
sqlCmdHistoryLength
- timeYearPeriod
+ timeYearPeriod
timestamp_begin
timestamp_end
timeDiffToNow
timeOlderThan
- sqlResultFormat
+ sqlResultFormat
useAdminCredentials
);
@@ -1190,7 +1202,7 @@ sub DbRep_Attr {
}
$do = 0 if($cmd eq "del");
my $val = ($do == 1 ? "disabled" : "initialized");
- ReadingsSingleUpdateValue ($hash, "state", $val, 1);
+ ReadingsSingleUpdateValue ($hash, "state", $val, 1);
if ($do == 1) {
my $dbh = $hash->{DBH};
$dbh->disconnect() if($dbh);
@@ -1237,16 +1249,16 @@ sub DbRep_Attr {
DbRep_setCmdFile($name."_sqlCmdList","",$hash); # Löschen der sql History Liste im DbRep-Keyfile
}
}
-
- if ($aName eq "userExitFn") {
+
+ if ($aName eq "userExitFn") {
if($cmd eq "set") {
if(!$aVal) {return "Usage of $aName is wrong. The function has to be specified as \" [reading:value]\" ";}
- my @a = split(/ /,$aVal,2);
+ my @a = split(/ /,$aVal,2);
$hash->{HELPER}{USEREXITFN} = $a[0];
- $hash->{HELPER}{UEFN_REGEXP} = $a[1] if($a[1]);
+ $hash->{HELPER}{UEFN_REGEXP} = $a[1] if($a[1]);
} else {
delete $hash->{HELPER}{USEREXITFN} if($hash->{HELPER}{USEREXITFN});
- delete $hash->{HELPER}{UEFN_REGEXP} if($hash->{HELPER}{UEFN_REGEXP});
+ delete $hash->{HELPER}{UEFN_REGEXP} if($hash->{HELPER}{UEFN_REGEXP});
}
}
@@ -1282,7 +1294,7 @@ sub DbRep_Attr {
}
if ($cmd eq "set") {
- if ($aName =~ /valueFilter/) {
+ if ($aName =~ /valueFilter/) {
eval { "Hallo" =~ m/$aVal/ };
return "Bad regexp: $@" if($@);
}
@@ -1302,7 +1314,7 @@ sub DbRep_Attr {
}
}
- if ($aName =~ /seqDoubletsVariance/) {
+ if ($aName =~ /seqDoubletsVariance/) {
my $edge = "";
if($aVal =~ /EDGE=/) {
($aVal,$edge) = split("EDGE=", $aVal);
@@ -1315,24 +1327,24 @@ sub DbRep_Attr {
unless (looks_like_number($varpos) && looks_like_number($varneg)) { return " The Value of $aName is not valid. Only figures are allowed (except \"EDGE\") !";}
}
- if ($aName eq "timeYearPeriod") {
- # 06-01 02-28
+ if ($aName eq "timeYearPeriod") {
+ # 06-01 02-28
unless ($aVal =~ /^(\d{2})-(\d{2}) (\d{2})-(\d{2})$/ )
- { return "The Value of \"$aName\" isn't valid. Set the account period as \"MM-DD MM-DD\".";}
+ { return "The Value of \"$aName\" isn't valid. Set the account period as \"MM-DD MM-DD\".";}
my ($mm1, $dd1, $mm2, $dd2) = ($aVal =~ /^(\d{2})-(\d{2}) (\d{2})-(\d{2})$/);
- my (undef,undef,undef,$mday,$mon,$year1,undef,undef,undef) = localtime(time); # Istzeit Ableitung
- my $year2 = $year1;
+ my (undef,undef,undef,$mday,$mon,$year1,undef,undef,undef) = localtime(time); # Istzeit Ableitung
+ my $year2 = $year1;
# a b c d
# 06-01 02-28 , wenn c < a && $mon < a -> Jahr(a)-1, sonst Jahr(c)+1
- my $c = ($mon+1).$mday;
- my $e = $mm2.$dd2;
+ my $c = ($mon+1).$mday;
+ my $e = $mm2.$dd2;
if ($mm2 <= $mm1 && $c <= $e) {
- $year1--;
- } else {
- $year2++;
- }
+ $year1--;
+ } else {
+ $year2++;
+ }
eval { my $t1 = timelocal(00, 00, 00, $dd1, $mm1-1, $year1-1900);
- my $t2 = timelocal(00, 00, 00, $dd2, $mm2-1, $year2-1900); };
+ my $t2 = timelocal(00, 00, 00, $dd2, $mm2-1, $year2-1900); };
if ($@) {
my @l = split (/at/, $@);
return " The Value of $aName is out of range - $l[0]";
@@ -1351,7 +1363,7 @@ sub DbRep_Attr {
delete($attr{$name}{timeYearPeriod}) if ($attr{$name}{timeYearPeriod});
return undef;
}
- $aVal = DbRep_formatpicker($aVal);
+ $aVal = DbRep_formatpicker($aVal);
unless ($aVal =~ /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/)
{return " The Value of $aName is not valid. Use format YYYY-MM-DD HH:MM:SS or one of \"current_[year|month|day|hour]_begin\",\"current_[year|month|day|hour]_end\", \"previous_[year|month|day|hour]_begin\", \"previous_[year|month|day|hour]_end\" !";}
@@ -1367,41 +1379,41 @@ sub DbRep_Attr {
delete($attr{$name}{timeOlderThan}) if ($attr{$name}{timeOlderThan});
delete($attr{$name}{timeYearPeriod}) if ($attr{$name}{timeYearPeriod});
}
- if ($aName =~ /ftpTimeout|timeout|diffAccept/) {
+ if ($aName =~ /ftpTimeout|timeout|diffAccept/) {
unless ($aVal =~ /^[0-9]+$/) { return " The Value of $aName is not valid. Use only figures 0-9 without decimal places !";}
}
- if ($aName eq "readingNameMap") {
+ if ($aName eq "readingNameMap") {
unless ($aVal =~ m/^[A-Za-z\d_\.-]+$/) { return " Unsupported character in $aName found. Use only A-Z a-z _ . -";}
}
- if ($aName eq "timeDiffToNow") {
+ if ($aName eq "timeDiffToNow") {
unless ($aVal =~ /^[0-9]+$/ || $aVal =~ /^\s*[ydhms]:([\d]+)\s*/ && $aVal !~ /.*,.*/ )
- { return "The Value of \"$aName\" isn't valid. Set simple seconds like \"86400\" or use form like \"y:1 d:10 h:6 m:12 s:20\". Refer to commandref !";}
+ { return "The Value of \"$aName\" isn't valid. Set simple seconds like \"86400\" or use form like \"y:1 d:10 h:6 m:12 s:20\". Refer to commandref !";}
delete($attr{$name}{timestamp_begin}) if ($attr{$name}{timestamp_begin});
delete($attr{$name}{timestamp_end}) if ($attr{$name}{timestamp_end});
delete($attr{$name}{timeYearPeriod}) if ($attr{$name}{timeYearPeriod});
}
- if ($aName eq "timeOlderThan") {
+ if ($aName eq "timeOlderThan") {
unless ($aVal =~ /^[0-9]+$/ || $aVal =~ /^\s*[ydhms]:([\d]+)\s*/ && $aVal !~ /.*,.*/ )
- { return "The Value of \"$aName\" isn't valid. Set simple seconds like \"86400\" or use form like \"y:1 d:10 h:6 m:12 s:20\". Refer to commandref !";}
+ { return "The Value of \"$aName\" isn't valid. Set simple seconds like \"86400\" or use form like \"y:1 d:10 h:6 m:12 s:20\". Refer to commandref !";}
delete($attr{$name}{timestamp_begin}) if ($attr{$name}{timestamp_begin});
delete($attr{$name}{timestamp_end}) if ($attr{$name}{timestamp_end});
delete($attr{$name}{timeYearPeriod}) if ($attr{$name}{timeYearPeriod});
}
- if ($aName eq "dumpMemlimit" || $aName eq "dumpSpeed") {
+ if ($aName eq "dumpMemlimit" || $aName eq "dumpSpeed") {
unless ($aVal =~ /^[0-9]+$/) { return "The Value of $aName is not valid. Use only figures 0-9 without decimal places.";}
- my $dml = AttrVal($name, "dumpMemlimit", 100000);
- my $ds = AttrVal($name, "dumpSpeed", 10000);
- if($aName eq "dumpMemlimit") {
- unless($aVal >= (10 * $ds)) {return "The Value of $aName has to be at least '10 x dumpSpeed' ! ";}
- }
- if($aName eq "dumpSpeed") {
- unless($aVal <= ($dml / 10)) {return "The Value of $aName mustn't be greater than 'dumpMemlimit / 10' ! ";}
- }
+ my $dml = AttrVal($name, "dumpMemlimit", 100000);
+ my $ds = AttrVal($name, "dumpSpeed", 10000);
+ if($aName eq "dumpMemlimit") {
+ unless($aVal >= (10 * $ds)) {return "The Value of $aName has to be at least '10 x dumpSpeed' ! ";}
+ }
+ if($aName eq "dumpSpeed") {
+ unless($aVal <= ($dml / 10)) {return "The Value of $aName mustn't be greater than 'dumpMemlimit / 10' ! ";}
+ }
}
- if ($aName eq "ftpUse") {
+ if ($aName eq "ftpUse") {
delete($attr{$name}{ftpUseSSL});
}
- if ($aName eq "ftpUseSSL") {
+ if ($aName eq "ftpUseSSL") {
delete($attr{$name}{ftpUse});
}
@@ -1411,14 +1423,14 @@ sub DbRep_Attr {
"Make shure you have set them with command \"set $name adminCredentials \" before. ";}
}
- if ($aName eq "reading" || $aName eq "device") {
+ if ($aName eq "reading" || $aName eq "device") {
if ($aVal !~ m/,/ && $dbmodel && $dbmodel ne 'SQLITE') {
my $attrname = uc($aName);
- my $mlen = $hash->{HELPER}{DBREPCOL}{$attrname}?$hash->{HELPER}{DBREPCOL}{$attrname}:$dbrep_col{$attrname};
- return "Length of \"$aName\" is too big. Maximum length for database type $dbmodel is $mlen" if(length($aVal) > $mlen);
+ my $mlen = $hash->{HELPER}{DBREPCOL}{$attrname}?$hash->{HELPER}{DBREPCOL}{$attrname}:$dbrep_col{$attrname};
+ return "Length of \"$aName\" is too big. Maximum length for database type $dbmodel is $mlen" if(length($aVal) > $mlen);
}
}
- }
+ }
return;
}
@@ -1452,7 +1464,7 @@ sub DbRep_Notify {
}
if ($own_hash->{ROLE} eq "Agent") {
- # wenn Rolle "Agent" Verbeitung von RENAMED Events
+ # wenn Rolle "Agent" Verbeitung von RENAMED Events
next if ($event !~ /RENAMED/);
my $strucChanged;
@@ -1472,7 +1484,7 @@ sub DbRep_Notify {
Log3 ($myName, 4, "DbRep Agent $myName - Evt RENAMED rec - old device: $evl[1], new device: $evl[2] -> start deviceRename in DB: $own_hash->{DATABASE} ");
$own_hash->{HELPER}{OLDDEV} = $evl[1];
$own_hash->{HELPER}{NEWDEV} = $evl[2];
- $own_hash->{HELPER}{RENMODE} = "devren";
+ $own_hash->{HELPER}{RENMODE} = "devren";
DbRep_Main($own_hash,"deviceRename");
# die Attribute "device" in allen DbRep-Devices mit der Datenbank = DB des Agenten von alten Device in neues Device ändern
@@ -1576,12 +1588,12 @@ sub DbRep_firstconnect {
}
# DB Struktur aus DbLog Instanz übernehmen
$hash->{HELPER}{DBREPCOL}{COLSET} = $dbloghash->{HELPER}{COLSET};
- $hash->{HELPER}{DBREPCOL}{DEVICE} = $dbloghash->{HELPER}{DEVICECOL};
- $hash->{HELPER}{DBREPCOL}{TYPE} = $dbloghash->{HELPER}{TYPECOL};
- $hash->{HELPER}{DBREPCOL}{EVENT} = $dbloghash->{HELPER}{EVENTCOL};
- $hash->{HELPER}{DBREPCOL}{READING} = $dbloghash->{HELPER}{READINGCOL};
- $hash->{HELPER}{DBREPCOL}{VALUE} = $dbloghash->{HELPER}{VALUECOL};
- $hash->{HELPER}{DBREPCOL}{UNIT} = $dbloghash->{HELPER}{UNITCOL};
+ $hash->{HELPER}{DBREPCOL}{DEVICE} = $dbloghash->{HELPER}{DEVICECOL};
+ $hash->{HELPER}{DBREPCOL}{TYPE} = $dbloghash->{HELPER}{TYPECOL};
+ $hash->{HELPER}{DBREPCOL}{EVENT} = $dbloghash->{HELPER}{EVENTCOL};
+ $hash->{HELPER}{DBREPCOL}{READING} = $dbloghash->{HELPER}{READINGCOL};
+ $hash->{HELPER}{DBREPCOL}{VALUE} = $dbloghash->{HELPER}{VALUECOL};
+ $hash->{HELPER}{DBREPCOL}{UNIT} = $dbloghash->{HELPER}{UNITCOL};
# DB Strukturelemente abrufen
Log3 ($name, 3, "DbRep $name - Connectiontest to database $dbconn with user $dbuser") if($hash->{LASTCMD} ne "minTimestamp");
@@ -1617,8 +1629,8 @@ sub DbRep_getInitData {
($err,$dbh) = DbRep_dbConnect($name,0);
if ($err) {
- $err = encode_base64($err,"");
- return "$name|''|''|$err";
+ $err = encode_base64($err,"");
+ return "$name|''|''|$err";
}
# SQL-Startzeit
@@ -1793,7 +1805,7 @@ sub DbRep_dbConnect {
} else {
$err = "Can't use admin credentials for database access, see logfile !";
Log3 ($name, 2, "DbRep $name - ERROR - admin credentials are needed for database operation, but are not set or can't read it");
- return $err;
+ return $err;
}
}
@@ -1842,19 +1854,19 @@ sub DbRep_Main {
# Readings löschen die nicht in der Ausnahmeliste (Attr readingPreventFromDel) stehen
DbRep_delread($hash);
- if ($opt =~ /dumpMySQL|dumpSQLite/) {
+ if ($opt =~ /dumpMySQL|dumpSQLite/) {
BlockingKill($hash->{HELPER}{RUNNING_BACKUP_CLIENT}) if (exists($hash->{HELPER}{RUNNING_BACKUP_CLIENT}));
BlockingKill($hash->{HELPER}{RUNNING_BCKPREST_SERVER}) if (exists($hash->{HELPER}{RUNNING_BCKPREST_SERVER}));
- BlockingKill($hash->{HELPER}{RUNNING_OPTIMIZE}) if (exists($hash->{HELPER}{RUNNING_OPTIMIZE}));
+ BlockingKill($hash->{HELPER}{RUNNING_OPTIMIZE}) if (exists($hash->{HELPER}{RUNNING_OPTIMIZE}));
if($dbmodel =~ /MYSQL/) {
- if ($prop eq "serverSide") {
- $hash->{HELPER}{RUNNING_BCKPREST_SERVER} = BlockingCall("mysql_DoDumpServerSide", "$name", "DbRep_DumpDone", $to, "DbRep_DumpAborted", $hash);
- ReadingsSingleUpdateValue ($hash, "state", "serverSide Dump is running - be patient and see Logfile !", 1);
- } else {
- $hash->{HELPER}{RUNNING_BACKUP_CLIENT} = BlockingCall("mysql_DoDumpClientSide", "$name", "DbRep_DumpDone", $to, "DbRep_DumpAborted", $hash);
- ReadingsSingleUpdateValue ($hash, "state", "clientSide Dump is running - be patient and see Logfile !", 1);
- }
+ if ($prop eq "serverSide") {
+ $hash->{HELPER}{RUNNING_BCKPREST_SERVER} = BlockingCall("mysql_DoDumpServerSide", "$name", "DbRep_DumpDone", $to, "DbRep_DumpAborted", $hash);
+ ReadingsSingleUpdateValue ($hash, "state", "serverSide Dump is running - be patient and see Logfile !", 1);
+ } else {
+ $hash->{HELPER}{RUNNING_BACKUP_CLIENT} = BlockingCall("mysql_DoDumpClientSide", "$name", "DbRep_DumpDone", $to, "DbRep_DumpAborted", $hash);
+ ReadingsSingleUpdateValue ($hash, "state", "clientSide Dump is running - be patient and see Logfile !", 1);
+ }
}
if($dbmodel =~ /SQLITE/) {
$hash->{HELPER}{RUNNING_BACKUP_CLIENT} = BlockingCall("DbRep_sqliteDoDump", "$name", "DbRep_DumpDone", $to, "DbRep_DumpAborted", $hash);
@@ -1863,13 +1875,13 @@ sub DbRep_Main {
return;
}
- if ($opt =~ /restoreMySQL/) {
+ if ($opt =~ /restoreMySQL/) {
BlockingKill($hash->{HELPER}{RUNNING_RESTORE}) if (exists($hash->{HELPER}{RUNNING_RESTORE}));
BlockingKill($hash->{HELPER}{RUNNING_OPTIMIZE}) if (exists($hash->{HELPER}{RUNNING_OPTIMIZE}));
if($prop =~ /csv/) {
$hash->{HELPER}{RUNNING_RESTORE} = BlockingCall("mysql_RestoreServerSide", "$name|$prop", "DbRep_restoreDone", $to, "DbRep_restoreAborted", $hash);
- } elsif ($prop =~ /sql/) {
+ } elsif ($prop =~ /sql/) {
$hash->{HELPER}{RUNNING_RESTORE} = BlockingCall("mysql_RestoreClientSide", "$name|$prop", "DbRep_restoreDone", $to, "DbRep_restoreAborted", $hash);
} else {
ReadingsSingleUpdateValue ($hash, "state", "restore database error - unknown fileextension \"$prop\"", 1);
@@ -1879,39 +1891,39 @@ sub DbRep_Main {
return;
}
- if ($opt =~ /restoreSQLite/) {
+ if ($opt =~ /restoreSQLite/) {
BlockingKill($hash->{HELPER}{RUNNING_RESTORE}) if (exists($hash->{HELPER}{RUNNING_RESTORE}));
BlockingKill($hash->{HELPER}{RUNNING_OPTIMIZE}) if (exists($hash->{HELPER}{RUNNING_OPTIMIZE}));
$hash->{HELPER}{RUNNING_RESTORE} = BlockingCall("DbRep_sqliteRestore", "$name|$prop", "DbRep_restoreDone", $to, "DbRep_restoreAborted", $hash);
- ReadingsSingleUpdateValue ($hash, "state", "restore database is running - be patient and see Logfile !", 1);
+ ReadingsSingleUpdateValue ($hash, "state", "restore database is running - be patient and see Logfile !", 1);
return;
}
- if ($opt =~ /optimizeTables|vacuum/) {
+ if ($opt =~ /optimizeTables|vacuum/) {
BlockingKill($hash->{HELPER}{RUNNING_OPTIMIZE}) if (exists($hash->{HELPER}{RUNNING_OPTIMIZE}));
BlockingKill($hash->{HELPER}{RUNNING_RESTORE}) if (exists($hash->{HELPER}{RUNNING_RESTORE}));
$hash->{HELPER}{RUNNING_OPTIMIZE} = BlockingCall("DbRep_optimizeTables", "$name", "DbRep_OptimizeDone", $to, "DbRep_OptimizeAborted", $hash);
- ReadingsSingleUpdateValue ($hash, "state", "optimize tables is running - be patient and see Logfile !", 1);
+ ReadingsSingleUpdateValue ($hash, "state", "optimize tables is running - be patient and see Logfile !", 1);
return;
}
- if ($opt =~ /repairSQLite/) {
+ if ($opt =~ /repairSQLite/) {
BlockingKill($hash->{HELPER}{RUNNING_BACKUP_CLIENT}) if (exists($hash->{HELPER}{RUNNING_BACKUP_CLIENT}));
BlockingKill($hash->{HELPER}{RUNNING_OPTIMIZE}) if (exists($hash->{HELPER}{RUNNING_OPTIMIZE}));
BlockingKill($hash->{HELPER}{RUNNING_REPAIR}) if (exists($hash->{HELPER}{RUNNING_REPAIR}));
$hash->{HELPER}{RUNNING_REPAIR} = BlockingCall("DbRep_sqliteRepair", "$name", "DbRep_RepairDone", $to, "DbRep_RepairAborted", $hash);
- ReadingsSingleUpdateValue ($hash, "state", "repair database is running - be patient and see Logfile !", 1);
+ ReadingsSingleUpdateValue ($hash, "state", "repair database is running - be patient and see Logfile !", 1);
return;
}
- if ($opt =~ /index/) {
+ if ($opt =~ /index/) {
if (exists($hash->{HELPER}{RUNNING_INDEX})) {
Log3 ($name, 3, "DbRep $name - WARNING - old process $hash->{HELPER}{RUNNING_INDEX}{pid} will be killed now to start a new index operation");
BlockingKill($hash->{HELPER}{RUNNING_INDEX});
}
Log3 ($name, 3, "DbRep $name - Command: $opt $prop");
$hash->{HELPER}{RUNNING_INDEX} = BlockingCall("DbRep_Index", "$name|$prop", "DbRep_IndexDone", $to, "DbRep_IndexAborted", $hash);
- ReadingsSingleUpdateValue ($hash, "state", "index operation in database is running - be patient and see Logfile !", 1);
+ ReadingsSingleUpdateValue ($hash, "state", "index operation in database is running - be patient and see Logfile !", 1);
$hash->{HELPER}{RUNNING_INDEX}{loglevel} = 5 if($hash->{HELPER}{RUNNING_INDEX}); # Forum #77057
return;
}
@@ -1959,11 +1971,11 @@ sub DbRep_Main {
#############################
if ($opt eq "sumValue") {
$hash->{HELPER}{RUNNING_PID} = BlockingCall("sumval_DoParse", "$name§$device§$reading§$prop§$ts", "sumval_ParseDone", $to, "DbRep_ParseAborted", $hash);
-
+
} elsif ($opt =~ m/countEntries/) {
my $table = $prop;
$hash->{HELPER}{RUNNING_PID} = BlockingCall("count_DoParse", "$name§$table§$device§$reading§$ts", "count_ParseDone", $to, "DbRep_ParseAborted", $hash);
-
+
} elsif ($opt eq "averageValue") {
Log3 ($name, 4, "DbRep $name - averageValue calculation sceme: ".AttrVal($name,"averageCalcForm","avgArithmeticMean"));
$hash->{HELPER}{RUNNING_PID} = BlockingCall("averval_DoParse", "$name§$device§$reading§$prop§$ts", "averval_ParseDone", $to, "DbRep_ParseAborted", $hash);
@@ -2022,13 +2034,13 @@ sub DbRep_Main {
$hash->{HELPER}{RUNNING_PID} = BlockingCall("diffval_DoParse", "$name§$device§$reading§$prop§$ts", "diffval_ParseDone", $to, "DbRep_ParseAborted", $hash);
} elsif ($opt eq "insert") {
- # Daten auf maximale Länge (entsprechend der Feldlänge in DbLog) beschneiden wenn nicht SQLite
- if ($dbmodel ne 'SQLITE') {
- $hash->{HELPER}{I_DEVICE} = substr($hash->{HELPER}{I_DEVICE},0, $hash->{HELPER}{DBREPCOL}{DEVICE});
- $hash->{HELPER}{I_READING} = substr($hash->{HELPER}{I_READING},0, $hash->{HELPER}{DBREPCOL}{READING});
- $hash->{HELPER}{I_VALUE} = substr($hash->{HELPER}{I_VALUE},0, $hash->{HELPER}{DBREPCOL}{VALUE});
- $hash->{HELPER}{I_UNIT} = substr($hash->{HELPER}{I_UNIT},0, $hash->{HELPER}{DBREPCOL}{UNIT}) if($hash->{HELPER}{I_UNIT});
- }
+ # Daten auf maximale Länge (entsprechend der Feldlänge in DbLog) beschneiden wenn nicht SQLite
+ if ($dbmodel ne 'SQLITE') {
+ $hash->{HELPER}{I_DEVICE} = substr($hash->{HELPER}{I_DEVICE},0, $hash->{HELPER}{DBREPCOL}{DEVICE});
+ $hash->{HELPER}{I_READING} = substr($hash->{HELPER}{I_READING},0, $hash->{HELPER}{DBREPCOL}{READING});
+ $hash->{HELPER}{I_VALUE} = substr($hash->{HELPER}{I_VALUE},0, $hash->{HELPER}{DBREPCOL}{VALUE});
+ $hash->{HELPER}{I_UNIT} = substr($hash->{HELPER}{I_UNIT},0, $hash->{HELPER}{DBREPCOL}{UNIT}) if($hash->{HELPER}{I_UNIT});
+ }
$hash->{HELPER}{RUNNING_PID} = BlockingCall("insert_Push", "$name", "insert_Done", $to, "DbRep_ParseAborted", $hash);
} elsif ($opt =~ /deviceRename|readingRename/) {
@@ -2104,11 +2116,11 @@ sub DbRep_Main {
my $nthants = timelocal($sec1, $min1, $hh1, $dd1, $mm1-1, $yyyy1-1900);
my $othants = timelocal($sec2, $min2, $hh2, $dd2, $mm2-1, $yyyy2-1900);
if($nthants > $othants) {
- ReadingsSingleUpdateValue ($hash, "state", "Error - Wrong time limits. The (days newer than) option must be greater than the (older than) one !", 1);
+ ReadingsSingleUpdateValue ($hash, "state", "Error - Wrong time limits. The (days newer than) option must be greater than the (older than) one !", 1);
return;
- }
+ }
$hash->{HELPER}{RUNNING_REDUCELOG} = BlockingCall("DbRep_reduceLog", "$name|$device|$reading|$runtime_string_first|$runtime_string_next", "DbRep_reduceLogDone", $to, "DbRep_reduceLogAborted", $hash);
- ReadingsSingleUpdateValue ($hash, "state", "reduceLog database is running - be patient and see Logfile !", 1);
+ ReadingsSingleUpdateValue ($hash, "state", "reduceLog database is running - be patient and see Logfile !", 1);
$hash->{HELPER}{RUNNING_REDUCELOG}{loglevel} = 5 if($hash->{HELPER}{RUNNING_REDUCELOG}); # Forum #77057
return;
}
@@ -2148,138 +2160,138 @@ sub DbRep_createTimeArray {
if ( my $tap = AttrVal($name, "timeYearPeriod", undef)) {
# a b c d
# 06-01 02-28 , wenn c < a && $mon < a -> Jahr(a)-1, sonst Jahr(c)+1
- my $ybp = $year+1900;
+ my $ybp = $year+1900;
my $yep = $year+1900;
- $tap =~ qr/^(\d{2})-(\d{2}) (\d{2})-(\d{2})$/p;
- my $mbp = $1;
- my $dbp = $2;
- my $mep = $3;
- my $dep = $4;
- my $c = ($mon+1).$mday;
- my $e = $mep.$dep;
+ $tap =~ qr/^(\d{2})-(\d{2}) (\d{2})-(\d{2})$/p;
+ my $mbp = $1;
+ my $dbp = $2;
+ my $mep = $3;
+ my $dep = $4;
+ my $c = ($mon+1).$mday;
+ my $e = $mep.$dep;
if ($mep <= $mbp && $c <= $e) {
- $ybp--;
- } else {
- $yep++;
- }
- $tsbegin = "$ybp-$mbp-$dbp 00:00:00";
- $tsend = "$yep-$mep-$dep 23:59:59";
+ $ybp--;
+ } else {
+ $yep++;
+ }
+ $tsbegin = "$ybp-$mbp-$dbp 00:00:00";
+ $tsend = "$yep-$mep-$dep 23:59:59";
}
if (AttrVal($name,"timestamp_begin","") eq "current_year_begin" ||
AttrVal($name,"timestamp_end","") eq "current_year_begin") {
$tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,0,$year)) if(AttrVal($name,"timestamp_begin","") eq "current_year_begin");
- $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,0,$year)) if(AttrVal($name,"timestamp_end","") eq "current_year_begin");
+ $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,0,$year)) if(AttrVal($name,"timestamp_end","") eq "current_year_begin");
}
if (AttrVal($name, "timestamp_begin", "") eq "current_year_end" ||
AttrVal($name, "timestamp_end", "") eq "current_year_end") {
$tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,31,11,$year)) if(AttrVal($name,"timestamp_begin","") eq "current_year_end");
- $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,31,11,$year)) if(AttrVal($name,"timestamp_end","") eq "current_year_end");
+ $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,31,11,$year)) if(AttrVal($name,"timestamp_end","") eq "current_year_end");
}
if (AttrVal($name, "timestamp_begin", "") eq "previous_year_begin" ||
AttrVal($name, "timestamp_end", "") eq "previous_year_begin") {
$tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,0,$year-1)) if(AttrVal($name, "timestamp_begin", "") eq "previous_year_begin");
- $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,0,$year-1)) if(AttrVal($name, "timestamp_end", "") eq "previous_year_begin");
+ $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,0,$year-1)) if(AttrVal($name, "timestamp_end", "") eq "previous_year_begin");
}
if (AttrVal($name, "timestamp_begin", "") eq "previous_year_end" ||
AttrVal($name, "timestamp_end", "") eq "previous_year_end") {
$tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,31,11,$year-1)) if(AttrVal($name, "timestamp_begin", "") eq "previous_year_end");
- $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,31,11,$year-1)) if(AttrVal($name, "timestamp_end", "") eq "previous_year_end");
+ $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,31,11,$year-1)) if(AttrVal($name, "timestamp_end", "") eq "previous_year_end");
}
if (AttrVal($name, "timestamp_begin", "") eq "current_month_begin" ||
AttrVal($name, "timestamp_end", "") eq "current_month_begin") {
$tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,$mon,$year)) if(AttrVal($name, "timestamp_begin", "") eq "current_month_begin");
- $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,$mon,$year)) if(AttrVal($name, "timestamp_end", "") eq "current_month_begin");
+ $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,$mon,$year)) if(AttrVal($name, "timestamp_end", "") eq "current_month_begin");
}
if (AttrVal($name, "timestamp_begin", "") eq "current_month_end" ||
AttrVal($name, "timestamp_end", "") eq "current_month_end") {
$dim = $mon-1?30+(($mon+1)*3%7<4):28+!($year%4||$year%400*!($year%100));
- $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$dim,$mon,$year)) if(AttrVal($name, "timestamp_begin", "") eq "current_month_end");
+ $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$dim,$mon,$year)) if(AttrVal($name, "timestamp_begin", "") eq "current_month_end");
$tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$dim,$mon,$year)) if(AttrVal($name, "timestamp_end", "") eq "current_month_end");
}
if (AttrVal($name, "timestamp_begin", "") eq "previous_month_begin" ||
AttrVal($name, "timestamp_end", "") eq "previous_month_begin") {
$ryear = ($mon-1<0)?$year-1:$year;
- $rmon = ($mon-1<0)?11:$mon-1;
+ $rmon = ($mon-1<0)?11:$mon-1;
$tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "previous_month_begin");
- $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_month_begin");
+ $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,1,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_month_begin");
}
if (AttrVal($name, "timestamp_begin", "") eq "previous_month_end" ||
AttrVal($name, "timestamp_end", "") eq "previous_month_end") {
$ryear = ($mon-1<0)?$year-1:$year;
- $rmon = ($mon-1<0)?11:$mon-1;
- $dim = $rmon-1?30+(($rmon+1)*3%7<4):28+!($ryear%4||$ryear%400*!($ryear%100));
- $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$dim,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "previous_month_end");
+ $rmon = ($mon-1<0)?11:$mon-1;
+ $dim = $rmon-1?30+(($rmon+1)*3%7<4):28+!($ryear%4||$ryear%400*!($ryear%100));
+ $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$dim,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "previous_month_end");
$tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$dim,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_month_end");
}
if (AttrVal($name, "timestamp_begin", "") eq "current_week_begin" ||
AttrVal($name, "timestamp_end", "") eq "current_week_begin") {
- $tsub = 0 if($wday == 1); # wenn Start am "Mo" keine Korrektur
- $tsub = 86400 if($wday == 2); # wenn Start am "Di" dann Korrektur -1 Tage
- $tsub = 172800 if($wday == 3); # wenn Start am "Mi" dann Korrektur -2 Tage
- $tsub = 259200 if($wday == 4); # wenn Start am "Do" dann Korrektur -3 Tage
- $tsub = 345600 if($wday == 5); # wenn Start am "Fr" dann Korrektur -4 Tage
- $tsub = 432000 if($wday == 6); # wenn Start am "Sa" dann Korrektur -5 Tage
- $tsub = 518400 if($wday == 0); # wenn Start am "So" dann Korrektur -6 Tage
- ($rsec,$rmin,$rhour,$rmday,$rmon,$ryear) = localtime(time-$tsub);
- $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "current_week_begin");
- $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "current_week_begin");
+ $tsub = 0 if($wday == 1); # wenn Start am "Mo" keine Korrektur
+ $tsub = 86400 if($wday == 2); # wenn Start am "Di" dann Korrektur -1 Tage
+ $tsub = 172800 if($wday == 3); # wenn Start am "Mi" dann Korrektur -2 Tage
+ $tsub = 259200 if($wday == 4); # wenn Start am "Do" dann Korrektur -3 Tage
+ $tsub = 345600 if($wday == 5); # wenn Start am "Fr" dann Korrektur -4 Tage
+ $tsub = 432000 if($wday == 6); # wenn Start am "Sa" dann Korrektur -5 Tage
+ $tsub = 518400 if($wday == 0); # wenn Start am "So" dann Korrektur -6 Tage
+ ($rsec,$rmin,$rhour,$rmday,$rmon,$ryear) = localtime(time-$tsub);
+ $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "current_week_begin");
+ $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "current_week_begin");
}
if (AttrVal($name, "timestamp_begin", "") eq "current_week_end" ||
AttrVal($name, "timestamp_end", "") eq "current_week_end") {
- $tadd = 518400 if($wday == 1); # wenn Start am "Mo" dann Korrektur +6 Tage
- $tadd = 432000 if($wday == 2); # wenn Start am "Di" dann Korrektur +5 Tage
- $tadd = 345600 if($wday == 3); # wenn Start am "Mi" dann Korrektur +4 Tage
- $tadd = 259200 if($wday == 4); # wenn Start am "Do" dann Korrektur +3 Tage
- $tadd = 172800 if($wday == 5); # wenn Start am "Fr" dann Korrektur +2 Tage
- $tadd = 86400 if($wday == 6); # wenn Start am "Sa" dann Korrektur +1 Tage
- $tadd = 0 if($wday == 0); # wenn Start am "So" keine Korrektur
- ($rsec,$rmin,$rhour,$rmday,$rmon,$ryear) = localtime(time+$tadd);
- $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "current_week_end");
- $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "current_week_end");
+ $tadd = 518400 if($wday == 1); # wenn Start am "Mo" dann Korrektur +6 Tage
+ $tadd = 432000 if($wday == 2); # wenn Start am "Di" dann Korrektur +5 Tage
+ $tadd = 345600 if($wday == 3); # wenn Start am "Mi" dann Korrektur +4 Tage
+ $tadd = 259200 if($wday == 4); # wenn Start am "Do" dann Korrektur +3 Tage
+ $tadd = 172800 if($wday == 5); # wenn Start am "Fr" dann Korrektur +2 Tage
+ $tadd = 86400 if($wday == 6); # wenn Start am "Sa" dann Korrektur +1 Tage
+ $tadd = 0 if($wday == 0); # wenn Start am "So" keine Korrektur
+ ($rsec,$rmin,$rhour,$rmday,$rmon,$ryear) = localtime(time+$tadd);
+ $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "current_week_end");
+ $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "current_week_end");
}
if (AttrVal($name, "timestamp_begin", "") eq "previous_week_begin" ||
AttrVal($name, "timestamp_end", "") eq "previous_week_begin") {
- $tsub = 604800 if($wday == 1); # wenn Start am "Mo" dann Korrektur -7 Tage
- $tsub = 691200 if($wday == 2); # wenn Start am "Di" dann Korrektur -8 Tage
- $tsub = 777600 if($wday == 3); # wenn Start am "Mi" dann Korrektur -9 Tage
- $tsub = 864000 if($wday == 4); # wenn Start am "Do" dann Korrektur -10 Tage
- $tsub = 950400 if($wday == 5); # wenn Start am "Fr" dann Korrektur -11 Tage
- $tsub = 1036800 if($wday == 6); # wenn Start am "Sa" dann Korrektur -12 Tage
- $tsub = 1123200 if($wday == 0); # wenn Start am "So" dann Korrektur -13 Tage
- ($rsec,$rmin,$rhour,$rmday,$rmon,$ryear) = localtime(time-$tsub);
- $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "previous_week_begin");
- $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_week_begin");
+ $tsub = 604800 if($wday == 1); # wenn Start am "Mo" dann Korrektur -7 Tage
+ $tsub = 691200 if($wday == 2); # wenn Start am "Di" dann Korrektur -8 Tage
+ $tsub = 777600 if($wday == 3); # wenn Start am "Mi" dann Korrektur -9 Tage
+ $tsub = 864000 if($wday == 4); # wenn Start am "Do" dann Korrektur -10 Tage
+ $tsub = 950400 if($wday == 5); # wenn Start am "Fr" dann Korrektur -11 Tage
+ $tsub = 1036800 if($wday == 6); # wenn Start am "Sa" dann Korrektur -12 Tage
+ $tsub = 1123200 if($wday == 0); # wenn Start am "So" dann Korrektur -13 Tage
+ ($rsec,$rmin,$rhour,$rmday,$rmon,$ryear) = localtime(time-$tsub);
+ $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "previous_week_begin");
+ $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_week_begin");
}
if (AttrVal($name, "timestamp_begin", "") eq "previous_week_end" ||
AttrVal($name, "timestamp_end", "") eq "previous_week_end") {
- $tsub = 86400 if($wday == 1); # wenn Start am "Mo" dann Korrektur -1 Tage
- $tsub = 172800 if($wday == 2); # wenn Start am "Di" dann Korrektur -2 Tage
- $tsub = 259200 if($wday == 3); # wenn Start am "Mi" dann Korrektur -3 Tage
- $tsub = 345600 if($wday == 4); # wenn Start am "Do" dann Korrektur -4 Tage
- $tsub = 432000 if($wday == 5); # wenn Start am "Fr" dann Korrektur -5 Tage
- $tsub = 518400 if($wday == 6); # wenn Start am "Sa" dann Korrektur -6 Tage
- $tsub = 604800 if($wday == 0); # wenn Start am "So" dann Korrektur -7 Tage
- ($rsec,$rmin,$rhour,$rmday,$rmon,$ryear) = localtime(time-$tsub);
- $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "previous_week_end");
- $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_week_end");
+ $tsub = 86400 if($wday == 1); # wenn Start am "Mo" dann Korrektur -1 Tage
+ $tsub = 172800 if($wday == 2); # wenn Start am "Di" dann Korrektur -2 Tage
+ $tsub = 259200 if($wday == 3); # wenn Start am "Mi" dann Korrektur -3 Tage
+ $tsub = 345600 if($wday == 4); # wenn Start am "Do" dann Korrektur -4 Tage
+ $tsub = 432000 if($wday == 5); # wenn Start am "Fr" dann Korrektur -5 Tage
+ $tsub = 518400 if($wday == 6); # wenn Start am "Sa" dann Korrektur -6 Tage
+ $tsub = 604800 if($wday == 0); # wenn Start am "So" dann Korrektur -7 Tage
+ ($rsec,$rmin,$rhour,$rmday,$rmon,$ryear) = localtime(time-$tsub);
+ $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "previous_week_end");
+ $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_week_end");
}
if (AttrVal($name, "timestamp_begin", "") eq "current_day_begin" ||
AttrVal($name, "timestamp_end", "") eq "current_day_begin") {
$tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$mday,$mon,$year)) if(AttrVal($name, "timestamp_begin", "") eq "current_day_begin");
- $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$mday,$mon,$year)) if(AttrVal($name, "timestamp_end", "") eq "current_day_begin");
+ $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$mday,$mon,$year)) if(AttrVal($name, "timestamp_end", "") eq "current_day_begin");
}
if (AttrVal($name, "timestamp_begin", "") eq "current_day_end" ||
@@ -2290,34 +2302,34 @@ sub DbRep_createTimeArray {
if (AttrVal($name, "timestamp_begin", "") eq "previous_day_begin" ||
AttrVal($name, "timestamp_end", "") eq "previous_day_begin") {
- $rmday = $mday-1;
- $rmon = $mon;
- $ryear = $year;
- if($rmday<1) {
- $rmon--;
- if ($rmon<0) {
- $rmon=11;
- $ryear--;
- }
+ $rmday = $mday-1;
+ $rmon = $mon;
+ $ryear = $year;
+ if($rmday<1) {
+ $rmon--;
+ if ($rmon<0) {
+ $rmon=11;
+ $ryear--;
+ }
$rmday = $rmon-1?30+(($rmon+1)*3%7<4):28+!($ryear%4||$ryear%400*!($ryear%100)); # Achtung: Monat als 1...12 (statt 0...11)
- }
+ }
$tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "previous_day_begin");
- $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_day_begin");
+ $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,0,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_day_begin");
}
if (AttrVal($name, "timestamp_begin", "") eq "previous_day_end" ||
AttrVal($name, "timestamp_end", "") eq "previous_day_end") {
- $rmday = $mday-1;
- $rmon = $mon;
- $ryear = $year;
- if($rmday<1) {
- $rmon--;
- if ($rmon<0) {
- $rmon=11;
- $ryear--;
- }
+ $rmday = $mday-1;
+ $rmon = $mon;
+ $ryear = $year;
+ if($rmday<1) {
+ $rmon--;
+ if ($rmon<0) {
+ $rmon=11;
+ $ryear--;
+ }
$rmday = $rmon-1?30+(($rmon+1)*3%7<4):28+!($ryear%4||$ryear%400*!($ryear%100)); # Achtung: Monat als 1...12 (statt 0...11)
- }
+ }
$tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "previous_day_end");
$tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,23,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_day_end");
}
@@ -2325,56 +2337,56 @@ sub DbRep_createTimeArray {
if (AttrVal($name, "timestamp_begin", "") eq "current_hour_begin" ||
AttrVal($name, "timestamp_end", "") eq "current_hour_begin") {
$tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,$hour,$mday,$mon,$year)) if(AttrVal($name, "timestamp_begin", "") eq "current_hour_begin");
- $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,$hour,$mday,$mon,$year)) if(AttrVal($name, "timestamp_end", "") eq "current_hour_begin");
+ $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,$hour,$mday,$mon,$year)) if(AttrVal($name, "timestamp_end", "") eq "current_hour_begin");
}
if (AttrVal($name, "timestamp_begin", "") eq "current_hour_end" ||
AttrVal($name, "timestamp_end", "") eq "current_hour_end") {
- $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,$hour,$mday,$mon,$year)) if(AttrVal($name, "timestamp_begin", "") eq "current_hour_end");
+ $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,$hour,$mday,$mon,$year)) if(AttrVal($name, "timestamp_begin", "") eq "current_hour_end");
$tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,$hour,$mday,$mon,$year)) if(AttrVal($name, "timestamp_end", "") eq "current_hour_end");
}
if (AttrVal($name, "timestamp_begin", "") eq "previous_hour_begin" ||
AttrVal($name, "timestamp_end", "") eq "previous_hour_begin") {
$rhour = $hour-1;
- $rmday = $mday;
- $rmon = $mon;
- $ryear = $year;
- if($rhour<0) {
- $rhour = 23;
- $rmday = $mday-1;
- if($rmday<1) {
- $rmon--;
- if ($rmon<0) {
- $rmon=11;
- $ryear--;
- }
- $rmday = $rmon-1?30+(($rmon+1)*3%7<4):28+!($ryear%4||$ryear%400*!($ryear%100)); # Achtung: Monat als 1...12 (statt 0...11)
- }
- }
+ $rmday = $mday;
+ $rmon = $mon;
+ $ryear = $year;
+ if($rhour<0) {
+ $rhour = 23;
+ $rmday = $mday-1;
+ if($rmday<1) {
+ $rmon--;
+ if ($rmon<0) {
+ $rmon=11;
+ $ryear--;
+ }
+ $rmday = $rmon-1?30+(($rmon+1)*3%7<4):28+!($ryear%4||$ryear%400*!($ryear%100)); # Achtung: Monat als 1...12 (statt 0...11)
+ }
+ }
$tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,$rhour,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "previous_hour_begin");
- $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,$rhour,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_hour_begin");
+ $tsend = strftime "%Y-%m-%d %T",localtime(timelocal(0,0,$rhour,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_hour_begin");
}
if (AttrVal($name, "timestamp_begin", "") eq "previous_hour_end" ||
AttrVal($name, "timestamp_end", "") eq "previous_hour_end") {
$rhour = $hour-1;
- $rmday = $mday;
- $rmon = $mon;
- $ryear = $year;
- if($rhour<0) {
- $rhour = 23;
- $rmday = $mday-1;
- if($rmday<1) {
- $rmon--;
- if ($rmon<0) {
- $rmon=11;
- $ryear--;
- }
- $rmday = $rmon-1?30+(($rmon+1)*3%7<4):28+!($ryear%4||$ryear%400*!($ryear%100)); # Achtung: Monat als 1...12 (statt 0...11)
- }
- }
- $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,$rhour,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "previous_hour_end");
+ $rmday = $mday;
+ $rmon = $mon;
+ $ryear = $year;
+ if($rhour<0) {
+ $rhour = 23;
+ $rmday = $mday-1;
+ if($rmday<1) {
+ $rmon--;
+ if ($rmon<0) {
+ $rmon=11;
+ $ryear--;
+ }
+ $rmday = $rmon-1?30+(($rmon+1)*3%7<4):28+!($ryear%4||$ryear%400*!($ryear%100)); # Achtung: Monat als 1...12 (statt 0...11)
+ }
+ }
+ $tsbegin = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,$rhour,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_begin", "") eq "previous_hour_end");
$tsend = strftime "%Y-%m-%d %T",localtime(timelocal(59,59,$rhour,$rmday,$rmon,$ryear)) if(AttrVal($name, "timestamp_end", "") eq "previous_hour_end");
}
@@ -2400,7 +2412,7 @@ sub DbRep_createTimeArray {
if($fdopt) { # FullDay Option ist gesetzt
my $tbs = strftime "%Y-%m-%d %H:%M:%S", localtime($epoch_seconds_begin);
$tbs =~ /^(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+)$/;
- $epoch_seconds_begin = timelocal(00, 00, 00, $3, $2-1, $1-1900);
+ $epoch_seconds_begin = timelocal(00, 00, 00, $3, $2-1, $1-1900);
}
my $tsbegin_string = strftime "%Y-%m-%d %H:%M:%S", localtime($epoch_seconds_begin);
@@ -2420,7 +2432,7 @@ sub DbRep_createTimeArray {
if($fdopt) { # FullDay Option ist gesetzt
my $tes = strftime "%Y-%m-%d %H:%M:%S", localtime($epoch_seconds_end);
$tes =~ /^(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+)$/;
- $epoch_seconds_end = timelocal(59, 59, 23, $3, $2-1, $1-1900);
+ $epoch_seconds_end = timelocal(59, 59, 23, $3, $2-1, $1-1900);
}
my $tsend_string = strftime "%Y-%m-%d %H:%M:%S", localtime($epoch_seconds_end);
@@ -2815,7 +2827,7 @@ sub averval_DoParse {
$selspec = "TIMESTAMP,VALUE";
$qlf = "avgtwm";
}
-
+
# SQL-Startzeit
my $st = [gettimeofday];
@@ -2832,21 +2844,21 @@ sub averval_DoParse {
#
if ($IsTimeSet || $IsAggrSet) {
$sql = DbRep_createSelectSql($hash,"history",$selspec,$device,$reading,"'$runtime_string_first'","'$runtime_string_next'",$addon);
- } else {
- $sql = DbRep_createSelectSql($hash,"history",$selspec,$device,$reading,undef,undef,$addon);
- }
+ } else {
+ $sql = DbRep_createSelectSql($hash,"history",$selspec,$device,$reading,undef,undef,$addon);
+ }
Log3 ($name, 4, "DbRep $name - SQL execute: $sql");
eval{ $sth = $dbh->prepare($sql);
$sth->execute();
- };
- if ($@) {
+ };
+ if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - $@");
$dbh->disconnect;
return "$name|''|$device|$reading|''|$err|''";
}
-
+
my @line = $sth->fetchrow_array();
Log3 ($name, 5, "DbRep $name - SQL result: $line[0]") if($line[0]);
@@ -2885,13 +2897,13 @@ sub averval_DoParse {
my $bsel = $bdate." ".sprintf("%02d",$i).":00:00";
my $esel = ($i<23)?$bdate." ".sprintf("%02d",$i).":59:59":$runtime_string_next;
- $sql = DbRep_createSelectSql($hash,"history",$selspec,$device,$reading,"'$bsel'","'$esel'",$addon);
+ $sql = DbRep_createSelectSql($hash,"history",$selspec,$device,$reading,"'$bsel'","'$esel'",$addon);
Log3 ($name, 4, "DbRep $name - SQL execute: $sql");
eval{ $sth = $dbh->prepare($sql);
$sth->execute();
- };
- if ($@) {
+ };
+ if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - $@");
$dbh->disconnect;
@@ -2899,7 +2911,7 @@ sub averval_DoParse {
}
my $val = $sth->fetchrow_array();
Log3 ($name, 5, "DbRep $name - SQL result: $val") if($val);
- $val = DbRep_numval ($val); # nichtnumerische Zeichen eliminieren
+ $val = DbRep_numval ($val); # nichtnumerische Zeichen eliminieren
if(defined($val) && looks_like_number($val)) {
$sum += $val;
$t01 = $val if($val && $i == 00); # Wert f. Stunde 01 ist zw. letzter Wert vor 01
@@ -2959,7 +2971,7 @@ sub averval_DoParse {
eval { $tf = ($dbh->selectrow_array($sqlf))[0];
$tl = ($dbh->selectrow_array($sqll))[0];
};
- if ($@) {
+ if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - $@");
$dbh->disconnect;
@@ -2976,14 +2988,14 @@ sub averval_DoParse {
if ($IsTimeSet || $IsAggrSet) {
$sql = DbRep_createSelectSql($hash,"history",$selspec,$device,$reading,"'$runtime_string_first'","'$runtime_string_next'",$addon);
- } else {
- $sql = DbRep_createSelectSql($hash,"history",$selspec,$device,$reading,undef,undef,$addon);
- }
+ } else {
+ $sql = DbRep_createSelectSql($hash,"history",$selspec,$device,$reading,undef,undef,$addon);
+ }
Log3 ($name, 4, "DbRep $name - SQL execute: $sql");
eval{ $sth = $dbh->prepare($sql);
$sth->execute();
- };
+ };
if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - $@");
@@ -2995,7 +3007,7 @@ sub averval_DoParse {
foreach my $twmrow (@twm_array) {
($tn,$val) = split("_ESC_",$twmrow);
- $val = DbRep_numval ($val); # nichtnumerische Zeichen eliminieren
+ $val = DbRep_numval ($val); # nichtnumerische Zeichen eliminieren
my ($yyyyt1, $mmt1, $ddt1, $hht1, $mint1, $sect1) = ($tn =~ /(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/);
$tn = timelocal($sect1, $mint1, $hht1, $ddt1, $mmt1-1, $yyyyt1-1900);
if(!$to) {
@@ -3124,7 +3136,7 @@ sub averval_ParseDone {
$reading_runtime_string = $rsf.$ds.$rds."AVG".$acf."__".$runtime_string;
}
if($acf eq "DMGWS") {
- ReadingsBulkUpdateValue ($hash, $reading_runtime_string, looks_like_number($c)?sprintf("%.1f",$c):$c);
+ ReadingsBulkUpdateValue ($hash, $reading_runtime_string, looks_like_number($c)?sprintf("%.1f",$c):$c);
} else {
ReadingsBulkUpdateValue ($hash, $reading_runtime_string, $c?sprintf("%.4f",$c):"-");
}
@@ -3203,14 +3215,14 @@ sub count_DoParse {
if ($IsTimeSet || $IsAggrSet) {
$sql = DbRep_createSelectSql($hash,$table,$selspec,$device,$reading,"'$runtime_string_first'","'$runtime_string_next'",$addon);
- } else {
- $sql = DbRep_createSelectSql($hash,$table,$selspec,$device,$reading,undef,undef,$addon);
- }
+ } else {
+ $sql = DbRep_createSelectSql($hash,$table,$selspec,$device,$reading,undef,undef,$addon);
+ }
Log3 ($name, 4, "DbRep $name - SQL execute: $sql");
eval{ $sth = $dbh->prepare($sql);
$sth->execute();
- };
+ };
if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - $@");
@@ -3307,7 +3319,7 @@ sub count_ParseDone {
}
}
- ReadingsBulkUpdateValue ($hash, $reading_runtime_string, $c?$c:"-");
+ ReadingsBulkUpdateValue ($hash, $reading_runtime_string, $c?$c:"-");
}
ReadingsBulkUpdateTimeState($hash,$brt,$rt,"done");
@@ -3366,14 +3378,14 @@ sub maxval_DoParse {
if ($IsTimeSet || $IsAggrSet) {
$sql = DbRep_createSelectSql($hash,"history","VALUE,TIMESTAMP",$device,$reading,"'$runtime_string_first'","'$runtime_string_next'","ORDER BY TIMESTAMP");
- } else {
- $sql = DbRep_createSelectSql($hash,"history","VALUE,TIMESTAMP",$device,$reading,undef,undef,"ORDER BY TIMESTAMP");
- }
+ } else {
+ $sql = DbRep_createSelectSql($hash,"history","VALUE,TIMESTAMP",$device,$reading,undef,undef,"ORDER BY TIMESTAMP");
+ }
Log3 ($name, 4, "DbRep $name - SQL execute: $sql");
eval{ $sth = $dbh->prepare($sql);
$sth->execute();
- };
+ };
if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - $@");
@@ -3614,14 +3626,14 @@ sub minval_DoParse {
if ($IsTimeSet || $IsAggrSet) {
$sql = DbRep_createSelectSql($hash,"history","VALUE,TIMESTAMP",$device,$reading,"'$runtime_string_first'","'$runtime_string_next'","ORDER BY TIMESTAMP");
- } else {
- $sql = DbRep_createSelectSql($hash,"history","VALUE,TIMESTAMP",$device,$reading,undef,undef,"ORDER BY TIMESTAMP");
- }
+ } else {
+ $sql = DbRep_createSelectSql($hash,"history","VALUE,TIMESTAMP",$device,$reading,undef,undef,"ORDER BY TIMESTAMP");
+ }
Log3 ($name, 4, "DbRep $name - SQL execute: $sql");
eval{ $sth = $dbh->prepare($sql);
$sth->execute();
- };
+ };
if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - $@");
@@ -3801,7 +3813,7 @@ sub minval_ParseDone {
$reading_runtime_string = $rsf.$ds.$rds."MIN__".$k[0];
}
my $rv = $k[1];
-
+
ReadingsBulkUpdateValue ($hash, $reading_runtime_string, defined($rv)?sprintf("%.4f",$rv):"-");
}
@@ -3870,59 +3882,59 @@ sub diffval_DoParse {
my $runtime_string_next = $a[2];
$runtime_string = encode_base64($runtime_string,"");
- if($dbmodel eq "MYSQL") {
- eval {$dbh->do("set \@V:= 0, \@diff:= 0, \@diffTotal:= 0, \@RB:= 1;");}; # @\RB = Resetbit wenn neues Selektionsintervall beginnt
+ if($dbmodel eq "MYSQL") {
+ eval {$dbh->do("set \@V:= 0, \@diff:= 0, \@diffTotal:= 0, \@RB:= 1;");}; # @\RB = Resetbit wenn neues Selektionsintervall beginnt
}
- if ($@) {
+ if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - $@");
$dbh->disconnect;
return "$name|''|$device|$reading|''|''|''|$err|''";
}
-
+
if ($IsTimeSet || $IsAggrSet) {
$sql = DbRep_createSelectSql($hash,"history",$selspec,$device,$reading,"'$runtime_string_first'","'$runtime_string_next'",'ORDER BY TIMESTAMP');
- } else {
- $sql = DbRep_createSelectSql($hash,"history",$selspec,$device,$reading,undef,undef,'ORDER BY TIMESTAMP');
- }
+ } else {
+ $sql = DbRep_createSelectSql($hash,"history",$selspec,$device,$reading,undef,undef,'ORDER BY TIMESTAMP');
+ }
Log3 ($name, 4, "DbRep $name - SQL execute: $sql");
eval{ $sth = $dbh->prepare($sql);
$sth->execute();
- };
+ };
if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - $@");
$dbh->disconnect;
return "$name|''|$device|$reading|''|''|''|$err|''";
- } else {
- if($dbmodel eq "MYSQL") {
- @array = map { $runtime_string." ".$_ -> [0]." ".$_ -> [1]." ".$_ -> [2]."\n" } @{ $sth->fetchall_arrayref() };
+ } else {
+ if($dbmodel eq "MYSQL") {
+ @array = map { $runtime_string." ".$_ -> [0]." ".$_ -> [1]." ".$_ -> [2]."\n" } @{ $sth->fetchall_arrayref() };
} else {
- @array = map { $runtime_string." ".$_ -> [0]." ".$_ -> [1]."\n" } @{ $sth->fetchall_arrayref() };
+ @array = map { $runtime_string." ".$_ -> [0]." ".$_ -> [1]."\n" } @{ $sth->fetchall_arrayref() };
- if (@array) {
- my @sp;
- my $dse = 0;
- my $vold;
- my @sqlite_array;
+ if (@array) {
+ my @sp;
+ my $dse = 0;
+ my $vold;
+ my @sqlite_array;
foreach my $row (@array) {
@sp = split("[ \t][ \t]*", $row, 4);
my $runtime_string = $sp[0];
- my $timestamp = $sp[2]?$sp[1]." ".$sp[2]:$sp[1];
+ my $timestamp = $sp[2]?$sp[1]." ".$sp[2]:$sp[1];
my $vnew = $sp[3];
- $vnew =~ tr/\n//d;
+ $vnew =~ tr/\n//d;
- $dse = ($vold && (($vnew-$vold) > 0))?($vnew-$vold):0;
- @sp = $runtime_string." ".$timestamp." ".$vnew." ".$dse."\n";
- $vold = $vnew;
+ $dse = ($vold && (($vnew-$vold) > 0))?($vnew-$vold):0;
+ @sp = $runtime_string." ".$timestamp." ".$vnew." ".$dse."\n";
+ $vold = $vnew;
push(@sqlite_array, @sp);
}
- @array = @sqlite_array;
- }
- }
-
+ @array = @sqlite_array;
+ }
+ }
+
if(!@array) {
my $aval = AttrVal($name, "aggregation", "");
if($aval eq "hour") {
@@ -3986,49 +3998,49 @@ sub diffval_DoParse {
Log3 ($name, 5, "DbRep $name - Runtimestring: $runtime_string, DEVICE: $device, READING: $reading, \nTIMESTAMP: $timestamp, VALUE: $value, DIFF: $diff");
- # String ignorierter Zeilen erzeugen
- $diff_current = $timestamp." ".$diff;
- if($diff > $difflimit) {
- $rejectstr .= $diff_before." -> ".$diff_current."\n";
- }
- $diff_before = $diff_current;
-
- # Ergebnishash erzeugen
+ # String ignorierter Zeilen erzeugen
+ $diff_current = $timestamp." ".$diff;
+ if($diff > $difflimit) {
+ $rejectstr .= $diff_before." -> ".$diff_current."\n";
+ }
+ $diff_before = $diff_current;
+
+ # Ergebnishash erzeugen
if ($runtime_string eq $lastruntimestring) {
if ($i == 1) {
- $diff_total = $diff?$diff:0 if($diff <= $difflimit);
- $rh{$runtime_string} = $runtime_string."|".$diff_total."|".$timestamp;
+ $diff_total = $diff?$diff:0 if($diff <= $difflimit);
+ $rh{$runtime_string} = $runtime_string."|".$diff_total."|".$timestamp;
$ch{$runtime_string} = 1 if($value);
$lval = $value;
- $rslval = $runtime_string;
+ $rslval = $runtime_string;
}
if ($diff) {
- if($diff <= $difflimit) {
+ if($diff <= $difflimit) {
$diff_total = $diff_total+$diff;
- }
+ }
$rh{$runtime_string} = $runtime_string."|".$diff_total."|".$timestamp;
$ch{$runtime_string}++ if($value && $i > 1);
$lval = $value;
- $rslval = $runtime_string;
+ $rslval = $runtime_string;
}
} else {
# neuer Zeitabschnitt beginnt, ersten Value-Wert erfassen und Übertragsdifferenz bilden
$lastruntimestring = $runtime_string;
$i = 1;
-
- $uediff = $value - $lval if($value > $lval);
+
+ $uediff = $value - $lval if($value > $lval);
$diff = $uediff;
- $lval = $value if($value); # Übetrag über Perioden mit value = 0 hinweg !
+ $lval = $value if($value); # Übetrag über Perioden mit value = 0 hinweg !
$rslval = $runtime_string;
- Log3 ($name, 4, "DbRep $name - balance difference of $uediff between $rslval and $runtime_string");
-
-
+ Log3 ($name, 4, "DbRep $name - balance difference of $uediff between $rslval and $runtime_string");
+
+
$diff_total = $diff?$diff:0 if($diff <= $difflimit);
$rh{$runtime_string} = $runtime_string."|".$diff_total."|".$timestamp;
- $ch{$runtime_string} = 1 if($value);
+ $ch{$runtime_string} = 1 if($value);
- $uediff = 0;
+ $uediff = 0;
}
$i++;
}
@@ -4046,7 +4058,7 @@ sub diffval_DoParse {
foreach my $key (sort(keys%{$ncp})) {
Log3 ($name, 3, $key) ;
}
- $ncps = join('§', %$ncp);
+ $ncps = join('§', %$ncp);
$ncpslist = encode_base64($ncps,"");
}
@@ -4145,7 +4157,7 @@ sub diffval_ParseDone {
foreach my $key (sort(keys(%rh))) {
my @k = split("\\|",$rh{$key});
my $rts = $k[2]."__";
- $rts =~ s/:/-/g; # substituieren unsupported characters -> siehe fhem.pl
+ $rts =~ s/:/-/g; # substituieren unsupported characters -> siehe fhem.pl
if (AttrVal($hash->{NAME}, "readingNameMap", "")) {
$reading_runtime_string = $rts.AttrVal($hash->{NAME}, "readingNameMap", "")."__".$k[0];
@@ -4215,7 +4227,7 @@ sub sumval_DoParse {
} else {
$selspec = "SUM(VALUE)";
}
-
+
# SQL-Startzeit
my $st = [gettimeofday];
@@ -4229,26 +4241,26 @@ sub sumval_DoParse {
if ($IsTimeSet || $IsAggrSet) {
$sql = DbRep_createSelectSql($hash,"history",$selspec,$device,$reading,"'$runtime_string_first'","'$runtime_string_next'",'');
- } else {
+ } else {
$sql = DbRep_createSelectSql($hash,"history",$selspec,$device,$reading,undef,undef,'');
- }
+ }
Log3 ($name, 4, "DbRep $name - SQL execute: $sql");
eval{ $sth = $dbh->prepare($sql);
$sth->execute();
- };
- if ($@) {
+ };
+ if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - $@");
$dbh->disconnect;
return "$name|''|$device|$reading|''|$err|''";
}
-
+
# DB-Abfrage -> Ergebnis in @arr aufnehmen
my @line = $sth->fetchrow_array();
Log3 ($name, 5, "DbRep $name - SQL result: $line[0]") if($line[0]);
-
+
if(AttrVal($name, "aggregation", "") eq "hour") {
@rsf = split(/[ :]/,$runtime_string_first);
@rsn = split(/[ :]/,$runtime_string_next);
@@ -4346,7 +4358,7 @@ sub sumval_ParseDone {
$reading_runtime_string = $rsf.$ds.$rds."SUM__".$runtime_string;
}
- ReadingsBulkUpdateValue ($hash, $reading_runtime_string, $c?sprintf("%.4f",$c):"-");
+ ReadingsBulkUpdateValue ($hash, $reading_runtime_string, $c?sprintf("%.4f",$c):"-");
}
ReadingsBulkUpdateValue ($hash, "db_lines_processed", $irowdone) if($hash->{LASTCMD} =~ /writeToDB/);
@@ -4539,7 +4551,7 @@ sub insert_Push {
if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - $@");
- $dbh->disconnect();
+ $dbh->disconnect();
return "$name|''|''|$err";
}
@@ -4657,33 +4669,33 @@ sub currentfillup_Push {
# SQL zusammenstellen für DB-Operation
if ($usepkc && $dbloghash->{MODEL} eq 'MYSQL') {
$selspec = "INSERT IGNORE INTO current (TIMESTAMP,DEVICE,READING) SELECT timestamp,device,reading FROM history where";
- $addon = "group by timestamp,device,reading";
-
+ $addon = "group by timestamp,device,reading";
+
} elsif ($usepkc && $dbloghash->{MODEL} eq 'SQLITE') {
$selspec = "INSERT OR IGNORE INTO current (TIMESTAMP,DEVICE,READING) SELECT timestamp,device,reading FROM history where";
- $addon = "group by timestamp,device,reading";
+ $addon = "group by timestamp,device,reading";
} elsif ($usepkc && $dbloghash->{MODEL} eq 'POSTGRESQL') {
$selspec = "INSERT INTO current (DEVICE,TIMESTAMP,READING) SELECT device, (array_agg(timestamp ORDER BY reading ASC))[1], reading FROM history where";
- $addon = "group by device,reading ON CONFLICT ($pkc) DO NOTHING";
+ $addon = "group by device,reading ON CONFLICT ($pkc) DO NOTHING";
} else {
if($dbloghash->{MODEL} ne 'POSTGRESQL') {
- # MySQL und SQLite
+ # MySQL und SQLite
$selspec = "INSERT INTO current (TIMESTAMP,DEVICE,READING) SELECT timestamp,device,reading FROM history where";
- $addon = "group by device,reading";
- } else {
- # PostgreSQL
+ $addon = "group by device,reading";
+ } else {
+ # PostgreSQL
$selspec = "INSERT INTO current (DEVICE,TIMESTAMP,READING) SELECT device, (array_agg(timestamp ORDER BY reading ASC))[1], reading FROM history where";
- $addon = "group by device,reading";
- }
+ $addon = "group by device,reading";
+ }
}
# SQL-Statement zusammenstellen
if ($IsTimeSet || $IsAggrSet) {
- $sql = DbRep_createCommonSql($hash,$selspec,$device,$reading,"'$runtime_string_first'","'$runtime_string_next'",$addon);
+ $sql = DbRep_createCommonSql($hash,$selspec,$device,$reading,"'$runtime_string_first'","'$runtime_string_next'",$addon);
} else {
- $sql = DbRep_createCommonSql($hash,$selspec,$device,$reading,undef,undef,$addon);
+ $sql = DbRep_createCommonSql($hash,$selspec,$device,$reading,undef,undef,$addon);
}
# Log SQL Statement
@@ -4693,7 +4705,7 @@ sub currentfillup_Push {
if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - $@");
- $dbh->disconnect();
+ $dbh->disconnect();
return "$name|''|''|$err|''|''";
}
@@ -4810,35 +4822,35 @@ sub change_Push {
if ($renmode eq "devren") {
$old = delete $hash->{HELPER}{OLDDEV};
$new = delete $hash->{HELPER}{NEWDEV};
-
- # SQL zusammenstellen für DB-Operation
+
+ # SQL zusammenstellen für DB-Operation
Log3 ($name, 5, "DbRep $name -> Rename old device name \"$old\" to new device name \"$new\" in database $dblogname ");
-
- # prepare DB operation
- $old =~ s/'/''/g; # escape ' with ''
- $new =~ s/'/''/g; # escape ' with ''
- $sql = "UPDATE history SET TIMESTAMP=TIMESTAMP,DEVICE='$new' WHERE DEVICE='$old'; ";
- Log3 ($name, 4, "DbRep $name - SQL execute: $sql");
- $sth = $dbh->prepare($sql) ;
+
+ # prepare DB operation
+ $old =~ s/'/''/g; # escape ' with ''
+ $new =~ s/'/''/g; # escape ' with ''
+ $sql = "UPDATE history SET TIMESTAMP=TIMESTAMP,DEVICE='$new' WHERE DEVICE='$old'; ";
+ Log3 ($name, 4, "DbRep $name - SQL execute: $sql");
+ $sth = $dbh->prepare($sql) ;
} elsif ($renmode eq "readren") {
$old = delete $hash->{HELPER}{OLDREAD};
($dev,$old) = split(":",$old,2) if($old =~ /:/); # Wert besteht aus [device]:old_readingname, device ist optional
$new = delete $hash->{HELPER}{NEWREAD};
-
- # SQL zusammenstellen für DB-Operation
+
+ # SQL zusammenstellen für DB-Operation
Log3 ($name, 5, "DbRep $name -> Rename old reading name \"".($dev?"$dev:$old":"$old")."\" to new reading name \"$new\" in database $dblogname ");
-
- # prepare DB operation
- $old =~ s/'/''/g; # escape ' with ''
- $new =~ s/'/''/g; # escape ' with ''
+
+ # prepare DB operation
+ $old =~ s/'/''/g; # escape ' with ''
+ $new =~ s/'/''/g; # escape ' with ''
if($dev) {
$sql = "UPDATE history SET TIMESTAMP=TIMESTAMP,READING='$new' WHERE DEVICE='$dev' AND READING='$old'; ";
} else {
- $sql = "UPDATE history SET TIMESTAMP=TIMESTAMP,READING='$new' WHERE READING='$old'; ";
+ $sql = "UPDATE history SET TIMESTAMP=TIMESTAMP,READING='$new' WHERE READING='$old'; ";
}
- Log3 ($name, 4, "DbRep $name - SQL execute: $sql");
- $sth = $dbh->prepare($sql) ;
+ Log3 ($name, 4, "DbRep $name - SQL execute: $sql");
+ $sth = $dbh->prepare($sql) ;
}
@@ -4849,9 +4861,9 @@ sub change_Push {
eval { $sth->execute(); };
if ($@) {
$err = encode_base64($@,"");
- my $m = ($renmode eq "devren")?"device":"reading";
+ my $m = ($renmode eq "devren")?"device":"reading";
Log3 ($name, 2, "DbRep $name - Failed to rename old $m name \"$old\" to new $m name \"$new\": $@");
- $dbh->rollback() if(!$dbh->{AutoCommit});
+ $dbh->rollback() if(!$dbh->{AutoCommit});
$dbh->disconnect();
return "$name|''|''|$err";
} else {
@@ -4916,12 +4928,12 @@ sub changeval_Push {
$old = delete $hash->{HELPER}{OLDVAL};
$new = delete $hash->{HELPER}{NEWVAL};
- # SQL zusammenstellen für DB-Operation
+ # SQL zusammenstellen für DB-Operation
Log3 ($name, 5, "DbRep $name -> Change old value \"$old\" to new value \"$new\" in database $dblogname ");
-
- # prepare DB operation
- $old =~ s/'/''/g; # escape ' with ''
- $new =~ s/'/''/g; # escape ' with ''
+
+ # prepare DB operation
+ $old =~ s/'/''/g; # escape ' with ''
+ $new =~ s/'/''/g; # escape ' with ''
# SQL zusammenstellen für DB-Update
my $addon = $old =~ /%/?"WHERE VALUE LIKE '$old'":"WHERE VALUE='$old'";
@@ -4931,8 +4943,8 @@ sub changeval_Push {
} else {
$sql = DbRep_createCommonSql($hash,$selspec,$device,$reading,undef,undef,'');
}
- Log3 ($name, 4, "DbRep $name - SQL execute: $sql");
- $sth = $dbh->prepare($sql) ;
+ Log3 ($name, 4, "DbRep $name - SQL execute: $sql");
+ $sth = $dbh->prepare($sql) ;
$old =~ s/''/'/g; # escape back
$new =~ s/''/'/g; # escape back
@@ -4941,7 +4953,7 @@ sub changeval_Push {
if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - Failed to change old value \"$old\" to new value \"$new\": $@");
- $dbh->rollback() if(!$dbh->{AutoCommit});
+ $dbh->rollback() if(!$dbh->{AutoCommit});
$dbh->disconnect();
return "$name|''|''|$err";
} else {
@@ -4970,15 +4982,15 @@ sub changeval_Push {
if ($IsTimeSet || $IsAggrSet) {
$sql = DbRep_createSelectSql($hash,"history",$selspec,$device,$reading,"'$runtime_string_first'","'$runtime_string_next'",$addon);
- } else {
- $sql = DbRep_createSelectSql($hash,"history",$selspec,$device,$reading,undef,undef,$addon);
- }
+ } else {
+ $sql = DbRep_createSelectSql($hash,"history",$selspec,$device,$reading,undef,undef,$addon);
+ }
Log3 ($name, 4, "DbRep $name - SQL execute: $sql");
eval{ $sth = $dbh->prepare($sql);
$sth->execute();
- };
- if ($@) {
+ };
+ if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - $@");
$dbh->disconnect;
@@ -4998,9 +5010,9 @@ sub changeval_Push {
my $oval = $value; # Selektkriterium für Update alter Valuewert
my $VALUE = $value;
- my $UNIT = $unit;
+ my $UNIT = $unit;
eval $new;
- if ($@) {
+ if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - $@");
$dbh->disconnect;
@@ -5008,7 +5020,7 @@ sub changeval_Push {
}
$value = $VALUE if(defined $VALUE);
- $unit = $UNIT if(defined $UNIT);
+ $unit = $UNIT if(defined $UNIT);
# Daten auf maximale Länge beschneiden (DbLog-Funktion !)
(undef,undef,undef,undef,$value,$unit) = DbLog_cutCol($dbloghash,"1","1","1","1",$value,$unit);
@@ -5017,8 +5029,8 @@ sub changeval_Push {
# SQL zusammenstellen für DB-Update
$sql = "UPDATE history SET TIMESTAMP=TIMESTAMP,VALUE='$value',UNIT='$unit' WHERE TIMESTAMP = '$date $time' AND DEVICE = '$device' AND READING = '$reading' AND VALUE='$oval'";
- Log3 ($name, 5, "DbRep $name - SQL execute: $sql");
- $sth = $dbh->prepare($sql) ;
+ Log3 ($name, 5, "DbRep $name - SQL execute: $sql");
+ $sth = $dbh->prepare($sql) ;
$value =~ s/''/'/g; # escape back
$unit =~ s/''/'/g; # escape back
@@ -5027,7 +5039,7 @@ sub changeval_Push {
if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - Failed to change old value \"$old\" to new value \"$new\": $@");
- $dbh->rollback() if(!$dbh->{AutoCommit});
+ $dbh->rollback() if(!$dbh->{AutoCommit});
$dbh->disconnect();
return "$name|''|''|$err";
} else {
@@ -5086,19 +5098,19 @@ sub change_Done {
ReadingsBulkUpdateValue ($hash, "number_lines_updated", $urow);
if($renmode eq "devren") {
- ReadingsBulkUpdateValue ($hash, "device_renamed", "old: ".$old." to new: ".$new) if($urow != 0);
+ ReadingsBulkUpdateValue ($hash, "device_renamed", "old: ".$old." to new: ".$new) if($urow != 0);
ReadingsBulkUpdateValue ($hash, "device_not_renamed", "Warning - old: ".$old." not found, not renamed to new: ".$new)
- if($urow == 0);
+ if($urow == 0);
}
if($renmode eq "readren") {
- ReadingsBulkUpdateValue ($hash, "reading_renamed", "old: ".$old." to new: ".$new) if($urow != 0);
+ ReadingsBulkUpdateValue ($hash, "reading_renamed", "old: ".$old." to new: ".$new) if($urow != 0);
ReadingsBulkUpdateValue ($hash, "reading_not_renamed", "Warning - old: ".$old." not found, not renamed to new: ".$new)
- if ($urow == 0);
+ if ($urow == 0);
}
if($renmode eq "changeval") {
- ReadingsBulkUpdateValue ($hash, "value_changed", "old: ".$old." to new: ".$new) if($urow != 0);
+ ReadingsBulkUpdateValue ($hash, "value_changed", "old: ".$old." to new: ".$new) if($urow != 0);
ReadingsBulkUpdateValue ($hash, "value_not_changed", "Warning - old: ".$old." not found, not changed to new: ".$new)
- if ($urow == 0);
+ if ($urow == 0);
}
ReadingsBulkUpdateTimeState($hash,$brt,$rt,"done");
@@ -5106,12 +5118,12 @@ sub change_Done {
if ($urow != 0) {
Log3 ($name, 3, "DbRep ".(($hash->{ROLE} eq "Agent")?"Agent ":"")."$name - DEVICE renamed in \"$hash->{DATABASE}\", old: \"$old\", new: \"$new\", number: $urow ") if($renmode eq "devren");
- Log3 ($name, 3, "DbRep ".(($hash->{ROLE} eq "Agent")?"Agent ":"")."$name - READING renamed in \"$hash->{DATABASE}\", old: \"$old\", new: \"$new\", number: $urow ") if($renmode eq "readren");
- Log3 ($name, 3, "DbRep ".(($hash->{ROLE} eq "Agent")?"Agent ":"")."$name - VALUE changed in \"$hash->{DATABASE}\", old: \"$old\", new: \"$new\", number: $urow ") if($renmode eq "changeval");
+ Log3 ($name, 3, "DbRep ".(($hash->{ROLE} eq "Agent")?"Agent ":"")."$name - READING renamed in \"$hash->{DATABASE}\", old: \"$old\", new: \"$new\", number: $urow ") if($renmode eq "readren");
+ Log3 ($name, 3, "DbRep ".(($hash->{ROLE} eq "Agent")?"Agent ":"")."$name - VALUE changed in \"$hash->{DATABASE}\", old: \"$old\", new: \"$new\", number: $urow ") if($renmode eq "changeval");
} else {
Log3 ($name, 3, "DbRep ".(($hash->{ROLE} eq "Agent")?"Agent ":"")."$name - WARNING - old device \"$old\" was not found in database \"$hash->{DATABASE}\" ") if($renmode eq "devren");
- Log3 ($name, 3, "DbRep ".(($hash->{ROLE} eq "Agent")?"Agent ":"")."$name - WARNING - old reading \"$old\" was not found in database \"$hash->{DATABASE}\" ") if($renmode eq "readren");
- Log3 ($name, 3, "DbRep ".(($hash->{ROLE} eq "Agent")?"Agent ":"")."$name - WARNING - old value \"$old\" not found in database \"$hash->{DATABASE}\" ") if($renmode eq "changeval");
+ Log3 ($name, 3, "DbRep ".(($hash->{ROLE} eq "Agent")?"Agent ":"")."$name - WARNING - old reading \"$old\" was not found in database \"$hash->{DATABASE}\" ") if($renmode eq "readren");
+ Log3 ($name, 3, "DbRep ".(($hash->{ROLE} eq "Agent")?"Agent ":"")."$name - WARNING - old value \"$old\" not found in database \"$hash->{DATABASE}\" ") if($renmode eq "changeval");
}
return;
@@ -5251,7 +5263,7 @@ sub fetchrows_ParseDone {
$a[3] =~ s/:/-/g; # substituieren unsupported characters ":" -> siehe fhem.pl
my $ts = $a[2]."_".$a[3];
my $val = $a[4];
- my $unt = $a[5];
+ my $unt = $a[5];
$val = $unt?$val." ".$unt:$val;
$nrow = $ts.$dev.$rea;
@@ -5304,7 +5316,7 @@ sub fetchrows_ParseDone {
}
}
- ReadingsBulkUpdateValue($hash, $reading_runtime_string, $val);
+ ReadingsBulkUpdateValue($hash, $reading_runtime_string, $val);
}
my $sfx = AttrVal("global", "language", "EN");
$sfx = ($sfx eq "EN" ? "" : "_$sfx");
@@ -5378,15 +5390,15 @@ sub deldoublets_DoParse {
my $runtime_string_first = $a[1];
my $runtime_string_next = $a[2];
$runtime_string = encode_base64($runtime_string,"");
-
- # SQL-Startzeit
+
+ # SQL-Startzeit
$st = [gettimeofday];
# SQL zusammenstellen für Logausgabe
- my $sql1 = DbRep_createSelectSql($hash,$table,$selspec,$device,$reading,"'$runtime_string_first'","'$runtime_string_next'",$addon);
+ my $sql1 = DbRep_createSelectSql($hash,$table,$selspec,$device,$reading,"'$runtime_string_first'","'$runtime_string_next'",$addon);
Log3 ($name, 4, "DbRep $name - SQL execute: $sql1");
- eval{$sth->execute($runtime_string_first, $runtime_string_next);};
+ eval{$sth->execute($runtime_string_first, $runtime_string_next);};
if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - $@");
@@ -5398,7 +5410,7 @@ sub deldoublets_DoParse {
$rt = $rt+tv_interval($st);
# Beginn Löschlogik, Zusammenstellen der zu löschenden DS (warping)
- # Array @warp -> die zu löschenden Datensätze
+ # Array @warp -> die zu löschenden Datensätze
my (@warp);
my $i = 0;
foreach my $nr (map { $_->[1]."_ESC_".$_->[2]."_ESC_".($_->[0] =~ s/ /_ESC_/r)."_ESC_".$_->[3]."_|_".($_->[4]-1) } @{$sth->fetchall_arrayref()}) {
@@ -5419,7 +5431,7 @@ sub deldoublets_DoParse {
$dev =~ s/'/''/g; # escape ' with ''
$read =~ s/'/''/g; # escape ' with ''
$val =~ s/'/''/g; # escape ' with ''
- $val =~ s/\\/\\\\/g if($model eq "MYSQL"); # escape \ with \\ für MySQL
+ $val =~ s/\\/\\\\/g if($model eq "MYSQL"); # escape \ with \\ für MySQL
$st = [gettimeofday];
if($model =~ /MYSQL|SQLITE/) {
$dsql = "delete FROM $table WHERE TIMESTAMP = '$dt' AND DEVICE = '$dev' AND READING = '$read' AND VALUE = '$val' limit $limit;";
@@ -5549,15 +5561,15 @@ sub delseqdoubl_DoParse {
my $runtime_string_first = $a[1];
my $runtime_string_next = $a[2];
$runtime_string = encode_base64($runtime_string,"");
-
- # SQL-Startzeit
+
+ # SQL-Startzeit
$st = [gettimeofday];
# SQL zusammenstellen für Logausgabe
- my $sql1 = DbRep_createSelectSql($hash,$table,$selspec,$device,$reading,"'$runtime_string_first'","'$runtime_string_next'",'');
+ my $sql1 = DbRep_createSelectSql($hash,$table,$selspec,$device,$reading,"'$runtime_string_first'","'$runtime_string_next'",'');
Log3 ($name, 4, "DbRep $name - SQL execute: $sql1");
- eval{$sth->execute($runtime_string_first, $runtime_string_next);};
+ eval{$sth->execute($runtime_string_first, $runtime_string_next);};
if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - $@");
@@ -5569,13 +5581,13 @@ sub delseqdoubl_DoParse {
$rt = $rt+tv_interval($st);
# Beginn Löschlogik, Zusammenstellen der löschenden DS (warping)
- # Array @sel -> die VERBLEIBENDEN Datensätze, @warp -> die zu löschenden Datensätze
+ # Array @sel -> die VERBLEIBENDEN Datensätze, @warp -> die zu löschenden Datensätze
my (@sel,@warp);
my ($or,$oor,$odev,$oread,$oval,$ooval,$ndev,$nread,$nval);
my $i = 0;
foreach my $nr (map { $_->[0]."_ESC_".$_->[1]."_ESC_".($_->[2] =~ s/ /_ESC_/r)."_ESC_".$_->[3] } @{$sth->fetchall_arrayref()}) {
($ndev,$nread,undef,undef,$nval) = split("_ESC_", $nr); # Werte des aktuellen Elements
- $or = pop @sel; # das letzte Element der Liste
+ $or = pop @sel; # das letzte Element der Liste
($odev,$oread,undef,undef,$oval) = split("_ESC_", $or); # Value des letzten Elements
if (looks_like_number($oval) && defined $varpos && defined $varneg) { # unterschiedliche Varianz +/- für numerische Werte
@@ -5588,16 +5600,16 @@ sub delseqdoubl_DoParse {
undef $varo;
undef $varu;
}
- $oor = pop @sel; # das vorletzte Element der Liste
- $ooval = (split '_ESC_', $oor)[-1]; # Value des vorletzten Elements
- # Log3 ($name, 1, "DbRep $name - OOVAL: $ooval, OVAL: $oval, VARO: $varo, VARU: $varu");
+ $oor = pop @sel; # das vorletzte Element der Liste
+ $ooval = (split '_ESC_', $oor)[-1]; # Value des vorletzten Elements
+ # Log3 ($name, 1, "DbRep $name - OOVAL: $ooval, OVAL: $oval, VARO: $varo, VARU: $varu");
if ($ndev.$nread ne $odev.$oread) {
$i = 0; # neues Device/Reading in einer Periode -> ooor soll erhalten bleiben
- push (@sel,$oor) if($oor);
- push (@sel,$or) if($or);
- push (@sel,$nr);
-
+ push (@sel,$oor) if($oor);
+ push (@sel,$or) if($or);
+ push (@sel,$nr);
+
} elsif ($i>=2 && ($ooval eq $oval && $oval eq $nval) ||
($i>=2 && $varo && $varu && ($ooval <= $varo) && ($varu <= $ooval) && ($nval <= $varo) && ($varu <= $nval)) ) {
if ($edge =~ /negative/i && ($ooval > $oval)) {
@@ -5615,34 +5627,34 @@ sub delseqdoubl_DoParse {
}
if ($opt =~ /delete/ && $or) { # delete Datensätze
- my ($dev,$read,$date,$time,$val) = split("_ESC_", $or);
- my $dt = $date." ".$time;
- chomp($val);
- $dev =~ s/'/''/g; # escape ' with ''
- $read =~ s/'/''/g; # escape ' with ''
- $val =~ s/'/''/g; # escape ' with ''
- $st = [gettimeofday];
- my $dsql = "delete FROM $table where TIMESTAMP = '$dt' AND DEVICE = '$dev' AND READING = '$read' AND VALUE = '$val';";
- my $sthd = $dbh->prepare($dsql);
+ my ($dev,$read,$date,$time,$val) = split("_ESC_", $or);
+ my $dt = $date." ".$time;
+ chomp($val);
+ $dev =~ s/'/''/g; # escape ' with ''
+ $read =~ s/'/''/g; # escape ' with ''
+ $val =~ s/'/''/g; # escape ' with ''
+ $st = [gettimeofday];
+ my $dsql = "delete FROM $table where TIMESTAMP = '$dt' AND DEVICE = '$dev' AND READING = '$read' AND VALUE = '$val';";
+ my $sthd = $dbh->prepare($dsql);
Log3 ($name, 4, "DbRep $name - SQL execute: $dsql");
-
- eval {$sthd->execute();};
- if ($@) {
+
+ eval {$sthd->execute();};
+ if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - $@");
$dbh->disconnect;
return "$name|''|''|$err|''|$opt";
}
- $ndel = $ndel+$sthd->rows;
+ $ndel = $ndel+$sthd->rows;
$dbh->commit() if(!$dbh->{AutoCommit});
-
- $rt = $rt+tv_interval($st);
- }
+
+ $rt = $rt+tv_interval($st);
+ }
} else {
- push (@sel,$oor) if($oor);
- push (@sel,$or) if($or);
- push (@sel,$nr);
- }
+ push (@sel,$oor) if($oor);
+ push (@sel,$or) if($or);
+ push (@sel,$nr);
+ }
$i++;
}
if(@sel && $opt =~ /adviceRemain/) {
@@ -5731,9 +5743,9 @@ sub delseqdoubl_ParseDone {
s/_E#S#C_/\|/g for @row_array; # escaped Pipe return to "|"
Log3 ($name, 5, "DbRep $name - row_array decoded: @row_array");
foreach my $row (@row_array) {
- last if($l >= $limit);
+ last if($l >= $limit);
my @a = split("_ESC_", $row, 5);
- my $dev = $a[0];
+ my $dev = $a[0];
my $rea = $a[1];
$a[3] =~ s/:/-/g; # substituieren unsupported characters ":" -> siehe fhem.pl
my $ts = $a[2]."_".$a[3];
@@ -5744,8 +5756,8 @@ sub delseqdoubl_ParseDone {
} else {
$reading_runtime_string = $ts."__".$dev."__".$rea;
}
- ReadingsBulkUpdateValue($hash, $reading_runtime_string, $val);
- $l++;
+ ReadingsBulkUpdateValue($hash, $reading_runtime_string, $val);
+ $l++;
}
}
@@ -5852,15 +5864,15 @@ sub expfile_DoParse {
if ($IsTimeSet || $IsAggrSet) {
$sql = DbRep_createSelectSql($hash,"history","TIMESTAMP,DEVICE,TYPE,EVENT,READING,VALUE,UNIT",$device,$reading,"'$runtime_string_first'","'$runtime_string_next'",$addon);
- } else {
+ } else {
$sql = DbRep_createSelectSql($hash,"history","TIMESTAMP,DEVICE,TYPE,EVENT,READING,VALUE,UNIT",$device,$reading,undef,undef,$addon);
- }
+ }
Log3 ($name, 4, "DbRep $name - SQL execute: $sql");
eval{ $sth = $dbh->prepare($sql);
$sth->execute();
- };
- if ($@) {
+ };
+ if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - $@");
$dbh->disconnect;
@@ -6019,7 +6031,7 @@ sub impfile_Push {
if ($@) {
$err = encode_base64($@,"");
Log3 ($name, 2, "DbRep $name - $@");
- $dbh->disconnect();
+ $dbh->disconnect();
return "$name|''|''|$err|''";
}
@@ -6032,7 +6044,7 @@ sub impfile_Push {
$al = $_;
chomp $al;
my @alarr = split("\",\"", $al);
- foreach(@alarr) {
+ foreach(@alarr) {
tr/"//d;
}
my $i_timestamp = DbRep_trim($alarr[0]);
@@ -6172,8 +6184,8 @@ sub sqlCmd_DoParse {
($err,$dbh) = DbRep_dbConnect($name,0);
if ($err) {
- $err = encode_base64($err,"");
- return "$name|''|$opt|$cmd|''|''|$err";
+ $err = encode_base64($err,"");
+ return "$name|''|$opt|$cmd|''|''|$err";
}
# only for this block because of warnings if details of readings are not set
@@ -6278,8 +6290,8 @@ sub sqlCmd_DoParse {
Log3 ($name, 4, "DbRep $name - SQL result: @line");
$row = join("$srs", @line);
- # join Delimiter "§" escapen
- $row =~ s/§/|°escaped°|/g;
+ # join Delimiter "§" escapen
+ $row =~ s/§/|°escaped°|/g;
push(@rows, $row);
# Anzahl der Datensätze
@@ -6294,10 +6306,10 @@ sub sqlCmd_DoParse {
$dbh->disconnect;
return "$name|''|$opt|$sql|''|''|$err";
}
-
- push(@rows, $r);
- my $com = (split(" ",$sql, 2))[0];
- Log3 ($name, 3, "DbRep $name - Number of entries processed in db $hash->{DATABASE}: $nrows by $com");
+
+ push(@rows, $r);
+ my $com = (split(" ",$sql, 2))[0];
+ Log3 ($name, 3, "DbRep $name - Number of entries processed in db $hash->{DATABASE}: $nrows by $com");
}
$sth->finish;
@@ -6380,58 +6392,58 @@ sub sqlCmd_ParseDone {
ReadingsBulkUpdateValue ($hash, "SqlResult", $rowstring);
} elsif ($srf eq "table") {
- my $res = "";
- my @rows = split( /§/, $rowstring );
+ my $res = "";
+ my @rows = split( /§/, $rowstring );
my $row;
- foreach $row ( @rows ) {
- $row =~ s/\|°escaped°\|/§/g;
- $row =~ s/$srs/\|/g if($srs !~ /\|/);
- $row =~ s/\|/<\/td>/g;
+ foreach $row ( @rows ) {
+ $row =~ s/\|°escaped°\|/§/g;
+ $row =~ s/$srs/\|/g if($srs !~ /\|/);
+ $row =~ s/\|/<\/td> | /g;
$res .= " | ".$row." |
";
}
- $row .= $res."
";
-
- ReadingsBulkUpdateValue ($hash,"SqlResult", $row);
-
+ $row .= $res."
";
+
+ ReadingsBulkUpdateValue ($hash,"SqlResult", $row);
+
} elsif ($srf eq "mline") {
my $res = "";
- my @rows = split( /§/, $rowstring );
+ my @rows = split( /§/, $rowstring );
my $row;
- foreach $row ( @rows ) {
- $row =~ s/\|°escaped°\|/§/g;
+ foreach $row ( @rows ) {
+ $row =~ s/\|°escaped°\|/§/g;
$res .= $row."
";
}
- $row .= $res."";
-
+ $row .= $res."