moved tests to compose_namespace instead of compose_connection, marked compose_connec...
[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 base qw/
25         DBIx::Class::Storage::DBI::mysql
26         DBIx::Class::Storage::DBI::NoBindVars
27     /;
28     $INC{'DBIx/Class/Storage/DBI/MySQLNoBindVars.pm'} = 1;
29 }
30
31 DBICTest::Schema->storage(undef); # just in case?
32 DBICTest::Schema->storage_type('::DBI::MySQLNoBindVars');
33 DBICTest::Schema->compose_namespace('MySQLTest' => $dsn, $user, $pass);
34
35 my $dbh = MySQLTest->schema->storage->dbh;
36
37 $dbh->do("DROP TABLE IF EXISTS artist;");
38
39 $dbh->do("CREATE TABLE artist (artistid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), charfield CHAR(10));");
40
41 #'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', '');
42
43 MySQLTest::Artist->load_components('PK::Auto');
44
45 # test primary key handling
46 my $new = MySQLTest::Artist->create({ name => 'foo' });
47 ok($new->artistid, "Auto-PK worked");
48
49 # test LIMIT support
50 for (1..6) {
51     MySQLTest::Artist->create({ name => 'Artist ' . $_ });
52 }
53 my $it = MySQLTest::Artist->search( {},
54     { rows => 3,
55       offset => 2,
56       order_by => 'artistid' }
57 );
58 is( $it->count, 3, "LIMIT count ok" );
59 is( $it->next->name, "Artist 2", "iterator->next ok" );
60 $it->next;
61 $it->next;
62 is( $it->next, undef, "next past end of resultset ok" );
63
64 # clean up our mess
65 $dbh->do("DROP TABLE artist");