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