[Bast-commits] r4200 - in DBIx-Class/0.08/trunk:
lib/DBIx/Class/CDBICompat t/cdbi-t
schwern at dev.catalyst.perl.org
schwern at dev.catalyst.perl.org
Fri Mar 14 03:16:37 GMT 2008
Author: schwern
Date: 2008-03-14 03:16:36 +0000 (Fri, 14 Mar 2008)
New Revision: 4200
Modified:
DBIx-Class/0.08/trunk/lib/DBIx/Class/CDBICompat/Constructor.pm
DBIx-Class/0.08/trunk/t/cdbi-t/02-Film.t
Log:
Improve add_constructor() support to handle ORDER BY and LIMIT with newlines in
the SQL
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/CDBICompat/Constructor.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/CDBICompat/Constructor.pm 2008-03-14 02:01:20 UTC (rev 4199)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/CDBICompat/Constructor.pm 2008-03-14 03:16:36 UTC (rev 4200)
@@ -8,10 +8,15 @@
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);
};
}
Modified: DBIx-Class/0.08/trunk/t/cdbi-t/02-Film.t
===================================================================
--- DBIx-Class/0.08/trunk/t/cdbi-t/02-Film.t 2008-03-14 02:01:20 UTC (rev 4199)
+++ DBIx-Class/0.08/trunk/t/cdbi-t/02-Film.t 2008-03-14 03:16:36 UTC (rev 4200)
@@ -9,7 +9,7 @@
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 {
@@ -126,6 +126,11 @@
{
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%");
@@ -137,6 +142,11 @@
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
More information about the Bast-commits
mailing list