Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^4: My doubts about using fetchall_arrayref

by Anonymous Monk
on Apr 02, 2013 at 15:02 UTC ( #1026710=note: print w/replies, xml ) Need Help??


in reply to Re^3: My doubts about using fetchall_arrayref
in thread My doubts about using fetchall_arrayref

I know, but my question was in regards of this situation:
How would I pass " CONVERT(VARCHAR(10),date,101)" to the names of columns. From this code:
... my $sql = "select id, account_number, CONVERT(VARCHAR(10),date,101) a +s date from my_table where id <>'' order by date desc"; my @columns = qw( id account_number box ); my $results = $self->_all_data($sql, \@columns); ...
To this:
... my @columns = qw( id account_number date ); my $sql = "select ".join( ",", @columns). " from my_table where id <>'' order by date desc"; my $results = $self->_all_data($sql, \@columns); ...

Replies are listed 'Best First'.
Re^5: My doubts about using fetchall_arrayref
by hdb (Monsignor) on Apr 02, 2013 at 15:13 UTC

    You cannot. My proposal only works for simple column names. Do you really need to pass the columns names? Can you not use

    my $rs = $sth->fetchall_arrayref({});

    without specifying the columns? According to the documentation it should work but I do not have your database to test it. This way everything would be controlled by your sql only.

      In this case I will use the sample below for SQL queries that require a more complex call, yes I could use this:
      my $rs = $sth->fetchall_arrayref({});
      ... my $sql = "select id, account_number, CONVERT(VARCHAR(10),date,101) a +s date from my_table where id <>'' order by date desc"; my @columns = qw( id account_number box ); my $results = $self->_all_data($sql, \@columns); ...
        If you have a more advanced query like this one:
        my $sql = "select id, account_number, CONVERT(VARCHAR(10),date,101) as + date from my_table where id <> '' order by date desc";
        Then you can call the version of _all_data() that I gave above as either:
        my @columns = qw( id account_number date ); my $results = $self->_all_data($sql, \@columns);
        or
        my $results = $self->_all_data($sql);
        They will both get the same result set.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1026710]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2018-07-16 20:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (349 votes). Check out past polls.

    Notices?