
ok people, i've got some really weird problem with perl DBI, and I cannot find out what the hell I'm doing wrong. The code is below. The executed query is a simple count, which should always return a value. You can also see the "#TESTING"-part, which returns the count immediately for testing purposes. If the "TESTING"-part is not commented out: - %test_sd returns the actual value that is stored in the database (0 or higher). Checked manually. Not a problem. If the "TESTING"-part is commented out: a) $test_count is not zero: not a problem, the program just skips the content of the if-clause b) $test_count is zero: program crashes (just says: 'error: n'). That's it :s So, anybody can see what's wrong here? Michiel my $query_count = "SELECT count(`msa`.`aln`) as count FROM `msa` WHERE `msa`.`gf_id` ='".$gf_id."' ;"; my $rt_count = $dbh->prepare($query_count); my $dbi_ret_count = $rt_count->execute(); if(!$dbi_ret_count){ my %retval = ("error"=>"No valid database connection"); return \%retval; } my @res_count = $rt_count->fetchrow_array; my $test_count = @res_count[0]; my %test_sd = ("count result"=>$test_count); #TESTING return \%test_sd; #TESTING if($test_count==0){ my %retval = ("error"=>"no gf data"); return \%retval; } -- ================================================================== Michiel Van Bel PhD student Tel:+32 (0)9 331 36 95 fax:+32 (0)9 3313809 VIB Department of Plant Systems Biology, Ghent University Technologiepark 927, 9052 Gent, BELGIUM mibel@psb.ugent.be http://www.psb.ugent.be ==================================================================

k, problem fixed. stupid me, stupid me... Michiel Van Bel wrote:
ok people, i've got some really weird problem with perl DBI, and I cannot find out what the hell I'm doing wrong. The code is below. The executed query is a simple count, which should always return a value. You can also see the "#TESTING"-part, which returns the count immediately for testing purposes.
If the "TESTING"-part is not commented out: - %test_sd returns the actual value that is stored in the database (0 or higher). Checked manually. Not a problem.
If the "TESTING"-part is commented out: a) $test_count is not zero: not a problem, the program just skips the content of the if-clause b) $test_count is zero: program crashes (just says: 'error: n'). That's it :s
So, anybody can see what's wrong here?
Michiel
my $query_count = "SELECT count(`msa`.`aln`) as count FROM `msa` WHERE `msa`.`gf_id` ='".$gf_id."' ;"; my $rt_count = $dbh->prepare($query_count); my $dbi_ret_count = $rt_count->execute(); if(!$dbi_ret_count){ my %retval = ("error"=>"No valid database connection"); return \%retval; } my @res_count = $rt_count->fetchrow_array; my $test_count = @res_count[0];
my %test_sd = ("count result"=>$test_count); #TESTING return \%test_sd; #TESTING
if($test_count==0){ my %retval = ("error"=>"no gf data"); return \%retval; }
-- ================================================================== Michiel Van Bel PhD student Tel:+32 (0)9 331 36 95 fax:+32 (0)9 3313809 VIB Department of Plant Systems Biology, Ghent University Technologiepark 927, 9052 Gent, BELGIUM mibel@psb.ugent.be http://www.psb.ugent.be ==================================================================

A good habit would be to include the solution (annoying as hell when people do this on public fora..) ;-) Michiel Van Bel wrote:
k, problem fixed. stupid me, stupid me...
Michiel Van Bel wrote:
ok people, i've got some really weird problem with perl DBI, and I cannot find out what the hell I'm doing wrong. The code is below. The executed query is a simple count, which should always return a value. You can also see the "#TESTING"-part, which returns the count immediately for testing purposes.
If the "TESTING"-part is not commented out: - %test_sd returns the actual value that is stored in the database (0 or higher). Checked manually. Not a problem.
If the "TESTING"-part is commented out: a) $test_count is not zero: not a problem, the program just skips the content of the if-clause b) $test_count is zero: program crashes (just says: 'error: n'). That's it :s
So, anybody can see what's wrong here?
Michiel
my $query_count = "SELECT count(`msa`.`aln`) as count FROM `msa` WHERE `msa`.`gf_id` ='".$gf_id."' ;"; my $rt_count = $dbh->prepare($query_count); my $dbi_ret_count = $rt_count->execute(); if(!$dbi_ret_count){ my %retval = ("error"=>"No valid database connection"); return \%retval; } my @res_count = $rt_count->fetchrow_array; my $test_count = @res_count[0];
my %test_sd = ("count result"=>$test_count); #TESTING return \%test_sd; #TESTING
if($test_count==0){ my %retval = ("error"=>"no gf data"); return \%retval; }
-- Sofie Van Landeghem PhD Student VIB Department of Plant Systems Biology, Ghent University Bioinformatics and Evolutionary Genomics Technologiepark 927, 9052 Gent, BELGIUM Tel: +32 (0)9 331 36 95 fax:+32 (0)9 3313809 Website: http://bioinformatics.psb.ugent.be

Well, I was testing it over the webservice. And it appears the webservice "interpretes" the 'error'-keyword in a hash-reference. So the webservice assumes the perl-module crashed, and it throws an unncatchable php-exception thingie. While it is simply my program that tries to return an error-code. Part of the problem was of course that the webservice kinda removed most of the information (instead of "no gf data", it reduced this to "n"). This of course made finding the "featute" a bit more challenging. So the solution: my %retval = ("ws_error"=>"no gf data"); return \%retval; Michiel Sofie Van Landeghem wrote:
A good habit would be to include the solution (annoying as hell when people do this on public fora..) ;-)
Michiel Van Bel wrote:
k, problem fixed. stupid me, stupid me...
Michiel Van Bel wrote:
ok people, i've got some really weird problem with perl DBI, and I cannot find out what the hell I'm doing wrong. The code is below. The executed query is a simple count, which should always return a value. You can also see the "#TESTING"-part, which returns the count immediately for testing purposes.
If the "TESTING"-part is not commented out: - %test_sd returns the actual value that is stored in the database (0 or higher). Checked manually. Not a problem.
If the "TESTING"-part is commented out: a) $test_count is not zero: not a problem, the program just skips the content of the if-clause b) $test_count is zero: program crashes (just says: 'error: n'). That's it :s
So, anybody can see what's wrong here?
Michiel
my $query_count = "SELECT count(`msa`.`aln`) as count FROM `msa` WHERE `msa`.`gf_id` ='".$gf_id."' ;"; my $rt_count = $dbh->prepare($query_count); my $dbi_ret_count = $rt_count->execute(); if(!$dbi_ret_count){ my %retval = ("error"=>"No valid database connection"); return \%retval; } my @res_count = $rt_count->fetchrow_array; my $test_count = @res_count[0];
my %test_sd = ("count result"=>$test_count); #TESTING return \%test_sd; #TESTING
if($test_count==0){ my %retval = ("error"=>"no gf data"); return \%retval; }
-- ================================================================== Michiel Van Bel PhD student Tel:+32 (0)9 331 36 95 fax:+32 (0)9 3313809 VIB Department of Plant Systems Biology, Ghent University Technologiepark 927, 9052 Gent, BELGIUM mibel@psb.ugent.be http://www.psb.ugent.be ==================================================================
participants (2)
-
Michiel Van Bel
-
Sofie Van Landeghem