Commit | Line | Data |
d5130dd2 |
1 | use strict; |
68de9438 |
2 | use warnings; |
d5130dd2 |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
6e6ad6c3 |
7 | use DBIC::DebugObj; |
8 | use DBIC::SqlMakerTest; |
d5130dd2 |
9 | use DBI::Const::GetInfoType; |
10 | |
6e6ad6c3 |
11 | { # Fake storage driver for SQLite + no bind variables |
12 | package DBICTest::SQLite::NoBindVars; |
d944c5ae |
13 | use Class::C3; |
d5130dd2 |
14 | use base qw/ |
d5130dd2 |
15 | DBIx::Class::Storage::DBI::NoBindVars |
6e6ad6c3 |
16 | DBIx::Class::Storage::DBI::SQLite |
d5130dd2 |
17 | /; |
d5130dd2 |
18 | } |
19 | |
6e6ad6c3 |
20 | my $schema = DBICTest->init_schema (storage_type => 'DBICTest::SQLite::NoBindVars', no_populate => 1); |
d5130dd2 |
21 | |
22 | # test primary key handling |
3ff5b740 |
23 | my $new = $schema->resultset('Artist')->create({ name => 'foo' }); |
d5130dd2 |
24 | ok($new->artistid, "Auto-PK worked"); |
25 | |
26 | # test LIMIT support |
27 | for (1..6) { |
3ff5b740 |
28 | $schema->resultset('Artist')->create({ name => 'Artist ' . $_ }); |
d5130dd2 |
29 | } |
3ff5b740 |
30 | my $it = $schema->resultset('Artist')->search( {}, |
d5130dd2 |
31 | { rows => 3, |
32 | offset => 2, |
33 | order_by => 'artistid' } |
34 | ); |
6e6ad6c3 |
35 | |
fb4b58e8 |
36 | is( $it->count, 3, "LIMIT count ok" ); # ask for 3 rows out of 7 artists |
6e6ad6c3 |
37 | |
38 | my ($sql, @bind); |
39 | my $orig_debugobj = $schema->storage->debugobj; |
40 | my $orig_debug = $schema->storage->debug; |
41 | $schema->storage->debugobj (DBIC::DebugObj->new (\$sql, \@bind) ); |
42 | $schema->storage->debug (1); |
43 | |
d5130dd2 |
44 | is( $it->next->name, "Artist 2", "iterator->next ok" ); |
45 | $it->next; |
46 | $it->next; |
47 | is( $it->next, undef, "next past end of resultset ok" ); |
48 | |
6e6ad6c3 |
49 | $schema->storage->debugobj ($orig_debugobj); |
50 | $schema->storage->debug ($orig_debug); |
51 | |
52 | is_same_sql_bind ( |
53 | $sql, |
54 | \@bind, |
55 | 'SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me ORDER BY artistid LIMIT 3 OFFSET 2', |
56 | [], |
57 | 'Correctly interpolated SQL' |
58 | ); |
68de9438 |
59 | |
60 | done_testing; |