Skip to content

Commit 018c1d1

Browse files
committed
#36 configure connection timeout
1 parent 3434aec commit 018c1d1

File tree

9 files changed

+38
-5
lines changed

9 files changed

+38
-5
lines changed

driver/config.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ConnInfo::ConnInfo()
1818
ZERO_FIELD(port);
1919
ZERO_FIELD(sslmode);
2020
ZERO_FIELD(onlyread);
21+
ZERO_FIELD(timeout);
2122
ZERO_FIELD(show_system_tables);
2223
ZERO_FIELD(translation_dll);
2324
ZERO_FIELD(translation_option);
@@ -48,4 +49,7 @@ void getDSNinfo(ConnInfo * ci, bool overwrite)
4849

4950
if (ci->password[0] == '\0' || overwrite)
5051
SQLGetPrivateProfileString(ci->dsn, INI_PASSWORD, TEXT(""), ci->password, sizeof(ci->password), ODBC_INI);
52+
53+
if (ci->timeout[0] == '\0' || overwrite)
54+
SQLGetPrivateProfileString(ci->dsn, INI_TIMEOUT, TEXT("30"), ci->timeout, sizeof(ci->timeout), ODBC_INI);
5155
}

driver/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define INI_PASSWORD TEXT("Password") /* Default Password */
1515
#define INI_PORT TEXT("Port") /* Port on which the ClickHouse is listening */
1616
#define INI_READONLY TEXT("ReadOnly") /* Database is read only */
17+
#define INI_TIMEOUT TEXT("Timeout")
1718

1819
#ifndef WIN32
1920
# define ODBC_INI ".odbc.ini"
@@ -39,6 +40,7 @@ struct ConnInfo
3940
TCHAR port[SMALL_REGISTRY_LEN];
4041
TCHAR sslmode[16];
4142
TCHAR onlyread[SMALL_REGISTRY_LEN];
43+
TCHAR timeout[SMALL_REGISTRY_LEN];
4244
TCHAR show_system_tables[SMALL_REGISTRY_LEN];
4345
TCHAR translation_dll[MEDIUM_REGISTRY_LEN];
4446
TCHAR translation_option[SMALL_REGISTRY_LEN];

driver/connection.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void Connection::init()
4646
session.setHost(server);
4747
session.setPort(port);
4848
session.setKeepAlive(true);
49-
session.setTimeout(Poco::Timespan(30, 0));
49+
session.setTimeout(Poco::Timespan(timeout, 0));
5050
session.setKeepAliveTimeout(Poco::Timespan(86400, 0));
5151
}
5252

@@ -126,6 +126,15 @@ void Connection::loadConfiguration()
126126
else
127127
throw std::runtime_error("Cannot parse port number.");
128128
}
129+
if (timeout == 0)
130+
{
131+
const std::string timeout_string = stringFromTCHAR(ci.timeout);
132+
if (!timeout_string.empty())
133+
{
134+
if (!Poco::NumberParser::tryParse(timeout_string, this->timeout))
135+
throw std::runtime_error("Cannot parse connection timeout value.");
136+
}
137+
}
129138

130139
if (server.empty())
131140
server = stringFromTCHAR(ci.server);
@@ -149,4 +158,6 @@ void Connection::setDefaults()
149158
user = "default";
150159
if (database.empty())
151160
database = "default";
161+
if (timeout == 0)
162+
timeout = 30;
152163
}

driver/connection.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ struct Connection
1111

1212
std::string data_source;
1313
std::string server;
14-
uint16_t port = 0;
1514
std::string user;
1615
std::string password;
16+
uint16_t port = 0;
17+
int timeout = 0;
1718

1819
Poco::Net::HTTPClientSession session;
1920
DiagnosticRecord diagnostic_record;

driver/win/resource.h

184 Bytes
Binary file not shown.

driver/win/resource.rc

254 Bytes
Binary file not shown.

driver/win/setup.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ namespace
3939
#define INI_PORT TEXT("Port") /* Port on which the ClickHouse is listening */
4040
#define INI_READONLY TEXT("ReadOnly") /* Database is read only */
4141
#define INI_PROTOCOL TEXT("Protocol") /* What protocol (6.2) */
42+
#define INI_TIMEOUT TEXT("Timeout")
4243
#define INI_DSN TEXT("ClickHouse")
4344

