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