2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-23 08:36:24 +00:00

93_DbLog.pm: is now version 2.8.8, no dropdown list in SVG-Plot in

asynchronous mode, minor fixes

git-svn-id: https://svn.fhem.de/fhem/trunk@13039 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
nasseeder1 2017-01-10 22:19:58 +00:00
parent b8ffededf5
commit 26ac184fc2
2 changed files with 43 additions and 14 deletions

View File

@ -1,5 +1,7 @@
# 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.
- bugfix: 93_DbLog.pm: is now version 2.8.8, no dropdown list in SVG in
asynchronous mode, minor fixes
- feature: 20_ROOMMATE,20_GUEST: introduce new attribute r*_presenceDevices - feature: 20_ROOMMATE,20_GUEST: introduce new attribute r*_presenceDevices
to allow easy status synchronisation with to allow easy status synchronisation with
other FHEM devices (e.g. PRESENCE module) other FHEM devices (e.g. PRESENCE module)

View File

@ -13,6 +13,8 @@
############################################################################################################################ ############################################################################################################################
# Versions History done by DS_Starter: # Versions History done by DS_Starter:
# #
# 2.8.8 10.01.2017 connection check in Get added, avoid warning "commit/rollback ineffective with AutoCommit enabled"
# 2.8.7 10.01.2017 bugfix no dropdown list in SVG if asynchronous mode activated (func DbLog_sampleDataFn)
# 2.8.6 09.01.2017 Workaround for Warning begin_work failed: Turning off AutoCommit failed, start new timer of # 2.8.6 09.01.2017 Workaround for Warning begin_work failed: Turning off AutoCommit failed, start new timer of
# DbLog_execmemcache after reducelog # DbLog_execmemcache after reducelog
# 2.8.5 08.01.2017 attr syncEvents, cacheEvents added to minimize events # 2.8.5 08.01.2017 attr syncEvents, cacheEvents added to minimize events
@ -53,7 +55,7 @@ use Data::Dumper;
use Blocking; use Blocking;
use Time::HiRes qw(gettimeofday tv_interval); use Time::HiRes qw(gettimeofday tv_interval);
my $DbLogVersion = "2.8.6"; my $DbLogVersion = "2.8.8";
my %columns = ("DEVICE" => 64, my %columns = ("DEVICE" => 64,
"TYPE" => 64, "TYPE" => 64,
@ -855,8 +857,11 @@ sub DbLog_Log($$) {
# synchoner Mode # synchoner Mode
my $error = DbLog_Push($hash, $vb4show, @row_array); my $error = DbLog_Push($hash, $vb4show, @row_array);
Log3 $name, 5, "DbLog $name -> DbLog_Push Returncode: $error" if($vb4show); Log3 $name, 5, "DbLog $name -> DbLog_Push Returncode: $error" if($vb4show);
readingsSingleUpdate($hash, "state", $error, 1) if($error); if($error) {
readingsSingleUpdate($hash, "state", "connected", 0) if(!$error); readingsSingleUpdate($hash, "state", $error, 1);
} else {
readingsSingleUpdate($hash, "state", "connected", 0);
}
} }
} }
return; return;
@ -1011,13 +1016,13 @@ sub DbLog_Push(@) {
if ($@) { if ($@) {
Log3 $hash->{NAME}, 2, "DbLog $name -> Error: $@"; Log3 $hash->{NAME}, 2, "DbLog $name -> Error: $@";
$dbh->rollback(); $dbh->rollback() if(!$dbh->{AutoCommit});
$error = $@; $error = $@;
$dbh->disconnect(); $dbh->disconnect();
DbLog_Connect($hash); DbLog_Connect($hash);
} }
else { else {
$dbh->commit(); $dbh->commit() if(!$dbh->{AutoCommit});
$dbh->{RaiseError} = 0; $dbh->{RaiseError} = 0;
$dbh->{PrintError} = 1; $dbh->{PrintError} = 1;
} }
@ -1055,7 +1060,7 @@ sub DbLog_execmemcache ($) {
# nur Verbindungstest, DbLog_PushAsyncDone hat eigene Verbindungsroutine # nur Verbindungstest, DbLog_PushAsyncDone hat eigene Verbindungsroutine
eval { eval {
$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoInactiveDestroy => 1 }); $dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1 });
}; };
if ($@) { if ($@) {
@ -1146,7 +1151,7 @@ sub DbLog_PushAsync(@) {
# Background-Startzeit # Background-Startzeit
my $bst = [gettimeofday]; my $bst = [gettimeofday];
eval {$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoInactiveDestroy => 1 });}; eval {$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1 });};
if ($@) { if ($@) {
$error = encode_base64($@,""); $error = encode_base64($@,"");
@ -1281,12 +1286,12 @@ sub DbLog_PushAsync(@) {
if ($@) { if ($@) {
Log3 $hash->{NAME}, 2, "DbLog $name -> Error: $@"; Log3 $hash->{NAME}, 2, "DbLog $name -> Error: $@";
$dbh->rollback(); $dbh->rollback() if(!$dbh->{AutoCommit});
$error = $@; $error = $@;
$dbh->disconnect(); $dbh->disconnect();
} }
else { else {
$dbh->commit(); $dbh->commit() if(!$dbh->{AutoCommit});
$dbh->disconnect(); $dbh->disconnect();
} }
# SQL-Laufzeit ermitteln # SQL-Laufzeit ermitteln
@ -1500,7 +1505,11 @@ sub DbLog_Connect($)
Log3 $hash->{NAME}, 4, 'Waiting for database connection'; Log3 $hash->{NAME}, 4, 'Waiting for database connection';
return 0; return 0;
} }
# if(!$dbhf) {
# Log3 $hash->{NAME}, 2, "Can't connect to $dbconn: $DBI::errstr";
# return 0;
# }
Log3 $hash->{NAME}, 3, "Connection to db $dbconn established"; Log3 $hash->{NAME}, 3, "Connection to db $dbconn established";
$hash->{DBHF}= $dbhf; $hash->{DBHF}= $dbhf;
@ -1564,7 +1573,13 @@ DbLog_Get($@)
{ {
my ($hash, @a) = @_; my ($hash, @a) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $dbh = $hash->{DBH};
if ( !$dbh || not $dbh->ping ) {
#### DB Session dead, try to reopen now !
DbLog_Connect($hash);
}
return dbReadings($hash,@a) if $a[1] =~ m/^Readings/; return dbReadings($hash,@a) if $a[1] =~ m/^Readings/;
return "Usage: get $a[0] <in> <out> <from> <to> <column_spec>...\n". return "Usage: get $a[0] <in> <out> <from> <to> <column_spec>...\n".
@ -1636,7 +1651,7 @@ DbLog_Get($@)
return "Can't connect to database." if(!DbLog_Connect($hash)); return "Can't connect to database." if(!DbLog_Connect($hash));
} }
my $dbh = $hash->{DBH}; $dbh = $hash->{DBH};
if ( !$dbh || not $dbh->ping ) { if ( !$dbh || not $dbh->ping ) {
Log3($name, 1, "DbLog $name: DBLog_Get - DB Session dead, try to reopen now !"); Log3($name, 1, "DbLog $name: DBLog_Get - DB Session dead, try to reopen now !");
@ -2603,6 +2618,16 @@ DbLog_sampleDataFn($$$$$)
my @example; my @example;
my @colregs; my @colregs;
my $counter; my $counter;
# Fix keine Vorschlagswerte aus Current im asynchronen Mode
my $hash = $defs{$dlName};
my $dbh = $defs{$dlName}{DBH};
eval {
if ( !$dbh || not $dbh->ping ) {
#### DB Session dead, try to reopen now !
DbLog_Connect($hash);
}
};
my $currentPresent = AttrVal($dlName,'DbLogType','Current'); my $currentPresent = AttrVal($dlName,'DbLogType','Current');
if($currentPresent =~ m/Current/) { if($currentPresent =~ m/Current/) {
@ -3002,7 +3027,8 @@ sub dbReadings($@) {
</code><br> </code><br>
This attribute determines which table or which tables in the database are wanted to use. If the attribute isn't set, This attribute determines which table or which tables in the database are wanted to use. If the attribute isn't set,
the table <i>history</i> will be used as default. <br> the table <i>history</i> will be used as default. NOTE: The current-table has to be used to get a Device:Reading-DropDown
list when a SVG-Plot will be created. <br>
</ul> </ul>
</ul> </ul>
<br> <br>
@ -3518,7 +3544,8 @@ sub dbReadings($@) {
</code><br> </code><br>
Dieses Attribut legt fest, welche Tabelle oder Tabellen in der Datenbank genutzt werden sollen. Ist dieses Attribut nicht gesetzt, wird Dieses Attribut legt fest, welche Tabelle oder Tabellen in der Datenbank genutzt werden sollen. Ist dieses Attribut nicht gesetzt, wird
per default die Tabelle <i>history</i> verwendet. <br> per default die Tabelle <i>history</i> verwendet. HINWEIS: Die Current-Tabelle muß genutzt werden um eine Device:Reading-DropDown
Liste bei der Erstellung eines SVG-Plots zu erhalten. <br>
</ul> </ul>
</ul> </ul>
<br> <br>