Commit | Line | Data |
70350518 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
0567538f |
7 | |
8 | my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}; |
9 | |
10 | #warn "$dsn $user $pass"; |
11 | |
70350518 |
12 | plan skip_all => 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test' |
0567538f |
13 | unless ($dsn && $user); |
14 | |
a953d8d9 |
15 | plan tests => 5; |
0567538f |
16 | |
70fe6d6e |
17 | DBICTest::Schema->compose_connection('MySQLTest' => $dsn, $user, $pass); |
0567538f |
18 | |
a953d8d9 |
19 | my $dbh = MySQLTest->schema->storage->dbh; |
0567538f |
20 | |
21 | $dbh->do("DROP TABLE IF EXISTS artist;"); |
22 | |
103e3e03 |
23 | $dbh->do("CREATE TABLE artist (artistid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), charfield CHAR(10));"); |
0567538f |
24 | |
25 | #'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', ''); |
26 | |
843f8ecd |
27 | MySQLTest::Artist->load_components('PK::Auto'); |
0567538f |
28 | |
29 | # test primary key handling |
30 | my $new = MySQLTest::Artist->create({ name => 'foo' }); |
31 | ok($new->artistid, "Auto-PK worked"); |
32 | |
33 | # test LIMIT support |
34 | for (1..6) { |
35 | MySQLTest::Artist->create({ name => 'Artist ' . $_ }); |
36 | } |
37 | my $it = MySQLTest::Artist->search( {}, |
38 | { rows => 3, |
39 | offset => 2, |
40 | order_by => 'artistid' } |
41 | ); |
42 | is( $it->count, 3, "LIMIT count ok" ); |
43 | is( $it->next->name, "Artist 2", "iterator->next ok" ); |
44 | $it->next; |
45 | $it->next; |
46 | is( $it->next, undef, "next past end of resultset ok" ); |
47 | |
a953d8d9 |
48 | my $test_type_info = { |
49 | 'artistid' => { |
103e3e03 |
50 | 'data_type' => 'INT', |
51 | 'is_nullable' => 0, |
fc22fbac |
52 | 'size' => 11, |
53 | 'default_value' => undef, |
a953d8d9 |
54 | }, |
55 | 'name' => { |
103e3e03 |
56 | 'data_type' => 'VARCHAR', |
a953d8d9 |
57 | 'is_nullable' => 1, |
fc22fbac |
58 | 'size' => 255, |
59 | 'default_value' => undef, |
103e3e03 |
60 | }, |
61 | 'charfield' => { |
62 | 'data_type' => 'VARCHAR', |
63 | 'is_nullable' => 1, |
fc22fbac |
64 | 'size' => 10, |
65 | 'default_value' => undef, |
103e3e03 |
66 | }, |
a953d8d9 |
67 | }; |
68 | |
69 | |
faa78b0b |
70 | my $type_info = MySQLTest->schema->storage->columns_info_for('artist'); |
a953d8d9 |
71 | is_deeply($type_info, $test_type_info, 'columns_info_for - column data types'); |
72 | |
73 | |
74 | |
0567538f |
75 | # clean up our mess |
76 | $dbh->do("DROP TABLE artist"); |
77 | |