diff -Nacr a/connection.c b/connection.c
*** a/connection.c	2016-04-15 22:11:34.000000000 +0900
--- b/connection.c	2016-05-26 17:22:08.000000000 +0900
***************
*** 988,994 ****
  	return 1;
  }
  
- static	char	CC_setenv(ConnectionClass *self);
  static int LIBPQ_connect(ConnectionClass *self);
  static char
  LIBPQ_CC_connect(ConnectionClass *self, char *salt_para)
--- 988,993 ----
***************
*** 1003,1009 ****
  
  	if (ret = LIBPQ_connect(self), ret <= 0)
  		return ret;
! 	CC_setenv(self);
  
  	return 1;
  }
--- 1002,1008 ----
  
  	if (ret = LIBPQ_connect(self), ret <= 0)
  		return ret;
! 	CC_send_settings(self, "SET DateStyle = 'ISO';SET extra_float_digits = 2");
  
  	return 1;
  }
***************
*** 1035,1042 ****
  	 * rules.  Therefore, these functions call the corresponding local
  	 * function instead.
  	 */
! inolog("CC_send_settings\n");
! 	retsend = CC_send_settings(self);
  
  	if (CC_get_errornumber(self) > 0)
  		saverr = strdup(CC_get_errormsg(self));
--- 1034,1045 ----
  	 * rules.  Therefore, these functions call the corresponding local
  	 * function instead.
  	 */
! 
! 	/* Global settings */
!  retsend = CC_send_settings(self, GET_NAME(self->connInfo.drivers.conn_settings));
! 	/* Per Datasource settings */
!  if (retsend)
! 	 retsend = CC_send_settings(self, GET_NAME(self->connInfo.conn_settings));
  
  	if (CC_get_errornumber(self) > 0)
  		saverr = strdup(CC_get_errormsg(self));
***************
*** 1090,1096 ****
  			CC_set_error(self, -1, saverr, func);
  		free(saverr);
  	}
! 	if (1 == ret && 0 == retsend)
  		ret = 2;
  
  	return ret;
--- 1093,1099 ----
  			CC_set_error(self, -1, saverr, func);
  		free(saverr);
  	}
! 	if (1 == ret && FALSE == retsend)
  		ret = 2;
  
  	return ret;
***************
*** 2127,2180 ****
  }
  
  
- static	char
- CC_setenv(ConnectionClass *self)
- {
- 	HSTMT		hstmt;
- 	StatementClass *stmt;
- 	RETCODE		result;
- 	char		status = TRUE;
- 	CSTR func = "CC_setenv";
- 
- 
- 	mylog("%s: entering...\n", func);
- 
- /*
-  *	This function must use the local odbc API functions since the odbc state
-  *	has not transitioned to "connected" yet.
-  */
- 
- 	result = PGAPI_AllocStmt(self, &hstmt, 0);
- 	if (!SQL_SUCCEEDED(result))
- 		return FALSE;
- 	stmt = (StatementClass *) hstmt;
- 
- 	stmt->internal = TRUE;		/* ensure no BEGIN/COMMIT/ABORT stuff */
- 
- 	/* Set the Datestyle to the format the driver expects it to be in */
- 	result = PGAPI_ExecDirect(hstmt, (SQLCHAR *) "set DateStyle to 'ISO'", SQL_NTS, 0);
- 	if (!SQL_SUCCEEDED(result))
- 		status = FALSE;
- 
- 	mylog("%s: result %d, status %d from set DateStyle\n", func, result, status);
- 
- 	result = PGAPI_ExecDirect(hstmt, (SQLCHAR *) "set extra_float_digits to 2", SQL_NTS, 0);
- 	if (!SQL_SUCCEEDED(result))
- 		status = FALSE;
- 
- 	mylog("%s: result %d, status %d from set extra_float_digits\n", func, result, status);
- 
- 	PGAPI_FreeStmt(hstmt, SQL_DROP);
- 
- 	return status;
- }
- 
  char
! CC_send_settings(ConnectionClass *self)
  {
- 	ConnInfo   *ci = &(self->connInfo);
- 
- /* QResultClass *res; */
  	HSTMT		hstmt;
  	StatementClass *stmt;
  	RETCODE		result;
--- 2130,2138 ----
  }
  
  
  char
