test blobs, they work, didn't have to do anything
[dbsrgits/DBIx-Class.git] / t / 749sybase_asa.t
CommitLineData
f200d74b 1use strict;
2use warnings;
3
4use Test::More;
5use Test::Exception;
6use lib qw(t/lib);
7use DBICTest;
8
b341186f 9# tests stolen from 748informix.t
f200d74b 10
b341186f 11my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_ASA_${_}" } qw/DSN USER PASS/};
f200d74b 12
13plan skip_all => 'Set $ENV{DBICTEST_SYBASE_ASA_DSN}, _USER and _PASS to run this test'
b341186f 14 unless ($dsn);
f200d74b 15
16my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
17
18my $dbh = $schema->storage->dbh;
19
20eval { $dbh->do("DROP TABLE artist") };
21
22$dbh->do("CREATE TABLE artist (artistid INT IDENTITY PRIMARY KEY, name VARCHAR(255), charfield CHAR(10), rank INT DEFAULT 13)");
23
24my $ars = $schema->resultset('Artist');
25is ( $ars->count, 0, 'No rows at first' );
26
27# test primary key handling
28my $new = $ars->create({ name => 'foo' });
29ok($new->artistid, "Auto-PK worked");
30
31# test explicit key spec
32$new = $ars->create ({ name => 'bar', artistid => 66 });
33is($new->artistid, 66, 'Explicit PK worked');
34$new->discard_changes;
35is($new->artistid, 66, 'Explicit PK assigned');
36
37# test populate
38lives_ok (sub {
39 my @pop;
40 for (1..2) {
41 push @pop, { name => "Artist_$_" };
42 }
43 $ars->populate (\@pop);
44});
45
46# test populate with explicit key
47lives_ok (sub {
48 my @pop;
49 for (1..2) {
50 push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
51 }
52 $ars->populate (\@pop);
53});
54
55# count what we did so far
56is ($ars->count, 6, 'Simple count works');
57
58# test LIMIT support
59my $lim = $ars->search( {},
60 {
61 rows => 3,
62 offset => 4,
63 order_by => 'artistid'
64 }
65);
66is( $lim->count, 2, 'ROWS+OFFSET count ok' );
67is( $lim->all, 2, 'Number of ->all objects matches count' );
68
69# test iterator
70$lim->reset;
71is( $lim->next->artistid, 101, "iterator->next ok" );
72is( $lim->next->artistid, 102, "iterator->next ok" );
73is( $lim->next, undef, "next past end of resultset ok" );
74
b341186f 75# test blobs (stolen from 73oracle.t)
76eval { $dbh->do('DROP TABLE bindtype_test') };
77$dbh->do(qq[
78CREATE TABLE bindtype_test
79(
80 id INT NOT NULL PRIMARY KEY,
81 bytea INT NULL,
82 blob LONG BINARY NULL,
83 clob LONG VARCHAR NULL
84)
85],{ RaiseError => 1, PrintError => 1 });
86
87my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
88$binstr{'large'} = $binstr{'small'} x 1024;
89
90my $maxloblen = length $binstr{'large'};
91local $dbh->{'LongReadLen'} = $maxloblen;
92
93my $rs = $schema->resultset('BindType');
94my $id = 0;
95
96foreach my $type (qw( blob clob )) {
97 foreach my $size (qw( small large )) {
98 $id++;
99
100 lives_ok { $rs->create( { 'id' => $id, $type => $binstr{$size} } ) }
101 "inserted $size $type without dying";
102
103 ok($rs->find($id)->$type eq $binstr{$size}, "verified inserted $size $type" );
104 }
105}
f200d74b 106
107done_testing;
108
109# clean up our mess
110END {
111 my $dbh = eval { $schema->storage->_dbh };
b341186f 112 if ($dbh) {
113 $dbh->do("DROP TABLE $_") for qw/artist bindtype_test/;
114 }
f200d74b 115}