rolling back my last change, waiting until new sqlt is on cpan
[dbsrgits/DBIx-Class.git] / t / 64db.t
CommitLineData
70350518 1use strict;
2use warnings;
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;
34($artist) = $schema->resultset("Artist")->search( artistid => 25 );
0567538f 35is($artist, undef, "Rollback ok");
36
40708af1 37is_deeply (
38 get_storage_column_info ($schema->storage, 'collection'),
39 {
40 collectionid => {
41 data_type => 'INTEGER',
42 is_nullable => 0,
a953d8d9 43 },
40708af1 44 name => {
45 data_type => 'varchar',
46 is_nullable => 0,
93cec8c3 47 },
40708af1 48 },
49 'Correctly retrieve column info (all columns non-nullable)'
50);
51
52TODO: {
53 local $TODO = 'All current versions of SQLite seem to mis-report is_nullable';
54
55 is_deeply (
56 get_storage_column_info ($schema->storage, 'artist'),
57 {
58 'artistid' => {
59 'data_type' => 'INTEGER',
60 'is_nullable' => 0,
61 },
62 'name' => {
63 'data_type' => 'varchar',
64 'is_nullable' => 1,
65 },
66 'rank' => {
67 'data_type' => 'integer',
68 'is_nullable' => 0,
69 },
39da2a2b 70 },
40708af1 71 'Correctly retrieve column info (mixed null and non-null columns)'
72 );
a953d8d9 73};
a953d8d9 74
40708af1 75
76sub get_storage_column_info {
77 my ($storage, $table) = @_;
78
79 my $type_info = $storage->columns_info_for($table);
80
81 # I know this is gross but SQLite reports the size differently from release
82 # to release. At least this way the test still passes.
83 # Also it seems that some SQLite releases report stuff that isn't there as
84 # undef. So strip them out.
85 for my $col (keys %$type_info) {
86 for my $type (keys %{$type_info->{$col}}) {
87 if ($type eq 'size' or not defined $type_info->{$col}{$type} ) {
88 delete $type_info->{$col}{$type};
89 }
90 }
91 }
92
93 return $type_info;
94}