[Bast-commits] r6500 - in DBIx-Class/0.08/branches/sybase:
lib/DBIx/Class/Storage lib/DBIx/Class/Storage/DBI
lib/DBIx/Class/Storage/DBI/Sybase t
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Thu Jun 4 12:50:49 GMT 2009
Author: caelum
Date: 2009-06-04 12:50:49 +0000 (Thu, 04 Jun 2009)
New Revision: 6500
Modified:
DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI.pm
DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase.pm
DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase/Microsoft_SQL_Server.pm
DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase/NoBindVars.pm
DBIx-Class/0.08/branches/sybase/t/746sybase.t
Log:
sybase limit count without offset now works
Modified: DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase/Microsoft_SQL_Server.pm
===================================================================
--- DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase/Microsoft_SQL_Server.pm 2009-06-04 09:55:52 UTC (rev 6499)
+++ DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase/Microsoft_SQL_Server.pm 2009-06-04 12:50:49 UTC (rev 6500)
@@ -3,6 +3,7 @@
use strict;
use warnings;
+use Class::C3;
use base qw/
DBIx::Class::Storage::DBI::ODBC::Microsoft_SQL_Server
DBIx::Class::Storage::DBI::NoBindVars
@@ -33,10 +34,8 @@
=head1 AUTHORS
-Brandon L Black <blblack at gmail.com>
+See L<DBIx::Class/CONTRIBUTORS>.
-Justin Hunter <justin.d.hunter at gmail.com>
-
=head1 LICENSE
You may distribute this code under the same terms as Perl itself.
Modified: DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase/NoBindVars.pm
===================================================================
--- DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase/NoBindVars.pm 2009-06-04 09:55:52 UTC (rev 6499)
+++ DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase/NoBindVars.pm 2009-06-04 12:50:49 UTC (rev 6500)
@@ -1,5 +1,6 @@
package DBIx::Class::Storage::DBI::Sybase::NoBindVars;
+use Class::C3;
use base qw/
DBIx::Class::Storage::DBI::NoBindVars
DBIx::Class::Storage::DBI::Sybase
Modified: DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase.pm
===================================================================
--- DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase.pm 2009-06-04 09:55:52 UTC (rev 6499)
+++ DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase.pm 2009-06-04 12:50:49 UTC (rev 6500)
@@ -59,6 +59,36 @@
return ($dbh->selectrow_array($sth))[0];
}
+sub count {
+ my ($self, $source, $attrs) = @_;
+
+ if (exists $attrs->{rows}) {
+ my $new_attrs = $self->_trim_attributes_for_count($source, $attrs);
+
+ $new_attrs->{select} = '1';
+ $new_attrs->{as} = ['dummy'];
+
+# speed things up at least *a little*
+ $new_attrs->{result_class} = 'DBIx::Class::ResultClass::HashRefInflator';
+
+ my $offset = $attrs->{offset} || 0;
+ my $total = $attrs->{rows} + $offset;
+
+ $self->dbh->do("set rowcount $total");
+
+ my $tmp_rs = $source->resultset_class->new($source, $new_attrs);
+
+ my $count = 0;
+ $count++ while $tmp_rs->cursor->next;
+
+ $self->dbh->do("set rowcount 0");
+
+ return $count;
+ }
+
+ return $self->next::method(@_);
+}
+
sub datetime_parser_type { "DBIx::Class::Storage::DBI::Sybase::DateTime" }
1;
@@ -90,6 +120,9 @@
C<2004-08-21T14:36:48.080Z> and C<dateformat> is set to C<mdy>, e.g.:
C<08/13/1979 18:08:55.080>.
+This works for both C<DATETIME> and C<SMALLDATETIME> columns, although
+C<SMALLDATETIME> columns only have minute precision.
+
You will need the L<DateTime::Format::Strptime> module if you are going to use
L<DBIx::Class::InflateColumn::DateTime>.
Modified: DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI.pm 2009-06-04 09:55:52 UTC (rev 6499)
+++ DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI.pm 2009-06-04 12:50:49 UTC (rev 6500)
@@ -926,6 +926,22 @@
} @bind;
}
+sub _flatten_bind_params {
+ my ($self, @bind) = @_;
+
+ ### Turn @bind from something like this:
+ ### ( [ "artist", 1 ], [ "cdid", 1, 3 ] )
+ ### to this:
+ ### ( 1, 1, 3 )
+ return
+ map {
+ if ( defined( $_ && $_->[1] ) ) {
+ @{$_}[ 1 .. $#$_ ];
+ }
+ else { undef; }
+ } @bind;
+}
+
sub _query_start {
my ( $self, $sql, @bind ) = @_;
@@ -1229,16 +1245,25 @@
return @args;
}
-sub count {
+sub _trim_attributes_for_count {
my ($self, $source, $attrs) = @_;
+ my %attrs = %$attrs;
# take off any column specs, any pagers, record_filter is cdbi, and no point of ordering a count
- delete $attrs->{$_} for (qw/columns +columns select +select as +as rows offset page pager order_by record_filter/);
+ delete $attrs{$_} for (qw/columns +columns select +select as +as rows offset page pager order_by record_filter/);
- $attrs->{select} = { count => '*' };
- $attrs->{as} = [qw/count/];
+ return \%attrs;
+}
- my $tmp_rs = $source->resultset_class->new($source, $attrs);
+sub count {
+ my ($self, $source, $attrs) = @_;
+
+ my $new_attrs = $self->_trim_attributes_for_count($source, $attrs);
+
+ $new_attrs->{select} = { count => '*' };
+ $new_attrs->{as} = [qw/count/];
+
+ my $tmp_rs = $source->resultset_class->new($source, $new_attrs);
my ($count) = $tmp_rs->cursor->next;
return $count;
Modified: DBIx-Class/0.08/branches/sybase/t/746sybase.t
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/746sybase.t 2009-06-04 09:55:52 UTC (rev 6499)
+++ DBIx-Class/0.08/branches/sybase/t/746sybase.t 2009-06-04 12:50:49 UTC (rev 6500)
@@ -62,17 +62,16 @@
$seen_id{$new->artistid}++;
}
- my $it = $schema->resultset('Artist')->search( {}, {
+## avoid quoting bug with NoBindVars for now
+# my $it = $schema->resultset('Artist')->search({artistid => { '>' => 0 }}, {
+
+ my $it = $schema->resultset('Artist')->search({}, {
rows => 3,
order_by => 'artistid',
});
- TODO: {
- local $TODO = 'Sybase is very very fucked in the limit department';
+ is( $it->count, 3, "LIMIT count ok" );
- is( $it->count, 3, "LIMIT count ok" );
- }
-
is( $it->next->name, "foo", "iterator->next ok" );
$it->next;
is( $it->next->name, "Artist 2", "iterator->next ok" );
More information about the Bast-commits
mailing list