Skip to content

Commit 544c3bd

Browse files
isapegoMmuzaf
authored andcommitted
IGNITE-15677 Correctly handle windows in ODBC on Windows
This closes #9469
1 parent d0fa83f commit 544c3bd

7 files changed

Lines changed: 95 additions & 25 deletions

File tree

modules/platforms/cpp/odbc/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ if (WIN32)
9191

9292
remove_definitions(-DUNICODE=1)
9393

94-
add_definitions(-DTARGET_MODULE_FULL_NAME="${TARGET}")
94+
add_definitions(-DTARGET_MODULE_FULL_NAME="$<TARGET_FILE_NAME:${TARGET}>")
9595

9696
if (MSVC_VERSION GREATER_EQUAL 1900)
9797
target_link_libraries(${TARGET} legacy_stdio_definitions)

modules/platforms/cpp/odbc/include/ignite/odbc/common_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ namespace ignite
171171
/** Invalid SQL data type. */
172172
SHY004_INVALID_SQL_DATA_TYPE,
173173

174+
/** Operation canceled. */
175+
SHY008_OPERATION_CANCELED,
176+
174177
/** Invalid use of null pointer. */
175178
SHY009_INVALID_USE_OF_NULL_POINTER,
176179

modules/platforms/cpp/odbc/include/ignite/odbc/connection.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ namespace ignite
9090
* Establish connection to ODBC server.
9191
*
9292
* @param connectStr Connection string.
93+
* @param parentWindow Parent window pointer.
9394
*/
94-
void Establish(const std::string& connectStr);
95+
void Establish(const std::string& connectStr, void* parentWindow);
9596

9697
/**
9798
* Establish connection to ODBC server.
@@ -360,9 +361,10 @@ namespace ignite
360361
* Internal call.
361362
*
362363
* @param connectStr Connection string.
364+
* @param parentWindow Parent window.
363365
* @return Operation result.
364366
*/
365-
SqlResult::Type InternalEstablish(const std::string& connectStr);
367+
SqlResult::Type InternalEstablish(const std::string& connectStr, void* parentWindow);
366368

367369
/**
368370
* Establish connection to ODBC server.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef _IGNITE_ODBC_SYSTEM_SYSTEM_DSN
19+
#define _IGNITE_ODBC_SYSTEM_SYSTEM_DSN
20+
21+
#include <ignite/odbc/system/odbc_constants.h>
22+
23+
namespace ignite
24+
{
25+
namespace odbc
26+
{
27+
namespace config
28+
{
29+
class Configuration;
30+
}
31+
}
32+
}
33+
34+
/**
35+
* Display connection window for user to configure connection parameters.
36+
*
37+
* @param windowParent Parent window handle.
38+
* @param config Output configuration.
39+
* @return True on success and false on fail.
40+
*/
41+
bool DisplayConnectionWindow(void* windowParent, ignite::odbc::config::Configuration& config);
42+
43+
#endif //_IGNITE_ODBC_SYSTEM_SYSTEM_DSN

modules/platforms/cpp/odbc/os/win/src/system_dsn.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,14 @@
2828

2929
using ignite::odbc::config::Configuration;
3030

