Perl's SQLite3: {NAME} not working?

Here's a snippet of code from an sqlite database application I'm working on:

my $query = "select * from pins";
my $sth = $dbh->prepare($query) or die "Couldn't prep: $DBI::errstr";
$sth->execute or die "Exec problem: $DBI::errstr";
my $result = $sth->fetchall_arrayref();
my $names = $sth->{NAME} or die "Name failed: $DBI::errstr";
foreach my $row (@$res) {
    # ... do some row-specific things
    foreach my $cell (@$row) {
        # ... do some cell-specific things

The query fires off just fine, and in fact it returns the correct results. However, for some reason, this line,

my $names = $sth->{NAME} or die "Name failed: $DBI::errstr";

Fails. {NAME} never returns the arrayref I'd expect. If I take the die clause out, it runs fine (throwing the expected "using uninitialized values" warning wherever I'm using $names, of course).

Is there some obvious reason I'm missing that {NAME} wouldn't fire off, given that the query worked just fine?



Big-time boneheaded mistake on my part. Switching two lines so that it's

my $names ...
my $result ...

Fixes it. I guess I have to grab for {NAME} directly after execute() (or rather, before $sth changes). I didn't expect fetchall_arrayref to wipe {NAME}.

Works now! Sorry for the post. I'll leave this up for posterity until someone decides it's not worth the space. :-)

Need Your Help

Doing Arithmetic on VARCHAR columns


The 3 fields below 'Winning', 'BuyIn', 'ChampFund' are VARCHAR datatype with values that include a $ character like $250.00

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.