Commit | Line | Data |
c0329273 |
1 | BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } |
2 | |
70350518 |
3 | use strict; |
b9df8e39 |
4 | use warnings; |
70350518 |
5 | |
6 | use Test::More; |
c0329273 |
7 | |
70350518 |
8 | use DBICTest; |
9 | |
a47e1233 |
10 | my $schema = DBICTest->init_schema(); |
70350518 |
11 | |
40708af1 |
12 | plan tests => 4; |
0567538f |
13 | |
14 | # add some rows inside a transaction and commit it |
15 | # XXX: Is storage->dbh the only way to get a dbh? |
f9db5527 |
16 | $schema->storage->txn_begin; |
0567538f |
17 | for (10..15) { |
8273e845 |
18 | $schema->resultset("Artist")->create( { |
0567538f |
19 | artistid => $_, |
20 | name => "artist number $_", |
21 | } ); |
22 | } |
f9db5527 |
23 | $schema->storage->txn_commit; |
24 | my ($artist) = $schema->resultset("Artist")->find(15); |
0567538f |
25 | is($artist->name, 'artist number 15', "Commit ok"); |
26 | |
0567538f |
27 | # add some rows inside a transaction and roll it back |
f9db5527 |
28 | $schema->storage->txn_begin; |
0567538f |
29 | for (21..30) { |
f9db5527 |
30 | $schema->resultset("Artist")->create( { |
0567538f |
31 | artistid => $_, |
32 | name => "artist number $_", |
33 | } ); |
34 | } |
f9db5527 |
35 | $schema->storage->txn_rollback; |
450e6dbf |
36 | ($artist) = $schema->resultset("Artist")->search({ artistid => 25 }); |
0567538f |
37 | is($artist, undef, "Rollback ok"); |
38 | |
40708af1 |
39 | is_deeply ( |
a7b99956 |
40 | get_storage_column_info ($schema->storage, 'collection', qw/size is_nullable/), |
40708af1 |
41 | { |
42 | collectionid => { |
43 | data_type => 'INTEGER', |
a953d8d9 |
44 | }, |
40708af1 |
45 | name => { |
46 | data_type => 'varchar', |
93cec8c3 |
47 | }, |
40708af1 |
48 | }, |
a7b99956 |
49 | 'Correctly retrieve column info (no size or is_nullable)' |
40708af1 |
50 | ); |
51 | |
b9df8e39 |
52 | { |
40708af1 |
53 | is_deeply ( |
a7b99956 |
54 | get_storage_column_info ($schema->storage, 'artist', qw/size/), |
40708af1 |
55 | { |
56 | 'artistid' => { |
57 | 'data_type' => 'INTEGER', |
58 | 'is_nullable' => 0, |
59 | }, |
60 | 'name' => { |
61 | 'data_type' => 'varchar', |
62 | 'is_nullable' => 1, |
63 | }, |
64 | 'rank' => { |
65 | 'data_type' => 'integer', |
66 | 'is_nullable' => 0, |
f45dc928 |
67 | DBIx::Class::_ENV_::STRESSTEST_COLUMN_INFO_UNAWARE_STORAGE ? () : ( 'default_value' => '13' ), |
aab0d3b7 |
68 | }, |
69 | 'charfield' => { |
70 | 'data_type' => 'char', |
71 | 'is_nullable' => 1, |
40708af1 |
72 | }, |
39da2a2b |
73 | }, |
40708af1 |
74 | 'Correctly retrieve column info (mixed null and non-null columns)' |
75 | ); |
a953d8d9 |
76 | }; |
a953d8d9 |
77 | |
40708af1 |
78 | |
a7b99956 |
79 | # Depending on test we need to strip away certain column info. |
80 | # - SQLite is known to report the size differently from release to release |
81 | # - Current DBD::SQLite versions do not implement NULLABLE |
82 | # - Some SQLite releases report stuff that isn't there as undef |
83 | |
40708af1 |
84 | sub get_storage_column_info { |
a7b99956 |
85 | my ($storage, $table, @ignore) = @_; |
40708af1 |
86 | |
87 | my $type_info = $storage->columns_info_for($table); |
88 | |
40708af1 |
89 | for my $col (keys %$type_info) { |
90 | for my $type (keys %{$type_info->{$col}}) { |
a7b99956 |
91 | if ( |
92 | grep { $type eq $_ } (@ignore) |
93 | or |
94 | not defined $type_info->{$col}{$type} |
95 | ) { |
40708af1 |
96 | delete $type_info->{$col}{$type}; |
97 | } |
98 | } |
99 | } |
100 | |
101 | return $type_info; |
102 | } |