Permalink
Browse files

add support for copy* extended protocol messages

  • Loading branch information...
1 parent 2d8148d commit dea1ecddc640fc80aaec20bfec746b93b91dbb69 @nniclausse nniclausse committed Aug 16, 2011
Showing with 22 additions and 2 deletions.
  1. +15 −0 src/lib/pgsql_proto.erl
  2. +7 −2 src/lib/pgsql_util.erl
View
@@ -36,6 +36,7 @@
-define(PG_CLOSE_COMPLETE, $3).
-define(PG_PORTAL_SUSPENDED, $s).
-define(PG_NO_DATA, $n).
+-define(PG_COPY_RESPONSE, $G).
-export([init/2, idle/2]).
-export([run/1]).
@@ -524,6 +525,14 @@ decode_packet(Code, Packet) ->
Ret(portal_suspended, []);
?PG_CLOSE_COMPLETE ->
Ret(close_complete, []);
+ ?PG_COPY_RESPONSE ->
+ <<FormatCode:8/integer, ColN:16/integer, ColFormat/binary>> = Packet,
+ Format = case FormatCode of
+ 0 -> text;
+ 1 -> binary
+ end,
+ Cols=pgsql_util:int16(ColFormat,[]),
+ Ret(copy_response, {Format,Cols});
$t ->
<<NParams:16/integer, OidsP/binary>> = Packet,
Oids = pgsql_util:oids(OidsP, []),
@@ -554,6 +563,12 @@ encode_message(pass_md5, {User, Password, Salt}) ->
encode($p, Pass);
encode_message(terminate, _) ->
encode($X, <<>>);
+encode_message(copydone, _) ->
+ encode($c, <<>>);
+encode_message(copyfail, Msg) ->
+ encode($f, string(Msg));
+encode_message(copy, Data) ->
+ encode($d, Data );
encode_message(squery, Query) -> % squery as in simple query.
encode($Q, string(Query));
encode_message(close, {Object, Name}) ->
View
@@ -18,7 +18,7 @@
-export([string/1, make_pair/2, split_pair/1]).
-export([split_pair_rec/1]).
-export([count_string/1, to_string/1]).
--export([oids/2, coldescs/2, datacoldescs/3]).
+-export([oids/2, coldescs/2, datacoldescs/3, int16/2]).
-export([decode_row/2, decode_descs/1]).
-export([errordesc/1]).
@@ -145,7 +145,12 @@ oids(<<>>, Oids) ->
lists:reverse(Oids);
oids(<<Oid:32/integer, Rest/binary>>, Oids) ->
oids(Rest, [Oid|Oids]).
-
+
+int16(<<>>, Vals) ->
+ lists:reverse(Vals);
+int16(<<Val:16/integer, Rest/binary>>, Vals) ->
+ int16(Rest, [Val|Vals]).
+
coldescs(<<>>, Descs) ->
lists:reverse(Descs);
coldescs(Bin, Descs) ->

0 comments on commit dea1ecd

Please sign in to comment.