Fix multiple storage regressions from 52416317
[dbsrgits/DBIx-Class.git] / t / 93nobindvars.t
CommitLineData
d5130dd2 1use strict;
68de9438 2use warnings;
d5130dd2 3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7use DBI::Const::GetInfoType;
8
9my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/};
10
11#warn "$dsn $user $pass";
12
13plan skip_all => 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test'
14 unless ($dsn && $user);
15
d5130dd2 16{ # Fake storage driver for mysql + no bind variables
17 package DBIx::Class::Storage::DBI::MySQLNoBindVars;
d944c5ae 18 use Class::C3;
d5130dd2 19 use base qw/
d5130dd2 20 DBIx::Class::Storage::DBI::NoBindVars
d944c5ae 21 DBIx::Class::Storage::DBI::mysql
d5130dd2 22 /;
23 $INC{'DBIx/Class/Storage/DBI/MySQLNoBindVars.pm'} = 1;
24}
25
d944c5ae 26# XXX Class::C3 doesn't like some of the Storage stuff happening late...
27Class::C3::reinitialize();
28
3ff5b740 29my $schema = DBICTest::Schema->clone;
30$schema->storage_type('::DBI::MySQLNoBindVars');
31$schema->connection($dsn, $user, $pass);
d5130dd2 32
3ff5b740 33my $dbh = $schema->storage->dbh;
d5130dd2 34
35$dbh->do("DROP TABLE IF EXISTS artist;");
36
a0dd8679 37$dbh->do("CREATE TABLE artist (artistid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), rank INTEGER NOT NULL DEFAULT '13', charfield CHAR(10));");
d5130dd2 38
3ff5b740 39$schema->class('Artist')->load_components('PK::Auto');
d5130dd2 40
41# test primary key handling
3ff5b740 42my $new = $schema->resultset('Artist')->create({ name => 'foo' });
d5130dd2 43ok($new->artistid, "Auto-PK worked");
44
45# test LIMIT support
46for (1..6) {
3ff5b740 47 $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
d5130dd2 48}
3ff5b740 49my $it = $schema->resultset('Artist')->search( {},
d5130dd2 50 { rows => 3,
51 offset => 2,
52 order_by => 'artistid' }
53);
fb4b58e8 54is( $it->count, 3, "LIMIT count ok" ); # ask for 3 rows out of 7 artists
d5130dd2 55is( $it->next->name, "Artist 2", "iterator->next ok" );
56$it->next;
57$it->next;
58is( $it->next, undef, "next past end of resultset ok" );
59
60# clean up our mess
3ff5b740 61END {
3a4c1d89 62 my $dbh = eval { $schema->storage->_dbh };
cd99a557 63 $dbh->do("DROP TABLE artist") if $dbh;
3ff5b740 64}
68de9438 65
66done_testing;