Skip to content

Commit

Permalink
removed usage of plain_value bind value workaround in the cookbook
Browse files Browse the repository at this point in the history
  • Loading branch information
abraxxa authored and ribasushi committed Apr 6, 2013
1 parent b81bf85 commit ac09a39
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
15 changes: 6 additions & 9 deletions lib/DBIx/Class/Manual/Cookbook.pod
Original file line number Diff line number Diff line change
Expand Up @@ -421,26 +421,23 @@ you create an index on the return value of the function in question.) However,
it can be accomplished with C<DBIx::Class> when necessary by resorting to
literal SQL:

$rs->search(\[ 'YEAR(date_of_birth) = ?', [ plain_value => 1979 ] ]);
$rs->search(
\[ 'YEAR(date_of_birth) = ?', 1979 ]
);

# Equivalent SQL:
# SELECT * FROM employee WHERE YEAR(date_of_birth) = ?

$rs->search({ -and => [
name => 'Bob',
\[ 'YEAR(date_of_birth) = ?', [ plain_value => 1979 ] ],
\[ 'YEAR(date_of_birth) = ?', 1979 ]
]});

# Equivalent SQL:
# SELECT * FROM employee WHERE name = ? AND YEAR(date_of_birth) = ?

Note: the C<plain_value> string in the C<< [ plain_value => 1979 ] >> part
should be either the same as the name of the column (do this if the type of the
return value of the function is the same as the type of the column) or in the
case of a function it's currently treated as a dummy string (it is a good idea
to use C<plain_value> or something similar to convey intent). The value is
currently only significant when handling special column types (BLOBs, arrays,
etc.), but this may change in the future.
Note: the syntax for specifying the bind value's datatype and value is
explained in L<DBIx::Class::ResultSet/DBIC BIND VALUES>.

See also L<SQL::Abstract/Literal SQL with placeholders and bind values
(subqueries)>.
Expand Down
10 changes: 1 addition & 9 deletions lib/DBIx/Class/Manual/FAQ.pod
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,7 @@ documentation for details.
To use an SQL function on the left hand side of a comparison you currently need
to resort to literal SQL:

->search( \[ 'YEAR(date_of_birth) = ?', [ plain_value => 1979 ] ] );

Note: the C<plain_value> string in the C<< [ plain_value => 1979 ] >> part
should be either the same as the name of the column (do this if the type of the
return value of the function is the same as the type of the column) or in the
case of a function it's currently treated as a dummy string (it is a good idea
to use C<plain_value> or something similar to convey intent). The value is
currently only significant when handling special column types (BLOBs, arrays,
etc.), but this may change in the future.
->search( \[ 'YEAR(date_of_birth) = ?', 1979 ] );

=item .. find more help on constructing searches?

Expand Down

0 comments on commit ac09a39

Please sign in to comment.