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