Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: DBD::Pg no errors but empty result?

by choroba (Cardinal)
on Mar 18, 2021 at 23:31 UTC ( [id://11129933]=note: print w/replies, xml ) Need Help??


in reply to DBD::Pg no errors but empty result?

Are you able to connect using DBI and DBD::Pg?

Without seeing your helper module, we can only guess. Do you properly check for connection failures?

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: DBD::Pg no errors but empty result?
by cormanaz (Deacon) on Mar 19, 2021 at 00:34 UTC
    Well don't I feel stupid. It works. I printed $n rather than "$n\n" so it output the answer then the commend prompt immediately after and I didn't notice.

    Thanks for the response and sorry for the cycles. :-/

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^2: DBD::Pg no errors but empty result?
by cormanaz (Deacon) on Mar 19, 2021 at 00:10 UTC
    Here's the test script that includes the helper subs. Yes I check for connection failures, whether I'm doing it the right way...
    #!/usr/bin/perl -w use DBI; my $dbh = connectpgdb('****','****','****','Pg','localhost'); my $n = getsqlvalue($dbh,"select count(*) from blog"); print $n; sub connectpgdb { # this is used to connect with DBD::Pg my ($database,$user,$password,$driver,$server) = @_; my $url; unless ($driver) { $driver = "Pg"; } unless ($server) { $url = "DBI:$driver:dbname=$database;host=localhost"; } else { $url = "DBI:$driver:dbname=$database;host=$server;port=54 +32"; } unless ($user) { $user = "****"; $password = "****"; } my $dbh = DBI->connect( $url, $user, $password,{AutoCommit=>1,Rais +eError=>1,PrintError=>1}) or die "connectdb can't connect to psql: $! +\n"; return $dbh; } sub getsqlvalue { my @results = (); my ($dbh,$sqlstatement)= @_; my $sth = $dbh->prepare($sqlstatement); my @row; $sth->execute || die "Could not execute MySQL statement: $sqlstate +ment"; while (@row=$sth->fetchrow_array) { push(@results, [ @row ]); } $sth->finish(); return $results[0][0]; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11129933]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-19 16:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found