Skip to content

Commit 70b4e6d

Browse files
committed
- Add ConnectTimout and QueryTimout options for ODBC tables. Should
fix MDEV-7415. (To be specified in option_list) modified: storage/connect/ha_connect.cc storage/connect/odbccat.h storage/connect/odbconn.cpp storage/connect/odbconn.h storage/connect/tabodbc.cpp storage/connect/tabodbc.h
1 parent 85c65f4 commit 70b4e6d

File tree

6 files changed

+70
-31
lines changed

6 files changed

+70
-31
lines changed

storage/connect/ha_connect.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) Olivier Bertrand 2004 - 2014
1+
/* Copyright (C) Olivier Bertrand 2004 - 2015
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -170,7 +170,7 @@
170170
#define SZWMIN 4194304 // Minimum work area size 4M
171171

172172
extern "C" {
173-
char version[]= "Version 1.03.0005 November 08, 2014";
173+
char version[]= "Version 1.03.0005 January 13, 2015";
174174
char compver[]= "Version 1.03.0005 " __DATE__ " " __TIME__;
175175

176176
#if defined(WIN32)
@@ -4830,6 +4830,9 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
48304830
#endif // WIN32
48314831
int port= 0, hdr= 0, mxr __attribute__((unused))= 0, mxe= 0, rc= 0;
48324832
int cop __attribute__((unused)) = 0;
4833+
#if defined(ODBC_SUPPORT)
4834+
int cto= -1, qto= -1;
4835+
#endif // ODBC_SUPPORT
48334836
uint tm, fnc= FNC_NO, supfnc= (FNC_NO | FNC_COL);
48344837
bool bif, ok= false, dbf= false;
48354838
TABTYPE ttp= TAB_UNDEF;
@@ -4889,6 +4892,8 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
48894892
port= atoi(GetListOption(g, "port", topt->oplist, "0"));
48904893
#if defined(ODBC_SUPPORT)
48914894
mxr= atoi(GetListOption(g,"maxres", topt->oplist, "0"));
4895+
cto= atoi(GetListOption(g,"ConnectTimeout", topt->oplist, "-1"));
4896+
qto= atoi(GetListOption(g,"QueryTimeout", topt->oplist, "-1"));
48924897
#endif
48934898
mxe= atoi(GetListOption(g,"maxerr", topt->oplist, "0"));
48944899
#if defined(PROMPT_OK)
@@ -5107,14 +5112,15 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
51075112
case FNC_NO:
51085113
case FNC_COL:
51095114
if (src) {
5110-
qrp= ODBCSrcCols(g, dsn, (char*)src);
5115+
qrp= ODBCSrcCols(g, dsn, (char*)src, cto, qto);
51115116
src= NULL; // for next tests
51125117
} else
5113-
qrp= ODBCColumns(g, dsn, shm, tab, NULL, mxr, fnc == FNC_COL);
5118+
qrp= ODBCColumns(g, dsn, shm, tab, NULL,
5119+
mxr, cto, qto, fnc == FNC_COL);
51145120

51155121
break;
51165122
case FNC_TABLE:
5117-
qrp= ODBCTables(g, dsn, shm, tab, mxr, true);
5123+
qrp= ODBCTables(g, dsn, shm, tab, mxr, cto, qto, true);
51185124
break;
51195125
case FNC_DSN:
51205126
qrp= ODBCDataSources(g, mxr, true);

storage/connect/odbccat.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Timeout and net wait defaults
2+
#define DEFAULT_LOGIN_TIMEOUT -1 // means do not set
3+
#define DEFAULT_QUERY_TIMEOUT -1 // means do not set
4+
15
/***********************************************************************/
26
/* ODBC catalog function prototypes. */
37
/***********************************************************************/
@@ -6,8 +10,8 @@ char *ODBCCheckConnection(PGLOBAL g, char *dsn, int cop);
610
#endif // PROMPT_OK
711
PQRYRES ODBCDataSources(PGLOBAL g, int maxres, bool info);
812
PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table,
9-
char *colpat, int maxres, bool info);
10-
PQRYRES ODBCSrcCols(PGLOBAL g, char *dsn, char *src);
13+
char *colpat, int maxres, int cto, int qto, bool info);
14+
PQRYRES ODBCSrcCols(PGLOBAL g, char *dsn, char *src, int cto, int qto);
1115
PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *db, char *tabpat,
12-
int maxres, bool info);
16+
int maxres, int cto, int qto, bool info);
1317
PQRYRES ODBCDrivers(PGLOBAL g, int maxres, bool info);

