...
This page describes the variable table in the database. The purpose of this table is to allow pieces of data to be stored without easily stored in the database without having to manipulate the database schema. The need for such a table has grown over time as more and more features are added to VCL. This table will become very useful as VCL becomes more and more increasingly modularized. Any This table will allow any VCL component will be able to easily set and retrieve the data they require to access the variable data without having to interact directly with the database.
...
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 is used to serialize the data. YAML is a human friendly data serialization standard for all programming languages (http://yaml.org/). YAML modules are available for Perl, PHP, and many other languages:
Because the data is serialized into a highly compatible format, the backend and frontend can utilize common variables. It will be easy for the frontend to provide a means to configure variables by capturing the data entered into a web page, constructing a data structure, serializing it via a PHP YAML module, and then saving the data structure in the variable table. The backend can then access the identical data structure using a Perl YAML module to deserialize the data.
The variable table is utilized by backend code via functions provided by the DataStructure.pm module:
The variable table will have has the following columns:
| id | name | value | setby | timestamp | type |
---|---|---|---|---|---|---|
smallint(5) | varchar(128) | longtext | varchar(40) | timestamp |
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 ; |
The following 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'", ); $self->data->set_variable("kms-configuration", \%kms_configuration); |
The keys 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 , and then a row which transforms the hash into:
Code Block |
---|
---
ECU: 192.168.22.33:1688
NCSU: 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 | --- | 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};
|
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 } ); $self->data->set_variable("contacts", \@contacts); |
DataStructure.pm::set_variable() uses YAML::Dump transforms to transform this data structure into the value stored in the value column in the following row:
Code Block |
---|
---
- 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
|
The following row is then added to the variable table:
id | name | value | setby | timestamp |
---|---|---|---|---|
3 | contacts | --- | 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";
}
|