Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

If I understand the question (and your subsequent clarification) correctly, I think this should do the trick:

use strict; use warnings; use DBI; use DBD::SQLite; use Data::Dumper; my $dbh = DBI->connect( 'dbi:SQLite:dbname=test.sqlite', undef, undef, { RaiseError => 1, PrintError => 1, } ); eval { $dbh->do('CREATE TABLE evkeypairs (id INTEGER PRIMARY KEY NOT NULL +,key TEXT,value TEXT);'); $dbh->do(q!INSERT INTO evkeypairs (key, value) VALUES ('foo','bar' +);!); $dbh->do(q!INSERT INTO evkeypairs (key, value) VALUES ('kung','foo +');!); } or warn "$@"; my $sth = $dbh->prepare( 'SELECT * FROM evkeypairs' ); $sth->execute; my $href = $sth->fetchall_hashref( 'id' ); print Dumper $href; $dbh->disconnect; unlink 'test.sqlite'; __END__ $VAR1 = { '1' => { 'value' => 'bar', 'id' => '1', 'key' => 'foo' }, '2' => { 'value' => 'foo', 'id' => '2', 'key' => 'kung' } };

Thanks to AM for providing the code to create a test db.


In reply to Re: selectall_hashref structure by bobf
in thread selectall_hashref structure by 0xbeef

Title:
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 How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-18 12:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found