[Jifty-commit] r4471 - in Jifty-DBI/trunk: lib/Jifty/DBI
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Tue Nov 20 02:41:57 EST 2007
Author: ishigaki
Date: Tue Nov 20 02:41:56 2007
New Revision: 4471
Modified:
Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm
Jifty-DBI/trunk/t/01searches.t
Log:
JDBI: added 'escape' option (undef by default) to Collection->limit, to allow "where column like 'something including wildcard(\\%)' ESCAPE '\\'" kind of stuff, mainly for SQLite which doesn't seem to be able to escape wildcards without ESCAPE
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm Tue Nov 20 02:41:56 2007
@@ -1155,6 +1155,7 @@
entry_aggregator => 'or',
case_sensitive => undef,
operator => '=',
+ escape => undef,
subclause => undef,
leftjoin => undef,
@_ # get the real argumentlist
@@ -1210,6 +1211,10 @@
}
}
+ if ( $args{'escape'} ) {
+ $args{'escape'} = 'ESCAPE ' . $self->_quote_value( $args{escape} );
+ }
+
#If we're performing a left join, we really want the alias to be the
#left join criterion.
@@ -1297,6 +1302,7 @@
column => $qualified_column,
operator => $args{'operator'},
value => $args{'value'},
+ escape => $args{'escape'},
};
# Juju because this should come _AFTER_ the EA
@@ -1404,7 +1410,7 @@
unless ( ref $entry ) {
$result .= ' ' . $entry . ' ';
} else {
- $result .= join ' ', @{$entry}{qw(column operator value)};
+ $result .= join ' ', grep { defined } @{$entry}{qw(column operator value escape)};
}
}
$result .= ')';
Modified: Jifty-DBI/trunk/t/01searches.t
==============================================================================
--- Jifty-DBI/trunk/t/01searches.t (original)
+++ Jifty-DBI/trunk/t/01searches.t Tue Nov 20 02:41:56 2007
@@ -8,7 +8,7 @@
BEGIN { require "t/utils.pl" }
our (@available_drivers);
-use constant TESTS_PER_DRIVER => 97;
+use constant TESTS_PER_DRIVER => 109;
my $total = scalar(@available_drivers) * TESTS_PER_DRIVER;
plan tests => $total;
@@ -118,6 +118,36 @@
isa_ok( $first_rec, 'Jifty::DBI::Record', 'First returns record object' );
is( $first_rec->login, 'glasser', 'login is correct' );
+ # LIKE with wildcard
+ $users_obj->clean_slate;
+ is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
+ $users_obj->limit( column => 'name', operator => 'MATCHES', value => 'G_ass' );
+ is( $users_obj->count, 1, "found one user with 'Glass' in the name" );
+ $first_rec = $users_obj->first;
+ isa_ok( $first_rec, 'Jifty::DBI::Record', 'First returns record object' );
+ is( $first_rec->login, 'glasser', 'login is correct' );
+
+ # LIKE with escaped wildcard
+ $users_obj->clean_slate;
+ is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
+ $users_obj->limit( column => 'name', operator => 'MATCHES', value => 'G\\_ass', escape => '\\' );
+ is( $users_obj->count, 0, "should not find users with 'Glass' in the name" );
+
+ # LIKE with wildcard
+ $users_obj->clean_slate;
+ is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
+ $users_obj->limit( column => 'name', operator => 'MATCHES', value => 'Glass%' );
+ is( $users_obj->count, 1, "found one user with 'Glass' in the name" );
+ $first_rec = $users_obj->first;
+ isa_ok( $first_rec, 'Jifty::DBI::Record', 'First returns record object' );
+ is( $first_rec->login, 'glasser', 'login is correct' );
+
+ # LIKE with escaped wildcard
+ $users_obj->clean_slate;
+ is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
+ $users_obj->limit( column => 'name', operator => 'MATCHES', value => 'Glass\\%', escape => '\\' );
+ is( $users_obj->count, 0, "should not find users with 'Glass' in the name" );
+
# STARTSWITH
$users_obj->clean_slate;
is_deeply( $users_obj, $clean_obj, 'after clean_slate looks like new object');
More information about the Jifty-commit
mailing list