-
Notifications
You must be signed in to change notification settings - Fork 14
/
12blob.t
executable file
·157 lines (130 loc) · 4.06 KB
/
12blob.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/perl -w -I./t
#
# blob tests
# currently tests you can insert a clob with various odbc_putdata_start settings
#
use Test::More;
use strict;
#use Data::Dumper;
$| = 1;
my $has_test_nowarnings = 1;
eval "require Test::NoWarnings";
$has_test_nowarnings = undef if $@;
my $tests = 24;
$tests += 1 if $has_test_nowarnings;
plan tests => $tests;
my $dbh;
# can't seem to get the imports right this way
use DBI qw(:sql_types);
use_ok('ODBCTEST');
sub tidyup {
if ($dbh) {
#diag "Tidying up\n";
eval {
local $dbh->{PrintWarn} = 0;
local $dbh->{PrintError} = 0;
$dbh->do(q/drop table DBD_ODBC_drop_me/);
};
}
}
BEGIN {
if (!defined $ENV{DBI_DSN}) {
plan skip_all => "DBI_DSN is undefined";
}
}
END {
tidyup();
Test::NoWarnings::had_no_warnings()
if ($has_test_nowarnings);
}
my $ev;
$dbh = DBI->connect();
unless($dbh) {
BAIL_OUT("Unable to connect to the database $DBI::errstr\nTests skipped.\n");
exit 0;
}
tidyup();
my $putdata_start = $dbh->{odbc_putdata_start};
is($putdata_start, 32768, 'default putdata_start');
my $type_info_all = $dbh->type_info_all();
ok($type_info_all, "type_info_all") or BAIL_OUT("type_info_all failed");
my $map = shift @{$type_info_all};
my ($type_name, $type);
while (my $row = shift @{$type_info_all}) {
#diag("$row->[$map->{TYPE_NAME}],$row->[$map->{DATA_TYPE}], $row->[$map->{COLUMN_SIZE}]");
next if (($row->[$map->{DATA_TYPE}] != SQL_WLONGVARCHAR) && ($row->[$map->{DATA_TYPE}] != SQL_LONGVARCHAR));
# Postgres driver does not have COLUMN_SIZE but its text data type is big enough
# Postgres has no COLUMN_SIZE - it uses the old PRECISION
# In Postgres the PRECISION on text column type is 8190 - it is wrong, it is up to 1GB
#print Dumper($map);
#print Dumper($row);
if ($row->[$map->{TYPE_NAME}] eq 'text' || $row->[$map->{COLUMN_SIZE}] > 60000) {
#diag("$row->[$map->{TYPE_NAME}] $row->[$map->{DATA_TYPE}] $row->[$map->{COLUMN_SIZE}]");
($type_name, $type) = ($row->[$map->{TYPE_NAME}],
$row->[$map->{DATA_TYPE}]);
last;
}
}
SKIP: {
skip "ODBC Driver/Database has not got a big enough type", 21
if (!$type_name);
#diag("Using type $type_name");
eval { $dbh->do(qq/create table DBD_ODBC_drop_me(a $type_name)/); };
$ev = $@;
diag($ev) if $ev;
ok(!$ev, "table DBD_ODBC_drop_me created");
SKIP: {
skip "Cannot create test table", 17 if $ev;
my $bigval = "x" x 30000;
test($dbh, $bigval);
test($dbh, $bigval, 500);
$bigval = 'x' x 60000;
test($dbh, $bigval, 60001);
};
};
sub test
{
my ($dbh, $val, $putdata_start) = @_;
my $rc;
if ($putdata_start) {
$dbh->{odbc_putdata_start} = $putdata_start;
my $pds = $dbh->{odbc_putdata_start};
is($pds, $putdata_start, "retrieved putdata_start = set value");
}
my $sth = $dbh->prepare(q/insert into DBD_ODBC_drop_me values(?)/);
ok($sth, "prepare for insert");
SKIP: {
skip "prepare failed", 3 unless $sth;
$rc = $sth->execute($val);
ok($rc, "insert clob");
SKIP: {
skip "insert failed - skipping the retrieval test", 2 unless $rc;
test_value($dbh, $val);
};
};
$sth = undef;
eval {$dbh->do(q/delete from DBD_ODBC_drop_me/); };
$ev = $@;
diag($ev) if $ev;
ok(!$ev, 'delete records from test table');
return;
}
sub test_value
{
my ($dbh, $value) = @_;
local $dbh->{RaiseError} = 1;
my $max = 60001;
$max = 120001 if ($type == SQL_WLONGVARCHAR || $dbh->{odbc_has_unicode});
local $dbh->{LongReadLen} = $max;
my $row = $dbh->selectall_arrayref(q/select a from DBD_ODBC_drop_me/);
$ev = $@;
diag($ev) if $ev;
ok(!$ev, 'select test data back');
my $rc = is(length($row->[0]->[0]), length($value),
"sizes of insert/select compare");
SKIP: {
skip "sizes do not match", 1 unless $rc;
is($row->[0]->[0], $value, 'data read back compares');
};
return;
}