Hi,

I am having problem putting together a DBIx::Class query that uses a mysql-function in the where-clause.

Here is my resultset:

package MyDB::Schema::Result::Queue; use strict; use base qw/DBIx::Class::Core/; __PACKAGE__->table('queue'); __PACKAGE__->add_columns( id => { is_auto_increment => 1}, qw/ msg box /); __PACKAGE__->set_primary_key('id'); 1;
The query I want to (re-)construct is select id, msg, box from queue where is_lock_free(box) order by id limit 1

The best I can get at the moment is

my $rs = $schema->resultset('Queue'); my $q = $rs->search ({ -bool => "is_free_lock(me.box)" }, { order_by = +> 'id', rows => 1 })->single;
Which produces SELECT me.id, me.msg, me.box FROM queue me WHERE ( is_free_lock(me.box) ) ORDER BY id LIMIT 1 which actually works but of course is obtained by cheating because I supplied the me.box argument to is_lock_free by hand...

How can I do this without cheating?

Many thanks!


In reply to DBIx::Class query question by morgon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.