storage/connect/odbconn.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/************ Odbconn C++ Functions Source Code File (.CPP) ************/
2-
/* Name: ODBCONN.CPP Version 2.0 */
2+
/* Name: ODBCONN.CPP Version 2.1 */
33
/* */
4-
/* (C) Copyright to the author Olivier BERTRAND 1998-2014 */
4+
/* (C) Copyright to the author Olivier BERTRAND 1998-2015 */
55
/* */
66
/* This file contains the ODBC connection classes functions. */
77
/***********************************************************************/
@@ -291,7 +291,7 @@ static void ResetNullValues(CATPARM *cap)
291291
/* of an ODBC table that will be retrieved by GetData commands. */
292292
/***********************************************************************/
293293
PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table,
294-
char *colpat, int maxres, bool info)
294+
char *colpat, int maxres, int cto, int qto, bool info)
295295
{
296296
int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING,
297297
TYPE_SHORT, TYPE_STRING, TYPE_INT, TYPE_INT,
@@ -310,6 +310,8 @@ PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table,
310310
/************************************************************************/
311311
if (!info) {
312312
ocp = new(g) ODBConn(g, NULL);
313+
ocp->SetLoginTimeout((DWORD)cto);
314+
ocp->SetQueryTimeout((DWORD)qto);
313315

314316
if (ocp->Open(dsn, 10) < 1) // openReadOnly + noODBCdialog
315317
return NULL;
@@ -386,10 +388,12 @@ PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table,
386388
/* ODBCSrcCols: constructs the result blocks containing the */
387389
/* description of all the columns of a Srcdef option. */
388390
/**************************************************************************/
389-
PQRYRES ODBCSrcCols(PGLOBAL g, char *dsn, char *src)
391+
PQRYRES ODBCSrcCols(PGLOBAL g, char *dsn, char *src, int cto, int qto)
390392
{
391393
ODBConn *ocp = new(g) ODBConn(g, NULL);
392394

395+
ocp->SetLoginTimeout((DWORD)cto);
396+
ocp->SetQueryTimeout((DWORD)qto);
393397
return ocp->GetMetaData(g, dsn, src);
394398
} // end of ODBCSrcCols
395399

@@ -570,7 +574,7 @@ PQRYRES ODBCDataSources(PGLOBAL g, int maxres, bool info)
570574
/* an ODBC database that will be retrieved by GetData commands. */
571575
/**************************************************************************/
572576
PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *db, char *tabpat,
573-
int maxres, bool info)
577+
int maxres, int cto, int qto, bool info)
574578
{
575579
int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING,
576580
TYPE_STRING, TYPE_STRING};
@@ -590,6 +594,8 @@ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *db, char *tabpat,
590594
/* Open the connection with the ODBC data source. */
591595
/**********************************************************************/
592596
ocp = new(g) ODBConn(g, NULL);
597+
ocp->SetLoginTimeout((DWORD)cto);
598+
ocp->SetQueryTimeout((DWORD)qto);
593599

594600
if (ocp->Open(dsn, 2) < 1) // 2 is openReadOnly
595601
return NULL;
@@ -1134,10 +1140,13 @@ void ODBConn::AllocConnect(DWORD Options)
11341140
} // endif
11351141
#endif // _DEBUG
11361142

1137-
rc = SQLSetConnectOption(m_hdbc, SQL_LOGIN_TIMEOUT, m_LoginTimeout);
1143+
if ((signed)m_LoginTimeout >= 0) {
1144+
rc = SQLSetConnectOption(m_hdbc, SQL_LOGIN_TIMEOUT, m_LoginTimeout);
11381145

1139-
if (trace && rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO)
1140-
htrc("Warning: Failure setting login timeout\n");
1146+
if (trace && rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO)
1147+
htrc("Warning: Failure setting login timeout\n");
1148+
1149+
} // endif Timeout
11411150

