Switch the main dev branch back to 'master'
[dbsrgits/DBIx-Class.git] / t / storage / nobindvars.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use lib qw(t/lib);
6 use DBICTest;
7
8 { # Fake storage driver for SQLite + no bind variables
9   package DBICTest::SQLite::NoBindVars;
10   use base qw(
11     DBIx::Class::Storage::DBI::NoBindVars
12     DBIx::Class::Storage::DBI::SQLite
13   );
14   use mro 'c3';
15 }
16
17 my $schema = DBICTest->init_schema (storage_type => 'DBICTest::SQLite::NoBindVars', no_populate => 1);
18
19 # test primary key handling
20 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
21 ok($new->artistid, "Auto-PK worked");
22
23 # test LIMIT support
24 for (1..6) {
25     $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
26 }
27 my $it = $schema->resultset('Artist')->search( {},
28     { rows => 3,
29       offset => 2,
30       order_by => 'artistid' }
31 );
32
33 is( $it->count, 3, "LIMIT count ok" );  # ask for 3 rows out of 7 artists
34
35 $schema->is_executed_sql_bind( sub {
36   is( $it->next->name, "Artist 2", "iterator->next ok" );
37   $it->next;
38   $it->next;
39   is( $it->next, undef, "next past end of resultset ok" );
40 }, [
41   [ 'SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me ORDER BY artistid LIMIT 3 OFFSET 2' ],
42 ], 'Correctly interpolated SQL' );
43
44 done_testing;