LonelyPilgrim has asked for the wisdom of the Perl Monks concerning the following question:
Hail, great masters. I have returned after a long sojourn, in which I have traveled far in the paths of Perl, but am still very much a novice.
I am especially a newb to database work, and am trying to catch myself up. I feel like I am probably making a very simple and laughable mistake, so I only come to you after hours spent beating my head against this in futility, much google-searching, and throwing up my hands.
I am working with SQLite3 and DBD::SQLite (on WinXP, with ActivePerl 5.14.2), and have a fairly simple situation in which I have a table "profile," with integer primary key "profile_id", and another column "name". I want to do lookups on this table by "name", so I created an index "idx_name":
CREATE INDEX idx_name ON profile (name COLLATE NOCASE DESC);Queries on this index work just fine when testing them on the SQLite command line:
SELECT profile_id ON profile INDEXED BY idx_name WHERE name == 'William';However, when I try to run this in Perl, I get an error:
DBD::SQLite::db prepare failed: cannot use index: idx_nameuse strict; use warnings 'all'; use DBI; my $dbh = DBI->connect("dbi:SQLite:test.db","",""); my $sql = q{ SELECT profile_id FROM profile INDEXED BY idx_name WHERE +name == ? }; my $sth = $dbh->prepare($sql); my $name = 'William'; my $rc = $sth->execute($name);
What am I doing wrong? I appreciate your patience.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: "Can't use index" with DBD::SQLite
by choroba (Cardinal) on Jan 29, 2013 at 21:12 UTC | |
by LonelyPilgrim (Beadle) on Jan 29, 2013 at 22:50 UTC | |
by zyxsys.com (Initiate) on Mar 01, 2013 at 10:24 UTC | |
Re: "Can't use index" with DBD::SQLite
by Anonymous Monk on Jan 29, 2013 at 21:42 UTC | |
by LonelyPilgrim (Beadle) on Jan 29, 2013 at 22:51 UTC |