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