• Subject: DB2 cli in multithread app
  • From: "Adolfo Lopez Escribano" <escriban@xxxxxxxxxxxx>
  • Date: Tue, 1 Aug 2000 12:21:08 +0200

Hello,
I've a little problem in a multithread aplication using DB2 CLI API. See first an extract of the code
 
------------------------------------------------------------------------------------------------------------------------------------------
    struct tableEntry{
        SQLCHAR     tableName[11];
        SQLINTEGER  lastId;
        SQLHSTMT hstmt;         /* prepared statement for update */
        struct tableEntry* nextTableEntry;
    };
 
    struct schemaEntry{
        SQLCHAR     schemaName[11];
        SQLCHAR     tableCounterName[11];
        int         tablesNumber;
        struct tableEntry* tableEntry;
        struct schemaEntry* nextSchemaEntry;
    };
.
.
.
 
/* global sql variables */
struct schemaEntry* firstSchema;
SQLHENV henv;
SQLHDBC hdbc;
SQLCHAR msgFmt[80];
.
.
.
 
SQLRETURN updateTable( struct schemaEntry* se, struct tableEntry* te )
{
   SQLRETURN returnCode;
 
   if( !te->hstmt ){
       returnCode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &(te->hstmt));
       CHECK_HANDLE( SQL_HANDLE_DBC, hdbc, returnCode );
       if( returnCode != SQL_SUCCESS )
           return returnCode;
       sprintf( msgFmt, "UPDATE %s.%s SET UltimoId = UltimoId + 1 "
                     "WHERE NombreTbl = \'%s\'",
            se->schemaName, se->tableCounterName, te->tableName );
       returnCode = SQLPrepare( te->hstmt, msgFmt, SQL_NTS );
       CHECK_HANDLE( SQL_HANDLE_STMT, te->hstmt, returnCode );
       if( returnCode != SQL_SUCCESS )
           return returnCode;
   }
   returnCode = SQLExecute( te->hstmt );
   CHECK_HANDLE( SQL_HANDLE_STMT, te->hstmt, returnCode );
   return returnCode;
}
------------------------------------------------------------------------------------------------------------------------------------------
 
 
 
 My problem is that I want to prepare the statement only one twice in a global variable from the first thread that required its value. The first thread that use this function update the table without problems, but the second and the rest, the SQLExecute fails with a machine error in module SQLCLI.
I think that SQLAllocHandle reserves memory in the head of the first thread that uses this function, the handle is global but the memory reserved around this handle is thread-private.
I'd like to somebody confirm me this idea.
 
Of course, the function called is between a mutex lock.
I'm working in a V4R4 version.
 
Regards
 
Adolfo Lopez
 

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].