Browse Source

execute_batch: send Sync after series of Bind,Execute

Anton Lebedevich 13 years ago
parent
commit
5142cd76bb
1 changed files with 16 additions and 15 deletions
  1. 16 15
      src/pgsql_sock.erl

+ 16 - 15
src/pgsql_sock.erl

@@ -184,21 +184,22 @@ command({execute, _Statement, PortalName, MaxRows}, State) ->
 
 
 command({execute_batch, Batch}, State) ->
 command({execute_batch, Batch}, State) ->
     #state{mod = Mod, sock = Sock} = 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)),
+    BindExecute =
+        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),
+    Sync = pgsql_wire:encode($S, []),
+    do_send(Mod, Sock, [BindExecute, Sync]),
     {noreply, State};
     {noreply, State};
 
 
 command({describe_statement, Name}, State) ->
 command({describe_statement, Name}, State) ->