diff options
Diffstat (limited to 'config-db/OpenSLX/MetaDB/SQLite.pm')
-rw-r--r-- | config-db/OpenSLX/MetaDB/SQLite.pm | 64 |
1 files changed, 34 insertions, 30 deletions
diff --git a/config-db/OpenSLX/MetaDB/SQLite.pm b/config-db/OpenSLX/MetaDB/SQLite.pm index d073f305..65e1668c 100644 --- a/config-db/OpenSLX/MetaDB/SQLite.pm +++ b/config-db/OpenSLX/MetaDB/SQLite.pm @@ -15,7 +15,7 @@ package OpenSLX::MetaDB::SQLite; use strict; use vars qw($VERSION); -$VERSION = 1.01; # API-version . implementation-version +$VERSION = 1.01; # API-version . implementation-version use base qw(OpenSLX::MetaDB::DBI); ################################################################################ @@ -34,7 +34,7 @@ use OpenSLX::MetaDB::DBI 1; sub new { my $class = shift; - my $self = {}; + my $self = {}; return bless $self, $class; } @@ -46,57 +46,61 @@ sub connect if (!defined $dbSpec) { # build $dbSpec from individual parameters: my $dbBasepath = "$openslxConfig{'private-path'}/db"; - my $dbDatadir = 'sqlite'; - my $dbPath = "$dbBasepath/$dbDatadir"; - system("mkdir -p $dbPath") unless -e $dbPath; + my $dbDatadir = 'sqlite'; + my $dbPath = "$dbBasepath/$dbDatadir"; + system("mkdir -p $dbPath") unless -e $dbPath; $dbSpec = "dbname=$dbPath/$openslxConfig{'db-name'}"; } vlog(1, "trying to connect to SQLite-database <$dbSpec>"); - eval ('require DBD::SQLite; 1;') - or die _tr(qq[%s doesn't seem to be installed, -so there is no support for %s available, sorry!\n%s], 'DBD::SQLite', 'SQLite', $@); - $self->{'dbh'} = DBI->connect("dbi:SQLite:$dbSpec", undef, undef, - {PrintError => 0, AutoCommit => 1}) - or die _tr("Cannot connect to database <%s> (%s)", - $dbSpec, $DBI::errstr); + eval('require DBD::SQLite; 1;') + or die _tr( + qq[%s doesn't seem to be installed, +so there is no support for %s available, sorry!\n%s], 'DBD::SQLite', 'SQLite', + $@ + ); + $self->{'dbh'} = + DBI->connect("dbi:SQLite:$dbSpec", undef, undef, + {PrintError => 0, AutoCommit => 1}) + or die _tr("Cannot connect to database <%s> (%s)", $dbSpec, $DBI::errstr); } sub schemaRenameTable { - my $self = shift; - my $oldTable = shift; - my $newTable = shift; + my $self = shift; + my $oldTable = shift; + my $newTable = shift; my $colDescrs = shift; - my $isSubCmd = shift; + my $isSubCmd = shift; my $dbh = $self->{'dbh'}; - vlog(1, "renaming table <$oldTable> to <$newTable>..." unless $isSubCmd); + vlog(1, "renaming table <$oldTable> to <$newTable>...") unless $isSubCmd; my $sql = "ALTER TABLE $oldTable RENAME TO $newTable"; vlog(3, $sql); $dbh->do($sql) - or confess _tr(q[Can't rename table <%s> (%s)], $oldTable, $dbh->errstr); + or confess _tr(q[Can't rename table <%s> (%s)], $oldTable, $dbh->errstr); } sub schemaAddColumns { - my $self = shift; - my $table = shift; - my $newColDescrs = shift; + my $self = shift; + my $table = shift; + my $newColDescrs = shift; my $newColDefaultVals = shift; - my $colDescrs = shift; - my $isSubCmd = shift; + my $colDescrs = shift; + my $isSubCmd = shift; - my $dbh = $self->{'dbh'}; + my $dbh = $self->{'dbh'}; my $newColNames = $self->_convertColDescrsToColNamesString($newColDescrs); - vlog(1, "adding columns <$newColNames> to table <$table>" unless $isSubCmd); + vlog(1, "adding columns <$newColNames> to table <$table>") + unless $isSubCmd; foreach my $colDescr (@$newColDescrs) { - my $colDescrString - = $self->_convertColDescrsToDBNativeString([$colDescr]); + my $colDescrString = + $self->_convertColDescrsToDBNativeString([$colDescr]); my $sql = "ALTER TABLE $table ADD COLUMN $colDescrString"; vlog(3, $sql); $dbh->do($sql) - or confess _tr(q[Can't add column to table <%s> (%s)], $table, - $dbh->errstr); + or confess _tr(q[Can't add column to table <%s> (%s)], $table, + $dbh->errstr); } # if default values have been provided, we apply them now: if (defined $newColDefaultVals) { @@ -104,4 +108,4 @@ sub schemaAddColumns } } -1;
\ No newline at end of file +1; |