From e7461300db87b83eccfa5d9ecf22b8e665cb18da Mon Sep 17 00:00:00 2001 From: tobiasfaust Date: Tue, 5 Mar 2013 19:14:41 +0000 Subject: [PATCH] 93_DbLog.pm: Changes only for SQLite - Moves the 'current' table to memory and modifies a few internal parameters in SQLite to minimize flash wear. - Makes easier to setup DbLog with SQLite. Database tables are created if not exists automatically when the database is opened. git-svn-id: https://svn.fhem.de/fhem/trunk@2855 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/93_DbLog.pm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fhem/FHEM/93_DbLog.pm b/fhem/FHEM/93_DbLog.pm index eb2bf0a7f..07b591290 100644 --- a/fhem/FHEM/93_DbLog.pm +++ b/fhem/FHEM/93_DbLog.pm @@ -396,6 +396,15 @@ DbLog_Connect($) Log 3, "Connection to db $dbconn established"; $hash->{DBH}= $dbh; + if ($hash->{DBMODEL} eq "SQLITE") { + $dbh->do("PRAGMA temp_store=MEMORY"); + $dbh->do("PRAGMA synchronous=NORMAL"); + $dbh->do("PRAGMA journal_mode=WAL"); + $dbh->do("CREATE TEMP TABLE IF NOT EXISTS current (TIMESTAMP TIMESTAMP, DEVICE varchar(32), TYPE varchar(32), EVENT varchar(512), READING varchar(32), VALUE varchar(32), UNIT varchar(32))"); + $dbh->do("CREATE TABLE IF NOT EXISTS history (TIMESTAMP TIMESTAMP, DEVICE varchar(32), TYPE varchar(32), EVENT varchar(512), READING varchar(32), VALUE varchar(32), UNIT varchar(32))"); + $dbh->do("CREATE INDEX IF NOT EXISTS Search_Idx ON `history` (DEVICE, READING, TIMESTAMP)"); + } + return 1; }