2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2024-11-22 09:49:50 +00:00

configDB - added: cfgDB_Diff

git-svn-id: https://svn.fhem.de/fhem/trunk@5146 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
betateilchen 2014-03-06 13:46:01 +00:00
parent 5c4ed3e9b3
commit a675c4ce9c

View File

@ -494,6 +494,34 @@ sub cfgDB_List(;$$) {
return $ret;
}
sub cfgDB_Diff($$){
my ($search,$searchversion) = @_;
eval {use Text::Diff};
return "error: Please install Text::Diff!" if($@);
my ($sql, $sth, @line, $row, @result, $ret, $v0, $v1);
my $fhem_dbh = cfgDB_Connect;
$sql = "SELECT command, device, p1, p2 FROM fhemconfig as c join fhemversions as v ON v.versionuuid=c.versionuuid ".
"WHERE v.version = 0 AND device = '$search' ORDER BY command DESC";
$sth = $fhem_dbh->prepare( $sql);
$sth->execute();
while (@line = $sth->fetchrow_array()) {
$v0 .= "$line[0] $line[1] $line[2] $line[3]\n";
}
$sql = "SELECT command, device, p1, p2 FROM fhemconfig as c join fhemversions as v ON v.versionuuid=c.versionuuid ".
"WHERE v.version = '$searchversion' AND device = '$search' ORDER BY command DESC";
$sth = $fhem_dbh->prepare( $sql);
$sth->execute();
while (@line = $sth->fetchrow_array()) {
$v1 .= "$line[0] $line[1] $line[2] $line[3]\n";
}
$fhem_dbh->disconnect();
$ret = "compare device: $search in current version (left) to version: $searchversion (right)\n";
$ret .= diff \$v0, \$v1, { STYLE => "Table" }; #, \%options;
return $ret;
}
1;