Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed build to work with R14,R15,R16,17 and 18 #172

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ before_script:
- make

script: "make test"

otp_release:
- 17.0-rc1
- 18.0
- 17.5
- R16B03-1
- R16B
- R15B03
Expand Down
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ APP_NAME=emysql
MODULES=$(shell ls -1 src/*.erl | awk -F[/.] '{ print $$2 }' | sed '$$q;s/$$/,/g')
MAKETIME=$(shell date)

## Check if we are on erlang version that has namespaced types
ERL_NT=$(shell escript ./support/ntype_check.escript)

## Check if we are on erlang version that has erlang:timestamp/0
ERL_TS=$(shell escript ./support/timestamp_check.escript)

ifeq ($(ERL_NT),true)
ERLC_NT_FLAG=-Dnamespaced_types
endif
ifeq ($(ERL_TS),true)
ERLC_TS_FLAG=-Dtimestamp_support
endif

all: crypto_compat app
(cd src;$(MAKE))

Expand Down Expand Up @@ -80,7 +93,7 @@ CT_RUN = ct_run \
CT_SUITES=environment basics conn_mgr

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

test: all build-tests
@mkdir -p logs
Expand Down
130 changes: 64 additions & 66 deletions include/emysql.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
%% Jacob Vorreuter <[email protected]>,
%% Henning Diedrich <[email protected]>,
%% Eonblast Corporation <http://www.eonblast.com>
%%
%%
%% Permission is hereby granted, free of charge, to any person
%% obtaining a copy of this software and associated documentation
%% files (the "Software"),to deal in the Software without restric-
%% tion, including without limitation the rights to use, copy,
%% tion, including without limitation the rights to use, copy,
%% modify, merge, publish, distribute, sublicense, and/or sell
%% copies of the Software, and to permit persons to whom the
%% Software is furnished to do so, subject to the following
%% Software is furnished to do so, subject to the following
%% conditions:
%%
%%
%% The above copyright notice and this permission notice shall be
%% included in all copies or substantial portions of the Software.
%%
Expand All @@ -25,89 +25,88 @@
%% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
%% OTHER DEALINGS IN THE SOFTWARE.


-record(pool, {pool_id :: atom(),
size :: number(),
user :: string(),
password :: string(),
host :: string(),
port :: number(),
database :: string(),
-record(pool, {pool_id :: atom(),
size :: number(),
user :: string(),
password :: string(),
host :: string(),
port :: number(),
database :: string(),
encoding :: utf8 | latin1 | {utf8, utf8_unicode_ci} | {utf8, utf8_general_ci},
available=queue:new() :: queue(),
locked=gb_trees:empty() :: gb_tree(),
waiting=queue:new() :: queue(),
start_cmds=[] :: string(),
conn_test_period=0 :: number(),
available=queue:new() :: emysql:t_queue(),
locked=gb_trees:empty() :: emysql:t_gb_tree(),
waiting=queue:new() :: emysql:t_queue(),
start_cmds=[] :: string(),
conn_test_period=0 :: number(),
connect_timeout=infinity :: number() | infinity,
warnings=false :: boolean()}).

-record(emysql_connection, {id :: string(),
pool_id :: atom(),
-record(emysql_connection, {id :: string(),
pool_id :: atom(),
encoding :: atom(), % maybe could be latin1 | utf8 ?
socket :: inet:socket(),
version :: number(),
thread_id :: number(),
caps :: number(),
language :: number,
prepared=gb_trees:empty(),
locked_at :: number(),
alive=true :: boolean(),
test_period=0 :: number(),
last_test_time=0 :: number(),
socket :: inet:socket(),
version :: number(),
thread_id :: number(),
caps :: number(),
language :: number,
prepared=gb_trees:empty(),
locked_at :: number(),
alive=true :: boolean(),
test_period=0 :: number(),
last_test_time=0 :: number(),
monitor_ref :: reference(),
warnings=false :: boolean()}).

-record(greeting, {protocol_version :: number(),
server_version :: binary(),
thread_id :: number(),
salt1 :: binary(),
salt2 :: binary(),
caps :: number(),
caps_high :: number(),
language :: number(),
status :: number(),
seq_num :: number(),
-record(greeting, {protocol_version :: number(),
server_version :: binary(),
thread_id :: number(),
salt1 :: binary(),
salt2 :: binary(),
caps :: number(),
caps_high :: number(),
language :: number(),
status :: number(),
seq_num :: number(),
plugin :: binary()}).

-record(field, {seq_num :: number(),
catalog :: binary(),
db :: binary(),
table :: binary(),
org_table :: binary(),
name :: binary(),
org_name :: binary(),
type :: number(),
default :: number(),
charset_nr :: number(),
length :: number(),
flags :: number(),
decimals :: number(),
-record(field, {seq_num :: number(),
catalog :: binary(),
db :: binary(),
table :: binary(),
org_table :: binary(),
name :: binary(),
org_name :: binary(),
type :: number(),
default :: number(),
charset_nr :: number(),
length :: number(),
flags :: number(),
decimals :: number(),
decoder :: fun()}).
-record(packet, {size :: number(),
seq_num :: number(),
-record(packet, {size :: number(),
seq_num :: number(),
data :: binary()}).
-record(ok_packet, {seq_num :: number(),
affected_rows :: number(),
insert_id :: number(),
status :: number(),
warning_count :: number(),
-record(ok_packet, {seq_num :: number(),
affected_rows :: number(),
insert_id :: number(),
status :: number(),
warning_count :: number(),
msg :: string()
| {error, string(), unicode:latin1_chardata() | unicode:chardata() | unicode:external_chardata()}
| {incomplete, string(), binary()}}).

% It's unfortunate that error_packet's status is binary when the status of other
% packets is a number.
-record(error_packet, {seq_num :: number(),
code :: number(),
status :: binary(),
-record(error_packet, {seq_num :: number(),
code :: number(),
status :: binary(),
msg :: [byte()]}).

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

-record(result_packet, {seq_num :: number(),
-record(result_packet, {seq_num :: number(),
field_list :: list(),
rows, extra}).

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

2 changes: 2 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
% -*- Erlang -*-
% vim: ts=4 sw=4 et ft=erlang
{erl_opts, [
{platform_define, "^[0-9]+", namespaced_types},
nowarn_deprecated_type
]}.
{pre_hooks,[

{"linux|bsd|darwin|solaris", compile, "escript ./support/crypto_compat.escript"},
{"win32", compile, "escript.exe support/crypto_compat.escript"}
]}.
14 changes: 14 additions & 0 deletions rebar.config.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{exports, ExportList} = lists:keyfind(exports,1,erlang:module_info()),
Check = lists:member({timestamp,0},ExportList),
case Check of
true ->
case lists:keyfind(erl_opts, 1, CONFIG) of
false ->
CONFIG ++ [{erl_opts,[{d,timestamp_support}]}];
{erl_opts, Opts} ->
NewOpts = {erl_opts, Opts ++ [{d,timestamp_support}]},
lists:keyreplace(erl_opts, 1, CONFIG, NewOpts)
end;
false ->
CONFIG
end.
35 changes: 26 additions & 9 deletions src/emysql.erl
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@
add_pool/9,
add_pool/8, remove_pool/1, increment_pool_size/2, decrement_pool_size/2
]).

%% Interaction API
%% Used to interact with the database.
%% Used to interact with the database.
-export([
prepare/2,
execute/2, execute/3, execute/4, execute/5,
Expand Down Expand Up @@ -136,6 +136,23 @@
% for record and constant defines
-include("emysql.hrl").

-export_type([
t_gb_tree/0,
t_queue/0,
t_dict/0
]).

-ifdef(namespaced_types).
-type t_gb_tree() :: gb_trees:tree().
-type t_queue() :: queue:queue().
-type t_dict() :: dict:dict().
-else.
-type t_gb_tree() :: gb_tree().
-type t_queue() :: queue().
-type t_dict() :: dict().
-endif.


%% @spec start() -> ok
%% @doc Start the Emysql application.
%%
Expand Down Expand Up @@ -246,8 +263,8 @@ config_ok(#pool{pool_id=PoolId,size=Size,user=User,password=Password,host=Host,p
config_ok(_BadOptions) ->
erlang:error(badarg).

encoding_ok(Enc) when is_atom(Enc) -> ok;
encoding_ok({Enc, Coll}) when is_atom(Enc), is_atom(Coll) -> ok;
encoding_ok(Enc) when is_atom(Enc) -> ok;
encoding_ok({Enc, Coll}) when is_atom(Enc), is_atom(Coll) -> ok;
encoding_ok(_) -> erlang:error(badarg).

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

add_pool(#pool{pool_id=PoolId,size=Size,user=User,password=Password,host=Host,port=Port,
database=Database,encoding=Encoding,start_cmds=StartCmds,
connect_timeout=ConnectTimeout,warnings=Warnings}=PoolSettings)->
config_ok(PoolSettings),
case emysql_conn_mgr:has_pool(PoolId) of
true ->
true ->
{error,pool_already_exists};
false ->
Pool = #pool{
Expand Down Expand Up @@ -328,8 +345,8 @@ add_pool(PoolId, Size, User, Password, Host, Port, Database, Encoding) ->
add_pool(PoolId, Size, User, Password, Host, Port, Database, Encoding, StartCmds) ->
add_pool(PoolId, Size, User, Password, Host, Port, Database, Encoding, StartCmds, infinity).

add_pool(PoolId, Size, User, Password, Host, Port, Database,
Encoding, StartCmds, ConnectTimeout)->
add_pool(PoolId, Size, User, Password, Host, Port, Database,
Encoding, StartCmds, ConnectTimeout)->
add_pool(PoolId,[{size,Size},{user,User},{password,Password},
{host,Host},{port,Port},{database,Database},
{encoding,Encoding},{start_cmds,StartCmds},
Expand Down Expand Up @@ -669,7 +686,7 @@ result_type(#eof_packet{}) -> eof.
-spec as_dict(Result) -> Dict
when
Result :: #result_packet{},
Dict :: dict().
Dict :: t_dict().
as_dict(Res) -> emysql_conv:as_dict(Res).


Expand Down
12 changes: 6 additions & 6 deletions src/emysql_conn.erl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ set_database(Connection, Database) ->

set_encoding(_, undefined) -> ok;
set_encoding(Connection, {Encoding, Collation}) ->
Packet = <<?COM_QUERY, "set names '", (erlang:atom_to_binary(Encoding, utf8))/binary,
Packet = <<?COM_QUERY, "set names '", (erlang:atom_to_binary(Encoding, utf8))/binary,
"' collate '", (erlang:atom_to_binary(Collation, utf8))/binary,"'">>,
emysql_tcp:send_and_recv_packet(Connection#emysql_connection.socket, Packet, 0);
set_encoding(Connection, Encoding) ->
Expand Down Expand Up @@ -260,7 +260,7 @@ run_startcmds_or_die(#emysql_connection{socket=Socket}, StartCmds) ->
end,
StartCmds
).

set_encoding_or_die(#emysql_connection { socket = Socket } = Connection, Encoding) ->
case set_encoding(Connection, Encoding) of
ok -> ok;
Expand All @@ -269,7 +269,7 @@ set_encoding_or_die(#emysql_connection { socket = Socket } = Connection, Encodin
gen_tcp:close(Socket),
exit({failed_to_set_encoding, Err2#error_packet.msg})
end.

reset_connection(Pools, Conn, StayLocked) ->
%% if a process dies or times out while doing work
%% the socket must be closed and the connection reset
Expand Down Expand Up @@ -334,7 +334,7 @@ need_test_connection(Conn) ->
(Conn#emysql_connection.last_test_time + Conn#emysql_connection.test_period < now_seconds()).

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

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

Expand Down Expand Up @@ -449,7 +449,7 @@ encode({_Time1, _Time2, _Time3}=Val, binary) ->
list_to_binary(encode(Val, list));
encode(Val, _) ->
{error, {unrecognized_value, Val}}.

%% @private
two_digits(Nums) when is_list(Nums) ->
[two_digits(Num) || Num <- Nums];
Expand Down
Loading