! CC_send_settings(ConnectionClass *self, const char *set_query)
  {
  	HSTMT		hstmt;
  	StatementClass *stmt;
  	RETCODE		result;
***************
*** 2189,2194 ****
--- 2147,2154 ----
  
  	mylog("%s: entering...\n", func);
  
+ 	if (set_query == NULL) return TRUE;
+ 
  /*
   *	This function must use the local odbc API functions since the odbc state
   *	has not transitioned to "connected" yet.
***************
*** 2201,2267 ****
  
  	stmt->internal = TRUE;		/* ensure no BEGIN/COMMIT/ABORT stuff */
  
! 	/* Global settings */
! 	if (NAME_IS_VALID(ci->drivers.conn_settings))
  	{
! 		cs = strdup(GET_NAME(ci->drivers.conn_settings));
! 		if (cs)
! 		{
! #ifdef	HAVE_STRTOK_R
! 			ptr = strtok_r(cs, ";", &last);
! #else
! 			ptr = strtok(cs, ";");
! #endif /* HAVE_STRTOK_R */
! 			while (ptr)
! 			{
! 				result = PGAPI_ExecDirect(hstmt, (SQLCHAR *) ptr, SQL_NTS, 0);
! 				if (!SQL_SUCCEEDED(result))
! 					status = FALSE;
! 
! 				mylog("%s: result %d, status %d from '%s'\n", func, result, status, ptr);
! 
! #ifdef	HAVE_STRTOK_R
! 				ptr = strtok_r(NULL, ";", &last);
! #else
! 				ptr = strtok(NULL, ";");
! #endif /* HAVE_STRTOK_R */
! 			}
! 			free(cs);
! 		}
! 		else
! 			status = FALSE;
  	}
  
- 	/* Per Datasource settings */
- 	if (NAME_IS_VALID(ci->conn_settings))
- 	{
- 		cs = strdup(GET_NAME(ci->conn_settings));
- 		if (cs)
- 		{
  #ifdef	HAVE_STRTOK_R
! 			ptr = strtok_r(cs, ";", &last);
  #else
! 			ptr = strtok(cs, ";");
  #endif /* HAVE_STRTOK_R */
! 			while (ptr)
! 			{
! 				result = PGAPI_ExecDirect(hstmt, (SQLCHAR *) ptr, SQL_NTS, 0);
! 				if (!SQL_SUCCEEDED(result))
! 					status = FALSE;
  
! 				mylog("%s: result %d, status %d from '%s'\n", func, result, status, ptr);
  
  #ifdef	HAVE_STRTOK_R
! 				ptr = strtok_r(NULL, ";", &last);
  #else
! 				ptr = strtok(NULL, ";");
  #endif /* HAVE_STRTOK_R */
- 			}
- 			free(cs);
- 		}
- 		else
- 			status = FALSE;
  	}
  
  	PGAPI_FreeStmt(hstmt, SQL_DROP);
  
--- 2161,2193 ----
  
  	stmt->internal = TRUE;		/* ensure no BEGIN/COMMIT/ABORT stuff */
  
! 	cs = strdup(set_query);
! 	if (cs == NULL)
  	{
! 		CC_set_error(self, CONN_NO_MEMORY_ERROR, "Couldn't alloc buffer for query.", func);
! 		return FALSE;
  	}
  
  #ifdef	HAVE_STRTOK_R
! 	ptr = strtok_r(cs, ";", &last);
  #else
! 	ptr = strtok(cs, ";");
  #endif /* HAVE_STRTOK_R */
! 	while (ptr)
! 	{
! 		result = PGAPI_ExecDirect(hstmt, (SQLCHAR *) ptr, SQL_NTS, 0);
! 		if (!SQL_SUCCEEDED(result))
! 			status = FALSE;
  
! 		mylog("%s: result %d, status %d from '%s'\n", func, result, status, ptr);
  
  #ifdef	HAVE_STRTOK_R
! 		ptr = strtok_r(NULL, ";", &last);
  #else
! 		ptr = strtok(NULL, ";");
  #endif /* HAVE_STRTOK_R */
  	}
+ 	free(cs);
  
  	PGAPI_FreeStmt(hstmt, SQL_DROP);
  
diff -Nacr a/connection.h b/connection.h
*** a/connection.h	2016-04-15 22:11:34.000000000 +0900
--- b/connection.h	2016-05-26 17:22:08.000000000 +0900
***************
*** 381,386 ****
--- 381,387 ----
  	DescriptorClass	**descs;
  	pgNAME		schemaIns;
  	pgNAME		tableIns;
+ 	SQLULEN		stmt_timeout_in_effect;
  #if defined(WIN_MULTITHREAD_SUPPORT)
  	CRITICAL_SECTION	cs;
  	CRITICAL_SECTION	slock;
***************
*** 465,471 ****
  				   QResultClass *res, BOOL fatal);
  void		CC_clear_error(ConnectionClass *self);
  int		CC_send_function(ConnectionClass *conn, const char *fn_name, void *result_buf, int *actual_result_len, int result_is_int, LO_ARG *argv, int nargs);
! char		CC_send_settings(ConnectionClass *self);
  void		CC_initialize_pg_version(ConnectionClass *conn);
  void		CC_log_error(const char *func, const char *desc, const ConnectionClass *self);
  int			CC_send_cancel_request(const ConnectionClass *conn);
--- 466,472 ----
  				   QResultClass *res, BOOL fatal);
  void		CC_clear_error(ConnectionClass *self);
  int		CC_send_function(ConnectionClass *conn, const char *fn_name, void *result_buf, int *actual_result_len, int result_is_int, LO_ARG *argv, int nargs);
