Commit | Line | Data |
70350518 |
1 | use strict; |
ddf66ced |
2 | use warnings; |
70350518 |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
5db49b9a |
7 | use DBI::Const::GetInfoType; |
adb3554a |
8 | use DBICTest::Stats; |
0567538f |
9 | |
10 | my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}; |
11 | |
12 | #warn "$dsn $user $pass"; |
13 | |
70350518 |
14 | plan skip_all => 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test' |
0567538f |
15 | unless ($dsn && $user); |
16 | |
ddf66ced |
17 | plan tests => 7; |
0567538f |
18 | |
3ff5b740 |
19 | my $schema = DBICTest::Schema->connect($dsn, $user, $pass); |
0567538f |
20 | |
3ff5b740 |
21 | my $dbh = $schema->storage->dbh; |
adb3554a |
22 | my $stats = new DBICTest::Stats(); |
23 | $schema->storage->debugobj($stats); |
24 | $schema->storage->debug(1); |
0567538f |
25 | |
26 | $dbh->do("DROP TABLE IF EXISTS artist;"); |
27 | |
adb3554a |
28 | $dbh->do("CREATE TABLE artist (artistid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), charfield CHAR(10)) ENGINE=InnoDB;"); |
0567538f |
29 | |
30 | #'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', ''); |
31 | |
3ff5b740 |
32 | # This is in Core now, but it's here just to test that it doesn't break |
33 | $schema->class('Artist')->load_components('PK::Auto'); |
0567538f |
34 | |
35 | # test primary key handling |
3ff5b740 |
36 | my $new = $schema->resultset('Artist')->create({ name => 'foo' }); |
0567538f |
37 | ok($new->artistid, "Auto-PK worked"); |
38 | |
39 | # test LIMIT support |
40 | for (1..6) { |
3ff5b740 |
41 | $schema->resultset('Artist')->create({ name => 'Artist ' . $_ }); |
0567538f |
42 | } |
3ff5b740 |
43 | my $it = $schema->resultset('Artist')->search( {}, |
0567538f |
44 | { rows => 3, |
45 | offset => 2, |
46 | order_by => 'artistid' } |
47 | ); |
48 | is( $it->count, 3, "LIMIT count ok" ); |
49 | is( $it->next->name, "Artist 2", "iterator->next ok" ); |
50 | $it->next; |
51 | $it->next; |
52 | is( $it->next, undef, "next past end of resultset ok" ); |
53 | |
a953d8d9 |
54 | my $test_type_info = { |
55 | 'artistid' => { |
103e3e03 |
56 | 'data_type' => 'INT', |
57 | 'is_nullable' => 0, |
fc22fbac |
58 | 'size' => 11, |
59 | 'default_value' => undef, |
a953d8d9 |
60 | }, |
61 | 'name' => { |
103e3e03 |
62 | 'data_type' => 'VARCHAR', |
a953d8d9 |
63 | 'is_nullable' => 1, |
fc22fbac |
64 | 'size' => 255, |
65 | 'default_value' => undef, |
103e3e03 |
66 | }, |
67 | 'charfield' => { |
637219ab |
68 | 'data_type' => 'CHAR', |
103e3e03 |
69 | 'is_nullable' => 1, |
fc22fbac |
70 | 'size' => 10, |
71 | 'default_value' => undef, |
103e3e03 |
72 | }, |
a953d8d9 |
73 | }; |
74 | |
ddf66ced |
75 | $schema->txn_begin; |
adb3554a |
76 | |
77 | my $arty = $schema->resultset('Artist')->find(1); |
78 | |
ddf66ced |
79 | my $name = $arty->name; |
adb3554a |
80 | |
ddf66ced |
81 | $schema->storage->_svp_begin ("mysavepoint"); |
adb3554a |
82 | |
83 | $arty->update({ name => 'Jheephizzy' }); |
84 | |
ddf66ced |
85 | $arty->discard_changes; |
adb3554a |
86 | |
ddf66ced |
87 | cmp_ok($arty->name, 'eq', 'Jheephizzy', 'Name changed'); |
adb3554a |
88 | |
ddf66ced |
89 | $schema->storage->_svp_rollback ("mysavepoint"); |
adb3554a |
90 | |
ddf66ced |
91 | $arty->discard_changes; |
adb3554a |
92 | |
ddf66ced |
93 | cmp_ok($arty->name, 'eq', $name, 'Name rolled back'); |
adb3554a |
94 | |
ddf66ced |
95 | $schema->txn_commit; |
adb3554a |
96 | |
5db49b9a |
97 | SKIP: { |
98 | my $mysql_version = $dbh->get_info( $GetInfoType{SQL_DBMS_VER} ); |
5db49b9a |
99 | skip "Cannot determine MySQL server version", 1 if !$mysql_version; |
a953d8d9 |
100 | |
f750163c |
101 | my ($v1, $v2, $v3) = $mysql_version =~ /^(\d+)\.(\d+)(?:\.(\d+))?/; |
102 | skip "Cannot determine MySQL server version", 1 if !$v1 || !defined($v2); |
103 | |
104 | $v3 ||= 0; |
105 | |
5db49b9a |
106 | if( ($v1 < 5) || ($v1 == 5 && $v2 == 0 && $v3 <= 3) ) { |
107 | $test_type_info->{charfield}->{data_type} = 'VARCHAR'; |
108 | } |
a953d8d9 |
109 | |
3ff5b740 |
110 | my $type_info = $schema->storage->columns_info_for('artist'); |
5db49b9a |
111 | is_deeply($type_info, $test_type_info, 'columns_info_for - column data types'); |
112 | } |
a953d8d9 |
113 | |
0567538f |
114 | # clean up our mess |
3ff5b740 |
115 | END { |
116 | $dbh->do("DROP TABLE artist") if $dbh; |
117 | } |