aboutsummaryrefslogtreecommitdiffstats
path: root/src/mysqlerl.erl
blob: 68185a296b0635c411d0617f664afcb0d417e2d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
%% Modeled from ODBC
%% http://www.erlang.org/doc/apps/odbc/

-module(mysqlerl).
-author('bjc@kublai.com').

-export([test_start/0, test_msg/0]).

-export([start/0, start/1, stop/0, commit/2, commit/3,
         connect/6, disconnect/1, describe_table/2,
         describe_table/3, first/1, first/2,
         last/1, last/2, next/1, next/2, prev/1,
         prev/2, select_count/2, select_count/3,
         select/3, select/4, param_query/3, param_query/4,
         sql_query/2, sql_query/3]).

-define(CONFIG, "/Users/bjc/tmp/test-server.cfg").
-define(NOTIMPLEMENTED, {error, {not_implemented,
                                 "This function has only been stubbed "
                                 "out for reference."}}).

test_start() ->
    {ok, [{Host, Port, DB, User, Pass, Options}]} = file:consult(?CONFIG),
    mysqlerl:connect(Host, Port, DB, User, Pass, Options).

test_msg() ->
    mysqlerl_connection:testmsg(mysqlerl_connection_sup:random_child()).

start() ->
    start(temporary).

%% Arguments:
%%     Type = permanent | transient | temporary
%%
%% Returns:
%%     ok | {error, Reason}
start(Type) ->
    application:start(sasl),
    application:start(mysqlerl, Type).

stop() ->
    application:stop(mysqlerl).

commit(Ref, CommitMode) ->
    commit(Ref, CommitMode, infinity).

%% Arguments:
%%     Ref = connection_reference()
%%     Timeout = time_out()
%%     CommitMode = commit | rollback
%%     Reason = not_an_explicit_commit_connection |
%%              process_not_owner_of_odbc_connection |
%%              common_reason()
%%     ok | {error, Reason}
commit(Ref, commit, Timeout) ->
    mysqlerl_connection:sql_query(Ref, "COMMIT", Timeout);
commit(Ref, rollback, Timeout) ->
    mysqlerl_connection:sql_query(Ref, "ROLLBACK", Timeout).

%% Arguments:
%%     Host = string()
%%     Port = integer()
%%     Database = string()
%%     User = string()
%%     Password = string()
%%     Options = list()
%%
%% Returns:
%%     {ok, Ref} | {error, Reason}
%%     Ref = connection_reference()
connect(Host, Port, Database, User, Password, Options) ->
    mysqlerl_connection_sup:connect(Host, Port, Database,
                                    User, Password, Options).

%% Arguments:
%%     Ref = connection_reference()
%%
%% Returns:
%%     ok | {error, Reason}
disconnect(Ref) ->
    mysqlerl_connection:stop(Ref).

describe_table(Ref, Table) ->
    describe_table(Ref, Table, infinity).

%% Arguments:
%%     Ref = connection_reference()
%%     Table = string()
%%     Timeout = time_out()
%%
%% Returns:
%%     {ok, Description} | {error, Reason}
%%     Description = [{col_name(), odbc_data_type()}]
describe_table(_Ref, _Table, _Timeout) ->
    ?NOTIMPLEMENTED.

first(Ref) ->
    first(Ref, infinity).

%% Arguments:
%%     Ref = connection_reference()
%%     Timeout = time_out()
%% Returns:
%%     {selected, ColNames, Rows} | {error, Reason}
%%     Rows = rows()
first(_Ref, _Timeout) ->
    ?NOTIMPLEMENTED.

last(Ref) ->
    last(Ref, infinity).

%% Arguments:
%%     Ref = connection_reference()
%%     Timeout = time_out()
%% Returns:
%%     {selected, ColNames, Rows} | {error, Reason}
%%     Rows = rows()
last(_Ref, _Timeout) ->
    ?NOTIMPLEMENTED.

next(Ref) ->
    next(Ref, infinity).

%% Arguments:
%%     Ref = connection_reference()
%%     Timeout = time_out()
%% Returns:
%%     {selected, ColNames, Rows} | {error, Reason}
%%     Rows = rows()
next(_Ref, _Timeout) ->
    ?NOTIMPLEMENTED.

prev(Ref) ->
    prev(Ref, infinity).

%% Arguments:
%%     Ref = connection_reference()
%%     Timeout = time_out()
%% Returns:
%%     {selected, ColNames, Rows} | {error, Reason}
%%     Rows = rows()
prev(_Ref, _Timeout) ->
    ?NOTIMPLEMENTED.

select_count(Ref, SQLQuery) ->
    select_count(Ref, SQLQuery, infinity).

%% Arguments:
%%     Ref = connection_reference()
%%     SQLQuery = string()
%%     Timeout = time_out()
%% Returns:
%%     {ok, NrRows} | {error, Reason}
%%     NrRows = n_rows()
select_count(_Ref, _SQLQuery, _Timeout) ->
    ?NOTIMPLEMENTED.

select(Ref, Pos, N) ->
    select(Ref, Pos, N, infinity).

%% Arguments:
%%     Ref = connection_reference()
%%     Pos = integer()
%%     Timeout = time_out()
%% Returns:
%%     {selected, ColNames, Rows} | {error, Reason}
%%     Rows = rows()
select(_Ref, _Pos, _N, _Timeout) ->
    ?NOTIMPLEMENTED.

param_query(Ref, SQLQuery, Params) ->
    param_query(Ref, SQLQuery, Params, infinity).

%% Arguments:
%%     Ref = connection_reference()
%%     SQLQuery = string()
%%     Params = [{odbc_data_type(), [value()]}]
%%     Timeout = time_out()
%% Returns:
%%     {selected, ColNames, Rows} | {error, Reason}
%%     Rows = rows()
param_query(_Ref, _SQLQuery, _Params, _Timeout) ->
    ?NOTIMPLEMENTED.

sql_query(Ref, SQLQuery) ->
    sql_query(Ref, SQLQuery, infinity).

%% Arguments:
%%     Ref = connection_reference()
%%     SQLQuery = string()
%%     Timeout = time_out()
%% Returns:
%%     {selected, ColNames, Rows} | {error, Reason}
%%     Rows = rows()
sql_query(_Ref, _SQLQuery, _Timeout) ->
    ?NOTIMPLEMENTED.