Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

dbi bind_columns with an array: fail

by ag4ve (Monk)
on Oct 17, 2010 at 22:27 UTC ( [id://865850]=perlquestion: print w/replies, xml ) Need Help??

ag4ve has asked for the wisdom of the Perl Monks concerning the following question:

it seems that i'm bashing heads with dbi here. i need to bind_columns to an array. now while it seems that this was never meant to happen:

http://www.mail-archive.com/dbi-dev@perl.org/msg03906.html

... and there's probably a more elegant way to solve this in sql itself, i am not good enough with nested select statements to figure it out (or maybe union) and still think that i wouldn't know exactly what i'm returning - hence the array. i've tried the two methods they state here

http://www.perlmonks.org/?node_id=284436

with the same results. here is my (not so pretty) code:

my ($sth, $query, $select, $from, $where, $likedate, $join, $s +elmin, $selmax, $min, $max, @sogs); $key =~ s/\'/\\\'/g; $select = qq/SELECT FLOOR( MIN( n.x ) ), FLOOR( MAX( n.x + ) ) /; $from = qq/FROM o, n /; $where = qq/WHERE MATCH( o.owner, o.mn, o.manag +er ) AGAINST( '+$key' IN BOOLEAN MODE ) /; $likedate = qq/AND n.time LIKE '$date%' /; $join = qq/AND o.key = n.key /; $query = $select . $from . $where . $likedate . $join; $sth = $dbh->prepare( $query ); $sth->execute; $sth->bind_columns( $selmin, $selmax ); while( $sth->fetch ) { if ( !defined( $min ) || !defined( $max ) ) { $min = $selmin; $max = $selmax; } $min = $selmin if $selmin < $min; $max = $selmax if $selmax > $max; } my $countif = ""; for my $i ( $min .. $max ) { $countif .= qq/COUNT( IF( FLOOR( n.x ) = $i,1,null ) ) + /; } $select = qq/SELECT $countif /; $from = qq/FROM o, n /; $where = qq/WHERE MATCH( o.owner, o.mn, o.manag +er ) AGAINST( '+$key' IN BOOLEAN MODE ) /; $likedate = qq/AND n.time LIKE '$date%' /; $join = qq/o.key = n.key /; $query = $select . $from . $where . $likedate . $join; $sth = dbh->prepare( $query ); $sth->execute; $sth->bind_columns( map {$_} @sogs ); while( $sth->fetchrow_arrayref ) { print "$key,"; for( 1 .. $min ) { print ","; } print join( ',', @sogs ), "\n"; }

my error, no matter how i try to return arrays is pretty much the same

Can't DBI::st=HASH(0x1aa7a40)->bind_col(1, undef,...), need a referenc +e to a scalar at /usr/lib/perl5/DBI.pm line 1867, <FILE> line 56.

heh, and it's quite stupid of me to redefine half of my select statement when i don't have to.....

Replies are listed 'Best First'.
Re: dbi bind_columns with an array: fail
by zwon (Abbot) on Oct 18, 2010 at 00:32 UTC

    I think problem is because you passing list of variables to bind_columns method, and it expects the list of references to variables, like that:

    bind_columns(\$selmin, \$selmax);

      In which case $sth->bind_columns( map {\$_} @sogs ); might solve the problem?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-24 17:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found