X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FAbstract.pm;fp=lib%2FSQL%2FAbstract.pm;h=dd55fb43f1d16444b3747ad9303d3be3d6c3cbf8;hb=fe3c2cecf9514bf0b9d1c6db3a0b7cb61d710f83;hp=bd512cac7307a3efda1e133d5bbddbbecd1cd9c1;hpb=daa4ccdd1890db8dd6b15a512a2c4f91617aa5fb;p=dbsrgits%2FSQL-Abstract.git diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index bd512ca..dd55fb4 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -330,12 +330,25 @@ sub _insert_value { push @all_bind, @bind; }, - # THINK: anything useful to do with a HASHREF ? - HASHREF => sub { # (nothing, but old SQLA passed it through) - #TODO in SQLA >= 2.0 it will die instead - belch "HASH ref as bind value in insert is not supported"; - push @values, '?'; - push @all_bind, $self->_bindtype($column, $v); + HASHREF => sub { + my ($op, $arg, @rest) = %$v; + + if (@rest or not $op =~ /^\-(.+)/) { + #TODO in SQLA >= 2.0 it will die instead + belch "Operator calls in insert must be in the form { -op => $arg }, if you wanted a plain HASH ref as a bind value, please use -value"; + push @values, '?'; + push @all_bind, $self->_bindtype($column, $v); + return; + } + + # column may be undef and this currently triggers a croak in + # _where_unary_op for the potentially-sane-here -ident and -value + # (we should probably improve the test for the croak) + local $self->{_nested_func_lhs} = $column || 'INSERT_ANON_COLUMN_NAME'; + my ($sql, @bind) = $self->_where_unary_op($1, $arg); + + push @values, $sql; + push @all_bind, @bind; }, SCALARREF => sub { # literal SQL without bind