bigpresh / Dancer-Plugin-Database

Dancer::Plugin::Database - easy database support for Dancer applications
http://search.cpan.org/dist/Dancer-Plugin-Database
37 stars 36 forks source link

Tests failed on negated "is" #15

Closed bigpresh closed 12 years ago

bigpresh commented 12 years ago

Installing D::P::D on a VPS, testing failed with the following error:

DBD::SQLite::db selectrow_hashref failed: near "?": syntax error at /home/dave/.cpanm/work/1321562359.11167/Dancer-Plugin-Database-1.50/blib/lib/Dancer/Plugin/Database/Handle.pm line 266.

#   Failed test 'Complex not where clause succeeded'
#   at t/01-basic.t line 60.
#                   'No matching user'
#     doesn't match 'Markus Kögler <mytestarea@googlemail.com>(?-xism:sukria)'
# Looks like you failed 1 test of 26.

This test passes fine on my normal development box, and there's no failure reports on cpantesters.

t/01-basic.t line 60 calls GET => '/complex_not/42' from the test app, which is:

87 get '/complex_not/:id' => sub {
88     my $row = database->quick_select('users', { category => { 'is' => undef, 'not' => 1 } });

Looking at _where_sql(), given those params, I'd expect this special case to fire:

return ' IS NOT ?' if ( $op eq 'is' && $not );

Given undef, it will be turned into the literal string 'NULL' in the bind params, so you'd get a query like: "SELECT * FROM users WHERE category IS NOT ?", with NULL as a bind param.

That's where the issue is, I think; _get_where_sql() needs to be able to return "IS NULL" or "IS NOT NULL" if given an undef value, and also indicate that no extra bind param should be added.

This will require a little refactoring.

bigpresh commented 12 years ago

Fixed in 1.51