11421151
if (!m_Updatable) {
11431152
rc = SQLSetConnectOption(m_hdbc, SQL_ACCESS_MODE, SQL_MODE_READ_ONLY);

storage/connect/odbconn.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@
3333
typedef unsigned char *PUCHAR;
3434
#endif // !WIN32
3535

36-
// Timeout and net wait defaults
37-
#define DEFAULT_LOGIN_TIMEOUT 15 // seconds to before fail on connect
38-
#define DEFAULT_QUERY_TIMEOUT 15 // seconds to before fail waiting for results
39-
4036
// Field Flags, used to indicate status of fields
4137
//efine SQL_FIELD_FLAG_DIRTY 0x1
4238
//efine SQL_FIELD_FLAG_NULL 0x2

storage/connect/tabodbc.cpp

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/************* Tabodbc C++ Program Source Code File (.CPP) *************/
22
/* PROGRAM NAME: TABODBC */
33
/* ------------- */
4-
/* Version 2.8 */
4+
/* Version 2.9 */
55
/* */
66
/* COPYRIGHT: */
77
/* ---------- */
8-
/* (C) Copyright to the author Olivier BERTRAND 2000-2014 */
8+
/* (C) Copyright to the author Olivier BERTRAND 2000-2015 */
99
/* */
1010
/* WHAT THIS PROGRAM DOES: */
1111
/* ----------------------- */
@@ -94,7 +94,7 @@ bool ExactInfo(void);
9494
ODBCDEF::ODBCDEF(void)
9595
{
9696
Connect= Tabname= Tabschema= Tabcat= Srcdef= Qchar= Qrystr= Sep= NULL;
97-
Catver = Options = Quoted = Maxerr = Maxres = 0;
97+
Catver = Options = Cto = Qto = Quoted = Maxerr = Maxres = 0;
9898
Scrollable = Memory = Xsrc = false;
9999
} // end of ODBCDEF constructor
100100

@@ -130,6 +130,8 @@ bool ODBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
130130
Quoted = GetIntCatInfo("Quoted", 0);
131131
Options = ODBConn::noOdbcDialog;
132132
//Options = ODBConn::noOdbcDialog | ODBConn::useCursorLib;
133+
Cto= GetIntCatInfo("ConnectTimeout", DEFAULT_LOGIN_TIMEOUT);
134+
Qto= GetIntCatInfo("QueryTimeout", DEFAULT_QUERY_TIMEOUT);
133135
Scrollable = GetBoolCatInfo("Scrollable", false);
134136
Memory = GetBoolCatInfo("Memory", false);
135137
Pseudo = 2; // FILID is Ok but not ROWID
@@ -193,6 +195,8 @@ TDBODBC::TDBODBC(PODEF tdp) : TDBASE(tdp)
193195
Qrystr = tdp->Qrystr;
194196
Sep = tdp->GetSep();
195197
Options = tdp->Options;
198+
Cto = tdp->Cto;
199+
Qto = tdp->Qto;
196200
Quoted = MY_MAX(0, tdp->GetQuoted());
197201
Rows = tdp->GetElemt();
198202
Catver = tdp->Catver;
@@ -207,6 +211,8 @@ TDBODBC::TDBODBC(PODEF tdp) : TDBASE(tdp)
207211
Qrystr = NULL;
208212
Sep = 0;
209213
Options = 0;
214+
Cto = DEFAULT_LOGIN_TIMEOUT;
215+
Qto = DEFAULT_QUERY_TIMEOUT;
210216
Quoted = 0;
211217
Rows = 0;
212218
Catver = 0;
@@ -248,6 +254,8 @@ TDBODBC::TDBODBC(PTDBODBC tdbp) : TDBASE(tdbp)
248254
MulConn = tdbp->MulConn;
249255
DBQ = tdbp->DBQ;
250256
Options = tdbp->Options;
257+
Cto = tdbp->Cto;
258+
Qto = tdbp->Qto;
251259
Quoted = tdbp->Quoted;
252260
Rows = tdbp->Rows;
253261
Fpos = tdbp->Fpos;
@@ -690,6 +698,9 @@ int TDBODBC::Cardinality(PGLOBAL g)
690698
char qry[96], tbn[64];
691699
ODBConn *ocp = new(g) ODBConn(g, this);
692700

701+
ocp->SetLoginTimeout((DWORD)Cto);
702+
ocp->SetQueryTimeout((DWORD)Qto);
703+
693704
if (ocp->Open(Connect, Options) < 1)
694705
return -1;
695706

@@ -791,9 +802,11 @@ bool TDBODBC::OpenDB(PGLOBAL g)
791802
/* and if so to allocate just a new result set. But this only for */
792803
/* drivers allowing concurency in getting results ??? */
793804
/*********************************************************************/
794-
if (!Ocp)
805+
if (!Ocp) {
795806
Ocp = new(g) ODBConn(g, this);
796-
else if (Ocp->IsOpen())
807+
Ocp->SetLoginTimeout((DWORD)Cto);
808+
Ocp->SetQueryTimeout((DWORD)Qto);
809+
} else if (Ocp->IsOpen())
797810
Ocp->Close();
798811

799812
if (Ocp->Open(Connect, Options) < 1)
@@ -1400,9 +1413,11 @@ bool TDBXDBC::OpenDB(PGLOBAL g)
14001413
/* and if so to allocate just a new result set. But this only for */
14011414
/* drivers allowing concurency in getting results ??? */
14021415
/*********************************************************************/
1403-
if (!Ocp)
1416+
if (!Ocp) {
14041417
Ocp = new(g) ODBConn(g, this);
1405-
else if (Ocp->IsOpen())
1418+
Ocp->SetLoginTimeout((DWORD)Cto);
1419+
Ocp->SetQueryTimeout((DWORD)Qto);
1420+
} else if (Ocp->IsOpen())
14061421
Ocp->Close();
14071422

14081423
if (Ocp->Open(Connect, Options) < 1)
@@ -1539,14 +1554,16 @@ TDBOTB::TDBOTB(PODEF tdp) : TDBDRV(tdp)
15391554
Dsn = tdp->GetConnect();
15401555
Schema = tdp->GetTabschema();
15411556
Tab = tdp->GetTabname();
1557+
Cto = tdp->Cto;
1558+
Qto = tdp->Qto;
15421559
} // end of TDBOTB constructor
15431560

