@@ -140,15 +140,15 @@ defmodule Ecto.Adapters.SQL do
140140 def autogenerate ( :binary_id ) , do: Ecto.UUID . bingenerate ( )
141141
142142 @ impl true
143- def insert_all ( adapter_meta , schema_meta , header , rows , on_conflict , returning , opts ) do
144- Ecto.Adapters.SQL . insert_all ( adapter_meta , schema_meta , @ conn , header , rows , on_conflict , returning , opts )
143+ def insert_all ( adapter_meta , schema_meta , header , rows , on_conflict , returning , placeholders , opts ) do
144+ Ecto.Adapters.SQL . insert_all ( adapter_meta , schema_meta , @ conn , header , rows , on_conflict , returning , placeholders , opts )
145145 end
146146
147147 @ impl true
148148 def insert ( adapter_meta , % { source: source , prefix: prefix } , params ,
149149 { kind , conflict_params , _ } = on_conflict , returning , opts ) do
150150 { fields , values } = :lists . unzip ( params )
151- sql = @ conn . insert ( prefix , source , fields , [ fields ] , on_conflict , returning )
151+ sql = @ conn . insert ( prefix , source , fields , [ fields ] , on_conflict , returning , [ ] )
152152 Ecto.Adapters.SQL . struct ( adapter_meta , @ conn , sql , :insert , source , [ ] , values ++ conflict_params , kind , returning , opts )
153153 end
154154
@@ -191,7 +191,7 @@ defmodule Ecto.Adapters.SQL do
191191 Ecto.Adapters.SQL . execute_ddl ( meta , @ conn , definition , opts )
192192 end
193193
194- defoverridable [ prepare: 2 , execute: 5 , insert: 6 , update: 6 , delete: 4 , insert_all: 7 ,
194+ defoverridable [ prepare: 2 , execute: 5 , insert: 6 , update: 6 , delete: 4 , insert_all: 8 ,
195195 execute_ddl: 3 , loaders: 2 , dumpers: 2 , autogenerate: 1 ,
196196 ensure_all_started: 2 , __before_compile__: 1 ]
197197 end
@@ -639,16 +639,18 @@ defmodule Ecto.Adapters.SQL do
639639 ## Query
640640
641641 @ doc false
642- def insert_all ( adapter_meta , schema_meta , conn , header , rows , on_conflict , returning , opts ) do
642+ def insert_all ( adapter_meta , schema_meta , conn , header , rows , on_conflict , returning , placeholders , opts ) do
643643 % { source: source , prefix: prefix } = schema_meta
644644 { _ , conflict_params , _ } = on_conflict
645645 { rows , params } = unzip_inserts ( header , rows )
646- sql = conn . insert ( prefix , source , header , rows , on_conflict , returning )
646+
647+ sql = conn . insert ( prefix , source , header , rows , on_conflict , returning , placeholders )
647648
648649 opts = [ { :cache_statement , "ecto_insert_all_#{ source } " } | opts ]
649650
651+ all_params = placeholders ++ Enum . reverse ( params , conflict_params )
650652 % { num_rows: num , rows: rows } =
651- query! ( adapter_meta , sql , Enum . reverse ( params ) ++ conflict_params , opts )
653+ query! ( adapter_meta , sql , all_params , opts )
652654
653655 { num , rows }
654656 end
@@ -658,10 +660,12 @@ defmodule Ecto.Adapters.SQL do
658660 Enum . map_reduce header , params , fn key , acc ->
659661 case :lists . keyfind ( key , 1 , fields ) do
660662 { ^ key , { % Ecto.Query { } = query , query_params } } ->
661- { { query , length ( query_params ) } , Enum . reverse ( query_params ) ++ acc }
663+ { { query , length ( query_params ) } , Enum . reverse ( query_params , acc ) }
664+
665+ { ^ key , { :placeholder , placeholder_index } } ->
666+ { { :placeholder , Integer . to_string ( placeholder_index ) } , acc }
662667
663- { ^ key , value } ->
664- { key , [ value | acc ] }
668+ { ^ key , value } -> { key , [ value | acc ] }
665669
666670 false -> { nil , acc }
667671 end
0 commit comments