[ic] Database connection in AddDirective sub
Stefan Hornburg (Racke)
racke at linuxia.de
Fri Oct 16 13:08:45 UTC 2009
Mathew Jones wrote:
> Hi Everyone,
>
> I am using AddDirective and would like to pull some data from a DB
> table and store it in $Config. I am having trouble with connecting to
> the database. Using the example code below, the connection always fails,
> even though the table exists.
>
>
> GlobalSub <<EOS
> sub declare_extra_config {
>
> package Vend::Config;
>
> sub parse_foobar {
> my ($directive,$value) = @_;
> return undef unless $value =~ /yes/i;
>
> my $db = Vend::Data::database_exists_ref('products') or
> die "Couldn't get handle to table products'!";
>
> # some more code here eventually to add data to $Config
>
> 1;
> }
>
> }
> EOS
>
> AddDirective Foobar foobar
>
>
> Foobar Yes, is set at the end of my catalog.cfg file after the
> Database setup section.
>
> Any thoughts?
I found out that you need first to invoke Vend::Data::open_database() in
order to get Vend::Data::database_exists_ref() working in this case.
Regards
Racke
--
LinuXia Systems => http://www.linuxia.de/
Expert Interchange Consulting and System Administration
ICDEVGROUP => http://www.icdevgroup.org/
Interchange Development Team
More information about the interchange-users
mailing list