From: Matt S Trout Date: Mon, 27 Mar 2006 17:35:26 +0000 (+0000) Subject: Quoting fixes for single-table ops X-Git-Tag: v0.06001~26 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6346a152bc0b64e0bb43fdd58b6431eb935db051;p=dbsrgits%2FDBIx-Class.git Quoting fixes for single-table ops --- diff --git a/Changes b/Changes index 3eef90f..7f51a67 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for DBIx::Class +0.06001 + - Added fix for quoting with single table + 0.06000 - Lots of documentation improvements - Minor tweak to related_resultset to prevent it storing a searched rs diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index a6d50c9..af628e2 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -18,6 +18,7 @@ use base qw/SQL::Abstract::Limit/; sub select { my ($self, $table, $fields, $where, $order, @rest) = @_; + $table = $self->_quote($table) unless ref($table); @rest = (-1) unless defined $rest[0]; local $self->{having_bind} = []; my ($sql, @ret) = $self->SUPER::select( @@ -26,6 +27,27 @@ sub select { return wantarray ? ($sql, @ret, @{$self->{having_bind}}) : $sql; } +sub insert { + my $self = shift; + my $table = shift; + $table = $self->_quote($table) unless ref($table); + $self->SUPER::insert($table, @_); +} + +sub update { + my $self = shift; + my $table = shift; + $table = $self->_quote($table) unless ref($table); + $self->SUPER::update($table, @_); +} + +sub delete { + my $self = shift; + my $table = shift; + $table = $self->_quote($table) unless ref($table); + $self->SUPER::delete($table, @_); +} + sub _emulate_limit { my $self = shift; if ($_[3] == -1) { @@ -90,7 +112,12 @@ sub _table { } elsif (ref $from eq 'HASH') { return $self->_make_as($from); } else { - return $from; + return $from; # would love to quote here but _table ends up getting called + # twice during an ->select without a limit clause due to + # the way S::A::Limit->select works. should maybe consider + # bypassing this and doing S::A::select($self, ...) in + # our select method above. meantime, quoting shims have + # been added to select/insert/update/delete here } } diff --git a/t/19quotes.t b/t/19quotes.t index 18588c8..7a85075 100644 --- a/t/19quotes.t +++ b/t/19quotes.t @@ -6,7 +6,7 @@ BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 6 ); + : ( tests => 7 ); } use lib qw(t/lib); @@ -52,6 +52,13 @@ $rs = DBICTest::CD->search( { join => 'artist' }); cmp_ok($rs->count,'==', 1,"join quoted with brackets."); +my %data = ( + name => 'Bill', + order => '12' +); +DBICTest->schema->storage->sql_maker->quote_char('`'); +DBICTest->schema->storage->sql_maker->name_sep('.'); +cmp_ok(DBICTest->schema->storage->sql_maker->update('group', \%data), 'eq', 'UPDATE `group` SET `name` = ?, `order` = ?', "quoted table names for UPDATE");