This is an automated email from the ASF dual-hosted git repository.

mmuzaf pushed a commit to branch ignite-2.11.1
in repository https://gitbox.apache.org/repos/asf/ignite.git

commit 544c3bd08c3184c8b92dc0dd4f1310388acff65b
Author: Igor Sapego <[email protected]>
AuthorDate: Tue Oct 5 13:13:16 2021 +0200

    IGNITE-15677 Correctly handle windows in ODBC on Windows
    
    This closes #9469
---
 modules/platforms/cpp/odbc/CMakeLists.txt          |  2 +-
 .../cpp/odbc/include/ignite/odbc/common_types.h    |  3 ++
 .../cpp/odbc/include/ignite/odbc/connection.h      |  6 ++-
 .../odbc/include/ignite/odbc/system/system_dsn.h   | 43 ++++++++++++++++++++++
 .../platforms/cpp/odbc/os/win/src/system_dsn.cpp   | 17 +++------
 modules/platforms/cpp/odbc/src/connection.cpp      | 20 +++++++---
 modules/platforms/cpp/odbc/src/odbc.cpp            | 29 ++++++++++++---
 7 files changed, 95 insertions(+), 25 deletions(-)

diff --git a/modules/platforms/cpp/odbc/CMakeLists.txt 
b/modules/platforms/cpp/odbc/CMakeLists.txt
index 6d6d50b..742d36f 100644
--- a/modules/platforms/cpp/odbc/CMakeLists.txt
+++ b/modules/platforms/cpp/odbc/CMakeLists.txt
@@ -91,7 +91,7 @@ if (WIN32)
 
     remove_definitions(-DUNICODE=1)
 
-    add_definitions(-DTARGET_MODULE_FULL_NAME="${TARGET}")
+    add_definitions(-DTARGET_MODULE_FULL_NAME="$<TARGET_FILE_NAME:${TARGET}>")
 
     if (MSVC_VERSION GREATER_EQUAL 1900)
         target_link_libraries(${TARGET} legacy_stdio_definitions)
diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/common_types.h 
b/modules/platforms/cpp/odbc/include/ignite/odbc/common_types.h
index 9241bbc..c2158ab 100644
--- a/modules/platforms/cpp/odbc/include/ignite/odbc/common_types.h
+++ b/modules/platforms/cpp/odbc/include/ignite/odbc/common_types.h
@@ -171,6 +171,9 @@ namespace ignite
                 /** Invalid SQL data type. */
                 SHY004_INVALID_SQL_DATA_TYPE,
 
+                /** Operation canceled. */
+                SHY008_OPERATION_CANCELED,
+
                 /** Invalid use of null pointer. */
                 SHY009_INVALID_USE_OF_NULL_POINTER,
 
diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/connection.h 
b/modules/platforms/cpp/odbc/include/ignite/odbc/connection.h
index 4b1df30..b670ee0 100644
--- a/modules/platforms/cpp/odbc/include/ignite/odbc/connection.h
+++ b/modules/platforms/cpp/odbc/include/ignite/odbc/connection.h
@@ -90,8 +90,9 @@ namespace ignite
              * Establish connection to ODBC server.
              *
              * @param connectStr Connection string.
+             * @param parentWindow Parent window pointer.
              */
-            void Establish(const std::string& connectStr);
+            void Establish(const std::string& connectStr, void* parentWindow);
 
             /**
              * Establish connection to ODBC server.
@@ -360,9 +361,10 @@ namespace ignite
              * Internal call.
              *
              * @param connectStr Connection string.
+             * @param parentWindow Parent window.
              * @return Operation result.
              */
-            SqlResult::Type InternalEstablish(const std::string& connectStr);
+            SqlResult::Type InternalEstablish(const std::string& connectStr, 
void* parentWindow);
 
             /**
              * Establish connection to ODBC server.
diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/system/system_dsn.h 
b/modules/platforms/cpp/odbc/include/ignite/odbc/system/system_dsn.h
new file mode 100644
index 0000000..38da117
--- /dev/null
+++ b/modules/platforms/cpp/odbc/include/ignite/odbc/system/system_dsn.h
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _IGNITE_ODBC_SYSTEM_SYSTEM_DSN
+#define _IGNITE_ODBC_SYSTEM_SYSTEM_DSN
+
+#include <ignite/odbc/system/odbc_constants.h>
+
+namespace ignite
+{
+    namespace odbc
+    {
+        namespace config
+        {
+            class Configuration;
+        }
+    }
+}
+
+/**
+ * Display connection window for user to configure connection parameters.
+ *
+ * @param windowParent Parent window handle.
+ * @param config Output configuration.
+ * @return True on success and false on fail.
+ */
+bool DisplayConnectionWindow(void* windowParent, 
ignite::odbc::config::Configuration& config);
+
+#endif //_IGNITE_ODBC_SYSTEM_SYSTEM_DSN
diff --git a/modules/platforms/cpp/odbc/os/win/src/system_dsn.cpp 
b/modules/platforms/cpp/odbc/os/win/src/system_dsn.cpp
index 0672911..0693550 100644
--- a/modules/platforms/cpp/odbc/os/win/src/system_dsn.cpp
+++ b/modules/platforms/cpp/odbc/os/win/src/system_dsn.cpp
@@ -28,19 +28,14 @@
 
 using ignite::odbc::config::Configuration;
 
