configDB: improve table check for migration

git-svn-id: https://svn.fhem.de/fhem/trunk@15012 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
betateilchen
2017-09-05 17:35:14 +00:00
parent 9f756cdb50
commit 3c5e593cc0
2 changed files with 32 additions and 1269 deletions

View File

@@ -179,6 +179,7 @@ sub _cfgDB_Reorg(;$$);
sub _cfgDB_Rotate($$); sub _cfgDB_Rotate($$);
sub _cfgDB_Search($$;$); sub _cfgDB_Search($$;$);
sub _cfgDB_Uuid(); sub _cfgDB_Uuid();
sub _cfgDB_table_exists($$);
################################################## ##################################################
# Read configuration file for DB connection # Read configuration file for DB connection
@@ -299,13 +300,13 @@ sub cfgDB_Init() {
} }
### migrate fhembinfilesave to fhemb64filesave ### migrate fhembinfilesave to fhemb64filesave
# check: fhembinfilesave exists? # # check: fhembinfilesave exists?
my $sth_test = $fhem_dbh->table_info(undef, 'public', "fhembinfilesave", 'TABLE'); # my $sth_test = $fhem_dbh->table_info(undef, 'public', "fhembinfilesave", 'TABLE');
$sth_test->execute; # $sth_test->execute;
my @info = $sth_test->fetchrow_array; # my @info = $sth_test->fetchrow_array;
my $exists = scalar @info; # my $exists = scalar @info;
if ($exists) { if (_cfgDB_table_exists($fhem_dbh,'fhembinfilesave')) {
$sth_test->finish(); # $sth_test->finish();
# check: any files for migratione? # check: any files for migratione?
$count = undef; $count = undef;
$count = $fhem_dbh->selectrow_array('SELECT count(*) FROM fhembinfilesave'); $count = $fhem_dbh->selectrow_array('SELECT count(*) FROM fhembinfilesave');
@@ -343,6 +344,30 @@ sub cfgDB_Init() {
return; return;
} }
sub _cfgDB_table_exists($$) {
my ($dbh,$table) = @_;
printf "looking for table: $table \n";
my @tables = $dbh->tables('','','','TABLE');
if (@tables) {
printf "testing: #1\n";
for (@tables) {
next unless $_;
printf "found: $_"."\n";
return 1 if $_ =~ $table;
}
} else {
printf "testing: #2\n";
eval {
local $dbh->{PrintError} = 0;
local $dbh->{RaiseError} = 1;
$dbh->do(qq{SELECT * FROM $table WHERE 1 = 0 });
};
return 1 unless $@;
}
printf "table not found\n";
return 0;
}
# read attributes # read attributes
sub cfgDB_AttrRead($) { sub cfgDB_AttrRead($) {
my ($readSpec) = @_; my ($readSpec) = @_;

File diff suppressed because it is too large Load Diff