Hi,

is C< where > supposed to work with a scalar (or list) reference? If yes,
then it's broken.

Note: The following code is for MySQL.

CREATE TABLE confirmation (
   id         INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
   user       INT UNSIGNED,
              FOREIGN KEY (user) REFERENCES user (id),
   confirm_id VARCHAR(40),
   created    TIMESTAMP,
   INDEX(confirm_id)
);

I would like to query all confirmations that are outdated (older than
2 days), in MySQL this could be

SELECT id FROM confirmation WHERE DATEDIFF( NOW(), created ) > 2;

With DBIC, this works fine if I set some conditions as first param to
C< search >:

my $outdated = $c->model('DBIC::Confirmation')->search(
     $condition,
     { where => \'DATEDIFF( NOW(), created ) > 2' }
);

But if C< $condition > is undef, then DBIC complains:

my $outdated = $c->model('DBIC::Confirmation')->search(
     undef,
     { where => \'DATEDIFF( NOW(), created ) > 2' }
);

Modification of a read-only value attempted at
/usr/local/share/perl/5.8.8/DBIx/Class/Storage/DBI.pm line 812.

A simpler testcase for the DBIC testsuite is attached.


Thanks, Frank
use strict;
use warnings;  

use Test::More;
use lib qw(t/lib);
use DBICTest;

my $schema = DBICTest->init_schema();

BEGIN {
    eval "use DBD::SQLite";
    plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 3);
}                                                                               

# test where attribut
my $it = $schema->resultset("CD")->search(
    { title => { like => '%bees%' } },
    { where => \'artist = cdid' }
);
is( $it->count, 1, '$cond and where with scalarref' );

$it = $schema->resultset("CD")->search(
    undef,
    { where => \'artist = cdid' }
);
is( $it->count, 1, 'no $cond and where with scalarref' );

$it = $schema->resultset("CD")->search(
    undef,
    { where => ['artist = cdid'] }
);
is( $it->count, 1, 'no $cond and where with list' );

_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to