Permalink
Fetching contributors…
Cannot retrieve contributors at this time
568 lines (563 sloc) 18.2 KB
Diff of ejabberd mysql driver vs yxa mysql driver (comment changes ignored)
---------------------------------------------------------------------------
Both depend on Magnus Ahltorp' code. Half of the difference are simply changed
comments, as Yxa went edoc. The remainder are mostly result inspection extensions
on the part of the ejabberd source.
This diff ignores changes to comments but lists added comments. Find one listing all
changes here: https://github.com/Eonblast/Emysql/blob/master/doc/diff-ejabberd-yxa.txt
Yxa: https://github.com/fredrikt/yxa/tree/master/src/mysql/
Ejabberd: http://svn.process-one.net/ejabberd-modules/mysql/trunk/
Diff: Jan 2011
Only in ejabberd-modules/mysql/trunk/: .svn
Only in yxa-1.0/src/mysql/: Makefile.in
diff -I '^%.*$' ejabberd-modules/mysql/trunk/mysql.erl yxa-1.0/src/mysql/mysql.erl
73,77d60
< get_result_field_info/1,
< get_result_rows/1,
< get_result_affected_rows/1,
< get_result_reason/1,
<
81,84c64
< connect/7,
< stop/0,
<
< gc_each/1
---
> connect/7
108c88,89
< -include("mysql.hrl").
---
> %% @type state() = #state{}.
> %% no description
111,112c92
< log_fun, %% undefined | function for logging,
< gc_tref %% undefined | timer:TRef
---
> log_fun %% undefined | function for logging,
173,178d154
< stop() ->
< gen_server:call(?SERVER, stop).
<
< gc_each(Millisec) ->
< gen_server:call(?SERVER, {gc_each, Millisec}).
<
197,241c177,186
< %% Function: get_result_field_info(MySQLRes)
< %% MySQLRes = term(), result of fetch function on "data"
< %% Descrip.: Extract the FieldInfo from MySQL Result on data received
< %% Returns : FieldInfo
< %% FieldInfo = list() of {Table, Field, Length, Name}
< %%--------------------------------------------------------------------
< get_result_field_info(#mysql_result{fieldinfo = FieldInfo}) ->
< FieldInfo.
<
< %%--------------------------------------------------------------------
< %% Function: get_result_rows(MySQLRes)
< %% MySQLRes = term(), result of fetch function on "data"
< %% Descrip.: Extract the Rows from MySQL Result on data received
< %% Returns : Rows
< %% Rows = list() of list() representing records
< %%--------------------------------------------------------------------
< get_result_rows(#mysql_result{rows=AllRows}) ->
< AllRows.
<
< %%--------------------------------------------------------------------
< %% Function: get_result_affected_rows(MySQLRes)
< %% MySQLRes = term(), result of fetch function on "updated"
< %% Descrip.: Extract the Rows from MySQL Result on update
< %% Returns : AffectedRows
< %% AffectedRows = integer()
< %%--------------------------------------------------------------------
< get_result_affected_rows(#mysql_result{affectedrows=AffectedRows}) ->
< AffectedRows.
<
< %%--------------------------------------------------------------------
< %% Function: get_result_reason(MySQLRes)
< %% MySQLRes = term(), result of fetch function on "error"
< %% Descrip.: Extract the error Reason from MySQL Result on error
< %% Returns : Reason
< %% Reason = string()
< %%--------------------------------------------------------------------
< get_result_reason(#mysql_result{error=Reason}) ->
< Reason.
<
< %%--------------------------------------------------------------------
< %% Function: quote(String)
< %% String = string()
< %% Descrip.: Quote a string so that it can be included safely in a
< %% MySQL query.
< %% Returns : Quoted = string()
---
> %% @spec (String) ->
> %% Quoted
> %%
> %% String = string()
> %%
> %% Quoted = string()
> %%
> %% @doc Quote a string so that it can be included safely in a
> %% MySQL query.
> %% @end
391,392c344
< conn_list = ConnList,
< gc_tref = undefined
---
> conn_list = ConnList
414a370,371
> %% @clear
>
472,487d442
< handle_call(stop, _From, State) ->
< {stop, normal, State};
<
< handle_call({gc_each, Millisec}, _From, State) ->
< case State#state.gc_tref of
< undefined -> ok;
< TRef ->
< timer:cancel(TRef)
< end,
< case timer:send_interval(Millisec, gc) of
< {ok, NewTRef} ->
< {reply, ok, State#state{gc_tref = NewTRef}};
< {error, Reason} ->
< {reply, {error, Reason}, State}
< end;
<
499a458,460
>
> %% @clear
>
512a477,478
> %% @clear
>
551,556d519
< handle_info(gc, #state{conn_list = Connections} = State) ->
< [erlang:garbage_collect(C#mysql_connection.conn_pid) || C <- Connections],
< erlang:garbage_collect(self()),
< {noreply, State};
<
<
573,575d537
< lists:foreach(fun(MysqlConn) ->
< MysqlConn#mysql_connection.conn_pid ! close
< end, State#state.conn_list),
Only in ejabberd-modules/mysql/trunk/: mysql.hrl
diff -I '^%.*$' ejabberd-modules/mysql/trunk/mysql_auth.erl yxa-1.0/src/mysql/mysql_auth.erl
28d28
< -define(FOUND_ROWS, 2).
109,110c113
< Caps = ?LONG_PASSWORD bor ?LONG_FLAG
< bor ?TRANSACTIONS bor ?FOUND_ROWS,
---
> Caps = ?LONG_PASSWORD bor ?LONG_FLAG bor ?TRANSACTIONS,
126,127c129
< ?PROTOCOL_41 bor ?SECURE_CONNECTION bor DBCaps
< bor ?FOUND_ROWS,
---
> ?PROTOCOL_41 bor ?SECURE_CONNECTION bor DBCaps,
diff -I '^%.*$' ejabberd-modules/mysql/trunk/mysql_conn.erl yxa-1.0/src/mysql/mysql_conn.erl
67d48
< start_link/6,
69,71c50
< fetch/4,
< squery/4,
< stop/1
---
> fetch/4
80c59,60
< -include("mysql.hrl").
---
> %% @type state() = #state{}.
> %% no description
82d61
< mysql_version,
92,94d70
< -define(DEFAULT_RESULT_TYPE, list).
< -define(MYSQL_4_0, 40). %% Support for MySQL 4.0.x
< -define(MYSQL_4_1, 41). %% Support for MySQL 4.1.x et 5.0.x
121,135d99
< post_start(Pid, LogFun).
<
< start_link(Host, Port, User, Password, Database, LogFun) when is_list(Host), is_integer(Port), is_list(User),
< is_list(Password), is_list(Database) ->
< ConnPid = self(),
< Pid = spawn_link(fun () ->
< init(Host, Port, User, Password, Database, LogFun, ConnPid)
< end),
< post_start(Pid, LogFun).
<
< %% part of start/6 or start_link/6:
< post_start(Pid, _LogFun) ->
< %%Timeout = get_option(timeout, Options, ?DEFAULT_STANDALONE_TIMEOUT),
< %%TODO find a way to get configured Options here
< Timeout= ?DEFAULT_STANDALONE_TIMEOUT,
140,147c104,109
< stop(Pid),
< {error, Reason}
< % Unknown ->
< % mysql:log(_LogFun, error, "mysql_conn: Received unknown signal, exiting"),
< % mysql:log(_LogFun, debug, "mysql_conn: Unknown signal : ~p", [Unknown]),
< % {error, "unknown signal received"}
< after Timeout ->
< stop(Pid),
---
> {error, Reason};
> Unknown ->
> mysql:log(LogFun, error, "mysql_conn: Received unknown signal, exiting"),
> mysql:log(LogFun, debug, "mysql_conn: Unknown signal : ~p", [Unknown]),
> {error, "unknown signal received"}
> after 5000 ->
173d132
<
175,177c134
< squery(Pid, Query, From, []).
< fetch(Pid, Query, From, Timeout) ->
< squery(Pid, Query, From, [{timeout, Timeout}]).
---
> fetch(Pid, Query, From, ?DEFAULT_STANDALONE_TIMEOUT).
179c136
< squery(Pid, Query, From, Options) when is_pid(Pid), is_list(Query) ->
---
> fetch(Pid, Query, From, Timeout) when is_pid(Pid), is_list(Query), is_integer(Timeout) ->
181,183c138
< Timeout = get_option(timeout, Options, ?DEFAULT_STANDALONE_TIMEOUT),
< TRef = erlang:start_timer(Timeout, self(), timeout),
< Pid ! {fetch, TRef, Query, From, Options},
---
> Pid ! {fetch, Query, From},
187c142,147
< wait_fetch_result(TRef, Pid);
---
> receive
> {fetch_result, Pid, Result} ->
> Result
> after Timeout ->
> {error, "query timed out"}
> end;
193,218d152
< wait_fetch_result(TRef, Pid) ->
< receive
< {fetch_result, TRef, Pid, Result} ->
< case erlang:cancel_timer(TRef) of
< false ->
< receive
< {timeout, TRef, _} ->
< ok
< after 0 ->
< ok
< end;
< _ ->
< ok
< end,
< Result;
< {fetch_result, _BadRef, Pid, _Result} ->
< wait_fetch_result(TRef, Pid);
< {timeout, TRef, _} ->
< stop(Pid),
< {error, "query timed out"}
< end.
<
< stop(Pid) ->
< Pid ! close.
<
<
275,282c215,217
< {ok, Version} ->
< case do_query(Sock, RecvPid, LogFun, "use " ++ Database, Version, [{result_type, binary}]) of
< {error, MySQLRes} ->
< mysql:log(LogFun, error, "mysql_conn: Failed changing to database ~p : ~p",
< [Database, mysql:get_result_reason(MySQLRes)]),
< Parent ! {mysql_conn, self(), {error, failed_changing_database}};
< %% ResultType: data | updated
< {_ResultType, _MySQLRes} ->
---
> ok ->
> case do_query(Sock, RecvPid, LogFun, "use " ++ Database) of
> {ok, _Fields, _Rows} ->
284,285c219
< State = #state{mysql_version=Version,
< recv_pid = RecvPid,
---
> State = #state{recv_pid = RecvPid,
290c224,228
< loop(State)
---
> loop(State);
> {error, Reason} ->
> mysql:log(LogFun, error, "mysql_conn: Failed changing to database ~p : ~p",
> [Database, Reason]),
> Parent ! {mysql_conn, self(), {error, failed_changing_database}}
311c251
< {fetch, Ref, Query, GenSrvFrom, Options} ->
---
> {fetch, Query, GenSrvFrom} ->
314c254
< Res = do_query(State, Query, Options),
---
> Res = do_query(State, Query),
318c258
< GenSrvFrom ! {fetch_result, Ref, self(), Res};
---
> GenSrvFrom ! {fetch_result, self(), Res};
320,323d259
< %% the timer is canceled in wait_fetch_result/2, but we wait on that funtion only if the query
< %% was not sent using the mysql gen_server. So we at least should try to cancel the timer here
< %% (no warranty, the gen_server can still receive timeout messages)
< erlang:cancel_timer(Ref),
333,334d268
< close ->
< close_connection(State);
336,337c270,271
< mysql:log(State#state.log_fun, error, "mysql_conn: Received unknown signal, exiting : ~p", [Unknown]),
< close_connection(State),
---
> mysql:log(State#state.log_fun, error, "mysql_conn: Received unknown signal, exiting"),
> mysql:log(State#state.log_fun, debug, "mysql_conn: Unknown signal : ~p", [Unknown]),
355c293
< {Version, Salt1, Salt2, Caps} = greeting(Packet, LogFun),
---
> {Salt1, Salt2, Caps} = greeting(Packet, LogFun),
365c303
< {ok,Version};
---
> ok;
382c320
< <<Protocol:8, Rest/binary>> = Packet,
---
> <<_Protocol:8, Rest/binary>> = Packet,
389,391c327,329
< mysql:log(LogFun, debug, "mysql_conn: greeting version ~p (protocol ~p) salt ~p caps ~p serverchar ~p salt2 ~p",
< [Version, Protocol, Salt, Caps, ServerChar, Salt2]),
< {normalize_version(Version, LogFun), Salt, Salt2, Caps}.
---
> mysql:log(LogFun, debug, "mysql_conn: greeting version ~p salt ~p caps ~p serverchar ~p salt2 ~p",
> [Version, Salt, Caps, ServerChar, Salt2]),
> {Salt, Salt2, Caps}.
394c332
< asciz(Data) when is_binary(Data) ->
---
> asciz(Data) when binary(Data) ->
396c334
< asciz(Data) when is_list(Data) ->
---
> asciz(Data) when list(Data) ->
416c355
< get_query_response(LogFun, RecvPid, Version, Options) ->
---
> get_query_response(LogFun, RecvPid) ->
421,423c360
< %% No Tabular data
< <<AffectedRows:8, _Rest2/binary>> = Rest,
< {updated, #mysql_result{affectedrows=AffectedRows}};
---
> {ok, [], []};
426c363
< {error, #mysql_result{error=binary_to_list(Message)}};
---
> {error, binary_to_list(Message)};
428,429c365
< %% Tabular data received
< case get_fields(LogFun, RecvPid, [], Version) of
---
> case get_fields(LogFun, RecvPid, []) of
431,432c367
< ResultType = get_option(result_type, Options, ?DEFAULT_RESULT_TYPE),
< case get_rows(Fieldcount, LogFun, RecvPid, ResultType, []) of
---
> case get_rows(Fieldcount, LogFun, RecvPid, []) of
434c369
< {data, #mysql_result{fieldinfo=Fields, rows=Rows}};
---
> {ok, Fields, Rows};
436c371
< {error, #mysql_result{error=Reason}}
---
> {error, Reason}
439c374
< {error, #mysql_result{error=Reason}}
---
> {error, Reason}
443c378
< {error, #mysql_result{error=Reason}}
---
> {error, Reason}
457,458c395
< %% Support for MySQL 4.0.x:
< get_fields(LogFun, RecvPid, Res, ?MYSQL_4_0) ->
---
> get_fields(LogFun, RecvPid, Res) ->
477,479d413
< %% TODO: Check on MySQL 4.0 if types are specified
< %% using the same 4.1 formalism and could
< %% be expanded to atoms:
481,514c415
< get_fields(LogFun, RecvPid, [This | Res], ?MYSQL_4_0)
< end;
< {error, Reason} ->
< {error, Reason}
< end;
< %% Support for MySQL 4.1.x and 5.x:
< get_fields(LogFun, RecvPid, Res, ?MYSQL_4_1) ->
< case do_recv(LogFun, RecvPid, undefined) of
< {ok, Packet, _Num} ->
< case Packet of
< <<254:8>> ->
< {ok, lists:reverse(Res)};
< <<254:8, Rest/binary>> when size(Rest) < 8 ->
< {ok, lists:reverse(Res)};
< _ ->
< {_Catalog, Rest} = get_with_length(Packet),
< {_Database, Rest2} = get_with_length(Rest),
< {Table, Rest3} = get_with_length(Rest2),
< %% OrgTable is the real table name if Table is an alias
< {_OrgTable, Rest4} = get_with_length(Rest3),
< {Field, Rest5} = get_with_length(Rest4),
< %% OrgField is the real field name if Field is an alias
< {_OrgField, Rest6} = get_with_length(Rest5),
<
< <<_Metadata:8/little, _Charset:16/little,
< Length:32/little, Type:8/little,
< _Flags:16/little, _Decimals:8/little,
< _Rest7/binary>> = Rest6,
<
< This = {binary_to_list(Table),
< binary_to_list(Field),
< Length,
< get_field_datatype(Type)},
< get_fields(LogFun, RecvPid, [This | Res], ?MYSQL_4_1)
---
> get_fields(LogFun, RecvPid, [This | Res])
530c435
< get_rows(N, LogFun, RecvPid, ResultType, Res) ->
---
> get_rows(N, LogFun, RecvPid, Res) ->
537,538c442,443
< {ok, This} = get_row(N, Packet, ResultType, []),
< get_rows(N, LogFun, RecvPid, ResultType, [This | Res])
---
> {ok, This} = get_row(N, Packet, []),
> get_rows(N, LogFun, RecvPid, [This | Res])
544d448
<
546c450
< get_row(0, _Data, _ResultType, Res) ->
---
> get_row(0, _Data, Res) ->
548c452
< get_row(N, Data, ResultType, Res) ->
---
> get_row(N, Data, Res) ->
554,559c458
< if
< ResultType == list ->
< binary_to_list(Col);
< ResultType == binary ->
< Col
< end
---
> binary_to_list(Col)
561c460,461
< get_row(N - 1, Rest, ResultType, [This | Res]).
---
> get_row(N - 1, Rest, [This | Res]).
>
574,579d473
< close_connection(State) ->
< Result = gen_tcp:close(State#state.socket),
< mysql:log(State#state.log_fun, normal, "Closing connection ~p: ~p~n", [State#state.socket, Result]),
< Result.
<
<
590c486
< do_query(State, Query, Options) when is_record(State, state) ->
---
> do_query(State, Query) when is_record(State, state) ->
594,596c490
< Query,
< State#state.mysql_version,
< Options
---
> Query
599,600c493
< do_query(Sock, RecvPid, LogFun, Query, Version, Options) when is_pid(RecvPid),
< is_list(Query) ->
---
> do_query(Sock, RecvPid, LogFun, Query) when is_pid(RecvPid), is_list(Query) ->
604c497
< get_query_response(LogFun, RecvPid, Version, Options);
---
> get_query_response(LogFun, RecvPid);
623,693d517
<
< %%--------------------------------------------------------------------
< %% Function: normalize_version(Version, LogFun)
< %% Version = string()
< %% LogFun = undefined | function() with arity 3
< %% Descrip.: Return a flag corresponding to the MySQL version used.
< %% The protocol used depends on this flag.
< %% Returns : Version = string()
< %%--------------------------------------------------------------------
< normalize_version([$4,$.,$0|_T], LogFun) ->
< mysql:log(LogFun, debug, "Switching to MySQL 4.0.x protocol.~n"),
< ?MYSQL_4_0;
< normalize_version([$4,$.,$1|_T], _LogFun) ->
< ?MYSQL_4_1;
< normalize_version([$5|_T], _LogFun) ->
< %% MySQL version 5.x protocol is compliant with MySQL 4.1.x:
< ?MYSQL_4_1;
< normalize_version(_Other, LogFun) ->
< mysql:log(LogFun, error, "MySQL version not supported: MySQL Erlang module might not work correctly.~n"),
< %% Error, but trying the oldest protocol anyway:
< ?MYSQL_4_0.
<
< %%--------------------------------------------------------------------
< %% Function: get_field_datatype(DataType)
< %% DataType = integer(), MySQL datatype
< %% Descrip.: Return MySQL field datatype as description string
< %% Returns : String, MySQL datatype
< %%--------------------------------------------------------------------
< get_field_datatype(0) -> 'DECIMAL';
< get_field_datatype(1) -> 'TINY';
< get_field_datatype(2) -> 'SHORT';
< get_field_datatype(3) -> 'LONG';
< get_field_datatype(4) -> 'FLOAT';
< get_field_datatype(5) -> 'DOUBLE';
< get_field_datatype(6) -> 'NULL';
< get_field_datatype(7) -> 'TIMESTAMP';
< get_field_datatype(8) -> 'LONGLONG';
< get_field_datatype(9) -> 'INT24';
< get_field_datatype(10) -> 'DATE';
< get_field_datatype(11) -> 'TIME';
< get_field_datatype(12) -> 'DATETIME';
< get_field_datatype(13) -> 'YEAR';
< get_field_datatype(14) -> 'NEWDATE';
< get_field_datatype(16) -> 'BIT';
< get_field_datatype(246) -> 'DECIMAL';
< get_field_datatype(247) -> 'ENUM';
< get_field_datatype(248) -> 'SET';
< get_field_datatype(249) -> 'TINYBLOB';
< get_field_datatype(250) -> 'MEDIUM_BLOG';
< get_field_datatype(251) -> 'LONG_BLOG';
< get_field_datatype(252) -> 'BLOB';
< get_field_datatype(253) -> 'VAR_STRING';
< get_field_datatype(254) -> 'STRING';
< get_field_datatype(255) -> 'GEOMETRY'.
<
< %%--------------------------------------------------------------------
< %% Function: get_option(Key1, Options, Default) -> Value1
< %% Options = [Option]
< %% Option = {Key2, Value2}
< %% Key1 = Key2 = atom()
< %% Value1 = Value2 = Default = term()
< %% Descrip.: Return the option associated with Key passed to squery/4
< %%--------------------------------------------------------------------
<
< get_option(Key, Options, Default) ->
< case lists:keysearch(Key, 1, Options) of
< {value, {_, Value}} ->
< Value;
< false ->
< Default
< end.
Only in yxa-1.0/src/mysql/: overview.edoc
cube:~ hd$