Thread: asynchronous support

asynchronous support

From
Radhesh Krishnan K
Date:

Hi,

I  wanted to lock a table from one application and insert some data. And my requirement is, if that table is already locked by anyother process then I need to try to lock after a specific amount of time.

I am using unixODBC driver in centOS machine and my database is postgresql. I did a research on how to execute a sql asynchronously using odbc api. I found SQLSetStmtAttr api can be used to execute the sql statement asynchronously. But its not working. 

This is how I wrote the code 

ret =  SQLSetStmtAttr( stmt1,  SQL_ATTR_ASYNC_ENABLE,(SQLPOINTER) SQL_ASYNC_ENABLE_ON, 0);
// above statement returned 0 which means success

 
if((ret = SQLExecDirect(stmt1,"lock table test",SQL_NTS)) == SQL_STILL_EXECUTING)
 
{
     printf
("\nCanceling\n");
     ret
= SQLCancel(stmt);
 
}

But process is getting hang on SQLExecDirect api, as that table "test" is already locked by another process. (Hang in the sense, waiting for all other processes to release the lock)

Why is it so ? Is that because my unixODBC driver does not support asynchronous execution. if its so why SQLSetStmtAttr is returning success ?

Any help is greatly appreciated. Thanks in advance.


--
 
 
 
 
Regards,
Radhesh Krishnan K.

Re: asynchronous support

From
Radhesh Krishnan K
Date:
Hi Nick,


Thanks for your quick response.


Hi, from a unixODBC perspective, async should work fine, but make sure that the driver manager is not set to searialise threads, Check that Theading=0 is set in the odbcinst.ini entry for the driver. Current (2.3.x) builds of unixODBC default to this but in the past drivers were often not thread safe.

 
Currently in my odbcinst.ini I don't see any "Threading" field. Should I add that, If so what should be the value ? 
 

--
 
 
 
 
Thanks & Regards,
Radhesh Krishnan K.