Revert workarounds for $@ broken during 5.13.x - mainly 1f870d5a
[dbsrgits/DBIx-Class.git] / t / storage / nobindvars.t
CommitLineData
d5130dd2 1use strict;
68de9438 2use warnings;
d5130dd2 3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
6e6ad6c3 7use DBIC::DebugObj;
8use DBIC::SqlMakerTest;
d5130dd2 9use DBI::Const::GetInfoType;
10
6e6ad6c3 11{ # Fake storage driver for SQLite + no bind variables
12 package DBICTest::SQLite::NoBindVars;
d944c5ae 13 use Class::C3;
d5130dd2 14 use base qw/
d5130dd2 15 DBIx::Class::Storage::DBI::NoBindVars
6e6ad6c3 16 DBIx::Class::Storage::DBI::SQLite
d5130dd2 17 /;
d5130dd2 18}
19
6e6ad6c3 20my $schema = DBICTest->init_schema (storage_type => 'DBICTest::SQLite::NoBindVars', no_populate => 1);
d5130dd2 21
22# test primary key handling
3ff5b740 23my $new = $schema->resultset('Artist')->create({ name => 'foo' });
d5130dd2 24ok($new->artistid, "Auto-PK worked");
25
26# test LIMIT support
27for (1..6) {
3ff5b740 28 $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
d5130dd2 29}
3ff5b740 30my $it = $schema->resultset('Artist')->search( {},
d5130dd2 31 { rows => 3,
32 offset => 2,
33 order_by => 'artistid' }
34);
6e6ad6c3 35
fb4b58e8 36is( $it->count, 3, "LIMIT count ok" ); # ask for 3 rows out of 7 artists
6e6ad6c3 37
38my ($sql, @bind);
39my $orig_debugobj = $schema->storage->debugobj;
40my $orig_debug = $schema->storage->debug;
41$schema->storage->debugobj (DBIC::DebugObj->new (\$sql, \@bind) );
42$schema->storage->debug (1);
43
d5130dd2 44is( $it->next->name, "Artist 2", "iterator->next ok" );
45$it->next;
46$it->next;
47is( $it->next, undef, "next past end of resultset ok" );
48
6e6ad6c3 49$schema->storage->debugobj ($orig_debugobj);
50$schema->storage->debug ($orig_debug);
51
52is_same_sql_bind (
53 $sql,
54 \@bind,
55 'SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me ORDER BY artistid LIMIT 3 OFFSET 2',
56 [],
57 'Correctly interpolated SQL'
58);
68de9438 59
60done_testing;