From: Mike Baas Date: Fri, 29 Oct 2010 02:55:49 +0000 (-0500) Subject: Add notes about handling of inflated objects in resultset conditions X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0ac0af6c62637a5fdb06ecfb8ba4b60f93bf9d75;p=dbsrgits%2FDBIx-Class-Historic.git Add notes about handling of inflated objects in resultset conditions --- diff --git a/lib/DBIx/Class.pm b/lib/DBIx/Class.pm index b32efe4..3b71596 100644 --- a/lib/DBIx/Class.pm +++ b/lib/DBIx/Class.pm @@ -295,6 +295,8 @@ hobbs: Andrew Rodland ilmari: Dagfinn Ilmari MannsEker +initself: Mike Baas + jasonmay: Jason May jesper: Jesper Krogh diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index 3c08004..6bbd343 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -1731,8 +1731,41 @@ See L and L for more explanation. Note that L sets L to C, so you must pass the bind values (the C<[1, 2, 3]> arrayref in the above example) wrapped in -arrayrefs together with the column name, like this: C<< [column_name => value] ->>. +arrayrefs together with the column name, like this: +C<< [column_name => value] >>. + +=head2 Formatting DateTime objects in queries + +To ensure C conditions containing L arguments are properly +formatted to be understood by your RDBMS, you must use the C +formatter returned by L to format +any L objects you pass to L +conditions. Any L object attached to your +L provides a correct C formatter, so +all you have to do is: + + my $dtf = $schema->storage->datetime_parser; + my $rs = $schema->resultset('users')->search( + { + signup_date => { + -between => [ + $dtf->format_datetime($dt_start), + $dtf->format_datetime($dt_end), + ], + } + }, + ); + +Without doing this the query will contain the simple stringification of the +C object, which almost never matches the RDBMS expectations. + +This kludge is necessary only for conditions passed to +L, whereas +L, +L, +L (but not L) are all +L-aware and will do the right thing when supplied +an inflated C object. =head2 Using Unicode diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 46ac2d1..36647ed 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -245,6 +245,16 @@ documentation for the first argument, see L. For more help on using joins with search, see L. +=head3 CAVEAT + +Note that L does not process/deflate any of the values passed in the +L-compatible search condition structure. This is unlike other +condition-bound methods L, L and L. The user must ensure +manually that any value passed to this method will stringify to something the +RDBMS knows how to deal with. A notable example is the handling of L +objects, for more info see: +L. + =cut sub search { @@ -1511,6 +1521,15 @@ The return value is a pass through of what the underlying storage backend returned, and may vary. See L for the most common case. +=head3 CAVEAT + +Note that L does not process/deflate any of the values passed in. +This is unlike the corresponding L. The user must +ensure manually that any value passed to this method will stringify to +something the RDBMS knows how to deal with. A notable example is the +handling of L objects, for more info see: +L. + =cut sub update {