4445
#define ABBR_PROTOCOL TEXT("A1")
@@ -70,6 +71,7 @@ struct ConnInfo
7071
TCHAR port[SMALL_REGISTRY_LEN];
7172
TCHAR sslmode[16];
7273
TCHAR onlyread[SMALL_REGISTRY_LEN];
74+
TCHAR timeout[SMALL_REGISTRY_LEN];
7375
TCHAR fake_oid_index[SMALL_REGISTRY_LEN];
7476
TCHAR show_oid_column[SMALL_REGISTRY_LEN];
7577
TCHAR row_versioning[SMALL_REGISTRY_LEN];
@@ -113,7 +115,7 @@ struct SetupDialogData
113115
BOOL
114116
copyAttributes(ConnInfo *ci, LPCTSTR attribute, LPCTSTR value)
115117
{
116-
BOOL found = TRUE;
118+
BOOL found = TRUE;
117119

118120
if (stricmp(attribute, TEXT("DSN")) == 0)
119121
strcpy(ci->dsn, value);
@@ -142,6 +144,9 @@ copyAttributes(ConnInfo *ci, LPCTSTR attribute, LPCTSTR value)
142144
else if (stricmp(attribute, INI_READONLY) == 0 || stricmp(attribute, ABBR_READONLY) == 0)
143145
strcpy(ci->onlyread, value);
144146

147+
else if (stricmp(attribute, INI_TIMEOUT) == 0)
148+
strcpy(ci->timeout, value);
149+
145150
else
146151
found = FALSE;
147152

@@ -218,6 +223,9 @@ void getDSNinfo(ConnInfo *ci, bool overwrite)
218223

219224
if (ci->password[0] == '\0' || overwrite)
220225
SQLGetPrivateProfileString(DSN, INI_PASSWORD, TEXT(""), ci->password, sizeof(ci->password), ODBC_INI);
226+
227+
if (ci->timeout[0] == '\0' || overwrite)
228+
SQLGetPrivateProfileString(DSN, INI_TIMEOUT, TEXT("30"), ci->timeout, sizeof(ci->timeout), ODBC_INI);
221229
}
222230

223231
/* This is for datasource based options only */
@@ -262,6 +270,11 @@ void writeDSNinfo(const ConnInfo * ci)
262270
INI_PASSWORD,
263271
ci->password,
264272
ODBC_INI);
273+
274+
SQLWritePrivateProfileString(DSN,
275+
INI_TIMEOUT,
276+
ci->timeout,
277+
ODBC_INI);
265278
}
266279

267280
static bool setDSNAttributes(HWND hwndParent, SetupDialogData * lpsetupdlg, DWORD * errcode)
@@ -386,6 +399,7 @@ INT_PTR CALLBACK
386399
SetDlgItemText(hdlg, IDC_DATABASE, ci->database);
387400
SetDlgItemText(hdlg, IDC_USER, ci->username);
388401
SetDlgItemText(hdlg, IDC_PASSWORD, ci->password);
402+
SetDlgItemText(hdlg, IDC_TIMEOUT, ci->timeout);
389403

390404
return TRUE; /* Focus was not set */
391405
}
@@ -404,6 +418,7 @@ INT_PTR CALLBACK
404418
GetDlgItemText(hdlg, IDC_DATABASE, ci->database, sizeof(ci->database));
405419
GetDlgItemText(hdlg, IDC_USER, ci->username, sizeof(ci->username));
406420
GetDlgItemText(hdlg, IDC_PASSWORD, ci->password, sizeof(ci->password));
421+
GetDlgItemText(hdlg, IDC_TIMEOUT, ci->timeout, sizeof(ci->timeout));
407422

408423
/* Return to caller */
409424
case IDCANCEL:

vs/installer32/Product.wxs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<Product Id="$(var.PRODUCT_ID)"
3333
Name="$(var.PKGNAME)"
3434
Language="1033"
35-
Version="1.0.0.20171031"
35+
Version="1.0.0.20171107"
3636
Manufacturer="Yandex LLC"
3737
UpgradeCode="$(var.UPGRADE_ID)">
3838

vs/installer64/Product.wxs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<Product Id="$(var.PRODUCT_ID)"
3333
Name="$(var.PKGNAME)"
3434
Language="1033"
35-
Version="1.0.0.20171031"
35+
Version="1.0.0.20171107"
3636
Manufacturer="Yandex LLC"
3737
UpgradeCode="$(var.UPGRADE_ID)">
3838

0 commit comments

Comments
 (0)