diff --git a/doc/src/sgml/ecpg.sgml b/doc/src/sgml/ecpg.sgml index cdc4761c60..c0734cd6c4 100644 --- a/doc/src/sgml/ecpg.sgml +++ b/doc/src/sgml/ecpg.sgml @@ -222,12 +222,36 @@ EXEC SQL CONNECT TO target AS The connection-name is used to handle multiple connections in one program. It can be omitted if a - program uses only one connection. The most recently opened - connection becomes the current connection, which is used by default - when an SQL statement is to be executed (see later in this - chapter). + program uses only one connection. + + The most recently opened connection becomes the current connection. + If your application uses multiple threads, each thread has its own + current connection, and it is the most recently opened connection + in each thread. Threads that have not yet opened the current + connection treat the most recently opened connection in the + application as the current connection. The current connection is + used by default when an SQL statement is to be executed (see later + in this chapter). + + + + + If you execute an SQL statement without connection name in a thread in + multiple thread application, a thread must not do + DISCONNECT command for a connection which is + used as the current connection in other threads. In particular, + you should follow one of the following two use cases. The first is that + one thread does all the CONNECT and + DISCONNECT commands. Other threads just use the + current connection, with mutual exclusion. The second is that each + thread does its own CONNECT, DISCONNECT, + and other commands. Each thread has its own current connection. + No sharing at all. + + + Here are some examples of CONNECT statements: @@ -276,8 +300,8 @@ EXEC SQL CONNECT TO :target USER :user USING :passwd; SQL statements in embedded SQL programs are by default executed on - the current connection, that is, the most recently opened one. If - an application needs to manage multiple connections, then there are + the current connection, that is, the most recently opened one in each thread. + If an application needs to manage multiple connections, then there are three ways to handle this.