pg.ddx.io pgsql-odbc@postgresql.org mailing list archive
help / color / mirror / Atom feedADO CommandTimeout vs Postgres statement_timeout parameter
5+ messages / 3 participants
[nested] [flat]
* ADO CommandTimeout vs Postgres statement_timeout parameter
@ 2016-05-18 12:12 Richard Hetherington <hetheringtonrichard@hotmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: Richard Hetherington @ 2016-05-18 12:12 UTC (permalink / raw)
To: pgsql-odbc; +Cc: james.willison@aztecretail.co.uk <james.willison@aztecretail.co.uk>; Brad Bence <brad.bence@aztecretail.co.uk>
Hi, I have been debugging why the ADO CommandTimeout property has no effect on Postgres Queries and I believe that it is being ignored. Is this something that could be modified in a future ODBC Driver release. What I would like to see is an auto prepending of this value to a SQL Query being passed in if set.
I understand that the statement_timeout config parameter in postgres can be configured at the server level, user level and query level. I have tested each and they work as expected. What I wasn't expecting was for my CommandTimeout to be ignored / not passed through.
e.g.
Set p_objConn = Server.CreateObject("ADODB.Connection")
p_objConn.ConnectionString = "SOME DSN or DSNLess Connection String"
' e.g. DB.ConnectionString = "Driver={PostgreSQL UNICODE};Server=localhost;Port=5432;UID=someuser;PWD=somepassword;Database=somedatabase;"
p_objConn.ConnectionTimeout = 10
p_objConn.Open
p_objConn.CommandTimeout = 30 ' This has no effect on queries run against Postgres !!
If The ADO CommandTimeout value is set, could this be detected, check that the SQL Query hasn't already got a statement_timeout value and if not prepend the SQL Query as follows:
SET statement_timeout = 30000;
SELECT somedata FROM
somedatabasetable WHERE somevalue=anothervalue,
Many thanks in advance.
Feel free to contact me if you need any further information.
RICHARD HETHERINGTON =
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: ADO CommandTimeout vs Postgres statement_timeout parameter
@ 2016-05-19 05:21 Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>
parent: Richard Hetherington <hetheringtonrichard@hotmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: Tsunakawa, Takayuki @ 2016-05-19 05:21 UTC (permalink / raw)
To: Richard Hetherington <hetheringtonrichard@hotmail.com>; pgsql-odbc; +Cc: james.willison@aztecretail.co.uk <james.willison@aztecretail.co.uk>; Brad Bence <brad.bence@aztecretail.co.uk>
From: pgsql-odbc-owner@postgresql.org [mailto:pgsql-odbc-owner@postgresql.org] On Behalf Of Richard Hetherington
Hi, I have been debugging why the ADO CommandTimeout property has no effect on Postgres Queries and I believe that it is being ignored. Is this something that could be modified in a future ODBC Driver release. What I would like to see is an auto prepending of this value to a SQL Query being passed in if set.
I guess you are right. The current psqlODBC does not implement SQLSetConnectAttr/SQLSetStmtAttr(SQL_QUERY_TIMEOUT) and do nothing when it is called, as follows:
case SQL_QUERY_TIMEOUT: /* ignored */
mylog("SetStmtOption: SQL_QUERY_TIMEOUT, vParam = " FORMAT_LEN "\n", vParam);
/* "0" returned in SQLGetStmtOption */
break;
But I don't know whether setting ADO's CommandTimeout leads to setting SQL_QUERY_TIMEOUT. Could you show us the MyLog output of psqlODBC to confirm that?
Regards
Takayuki Tsunakawa
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: ADO CommandTimeout vs Postgres statement_timeout parameter
@ 2016-05-26 08:27 Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>
parent: Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>
0 siblings, 1 reply; 5+ messages in thread
From: Tsunakawa, Takayuki @ 2016-05-26 08:27 UTC (permalink / raw)
To: Richard Hetherington <hetheringtonrichard@hotmail.com>; +Cc: pgsql-odbc
Hello, Richard, Inoue-san,
Richard, please post to pgsql-odbc ML as much as possible, because I$B!G(Bd like Inoue-san to have a look. He is currently the only committer of psqlODBC, and I$B!G(Bm still an apprentice.
I implemented SQL_QUERY_TIMEOUT, which seems to work. Please find the attached patch.
Inoue-san,
At first, I used CC_send_settings() to execute $B!H(BSET statement_timeout$B!I(B and refactored it. After that, I realized I can use CC_send_query() and used it instead. However, I$B!G(Bd like the refactored code to be applied too.
Regards
Takayuki Tsunakawa
From: Richard Hetherington [mailto:hetheringtonrichard@hotmail.com]
Sent: Friday, May 20, 2016 7:09 PM
To: Tsunakawa, Takayuki/$B9K@n(B $B5.G7(B
Subject: RE: [ODBC] ADO CommandTimeout vs Postgres statement_timeout parameter
Many thanks for you advice. I realised after receiving your email that I had made a fundamental error - I was logging from a website to my desktop folder which clearly isn't going to be writable by a Web Identity Account - oops.
Attached are 2 log files which I have cleaned up to remove all UID, PWD, Server values etc.
You should see that I set the SQL_QUERY_TIMEOUT via the ADO CommandTimeout = 60 seconds
This value has been logged but has no effect on the long running query.
[7212-0.181]SetStmtOption: SQL_QUERY_TIMEOUT, vParam = 60
I hope this is useful.
If you need anything esle, let me know.
Many thanks and have a good weekend,
RICHARD
________________________________
From: tsunakawa.takay@jp.fujitsu.com<mailto:tsunakawa.takay@jp.fujitsu.com>
To: hetheringtonrichard@hotmail.com<mailto:hetheringtonrichard@hotmail.com>
Subject: RE: [ODBC] ADO CommandTimeout vs Postgres statement_timeout parameter
Date: Fri, 20 May 2016 02:39:30 +0000
Hello,
If SQL_QUERY_TIMEOUT is set on the connection or statement, mylog_xxx.log will have entries like this:
[140168204601088]PGAPI_SetConnectAttr for 0x8d5360: 0 0xa
[140168204601088]PGAPI_SetConnectOption: entering fOption = 0 vParam = 10
[140168204601088]SetStmtOption: SQL_QUERY_TIMEOUT, vParam = 10
...
[140168204601088][[SQLSetStmtAttr]] Handle=0x8e2110 0,10
[140168204601088]PGAPI_SetStmtAttr Handle=0x8e2110 0,10(0xa)
[140168204601088]PGAPI_SetStmtOption: entering...
[140168204601088]SetStmtOption: SQL_QUERY_TIMEOUT, vParam = 10
I'm not sure about the cause of your logging failure, but perhaps you will be able to log to another directory by creating the following registry value:
HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\<your ODBC driver name>\Logdir
type: REG_SZ
value: directory path
Regards
Takayuki Tsunakawa
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
Attachments:
query_timeout.patch (application/octet-stream, 10.4K) download
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);
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: ADO CommandTimeout vs Postgres statement_timeout parameter
@ 2016-05-27 08:04 Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
parent: Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>
0 siblings, 1 reply; 5+ messages in thread
From: Inoue, Hiroshi @ 2016-05-27 08:04 UTC (permalink / raw)
To: Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>; Richard Hetherington <hetheringtonrichard@hotmail.com>; +Cc: pgsql-odbc
Hi,
What does SQL_QUERY_TIMEOUT means for e.g.SQLBulkOperations()?
regards,
Hiroshi Inoue
On 2016/05/26 17:27, Tsunakawa, Takayuki wrote:
>
> Hello, Richard, Inoue-san,
>
> Richard, please post to pgsql-odbc ML as much as possible, because I’d
> like Inoue-san to have a look. He is currently the only committer of
> psqlODBC, and I’m still an apprentice.
>
> I implemented SQL_QUERY_TIMEOUT, which seems to work. Please find the
> attached patch.
>
> Inoue-san,
>
> At first, I used CC_send_settings() to execute “SET statement_timeout”
> and refactored it. After that, I realized I can use CC_send_query()
> and used it instead. However, I’d like the refactored code to be
> applied too.
>
> Regards
>
> Takayuki Tsunakawa
>
> *From:*Richard Hetherington [mailto:hetheringtonrichard@hotmail.com]
> *Sent:* Friday, May 20, 2016 7:09 PM
> *To:* Tsunakawa, Takayuki/綱川貴之
> *Subject:* RE: [ODBC] ADO CommandTimeout vs Postgres statement_timeout
> parameter
>
> Many thanks for you advice. I realised after receiving your email that
> I had made a fundamental error - I was logging from a website to my
> desktop folder which clearly isn't going to be writable by a Web
> Identity Account - oops.
>
> Attached are 2 log files which I have cleaned up to remove all UID,
> PWD, Server values etc.
>
> You should see that I set the SQL_QUERY_TIMEOUT via the ADO
> CommandTimeout = 60 seconds
>
> This value has been logged but has no effect on the long running query.
> [7212-0.181]SetStmtOption: SQL_QUERY_TIMEOUT, vParam = 60
>
> I hope this is useful.
>
> If you need anything esle, let me know.
>
> Many thanks and have a good weekend,
>
> **RICHARD**
>
> ------------------------------------------------------------------------
>
> From: tsunakawa.takay@jp.fujitsu.com
> <mailto:tsunakawa.takay@jp.fujitsu.com>
> To: hetheringtonrichard@hotmail.com
> <mailto:hetheringtonrichard@hotmail.com>
> Subject: RE: [ODBC] ADO CommandTimeout vs Postgres statement_timeout
> parameter
> Date: Fri, 20 May 2016 02:39:30 +0000
>
> Hello,
>
> If SQL_QUERY_TIMEOUT is set on the connection or statement,
> mylog_xxx.log will have entries like this:
>
> [140168204601088]PGAPI_SetConnectAttr for 0x8d5360: 0 0xa
>
> [140168204601088]PGAPI_SetConnectOption: entering fOption = 0 vParam = 10
>
> [140168204601088]SetStmtOption: SQL_QUERY_TIMEOUT, vParam = 10
>
> ...
>
> [140168204601088][[SQLSetStmtAttr]] Handle=0x8e2110 0,10
>
> [140168204601088]PGAPI_SetStmtAttr Handle=0x8e2110 0,10(0xa)
>
> [140168204601088]PGAPI_SetStmtOption: entering...
>
> [140168204601088]SetStmtOption: SQL_QUERY_TIMEOUT, vParam = 10
>
> I'm not sure about the cause of your logging failure, but perhaps you
> will be able to log to another directory by creating the following
> registry value:
>
> HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\<your ODBC driver
> name>\Logdir
>
> type: REG_SZ
>
> value: directory path
>
> Regards
>
> Takayuki Tsunakawa
>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: ADO CommandTimeout vs Postgres statement_timeout parameter
@ 2016-05-30 01:24 Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>
parent: Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
0 siblings, 0 replies; 5+ messages in thread
From: Tsunakawa, Takayuki @ 2016-05-30 01:24 UTC (permalink / raw)
To: Inoue, Hiroshi <h-inoue@dream.email.ne.jp>; Richard Hetherington <hetheringtonrichard@hotmail.com>; +Cc: pgsql-odbc
From: Inoue, Hiroshi [mailto:h-inoue@dream.email.ne.jp]
What does SQL_QUERY_TIMEOUT means for e.g.SQLBulkOperations()?
The ODBC spec doesn’t seem to specify it. The SQL_ATTR_QUERY_TIMEOUT description in the SQLSetStmtAttr() reference page mentions “SQL Statement”, whereas SQLBulkOperations() talks about “operations.” And the relationship between SQL statements and operations is not specified. I think that depends on the driver, and it’s legal that the query timeout applies to each operation.
Apart from that, I forgot to call QR_Destructor() after CC_send_query(). Revised patch attached.
Regards
Takayuki Tsunakawa
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
Attachments:
query_timeout_v2.patch (application/octet-stream, 10.4K) download
diff -Nacr a/connection.c b/connection.c
*** a/connection.c 2016-04-15 22:11:34.000000000 +0900
--- b/connection.c 2016-05-30 10:12:09.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-30 10:12:09.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-30 10:12:09.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-30 10:12:09.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-30 10:12:19.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,1898 ----
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;
! QR_Destructor(res);
! }
!
if (!SC_SetExecuting(self, TRUE))
{
SC_set_error(self, STMT_OPERATION_CANCELLED, "Cancel Reuest Accepted", func);
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2016-05-30 01:24 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-05-18 12:12 ADO CommandTimeout vs Postgres statement_timeout parameter Richard Hetherington <hetheringtonrichard@hotmail.com>
2016-05-19 05:21 ` Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>
2016-05-26 08:27 ` Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>
2016-05-27 08:04 ` Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
2016-05-30 01:24 ` Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox