[freetds] Query Time Out

Christos Zoulas christos at zoulas.com
Tue Aug 8 11:30:12 EDT 2006


On Aug 8,  4:08pm, Frediano.Ziglio at vodafone.com ("ZIGLIO, Frediano, VF-IT") wrote:
-- Subject: Re: [freetds] Query Time Out

| Actually I wrote these changes


Why don't you use gettimeofday?

christos
| 
| Index: src/tds/query.c
| ===================================================================
| RCS file: /cvsroot/freetds/freetds/src/tds/query.c,v
| retrieving revision 1.196
| diff -u -1 -0 -r1.196 query.c
| --- src/tds/query.c	7 Aug 2006 19:37:59 -0000	1.196
| +++ src/tds/query.c	8 Aug 2006 12:36:07 -0000
| @@ -998,20 +998,21 @@
|  		*dyn_out = dyn;
|  
|  	if (!IS_TDS50(tds) && !IS_TDS7_PLUS(tds)) {
|  		dyn->emulated = 1;
|  		return TDS_SUCCEED;
|  	}
|  
|  	if (tds_set_state(tds, TDS_QUERYING) != TDS_QUERYING)
|  		goto failure_nostate;
|  
| +	tds->query_start_time = time(NULL);
|  	query_len = strlen(query);
|  
|  	if (IS_TDS7_PLUS(tds)) {
|  		int definition_len = 0;
|  		char *param_definition = NULL;
|  		int converted_query_len;
|  		const char *converted_query;
|  
|  		param_definition = tds_build_param_def_from_query(tds,
| query, query_len, params, &converted_query, &converted_query_len,
| &definition_len);
|  		if (!param_definition)
| @@ -1109,20 +1110,21 @@
|  	query_len = strlen(query);
|  
|  	if (IS_TDS7_PLUS(tds)) {
|  		int definition_len = 0, i;
|  		char *param_definition = NULL;
|  		int converted_query_len;
|  		const char *converted_query;
|  
|  		if (tds_set_state(tds, TDS_QUERYING) != TDS_QUERYING)
|  			return TDS_FAIL;
| +		tds->query_start_time = time(NULL);
|  
|  		param_definition = tds_build_param_def_from_query(tds,
| query, query_len, params, &converted_query, &converted_query_len,
| &definition_len);
|  		if (!param_definition) {
|  			tds_set_state(tds, TDS_IDLE);
|  			return TDS_FAIL;
|  		}
|  
|  		tds->out_flag = TDS_RPC;
|  		/* procedure name */
|  		if (IS_TDS80(tds)) {
| @@ -1172,34 +1174,36 @@
|  
|  		dyn->emulated = 1;
|  		dyn->params = params;
|  		dyn->query = strdup(query);
|  		if (!dyn->query)
|  			ret = TDS_FAIL;
|  		if (ret != TDS_FAIL)
|  			if (tds_set_state(tds, TDS_QUERYING) !=
| TDS_QUERYING)
|  				ret = TDS_FAIL;
|  		if (ret != TDS_FAIL) {
| +			tds->query_start_time = time(NULL);
|  			ret = tds_send_emulated_execute(tds, dyn->query,
| dyn->params);
|  			if (ret == TDS_SUCCEED)
|  				ret = tds_query_flush_packet(tds);
|  		}
|  		/* do not free our parameters */
|  		dyn->params = NULL;
|  		tds_free_dynamic(tds, dyn);
|  		return ret;
|  	}
|  
|  	tds->cur_dyn = dyn;
|  
|  	if (tds_set_state(tds, TDS_QUERYING) != TDS_QUERYING)
|  		return TDS_FAIL;
| +	tds->query_start_time = time(NULL);
|  
|  	tds->out_flag = TDS_NORMAL;
|  
|  	id_len = strlen(dyn->id);
|  	tds_put_byte(tds, TDS5_DYNAMIC_TOKEN);
|  	tds_put_smallint(tds, query_len + id_len * 2 + 21);
|  	tds_put_byte(tds, 0x08);
|  	tds_put_byte(tds, params ? 0x01 : 0);
|  	tds_put_byte(tds, id_len);
|  	tds_put_n(tds, dyn->id, id_len);
| @@ -1566,20 +1570,21 @@
|  	int id_len;
|  
|  	CHECK_TDS_EXTRA(tds);
|  	/* TODO this dynamic should be in tds */
|  	CHECK_DYNAMIC_EXTRA(dyn);
|  
|  	tdsdump_log(TDS_DBG_FUNC, "tds_submit_execute()\n");
|  
|  	if (tds_set_state(tds, TDS_QUERYING) != TDS_QUERYING)
|  		return TDS_FAIL;
| +	tds->query_start_time = time(NULL);
|  
|  	tds->cur_dyn = dyn;
|  
|  	if (IS_TDS7_PLUS(tds)) {
|  		/* check proper id */
|  		if (dyn->num_id == 0) {
|  			tds_set_state(tds, TDS_IDLE);
|  			return TDS_FAIL;
|  		}
|  
| @@ -1703,20 +1708,21 @@
|  	CHECK_DYNAMIC_EXTRA(dyn);
|  
|  	if (!dyn)
|  		return TDS_FAIL;
|  
|  	tdsdump_log(TDS_DBG_FUNC, "tds_submit_unprepare() %s\n",
| dyn->id);
|  
|  	if (tds_set_state(tds, TDS_QUERYING) != TDS_QUERYING)
|  		return TDS_FAIL;
|  
| +	tds->query_start_time = time(NULL);
|  	tds->cur_dyn = dyn;
|  
|  	if (IS_TDS7_PLUS(tds)) {
|  		/* RPC on sp_execute */
|  		tds->out_flag = TDS_RPC;
|  		/* procedure name */
|  		if (IS_TDS80(tds)) {
|  			/* save some byte for mssql2k */
|  			tds_put_smallint(tds, -1);
|  			tds_put_smallint(tds, TDS_SP_UNPREPARE);
| @@ -1776,20 +1782,21 @@
|  
|  	CHECK_TDS_EXTRA(tds);
|  	if (params)
|  		CHECK_PARAMINFO_EXTRA(params);
|  
|  	assert(tds);
|  	assert(rpc_name);
|  
|  	if (tds_set_state(tds, TDS_QUERYING) != TDS_QUERYING)
|  		return TDS_FAIL;
| +	tds->query_start_time = time(NULL);
|  
|  	/* distinguish from dynamic query  */
|  	tds->cur_dyn = NULL;
|  
|  	rpc_name_len = strlen(rpc_name);
|  	if (IS_TDS7_PLUS(tds)) {
|  		const char *converted_name;
|  		int converted_name_len;
|  
|  		tds->out_flag = TDS_RPC;
| 
| 
| Mainly set query_start_time when state goes to TDS_QUERYING, perhaps it
| should be set even when state goes from QUERYING to PENDING.
| 
| freddy77
| 
| _______________________________________________
| FreeTDS mailing list
| FreeTDS at lists.ibiblio.org
| http://lists.ibiblio.org/mailman/listinfo/freetds
-- End of excerpt from "ZIGLIO, Frediano, VF-IT"





More information about the FreeTDS mailing list