Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Interchange: users

Database connection in AddDirective sub

 

 

Interchange users RSS feed   Index | Next | Previous | View Threaded


mat at bibliopolis

Oct 13, 2009, 10:32 AM

Post #1 of 2 (680 views)
Permalink
Database connection in AddDirective sub

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?

Regards,

Mat

_______________________________________________
interchange-users mailing list
interchange-users [at] icdevgroup
http://www.icdevgroup.org/mailman/listinfo/interchange-users


racke at linuxia

Oct 16, 2009, 6:08 AM

Post #2 of 2 (601 views)
Permalink
Re: Database connection in AddDirective sub [In reply to]

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


_______________________________________________
interchange-users mailing list
interchange-users [at] icdevgroup
http://www.icdevgroup.org/mailman/listinfo/interchange-users

Interchange users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.