From: Nigel Metheringham Date: Tue, 29 Jun 2010 14:09:36 +0000 (+0000) Subject: Improvements to where clause docs for undef/NULL - tackling RT Bug #58490 X-Git-Tag: v1.70~94 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b864ba9b6dc3aa439d85736c3d966a0434212b16;p=dbsrgits%2FSQL-Abstract.git Improvements to where clause docs for undef/NULL - tackling RT Bug #58490 --- diff --git a/Changes b/Changes index c8dade1..5a23757 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for SQL::Abstract +revision 1.68 work in progress +---------------------------- + - Better documentation of undef/NULL in where clause + revision 1.67 2010-05-31 14:21 (UTC) ---------------------------- - Fix SQL::Test failure when first chunk is an unrecognized diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 265d5f0..ee6aca7 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -1900,6 +1900,20 @@ This simple code will create the following: A field associated to an empty arrayref will be considered a logical false and will generate 0=1. +=head2 Tests for NULL values + +If the value part is C then this is converted to SQL + + my %where = ( + user => 'nwiger', + status => undef, + ); + +becomes: + + $stmt = "WHERE user = ? AND status IS NULL"; + @bind = ('nwiger'); + =head2 Specific comparison operators If you want to specify a different type of operator for your comparison, @@ -2261,6 +2275,17 @@ which yields $stmt = "WHERE priority < ? AND is_ready"; @bind = ('2'); +Literal SQL is also the only way to compare 2 columns to one another: + + my %where = ( + priority => { '<', 2 }, + requestor => \'= submittor' + ); + +which creates: + + $stmt = "WHERE priority < ? AND requestor = submitter"; + @bind = ('2'); =head2 Literal SQL with placeholders and bind values (subqueries) @@ -2584,6 +2609,12 @@ the same structure, you only have to generate the SQL the first time around. On subsequent queries, simply use the C function provided by this module to return your values in the correct order. +However this depends on the values having the same type - if, for +example, the values of a where clause may either have values +(resulting in sql of the form C with a single bind +value), or alternatively the values might be C (resulting in +sql of the form C with no bind value) then the +caching technique suggested will not work. =head1 FORMBUILDER