[erlang-questions] gen_server and odbc problem about How to share a odbc connection
wenew zhang
wenewboy@REDACTED
Sat Mar 29 03:38:46 CET 2008
i even don't know what's the "State" mean!
now i got!
Best Regards
Wenew Zhang
2008/3/28, Anthony Kong <anthony.hw.kong@REDACTED>:
> "State" is here for you to store per server state information.
>
> So, you can
>
>
> init([]) ->
> process_flag(trap_exit, true),
> io:format("Authserver init with []~n"),
>
> {ok,Conn}=odbc:connect("DSN=flashpk;UID=flashpk;PWD=flashpk",[{trace_driver,on}]),
>
> {ok, [Conn]}. %% keep the connection in the state
>
>
> handle_info({?PLLOGIN,Uid,Pwd},State) ->
>
> [Conn] = State, %% get the connection back from the state
>
> io:format("PLLogin id:~w Uid:~w Pwd:~w~n",[?PLLOGIN,Uid,Pwd]),
> odbc:sql_query(Conn,"insert into customer(cno,password) values
> ('root','123456')"),
> {noreply, State}.
>
>
>
> Cheers, Anthony
>
>
> On Fri, Mar 28, 2008 at 10:23 PM, wenew zhang <wenewboy@REDACTED> wrote:
> > Dear All,
> > Maybe another low-level question,but it's make me confused,
> >
> > init([]) ->
> > process_flag(trap_exit, true),
> > io:format("Authserver init with []~n"),
> > % {ok,Bin}=file:consult(?AUTHCONF),
> > % DDsn=element(2,lists:nth(1,Bin)),
> > % Duser=element(2,lists:nth(2,Bin)),
> > % Dpwd=element(2,lists:nth(3,Bin)),
> > %%Ddatabase=element(2,lists:nth(4,Bin)),
> > % DSNString="DSN="++DDsn++";UID="++Duser++";PWD="++Dpwd,
> > % {ok,Conn}=odbc:connect(DSNString,[{trace_driver,on}]),%% read the
> > odbc settings
> > {ok,Conn}=odbc:connect("DSN=flashpk;UID=flashpk;PWD=flashpk",[{trace_driver,on}]),
> > {ok,0}.
> >
> > handle_info({?PLLOGIN,Uid,Pwd},_State) ->
> > io:format("PLLogin id:~w Uid:~w Pwd:~w~n",[?PLLOGIN,Uid,Pwd]),
> > odbc:sql_query(Conn,"insert into customer(cno,password) values
> > ('root','123456')"),
> > {noreply, _State}.
> >
> > i want share the Conn ,but i get the unbound error,
> > so How to share a odbc connection?
> > or anybody have other solutions?
> >
> > Best Regards
> >
> > wenew zhang
>
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://www.erlang.org/mailman/listinfo/erlang-questions
> >
>
>
>
>
> --
> /*--*/
> Don't EVER make the mistake that you can design something better than
> what you get from ruthless massively parallel trial-and-error with a
> feedback cycle. That's giving your intelligence _much_ too much
> credit.
>
> - Linus Torvalds
>
More information about the erlang-questions
mailing list