-/**
- * Display configuration window for user to configure DSN.
- *
- * @param hwndParent Parent window handle.
- * @param config Output configuration.
- * @return True on success and false on fail.
- */
-bool DisplayConfigureDsnWindow(HWND hwndParent, Configuration& config)
+bool DisplayConnectionWindow(void* windowParent, Configuration& config)
 {
     using namespace ignite::odbc::system::ui;
 
+    HWND hwndParent = (HWND) windowParent;
+
     if (!hwndParent)
-        return false;
+        return true;
 
     try
     {
@@ -172,7 +167,7 @@ BOOL INSTAPI ConfigDSN(HWND hwndParent, WORD req, LPCSTR 
driver, LPCSTR attribut
         {
             LOG_MSG("ODBC_ADD_DSN");
 
-            if (!DisplayConfigureDsnWindow(hwndParent, config))
+            if (!DisplayConnectionWindow(hwndParent, config))
                 return FALSE;
 
             if (!RegisterDsn(config, driver))
@@ -191,7 +186,7 @@ BOOL INSTAPI ConfigDSN(HWND hwndParent, WORD req, LPCSTR 
driver, LPCSTR attribut
 
             ReadDsnConfiguration(dsn.c_str(), loaded, &diag);
 
-            if (!DisplayConfigureDsnWindow(hwndParent, loaded))
+            if (!DisplayConnectionWindow(hwndParent, loaded))
                 return FALSE;
 
             if (!RegisterDsn(loaded, driver))
diff --git a/modules/platforms/cpp/odbc/src/connection.cpp 
b/modules/platforms/cpp/odbc/src/connection.cpp
index b073580..337cacc 100644
--- a/modules/platforms/cpp/odbc/src/connection.cpp
+++ b/modules/platforms/cpp/odbc/src/connection.cpp
@@ -35,6 +35,7 @@
 #include "ignite/odbc/dsn_config.h"
 #include "ignite/odbc/config/configuration.h"
 #include "ignite/odbc/config/connection_string_parser.h"
+#include "ignite/odbc/system/system_dsn.h"
 
 // Uncomment for per-byte debug.
 //#define PER_BYTE_DEBUG
@@ -102,19 +103,28 @@ namespace ignite
             return res;
         }
 
-        void Connection::Establish(const std::string& connectStr)
+        void Connection::Establish(const std::string& connectStr, void* 
parentWindow)
         {
-            IGNITE_ODBC_API_CALL(InternalEstablish(connectStr));
+            IGNITE_ODBC_API_CALL(InternalEstablish(connectStr, parentWindow));
         }
 
-        SqlResult::Type Connection::InternalEstablish(const std::string& 
connectStr)
+        SqlResult::Type Connection::InternalEstablish(const std::string& 
connectStr, void* parentWindow)
         {
             config::Configuration config;
-
             config::ConnectionStringParser parser(config);
-
             parser.ParseConnectionString(connectStr, &GetDiagnosticRecords());
 
+            if (parentWindow)
+            {
+                LOG_MSG("Parent window is passed. Creating configuration 
window.");
+                if (!DisplayConnectionWindow(parentWindow, config))
+                {
+                    AddStatusRecord(odbc::SqlState::SHY008_OPERATION_CANCELED, 
"Connection canceled by user");
+
+                    return SqlResult::AI_ERROR;
+                }
+            }
+
             if (config.IsDsnSet())
             {
                 std::string dsn = config.GetDsn();
diff --git a/modules/platforms/cpp/odbc/src/odbc.cpp 
b/modules/platforms/cpp/odbc/src/odbc.cpp
index f297ec4..ef61bb4 100644
--- a/modules/platforms/cpp/odbc/src/odbc.cpp
+++ b/modules/platforms/cpp/odbc/src/odbc.cpp
@@ -23,6 +23,7 @@
 #include "ignite/odbc/log.h"
 #include "ignite/odbc/utility.h"
 #include "ignite/odbc/system/odbc_constants.h"
+#include "ignite/odbc/system/system_dsn.h"
 
 #include "ignite/odbc/config/connection_string_parser.h"
 #include "ignite/odbc/config/configuration.h"
@@ -33,6 +34,26 @@
 #include "ignite/odbc/dsn_config.h"
 #include "ignite/odbc.h"
 
+/**
+ * Handle window handle.
+ * @param windowHandle Window handle.
+ * @param config Configuration.
+ * @return @c true on success and @c false otherwise.
+ */
+bool HandleParentWindow(SQLHWND windowHandle, 
ignite::odbc::config::Configuration &config)
+{
+#ifdef _WIN32
+    if (windowHandle)
+    {
+        LOG_MSG("Parent window is passed. Creating configuration window.");
+        return DisplayConnectionWindow(windowHandle, config);
+    }
+#else
+    IGNITE_UNUSED(windowHandle);
+    IGNITE_UNUSED(config);
+#endif
+    return true;
+}
 
 namespace ignite
 {
@@ -262,8 +283,6 @@ namespace ignite
         using utility::SqlStringToString;
         using utility::CopyStringToBuffer;
 
-        UNREFERENCED_PARAMETER(windowHandle);
-
         LOG_MSG("SQLDriverConnect called");
         if (inConnectionString)
             LOG_MSG("Connection String: [" << inConnectionString << "]");
@@ -274,11 +293,9 @@ namespace ignite
             return SQL_INVALID_HANDLE;
 
         std::string connectStr = SqlStringToString(inConnectionString, 
inConnectionStringLen);
+        connection->Establish(connectStr, windowHandle);
 
-        connection->Establish(connectStr);
-
-        const DiagnosticRecordStorage& diag = 
connection->GetDiagnosticRecords();
-
+        DiagnosticRecordStorage& diag = connection->GetDiagnosticRecords();
         if (!diag.IsSuccessful())
             return diag.GetReturnCode();
 

Reply via email to