Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Thank you for the tutorial. I'm new to PERL, more used to PHP, and I'm tailoring your code and making a Postgres database of songs that I perform and write to help organise my practice. But for the life of me I can't get the prepared statement to work with my Postgres query. The "ORDER BY" clause silently fails:
my $data = $DBH->selectall_arrayref(" select @{[join(',', @COLS)]} from songs order by ? ", undef, ($sort));
I've tried all sorts of things, but I can't get the sort order to work, so I resorted to the following which would be open to SQL injection:
my $data = $DBH->selectall_arrayref(" select @{[join(',', @COLS)]} from song order by $sort") or die "DBI::errstr";
Here is some DBI->Trace output, but I can't debug the problem...
... STORE DBI::db=HASH(0x11c9078) 'dbi_connect_closure' => CODE(0x11c9 +7f8) <- STORE= ( 1 ) [1 items] at /usr/local/lib/perl/5.18.2/ lin +e 754 via at /home/XXXX/.../songs_perlmonks_org/songs.cgi line 11 -> selectall_arrayref for DBD::Pg::db (DBI::db=HASH(0x11c8f10)~0x1 +1c9078 ' select id,title,key,recorded,songwriter,vocals_needed,length from song order by ? ' HASH(0x110dd70) 'songwriter') thr#bac010 1 -> prepare for DBD::Pg::db (DBI::db=HASH(0x11c9078)~INNER ' select id,title,key,recorded,songwriter,vocals_needed,length from song order by ? ' HASH(0x110dd70)) thr#bac010 Begin dbd_st_prepare (statement: select id,title,key,recorded,songwriter,vocals_needed,length from song order by ? ) Begin pg_st_split_statement End pg_st_split_statement Immediate prepare decision: dml=1 direct=0 server_prepare=1 prepare_no +w=0 PGLIBVERSION=90309 End dbd_st_prepare 1 <- prepare= ( DBI::st=HASH(0x110df38) ) [1 items] at /home/XXXX/.. +./songs_perlmonks_org/songs.cgi line 23 Begin dbd_bind_ph (ph_name: 1) End dbd_bind_ph Begin dbd_st_execute PQexec* decision: dml=1 direct=0 server_prepare=1 numbound=0 numphs=1 +default=0 current=0 Begin _sqlstate End _sqlstate (imp_dbh->sqlstate: 00000) End _sqlstate (status: 2) End dbd_st_execute (rows: 32) Begin dbd_st_fetch End dbd_st_fetch ...

In reply to "ORDER BY" clause silently fails by mikecorb
in thread HTML::Template Tutorial by jeffa

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2022-05-25 18:48 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (90 votes). Check out past polls.