On Tue, May 28, 2013 at 5:07 AM, Peter Rabbitson <rabbit+d...@rabbit.us>wrote:

> On Mon, May 27, 2013 at 04:15:08PM -0700, Bill Moseley wrote:
> > I have created a partial index in Postgresql using lower() on a column
> name
> > so I need to use that in my query to make use of the index.
> >
> > The Cookbook<
> http://search.cpan.org/~ribasushi/DBIx-Class-0.08250/lib/DBIx/Class/Manual/Cookbook.pod#Using_SQL_functions_on_the_left_hand_side_of_a_comparison
> >discusses
> > this usage.    But, I also need to identify the bind parameter.
> >
> > Is this the correct syntax for the bind value?
> >
> > my $rs = $schema->resultset( 'User' )->search(
> >     \['lower( first_name ) like ?', [{ dbic_colname => 'first_name' },
> > "$query%"]],
> > );
>
> No it isn't. You have an extra set of []s in there. The "litral with
> bind" syntax is defined thus:
>
> \[ $sql_portion, $bind1, $bind2, $bind3,... ]
>

Ok, I'm confused by the docs, I guess.  They say:

Each bind value should be composed of an arrayref of [ \%args => $val ].
> The format of \%args is currently:


So, my arrayref is:

[{ dbic_colname => 'first_name' }, "$query%"]],


Oh, maybe it should just be this short-cut version?

\['lower( first_name ) like ?', [ first_name => "$query%"]],


They both seem to generate this WHERE:

WHERE ( lower( first_name ) like ? ): 'foo%'


>
> > Second, what is the correct way to escape $query?
>
> There currently is no canned solution for this. The feature is blocked
> due to the unavailability of a way to mark some nodes as a specific
> dialect of SQL (per engine). In other words this is something which will
> take place post-Data::Query.
>

Ok, then I'll just try and filter the query on input.


Thanks,


-- 
Bill Moseley
mose...@hank.org
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk

Reply via email to