From: Rafael Kitover Date: Fri, 18 Sep 2009 06:33:14 +0000 (+0000) Subject: fix freetds X-Git-Tag: v0.08112~14^2~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=758b5941171ad244192af1d5553d76a780394c72;p=dbsrgits%2FDBIx-Class.git fix freetds --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 4990e78..b75ac87 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1339,7 +1339,12 @@ sub insert_bulk { my %colvalues; my $table = $source->from; @colvalues{@$cols} = (0..$#$cols); - my ($sql, @bind) = $self->sql_maker->insert($table, \%colvalues); + + my ($sql, $bind) = $self->_prep_for_execute ( + 'insert', undef, $source, [\%colvalues] + ); + my @bind = @$bind + or croak 'Cannot insert_bulk without support for placeholders'; $self->_query_start( $sql, @bind ); my $sth = $self->sth($sql); @@ -1371,6 +1376,7 @@ sub insert_bulk { $placeholder_index++; } my $rv = eval { $sth->execute_array({ArrayTupleStatus => $tuple_status}) }; + $sth->finish; if (my $err = $@) { my $i = 0; ++$i while $i <= $#$tuple_status && !ref $tuple_status->[$i]; diff --git a/lib/DBIx/Class/Storage/DBI/Sybase.pm b/lib/DBIx/Class/Storage/DBI/Sybase.pm index f6073cb..a4cdaba 100644 --- a/lib/DBIx/Class/Storage/DBI/Sybase.pm +++ b/lib/DBIx/Class/Storage/DBI/Sybase.pm @@ -18,6 +18,9 @@ __PACKAGE__->mk_group_accessors('simple' => ); my @also_proxy_to_writer_storage = qw/ + connect_call_set_auto_cast auto_cast connect_call_blob_setup + connect_call_datetime_setup + disconnect _connect_info _sql_maker _sql_maker_opts disable_sth_caching auto_savepoint unsafe cursor_class debug debugobj schema /; @@ -124,12 +127,14 @@ sub _init { $writer_storage->_is_writer_storage(1); $writer_storage->connect_info($self->connect_info); + $writer_storage->auto_cast($self->auto_cast); $self->_writer_storage($writer_storage); } for my $method (@also_proxy_to_writer_storage) { no strict 'refs'; + no warnings 'redefine'; my $replaced = __PACKAGE__->can($method); @@ -467,6 +472,9 @@ sub _unset_identity_insert { $self->_query_end($sql); } +# for tests +sub _can_insert_bulk { 1 } + # XXX this should use the DBD::Sybase bulk API, where possible sub insert_bulk { my $self = shift; diff --git a/lib/DBIx/Class/Storage/DBI/Sybase/NoBindVars.pm b/lib/DBIx/Class/Storage/DBI/Sybase/NoBindVars.pm index 32908ee..ebb1dcc 100644 --- a/lib/DBIx/Class/Storage/DBI/Sybase/NoBindVars.pm +++ b/lib/DBIx/Class/Storage/DBI/Sybase/NoBindVars.pm @@ -59,6 +59,9 @@ sub _prep_interpolated_value { return $value; } +# for tests +sub _can_insert_bulk { 0 } + 1; =head1 NAME diff --git a/t/746sybase.t b/t/746sybase.t index 84ed68a..0c1130c 100644 --- a/t/746sybase.t +++ b/t/746sybase.t @@ -204,71 +204,80 @@ SQL $ping_count-- if $@; } - -# test insert_bulk using populate, this should always pass whether or not it -# does anything Sybase specific or not. Just here to aid debugging. - lives_ok { - $schema->resultset('Artist')->populate([ - { - name => 'bulk artist 1', - charfield => 'foo', - }, - { - name => 'bulk artist 2', - charfield => 'foo', - }, - { - name => 'bulk artist 3', - charfield => 'foo', - }, - ]); - } 'insert_bulk via populate'; - my $bulk_rs = $schema->resultset('Artist')->search({ name => { -like => 'bulk artist %' } }); - is $bulk_rs->count, 3, 'correct number inserted via insert_bulk'; - - is ((grep $_->charfield eq 'foo', $bulk_rs->all), 3, - 'column set correctly via insert_bulk'); - - my %bulk_ids; - @bulk_ids{map $_->artistid, $bulk_rs->all} = (); - - is ((scalar keys %bulk_ids), 3, - 'identities generated correctly in insert_bulk'); +# test insert_bulk using populate, this should always pass whether or not it +# does anything Sybase specific or not. Just here to aid debugging. + SKIP: { + skip 'insert_bulk not supported', 4 + unless $schema->storage->_can_insert_bulk; - $bulk_rs->delete; + lives_ok { + $schema->resultset('Artist')->populate([ + { + name => 'bulk artist 1', + charfield => 'foo', + }, + { + name => 'bulk artist 2', + charfield => 'foo', + }, + { + name => 'bulk artist 3', + charfield => 'foo', + }, + ]); + } 'insert_bulk via populate'; + + is $bulk_rs->count, 3, 'correct number inserted via insert_bulk'; + + is ((grep $_->charfield eq 'foo', $bulk_rs->all), 3, + 'column set correctly via insert_bulk'); + + my %bulk_ids; + @bulk_ids{map $_->artistid, $bulk_rs->all} = (); + + is ((scalar keys %bulk_ids), 3, + 'identities generated correctly in insert_bulk'); + + $bulk_rs->delete; + } # now test insert_bulk with IDENTITY_INSERT - lives_ok { - $schema->resultset('Artist')->populate([ - { - artistid => 2001, - name => 'bulk artist 1', - charfield => 'foo', - }, - { - artistid => 2002, - name => 'bulk artist 2', - charfield => 'foo', - }, - { - artistid => 2003, - name => 'bulk artist 3', - charfield => 'foo', - }, - ]); - } 'insert_bulk with IDENTITY_INSERT via populate'; - - is $bulk_rs->count, 3, - 'correct number inserted via insert_bulk with IDENTITY_INSERT'; - - is ((grep $_->charfield eq 'foo', $bulk_rs->all), 3, - 'column set correctly via insert_bulk with IDENTITY_INSERT'); - - $bulk_rs->delete; + SKIP: { + skip 'insert_bulk not supported', 3 + unless $schema->storage->_can_insert_bulk; + + lives_ok { + $schema->resultset('Artist')->populate([ + { + artistid => 2001, + name => 'bulk artist 1', + charfield => 'foo', + }, + { + artistid => 2002, + name => 'bulk artist 2', + charfield => 'foo', + }, + { + artistid => 2003, + name => 'bulk artist 3', + charfield => 'foo', + }, + ]); + } 'insert_bulk with IDENTITY_INSERT via populate'; + + is $bulk_rs->count, 3, + 'correct number inserted via insert_bulk with IDENTITY_INSERT'; + + is ((grep $_->charfield eq 'foo', $bulk_rs->all), 3, + 'column set correctly via insert_bulk with IDENTITY_INSERT'); + + $bulk_rs->delete; + } # test correlated subquery my $subq = $schema->resultset('Artist')->search({ artistid => { '>' => 3 } }) @@ -281,7 +290,7 @@ SQL # mostly stolen from the blob stuff Nniuq wrote for t/73oracle.t SKIP: { - skip 'TEXT/IMAGE support does not work with FreeTDS', 16 + skip 'TEXT/IMAGE support does not work with FreeTDS', 15 if $schema->storage->using_freetds; my $dbh = $schema->storage->_dbh; @@ -401,10 +410,7 @@ SQL }); # test insert transaction when there's an active cursor - SKIP: { - skip 'not testing insert with active cursor if using ::NoBindVars', 1 - if $storage_type =~ /NoBindVars/i; - + { my $artist_rs = $schema->resultset('Artist'); $artist_rs->first; lives_ok {