[Bps-public-commit] jifty-dbi branch, master, updated. 4ea6d4e39ee5798a4b70ad88f12d09f614fd7f9f
Alex M Vandiver
alexmv at bestpractical.com
Wed Dec 30 17:14:29 EST 2009
The branch, master has been updated
via 4ea6d4e39ee5798a4b70ad88f12d09f614fd7f9f (commit)
via 5f5bceeaffb131217e047e4fb2ba70fc8c2cf8ad (commit)
via bd34a833e202d33b0bae52e82c6144d5361a645f (commit)
via 23daae5a069104c9a8ac5d0f8b5a72859b062e80 (commit)
from 91cb3225c8725729981f9eff39e9874ba6d3f0f0 (commit)
Summary of changes:
lib/Jifty/DBI/Handle.pm | 2 +-
lib/Jifty/DBI/Handle/Pg.pm | 12 ++--
lib/Jifty/DBI/Handle/SQLite.pm | 4 +
t/case_sensitivity.t | 153 +++++++++++++++++++++++++++++-----------
4 files changed, 121 insertions(+), 50 deletions(-)
- Log -----------------------------------------------------------------
commit 23daae5a069104c9a8ac5d0f8b5a72859b062e80
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Wed Dec 30 16:38:28 2009 -0500
Make sqlite respect _case_insensitivity_valid
diff --git a/lib/Jifty/DBI/Handle/SQLite.pm b/lib/Jifty/DBI/Handle/SQLite.pm
index fb9a725..53fe467 100644
--- a/lib/Jifty/DBI/Handle/SQLite.pm
+++ b/lib/Jifty/DBI/Handle/SQLite.pm
@@ -95,6 +95,10 @@ sub _make_clause_case_insensitive {
my $column = shift;
my $operator = shift;
my $value = shift;
+
+ return ($column, $operator, $value)
+ unless $self->_case_insensitivity_valid( $column, $operator, $value );
+
return("$column COLLATE NOCASE", $operator, $value);
}
commit bd34a833e202d33b0bae52e82c6144d5361a645f
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Wed Dec 30 16:38:57 2009 -0500
Refactor Pg's stricter operator testing out to Jifty::DBI::Handle
diff --git a/lib/Jifty/DBI/Handle.pm b/lib/Jifty/DBI/Handle.pm
index 5a8c4c6..e1b6a39 100755
--- a/lib/Jifty/DBI/Handle.pm
+++ b/lib/Jifty/DBI/Handle.pm
@@ -716,7 +716,7 @@ sub _case_insensitivity_valid {
return $value ne ''
&& $value ne "''"
- && ( $operator !~ /IS/ && $value !~ /^null$/i )
+ && ( $operator =~ /^(?:LIKE|=|IN)$/i )
# don't downcase integer values
&& $value !~ /^['"]?\d+['"]?$/;
diff --git a/lib/Jifty/DBI/Handle/Pg.pm b/lib/Jifty/DBI/Handle/Pg.pm
index 192cae6..682bdd8 100755
--- a/lib/Jifty/DBI/Handle/Pg.pm
+++ b/lib/Jifty/DBI/Handle/Pg.pm
@@ -173,13 +173,11 @@ sub _make_clause_case_insensitive {
my $value = shift;
if ( $self->_case_insensitivity_valid( $column, $operator, $value ) ) {
- if ( $operator =~ /^(?:LIKE|=|IN)$/i ) {
- $column = "LOWER($column)";
- if ( $operator =~ /^(IN|=)$/i and ref($value) eq 'ARRAY' ) {
- $value = [ map {"LOWER($_)"} @$value ];
- } else {
- $value = "LOWER($value)";
- }
+ $column = "LOWER($column)";
+ if ( $operator =~ /^(IN|=)$/i and ref($value) eq 'ARRAY' ) {
+ $value = [ map {"LOWER($_)"} @$value ];
+ } else {
+ $value = "LOWER($value)";
}
}
return ( $column, $operator, $value );
commit 5f5bceeaffb131217e047e4fb2ba70fc8c2cf8ad
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Wed Dec 30 16:40:03 2009 -0500
Fix insensitive operators to work with != and NOT LIKE
diff --git a/lib/Jifty/DBI/Handle.pm b/lib/Jifty/DBI/Handle.pm
index e1b6a39..bad3348 100755
--- a/lib/Jifty/DBI/Handle.pm
+++ b/lib/Jifty/DBI/Handle.pm
@@ -716,7 +716,7 @@ sub _case_insensitivity_valid {
return $value ne ''
&& $value ne "''"
- && ( $operator =~ /^(?:LIKE|=|IN)$/i )
+ && ( $operator =~ /^(?:(?:NOT )?LIKE|!?=|IN)$/i )
# don't downcase integer values
&& $value !~ /^['"]?\d+['"]?$/;
commit 4ea6d4e39ee5798a4b70ad88f12d09f614fd7f9f
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Wed Dec 30 16:40:40 2009 -0500
More extensive testing of case sensitivity in collections
diff --git a/t/case_sensitivity.t b/t/case_sensitivity.t
index 7b59f6a..02d096f 100644
--- a/t/case_sensitivity.t
+++ b/t/case_sensitivity.t
@@ -6,71 +6,135 @@ use Test::More;
BEGIN { require "t/utils.pl" }
our (@available_drivers);
-use constant TESTS_PER_DRIVER => 9;
+use constant TESTS_PER_DRIVER => 139;
my $total = scalar(@available_drivers) * TESTS_PER_DRIVER;
plan tests => $total;
use DateTime ();
-foreach my $d ( @available_drivers ) {
+foreach my $d (@available_drivers) {
SKIP: {
- unless( has_schema( 'TestApp::User', $d ) ) {
- skip "No schema for '$d' driver", TESTS_PER_DRIVER;
- }
- unless( should_test( $d ) ) {
- skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
- }
- diag("start testing with '$d' handle") if $ENV{TEST_VERBOSE};
-
- my $handle = get_handle( $d );
- connect_handle( $handle );
- isa_ok($handle->dbh, 'DBI::db');
-
- {my $ret = init_schema( 'TestApp::User', $handle );
- isa_ok($ret,'DBI::st', "Inserted the schema. got a statement handle back" );}
-
- my $rec = TestApp::User->new( handle => $handle );
- isa_ok($rec, 'Jifty::DBI::Record');
-
- my ($id) = $rec->create( name => 'Foobar', interests => 'Slacking' );
- ok($id, "Successfuly created ticket");
-
- $rec->load_by_cols( name => 'foobar');
- TODO: {
- local $TODO = "How do we force mysql to be case sensitive?" if ( $d eq 'mysql' || $d eq 'mysqlPP' );
- is($rec->id, undef);
+ unless ( has_schema( 'TestApp::User', $d ) ) {
+ skip "No schema for '$d' driver", TESTS_PER_DRIVER;
+ }
+ unless ( should_test($d) ) {
+ skip "ENV is not defined for driver '$d'", TESTS_PER_DRIVER;
+ }
+ diag("start testing with '$d' handle") if $ENV{TEST_VERBOSE};
+
+ my $handle = get_handle($d);
+ connect_handle($handle);
+ isa_ok( $handle->dbh, 'DBI::db' );
+
+ {
+ my $ret = init_schema( 'TestApp::User', $handle );
+ isa_ok( $ret, 'DBI::st',
+ "Inserted the schema. got a statement handle back" );
}
- $rec->load_by_cols( name => { value => 'foobar', case_sensitive => 0, operator => '=' });
- is($rec->id, $id);
+ my $rec = TestApp::User->new( handle => $handle );
+ isa_ok( $rec, 'Jifty::DBI::Record' );
- $rec->load_by_cols( name => 'Foobar');
- is($rec->id, $id);
+ my ($id) = $rec->create( name => 'Foobar', interests => 'Slacking' );
+ ok( $id, "Successfuly created ticket" );
- $rec->load_by_cols( interests => 'slacking');
- is($rec->id, $id);;
+ $rec->load_by_cols( name => 'foobar' );
+TODO: {
+ local $TODO = "How do we force mysql to be case sensitive?"
+ if ( $d eq 'mysql' || $d eq 'mysqlPP' );
+ is( $rec->id, undef );
+ }
+
+ $rec->load_by_cols( name =>
+ { value => 'foobar', case_sensitive => 0, operator => '=' } );
+ is( $rec->id, $id );
+
+ $rec->load_by_cols( name => 'Foobar' );
+ is( $rec->id, $id );
+
+ $rec->load_by_cols( interests => 'slacking' );
+ is( $rec->id, $id );
+
+ $rec->load_by_cols( interests => 'Slacking' );
+ is( $rec->id, $id );
+
+# IN
+# IS
+# IS NOT
+
+ ### Numbers
+ threeway_same($handle, id => $_, 42) for qw/= != < > <= >=/;
+ threeway_same($handle, id => $_, 42) for ("LIKE", "NOT LIKE", "MATCHES", "STARTS_WITH", "ENDS_WITH");
+ threeway_same($handle, id => $_ => [ 42, 17 ]) for qw/= IN/;
+ threeway_same($handle, id => $_ => 'NULL') for ("IS", "IS NOT");
+ threeway_same($handle, id => $_ => 'null') for ("IS", "IS NOT");
+
+ ## Strings
+ threeway_same($handle, name => $_, "bob") for qw/< > <= >=/;
+ threeway_same($handle, name => $_, 17) for ("=", "!=", "LIKE", "NOT LIKE");
+ threeway_different($handle, name => $_, 17) for ("MATCHES", "STARTS_WITH", "ENDS_WITH");
+ threeway_different($handle, name => $_, "bob") for ("=", "!=", "LIKE", "NOT LIKE", "MATCHES", "STARTS_WITH", "ENDS_WITH");
+ threeway_different($handle, name => $_, "null") for ("=", "!=", "LIKE", "NOT LIKE", "MATCHES", "STARTS_WITH", "ENDS_WITH");
+ threeway_different($handle, name => $_ => [ "bob", "alice" ]) for qw/= IN/;
+ threeway_same($handle, name => $_ => 'NULL') for ("IS", "IS NOT");
+ threeway_same($handle, name => $_ => 'null') for ("IS", "IS NOT");
+
+ ## Other
+ threeway_same($handle, created => $_, 42) for qw/= != < > <= >=/;
+ threeway_same($handle, created => $_, 42) for ("LIKE", "NOT LIKE", "MATCHES", "STARTS_WITH", "ENDS_WITH");
+ threeway_same($handle, created => $_ => [ 42, 17 ]) for qw/= IN/;
+ threeway_same($handle, created => $_ => 'NULL') for ("IS", "IS NOT");
+ threeway_same($handle, created => $_ => 'null') for ("IS", "IS NOT");
+
+ cleanup_schema( 'TestApp', $handle );
+ disconnect_handle($handle);
+}
+}
- $rec->load_by_cols( interests => 'Slacking');
- is($rec->id, $id);;
+sub threeway_same {
+ my ($default, $insensitive, $sensitive) = threeway_test(@_);
+ shift @_;
+ is( $default, $insensitive, "Default and insensitive queries are the same (@_)");
+ is( $sensitive, $insensitive, "Sensitive and insensitive queries are the same (@_)");
+}
- cleanup_schema( 'TestApp', $handle );
- disconnect_handle( $handle );
+sub threeway_different {
+ my ($default, $insensitive, $sensitive) = threeway_test(@_);
+ my $handle = shift @_;
+ is( $default, $sensitive, "Default and insensitive queries are the same (@_)");
+TODO: {
+ local $TODO = "How do we force mysql to be case sensitive?"
+ if $handle =~ /mysql/;
+ isnt( $sensitive, $insensitive, "Sensitive and insensitive queries are not the same (@_)");
+ }
}
+
+sub threeway_test {
+ my ($handle, $column, $op, $value) = @_;
+ my $default = TestApp::UserCollection->new( handle => $handle );
+ $default->limit( column => $column, value => $value, operator => $op );
+
+ my $insensitive = TestApp::UserCollection->new( handle => $handle );
+ $insensitive->limit( column => $column, value => $value, operator => $op, case_sensitive => 0 );
+
+ my $sensitive = TestApp::UserCollection->new( handle => $handle );
+ $sensitive->limit( column => $column, value => $value, operator => $op, case_sensitive => 1 );
+
+ return map {$_->build_select_query} ($default, $insensitive, $sensitive);
}
package TestApp::User;
use base qw/Jifty::DBI::Record/;
-1;
-
sub schema_sqlite {
<<EOF;
CREATE table users (
id integer primary key,
name varchar,
- interests varchar
+ interests varchar,
+ created date
)
EOF
@@ -82,7 +146,8 @@ sub schema_mysql {
CREATE TEMPORARY table users (
id integer auto_increment primary key,
name varchar(255),
- interests varchar(255)
+ interests varchar(255),
+ created date
)
EOF
@@ -94,7 +159,8 @@ sub schema_pg {
CREATE TEMPORARY table users (
id serial primary key,
name varchar,
- interests varchar
+ interests varchar,
+ created date
)
EOF
@@ -105,8 +171,11 @@ use Jifty::DBI::Schema;
use Jifty::DBI::Record schema {
column name => type is 'varchar', label is 'Name', is case_sensitive;
column interests => type is 'varchar';
+ column created => type is 'date';
};
+package TestApp::UserCollection;
+use base qw/Jifty::DBI::Collection/;
1;
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list