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