31-
/**
32-
* Display configuration window for user to configure DSN.
33-
*
34-
* @param hwndParent Parent window handle.
35-
* @param config Output configuration.
36-
* @return True on success and false on fail.
37-
*/
38-
bool DisplayConfigureDsnWindow(HWND hwndParent, Configuration& config)
31+
bool DisplayConnectionWindow(void* windowParent, Configuration& config)
3932
{
4033
using namespace ignite::odbc::system::ui;
4134

35+
HWND hwndParent = (HWND) windowParent;
36+
4237
if (!hwndParent)
43-
return false;
38+
return true;
4439

4540
try
4641
{
@@ -172,7 +167,7 @@ BOOL INSTAPI ConfigDSN(HWND hwndParent, WORD req, LPCSTR driver, LPCSTR attribut
172167
{
173168
LOG_MSG("ODBC_ADD_DSN");
174169

175-
if (!DisplayConfigureDsnWindow(hwndParent, config))
170+
if (!DisplayConnectionWindow(hwndParent, config))
176171
return FALSE;
177172

178173
if (!RegisterDsn(config, driver))
@@ -191,7 +186,7 @@ BOOL INSTAPI ConfigDSN(HWND hwndParent, WORD req, LPCSTR driver, LPCSTR attribut
191186

192187
ReadDsnConfiguration(dsn.c_str(), loaded, &diag);
193188

194-
if (!DisplayConfigureDsnWindow(hwndParent, loaded))
189+
if (!DisplayConnectionWindow(hwndParent, loaded))
195190
return FALSE;
196191

197192
if (!RegisterDsn(loaded, driver))

modules/platforms/cpp/odbc/src/connection.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "ignite/odbc/dsn_config.h"
3636
#include "ignite/odbc/config/configuration.h"
3737
#include "ignite/odbc/config/connection_string_parser.h"
38+
#include "ignite/odbc/system/system_dsn.h"
3839

3940
// Uncomment for per-byte debug.
4041
//#define PER_BYTE_DEBUG
@@ -102,19 +103,28 @@ namespace ignite
102103
return res;
103104
}
104105

105-
void Connection::Establish(const std::string& connectStr)
106+
void Connection::Establish(const std::string& connectStr, void* parentWindow)
106107
{
107-
IGNITE_ODBC_API_CALL(InternalEstablish(connectStr));
108+
IGNITE_ODBC_API_CALL(InternalEstablish(connectStr, parentWindow));
108109
}
109110

110-
SqlResult::Type Connection::InternalEstablish(const std::string& connectStr)
111+
SqlResult::Type Connection::InternalEstablish(const std::string& connectStr, void* parentWindow)
111112
{
112113
config::Configuration config;
113-
114114
config::ConnectionStringParser parser(config);
115-
116115
parser.ParseConnectionString(connectStr, &GetDiagnosticRecords());
117116

117+
if (parentWindow)
118+
{
119+
LOG_MSG("Parent window is passed. Creating configuration window.");
120+
if (!DisplayConnectionWindow(parentWindow, config))
121+
{
122+
AddStatusRecord(odbc::SqlState::SHY008_OPERATION_CANCELED, "Connection canceled by user");
123+
124+
return SqlResult::AI_ERROR;
125+
}
126+
}
127+
118128
if (config.IsDsnSet())
119129
{
120130
std::string dsn = config.GetDsn();

modules/platforms/cpp/odbc/src/odbc.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "ignite/odbc/log.h"
2424
#include "ignite/odbc/utility.h"
2525
#include "ignite/odbc/system/odbc_constants.h"
26+
#include "ignite/odbc/system/system_dsn.h"
2627

2728
#include "ignite/odbc/config/connection_string_parser.h"
2829
#include "ignite/odbc/config/configuration.h"
@@ -33,6 +34,26 @@
3334
#include "ignite/odbc/dsn_config.h"
3435
#include "ignite/odbc.h"
3536

37+
/**
38+
* Handle window handle.
39+
* @param windowHandle Window handle.
40+
* @param config Configuration.
41+
* @return @c true on success and @c false otherwise.
42+
*/
43+
bool HandleParentWindow(SQLHWND windowHandle, ignite::odbc::config::Configuration &config)
44+
{
45+
#ifdef _WIN32
46+
if (windowHandle)
47+
{
48+
LOG_MSG("Parent window is passed. Creating configuration window.");
49+
return DisplayConnectionWindow(windowHandle, config);
50+
}
51+
#else
52+
IGNITE_UNUSED(windowHandle);
53+
IGNITE_UNUSED(config);
54+
#endif
55+
return true;
56+
}
3657

3758
namespace ignite
3859
{
@@ -262,8 +283,6 @@ namespace ignite
262283
using utility::SqlStringToString;
263284
using utility::CopyStringToBuffer;
264285

265-
UNREFERENCED_PARAMETER(windowHandle);
266-
267286
LOG_MSG("SQLDriverConnect called");
268287
if (inConnectionString)
269288
LOG_MSG("Connection String: [" << inConnectionString << "]");
@@ -274,11 +293,9 @@ namespace ignite
274293
return SQL_INVALID_HANDLE;
275294

276295
std::string connectStr = SqlStringToString(inConnectionString, inConnectionStringLen);
296+
connection->Establish(connectStr, windowHandle);
277297

278-
connection->Establish(connectStr);
279-
280-
const DiagnosticRecordStorage& diag = connection->GetDiagnosticRecords();
281-
298+
DiagnosticRecordStorage& diag = connection->GetDiagnosticRecords();
282299
if (!diag.IsSuccessful())
283300
return diag.GetReturnCode();
284301

0 commit comments

Comments
 (0)