Cursors across threads

Like prepared statements, cursors are scoped at the connection level. That is, they are associated with a connection. When a thread makes a connection active, it can access any of the database cursors that are declared for this connection. If your thread-safe application uses database cursors, you might want to isolate the declaration of cursors in much the same way that you can isolate prepared statements (see Prepared statements across threads). The following code fragment shows a modified version of the start_con_thread() function (in Using prepared SQL statements across threads). This version prepares an SQL statement and declares a cursor for that statement:
EXEC SQL connect to 'db1' as 'con1';
EXEC SQL prepare s1 ....
EXEC SQL declare cursor cursor1 for s1;
EXEC SQL set connection 'con1' dormant;