mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-12 22:56:34 +00:00
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:
parent
f6cf456abd
commit
48126c06ae
@ -179,6 +179,7 @@ sub _cfgDB_Reorg(;$$);
|
||||
sub _cfgDB_Rotate($$);
|
||||
sub _cfgDB_Search($$;$);
|
||||
sub _cfgDB_Uuid();
|
||||
sub _cfgDB_table_exists($$);
|
||||
|
||||
##################################################
|
||||
# Read configuration file for DB connection
|
||||
@ -299,13 +300,13 @@ sub cfgDB_Init() {
|
||||
}
|
||||
|
||||
### migrate fhembinfilesave to fhemb64filesave
|
||||
# check: fhembinfilesave exists?
|
||||
my $sth_test = $fhem_dbh->table_info(undef, 'public', "fhembinfilesave", 'TABLE');
|
||||
$sth_test->execute;
|
||||
my @info = $sth_test->fetchrow_array;
|
||||
my $exists = scalar @info;
|
||||
if ($exists) {
|
||||
$sth_test->finish();
|
||||
# # check: fhembinfilesave exists?
|
||||
# my $sth_test = $fhem_dbh->table_info(undef, 'public', "fhembinfilesave", 'TABLE');
|
||||
# $sth_test->execute;
|
||||
# my @info = $sth_test->fetchrow_array;
|
||||
# my $exists = scalar @info;
|
||||
if (_cfgDB_table_exists($fhem_dbh,'fhembinfilesave')) {
|
||||
# $sth_test->finish();
|
||||
# check: any files for migratione?
|
||||
$count = undef;
|
||||
$count = $fhem_dbh->selectrow_array('SELECT count(*) FROM fhembinfilesave');
|
||||
@ -343,6 +344,30 @@ sub cfgDB_Init() {
|
||||
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
|
||||
sub cfgDB_AttrRead($) {
|
||||
my ($readSpec) = @_;
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user