Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 644 lines (523 sloc) 17.465 kb
a964a92 Rafael Kitover Sybase autopk, and a test, no limit support yet
rkitover authored
1 use strict;
68de943 Peter Rabbitson Massive cleanup of DateTime test dependencies, other interim
ribasushi authored
2 use warnings;
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
3 no warnings 'uninitialized';
a964a92 Rafael Kitover Sybase autopk, and a test, no limit support yet
rkitover authored
4
5 use Test::More;
e0b2344 Rafael Kitover todo tests for text/image columns in sybase
rkitover authored
6 use Test::Exception;
199fbc4 Rafael Kitover check database driver dependencies for tests
rkitover authored
7 use DBIx::Class::Optional::Dependencies ();
a964a92 Rafael Kitover Sybase autopk, and a test, no limit support yet
rkitover authored
8 use lib qw(t/lib);
9 use DBICTest;
2baff5d Peter Rabbitson All of caelum's work so far (not reviewed)
ribasushi authored
10
6d5679b Peter Rabbitson Fix ASE bulk_insert for bind changes in 0e773352
ribasushi authored
11 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/};
12 if (not ($dsn && $user)) {
13 plan skip_all => join ' ',
14 'Set $ENV{DBICTEST_SYBASE_DSN}, _USER and _PASS to run this test.',
15 'Warning: This test drops and creates the tables:',
16 "'artist', 'money_test' and 'bindtype_test'",
17 ;
18 };
19
199fbc4 Rafael Kitover check database driver dependencies for tests
rkitover authored
20 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_ase')
21 unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_ase');
22
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
23 my @storage_types = (
95787af Peter Rabbitson refactor part 2
ribasushi authored
24 'DBI::Sybase::ASE',
25 'DBI::Sybase::ASE::NoBindVars',
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
26 );
5ce107a Rafael Kitover fix test
rkitover authored
27 eval "require DBIx::Class::Storage::$_;" for @storage_types;
95787af Peter Rabbitson refactor part 2
ribasushi authored
28
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
29 my $schema;
30 my $storage_idx = -1;
31
32 sub get_schema {
33 DBICTest::Schema->connect($dsn, $user, $pass, {
34 on_connect_call => [
35 [ blob_setup => log_on_update => 1 ], # this is a safer option
36 ],
37 });
38 }
39
40 my $ping_count = 0;
41 {
95787af Peter Rabbitson refactor part 2
ribasushi authored
42 my $ping = DBIx::Class::Storage::DBI::Sybase::ASE->can('_ping');
43 *DBIx::Class::Storage::DBI::Sybase::ASE::_ping = sub {
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
44 $ping_count++;
45 goto $ping;
46 };
47 }
48
49 for my $storage_type (@storage_types) {
50 $storage_idx++;
51
95787af Peter Rabbitson refactor part 2
ribasushi authored
52 unless ($storage_type eq 'DBI::Sybase::ASE') { # autodetect
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
53 DBICTest::Schema->storage_type("::$storage_type");
54 }
61cfaef Rafael Kitover minor cleanups
rkitover authored
55
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
56 $schema = get_schema();
a964a92 Rafael Kitover Sybase autopk, and a test, no limit support yet
rkitover authored
57
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
58 $schema->storage->ensure_connected;
a964a92 Rafael Kitover Sybase autopk, and a test, no limit support yet
rkitover authored
59
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
60 if ($storage_idx == 0 &&
95787af Peter Rabbitson refactor part 2
ribasushi authored
61 $schema->storage->isa('DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars')) {
6d5679b Peter Rabbitson Fix ASE bulk_insert for bind changes in 0e773352
ribasushi authored
62 # no placeholders in this version of Sybase or DBD::Sybase (or using FreeTDS)
63 skip "Skipping entire test for $storage_type - no placeholder support", 1;
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
64 next;
65 }
5703eb1 Rafael Kitover some compatibility updated for older DBD::Sybase versions, some initial ...
rkitover authored
66
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
67 isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" );
6b1f5ef Rafael Kitover fix Sybase DT stuff and storage bases
rkitover authored
68
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
69 $schema->storage->_dbh->disconnect;
70 lives_ok (sub { $schema->storage->dbh }, 'reconnect works');
64f4e69 Rafael Kitover minor changes
rkitover authored
71
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
72 $schema->storage->dbh_do (sub {
73 my ($storage, $dbh) = @_;
74 eval { $dbh->do("DROP TABLE artist") };
75 $dbh->do(<<'SQL');
a964a92 Rafael Kitover Sybase autopk, and a test, no limit support yet
rkitover authored
76 CREATE TABLE artist (
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
77 artistid INT IDENTITY PRIMARY KEY,
a964a92 Rafael Kitover Sybase autopk, and a test, no limit support yet
rkitover authored
78 name VARCHAR(100),
79 rank INT DEFAULT 13 NOT NULL,
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
80 charfield CHAR(10) NULL
a964a92 Rafael Kitover Sybase autopk, and a test, no limit support yet
rkitover authored
81 )
26283ee Peter Rabbitson Backout sybase changes
ribasushi authored
82 SQL
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
83 });
a964a92 Rafael Kitover Sybase autopk, and a test, no limit support yet
rkitover authored
84
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
85 my %seen_id;
a964a92 Rafael Kitover Sybase autopk, and a test, no limit support yet
rkitover authored
86
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
87 # so we start unconnected
88 $schema->storage->disconnect;
fcc2ec1 Rafael Kitover fix and test redispatch to reblessed storage insert/update
rkitover authored
89
26283ee Peter Rabbitson Backout sybase changes
ribasushi authored
90 # test primary key handling
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
91 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
044f5b3 Rafael Kitover Fix auto-pk for Sybase ASE, broken by refactoring in fabbd5cc
rkitover authored
92 like $new->artistid, qr/^\d+\z/, 'Auto-PK returned a number';
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
93 ok($new->artistid > 0, "Auto-PK worked");
fcc2ec1 Rafael Kitover fix and test redispatch to reblessed storage insert/update
rkitover authored
94
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
95 $seen_id{$new->artistid}++;
fcc2ec1 Rafael Kitover fix and test redispatch to reblessed storage insert/update
rkitover authored
96
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
97 # check redispatch to storage-specific insert when auto-detected storage
95787af Peter Rabbitson refactor part 2
ribasushi authored
98 if ($storage_type eq 'DBI::Sybase::ASE') {
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
99 DBICTest::Schema->storage_type('::DBI');
100 $schema = get_schema();
101 }
102
103 $new = $schema->resultset('Artist')->create({ name => 'Artist 1' });
104 is ( $seen_id{$new->artistid}, undef, 'id for Artist 1 is unique' );
105 $seen_id{$new->artistid}++;
106
107 # inserts happen in a txn, so we make sure it still works inside a txn too
108 $schema->txn_begin;
109
110 for (2..6) {
a964a92 Rafael Kitover Sybase autopk, and a test, no limit support yet
rkitover authored
111 $new = $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
112 is ( $seen_id{$new->artistid}, undef, "id for Artist $_ is unique" );
113 $seen_id{$new->artistid}++;
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
114 }
a964a92 Rafael Kitover Sybase autopk, and a test, no limit support yet
rkitover authored
115
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
116 $schema->txn_commit;
a964a92 Rafael Kitover Sybase autopk, and a test, no limit support yet
rkitover authored
117
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
118 # test simple count
119 is ($schema->resultset('Artist')->count, 7, 'count(*) of whole table ok');
120
121 # test LIMIT support
122 my $it = $schema->resultset('Artist')->search({
123 artistid => { '>' => 0 }
124 }, {
a034815 Rafael Kitover use TOP for sybase limit count thanks to refactored count
rkitover authored
125 rows => 3,
126 order_by => 'artistid',
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
127 });
af9e4a5 Peter Rabbitson Caelum's work so far
ribasushi authored
128
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
129 is( $it->count, 3, "LIMIT count ok" );
e19677a Peter Rabbitson Rollback all bulk insert code before merge
ribasushi authored
130
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
131 is( $it->next->name, "foo", "iterator->next ok" );
132 $it->next;
133 is( $it->next->name, "Artist 2", "iterator->next ok" );
134 is( $it->next, undef, "next past end of resultset ok" );
135
136 # now try with offset
137 $it = $schema->resultset('Artist')->search({}, {
138 rows => 3,
139 offset => 3,
140 order_by => 'artistid',
141 });
142
143 is( $it->count, 3, "LIMIT with offset count ok" );
144
145 is( $it->next->name, "Artist 3", "iterator->next ok" );
146 $it->next;
147 is( $it->next->name, "Artist 5", "iterator->next ok" );
148 is( $it->next, undef, "next past end of resultset ok" );
149
150 # now try a grouped count
151 $schema->resultset('Artist')->create({ name => 'Artist 6' })
152 for (1..6);
153
154 $it = $schema->resultset('Artist')->search({}, {
155 group_by => 'name'
156 });
157
158 is( $it->count, 7, 'COUNT of GROUP_BY ok' );
159
2baff5d Peter Rabbitson All of caelum's work so far (not reviewed)
ribasushi authored
160 # do an IDENTITY_INSERT
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
161 {
162 no warnings 'redefine';
163
164 my @debug_out;
165 local $schema->storage->{debug} = 1;
166 local $schema->storage->debugobj->{callback} = sub {
167 push @debug_out, $_[1];
168 };
169
170 my $txn_used = 0;
171 my $txn_commit = \&DBIx::Class::Storage::DBI::txn_commit;
172 local *DBIx::Class::Storage::DBI::txn_commit = sub {
173 $txn_used = 1;
174 goto &$txn_commit;
175 };
176
177 $schema->resultset('Artist')
178 ->create({ artistid => 999, name => 'mtfnpy' });
179
2baff5d Peter Rabbitson All of caelum's work so far (not reviewed)
ribasushi authored
180 ok((grep /IDENTITY_INSERT/i, @debug_out), 'IDENTITY_INSERT used');
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
181
182 SKIP: {
183 skip 'not testing lack of txn on IDENTITY_INSERT with NoBindVars', 1
184 if $storage_type =~ /NoBindVars/i;
185
186 is $txn_used, 0, 'no txn on insert with IDENTITY_INSERT';
187 }
188 }
189
2baff5d Peter Rabbitson All of caelum's work so far (not reviewed)
ribasushi authored
190 # do an IDENTITY_UPDATE
191 {
192 my @debug_out;
193 local $schema->storage->{debug} = 1;
194 local $schema->storage->debugobj->{callback} = sub {
195 push @debug_out, $_[1];
196 };
197
198 lives_and {
199 $schema->resultset('Artist')
200 ->find(999)->update({ artistid => 555 });
201 ok((grep /IDENTITY_UPDATE/i, @debug_out));
202 } 'IDENTITY_UPDATE used';
203 $ping_count-- if $@;
204 }
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
205
206 my $bulk_rs = $schema->resultset('Artist')->search({
207 name => { -like => 'bulk artist %' }
208 });
209
0a9a995 Peter Rabbitson All sybase bulk-insert code by Caelum
ribasushi authored
210 # test insert_bulk using populate.
2baff5d Peter Rabbitson All of caelum's work so far (not reviewed)
ribasushi authored
211 SKIP: {
212 skip 'insert_bulk not supported', 4
d390bd3 Rafael Kitover minor cleanups, test update of blob to NULL
rkitover authored
213 unless $storage_type !~ /NoBindVars/i;
e06ad5d Rafael Kitover add money type support
rkitover authored
214
2baff5d Peter Rabbitson All of caelum's work so far (not reviewed)
ribasushi authored
215 lives_ok {
216 $schema->resultset('Artist')->populate([
217 {
218 name => 'bulk artist 1',
219 charfield => 'foo',
220 },
221 {
222 name => 'bulk artist 2',
223 charfield => 'foo',
224 },
225 {
226 name => 'bulk artist 3',
227 charfield => 'foo',
228 },
229 ]);
230 } 'insert_bulk via populate';
231
232 is $bulk_rs->count, 3, 'correct number inserted via insert_bulk';
233
234 is ((grep $_->charfield eq 'foo', $bulk_rs->all), 3,
235 'column set correctly via insert_bulk');
236
237 my %bulk_ids;
238 @bulk_ids{map $_->artistid, $bulk_rs->all} = ();
239
240 is ((scalar keys %bulk_ids), 3,
241 'identities generated correctly in insert_bulk');
242
243 $bulk_rs->delete;
244 }
e06ad5d Rafael Kitover add money type support
rkitover authored
245
0a9a995 Peter Rabbitson All sybase bulk-insert code by Caelum
ribasushi authored
246 # make sure insert_bulk works a second time on the same connection
247 SKIP: {
248 skip 'insert_bulk not supported', 3
d390bd3 Rafael Kitover minor cleanups, test update of blob to NULL
rkitover authored
249 unless $storage_type !~ /NoBindVars/i;
0a9a995 Peter Rabbitson All sybase bulk-insert code by Caelum
ribasushi authored
250
251 lives_ok {
252 $schema->resultset('Artist')->populate([
253 {
254 name => 'bulk artist 1',
255 charfield => 'bar',
256 },
257 {
258 name => 'bulk artist 2',
259 charfield => 'bar',
260 },
261 {
262 name => 'bulk artist 3',
263 charfield => 'bar',
264 },
265 ]);
266 } 'insert_bulk via populate called a second time';
267
268 is $bulk_rs->count, 3,
269 'correct number inserted via insert_bulk';
270
271 is ((grep $_->charfield eq 'bar', $bulk_rs->all), 3,
272 'column set correctly via insert_bulk');
273
274 $bulk_rs->delete;
275 }
276
277 # test invalid insert_bulk (missing required column)
278 #
279 # There should be a rollback, reconnect and the next valid insert_bulk should
280 # succeed.
281 throws_ok {
282 $schema->resultset('Artist')->populate([
283 {
284 charfield => 'foo',
285 }
286 ]);
287 } qr/no value or default|does not allow null|placeholders/i,
288 # The second pattern is the error from fallback to regular array insert on
289 # incompatible charset.
290 # The third is for ::NoBindVars with no syb_has_blk.
291 'insert_bulk with missing required column throws error';
292
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
293 # now test insert_bulk with IDENTITY_INSERT
2baff5d Peter Rabbitson All of caelum's work so far (not reviewed)
ribasushi authored
294 SKIP: {
295 skip 'insert_bulk not supported', 3
d390bd3 Rafael Kitover minor cleanups, test update of blob to NULL
rkitover authored
296 unless $storage_type !~ /NoBindVars/i;
e19677a Peter Rabbitson Rollback all bulk insert code before merge
ribasushi authored
297
2baff5d Peter Rabbitson All of caelum's work so far (not reviewed)
ribasushi authored
298 lives_ok {
299 $schema->resultset('Artist')->populate([
300 {
301 artistid => 2001,
302 name => 'bulk artist 1',
303 charfield => 'foo',
304 },
305 {
306 artistid => 2002,
307 name => 'bulk artist 2',
308 charfield => 'foo',
309 },
310 {
311 artistid => 2003,
312 name => 'bulk artist 3',
313 charfield => 'foo',
314 },
315 ]);
316 } 'insert_bulk with IDENTITY_INSERT via populate';
317
318 is $bulk_rs->count, 3,
319 'correct number inserted via insert_bulk with IDENTITY_INSERT';
320
321 is ((grep $_->charfield eq 'foo', $bulk_rs->all), 3,
322 'column set correctly via insert_bulk with IDENTITY_INSERT');
323
324 $bulk_rs->delete;
325 }
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
326
327 # test correlated subquery
328 my $subq = $schema->resultset('Artist')->search({ artistid => { '>' => 3 } })
329 ->get_column('artistid')
330 ->as_query;
331 my $subq_rs = $schema->resultset('Artist')->search({
332 artistid => { -in => $subq }
333 });
334 is $subq_rs->count, 11, 'correlated subquery';
335
336 # mostly stolen from the blob stuff Nniuq wrote for t/73oracle.t
337 SKIP: {
587daa9 Rafael Kitover remove some duplicate code
rkitover authored
338 skip 'TEXT/IMAGE support does not work with FreeTDS', 22
aca3b4c Peter Rabbitson Centralize (and privatize) handling of freetds driver/version detection
ribasushi authored
339 if $schema->storage->_using_freetds;
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
340
341 my $dbh = $schema->storage->_dbh;
342 {
343 local $SIG{__WARN__} = sub {};
344 eval { $dbh->do('DROP TABLE bindtype_test') };
345
346 $dbh->do(qq[
8273e84 Peter Rabbitson Trailing WS crusade - got to save them bits
ribasushi authored
347 CREATE TABLE bindtype_test
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
348 (
f3a9ea3 Rafael Kitover Add extra test blob type
rkitover authored
349 id INT IDENTITY PRIMARY KEY,
350 bytea IMAGE NULL,
351 blob IMAGE NULL,
352 clob TEXT NULL,
353 a_memo IMAGE NULL
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
354 )
355 ],{ RaiseError => 1, PrintError => 0 });
356 }
357
358 my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) );
359 $binstr{'large'} = $binstr{'small'} x 1024;
360
361 my $maxloblen = length $binstr{'large'};
8273e84 Peter Rabbitson Trailing WS crusade - got to save them bits
ribasushi authored
362
aca3b4c Peter Rabbitson Centralize (and privatize) handling of freetds driver/version detection
ribasushi authored
363 if (not $schema->storage->_using_freetds) {
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
364 $dbh->{'LongReadLen'} = $maxloblen * 2;
365 } else {
366 $dbh->do("set textsize ".($maxloblen * 2));
367 }
368
369 my $rs = $schema->resultset('BindType');
370 my $last_id;
371
372 foreach my $type (qw(blob clob)) {
373 foreach my $size (qw(small large)) {
374 no warnings 'uninitialized';
375
0a9a995 Peter Rabbitson All sybase bulk-insert code by Caelum
ribasushi authored
376 my $created;
377 lives_ok {
378 $created = $rs->create( { $type => $binstr{$size} } )
379 } "inserted $size $type without dying";
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
380
381 $last_id = $created->id if $created;
382
0a9a995 Peter Rabbitson All sybase bulk-insert code by Caelum
ribasushi authored
383 lives_and {
384 ok($rs->find($last_id)->$type eq $binstr{$size})
385 } "verified inserted $size $type";
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
386 }
387 }
388
689819e Peter Rabbitson Merge 'sybase_insert_bulk' into 'sybase_support'
ribasushi authored
389 $rs->delete;
390
0a9a995 Peter Rabbitson All sybase bulk-insert code by Caelum
ribasushi authored
391 # blob insert with explicit PK
392 # also a good opportunity to test IDENTITY_INSERT
393 lives_ok {
394 $rs->create( { id => 1, blob => $binstr{large} } )
395 } 'inserted large blob without dying with manual PK';
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
396
0a9a995 Peter Rabbitson All sybase bulk-insert code by Caelum
ribasushi authored
397 lives_and {
398 ok($rs->find(1)->blob eq $binstr{large})
399 } 'verified inserted large blob with manual PK';
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
400
401 # try a blob update
402 my $new_str = $binstr{large} . 'mtfnpy';
403
404 # check redispatch to storage-specific update when auto-detected storage
95787af Peter Rabbitson refactor part 2
ribasushi authored
405 if ($storage_type eq 'DBI::Sybase::ASE') {
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
406 DBICTest::Schema->storage_type('::DBI');
407 $schema = get_schema();
408 }
409
0a9a995 Peter Rabbitson All sybase bulk-insert code by Caelum
ribasushi authored
410 lives_ok {
411 $rs->search({ id => 1 })->update({ blob => $new_str })
412 } 'updated blob successfully';
413
414 lives_and {
415 ok($rs->find(1)->blob eq $new_str)
416 } 'verified updated blob';
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
417
2baff5d Peter Rabbitson All of caelum's work so far (not reviewed)
ribasushi authored
418 # try a blob update with IDENTITY_UPDATE
419 lives_and {
420 $new_str = $binstr{large} . 'hlagh';
421 $rs->find(1)->update({ id => 999, blob => $new_str });
422 ok($rs->find(999)->blob eq $new_str);
423 } 'verified updated blob with IDENTITY_UPDATE';
7ef97d2 Rafael Kitover I'll rewrite this bit tomorrow to be less retarded
rkitover authored
424
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
425 ## try multi-row blob update
426 # first insert some blobs
427 $new_str = $binstr{large} . 'foo';
0a9a995 Peter Rabbitson All sybase bulk-insert code by Caelum
ribasushi authored
428 lives_and {
429 $rs->delete;
430 $rs->create({ blob => $binstr{large} }) for (1..2);
431 $rs->update({ blob => $new_str });
432 is((grep $_->blob eq $new_str, $rs->all), 2);
433 } 'multi-row blob update';
434
435 $rs->delete;
436
587daa9 Rafael Kitover remove some duplicate code
rkitover authored
437 # now try insert_bulk with blobs and only blobs
0a9a995 Peter Rabbitson All sybase bulk-insert code by Caelum
ribasushi authored
438 $new_str = $binstr{large} . 'bar';
439 lives_ok {
440 $rs->populate([
441 {
442 blob => $binstr{large},
443 clob => $new_str,
444 },
445 {
446 blob => $binstr{large},
447 clob => $new_str,
448 },
449 ]);
450 } 'insert_bulk with blobs does not die';
451
452 is((grep $_->blob eq $binstr{large}, $rs->all), 2,
453 'IMAGE column set correctly via insert_bulk');
454
455 is((grep $_->clob eq $new_str, $rs->all), 2,
456 'TEXT column set correctly via insert_bulk');
2baff5d Peter Rabbitson All of caelum's work so far (not reviewed)
ribasushi authored
457
587daa9 Rafael Kitover remove some duplicate code
rkitover authored
458 # now try insert_bulk with blobs and a non-blob which also happens to be an
459 # identity column
460 SKIP: {
461 skip 'no insert_bulk without placeholders', 4
462 if $storage_type =~ /NoBindVars/i;
463
464 $rs->delete;
465 $new_str = $binstr{large} . 'bar';
466 lives_ok {
467 $rs->populate([
468 {
469 id => 1,
470 bytea => 1,
471 blob => $binstr{large},
472 clob => $new_str,
f3a9ea3 Rafael Kitover Add extra test blob type
rkitover authored
473 a_memo => 2,
587daa9 Rafael Kitover remove some duplicate code
rkitover authored
474 },
475 {
476 id => 2,
477 bytea => 1,
478 blob => $binstr{large},
479 clob => $new_str,
f3a9ea3 Rafael Kitover Add extra test blob type
rkitover authored
480 a_memo => 2,
587daa9 Rafael Kitover remove some duplicate code
rkitover authored
481 },
482 ]);
db66bc3 Rafael Kitover some cleanups
rkitover authored
483 } 'insert_bulk with blobs and explicit identity does NOT die';
587daa9 Rafael Kitover remove some duplicate code
rkitover authored
484
485 is((grep $_->blob eq $binstr{large}, $rs->all), 2,
486 'IMAGE column set correctly via insert_bulk with identity');
487
488 is((grep $_->clob eq $new_str, $rs->all), 2,
489 'TEXT column set correctly via insert_bulk with identity');
490
491 is_deeply [ map $_->id, $rs->all ], [ 1,2 ],
492 'explicit identities set correctly via insert_bulk with blobs';
493 }
494
d390bd3 Rafael Kitover minor cleanups, test update of blob to NULL
rkitover authored
495 lives_and {
496 $rs->delete;
497 $rs->create({ blob => $binstr{large} }) for (1..2);
498 $rs->update({ blob => undef });
499 is((grep !defined($_->blob), $rs->all), 2);
500 } 'blob update to NULL';
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
501 }
502
cd04833 Rafael Kitover fix insert with all defaults
rkitover authored
503 # test MONEY column support (and some other misc. stuff)
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
504 $schema->storage->dbh_do (sub {
505 my ($storage, $dbh) = @_;
506 eval { $dbh->do("DROP TABLE money_test") };
507 $dbh->do(<<'SQL');
508 CREATE TABLE money_test (
509 id INT IDENTITY PRIMARY KEY,
cd04833 Rafael Kitover fix insert with all defaults
rkitover authored
510 amount MONEY DEFAULT $999.99 NULL
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
511 )
512 SQL
513 });
514
cd04833 Rafael Kitover fix insert with all defaults
rkitover authored
515 my $rs = $schema->resultset('Money');
516
517 # test insert with defaults
518 lives_and {
519 $rs->create({});
520 is((grep $_->amount == 999.99, $rs->all), 1);
521 } 'insert with all defaults works';
522 $rs->delete;
523
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
524 # test insert transaction when there's an active cursor
2baff5d Peter Rabbitson All of caelum's work so far (not reviewed)
ribasushi authored
525 {
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
526 my $artist_rs = $schema->resultset('Artist');
527 $artist_rs->first;
528 lives_ok {
529 my $row = $schema->resultset('Money')->create({ amount => 100 });
530 $row->delete;
531 } 'inserted a row with an active cursor';
532 $ping_count-- if $@; # dbh_do calls ->connected
533 }
534
535 # test insert in an outer transaction when there's an active cursor
4ca1fd6 Peter Rabbitson Remove TODO labels from blocks not using todo_skip() - no test changes
ribasushi authored
536 {
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
537 local $TODO = 'this should work once we have eager cursors';
538
539 # clear state, or we get a deadlock on $row->delete
540 # XXX figure out why this happens
541 $schema->storage->disconnect;
542
543 lives_ok {
544 $schema->txn_do(sub {
545 my $artist_rs = $schema->resultset('Artist');
546 $artist_rs->first;
547 my $row = $schema->resultset('Money')->create({ amount => 100 });
548 $row->delete;
549 });
550 } 'inserted a row with an active cursor in outer txn';
551 $ping_count-- if $@; # dbh_do calls ->connected
552 }
553
554 # Now test money values.
555 my $row;
556 lives_ok {
557 $row = $rs->create({ amount => 100 });
558 } 'inserted a money value';
559
cdf7f02 Rafael Kitover fix sybase fail, add more diagnostics for firebird blob fail
rkitover authored
560 cmp_ok eval { $rs->find($row->id)->amount }, '==', 100,
561 'money value round-trip';
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
562
563 lives_ok {
564 $row->update({ amount => 200 });
565 } 'updated a money value';
566
cdf7f02 Rafael Kitover fix sybase fail, add more diagnostics for firebird blob fail
rkitover authored
567 cmp_ok eval { $rs->find($row->id)->amount }, '==', 200,
568 'updated money value round-trip';
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
569
570 lives_ok {
571 $row->update({ amount => undef });
572 } 'updated a money value to NULL';
573
4689104 Rafael Kitover fix test count
rkitover authored
574 lives_and {
ca507a2 Peter Rabbitson Minor test cleanups
ribasushi authored
575 my $null_amount = $rs->find($row->id)->amount;
4689104 Rafael Kitover fix test count
rkitover authored
576 is $null_amount, undef;
577 } 'updated money value to NULL round-trip';
6469dab Rafael Kitover empty insert into a Sybase table with computed columns and either data_t...
rkitover authored
578
579 # Test computed columns and timestamps
580 $schema->storage->dbh_do (sub {
581 my ($storage, $dbh) = @_;
582 eval { $dbh->do("DROP TABLE computed_column_test") };
583 $dbh->do(<<'SQL');
584 CREATE TABLE computed_column_test (
585 id INT IDENTITY PRIMARY KEY,
586 a_computed_column AS getdate(),
587 a_timestamp timestamp,
8273e84 Peter Rabbitson Trailing WS crusade - got to save them bits
ribasushi authored
588 charfield VARCHAR(20) DEFAULT 'foo'
6469dab Rafael Kitover empty insert into a Sybase table with computed columns and either data_t...
rkitover authored
589 )
590 SQL
591 });
592
593 require DBICTest::Schema::ComputedColumn;
594 $schema->register_class(
595 ComputedColumn => 'DBICTest::Schema::ComputedColumn'
596 );
597
598 ok (($rs = $schema->resultset('ComputedColumn')),
599 'got rs for ComputedColumn');
600
601 lives_ok { $row = $rs->create({}) }
602 'empty insert for a table with computed columns survived';
603
604 lives_ok {
605 $row->update({ charfield => 'bar' })
606 } 'update of a table with computed columns survived';
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
607 }
608
609 is $ping_count, 0, 'no pings';
f135848 Peter Rabbitson Whoops this should not have committed
ribasushi authored
610
72933b1 Peter Rabbitson Run the sybase C subtest *after* the main test
ribasushi authored
611 # if tests passed and did so under a non-C lang - let's rerun the test
612 if (Test::Builder->new->is_passing and $ENV{LANG} and $ENV{LANG} ne 'C') {
613 my $oldlang = $ENV{LANG};
614 local $ENV{LANG} = 'C';
615
616 pass ("Your lang is set to $oldlang - retesting with C");
617
f3ec358 Peter Rabbitson Entire test suite now executable under tainted perl (prove -lT)
ribasushi authored
618 local $ENV{PATH};
619 my @cmd = map { $_ =~ /(.+)/ } ($^X, __FILE__);
72933b1 Peter Rabbitson Run the sybase C subtest *after* the main test
ribasushi authored
620
621 # this is cheating, and may even hang here and there (testing on windows passed fine)
622 # will be replaced with Test::SubExec::Noninteractive in due course
623 require IPC::Open2;
624 IPC::Open2::open2(my $out, undef, @cmd);
625 while (my $ln = <$out>) {
626 print " $ln";
627 }
628
629 wait;
630 ok (! $?, "Wstat $? from: @cmd");
631 }
632
6d5679b Peter Rabbitson Fix ASE bulk_insert for bind changes in 0e773352
ribasushi authored
633 done_testing;
634
a964a92 Rafael Kitover Sybase autopk, and a test, no limit support yet
rkitover authored
635 # clean up our mess
636 END {
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
637 if (my $dbh = eval { $schema->storage->_dbh }) {
638 eval { $dbh->do("DROP TABLE $_") }
6469dab Rafael Kitover empty insert into a Sybase table with computed columns and either data_t...
rkitover authored
639 for qw/artist bindtype_test money_test computed_column_test/;
d867eed Peter Rabbitson Part one of the sybase work by Caelum (mostly reviewed)
ribasushi authored
640 }
65d3512 Peter Rabbitson Test suite wide leaktesting
ribasushi authored
641
642 undef $schema;
a964a92 Rafael Kitover Sybase autopk, and a test, no limit support yet
rkitover authored
643 }
Something went wrong with that request. Please try again.