% utiles :
resultat_transaction/1\r
]).
--import(qlc, [e/1, e/2, q/1, cursor/1]).\r
+-import(qlc, [e/2, q/1, cursor/2]).\r
-include("../include/euphorik_bd.hrl").
-include("../include/euphorik_defines.hrl").\r
-include_lib("stdlib/include/qlc.hrl").\r
9,
q([E || E <- mnesia:table(user)]),
[{order, descending}]
- )
+ ),
+ [{tmpdir, ?KEY_SORT_TEMP_DIR}]
),
Users = qlc:next_answers(C, N),
lists:foreach(
user_by_cookie(Cookie) ->
resultat_transaction(mnesia:transaction(
fun() ->
- case e(q([E || E <- mnesia:table(user), E#user.cookie =:= Cookie])) of
+ case e(q([E || E <- mnesia:table(user), E#user.cookie =:= Cookie]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of
[User] -> {ok, User};
_ -> erreur
end
user_by_id(ID) ->
resultat_transaction(mnesia:transaction(
fun() ->
- case e(q([E || E <- mnesia:table(user), E#user.id =:= ID])) of
+ case e(q([E || E <- mnesia:table(user), E#user.id =:= ID]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of
[User] -> {ok, User};
_ -> erreur
end
user_by_login(Login) ->\r
resultat_transaction(mnesia:transaction(\r
fun() ->\r
- Users = e(q([E || E <- mnesia:table(user), E#user.login =:= Login])),\r
+ Users = e(q([E || E <- mnesia:table(user), E#user.login =:= Login]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]),\r
case Users of\r
[User] -> {ok, User};\r
_ -> erreur\r
toggle_ek_master(User_id) ->
resultat_transaction(mnesia:transaction(
fun() ->
- Users = e(q([E || E <- mnesia:table(user), E#user.id =:= User_id])),
+ Users = e(q([E || E <- mnesia:table(user), E#user.id =:= User_id]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]),
case Users of
[User] ->
mnesia:write(User#user{ek_master = not User#user.ek_master});
user_by_login_password(Login, Password) ->
resultat_transaction(mnesia:transaction(
fun() ->
- case e(q([E || E <- mnesia:table(user), E#user.login =:= Login, E#user.password =:= Password])) of
+ case e(q([E || E <- mnesia:table(user), E#user.login =:= Login, E#user.password =:= Password]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of
[User | _] -> {ok, User};
_ -> erreur
end
user_by_mess(Id) ->
resultat_transaction(mnesia:transaction(
fun() ->
- case e(q([U || U <- mnesia:table(user), M <- mnesia:table(minichat), M#minichat.id =:= Id, M#minichat.auteur_id =:= U#user.id])) of
+ case e(q([U || U <- mnesia:table(user), M <- mnesia:table(minichat), M#minichat.id =:= Id, M#minichat.auteur_id =:= U#user.id]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of
[User | _] -> {ok, User};
_ -> erreur
end
nouveau_message(Mess, Auteur_id, Repond_A) ->
% regarde si les id 'Repond_A' existent
F = fun() ->
- Nb_id_trouve = length(e(q([E#minichat.id || E <- mnesia:table(minichat), lists:member(E#minichat.id, Repond_A)]))),
+ Nb_id_trouve = length(e(q([E#minichat.id || E <- mnesia:table(minichat), lists:member(E#minichat.id, Repond_A)]), [{tmpdir, ?KEY_SORT_TEMP_DIR}])),
% est-ce que l'auteur existe ?
- Auteur = case e(q([E || E <- mnesia:table(user), E#user.id =:= Auteur_id])) of
+ Auteur = case e(q([E || E <- mnesia:table(user), E#user.id =:= Auteur_id]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of
[A] -> A;
_ -> {erreur, "L'auteur du message est introuvable"}
end,
2,
q([E#minichat{contenu = contenu_message(E)} || E <- mnesia:table(minichat)]),
[{order, descending}]
- )
+ ),
+ [{tmpdir, ?KEY_SORT_TEMP_DIR}]
),
if P > 1 -> qlc:next_answers(C, N * (P - 1));
true -> ok
2,
q([E || E <- mnesia:table(minichat), lists:any(fun(Id) -> Id =:= E#minichat.id end, Ids)]),
[{order, ascending}]
- ))
+ ),[{tmpdir, ?KEY_SORT_TEMP_DIR}])
end
)).
% TODO : ya pas plus simple ?
message_existe(Id) ->
resultat_transaction(mnesia:transaction(fun() ->
- length(e(q([E#minichat.id || E <- mnesia:table(minichat), E#minichat.id =:= Id]))) =:= 1
+ length(e(q([E#minichat.id || E <- mnesia:table(minichat), E#minichat.id =:= Id]), [{tmpdir, ?KEY_SORT_TEMP_DIR}])) =:= 1
end)).
% Renvoie les reponses (utilisé normalement uniquement pendant le debug).
reponses() ->
F = fun() ->
- e(q([E || E <- mnesia:table(reponse_minichat)]))
+ e(q([E || E <- mnesia:table(reponse_minichat)]), [{tmpdir, ?KEY_SORT_TEMP_DIR}])
end,
resultat_transaction(mnesia:transaction(F)).
[M || E <- mnesia:table(reponse_minichat),
M <- mnesia:table(minichat),
E#reponse_minichat.repondant =:= M_id,
- M#minichat.id =:= E#reponse_minichat.cible]))
+ M#minichat.id =:= E#reponse_minichat.cible]), [{tmpdir, ?KEY_SORT_TEMP_DIR}])
end
)).
e(q([
M#minichat.auteur_id || M <- mnesia:table(minichat), R <- mnesia:table(reponse_minichat),
M#minichat.auteur_id =:= Id_user, M#minichat.id =:= R#reponse_minichat.cible, R#reponse_minichat.repondant =:= Id_mess
- ]), [{unique_all, true}])
+ ]), [{unique_all, true}, {tmpdir, ?KEY_SORT_TEMP_DIR}])
end
) of
{atomic, [_]} -> true;
e(q([
M#minichat.auteur_id || M <- mnesia:table(minichat), R <- mnesia:table(reponse_minichat),
R#reponse_minichat.cible =:= Id_mess, R#reponse_minichat.repondant =:= M#minichat.id, M#minichat.auteur_id =:= Id_user
- ]), [{unique_all, true}])
+ ]), [{unique_all, true}, {tmpdir, ?KEY_SORT_TEMP_DIR}])
end
) of
{atomic, [_]} -> true;
possede_message(Id_user, Id_mess) ->
case mnesia:transaction(
fun() ->
- e(q([E#minichat.auteur_id || E <- mnesia:table(minichat), E#minichat.id =:= Id_mess]))
+ e(q([E#minichat.auteur_id || E <- mnesia:table(minichat), E#minichat.id =:= Id_mess]), [{tmpdir, ?KEY_SORT_TEMP_DIR}])
end
) of
{atomic, [Id_user | []]} -> true;
{
IP#ip_table.ip,
delta_date_minute(date_plus_minutes(IP#ip_table.ban, IP#ip_table.ban_duration), Now),
- e(q([{U#user.pseudo, U#user.login} || U <- mnesia:table(user), U#user.last_ip =:= IP#ip_table.ip]))
+ e(q([{U#user.pseudo, U#user.login} || U <- mnesia:table(user), U#user.last_ip =:= IP#ip_table.ip]), [{tmpdir, ?KEY_SORT_TEMP_DIR}])
} ||
IP <- mnesia:table(ip_table),
if IP#ip_table.ban =:= undefined -> false; true -> date_plus_minutes(IP#ip_table.ban, IP#ip_table.ban_duration) > Now end
- ])))
+ ])), [{tmpdir, ?KEY_SORT_TEMP_DIR}])
end
)).
U#user.id =:= User_id,
IP <- mnesia:table(ip_table),
IP#ip_table.ip =:= U#user.last_ip
- ])) of
+ ]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of
[{Ban, Ban_duration}] ->
Echeance = date_plus_minutes(Ban, Ban_duration),
Now = now(),
can_register(IP) ->
resultat_transaction(mnesia:transaction(
fun() ->
- case e(q([I || I <- mnesia:table(ip_table), I#ip_table.ip =:= IP])) of
+ case e(q([I || I <- mnesia:table(ip_table), I#ip_table.ip =:= IP]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of
[] ->
mnesia:write(#ip_table{ip = IP, date_last_try_register = now()}),
true;
trolls() ->
resultat_transaction(mnesia:transaction(
fun() ->
- e(qlc:keysort(2, q([T || T <- mnesia:table(troll)])))
+ e(qlc:keysort(2, q([T || T <- mnesia:table(troll)])), [{tmpdir, ?KEY_SORT_TEMP_DIR}])
end
)).
trolls(Last_id) ->
resultat_transaction(mnesia:transaction(
fun() ->
- e(qlc:keysort(2, q([T || T <- mnesia:table(troll), T#troll.id > Last_id, T#troll.date_post =:= undefined])))
+ e(qlc:keysort(2, q([T || T <- mnesia:table(troll), T#troll.id > Last_id, T#troll.date_post =:= undefined])), [{tmpdir, ?KEY_SORT_TEMP_DIR}])
end
)).
E#troll.id_user =:= User_id,
E#troll.date_post =:= undefined
]
- ))),
+ ), [{tmpdir, ?KEY_SORT_TEMP_DIR}])),
Nb_troll_poste_total = length(e(q(
[
E#troll.id || E <- mnesia:table(troll),
E#troll.date_post =:= undefined
]
- ))),
+ ), [{tmpdir, ?KEY_SORT_TEMP_DIR}])),
User = user_by_id(User_id),
case User of
{ok, _} ->
troll_by_id(Troll_id) ->
resultat_transaction(mnesia:transaction(
fun() ->
- case e(q([T || T <- mnesia:table(troll), T#troll.id =:= Troll_id])) of
+ case e(q([T || T <- mnesia:table(troll), T#troll.id =:= Troll_id]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of
[T] -> {ok, T};
_ ->
erreur
resultat_transaction(mnesia:transaction(
fun() ->
% TODO : ya pas moyen de désigner le champs plutot qu'avec un nombre pour le tri ?
- C = cursor(qlc:keysort(5, q([T || T <- mnesia:table(troll), T#troll.date_post =/= undefined]), [{order, descending}])),
+ C = cursor(qlc:keysort(5, q([T || T <- mnesia:table(troll), T#troll.date_post =/= undefined]), [{order, descending}]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]),
R = case qlc:next_answers(C, 1) of
[T] -> T;
_ -> aucun
random:seed(A1, A2, A3),
mnesia:transaction(
fun() ->
- case e(q([T || T <- mnesia:table(troll), T#troll.date_post =:= undefined])) of
+ case e(q([T || T <- mnesia:table(troll), T#troll.date_post =:= undefined]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of
[] ->
plus_de_trolls;
Trolls ->
message_id_associe(Troll_id) ->
resultat_transaction(mnesia:transaction(
fun() ->
- case e(q([M#minichat.id || M <- mnesia:table(minichat), M#minichat.troll_id =:= Troll_id])) of
+ case e(q([M#minichat.id || M <- mnesia:table(minichat), M#minichat.troll_id =:= Troll_id]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of
[Id] -> Id;
_ -> undefined
end
-export([\r
conversations/4\r
]).
--include("euphorik_bd.hrl").
+-include("../include/euphorik_bd.hrl").
+-include("../include/euphorik_defines.hrl").
-include_lib("stdlib/include/qlc.hrl").
-import(lists, [reverse/1, any/2, map/2, sublist/3, filter/2]).
-import(euphorik_bd, [resultat_transaction/1]).
--import(qlc, [e/1, q/1, keysort/3]).
+-import(qlc, [e/2, q/1, keysort/3]).
-import(mnesia, [table/1, transaction/1]).
conversations_detailees(Racines, N, D, P) ->
Conversations = map(fun({Racine, P_conv, Dernier}) -> conversation(Racine, N, Dernier, P_conv) end, Racines),
Conversation_principale = resultat_transaction(transaction(fun() ->
- Curseur = qlc:cursor(q([E#minichat.id || E <- qlc:sort(table(minichat), [{order, descending}])])),
+ Curseur = qlc:cursor(q([E#minichat.id || E <- qlc:sort(table(minichat), [{order, descending}])]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]),
{CP, Plus} = conversation_principale(Curseur, Conversations, N, P),
qlc:delete_cursor(Curseur),
{[M || M <- CP, M > D], Plus} % filtre en fonction de D
qlc:sort(
q([E#reponse_minichat.repondant || E <- table(reponse_minichat), E#reponse_minichat.cible =:= M]),
[{order, ascending}]
- )
+ ),
+ [{tmpdir, ?KEY_SORT_TEMP_DIR}]
)
end)).
qlc:sort(
q([E#reponse_minichat.cible || E <- table(reponse_minichat), E#reponse_minichat.repondant =:= M]),
[{order, ascending}]
- )
+ ),
+ [{tmpdir, ?KEY_SORT_TEMP_DIR}]
)
end)).