Will add C<< odbc_cursortype => 2 >> to your DBI connection attributes. See
L<DBD::ODBC/odbc_cursortype> for more information.
-Alternatively, you can add it yourself and dynamic cursor will be automatically
-enabled.
+Alternatively, you can add it yourself and dynamic cursor support will be
+automatically enabled.
-This will not work with CODE ref connect_info's and will do nothing if you set
-C<odbc_cursortype> yourself.
+If you're using FreeTDS, C<tds_version> must be set to at least C<8.0>.
+
+This will not work with CODE ref connect_info's.
B<WARNING:> this will break C<SCOPE_IDENTITY()>, and C<SELECT @@IDENTITY> will
be used instead, which on SQL Server 2005 and later will return erroneous
sub _set_dynamic_cursors {
my $self = shift;
+ my $dbh = $self->_dbh;
+
+ eval {
+ local $dbh->{RaiseError} = 1;
+ local $dbh->{PrintError} = 0;
+ $dbh->do('SELECT @@IDENTITY');
+ };
+ if ($@) {
+ croak <<'EOF';
+
+Your drivers do not seem to support dynamic cursors (odbc_cursortype => 2),
+if you're using FreeTDS, make sure to set tds_version to 8.0 or greater.
+EOF
+ }
+
$self->_using_dynamic_cursors(1);
$self->_identity_method('@@identity');
}
# test Auto-PK with different options
for my $opts (@opts) {
- $schema = DBICTest::Schema->clone;
- $schema->connection($dsn, $user, $pass, $opts);
+ SKIP: {
+ $schema = DBICTest::Schema->connect($dsn, $user, $pass, $opts);
- $schema->resultset('Artist')->search({ name => 'foo' })->delete;
+ eval {
+ $schema->storage->ensure_connected
+ };
+ if ($@ =~ /dynamic cursors/) {
+ skip
+'Dynamic Cursors not functional, tds_version 8.0 or greater required if using'.
+' FreeTDS', 1;
+ }
- $new = $schema->resultset('Artist')->create({ name => 'foo' });
- ok($new->artistid > 0, "Auto-PK worked");
+ $schema->resultset('Artist')->search({ name => 'foo' })->delete;
+
+ $new = $schema->resultset('Artist')->create({ name => 'foo' });
+
+ ok($new->artistid > 0, "Auto-PK worked");
+ }
}
$seen_id{$new->artistid}++;