! char		CC_send_settings(ConnectionClass *self, const char *set_query);
  void		CC_initialize_pg_version(ConnectionClass *conn);
  void		CC_log_error(const char *func, const char *desc, const ConnectionClass *self);
  int			CC_send_cancel_request(const ConnectionClass *conn);
diff -Nacr a/options.c b/options.c
*** a/options.c	2016-04-15 22:11:34.000000000 +0900
--- b/options.c	2016-05-26 17:22:08.000000000 +0900
***************
*** 175,181 ****
  
  		case SQL_QUERY_TIMEOUT:	/* ignored */
  			mylog("SetStmtOption: SQL_QUERY_TIMEOUT, vParam = " FORMAT_LEN "\n", vParam);
! 			/* "0" returned in SQLGetStmtOption */
  			break;
  
  		case SQL_RETRIEVE_DATA:
--- 175,184 ----
  
  		case SQL_QUERY_TIMEOUT:	/* ignored */
  			mylog("SetStmtOption: SQL_QUERY_TIMEOUT, vParam = " FORMAT_LEN "\n", vParam);
! 			if (conn)
! 				conn->stmtOptions.stmt_timeout = (SQLULEN) vParam;
! 			if (stmt)
! 				stmt->options.stmt_timeout = (SQLULEN) vParam;
  			break;
  
  		case SQL_RETRIEVE_DATA:
***************
*** 557,562 ****
--- 560,569 ----
  			*((SQLUINTEGER *) pvParam) = 4096;
  			break;
  
+ 		case SQL_QUERY_TIMEOUT:
+ 			*((SQLULEN *) pvParam) = conn->stmtOptions.stmt_timeout;
+ 			break;
+ 
  		case SQL_QUIET_MODE:	/* NOT SUPPORTED */
  			*((SQLULEN *) pvParam) = 0;
  			break;
***************
*** 768,774 ****
  			break;
  
  		case SQL_QUERY_TIMEOUT:	/* NOT SUPPORTED */
! 			*((SQLINTEGER *) pvParam) = 0;
  			break;
  
  		case SQL_RETRIEVE_DATA:
--- 775,781 ----
  			break;
  
  		case SQL_QUERY_TIMEOUT:	/* NOT SUPPORTED */
! 			*((SQLULEN *) pvParam) = stmt->options.stmt_timeout;
  			break;
  
  		case SQL_RETRIEVE_DATA:
diff -Nacr a/psqlodbc.h b/psqlodbc.h
*** a/psqlodbc.h	2016-04-15 22:11:34.000000000 +0900
--- b/psqlodbc.h	2016-05-26 17:22:08.000000000 +0900
***************
*** 468,473 ****
--- 468,474 ----
  	SQLUINTEGER		use_bookmarks;
  	void			*bookmark_ptr;
  	SQLUINTEGER		metadata_id;
+ 	SQLULEN			stmt_timeout;
  } StatementOptions;
  
  /*	Used to pass extra query info to send_query */
diff -Nacr a/statement.c b/statement.c
*** a/statement.c	2016-04-15 22:11:35.000000000 +0900
--- b/statement.c	2016-05-26 17:22:08.000000000 +0900
***************
*** 331,339 ****
  InitializeStatementOptions(StatementOptions *opt)
  {
  	memset(opt, 0, sizeof(StatementOptions));
- 	opt->maxRows = 0;		/* driver returns all rows */
- 	opt->maxLength = 0;		/* driver returns all data for char/binary */
- 	opt->keyset_size = 0;		/* fully keyset driven is the default */
  	opt->scroll_concurrency = SQL_CONCUR_READ_ONLY;
  	opt->cursor_type = SQL_CURSOR_FORWARD_ONLY;
  	opt->retrieve_data = SQL_RD_ON;
--- 331,336 ----
***************
*** 1880,1886 ****
  		qflag |= GO_INTO_TRANSACTION;
  	}
  
! 	/* self->status = STMT_EXECUTING; */
  	if (!SC_SetExecuting(self, TRUE))
  	{
  		SC_set_error(self, STMT_OPERATION_CANCELLED, "Cancel Reuest Accepted", func);
--- 1877,1897 ----
  		qflag |= GO_INTO_TRANSACTION;
  	}
  
! 	/*
! 	 * If the session query timeout setting differs from the statement one,
! 	 * change it.
! 	 */
! 	if (conn->stmt_timeout_in_effect != self->options.stmt_timeout)
! 	{
! 		char query[64];
! 
! 		snprintf(query, sizeof(query), "SET statement_timeout = %d",
! 				 (int) self->options.stmt_timeout * 1000);
! 		res = CC_send_query(conn, query, NULL, 0, NULL);
! 		if (QR_command_maybe_successful(res))
! 			conn->stmt_timeout_in_effect = self->options.stmt_timeout;
! 	}
! 
  	if (!SC_SetExecuting(self, TRUE))
  	{
  		SC_set_error(self, STMT_OPERATION_CANCELLED, "Cancel Reuest Accepted", func);
