diff options
author | Oliver Tappe | 2008-01-03 16:20:44 +0100 |
---|---|---|
committer | Oliver Tappe | 2008-01-03 16:20:44 +0100 |
commit | a6b29cc972d8775398b4ae03d69123af3034a4ee (patch) | |
tree | 152fb2762f2c0b07ae633515a1eda74677d8cda0 /config-db/OpenSLX/MetaDB | |
parent | * Fixed problem with invocation of debootstrap that caused it to fail (diff) | |
download | core-a6b29cc972d8775398b4ae03d69123af3034a4ee.tar.gz core-a6b29cc972d8775398b4ae03d69123af3034a4ee.tar.xz core-a6b29cc972d8775398b4ae03d69123af3034a4ee.zip |
* intermediate checkin of refactoring of the way attributes are stored in DB
and passed in and out via the DB-layer
N.B.: this may break things, will be fixed later today
git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1440 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'config-db/OpenSLX/MetaDB')
-rw-r--r-- | config-db/OpenSLX/MetaDB/Base.pm | 12 | ||||
-rw-r--r-- | config-db/OpenSLX/MetaDB/DBI.pm | 125 |
2 files changed, 99 insertions, 38 deletions
diff --git a/config-db/OpenSLX/MetaDB/Base.pm b/config-db/OpenSLX/MetaDB/Base.pm index 7c4a8f3b..13ebe171 100644 --- a/config-db/OpenSLX/MetaDB/Base.pm +++ b/config-db/OpenSLX/MetaDB/Base.pm @@ -218,11 +218,19 @@ sub schemaFetchDBVersion { } -sub schemaConvertTypeDescrToNative +sub schemaSetDBVersion +{ +} + +sub schemaCreate { } -sub schemaDeclareTable +sub schemaUpgradeToCurrent +{ +} + +sub schemaConvertTypeDescrToNative { } diff --git a/config-db/OpenSLX/MetaDB/DBI.pm b/config-db/OpenSLX/MetaDB/DBI.pm index a1b782c1..dbc1faa8 100644 --- a/config-db/OpenSLX/MetaDB/DBI.pm +++ b/config-db/OpenSLX/MetaDB/DBI.pm @@ -221,6 +221,18 @@ sub fetchSystemByID return $self->_doSelect($sql); } +sub fetchSystemAttrs +{ + my $self = shift; + my $systemID = $self->{dbh}->quote(shift); + + my $sql = <<" End-of-Here"; + SELECT id, name, value FROM system_attr + WHERE system_id = $systemID + End-of-Here + return $self->_doSelect($sql); +} + sub fetchSystemIDsOfExport { my $self = shift; @@ -626,6 +638,36 @@ sub changeSystem return $self->_doUpdate('system', $systemIDs, $valRows); } +sub setSystemAttr +{ + my $self = shift; + my $systemID = shift; + my $attrName = shift; + my $attrValue = shift; + + my $quotedSystemID = $self->{dbh}->quote($systemID); + my $quotedAttrName = $self->{dbh}->quote($attrName); + + my $sql = <<" End-of-Here"; + SELECT id FROM system_attr + WHERE system_id = $quotedSystemID + AND name = $quotedAttrName + End-of-Here + my $id = $self->_doSelect($sql, 'id'); + if ($id) { + return $self->_doUpdate( + 'system_attr', [ $id ], [ { value => $attrValue } ] + ); + } + return $self->_doInsert( + 'system_attr', [ { + system_id => $systemID, + name => $attrName, + value => $attrValue, + } ] + ); +} + sub setClientIDsOfSystem { my $self = shift; @@ -800,7 +842,7 @@ sub schemaFetchDBVersion { my $self = shift; - my $dbh = $self->{'dbh'}; + my $dbh = $self->{dbh}; local $dbh->{RaiseError} = 1; my $row = eval { $dbh->selectrow_hashref('SELECT schema_version FROM meta'); }; @@ -811,6 +853,17 @@ sub schemaFetchDBVersion return $row->{schema_version}; } +sub schemaSetDBVersion +{ + my $self = shift; + my $dbVersion = shift; + + $self->{dbh}->do("UPDATE meta SET schema_version = '$dbVersion'") + or croak _tr('Unable to set DB-schema version to %s!', $dbVersion); + + return 1; +} + sub schemaConvertTypeDescrToNative { # a default implementation, many DBs need to override... my $self = shift; @@ -870,14 +923,14 @@ sub schemaDropTable } sub schemaRenameTable -{ # a rather simple-minded implementation that renames a table in several - # steps: - # - create the new table - # - copy the data over from the old one - # - drop the old table - # This should be overriden for advanced DBs, as these more often than not - # implement the 'ALTER TABLE <old> RENAME TO <new>' SQL-command (which - # is much more efficient). +{ # a rather simple-minded implementation that renames a table in several + # steps: + # - create the new table + # - copy the data over from the old one + # - drop the old table + # This should be overriden for advanced DBs, as these more often than not + # implement the 'ALTER TABLE <old> RENAME TO <new>' SQL-command (which + # is much more efficient). my $self = shift; my $oldTable = shift; my $newTable = shift; @@ -902,15 +955,15 @@ sub schemaRenameTable } sub schemaAddColumns -{ # a rather simple-minded implementation that adds columns to a table - # in several steps: - # - create a temp table with the new layout - # - copy the data from the old table into the new one - # - drop the old table - # - rename the temp table to the original name - # This should be overriden for advanced DBs, as these more often than not - # implement the 'ALTER TABLE <old> RENAME TO <new>' SQL-command (which - # is much more efficient). +{ # a rather simple-minded implementation that adds columns to a table + # in several steps: + # - create a temp table with the new layout + # - copy the data from the old table into the new one + # - drop the old table + # - rename the temp table to the original name + # This should be overriden for advanced DBs, as these more often than not + # implement the 'ALTER TABLE <table> ADD COLUMN <col>' SQL-command (which + # is much more efficient). my $self = shift; my $table = shift; my $newColDescrs = shift; @@ -944,15 +997,15 @@ sub schemaAddColumns } sub schemaDropColumns -{ # a rather simple-minded implementation that drops columns from a table - # in several steps: - # - create a temp table with the new layout - # - copy the data from the old table into the new one - # - drop the old table - # - rename the temp table to the original name - # This should be overriden for advanced DBs, as these sometimes - # implement the 'ALTER TABLE <old> DROP COLUMN <col>' SQL-command (which - # is much more efficient). +{ # a rather simple-minded implementation that drops columns from a table + # in several steps: + # - create a temp table with the new layout + # - copy the data from the old table into the new one + # - drop the old table + # - rename the temp table to the original name + # This should be overriden for advanced DBs, as these sometimes + # implement the 'ALTER TABLE <table> DROP COLUMN <col>' SQL-command (which + # is much more efficient). my $self = shift; my $table = shift; my $dropColNames = shift; @@ -977,15 +1030,15 @@ sub schemaDropColumns } sub schemaChangeColumns -{ # a rather simple-minded implementation that changes columns - # in several steps: - # - create a temp table with the new layout - # - copy the data from the old table into the new one - # - drop the old table - # - rename the temp table to the original name - # This should be overriden for advanced DBs, as these sometimes - # implement the 'ALTER TABLE <old> CHANGE COLUMN <col>' SQL-command (which - # is much more efficient). +{ # a rather simple-minded implementation that changes columns + # in several steps: + # - create a temp table with the new layout + # - copy the data from the old table into the new one + # - drop the old table + # - rename the temp table to the original name + # This should be overriden for advanced DBs, as these sometimes + # implement the 'ALTER TABLE <table> CHANGE COLUMN <col>' SQL-command (which + # is much more efficient). my $self = shift; my $table = shift; my $colChanges = shift; |