From: Dagfinn Ilmari Mannsåker Date: Sat, 23 Mar 2013 10:18:46 +0000 (+0000) Subject: Render empty insert value lists as DEFAULT VALUES X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7d0fb8c009ffee4dccc9372bfb163ca774fbc6f1;p=dbsrgits%2FData-Query.git Render empty insert value lists as DEFAULT VALUES Except for MySQL, which is Special™, as usual. --- diff --git a/lib/Data/Query/Renderer/SQL/MySQL.pm b/lib/Data/Query/Renderer/SQL/MySQL.pm new file mode 100644 index 0000000..9120e0f --- /dev/null +++ b/lib/Data/Query/Renderer/SQL/MySQL.pm @@ -0,0 +1,14 @@ +package Data::Query::Renderer::SQL::MySQL; + +use Moo; + +extends 'Data::Query::Renderer::SQL::Naive'; + +with 'Data::Query::Renderer::SQL::Slice::LimitXY'; + +sub _insert_default_values { + my ($self) = @_; + $self->_format_keyword('VALUES'), qw( ( ) ); +} + +1; diff --git a/lib/Data/Query/Renderer/SQL/Naive.pm b/lib/Data/Query/Renderer/SQL/Naive.pm index fb18512..6626002 100644 --- a/lib/Data/Query/Renderer/SQL/Naive.pm +++ b/lib/Data/Query/Renderer/SQL/Naive.pm @@ -463,11 +463,13 @@ sub _render_insert { ($names ? ('(', intersperse(',', map $self->_render($_), @$names), ')') : ()), - $self->_format_keyword('VALUES'), - intersperse(',', - map [ '(', intersperse(',', map $self->_render($_), @$_), ')' ], - @$values - ), + (@$values && @{$values->[0]} + ? ($self->_format_keyword('VALUES'), + intersperse(',', + map [ '(', intersperse(',', map $self->_render($_), @$_), ')' ], + @$values + )) + : ($self->_insert_default_values)), ($returning ? ($self->_format_keyword('RETURNING'), intersperse(',', map $self->_render($_), @$returning)) @@ -475,4 +477,9 @@ sub _render_insert { ]; } +sub _insert_default_values { + my ($self) = @_; + $self->_format_keyword('DEFAULT VALUES'), +} + 1;