Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

SQL table definition

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(40128) default NULL,
  `timestamp` timestampdatetime NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB InnoDB DEFAULT CHARSET=utf8latin1 AUTO_INCREMENT=1 ;

Examples

...

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

The keys represent affiliation IDs and the correspond to the affiliation.name column in the database.  The values represent the addresses (phony) of Windows Vista/2008 KMS activation servers.

This hash is serialized by DataStructure.pm::set_variable() using the YAML module's Dump function which transforms the hash into:

Code Block
---
3ECU: 192.168.22.33:1688
1NCSU: kms-server.ncsu.edu

The following row is saved in the variable table by the DataStructure.pm::set_variable() subroutine:

id

name

value

setby

timestamp

2

kms-configuration

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

new.pm:139

2009-05-26 11:35:36

To retrieve the data:

Code Block

my $kms_configuration = $self->data->get_variable("kms-configuration");
my $kms_address = $kms_configuration->{$affiliation_id};

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\@contacts);

DataStructure.pm::set_variable() uses YAML::Dump transforms to transform this data structure into:

...

id

name

value

setby

timestamp

3

contacts

---
- email:
    - joe@somewhere.org
    - jdoe22@unity.ncsu.edu
  employee_id: 3342
  firstname: Joe
  lastname: Doe
- email:
    - jane@somewhere.org
  employee_id: 7865
  firstname: Jane
  lastname: Doe

DataStructure.pm:554

2009-05-26 12:35:36

To retrieve the data:

Code Block

my @returned_contacts = @{$self->data->get_variable('contacts')};
for my $contact (@returned_contacts) {
   print "Name: $contact->{firstname} $contact->{lastname}\n";
   for my $email_address (@{$contact->{email}}) {
      print "Email: $email_address\n";
   }
   print "---\n";
}