From 96d4724c79570edd477612e3edef1d2e09f3a7ac Mon Sep 17 00:00:00 2001
From: nasseeder1 <>
Date: Fri, 14 Oct 2016 13:56:17 +0000
Subject: [PATCH] 93_DbRep: allow SQL-Wildcards (% _) in attr reading & attr
device
git-svn-id: https://svn.fhem.de/fhem/trunk@12337 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/FHEM/93_DbRep.pm | 46 ++++++++++++++++++++++++++++++++++++++-----
1 file changed, 41 insertions(+), 5 deletions(-)
diff --git a/fhem/FHEM/93_DbRep.pm b/fhem/FHEM/93_DbRep.pm
index 5bf7a4cb7..a3fd78c1d 100644
--- a/fhem/FHEM/93_DbRep.pm
+++ b/fhem/FHEM/93_DbRep.pm
@@ -37,6 +37,7 @@
###########################################################################################################
# Versions History:
#
+# 4.5 14.10.2016 get dbstatus, dbvars, tableinfo
# 4.4 13.10.2016 get function prepared
# 4.3 11.10.2016 Preparation of get metadata
# 4.2 10.10.2016 allow SQL-Wildcards (% _) in attr reading & attr device
@@ -1037,7 +1038,9 @@ sub averval_ParseDone($) {
my $name = $hash->{NAME};
my $arrstr = decode_base64($a[1]);
my $device = $a[2];
+ $device =~ s/%/\//g;
my $reading = $a[3];
+ $reading =~ s/%/\//g;
my $bt = $a[4];
my ($rt,$brt) = split(",", $bt);
my $err = $a[5]?decode_base64($a[5]):undef;
@@ -1200,7 +1203,9 @@ sub count_ParseDone($) {
my $name = $hash->{NAME};
my $arrstr = decode_base64($a[1]);
my $device = $a[2];
+ $device =~ s/%/\//g;
my $reading = $a[3];
+ $reading =~ s/%/\//g;
my $bt = $a[4];
my ($rt,$brt) = split(",", $bt);
my $err = $a[5]?decode_base64($a[5]):undef;
@@ -1429,7 +1434,9 @@ sub maxval_ParseDone($) {
my $name = $hash->{NAME};
my $rowlist = decode_base64($a[1]);
my $device = $a[2];
+ $device =~ s/%/\//g;
my $reading = $a[3];
+ $reading =~ s/%/\//g;
my $bt = $a[4];
my ($rt,$brt) = split(",", $bt);
my $err = $a[5]?decode_base64($a[5]):undef;
@@ -1660,7 +1667,9 @@ sub minval_ParseDone($) {
my $name = $hash->{NAME};
my $rowlist = decode_base64($a[1]);
my $device = $a[2];
+ $device =~ s/%/\//g;
my $reading = $a[3];
+ $reading =~ s/%/\//g;
my $bt = $a[4];
my ($rt,$brt) = split(",", $bt);
my $err = $a[5]?decode_base64($a[5]):undef;
@@ -1906,7 +1915,9 @@ sub diffval_ParseDone($) {
my $name = $hash->{NAME};
my $rowlist = decode_base64($a[1]);
my $device = $a[2];
+ $device =~ s/%/\//g;
my $reading = $a[3];
+ $reading =~ s/%/\//g;
my $bt = $a[4];
my ($rt,$brt) = split(",", $bt);
my $err = $a[5]?decode_base64($a[5]):undef;
@@ -2072,7 +2083,9 @@ sub sumval_ParseDone($) {
my $name = $hash->{NAME};
my $arrstr = decode_base64($a[1]);
my $device = $a[2];
+ $device =~ s/%/\//g;
my $reading = $a[3];
+ $reading =~ s/%/\//g;
my $bt = $a[4];
my ($rt,$brt) = split(",", $bt);
my $err = $a[5]?decode_base64($a[5]):undef;
@@ -3032,7 +3045,16 @@ sub dbmeta_DoParse($) {
} elsif ($opt eq "dbstatus") {
$sql = "show global status like '$ple';";
} elsif ($opt eq "tableinfo") {
- $sql = "select table_schema,round(sum(data_length+index_length)/1024/1024,4) from information_schema.tables group by table_schema;";
+ $sql = "select
+ table_schema,
+ round(sum(data_length+index_length)/1024/1024,2),
+ round(data_free/1024/1024,2),
+ row_format,
+ table_collation,
+ engine,
+ table_type,
+ create_time,
+ from information_schema.tables group by table_schema;";
}
Log3($name, 4, "DbRep $name - SQL execute: $sql");
@@ -3048,8 +3070,21 @@ sub dbmeta_DoParse($) {
return "$name|''|''|''|$err";
} else {
while (my @line = $sth->fetchrow_array()) {
- Log3 ($name, 5, "DbRep $name - SQL result: $line[0] : $line[1]");
- push(@row_array, $line[0]." ".$line[1]);
+ Log3 ($name, 5, "DbRep $name - SQL result: @line");
+ my $rowlist = join("§", @line);
+ $rowlist =~ s/ /_/g;
+ @line = split("§", $rowlist);
+ if ($opt eq "tableinfo") {
+ push(@row_array, $line[0]."___data_index_lenth_MB ".$line[1]);
+ push(@row_array, $line[0]."___data_free_MB ".$line[2]);
+ push(@row_array, $line[0]."___row_format ".$line[3]);
+ push(@row_array, $line[0]."___table_collation ".$line[4]);
+ push(@row_array, $line[0]."___engine ".$line[5]);
+ push(@row_array, $line[0]."___table_type ".$line[6]);
+ push(@row_array, $line[0]."___create_time ".$line[7]);
+ } else {
+ push(@row_array, $line[0]." ".$line[1]);
+ }
}
}
}
@@ -3117,7 +3152,6 @@ sub dbmeta_ParseDone($) {
foreach my $row (@row_array) {
my @a = split(" ", $row);
my $k = $a[0];
- $k = $a[0]."_MB" if($opt eq "tableinfo");
my $v = $a[1];
readingsBulkUpdate($hash, $pre.$k, $v);
}
@@ -3571,6 +3605,7 @@ return;
The function "insert" doesn't allow setting the mentioned attributes containing the wildcard "%", the character "_" will evaluated as a normal character.
The deletion function "delEntries" evaluates both characters "$", "_" NOT as wildcards and delete device/readings only if they are entered in the
attribute as exactly as they are stored in the database .
+ In readings the wildcard character "%" will be replaced by "/" to meet the rules of allowed characters in readings.