use DBIx::Class::Exception;
use namespace::clean;
-__PACKAGE__->mk_group_accessors (simple => qw/quote_char name_sep limit_dialect/);
+__PACKAGE__->mk_group_accessors (simple => qw/quote_char name_sep limit_dialect storage/);
# for when I need a normalized l/r pair
sub _quote_chars {
# poor man's de-qualifier
sub _quote {
- $_[0]->next::method( ( $_[0]{_dequalify_idents} and ! ref $_[1] )
+ return undef if not defined $_[1];
+
+ my $col = ( $_[0]{_dequalify_idents} and ! ref $_[1] )
? $_[1] =~ / ([^\.]+) $ /x
: $_[1]
- );
+ ;
+
+ if (
+ $_[0]->{FROM}
+ and
+ $_[0]->storage
+ and
+ my $alias = ($_[0]->storage->_resolve_column_info($_[0]->{FROM}, [$col]) || {})->{$col}{sql_alias}
+ ) {
+ $col =~ s/[^\.]+$/$alias/;
+ }
+
+ $_[0]->next::method( $col );
}
sub _where_op_NEST {
my ($self, $table, $fields, $where, $rs_attrs, $limit, $offset) = @_;
+ local $self->{FROM} = $table;
$fields = $self->_recurse_fields($fields);
if (defined $offset) {
# optimized due to hotttnesss
# my ($self, $table, $data, $options) = @_;
+ local $_[0]->{FROM} = $_[1];
# SQLA will emit INSERT INTO $table ( ) VALUES ( )
# which is sadly understood only by MySQL. Change default behavior here,
# until SQLA2 comes with proper dialect support
next::method(@_);
}
+sub update {
+ local $_[0]->{FROM} = $_[1];
+
+ shift->next::method(@_);
+}
+
+sub delete {
+
+ shift->next::method(@_);
+}
+
sub _recurse_fields {
my ($self, $fields) = @_;
my $ref = ref $fields;
}
$self->_sql_maker($sql_maker_class->new(
- bindtype=>'columns',
+ bindtype => 'columns',
array_datatypes => 1,
limit_dialect => $dialect,
($quote_char ? (quote_char => $quote_char) : ()),
name_sep => ($name_sep || '.'),
+ storage => $self,
%opts,
));
+
+ weaken($self->_sql_maker->{storage});
}
+
return $self->_sql_maker;
}
__PACKAGE__->load_classes(qw/
Artist
+ BadNames1
SequenceTest
BindType
Employee
--- /dev/null
+package # hide from PAUSE
+ DBICTest::Schema::BadNames1;
+
+use base qw/DBICTest::BaseResult/;
+
+__PACKAGE__->table('bad_names_1');
+
+__PACKAGE__->add_columns(
+ id => {
+ data_type => 'integer',
+ is_auto_increment => 1,
+ },
+ 'good_name' => {
+ data_type => 'int',
+ is_nullable => 1,
+ sql_alias => 'stupid_name',
+ },
+);
+__PACKAGE__->set_primary_key('id');
+1;
--- /dev/null
+use strict;
+use warnings;
+
+use Test::More;
+
+use lib qw(t/lib);
+use DBIC::SqlMakerTest;
+
+
+use_ok('DBICTest');
+use_ok('DBIC::DebugObj');
+my $schema = DBICTest->init_schema();
+
+my ($sql, @bind);
+$schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind));
+$schema->storage->debug(1);
+
+my $rs = $schema->resultset('BadNames1');
+
+eval {
+ $rs->create({ good_name => 2002, })
+};
+
+is_same_sql_bind(
+ $sql, \@bind,
+ "INSERT INTO bad_names_1( stupid_name ) VALUES ( ? )", ["'2002'"],
+ 'insert'
+);
+
+eval {
+ $rs->search({ 'me.good_name' => 2001 })->all
+};
+
+is_same_sql_bind(
+ $sql, \@bind,
+ "SELECT me.id, me.stupid_name FROM bad_names_1 me WHERE ( me.stupid_name = ? )", ["'2001'"],
+ 'select'
+);
+
+eval {
+ $rs->search({ 'me.good_name' => 2001 })->update({ good_name => 2112 })
+};
+
+
+is_same_sql_bind(
+ $sql, \@bind,
+ "UPDATE bad_names_1 SET stupid_name = ? WHERE ( stupid_name = ? )", ["'2112'", "'2001'"],
+ 'update'
+);
+
+eval {
+ $rs->search({ 'me.good_name' => 2001 })->delete
+};
+
+is_same_sql_bind(
+ $sql, \@bind,
+ "DELETE FROM bad_names_1 WHERE ( me.stupid_name = ? )", ["'2001'"],
+ 'delete'
+);
+
+done_testing;