- 论坛徽章:
- 27
|
- -module(myapp_app).
- -behaviour(application).
- -record(example,{id,deviceName,iPAddress,port}).
- -include_lib("stdlib/include/qlc.hrl").
- %% Application callbacks
- -compile(export_all).
- %% ===================================================================
- %% Application callbacks
- %% ===================================================================
- start(_StartType, _StartArgs) ->
- myapp_sup:start_link().
- init_table()->
- mnesia:start(),
- mnesia:create_table(example,[{attributes,record_info(fields,example)}]),
- read_txt().
- read_txt()->
- {ok,S}=file:read_file("example.txt"),
- i(S).
-
- i(S)->
- T=erlang:binary_to_list(S),
- R=string:tokens(T,"\r\n"),
- [ spawn(fun()->insert_data(U) end) || U <- R ].
- insert_data(L)->
- [N,H,I,P]=string:tokens(lists:flatten(L),","),
- Row = #example{id=N,deviceName=H,iPAddress=I,port=P},
- %io:format([Row]),
- F=fun()->
- mnesia:write(Row)
- end,
- mnesia:transaction(F).
- q()->
- F = fun() ->
- Q = qlc:q([[E#example.deviceName, E#example.port] || E <- mnesia:table(example)]),
- qlc:e(Q)
- end,
- mnesia:transaction(F).
复制代码 |
|