However, I've been trying to get the following code to work for a couple of hours now, but I seem to be stuck and am out of ideas.
The Sub GetPriceList gets a list of prices from the database, which contains a product_id. The product_id corresponds to the queue.id.
I want to retrieve the name of the queue using the product_id by calling the sub GetQueueNameByID.
I keep getting an Internal Server Error when the sub GetQueueNameByID calls the $Self->{DBObject}->Prepare(SQL => $SQL,); statement.
If I comment out the SQL prepare and fetch stuff in GetQueueNameByID, and just let the sub return some test string, it works.
Can someone please explain to me why this happens and how I can fix it? Thanks!
Code: Select all
sub GetPriceList {
my ( $Self, %Param ) = @_;
# create SQL query
my $SQL = 'SELECT * FROM my_prices';
# ask database
$Self->{DBObject}->Prepare(
SQL => $SQL,
);
# fetch the result
my @PijzenList;
while ( my @Row = $Self->{DBObject}->FetchrowArray() ) {
my %PijzenData;
$PijzenData{product_id} = $Row[0];
#$PijzenData{product_naam} = $Self->{BitosPrijzenObject}->GetQueueNameByID(
# #QueueID => $Row[0],
# QueueID => 0,
#);
$PijzenData{product_naam} = &GetQueueNameByID($Row[0]);
$PijzenData{werkuren_oc} = $Row[1];
$PijzenData{werkuren} = $Row[2];
$PijzenData{rijtijd_oc} = $Row[3];
$PijzenData{rijtijd} = $Row[4];
$PijzenData{consultancy_oc} = $Row[5];
$PijzenData{consultancy} = $Row[6];
$PijzenData{kost_kilometers} = $Row[7];
# add service data to service list
push @PijzenList, \%PijzenData;
}
return \@PijzenList;
}
Code: Select all
sub GetQueueNameByID {
my ( $Self, %Param ) = @_;
# create SQL query
my $SQL = 'SELECT name FROM queue WHERE id = ' . $_[0];
# ask database
$Self->{DBObject}->Prepare(
SQL => $SQL,
);
my $Result = '';
while ( my @Row = $Self->{DBObject}->FetchrowArray() ) {
$Result = $Row[0];
}
return $Result;
}