Browse Source

execute_batch command implementation

Anton Lebedevich 13 years ago
parent
commit
c03eb1488e
1 changed files with 19 additions and 0 deletions
  1. 19 0
      src/pgsql_sock.erl

+ 19 - 0
src/pgsql_sock.erl

@@ -182,6 +182,25 @@ command({execute, _Statement, PortalName, MaxRows}, State) ->
     send(State, $H, []),
     send(State, $H, []),
     {noreply, State};
     {noreply, State};
 
 
+command({execute_batch, Batch}, State) ->
+    #state{mod = Mod, sock = Sock} = State,
+    do_send(
+      Mod, Sock,
+      lists:map(
+        fun({Statement, PortalName, Parameters, MaxRows}) ->
+                #statement{name = StatementName,
+                           columns = Columns,
+                           types = Types} = Statement,
+                Typed_Parameters = lists:zip(Types, Parameters),
+                Bin1 = pgsql_wire:encode_parameters(Typed_Parameters),
+                Bin2 = pgsql_wire:encode_formats(Columns),
+                [pgsql_wire:encode($B, [PortalName, 0, StatementName, 0,
+                                        Bin1, Bin2]),
+                 pgsql_wire:encode($E, [PortalName, 0, <<MaxRows:?int32>>])]
+        end,
+        Batch)),
+    {noreply, State};
+
 command({describe_statement, Name}, State) ->
 command({describe_statement, Name}, State) ->
     send(State, $D, [$S, Name, 0]),
     send(State, $D, [$S, Name, 0]),
     send(State, $H, []),
     send(State, $H, []),