Skip to Content
0
Former Member
Aug 01, 2016 at 01:26 PM

How can I set a query timeout when connecting using unixODBC

712 Views

Hello dear community members,

I'm working on an application that connects to the SAP HANA database using the C++ unixODBC adapter and the SAP hdbODBC driver.

Everything is working perfectly, except for a single feature I just cannot implement.

I'm trying to set a timeout before executing statements (We don't want to wait for a response if it takes more than X seconds).

I've tried to accomplish this using the SQLSetStmtAttr, but it just won't work.

This is a snippet from our code:

// Allocate statement handle ret = SQLAllocHandle(SQL_HANDLE_STMT, m_dbc, &handle); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) { printError("SQLAllocHandle(SQL_HANDLE_STMT)", handle, SQL_HANDLE_STMT); return false;

}

// Set statement timeout ret = SQLSetStmtAttr(handle, SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER)timeout, 0); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) { printError("SQLSetStmtAttr(SQL_HANDLE_STMT)", handle, SQL_HANDLE_STMT); return false;

}

// Execute stmt ret = SQLExecDirect(handle, stmt, SQL_NTS); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) { printError("SQLExecDirect(SQL_HANDLE_STMT)", handle, SQL_HANDLE_STMT); SQLFreeHandle(SQL_HANDLE_STMT, handle); return false;

}

I tried to look for more ways to implement a timeout, and found a couple of posts on the subject:

I found references saying that HDB ODBC driver didn't support the timeout attribute, but couldn't find any formal reference.

On the other hand, I saw a post claiming you can add a TIMEOUT=X property to the connection string, which didn't work either.

Can you please help point me to the right direction?

Is this going to be a wild-goose chase?

Thanks!