summaryrefslogtreecommitdiffstats
path: root/config-db/OpenSLX/MetaDB/SQLite.pm
diff options
context:
space:
mode:
authorOliver Tappe2006-08-21 14:03:33 +0200
committerOliver Tappe2006-08-21 14:03:33 +0200
commit65556841d342d74059f7bc71e7496c64e3f23056 (patch)
treef375be4afcad2b83b1a7d2cce1e4db4f44b70192 /config-db/OpenSLX/MetaDB/SQLite.pm
parent* replaced all occurrences of 'opendiskless' with 'openslx' (diff)
downloadcore-65556841d342d74059f7bc71e7496c64e3f23056.tar.gz
core-65556841d342d74059f7bc71e7496c64e3f23056.tar.xz
core-65556841d342d74059f7bc71e7496c64e3f23056.zip
* now that project name is fixed, we use it: 'ODLX' => 'OpenSLX' and 'odlx' => 'openslx'
git-svn-id: http://svn.openslx.org/svn/openslx/trunk@321 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'config-db/OpenSLX/MetaDB/SQLite.pm')
-rw-r--r--config-db/OpenSLX/MetaDB/SQLite.pm96
1 files changed, 96 insertions, 0 deletions
diff --git a/config-db/OpenSLX/MetaDB/SQLite.pm b/config-db/OpenSLX/MetaDB/SQLite.pm
new file mode 100644
index 00000000..f40c618f
--- /dev/null
+++ b/config-db/OpenSLX/MetaDB/SQLite.pm
@@ -0,0 +1,96 @@
+package OpenSLX::MetaDB::SQLite;
+
+use vars qw(@ISA $VERSION);
+@ISA = ('OpenSLX::MetaDB::DBI');
+$VERSION = 1.01; # API-version . implementation-version
+
+################################################################################
+### This class provides a MetaDB backend for SQLite databases.
+### - by default the db will be created inside a 'openslxdata-sqlite' directory.
+################################################################################
+use strict;
+use Carp;
+use OpenSLX::Basics;
+use OpenSLX::MetaDB::DBI $VERSION;
+
+my $superVersion = $OpenSLX::MetaDB::DBI::VERSION;
+if ($superVersion < $VERSION) {
+ confess _tr('Unable to load module <%s> (Version <%s> required, but <%s> found)',
+ 'OpenSLX::MetaDB::DBI', $VERSION, $superVersion);
+}
+
+################################################################################
+### implementation
+################################################################################
+sub new
+{
+ my $class = shift;
+ my $self = {};
+ return bless $self, $class;
+}
+
+sub connectConfigDB
+{
+ my $self = shift;
+
+ my $dbSpec = $openslxConfig{'db-spec'};
+ if (!defined $dbSpec) {
+ # build $dbSpec from individual parameters:
+ my $dbBasepath = $openslxConfig{'db-basepath'};
+ my $dbDatadir = $openslxConfig{'db-datadir'} || 'openslxdata-sqlite';
+ my $dbPath = "$dbBasepath/$dbDatadir";
+ mkdir $dbPath unless -e $dbPath;
+ my $dbName = $openslxConfig{'db-name'};
+ $dbSpec = "dbname=$dbPath/$dbName";
+ }
+ vlog 1, "trying to connect to SQLite-database <$dbSpec>";
+ $self->{'dbh'} = DBI->connect("dbi:SQLite:$dbSpec", undef, undef,
+ {PrintError => 0})
+ or confess _tr("Cannot connect to database <%s> (%s)"),
+ $dbSpec, $DBI::errstr;
+}
+
+sub schemaRenameTable
+{
+ my $self = shift;
+ my $oldTable = shift;
+ my $newTable = shift;
+ my $colDescrs = shift;
+ my $isSubCmd = shift;
+
+ my $dbh = $self->{'dbh'};
+ 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);
+}
+
+sub schemaAddColumns
+{
+ my $self = shift;
+ my $table = shift;
+ my $newColDescrs = shift;
+ my $newColDefaultVals = shift;
+ my $colDescrs = shift;
+ my $isSubCmd = shift;
+
+ my $dbh = $self->{'dbh'};
+ my $newColNames = $self->_convertColDescrsToColNamesString($newColDescrs);
+ vlog 1, "adding columns <$newColNames> to table <$table>" unless $isSubCmd;
+ foreach my $colDescr (@$newColDescrs) {
+ 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);
+ }
+ # if default values have been provided, we apply them now:
+ if (defined $newColDefaultVals) {
+ $self->_doUpdate($table, undef, $newColDefaultVals);
+ }
+}
+
+1; \ No newline at end of file