diff options
| author | Unknown | 2006-07-23 16:55:00 +0200 |
|---|---|---|
| committer | Unknown | 2006-07-23 16:55:00 +0200 |
| commit | b9f432b9dc47440135baf46933df9b4397999b01 (patch) | |
| tree | 65dec6829bdd18582159bb21f8481c21fb4fa9f1 /config-db/ODLX/MetaDB/SQLite.pm | |
| parent | - testing commit access (diff) | |
| download | core-b9f432b9dc47440135baf46933df9b4397999b01.tar.gz core-b9f432b9dc47440135baf46933df9b4397999b01.tar.xz core-b9f432b9dc47440135baf46933df9b4397999b01.zip | |
Check-in of basic configuration database design:
- MetaDB database abstraction should be pretty complete, there already
are special backends for CSV, SQLite and mysql, as well as a common
DBI-backend which should work with most DBMSs.
- the configDB DB-layer is more or less done, accessing and modification
of data is done as well as transparent schema upgrading between
different DB-schema versions. Systems and clients are cared for,
groups exist in the schema but aren't finished yet.
- simnple translation and logging services are provided and the
mechanism for automatic evaluation of cmdline arguments and
global/user-specific configuration files works.
- documentation has started but isn't complete yet (well, this is OSS
after all... >;o)
git-svn-id: http://svn.openslx.org/svn/openslx/ld4@284 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'config-db/ODLX/MetaDB/SQLite.pm')
| -rw-r--r-- | config-db/ODLX/MetaDB/SQLite.pm | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/config-db/ODLX/MetaDB/SQLite.pm b/config-db/ODLX/MetaDB/SQLite.pm new file mode 100644 index 00000000..c8aa30fe --- /dev/null +++ b/config-db/ODLX/MetaDB/SQLite.pm @@ -0,0 +1,96 @@ +package ODLX::MetaDB::SQLite; + +use vars qw(@ISA $VERSION); +@ISA = ('ODLX::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 'odlxdata-sqlite' directory. +################################################################################ +use strict; +use Carp; +use ODLX::Basics; +use ODLX::MetaDB::DBI $VERSION; + +my $superVersion = $ODLX::MetaDB::DBI::VERSION; +if ($superVersion < $VERSION) { + confess _tr('Unable to load module <%s> (Version <%s> required, but <%s> found)', + 'ODLX::MetaDB::DBI', $VERSION, $superVersion); +} + +################################################################################ +### implementation +################################################################################ +sub new +{ + my $class = shift; + my $self = {}; + return bless $self, $class; +} + +sub connectConfigDB +{ + my $self = shift; + + my $dbSpec = $odlxConfig{'db-spec'}; + if (!defined $dbSpec) { + # build $dbSpec from individual parameters: + my $dbBasepath = $odlxConfig{'db-basepath'}; + my $dbDatadir = $odlxConfig{'db-datadir'} || 'odlxdata-sqlite'; + my $dbPath = "$dbBasepath/$dbDatadir"; + mkdir $dbPath unless -e $dbPath; + my $dbName = $odlxConfig{'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 |
