How can I get column names and row data in order with DBI in Perl?

前端 未结 5 1105
天涯浪人
天涯浪人 2021-02-19 22:42

I\'m using DBI to query a SQLite3 database. What I have works, but it doesn\'t return the columns in order. Example:

Query:  select col1, col2, col3, col4 from         


        
5条回答
  •  北恋
    北恋 (楼主)
    2021-02-19 23:22

    If you want to preserve the order, but still use a hash to refer to fields by name use:

    $dbh->selectall_arrayref($sql,{ Slice => {} } );
    

    This will give you an ordered array of hashes

提交回复
热议问题