Skip to content

Commit

Permalink
#36 configure connection timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
artpaul committed Nov 7, 2017
1 parent 3434aec commit 018c1d1
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 5 deletions.
4 changes: 4 additions & 0 deletions driver/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ConnInfo::ConnInfo()
ZERO_FIELD(port);
ZERO_FIELD(sslmode);
ZERO_FIELD(onlyread);
ZERO_FIELD(timeout);
ZERO_FIELD(show_system_tables);
ZERO_FIELD(translation_dll);
ZERO_FIELD(translation_option);
Expand Down Expand Up @@ -48,4 +49,7 @@ void getDSNinfo(ConnInfo * ci, bool overwrite)

if (ci->password[0] == '\0' || overwrite)
SQLGetPrivateProfileString(ci->dsn, INI_PASSWORD, TEXT(""), ci->password, sizeof(ci->password), ODBC_INI);

if (ci->timeout[0] == '\0' || overwrite)
SQLGetPrivateProfileString(ci->dsn, INI_TIMEOUT, TEXT("30"), ci->timeout, sizeof(ci->timeout), ODBC_INI);
}
2 changes: 2 additions & 0 deletions driver/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define INI_PASSWORD TEXT("Password") /* Default Password */
#define INI_PORT TEXT("Port") /* Port on which the ClickHouse is listening */
#define INI_READONLY TEXT("ReadOnly") /* Database is read only */
#define INI_TIMEOUT TEXT("Timeout")

#ifndef WIN32
# define ODBC_INI ".odbc.ini"
Expand All @@ -39,6 +40,7 @@ struct ConnInfo
TCHAR port[SMALL_REGISTRY_LEN];
TCHAR sslmode[16];
TCHAR onlyread[SMALL_REGISTRY_LEN];
TCHAR timeout[SMALL_REGISTRY_LEN];
TCHAR show_system_tables[SMALL_REGISTRY_LEN];
TCHAR translation_dll[MEDIUM_REGISTRY_LEN];
TCHAR translation_option[SMALL_REGISTRY_LEN];
Expand Down
13 changes: 12 additions & 1 deletion driver/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void Connection::init()
session.setHost(server);
session.setPort(port);
session.setKeepAlive(true);
session.setTimeout(Poco::Timespan(30, 0));
session.setTimeout(Poco::Timespan(timeout, 0));
session.setKeepAliveTimeout(Poco::Timespan(86400, 0));
}

Expand Down Expand Up @@ -126,6 +126,15 @@ void Connection::loadConfiguration()
else
throw std::runtime_error("Cannot parse port number.");
}
if (timeout == 0)
{
const std::string timeout_string = stringFromTCHAR(ci.timeout);
if (!timeout_string.empty())
{
if (!Poco::NumberParser::tryParse(timeout_string, this->timeout))
throw std::runtime_error("Cannot parse connection timeout value.");
}
}

if (server.empty())
server = stringFromTCHAR(ci.server);
Expand All @@ -149,4 +158,6 @@ void Connection::setDefaults()
user = "default";
if (database.empty())
database = "default";
if (timeout == 0)
timeout = 30;
}
3 changes: 2 additions & 1 deletion driver/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ struct Connection

std::string data_source;
std::string server;
uint16_t port = 0;
std::string user;
std::string password;
uint16_t port = 0;
int timeout = 0;

Poco::Net::HTTPClientSession session;
DiagnosticRecord diagnostic_record;
Expand Down
Binary file modified driver/win/resource.h
Binary file not shown.
Binary file modified driver/win/resource.rc
Binary file not shown.
17 changes: 16 additions & 1 deletion driver/win/setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace
#define INI_PORT TEXT("Port") /* Port on which the ClickHouse is listening */
#define INI_READONLY TEXT("ReadOnly") /* Database is read only */
#define INI_PROTOCOL TEXT("Protocol") /* What protocol (6.2) */
#define INI_TIMEOUT TEXT("Timeout")
#define INI_DSN TEXT("ClickHouse")

#define ABBR_PROTOCOL TEXT("A1")
Expand Down Expand Up @@ -70,6 +71,7 @@ struct ConnInfo
TCHAR port[SMALL_REGISTRY_LEN];
TCHAR sslmode[16];
TCHAR onlyread[SMALL_REGISTRY_LEN];
TCHAR timeout[SMALL_REGISTRY_LEN];
TCHAR fake_oid_index[SMALL_REGISTRY_LEN];
TCHAR show_oid_column[SMALL_REGISTRY_LEN];
TCHAR row_versioning[SMALL_REGISTRY_LEN];
Expand Down Expand Up @@ -113,7 +115,7 @@ struct SetupDialogData
BOOL
copyAttributes(ConnInfo *ci, LPCTSTR attribute, LPCTSTR value)
{
BOOL found = TRUE;
BOOL found = TRUE;

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

else if (stricmp(attribute, INI_TIMEOUT) == 0)
strcpy(ci->timeout, value);

else
found = FALSE;

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

if (ci->password[0] == '\0' || overwrite)
SQLGetPrivateProfileString(DSN, INI_PASSWORD, TEXT(""), ci->password, sizeof(ci->password), ODBC_INI);

if (ci->timeout[0] == '\0' || overwrite)
SQLGetPrivateProfileString(DSN, INI_TIMEOUT, TEXT("30"), ci->timeout, sizeof(ci->timeout), ODBC_INI);
}

/* This is for datasource based options only */
Expand Down Expand Up @@ -262,6 +270,11 @@ void writeDSNinfo(const ConnInfo * ci)
INI_PASSWORD,
ci->password,
ODBC_INI);

SQLWritePrivateProfileString(DSN,
INI_TIMEOUT,
ci->timeout,
ODBC_INI);
}

static bool setDSNAttributes(HWND hwndParent, SetupDialogData * lpsetupdlg, DWORD * errcode)
Expand Down Expand Up @@ -386,6 +399,7 @@ INT_PTR CALLBACK
SetDlgItemText(hdlg, IDC_DATABASE, ci->database);
SetDlgItemText(hdlg, IDC_USER, ci->username);
SetDlgItemText(hdlg, IDC_PASSWORD, ci->password);
SetDlgItemText(hdlg, IDC_TIMEOUT, ci->timeout);

return TRUE; /* Focus was not set */
}
Expand All @@ -404,6 +418,7 @@ INT_PTR CALLBACK
GetDlgItemText(hdlg, IDC_DATABASE, ci->database, sizeof(ci->database));
GetDlgItemText(hdlg, IDC_USER, ci->username, sizeof(ci->username));
GetDlgItemText(hdlg, IDC_PASSWORD, ci->password, sizeof(ci->password));
GetDlgItemText(hdlg, IDC_TIMEOUT, ci->timeout, sizeof(ci->timeout));

/* Return to caller */
case IDCANCEL:
Expand Down
2 changes: 1 addition & 1 deletion vs/installer32/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<Product Id="$(var.PRODUCT_ID)"
Name="$(var.PKGNAME)"
Language="1033"
Version="1.0.0.20171031"
Version="1.0.0.20171107"
Manufacturer="Yandex LLC"
UpgradeCode="$(var.UPGRADE_ID)">

Expand Down
2 changes: 1 addition & 1 deletion vs/installer64/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<Product Id="$(var.PRODUCT_ID)"
Name="$(var.PKGNAME)"
Language="1033"
Version="1.0.0.20171031"
Version="1.0.0.20171107"
Manufacturer="Yandex LLC"
UpgradeCode="$(var.UPGRADE_ID)">

Expand Down

0 comments on commit 018c1d1

Please sign in to comment.