From: Matt S Trout Date: Sat, 17 Sep 2005 14:50:30 +0000 (+0000) Subject: Added quote char test, supported quoting in S::A subclass for joins X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2a8168143cea9db25fc7531f08c84b01ef4cf395;p=dbsrgits%2FDBIx-Class-Historic.git Added quote char test, supported quoting in S::A subclass for joins --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 6b96ba5..e08fa7d 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -12,12 +12,7 @@ package DBIC::SQL::Abstract; # Temporary. Merge upstream. use base qw/SQL::Abstract::Limit/; -sub select { - my ($self, $ident, @rest) = @_; - return $self->SUPER::select($self->from($ident), @rest); -} - -sub from { +sub _table { my ($self, $from) = @_; if (ref $from eq 'ARRAY') { return $self->_recurse_from(@$from); @@ -56,7 +51,8 @@ sub _recurse_from { sub _make_as { my ($self, $from) = @_; - return join(' ', reverse each %{$self->_skip_options($from)}); + return join(' ', map { $self->_quote($_) } + reverse each %{$self->_skip_options($from)}); } sub _skip_options { @@ -71,10 +67,16 @@ sub _join_condition { my ($self, $cond) = @_; die "no chance" unless ref $cond eq 'HASH'; my %j; - for (keys %$cond) { my $x = '= '.$cond->{$_}; $j{$_} = \$x; }; + for (keys %$cond) { my $x = '= '.$self->_quote($cond->{$_}); $j{$_} = \$x; }; return $self->_recurse_where(\%j); } +sub _quote { + my ($self, $label) = @_; + return '' unless defined $label; + return $self->SUPER::_quote($label); +} + } # End of BEGIN block use base qw/DBIx::Class/; diff --git a/t/19quotes.t b/t/19quotes.t new file mode 100644 index 0000000..a312e35 --- /dev/null +++ b/t/19quotes.t @@ -0,0 +1,24 @@ +use strict; +use Test::More; +use IO::File; + +BEGIN { + eval "use DBD::SQLite"; + plan $@ + ? ( skip_all => 'needs DBD::SQLite for testing' ) + : ( tests => 2 ); +} + +use lib qw(t/lib); + +use_ok('DBICTest'); + +DBICTest::_db->storage->sql_maker->{'quote_char'} = q!'!; +DBICTest::_db->storage->sql_maker->{'name_sep'} = '.'; + +my $rs = DBICTest::CD->search( + { 'year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, + { join => 'artist' }); + +cmp_ok( $rs->count, '==', 1, "join with fields quoted"); +