Thread: Ecpg and reentrancy

Ecpg and reentrancy

From
"Dann Corbit"
Date:
Suggestion:
Because the Ecpg project uses a global sqlca, it can be accessed by only
one thread at a time.
If (instead) we had a user supplied sqlca, it could be used by multiple
threads.
Why not have the user allocate the sqlca or pass it in as a parameter
(maybe they want an auto sqlca).
In any case: a single, global sqlca is a very bad thing. (IMO-YMMV).

Question:
Why no sqlda structure?  Every other embedded SQL I have used has the
sqlda {and it is darn useful}.


Re: Ecpg and reentrancy

From
Michael Meskes
Date:
On Mon, Feb 04, 2002 at 04:51:38PM -0800, Dann Corbit wrote:
> Because the Ecpg project uses a global sqlca, it can be accessed by only
> one thread at a time.

That's correct.

> If (instead) we had a user supplied sqlca, it could be used by multiple
> threads.

How do you want to supply it? 

> Why not have the user allocate the sqlca or pass it in as a parameter
> (maybe they want an auto sqlca).

That's not exactly the way other RDBMS handle it. Thus compatibility might
become a problem. 

> In any case: a single, global sqlca is a very bad thing. (IMO-YMMV).

Okay, let's talk about a better way.

> Question:
> Why no sqlda structure?  Every other embedded SQL I have used has the
> sqlda {and it is darn useful}.

Noone volunteered to implement it. :-)

Michael
-- 
Michael Meskes
Michael@Fam-Meskes.De
Go SF 49ers! Go Rhein Fire!
Use Debian GNU/Linux! Use PostgreSQL!


Re: Ecpg and reentrancy

From
"Zeugswetter Andreas SB SD"
Date:
> > If (instead) we had a user supplied sqlca, it could be used by multiple
> > threads.
> 
> How do you want to supply it? 

Informix does this:

#else /* IFX_THREAD */
extern long * ifx_sqlcode();
extern struct sqlca_s * ifx_sqlca();
#define SQLCODE (*(ifx_sqlcode()))
#define SQLSTATE ((char *)(ifx_sqlstate()))
#define sqlca (*(ifx_sqlca()))
#endif /* IFX_THREAD */

They use one sqlca per active connection/thread. A connection is basically tied 
to a specific thread. If you want to use the conn in another thread you need 
to:
EXEC SQL SET CONNECTION DORMANT; EXEC SQL SET CONNECTION ...
When using the esql processor, you need to specify which thread package you use
(posix, dce, ...), so they know with which functioncall to get the current 
thread id. Of course this costs, so they have a switch to turn it on (-thread).

Andreas