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.....


In reply to dbi bind_columns with an array: fail by ag4ve

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.