Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 47 lines (40 sloc) 1.36 kb
84adefa The R13B03 release.
Erlang/OTP authored
1 %%
2 %% %CopyrightBegin%
3 %%
4 %% Copyright Ericsson AB 2006-2009. All Rights Reserved.
5 %%
6 %% The contents of this file are subject to the Erlang Public License,
7 %% Version 1.1, (the "License"); you may not use this file except in
8 %% compliance with the License. You should have received a copy of the
9 %% Erlang Public License along with this software. If not, it can be
10 %% retrieved online at http://www.erlang.org/.
11 %%
12 %% Software distributed under the License is distributed on an "AS IS"
13 %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14 %% the License for the specific language governing rights and limitations
15 %% under the License.
16 %%
17 %% %CopyrightEnd%
18 %%
19 -module(pg_sync).
20
21 -define(DRV_CONNECT, $C).
22 -define(DRV_DISCONNECT, $D).
23 -define(DRV_SELECT, $S).
24
25 -export([connect/1, disconnect/1, select/2]).
26
27 connect(ConnectStr) ->
28 case erl_ddll:load_driver(".", "pg_sync") of
29 ok -> ok;
30 {error, already_loaded} -> ok;
31 E -> exit(E)
32 end,
33 Port = open_port({spawn, ?MODULE}, []),
34 case binary_to_term(port_control(Port, ?DRV_CONNECT, ConnectStr)) of
35 ok -> {ok, Port};
36 Error -> Error
37 end.
38
39 disconnect(Port) ->
40 R = binary_to_term(port_control(Port, ?DRV_DISCONNECT, "")),
41 port_close(Port),
42 R.
43
44 select(Port, Query) ->
45 binary_to_term(port_control(Port, ?DRV_SELECT, Query)).
46
Something went wrong with that request. Please try again.