Thread: SQLNumResultCols does not have a timeout
Hello,
I stuck in
SQLNumResultCols
after
unplug my Ethernet cable.My configuration:
-----------------
server - Linux x86 + postgresql 14.2
client - Linux x86 + postgresql ODBC 16.00
Problem description: --------------------
My code is as follow:
SQLHENV henv;
SQLHDBC hdbc;
SQLRETURN retcode;
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0);
SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
SQLCHAR* connStr = (SQLCHAR*)"DRIVER={PostgreSQL};"
"SERVER=173.20.99.107;"
"Port=5432;"
"DATABASE=cpspg;"
"UserName=sac;"
"Password=sac;"
"Keepalive=1"
"KeepaliveTime=1;"
"KeepaliveInterval=1"
"Parse=1"
"UseServerSidePrepare=0";
//"CHARSET=UTF8;"
//"AUTOCOMMIT=0";
retcode = SQLDriverConnect(hdbc, NULL, connStr, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT);
if (retcode == SQL_SUCCESS || retcode== SQL_SUCCESS_WITH_INFO)
{
SQLHANDLE hstmt;
SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
const char* sql_statement = "select now()";
retcode = SQLPrepare(hstmt, (SQLCHAR*)sql_statement, SQL_NTS);
std::string temp;
std::cout << "input something:";
std::cin >> temp;
SQLSMALLINT count;
retcode = SQLNumResultCols(hstmt, &count);
std::cout << "col count is " << count << std::endl;
if (retcode == SQL_SUCCESS || retcode== SQL_SUCCESS_WITH_INFO)
{
std::cout << "insert success" << std::endl;
}
else
{
HandleDiagnosticRecord(hdbc, SQL_HANDLE_DBC, retcode);
}
//SQLEndTran(SQL_HANDLE_DBC, hdbc, SQL_ROLLBACK);
SQLEndTran(SQL_HANDLE_DBC, hdbc, SQL_COMMIT);
SQLDisconnect(hdbc);
}
else
{
HandleDiagnosticRecord(hdbc, SQL_HANDLE_DBC, retcode);
}
SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
SQLFreeHandle(SQL_HANDLE_ENV, henv);
I unplug my Ethernet cable when wait input and then input something, the program stucked in SQLNumResultCols. Finally got stuck in function PQgetResult and pqWaitTimed.
So my question is: Is this a bug or how to set timeout when the network has lost?
Thanks
Jin