in reply to "Cannot use index" with DBD::SQLite
If I switch name and profile_id in the index creation, I get the error you mentioned, but only if no other index has been yet defined. I am not sure this is the intended behaviour.#!/usr/bin/perl use warnings; use strict; use DBI; unlink 'test.db' or warn $!; my $dbh = DBI->connect('dbi:SQLite:test.db', q(), q()); $dbh->do(q(create table profile (profile_id integer, name varchar))); $dbh->do(q(create index idx_name on profile (name, profile_id))); my $insert = $dbh->prepare(q(insert into profile values(?, ?))); $insert->execute(@$_) for [10, 'Joseph'], [11, 'William'], [12, 'Elisabeth']; my $sql = q{ SELECT profile_id FROM profile INDEXED BY idx_name WHERE name == ? }; my $sth = $dbh->prepare($sql); my $name = 'William'; $sth->execute($name); my $arr = $sth->fetchall_arrayref; print "@$_\n" for @$arr;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: "Can't use index" with DBD::SQLite
by LonelyPilgrim (Beadle) on Jan 29, 2013 at 22:50 UTC | |
by zyxsys.com (Initiate) on Mar 01, 2013 at 10:24 UTC |