8 my $schema = DBICTest->init_schema;
11 eval "use DBD::SQLite";
13 ? ( skip_all => 'needs DBD::SQLite for testing' )
17 ### $schema->storage->debug(1);
20 where => \'name like ?',
27 local $TODO = 'bind args order needs fixing (semifor)';
29 # First, the simple cases...
30 $rs = $schema->resultset('Artist')->search(
35 is ( $rs->count, 1, 'where/bind combined' );
37 $rs= $schema->resultset('Artist')->search({}, $where_bind)
38 ->search({ artistid => 1});
40 is ( $rs->count, 1, 'where/bind first' );
42 $rs = $schema->resultset('Artist')->search({ artistid => 1})
43 ->search({}, $where_bind);
45 is ( $rs->count, 1, 'where/bind last' );
48 # More complex cases, based primarily on the Cookbook
49 # "Arbitrary SQL through a custom ResultSource" technique,
50 # which seems to be the only place the bind attribute is
51 # documented. Breaking this technique probably breaks existing
53 my $source = DBICTest::Artist->result_source_instance;
54 my $new_source = $source->new($source);
55 $new_source->source_name('Complex');
57 $new_source->name(\<<'');
58 ( select a.*, cd.cdid as cdid, cd.title as title, cd.year as year
60 join cd on cd.artist=a.artistid
63 $schema->register_extra_source('Complex' => $new_source);
65 $rs = $schema->resultset('Complex')->search({}, { bind => [ 1999 ] });
66 is ( $rs->count, 1, 'cookbook arbitrary sql example' );
68 $rs = $schema->resultset('Complex')->search({ 'artistid' => 1 }, { bind => [ 1999 ] });
69 is ( $rs->count, 1, '...coobook + search condition' );
71 $rs = $schema->resultset('Complex')->search({}, { bind => [ 1999 ] })
72 ->search({ 'artistid' => 1 });
73 is ( $rs->count, 1, '...cookbook (bind first) + chained search' );
76 # not sure what causes an uninit warning here, please remove when the TODO starts to pass,
77 # so the real reason for the warning can be found and fixed
78 local $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /uninitialized/ };
80 local $TODO = 'bind args order needs fixing (semifor)';
81 $rs = $schema->resultset('Complex')->search({}, { bind => [ 1999 ] })
82 ->search({ 'artistid' => 1 }, {
83 where => \'title like ?',
84 bind => [ 'Spoon%' ] });
85 is ( $rs->count, 1, '...cookbook + chained search with extra bind' );