Asynchronous ODBC

Michael McDaniel erlang@REDACTED
Wed May 31 21:13:00 CEST 2006


On Wed, May 31, 2006 at 10:09:38AM +0200, Bengt Kleberg wrote:
> On 2006-05-31 04:35, Michael FIG wrote:
> ...deleted
> >Looking at odbc.erl, everything is written in a synchronous style, so it 
> >appears the only way to use it asynchronously is to write an asynchronous 
> >wrapper for it and run the wrapper on another node so that when it blocks 
> >during each call() it doesn't block the caller of the wrapper.
> 
> imho it would be sufficient to have the wrapper in another process 
> (created by erlang:spawn/1). there is no need to involve another node.
> please accept my apology if i have misunderstood something.
> 
> 
> bengt
> -- 
>    EPO giudelines 1978: "If the contribution to the known art resides
>    solely in a computer program then the subject matter is not
>    patentable in whatever manner it may be presented in the claims."
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I agree with bengt (with, apparently, the same understanding of your
question).

Here is an extract of code I use in a production system which works fine for the
last year ...

----------
-module(x).
-export([x/0]).


funA(Req)

 spawn_link(dbexp, callComplete, [Req#crec.callid]) ,

 ...

.
---------
-module(dbexp).
-export([callComplete/1]).

callComplete(CallId) ->
% used from command line for testing or as 
% spawn(dbexp, callComplete, [CallId]) for background updates
%
  Ref = ?MODULE:conn(1000) ,    %% wrapper for odbc:connect/2
  Z = "update callinfo set complete_ts=NOW() where callid = " ++ 
      integer_to_list(CallId) ++ " ;" ,

  case odbc:sql_query(Ref, Z) of
    {updated, Return} -> odbc:disconnect(Ref), {updated, Return} ;
    {error, Error}    -> odbc:disconnect(Ref), 
		       expmaster:log_error(?MODULE, ?LINE,
		 'dbexp:callComplete,odbc:sql_query', Error), {error, Error}
end
.
----------

~Michael



More information about the erlang-questions mailing list