Fix pesky on_connect_* race condition abraxxa++ ilmari++
[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 use DBIC::DebugObj;
8 use DBIC::SqlMakerTest;
9 use DBI::Const::GetInfoType;
10
11 { # Fake storage driver for SQLite + no bind variables
12   package DBICTest::SQLite::NoBindVars;
13     use Class::C3;
14     use base qw/
15         DBIx::Class::Storage::DBI::NoBindVars
16         DBIx::Class::Storage::DBI::SQLite
17     /;
18 }
19
20 my $schema = DBICTest->init_schema (storage_type => 'DBICTest::SQLite::NoBindVars', no_populate => 1);
21
22 # test primary key handling
23 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
24 ok($new->artistid, "Auto-PK worked");
25
26 # test LIMIT support
27 for (1..6) {
28     $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
29 }
30 my $it = $schema->resultset('Artist')->search( {},
31     { rows => 3,
32       offset => 2,
33       order_by => 'artistid' }
34 );
35
36 is( $it->count, 3, "LIMIT count ok" );  # ask for 3 rows out of 7 artists
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
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
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 );
59
60 done_testing;