Name

VariableDatabase — specify database containing variables

SYNOPSIS

database_name

DESCRIPTION

The directive specifies name of a database containing a field Variable which will be used to return Interchange variable values.

In other words, instead of keeping a long list of Variable NAME value definitions in interchange.cfg or catalog.cfg, you can simply create a database with the name and value pairs.

DIRECTIVE TYPE AND DEFAULT VALUE

Catalog directive

EXAMPLES

Example: Enabling VariableDatabase

Save the following as products/variables.txt:

code	Variable
HELLO	Hi
ANON	Guest

Put the following lines in catalog.cfg:

Database  variables variables.txt TAB
VariableDatabase variables

Create a test page:

[tmp user][either][data session username][or]__ANON__[/either][/tmp]

__HELLO__, [scratch user]!

NOTES

If no Database entry corresponding to VariableDatabase definition is found, a default of TAB-separated .txt file is assumed. In other words:

VariableDatabase variables

is the same as:

Database variables variables.txt TAB
VariableDatabase variables

But if you want to use a non-default database, you must explicitly define it using the Database directive and do so before the VariableDatabase line.

AVAILABILITY

VariableDatabase is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: lib/Vend/Config.pm
Line 618

['VariableDatabase',  'dbconfig',        ''],

Source: lib/Vend/Config.pm
Line 4769 (context shows lines 4769-4815)

sub parse_dbconfig {
my ($var, $value) = @_;

my ($file, $type);
return '' if ! $value;
local($Vend::Cfg) = $C;

my ($db, $table);
eval {
  ($db, $table) = get_configdb($var, $value);
};

return '' if ! $db;

my ($k, @f);  # key and fields
my @l;      # refs to locale repository
my @n;      # names of locales
my @h;      # names of locales

@n = $db->columns();
shift @n;
my $extra;
for(@n) {
  my $real = $CDname{lc $_};
  if (! ref $Vend::Cfg->{$real} or $Vend::Cfg->{$real} !~ /HASH/) {
    # ignore non-existent directive, but put in hash
    my $ref = {};
    push @l, $ref;
    push @h, [$real, $ref];
    next;
  }
  push @l, $Vend::Cfg->{$real};
}
my $i;
while( ($k, undef, @f ) = $db->each_record) {
#::logDebug("Got key=$k f=@f");
  for ($i = 0; $i < @f; $i++) {
    next unless length($f[$i]);
    $l[$i]->{$k} = $f[$i];
  }
}
for(@h) {
  $Vend::Cfg->{Hash}{$_->[0]} = $_->[1];
}
$db->close_table();
return $table;
}

AUTHORS

Interchange Development Group

SEE ALSO

dynamic_variables(7ic), dynamic_variables_file_only(7ic), Variable(7ic), DirConfig(7ic)

DocBook! Interchange!