Guest User

Untitled

a guest
Feb 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. -module(mysql_proto_constants).
  2. -compile(export_all).
  3.  
  4. client_flags() ->
  5. [{long_password, 1, "new more secure passwords"}
  6. ,{found_rows, 2, "Found instead of affected rows"}
  7. ,{long_flag, 4, "Get all column flags"}
  8. ,{connect_with_db, 8, "One can specify db on connect"}
  9. ,{no_schema, 16, "Don't allow database.table.column"}
  10. ,{compress, 32, "Can use compression protocol"}
  11. ,{odbc, 64, "Odbc client"}
  12. ,{local_files, 128, "Can use LOAD DATA LOCAL"}
  13. ,{ignore_space, 256, "Ignore spaces before '('"}
  14. ,{protocol_41, 512, "New 4.1 protocol" }
  15. ,{interactive, 1024, "This is an interactive client"}
  16. ,{ssl, 2048, "Switch to SSL after handshake"}
  17. ,{ignore_sigpipe, 4096, "IGNORE sigpipes"}
  18. ,{transactions, 8192, "Client knows about transactions"}
  19. ,{reserved, 16384, "Old flag for 4.1 protocol "}
  20. ,{secure_connection, 32768, "New 4.1 authentication"}
  21. ,{multi_statements, 65536, "Enable/disable multi-stmt support"}
  22. ,{multi_results, 131072, "Enable/disable multi-results"}
  23. ].
  24.  
  25. client_flags(Value) when is_integer(Value) ->
  26. lists:reverse(flags(Value, client_flags())).
  27.  
  28. flags(Flags, FlagDefs) when is_integer(Flags) ->
  29. lists:foldl(fun ({Flag, Pos, _Desc}, Acc)
  30. when Flags band Pos =/= 0 ->
  31. [Flag | Acc];
  32. (_, Acc) -> Acc
  33. end,
  34. [],
  35. FlagDefs).
  36.  
  37. flag_value(Atom) when is_atom(Atom) ->
  38. {value, {Atom, Mask, _Desc}} = lists:keysearch(Atom, 1, client_flags()),
  39. Mask;
  40. flag_value([]) ->
  41. 0;
  42. flag_value([H|T]) ->
  43. flag_value(H) bor flag_value(T).
  44.  
  45. flag_value(Flags, FlagDefs) ->
  46. lists:foldl(fun (Flag, Acc) ->
  47. case lists:keysearch(Flag, 1, FlagDefs) of
  48. {value, {Flag, Pos, _Desc}} ->
  49. Acc bor Pos;
  50. false -> Acc
  51. end
  52. end,
  53. 0,
  54. Flags).
Add Comment
Please, Sign In to add comment