Commit | Line | Data |
f200d74b |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use Test::Exception; |
6 | use lib qw(t/lib); |
7 | use DBICTest; |
8 | |
b341186f |
9 | # tests stolen from 748informix.t |
f200d74b |
10 | |
cf7b6654 |
11 | my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_ASA_${_}" } qw/DSN USER PASS/}; |
12 | my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_SYBASE_ASA_ODBC_${_}" } qw/DSN USER PASS/}; |
f200d74b |
13 | |
8ebb1b58 |
14 | plan skip_all => <<'EOF' unless $dsn || $dsn2; |
cf7b6654 |
15 | Set $ENV{DBICTEST_SYBASE_ASA_DSN} and/or $ENV{DBICTEST_SYBASE_ASA_ODBC_DSN}, |
16 | _USER and _PASS to run these tests |
17 | EOF |
18 | |
19 | my @info = ( |
20 | [ $dsn, $user, $pass ], |
21 | [ $dsn2, $user2, $pass2 ], |
22 | ); |
23 | |
24 | my @handles_to_clean; |
f200d74b |
25 | |
cf7b6654 |
26 | foreach my $info (@info) { |
27 | my ($dsn, $user, $pass) = @$info; |
f200d74b |
28 | |
cf7b6654 |
29 | next unless $dsn; |
f200d74b |
30 | |
cf7b6654 |
31 | my $schema = DBICTest::Schema->connect($dsn, $user, $pass); |
f200d74b |
32 | |
cf7b6654 |
33 | my $dbh = $schema->storage->dbh; |
34 | |
35 | push @handles_to_clean, $dbh; |
36 | |
37 | eval { $dbh->do("DROP TABLE artist") }; |
38 | |
39 | $dbh->do(<<EOF); |
40 | CREATE TABLE artist ( |
41 | artistid INT IDENTITY PRIMARY KEY, |
42 | name VARCHAR(255) NULL, |
43 | charfield CHAR(10) NULL, |
44 | rank INT DEFAULT 13 |
45 | ) |
ed720bc5 |
46 | EOF |
f200d74b |
47 | |
cf7b6654 |
48 | my $ars = $schema->resultset('Artist'); |
49 | is ( $ars->count, 0, 'No rows at first' ); |
f200d74b |
50 | |
51 | # test primary key handling |
cf7b6654 |
52 | my $new = $ars->create({ name => 'foo' }); |
53 | ok($new->artistid, "Auto-PK worked"); |
f200d74b |
54 | |
55 | # test explicit key spec |
cf7b6654 |
56 | $new = $ars->create ({ name => 'bar', artistid => 66 }); |
57 | is($new->artistid, 66, 'Explicit PK worked'); |
58 | $new->discard_changes; |
59 | is($new->artistid, 66, 'Explicit PK assigned'); |
f200d74b |
60 | |
61 | # test populate |
cf7b6654 |
62 | lives_ok (sub { |
63 | my @pop; |
64 | for (1..2) { |
65 | push @pop, { name => "Artist_$_" }; |
66 | } |
67 | $ars->populate (\@pop); |
68 | }); |
f200d74b |
69 | |
70 | # test populate with explicit key |
cf7b6654 |
71 | lives_ok (sub { |
72 | my @pop; |
73 | for (1..2) { |
74 | push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ }; |
75 | } |
76 | $ars->populate (\@pop); |
77 | }); |
f200d74b |
78 | |
79 | # count what we did so far |
cf7b6654 |
80 | is ($ars->count, 6, 'Simple count works'); |
f200d74b |
81 | |
82 | # test LIMIT support |
cf7b6654 |
83 | my $lim = $ars->search( {}, |
84 | { |
85 | rows => 3, |
86 | offset => 4, |
87 | order_by => 'artistid' |
88 | } |
89 | ); |
90 | is( $lim->count, 2, 'ROWS+OFFSET count ok' ); |
91 | is( $lim->all, 2, 'Number of ->all objects matches count' ); |
f200d74b |
92 | |
93 | # test iterator |
cf7b6654 |
94 | $lim->reset; |
95 | is( $lim->next->artistid, 101, "iterator->next ok" ); |
96 | is( $lim->next->artistid, 102, "iterator->next ok" ); |
97 | is( $lim->next, undef, "next past end of resultset ok" ); |
f200d74b |
98 | |
ed720bc5 |
99 | # test empty insert |
cf7b6654 |
100 | { |
101 | local $ars->result_source->column_info('artistid')->{is_auto_increment} = 0; |
ed720bc5 |
102 | |
cf7b6654 |
103 | lives_ok { $ars->create({}) } |
104 | 'empty insert works'; |
105 | } |
ed720bc5 |
106 | |
b341186f |
107 | # test blobs (stolen from 73oracle.t) |
cf7b6654 |
108 | eval { $dbh->do('DROP TABLE bindtype_test') }; |
109 | $dbh->do(qq[ |
110 | CREATE TABLE bindtype_test |
111 | ( |
112 | id INT NOT NULL PRIMARY KEY, |
113 | bytea INT NULL, |
114 | blob LONG BINARY NULL, |
115 | clob LONG VARCHAR NULL |
116 | ) |
117 | ],{ RaiseError => 1, PrintError => 1 }); |
118 | |
119 | my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) ); |
120 | $binstr{'large'} = $binstr{'small'} x 1024; |
121 | |
122 | my $maxloblen = length $binstr{'large'}; |
123 | local $dbh->{'LongReadLen'} = $maxloblen; |
124 | |
125 | my $rs = $schema->resultset('BindType'); |
126 | my $id = 0; |
127 | |
128 | foreach my $type (qw( blob clob )) { |
129 | foreach my $size (qw( small large )) { |
130 | $id++; |
b341186f |
131 | |
ed720bc5 |
132 | # turn off horrendous binary DBIC_TRACE output |
cf7b6654 |
133 | local $schema->storage->{debug} = 0; |
ed720bc5 |
134 | |
cf7b6654 |
135 | lives_ok { $rs->create( { 'id' => $id, $type => $binstr{$size} } ) } |
136 | "inserted $size $type without dying"; |
b341186f |
137 | |
cf7b6654 |
138 | ok($rs->find($id)->$type eq $binstr{$size}, "verified inserted $size $type" ); |
139 | } |
b341186f |
140 | } |
141 | } |
f200d74b |
142 | |
143 | done_testing; |
144 | |
145 | # clean up our mess |
146 | END { |
cf7b6654 |
147 | foreach my $dbh (@handles_to_clean) { |
148 | eval { $dbh->do("DROP TABLE $_") } for qw/artist bindtype_test/; |
ed720bc5 |
149 | } |
f200d74b |
150 | } |