From 0f47ba10adaa6c94cff146463c476a934df1a335 Mon Sep 17 00:00:00 2001 From: betateilchen <> Date: Mon, 3 Mar 2014 13:13:52 +0000 Subject: [PATCH] configDB.pm - changed: improved migration performance git-svn-id: https://svn.fhem.de/fhem/trunk@5107 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/configDB.pm | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/fhem/configDB.pm b/fhem/configDB.pm index 5685611d3..327f6b015 100644 --- a/fhem/configDB.pm +++ b/fhem/configDB.pm @@ -49,8 +49,6 @@ sub AnalyzeCommandChain($$;$); sub Debug($); sub Log3($$$); -#$cfgDB_svnId = '$Id$'; - ################################################## # Read configuration file # @@ -117,6 +115,9 @@ sub cfgDB_Init { eval { $fhem_dbh->do("CREATE EXTENSION \"uuid-ossp\"") if($cfgDB_dbtype eq 'POSTGRESQL'); }; +# create TABLE fhemversions ifnonexistent + $fhem_dbh->do("CREATE TABLE IF NOT EXISTS fhemversions(VERSION INT, VERSIONUUID CHAR(50))"); + # create TABLE fhemconfig if nonexistent $fhem_dbh->do("CREATE TABLE IF NOT EXISTS fhemconfig(COMMAND CHAR(32), DEVICE CHAR(32), P1 CHAR(50), P2 TEXT, VERSION INT, VERSIONUUID CHAR(50))"); # check TABLE fhemconfig already populated @@ -125,7 +126,7 @@ sub cfgDB_Init { # insert default entries to get fhem running my $uuid = cfgDB_Uuid; $fhem_dbh->do("INSERT INTO fhemversions values (0, '$uuid')"); - cfgDB_InsertLine($fhem_dbh, $uuid, '# added by cfgDB_Init'); + cfgDB_InsertLine($fhem_dbh, $uuid, '#created by cfgDB_Init'); cfgDB_InsertLine($fhem_dbh, $uuid, 'attr global logfile ./log/fhem-%Y-%m-%d.log'); cfgDB_InsertLine($fhem_dbh, $uuid, 'attr global modpath .'); cfgDB_InsertLine($fhem_dbh, $uuid, 'attr global userattr devStateIcon devStateStyle icon sortby webCmd'); @@ -133,17 +134,11 @@ sub cfgDB_Init { cfgDB_InsertLine($fhem_dbh, $uuid, 'define telnetPort telnet 7072 global'); cfgDB_InsertLine($fhem_dbh, $uuid, 'define WEB FHEMWEB 8083 global'); cfgDB_InsertLine($fhem_dbh, $uuid, 'define Logfile FileLog ./log/fhem-%Y-%m-%d.log fakelog'); -# } else { -# if entries found and any database changes necessary, they will be done now. -# eval { $fhem_dbh->do("ALTER TABLE fhemconfig ADD VERSIONUUID VARCHAR(50)"); }; } # create TABLE fhemstate if nonexistent $fhem_dbh->do("CREATE TABLE IF NOT EXISTS fhemstate(stateString TEXT)"); -# create TABLE fhemversions ifnonexistent - $fhem_dbh->do("CREATE TABLE IF NOT EXISTS fhemversions(VERSION INT, VERSIONUUID CHAR(50))"); - # close database connection $fhem_dbh->commit(); $fhem_dbh->disconnect(); @@ -176,7 +171,7 @@ sub cfgDB_Info { $r .= " fhemconfig: $count entries\n\n"; # read versions creation time # $sth = $fhem_dbh->prepare( "SELECT * FROM fhemconfig WHERE COMMAND ='#created' ORDER by VERSION" ); - $sth = $fhem_dbh->prepare( "SELECT * FROM fhemconfig as c join fhemversions as v on v.versionuuid=c.versionuuid WHERE COMMAND ='#created' ORDER by v.VERSION" ); + $sth = $fhem_dbh->prepare( "SELECT * FROM fhemconfig as c join fhemversions as v on v.versionuuid=c.versionuuid WHERE COMMAND like '#created%' ORDER by v.VERSION" ); $sth->execute(); while (@line = $sth->fetchrow_array()) { $row = " Ver $line[6] saved: $line[1] $line[2] $line[3] def: ". @@ -467,7 +462,8 @@ sub cfgDB_Migrate { Log3('configDB',4,'Processing: cfgDB_SaveState.'); cfgDB_SaveState; Log3('configDB',4,'Migration finished.'); - return 'Migration finished.'; + return " Result after migration:\n".cfgDB_Info; + } sub cfgDB_List($) { @@ -582,7 +578,7 @@ sub cfgDB_List($) {
{cfgDB_Migrate}
into frontend's command line{cfgDB_Migrate}
in die Befehlszeile der fhem-Oberfläche eingeben