my ($class, $meth, $sql) = @_;
$class = ref $class if ref $class;
no strict 'refs';
+
+ my %attrs;
+ $attrs{rows} = $1 if $sql =~ s/LIMIT\s+(.*)\s+$//i;
+ $attrs{order_by} = $1 if $sql =~ s/ORDER BY\s+(.*)//i;
+
*{"${class}::${meth}"} =
sub {
my ($class, @args) = @_;
- return $class->search_literal($sql, @args);
+ return $class->search_literal($sql, @args, \%attrs);
};
}
next;
}
eval "use DBD::SQLite";
- plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 96);
+ plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 98);
}
INIT {
{
Film->add_constructor(title_asc => "title LIKE ? ORDER BY title");
Film->add_constructor(title_desc => "title LIKE ? ORDER BY title DESC");
+ Film->add_constructor(title_asc_nl => q{
+ title LIKE ?
+ ORDER BY title
+ LIMIT 1
+ });
{
my @films = Film->title_asc("Bladerunner%");
is @films, 2, "We have 2 Bladerunners";
is $films[0]->Title, $blrunner_dc->Title, "Ordered correctly";
}
+ {
+ my @films = Film->title_asc_nl("Bladerunner%");
+ is @films, 1, "We have 2 Bladerunners";
+ is $films[0]->Title, $blrunner->Title, "Ordered correctly";
+ }
}
# Multi-column search