From 2721b4767112db32a9b3be3aef87a32f5dc0f81f Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Tue, 30 Mar 2021 15:34:42 +0000 Subject: [PATCH] 93_DbLog: contrib 4.12.0 git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@24117 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- contrib/DS_Starter/93_DbLog.pm | 43 ++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/contrib/DS_Starter/93_DbLog.pm b/contrib/DS_Starter/93_DbLog.pm index f875b0c8e..7c2f8c47c 100644 --- a/contrib/DS_Starter/93_DbLog.pm +++ b/contrib/DS_Starter/93_DbLog.pm @@ -456,6 +456,11 @@ sub DbLog_Attr { if ($aName eq "shutdownWait") { return "DbLog $name - The attribute $aName is deprecated and has been removed !"; + } + + if ($aName eq "SQLiteCacheSize" || $aName eq "SQLiteJournalMode") { + InternalTimer(gettimeofday()+1.0, "DbLog_attrForSQLite", $hash, 0); + InternalTimer(gettimeofday()+1.5, "DbLog_attrForSQLite", $hash, 0); # muß zweimal ausgeführt werden - Grund unbekannt :-( } } @@ -564,6 +569,29 @@ sub DbLog_Attr { return; } +################################################################ +# reopen DB beim Setzen bestimmter Attribute +################################################################ +sub DbLog_attrForSQLite { + my $hash = shift; + + return if($hash->{MODEL} ne "SQLITE"); + + my $name = $hash->{NAME}; + + my $dbh = $hash->{DBHP}; + if ($dbh) { + my $history = $hash->{HELPER}{TH}; + if(!$dbh->{AutoCommit}) { + eval {$dbh->commit()} or Log3($name, 2, "DbLog $name -> Error commit $history - $@"); + } + $dbh->disconnect(); + } + DbLog_ConnectPush ($hash,1); + +return; +} + ################################################################ sub DbLog_Set { my ($hash, @a) = @_; @@ -3242,12 +3270,16 @@ sub DbLog_ConnectPush { if (AttrVal($name, "SQLiteJournalMode", "WAL") eq "off") { $dbhp->do("PRAGMA journal_mode=off"); + $hash->{SQLITEWALMODE} = "off"; } else { $dbhp->do("PRAGMA journal_mode=WAL"); + $hash->{SQLITEWALMODE} = "on"; } - $dbhp->do("PRAGMA cache_size=". AttrVal($name, "SQLiteCacheSize", "4000")); + my $cs = AttrVal($name, "SQLiteCacheSize", "4000"); + $dbhp->do("PRAGMA cache_size=$cs"); + $hash->{SQLITECACHESIZE} = $cs; } return 1; @@ -7678,8 +7710,7 @@ attr SMA_Energymeter DbLogValueFn Since WAL about doubles the spaces requirements on disk it might not be the best fit for embedded devices using a RAM backed disk. off will turn the journaling off. In case of corruption, the database probably won't be possible to repair and has to be recreated!
- (default: WAL)

- Note: FHEM must be restarted to take this attribute affected ! + (default: WAL) @@ -9144,8 +9175,7 @@ attr SMA_Energymeter DbLogValueFn Standardmäßig werden ca. 4MB RAM für Caching verwendet (page_size=1024bytes, cache_size=4000).
Bei Embedded Devices mit wenig RAM genügen auch 1000 Pages - zu Lasten der Performance.
- (default: 4000)

- Note: FHEM muß nach der Attributänderung restarted werden ! + (default: 4000) @@ -9165,8 +9195,7 @@ attr SMA_Energymeter DbLogValueFn Festplattenplatz (z.B. eine RAM Disk in Embedded Devices) kann das Journal deaktiviert werden (off). Im Falle eines Datenfehlers kann die Datenbank aber wahrscheinlich nicht repariert werden, und muss neu erstellt werden!
- (default: WAL)

- Note: FHEM muß nach der Attributänderung restarted werden ! + (default: WAL)