Skip to content

Commit 1728235

Browse files
committed
Merge remote-tracking branch 'djustinek/master' into tgf
Merging pull request 172 "Fixed build to work with R14,R15,R16,17 and 18": Eonblast#172
2 parents 1dd3aff + fa7c94b commit 1728235

12 files changed

+179
-87
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ before_script:
88
- make
99

1010
script: "make test"
11+
1112
otp_release:
12-
- 17.0-rc1
13+
- 18.0
14+
- 17.5
1315
- R16B03-1
1416
- R16B
1517
- R15B03

Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ APP_NAME=emysql
66
MODULES=$(shell ls -1 src/*.erl | awk -F[/.] '{ print $$2 }' | sed '$$q;s/$$/,/g')
77
MAKETIME=$(shell date)
88

9+
## Check if we are on erlang version that has namespaced types
10+
ERL_NT=$(shell escript ./support/ntype_check.escript)
11+
12+
## Check if we are on erlang version that has erlang:timestamp/0
13+
ERL_TS=$(shell escript ./support/timestamp_check.escript)
14+
15+
ifeq ($(ERL_NT),true)
16+
ERLC_NT_FLAG=-Dnamespaced_types
17+
endif
18+
ifeq ($(ERL_TS),true)
19+
ERLC_TS_FLAG=-Dtimestamp_support
20+
endif
21+
922
all: crypto_compat app
1023
(cd src;$(MAKE))
1124

@@ -80,7 +93,7 @@ CT_RUN = ct_run \
8093
CT_SUITES=environment basics conn_mgr
8194

8295
build-tests:
83-
erlc -v -o test/ $(wildcard test/*.erl) -pa ebin/
96+
erlc -v $(ERLC_NT_FLAG) $(ERLC_TS_FLAG) -o test/ $(wildcard test/*.erl) -pa ebin/
8497

8598
test: all build-tests
8699
@mkdir -p logs

include/emysql.hrl

Lines changed: 64 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
%% Jacob Vorreuter <[email protected]>,
44
%% Henning Diedrich <[email protected]>,
55
%% Eonblast Corporation <http://www.eonblast.com>
6-
%%
6+
%%
77
%% Permission is hereby granted, free of charge, to any person
88
%% obtaining a copy of this software and associated documentation
99
%% files (the "Software"),to deal in the Software without restric-
10-
%% tion, including without limitation the rights to use, copy,
10+
%% tion, including without limitation the rights to use, copy,
1111
%% modify, merge, publish, distribute, sublicense, and/or sell
1212
%% copies of the Software, and to permit persons to whom the
13-
%% Software is furnished to do so, subject to the following
13+
%% Software is furnished to do so, subject to the following
1414
%% conditions:
15-
%%
15+
%%
1616
%% The above copyright notice and this permission notice shall be
1717
%% included in all copies or substantial portions of the Software.
1818
%%
@@ -25,89 +25,88 @@
2525
%% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2626
%% OTHER DEALINGS IN THE SOFTWARE.
2727

28-
29-
-record(pool, {pool_id :: atom(),
30-
size :: number(),
31-
user :: string(),
32-
password :: string(),
33-
host :: string(),
34-
port :: number(),
35-
database :: string(),
28+
-record(pool, {pool_id :: atom(),
29+
size :: number(),
30+
user :: string(),
31+
password :: string(),
32+
host :: string(),
33+
port :: number(),
34+
database :: string(),
3635
encoding :: utf8 | latin1 | {utf8, utf8_unicode_ci} | {utf8, utf8_general_ci},
37-
available=queue:new() :: queue(),
38-
locked=gb_trees:empty() :: gb_tree(),
39-
waiting=queue:new() :: queue(),
40-
start_cmds=[] :: string(),
41-
conn_test_period=0 :: number(),
36+
available=queue:new() :: emysql:t_queue(),
37+
locked=gb_trees:empty() :: emysql:t_gb_tree(),
38+
waiting=queue:new() :: emysql:t_queue(),
39+
start_cmds=[] :: string(),
40+
conn_test_period=0 :: number(),
4241
connect_timeout=infinity :: number() | infinity,
4342
warnings=false :: boolean()}).
4443

45-
-record(emysql_connection, {id :: string(),
46-
pool_id :: atom(),
44+
-record(emysql_connection, {id :: string(),
45+
pool_id :: atom(),
4746
encoding :: atom(), % maybe could be latin1 | utf8 ?
48-
socket :: inet:socket(),
49-
version :: number(),
50-
thread_id :: number(),
51-
caps :: number(),
52-
language :: number,
53-
prepared=gb_trees:empty(),
54-
locked_at :: number(),
55-
alive=true :: boolean(),
56-
test_period=0 :: number(),
57-
last_test_time=0 :: number(),
47+
socket :: inet:socket(),
48+
version :: number(),
49+
thread_id :: number(),
50+
caps :: number(),
51+
language :: number,
52+
prepared=gb_trees:empty(),
53+
locked_at :: number(),
54+
alive=true :: boolean(),
55+
test_period=0 :: number(),
56+
last_test_time=0 :: number(),
5857
monitor_ref :: reference(),
5958
warnings=false :: boolean()}).
6059

61-
-record(greeting, {protocol_version :: number(),
62-
server_version :: binary(),
63-
thread_id :: number(),
64-
salt1 :: binary(),
65-
salt2 :: binary(),
66-
caps :: number(),
67-
caps_high :: number(),
68-
language :: number(),
69-
status :: number(),
70-
seq_num :: number(),
60+
-record(greeting, {protocol_version :: number(),
61+
server_version :: binary(),
62+
thread_id :: number(),
63+
salt1 :: binary(),
64+
salt2 :: binary(),
65+
caps :: number(),
66+
caps_high :: number(),
67+
language :: number(),
68+
status :: number(),
69+
seq_num :: number(),
7170
plugin :: binary()}).
7271

73-
-record(field, {seq_num :: number(),
74-
catalog :: binary(),
75-
db :: binary(),
76-
table :: binary(),
77-
org_table :: binary(),
78-
name :: binary(),
79-
org_name :: binary(),
80-
type :: number(),
81-
default :: number(),
82-
charset_nr :: number(),
83-
length :: number(),
84-
flags :: number(),
85-
decimals :: number(),
72+
-record(field, {seq_num :: number(),
73+
catalog :: binary(),
74+
db :: binary(),
75+
table :: binary(),
76+
org_table :: binary(),
77+
name :: binary(),
78+
org_name :: binary(),
79+
type :: number(),
80+
default :: number(),
81+
charset_nr :: number(),
82+
length :: number(),
83+
flags :: number(),
84+
decimals :: number(),
8685
decoder :: fun()}).
87-
-record(packet, {size :: number(),
88-
seq_num :: number(),
86+
-record(packet, {size :: number(),
87+
seq_num :: number(),
8988
data :: binary()}).
90-
-record(ok_packet, {seq_num :: number(),
91-
affected_rows :: number(),
92-
insert_id :: number(),
93-
status :: number(),
94-
warning_count :: number(),
89+
-record(ok_packet, {seq_num :: number(),
90+
affected_rows :: number(),
91+
insert_id :: number(),
92+
status :: number(),
93+
warning_count :: number(),
9594
msg :: string()
9695
| {error, string(), unicode:latin1_chardata() | unicode:chardata() | unicode:external_chardata()}
9796
| {incomplete, string(), binary()}}).
9897

9998
% It's unfortunate that error_packet's status is binary when the status of other
10099
% packets is a number.
101-
-record(error_packet, {seq_num :: number(),
102-
code :: number(),
103-
status :: binary(),
100+
-record(error_packet, {seq_num :: number(),
101+
code :: number(),
102+
status :: binary(),
104103
msg :: [byte()]}).
105104

106-
-record(eof_packet, {seq_num :: number(),
107-
status :: number(),
105+
-record(eof_packet, {seq_num :: number(),
106+
status :: number(),
108107
warning_count :: number()}). % extended to mySQL 4.1+ format
109108

110-
-record(result_packet, {seq_num :: number(),
109+
-record(result_packet, {seq_num :: number(),
111110
field_list :: list(),
112111
rows, extra}).
113112

@@ -179,4 +178,3 @@
179178
% we discovered that the new statement returns a different
180179
% number of result set columns.
181180
-define(SERVER_STATUS_METADATA_CHANGED, 1024).
182-

rebar.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
% -*- Erlang -*-
22
% vim: ts=4 sw=4 et ft=erlang
33
{erl_opts, [
4+
{platform_define, "^[0-9]+", namespaced_types},
45
nowarn_deprecated_type
56
]}.
67
{pre_hooks,[
8+
79
{"linux|bsd|darwin|solaris", compile, "escript ./support/crypto_compat.escript"},
810
{"win32", compile, "escript.exe support/crypto_compat.escript"}
911
]}.

rebar.config.script

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{exports, ExportList} = lists:keyfind(exports,1,erlang:module_info()),
2+
Check = lists:member({timestamp,0},ExportList),
3+
case Check of
4+
true ->
5+
case lists:keyfind(erl_opts, 1, CONFIG) of
6+
false ->
7+
CONFIG ++ [{erl_opts,[{d,timestamp_support}]}];
8+
{erl_opts, Opts} ->
9+
NewOpts = {erl_opts, Opts ++ [{d,timestamp_support}]},
10+
lists:keyreplace(erl_opts, 1, CONFIG, NewOpts)
11+
end;
12+
false ->
13+
CONFIG
14+
end.

src/emysql.erl

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@
105105
add_pool/9,
106106
add_pool/8, remove_pool/1, increment_pool_size/2, decrement_pool_size/2
107107
]).
108-
108+
109109
%% Interaction API
110-
%% Used to interact with the database.
110+
%% Used to interact with the database.
111111
-export([
112112
prepare/2,
113113
execute/2, execute/3, execute/4, execute/5,
@@ -136,6 +136,23 @@
136136
% for record and constant defines
137137
-include("emysql.hrl").
138138

139+
-export_type([
140+
t_gb_tree/0,
141+
t_queue/0,
142+
t_dict/0
143+
]).
144+
145+
-ifdef(namespaced_types).
146+
-type t_gb_tree() :: gb_trees:tree().
147+
-type t_queue() :: queue:queue().
148+
-type t_dict() :: dict:dict().
149+
-else.
150+
-type t_gb_tree() :: gb_tree().
151+
-type t_queue() :: queue().
152+
-type t_dict() :: dict().
153+
-endif.
154+
155+
139156
%% @spec start() -> ok
140157
%% @doc Start the Emysql application.
141158
%%
@@ -246,8 +263,8 @@ config_ok(#pool{pool_id=PoolId,size=Size,user=User,password=Password,host=Host,p
246263
config_ok(_BadOptions) ->
247264
erlang:error(badarg).
248265

249-
encoding_ok(Enc) when is_atom(Enc) -> ok;
250-
encoding_ok({Enc, Coll}) when is_atom(Enc), is_atom(Coll) -> ok;
266+
encoding_ok(Enc) when is_atom(Enc) -> ok;
267+
encoding_ok({Enc, Coll}) when is_atom(Enc), is_atom(Coll) -> ok;
251268
encoding_ok(_) -> erlang:error(badarg).
252269

253270
%% Creates a pool record, opens n=Size connections and calls
@@ -267,15 +284,15 @@ add_pool(PoolId, Options) when is_list(Options) ->
267284
Warnings = proplists:get_value(warnings, Options, false),
268285
add_pool(#pool{pool_id=PoolId,size=Size, user=User, password=Password,
269286
host=Host, port=Port, database=Database,
270-
encoding=Encoding, start_cmds=StartCmds,
287+
encoding=Encoding, start_cmds=StartCmds,
271288
connect_timeout=ConnectTimeout, warnings=Warnings}).
272289

273290
add_pool(#pool{pool_id=PoolId,size=Size,user=User,password=Password,host=Host,port=Port,
274291
database=Database,encoding=Encoding,start_cmds=StartCmds,
275292
connect_timeout=ConnectTimeout,warnings=Warnings}=PoolSettings)->
276293
config_ok(PoolSettings),
277294
case emysql_conn_mgr:has_pool(PoolId) of
278-
true ->
295+
true ->
279296
{error,pool_already_exists};
280297
false ->
281298
Pool = #pool{
@@ -328,8 +345,8 @@ add_pool(PoolId, Size, User, Password, Host, Port, Database, Encoding) ->
328345
add_pool(PoolId, Size, User, Password, Host, Port, Database, Encoding, StartCmds) ->
329346
add_pool(PoolId, Size, User, Password, Host, Port, Database, Encoding, StartCmds, infinity).
330347

331-
add_pool(PoolId, Size, User, Password, Host, Port, Database,
332-
Encoding, StartCmds, ConnectTimeout)->
348+
add_pool(PoolId, Size, User, Password, Host, Port, Database,
349+
Encoding, StartCmds, ConnectTimeout)->
333350
add_pool(PoolId,[{size,Size},{user,User},{password,Password},
334351
{host,Host},{port,Port},{database,Database},
335352
{encoding,Encoding},{start_cmds,StartCmds},
@@ -669,7 +686,7 @@ result_type(#eof_packet{}) -> eof.
669686
-spec as_dict(Result) -> Dict
670687
when
671688
Result :: #result_packet{},
672-
Dict :: dict().
689+
Dict :: t_dict().
673690
as_dict(Res) -> emysql_conv:as_dict(Res).
674691

675692

src/emysql_conn.erl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ set_database(Connection, Database) ->
7575

7676
set_encoding(_, undefined) -> ok;
7777
set_encoding(Connection, {Encoding, Collation}) ->
78-
Packet = <<?COM_QUERY, "set names '", (erlang:atom_to_binary(Encoding, utf8))/binary,
78+
Packet = <<?COM_QUERY, "set names '", (erlang:atom_to_binary(Encoding, utf8))/binary,
7979
"' collate '", (erlang:atom_to_binary(Collation, utf8))/binary,"'">>,
8080
emysql_tcp:send_and_recv_packet(Connection#emysql_connection.socket, Packet, 0);
8181
set_encoding(Connection, Encoding) ->
@@ -260,7 +260,7 @@ run_startcmds_or_die(#emysql_connection{socket=Socket}, StartCmds) ->
260260
end,
261261
StartCmds
262262
).
263-
263+
264264
set_encoding_or_die(#emysql_connection { socket = Socket } = Connection, Encoding) ->
265265
case set_encoding(Connection, Encoding) of
266266
ok -> ok;
@@ -269,7 +269,7 @@ set_encoding_or_die(#emysql_connection { socket = Socket } = Connection, Encodin
269269
gen_tcp:close(Socket),
270270
exit({failed_to_set_encoding, Err2#error_packet.msg})
271271
end.
272-
272+
273273
reset_connection(Pools, Conn, StayLocked) ->
274274
%% if a process dies or times out while doing work
275275
%% the socket must be closed and the connection reset
@@ -334,7 +334,7 @@ need_test_connection(Conn) ->
334334
(Conn#emysql_connection.last_test_time + Conn#emysql_connection.test_period < now_seconds()).
335335

336336
now_seconds() ->
337-
{M, S, _} = erlang:now(),
337+
{M, S, _} = emysql_util:timestamp(),
338338
M * 1000000 + S.
339339

340340
%%--------------------------------------------------------------------
@@ -365,7 +365,7 @@ set_params_packet(NumStart, Values) ->
365365
BinValues = [encode(Val, binary) || Val <- Values],
366366
BinNums = [encode(Num, binary) || Num <- lists:seq(NumStart, NumStart + length(Values) - 1)],
367367
BinPairs = lists:zip(BinNums, BinValues),
368-
Parts = [<<"@", NumBin/binary, "=", ValBin/binary>> || {NumBin, ValBin} <- BinPairs],
368+
Parts = [<<"@", NumBin/binary, "=", ValBin/binary>> || {NumBin, ValBin} <- BinPairs],
369369
Sets = list_to_binary(join(Parts, <<",">>)),
370370
<<?COM_QUERY, "SET ", Sets/binary>>.
371371

@@ -449,7 +449,7 @@ encode({_Time1, _Time2, _Time3}=Val, binary) ->
449449
list_to_binary(encode(Val, list));
450450
encode(Val, _) ->
451451
{error, {unrecognized_value, Val}}.
452-
452+
453453
%% @private
454454
two_digits(Nums) when is_list(Nums) ->
455455
[two_digits(Num) || Num <- Nums];

0 commit comments

Comments
 (0)