Added MySQL LIMIT tests
[dbsrgits/DBIx-Class.git] / t / 11mysql.t
CommitLineData
08aa0414 1use lib qw(lib t/lib);
2use DBICTest::Schema;
3
4use Test::More;
5
6my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/};
7
cba994a1 8#warn "$dsn $user $pass";
08aa0414 9
10plan skip_all, 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test'
11 unless ($dsn && $user);
12
13plan tests => 1;
14
15DBICTest::Schema->compose_connection('MySQLTest' => $dsn, $user, $pass);
16
17my $dbh = MySQLTest::Artist->storage->dbh;
18
19$dbh->do("DROP TABLE IF EXISTS artist;");
20
21$dbh->do("CREATE TABLE artist (artistid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255));");
22
23#'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', '');
24
25MySQLTest::Artist->load_components('PK::Auto::MySQL');
26
502784de 27# test primary key handling
08aa0414 28my $new = MySQLTest::Artist->create({ name => 'foo' });
08aa0414 29ok($new->artistid, "Auto-PK worked");
30
502784de 31# test LIMIT support
32for (1..6) {
33 MySQLTest::Artist->create({ name => 'Artist ' . $_ });
34}
35my $it = MySQLTest::Artist->search( {},
36 { rows => 3,
37 offset => 2,
38 order_by => 'artistid' }
39);
40is( $it->count, 3, "LIMIT count ok" );
41is( $it->next->name, "Artist 2", "iterator->next ok" );
42$it->next;
43$it->next;
44is( $it->next, undef, "next past end of resultset ok" );
45
46# clean up our mess
47$dbh->do("DROP TABLE artist");
48
08aa0414 491;