Product Documentation

SQL Operations Guide

Previous Topic

Next Topic

Query Timeout Option

FairCom DB SQL supports a timeout option for an executing query. This feature can ensure that an unintended query statement does not consume excessive processing time for FairCom DB SQL.

Examples

With FairCom DB SQL ODBC you can set the query timeout value for the statement with the SQLSetStmtAttr() FairCom DB SQL ODBC API function and the SQL_ATTR_QUERY_TIMEOUT parameter set to the number of seconds to wait for the query to execute before returning to the application. A value of 0 indicates no timeout value, which is also the default. The following example code will set a query timeout value of five seconds for the referenced statement handle.

ODBC Example

/* Set the Query timeout to 5 seconds */

SQLSetStmtAttr(hstmt, (void*)SQL_ATTR_QUERY_TIMEOUT, 5, 0);

In Java with the FairCom DB SQL JDBC Driver, you can use the setQueryTimeout() method of the java.sql.Statement interface as shown here.

JDBC Example

Class.forName (“ctree.jdbc.ctreeDriver”);

Connection myConnection = DriverManager.getConnection(“jdbc:ctree:6597@localhost:ctreeSQL”, ADMIN, ADMIN”);

Statement myStatement = myConnection.createStatement();

String query = “SELECT TOP 50000 FROM my_big_table WHERE this < that AND this_string = 'that_string' ORDER BY foo”

myStatement:setQueryTimeout(5);

myStatement.executeUpdate(query);

Using ADO .NET with the FairCom DB SQL Data Provider, you specify the query timeout with the CommandTimeout property of the CtreeSQLCommand component.

ADO .NET Example

myCommand = new CtreeSqlCommand(““, this.myConnection);

myCommand.CommandText = “SELECT TOP 50000 FROM my_big_table WHERE this < that AND this_string = 'that_string' ORDER BY foo”;

myCommand.CommandTimeout = 5;

try {

myCommand.ExecuteReader();

}

catch (CtreeSQLException ex) {

//Log some error.

}

Using ODBC through ADO.NET, you can specify the OdbcConnection.CommandTimeout property to set a query timeout value on an ODBC statement as demonstrated with the following syntax.

FairCom DB SQL ODBC via ADO .NET Example

OdbcConnection myConnection = new OdbcConnection();

myConnection.ConnectionString = "DSN=c-treeSQL ODBC Database";

myConnection.Open();

OdbcCommand oc = new OdbcCommand("SELECT TOP 50000 FROM my_big_table WHERE this < that AND this_string = 'that_string' ORDER BY foo”, myConnection);

// Set a query timeout of 5 seconds.

oc.CommandTimeout = 5;

try

{

oc.ExecuteReader();

}

catch (Exception ex)

{

// Log some error

}

TOCIndex