Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The variable value is completely flexible.  It can be a simple integer or a complex data structure.  This is accomplished by serializing the value before saving it to the database.  YAML will be used to serialize the data.  YAML is a human friendly data serialization standard for all programming languages (http://yaml.org/).&nbspImage Removed;   YAML modules are available for Perl, PHP, and many other languages.

Backend Interface

The variable table will be utilized by backend code via functions provided by the DataStructure.pm module:

  • get_variable($name)
  • set_variable($name, $value)

Database Table Structure

The variable table will have the following columns:

...

Code Block
CREATE TABLE IF NOT EXISTS `variable` (
  `id` smallint(5) unsigned NOT NULL auto_increment,
  `name` varchar(128) NOT NULL default '',
  `value` longtext NOT NULL,
  `setby` varchar(40) default NULL,
  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `name` (`name`)) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

Examples

Example 1:

A hash is created in Perl containing 2 keys with scalar values:

Code Block
my %kms_configuration = (
 'ECU' => '192.168.22.33:1688',
 'NCSU' => 'kms-server.ncsu.edu',
); my $serialized_data = YAML::Dump(\%kms_configuration);$self->data->set_variable('kms-configuration', $serialized_data);

This hash is serialized using the YAML module's Dump function, and then a row is saved in the variable table by the DataStructure.pm::set_variable() subroutine:

id

name

value

setby

timestamp

2

kms-configuration

---
ECU: 192.168.22.33:1688
NCSU: kms-server.ncsu.edu

new.pm:139

2009-05-26 11:35:36

Example 2:

A more elaborate data structure is created in Perl containing an array of hashes. One of the hash values (email) can be multivalued because the value is an anonymous array:

Code Block
my @contacts = (
 {
  'firstname' => 'Joe',
  'lastname' => 'Doe',
  'email' => ['joe@somewhere.org', 'jdoe22@unity.ncsu.edu'],
  'employee_id' => 3342
 },
 {
  'firstname' => 'Jane',
  'lastname' => 'Doe',
  'email' => ['jane@somewhere.org'],
  'employee_id' => 7865
 }
); my $serialized_data = YAML::Dump(\@contacts);$self->data->set_variable('contacts', $serialized_data);

YAML::Dump transforms this data structure into the value stored in the value column in the following row:

...