15441561
/***********************************************************************/
15451562
/* GetResult: Get the list of ODBC tables. */
15461563
/***********************************************************************/
15471564
PQRYRES TDBOTB::GetResult(PGLOBAL g)
15481565
{
1549-
return ODBCTables(g, Dsn, Schema, Tab, Maxres, false);
1566+
return ODBCTables(g, Dsn, Schema, Tab, Maxres, Cto, Qto, false);
15501567
} // end of GetResult
15511568

15521569
/* ---------------------------TDBOCL class --------------------------- */
@@ -1556,7 +1573,7 @@ PQRYRES TDBOTB::GetResult(PGLOBAL g)
15561573
/***********************************************************************/
15571574
PQRYRES TDBOCL::GetResult(PGLOBAL g)
15581575
{
1559-
return ODBCColumns(g, Dsn, Schema, Tab, NULL, Maxres, false);
1576+
return ODBCColumns(g, Dsn, Schema, Tab, NULL, Maxres, Cto, Qto, false);
15601577
} // end of GetResult
15611578

15621579
/* ------------------------ End of Tabodbc --------------------------- */

storage/connect/tabodbc.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*************** Tabodbc H Declares Source Code File (.H) **************/
2-
/* Name: TABODBC.H Version 1.7 */
2+
/* Name: TABODBC.H Version 1.8 */
33
/* */
4-
/* (C) Copyright to the author Olivier BERTRAND 2000-2014 */
4+
/* (C) Copyright to the author Olivier BERTRAND 2000-2015 */
55
/* */
66
/* This file contains the TDBODBC classes declares. */
77
/***********************************************************************/
@@ -24,6 +24,7 @@ class DllExport ODBCDEF : public TABDEF { /* Logical table description */
2424
friend class TDBODBC;
2525
friend class TDBXDBC;
2626
friend class TDBDRV;
27+
friend class TDBOTB;
2728
public:
2829
// Constructor
2930
ODBCDEF(void);
@@ -56,6 +57,8 @@ class DllExport ODBCDEF : public TABDEF { /* Logical table description */
5657
PSZ Sep; /* Decimal separator */
5758
int Catver; /* ODBC version for catalog functions */
5859
int Options; /* Open connection options */
60+
int Cto; /* Open connection timeout */
61+
int Qto; /* Query (command) timeout */
5962
int Quoted; /* Identifier quoting level */
6063
int Maxerr; /* Maxerr for an Exec table */
6164
int Maxres; /* Maxres for a catalog table */
@@ -135,6 +138,8 @@ class TDBODBC : public TDBASE {
135138
char *Qrystr; // The original query
136139
char Sep; // The decimal separator
137140
int Options; // Connect options
141+
int Cto; // Connect timeout
142+
int Qto; // Query timeout
138143
int Quoted; // The identifier quoting level
139144
int Fpos; // Position of last read record
140145
int AftRows; // The number of affected rows
@@ -311,6 +316,8 @@ class TDBOTB : public TDBDRV {
311316
char *Dsn; // Points to connection string
312317
char *Schema; // Points to schema name or NULL
313318
char *Tab; // Points to ODBC table name or pattern
319+
int Cto; // Connect timeout
320+
int Qto; // Query timeout
314321
}; // end of class TDBOTB
315322

316323
/***********************************************************************/

0 commit comments

Comments
 (0)