Permalink
Browse files

add more storages to ::ResultSet::Random (RT82110)

  • Loading branch information...
1 parent 9207659 commit 69f669880cbd732aaf1621f8cdb395da430a7db4 José Diaz Seng committed with Jan 5, 2013
Showing with 35 additions and 1 deletion.
  1. +1 −0 Changes
  2. +34 −1 lib/DBIx/Class/Helper/ResultSet/Random.pm
View
@@ -1,6 +1,7 @@
Revision history for {{$dist->name}}
{{$NEXT}}
+ - Add more storages for ::ResultSet::Random (Thanks José Diaz Seng!)
2.016003 2012-12-07 15:54:29 CST6CDT
- Fix bug in dup_check_source_auto and fk_check_source_auto. If
@@ -13,12 +13,45 @@ my %rand_order_by = (
'DBIx::Class::Storage::DBI::MSSQL' => 'NEWID()',
'DBIx::Class::Storage::DBI::Pg' => 'RANDOM()',
'DBIx::Class::Storage::DBI::Oracle' => 'dbms_random.value',
+ 'DBIx::Class::Storage::DBI::Sybase::MSSQL' => 'NEWID()',
+ 'DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::NoBindVars' =>
+ 'NEWID()',
+ 'DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server' => 'NEWID()',
+ 'DBIx::Class::Storage::DBI::Sybase::ASE::NoBindVars' => 'RAND()',
+ 'DBIx::Class::Storage::DBI::Sybase::ASE' => 'RAND()',
+ 'DBIx::Class::Storage::DBI::Sybase' => 'RAND()',
+ 'DBIx::Class::Storage::DBI::SQLAnywhere' => 'RAND()',
+ 'DBIx::Class::Storage::DBI::Oracle::WhereJoins' => 'dbms_random.value',
+ 'DBIx::Class::Storage::DBI::Oracle::Generic' => 'dbms_random.value',
+ 'DBIx::Class::Storage::DBI::ODBC::SQL_Anywhere' => 'RAND()',
+ 'DBIx::Class::Storage::DBI::ODBC::Firebird' => 'RAND()',
+ 'DBIx::Class::Storage::DBI::ODBC::ACCESS' => 'RND()',
+ 'DBIx::Class::Storage::DBI::mysql::backup' => 'RAND()',
+ 'DBIx::Class::Storage::DBI::InterBase' => 'RAND()',
+ 'DBIx::Class::Storage::DBI::Firebird::Common' => 'RAND()',
+ 'DBIx::Class::Storage::DBI::Firebird' => 'RAND()',
+ 'DBIx::Class::Storage::DBI::DB2' => 'RAND()',
+ 'DBIx::Class::Storage::DBI::ADO::MS_Jet' => 'RND()',
+ 'DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server' => 'NEWID()',
+ 'DBIx::Class::Storage::DBI::ACCESS' => 'RND()',
);
+{
+#sort keys descending to handle more specific storage classes first
+#(right now it does not make a difference though)
+my @keys_rand_order_by = sort { $b cmp $a } keys %rand_order_by;
+
sub _rand_order_by {
my $self = shift;
$self->result_source->storage->_determine_driver;
- return $rand_order_by{ref $self->result_source->storage} || 'RAND()';
+ my $storage = $self->result_source->storage;
+
+ for my $dbms (@keys_rand_order_by) {
+ return $rand_order_by{$dbms} if $storage->isa($dbms);
+ }
+
+ return 'RAND()';
+}
}
sub rand {

0 comments on commit 69f6698

Please sign in to comment.