Skip to content

Commit

Permalink
Pick SQL for appending in a cleaner way
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Axel 'fREW' Schmidt committed Jan 12, 2014
1 parent 2437a53 commit 685f435
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Revision history for {{$dist->name}}

{{$NEXT}}
- Pick SQL for appending in a cleaner way
- Ditch RT

0.002000 2013-01-21 15:30:32 CST6CDT
Expand Down
3 changes: 3 additions & 0 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
requires 'DBIx::Class' => 0.08196;
requires 'DBIx::Introspector';
requires 'Module::Runtime';
requires 'Try::Tiny';
requires 'DBIx::Class::Helpers' => 2.007004;
requires 'Class::C3::Componentised' => 1.001000;
requires 'SQL::Translator' => 0.11011;
Expand Down
33 changes: 17 additions & 16 deletions lib/DBIx/Class/MaterializedPath.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package DBIx::Class::MaterializedPath;
use strict;
use warnings;

use Module::Runtime 'use_module';
use Try::Tiny;
use base 'DBIx::Class::Helper::Row::OnColumnChange';

use English;
Expand Down Expand Up @@ -85,27 +87,26 @@ sub _install_after_column_change {
}
}

my %concat_operators = (
'DBIx::Class::Storage::DBI::MSSQL' => '+',
);
sub _introspector {
my $d = use_module('DBIx::Introspector')
->new(drivers => '2013-12.01');

$d->decorate_driver_unconnected(MSSQL => concat_sql => sub { '%s + %s' });
$d->decorate_driver_unconnected(mysql => concat_sql => sub { 'CONCAT( %s, %s )' });

$d
}

my $d;
sub _get_concat {
my ($self, $rsrc, @substrings) = @_;

my $format;
my $storage = $rsrc->storage;
$storage->ensure_connected;

if ($rsrc->storage->isa('DBIx::Class::Storage::DBI::mysql')) {
$format = q{CONCAT( %s, %s )};
} else {
my $concat_operator = '||';
for (keys %concat_operators) {
if ($rsrc->storage->isa($_)) {
$concat_operator = $concat_operators{ $_ };
last
}
}
$format = qq{%s $concat_operator %s};
}
$d ||= $self->_introspector;

my $format = try { $d->get($storage->dbh, undef, 'concat_sql') } catch { '%s || %s' };

return sprintf $format, @substrings;
}
Expand Down

0 comments on commit 685f435

Please sign in to comment.