IBM Support

How to set a timeout for queries using the ODBC API

Question & Answer


Question

What is SQL_ATTR_QUERY_TIMEOUT?

Answer

SQL_ATTR_QUERY_TIMEOUT is an attribute on a statement handle that allows you to set a timeout value for SQL queries ran through the ODBC API.

What it does

SQL_ATTR_QUERY_TIMEOUT tells ODBC to limit the amount of time a query can take to run. The time required to fetch the data returned by the query is not included.

What products have it

This feature is available in the IBM Informix® ODBC driver found in:



Product
Version
Operating System
IBM Informix SDK
2.80.xC1 or higher
All
x can be T, U, H, or F depending on your operating system.

How to use it

Call the ODBC API function SQLSetStmtAttr and pass the SQL_ATTR_QUERY_TIMEOUT constant along with a timeout value given in seconds. A timeout value of 0 (zero) disables the timeout.

Example:

This example shows you how to set SQL_ATTR_QUERY_TIMEOUT.

SQLSetStmtAttr(hstmt, SQL_ATTR_QUERY_TIMEOUT,(SQLPOINTER)secs, SQL_IS_UINTEGER);
    hstmt
      This is a valid ODBC statement handle.
    secs
      This is a SQLUINTEGER that can be 0 or greater.
[{"Product":{"code":"SSVT2J","label":"Informix Tools"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"Informix Client Software Development Kit (CSDK)","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF025","label":"Platform Independent"},{"code":"PF008","label":"DYNIX\/ptx"},{"code":"PF010","label":"HP-UX"},{"code":"PF015","label":"IRIX"},{"code":"PF016","label":"Linux"},{"code":"PF026","label":"Reliant UNIX"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"1.0;1.1;1.2;1.3;1.4;1.5;1.6;2.0;2.1;2.2;2.3;2.4;2.5;2.6;2.7;2.8;2.9;3.0;4.0;4.1;4.2;5.1;6.0;7.2;7.3","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Document Information

More support for:
Informix Tools

Software version:
1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 4.0, 4.1, 4.2, 5.1, 6.0, 7.2, 7.3

Operating system(s):
AIX, DYNIX/ptx, HP-UX, IRIX, Linux, Reliant UNIX, Solaris, Windows

Document number:
80431

Modified date:
20 January 2022

UID

swg21190442

Manage My Notification Subscriptions