From: Matt S Trout Date: Sat, 13 Oct 2012 19:58:39 +0000 (+0000) Subject: make setting limit_dialect do something useful again X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9f5e77ee0ef814895cecdcb1cb898278fb5818d0;p=dbsrgits%2FDBIx-Class-Historic.git make setting limit_dialect do something useful again --- diff --git a/lib/DBIx/Class/SQLMaker.pm b/lib/DBIx/Class/SQLMaker.pm index b14dd6d..94fe0f6 100644 --- a/lib/DBIx/Class/SQLMaker.pm +++ b/lib/DBIx/Class/SQLMaker.pm @@ -41,13 +41,25 @@ use base qw/ /; use mro 'c3'; +use Module::Runtime qw(use_module); use Sub::Name 'subname'; use DBIx::Class::Carp; use DBIx::Class::Exception; use Moo; use namespace::clean; -has limit_dialect => (is => 'rw', trigger => sub { shift->clear_renderer }); +has limit_dialect => ( + is => 'rw', default => sub { 'LimitOffset' }, + trigger => sub { shift->clear_renderer_class } +); + +around _build_renderer_class => sub { + my ($orig, $self) = (shift, shift); + use_module('Moo::Role')->create_class_with_roles( + $self->$orig(@_), + 'Data::Query::Renderer::SQL::Slice::'.$self->limit_dialect + ); +}; has limit_requires_order_by_stability_check => (is => 'rw', default => sub { 0 }); diff --git a/lib/DBIx/Class/SQLMaker/SQLite.pm b/lib/DBIx/Class/SQLMaker/SQLite.pm index ce719ba..cf4b8fa 100644 --- a/lib/DBIx/Class/SQLMaker/SQLite.pm +++ b/lib/DBIx/Class/SQLMaker/SQLite.pm @@ -3,9 +3,9 @@ package # Hide from PAUSE use base qw( DBIx::Class::SQLMaker ); -sub _build_renderer_class { - Module::Runtime::use_module('Data::Query::Renderer::SQL::SQLite') -} +#sub _build_renderer_class { +# Module::Runtime::use_module('Data::Query::Renderer::SQL::SQLite') +#} # # SQLite does not understand SELECT ... FOR UPDATE diff --git a/t/53lean_startup.t b/t/53lean_startup.t index 4542e6f..23d03e9 100644 --- a/t/53lean_startup.t +++ b/t/53lean_startup.t @@ -60,6 +60,7 @@ BEGIN { Class::C3::Componentised Moo Sub::Quote + Module::Runtime Data::Query::Constants /, $] < 5.010 ? ( 'Class::C3', 'MRO::Compat' ) : () }; # this is special-cased in DBIx/Class.pm diff --git a/t/sqlmaker/limit_dialects/fetch_first.t b/t/sqlmaker/limit_dialects/fetch_first.t index 58ee3f8..b1ba9de 100644 --- a/t/sqlmaker/limit_dialects/fetch_first.t +++ b/t/sqlmaker/limit_dialects/fetch_first.t @@ -10,12 +10,7 @@ my $schema = DBICTest->init_schema; # based on toplimit.t delete $schema->storage->_sql_maker->{_cached_syntax}; -$schema->storage->_sql_maker->renderer_class( - Moo::Role->create_class_with_roles(qw( - Data::Query::Renderer::SQL::Naive - Data::Query::Renderer::SQL::Slice::FetchFirst - )) -); +$schema->storage->_sql_maker->limit_dialect('FetchFirst'); $schema->storage->_sql_maker->limit_requires_order_by_stability_check(1); $schema->storage->_sql_maker->limit_enforces_order_by_stability(1); diff --git a/t/sqlmaker/limit_dialects/first_skip.t b/t/sqlmaker/limit_dialects/first_skip.t index 57894a8..91a8dfc 100644 --- a/t/sqlmaker/limit_dialects/first_skip.t +++ b/t/sqlmaker/limit_dialects/first_skip.t @@ -14,12 +14,7 @@ my ($LIMIT, $OFFSET) = ( my $schema = DBICTest->init_schema; -$schema->storage->_sql_maker->renderer_class( - Moo::Role->create_class_with_roles(qw( - Data::Query::Renderer::SQL::Naive - Data::Query::Renderer::SQL::Slice::FirstSkip - )) -); +$schema->storage->_sql_maker->limit_dialect('FirstSkip'); my $rs_selectas_col = $schema->resultset ('BooksInLibrary')->search ({}, { '+select' => ['owner.name'], diff --git a/t/sqlmaker/limit_dialects/generic_subq.t b/t/sqlmaker/limit_dialects/generic_subq.t index e387389..54bdd85 100644 --- a/t/sqlmaker/limit_dialects/generic_subq.t +++ b/t/sqlmaker/limit_dialects/generic_subq.t @@ -15,12 +15,7 @@ my ($ROWS, $TOTAL, $OFFSET) = ( my $schema = DBICTest->init_schema; -$schema->storage->_sql_maker->renderer_class( - Moo::Role->create_class_with_roles(qw( - Data::Query::Renderer::SQL::Naive - Data::Query::Renderer::SQL::Slice::GenericSubquery - )) -); +$schema->storage->_sql_maker->limit_dialect('GenericSubquery'); my $rs = $schema->resultset ('BooksInLibrary')->search ({}, { '+columns' => [{ owner_name => 'owner.name' }], diff --git a/t/sqlmaker/limit_dialects/rno.t b/t/sqlmaker/limit_dialects/rno.t index 15e33b4..4504d7a 100644 --- a/t/sqlmaker/limit_dialects/rno.t +++ b/t/sqlmaker/limit_dialects/rno.t @@ -14,12 +14,7 @@ my ($TOTAL, $OFFSET) = ( my $schema = DBICTest->init_schema; -$schema->storage->_sql_maker->renderer_class( - Moo::Role->create_class_with_roles(qw( - Data::Query::Renderer::SQL::Naive - Data::Query::Renderer::SQL::Slice::RowNumberOver - )) -); +$schema->storage->_sql_maker->limit_dialect('RowNumberOver'); my $rs_selectas_col = $schema->resultset ('BooksInLibrary')->search ({}, { '+select' => ['owner.name'], diff --git a/t/sqlmaker/limit_dialects/rownum.t b/t/sqlmaker/limit_dialects/rownum.t index 03d7a6f..9cf263c 100644 --- a/t/sqlmaker/limit_dialects/rownum.t +++ b/t/sqlmaker/limit_dialects/rownum.t @@ -16,12 +16,7 @@ my ($TOTAL, $OFFSET, $ROWS) = ( my $schema = DBICTest->init_schema; -$schema->storage->_sql_maker->renderer_class( - Moo::Role->create_class_with_roles(qw( - Data::Query::Renderer::SQL::Naive - Data::Query::Renderer::SQL::Slice::RowNum - )) -); +$schema->storage->_sql_maker->limit_dialect('RowNum'); $schema->storage->_sql_maker->limit_requires_order_by_stability_check(1); diff --git a/t/sqlmaker/limit_dialects/skip_first.t b/t/sqlmaker/limit_dialects/skip_first.t index 8325cc3..bdb5962 100644 --- a/t/sqlmaker/limit_dialects/skip_first.t +++ b/t/sqlmaker/limit_dialects/skip_first.t @@ -14,12 +14,7 @@ my ($LIMIT, $OFFSET) = ( my $schema = DBICTest->init_schema; -$schema->storage->_sql_maker->renderer_class( - Moo::Role->create_class_with_roles(qw( - Data::Query::Renderer::SQL::Naive - Data::Query::Renderer::SQL::Slice::SkipFirst - )) -); +$schema->storage->_sql_maker->limit_dialect('SkipFirst'); my $rs_selectas_col = $schema->resultset ('BooksInLibrary')->search ({}, { '+select' => ['owner.name'], diff --git a/t/sqlmaker/limit_dialects/toplimit.t b/t/sqlmaker/limit_dialects/toplimit.t index 4a9b083..3a80605 100644 --- a/t/sqlmaker/limit_dialects/toplimit.t +++ b/t/sqlmaker/limit_dialects/toplimit.t @@ -11,12 +11,7 @@ my $schema = DBICTest->init_schema; # Trick the sqlite DB to use Top limit emulation # We could test all of this via $sq->$op directly, # but some conditions need a $rsrc -$schema->storage->_sql_maker->renderer_class( - Moo::Role->create_class_with_roles(qw( - Data::Query::Renderer::SQL::Naive - Data::Query::Renderer::SQL::Slice::Top - )) -); +$schema->storage->_sql_maker->limit_dialect('Top'); $schema->storage->_sql_maker->limit_requires_order_by_stability_check(1); $schema->storage->_sql_maker->limit_enforces_order_by_stability(1);