You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2016/09/08 15:40:50 UTC

[08/50] [abbrv] ignite git commit: IGNITE-3390: ODBC: Added DSN configuration dialog for Windows. This closes #881.

http://git-wip-us.apache.org/repos/asf/ignite/blob/60afa372/modules/platforms/cpp/odbc/src/config/configuration.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc/src/config/configuration.cpp b/modules/platforms/cpp/odbc/src/config/configuration.cpp
index 24c2bdf..dbe40bd 100644
--- a/modules/platforms/cpp/odbc/src/config/configuration.cpp
+++ b/modules/platforms/cpp/odbc/src/config/configuration.cpp
@@ -122,7 +122,7 @@ namespace ignite
                 return connect_string_buffer.str();
             }
 
-            void Configuration::FillFromConfigAttributes(const char * attributes)
+            void Configuration::FillFromConfigAttributes(const char* attributes)
             {
                 // Initializing map.
                 arguments.clear();
@@ -150,6 +150,11 @@ namespace ignite
                 }
             }
 
+            void Configuration::SetTcpPort(uint16_t port)
+            {
+                arguments[Key::port] = common::LexicalCast<std::string>(port);
+            }
+
             ProtocolVersion Configuration::GetProtocolVersion() const
             {
                 ArgumentMap::const_iterator it = arguments.find(Key::protocolVersion);
@@ -160,6 +165,11 @@ namespace ignite
                 return DefaultValue::protocolVersion;
             }
 
+            void Configuration::SetProtocolVersion(const std::string& version)
+            {
+                arguments[Key::protocolVersion] = version;
+            }
+
             const std::string& Configuration::GetStringValue(const std::string& key, const std::string& dflt) const
             {
                 ArgumentMap::const_iterator it = arguments.find(common::ToLower(key));
@@ -206,6 +216,11 @@ namespace ignite
                 return dflt;
             }
 
+            void Configuration::SetBoolValue(const std::string& key, bool val)
+            {
+                arguments[key] = val ? "true" : "false";
+            }
+
             void Configuration::ParseAttributeList(const char * str, size_t len, char delimeter, ArgumentMap & args)
             {
                 std::string connect_str(str, len);

http://git-wip-us.apache.org/repos/asf/ignite/blob/60afa372/modules/platforms/cpp/odbc/src/connection.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc/src/connection.cpp b/modules/platforms/cpp/odbc/src/connection.cpp
index 4315698..0fd9513 100644
--- a/modules/platforms/cpp/odbc/src/connection.cpp
+++ b/modules/platforms/cpp/odbc/src/connection.cpp
@@ -117,7 +117,7 @@ namespace ignite
                 return SQL_RESULT_ERROR;
             }
 
-            connected = socket.Connect(cfg.GetHost().c_str(), cfg.GetPort());
+            connected = socket.Connect(cfg.GetHost().c_str(), cfg.GetTcpPort());
 
             if (!connected)
             {

http://git-wip-us.apache.org/repos/asf/ignite/blob/60afa372/modules/platforms/cpp/odbc/src/diagnostic/diagnostic_record.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc/src/diagnostic/diagnostic_record.cpp b/modules/platforms/cpp/odbc/src/diagnostic/diagnostic_record.cpp
index 0fdfbc8..8553ee4 100644
--- a/modules/platforms/cpp/odbc/src/diagnostic/diagnostic_record.cpp
+++ b/modules/platforms/cpp/odbc/src/diagnostic/diagnostic_record.cpp
@@ -171,7 +171,7 @@ namespace ignite
                 return ORIGIN_ISO_9075;
             }
 
-            const std::string& DiagnosticRecord::GetMessage() const
+            const std::string& DiagnosticRecord::GetMessageText() const
             {
                 return message;
             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/60afa372/modules/platforms/cpp/odbc/src/diagnostic/diagnostic_record_storage.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc/src/diagnostic/diagnostic_record_storage.cpp b/modules/platforms/cpp/odbc/src/diagnostic/diagnostic_record_storage.cpp
index 90c0a4f..99ef292 100644
--- a/modules/platforms/cpp/odbc/src/diagnostic/diagnostic_record_storage.cpp
+++ b/modules/platforms/cpp/odbc/src/diagnostic/diagnostic_record_storage.cpp
@@ -190,7 +190,7 @@ namespace ignite
 
                     case IGNITE_SQL_DIAG_STATUS_MESSAGE_TEXT:
                     {
-                        buffer.PutString(record.GetMessage());
+                        buffer.PutString(record.GetMessageText());
 
                         return SQL_RESULT_SUCCESS;
                     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/60afa372/modules/platforms/cpp/odbc/src/dsn_config.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc/src/dsn_config.cpp b/modules/platforms/cpp/odbc/src/dsn_config.cpp
new file mode 100644
index 0000000..a304567
--- /dev/null
+++ b/modules/platforms/cpp/odbc/src/dsn_config.cpp
@@ -0,0 +1,115 @@
+/*
+ * 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.
+ */
+
+#include <set>
+
+#include "ignite/odbc/utility.h"
+#include "ignite/odbc/system/odbc_constants.h"
+
+#include "ignite/odbc/dsn_config.h"
+
+using ignite::odbc::config::Configuration;
+
+#define BUFFER_SIZE 1024
+#define CONFIG_FILE "ODBC.INI"
+
+namespace ignite
+{
+    namespace odbc
+    {
+        void ThrowLastSetupError()
+        {
+            DWORD code;
+            char msg[BUFFER_SIZE];
+
+            SQLInstallerError(1, &code, msg, sizeof(msg), NULL);
+
+            std::stringstream buf;
+
+            buf << "Message: \"" << msg << "\", Code: " << code;
+
+            throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, buf.str().c_str());
+        }
+
+        void WriteDsnString(const char* dsn, const char* key, const char* value)
+        {
+            if (!SQLWritePrivateProfileString(dsn, key, value, CONFIG_FILE))
+                ThrowLastSetupError();
+        }
+
+        std::string ReadDsnString(const char* dsn, const std::string& key, const char* dflt)
+        {
+            char buf[BUFFER_SIZE];
+
+            memset(buf, 0, sizeof(buf));
+
+            SQLGetPrivateProfileString(dsn, key.c_str(), dflt, buf, sizeof(buf), CONFIG_FILE);
+
+            return std::string(buf);
+        }
+
+        int ReadDsnInt(const char* dsn, const std::string& key, int dflt)
+        {
+            char buf[BUFFER_SIZE];
+
+            memset(buf, 0, sizeof(buf));
+
+            std::string dflt0 = common::LexicalCast<std::string>(dflt);
+
+            SQLGetPrivateProfileString(dsn, key.c_str(), dflt0.c_str(), buf, sizeof(buf), CONFIG_FILE);
+
+            return common::LexicalCast<int, std::string>(buf);
+        }
+
+        bool ReadDsnBool(const char* dsn, const std::string& key, bool dflt)
+        {
+            char buf[BUFFER_SIZE];
+
+            memset(buf, 0, sizeof(buf));
+
+            std::string dflt0 = dflt ? "true" : "false";
+
+            SQLGetPrivateProfileString(dsn, key.c_str(), dflt0.c_str(), buf, sizeof(buf), CONFIG_FILE);
+
+            return std::string(buf) == "true";
+        }
+
+        void ReadDsnConfiguration(const char* dsn, Configuration& config)
+        {
+            std::string address = ReadDsnString(dsn, Configuration::Key::address, config.GetAddress().c_str());
+            std::string server = ReadDsnString(dsn, Configuration::Key::server, config.GetHost().c_str());
+            uint16_t port = ReadDsnInt(dsn, Configuration::Key::port, config.GetTcpPort());
+            std::string cache = ReadDsnString(dsn, Configuration::Key::cache, config.GetCache().c_str());
+            bool distributedJoins = ReadDsnBool(dsn, Configuration::Key::distributedJoins, config.IsDistributedJoins());
+            bool enforceJoinOrder = ReadDsnBool(dsn, Configuration::Key::enforceJoinOrder, config.IsEnforceJoinOrder());
+            std::string version = ReadDsnString(dsn, Configuration::Key::protocolVersion,
+                config.GetProtocolVersion().ToString().c_str());
+
+            LOG_MSG("%d\n", __LINE__);
+
+            config.SetAddress(address);
+            config.SetHost(server);
+            config.SetTcpPort(port);
+            config.SetCache(cache);
+            config.SetDistributedJoins(distributedJoins);
+            config.SetEnforceJoinOrder(enforceJoinOrder);
+            config.SetProtocolVersion(version);
+
+            LOG_MSG("%d\n", __LINE__);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/60afa372/modules/platforms/cpp/odbc/src/entry_points.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc/src/entry_points.cpp b/modules/platforms/cpp/odbc/src/entry_points.cpp
index c8e78a5..f6195e1 100644
--- a/modules/platforms/cpp/odbc/src/entry_points.cpp
+++ b/modules/platforms/cpp/odbc/src/entry_points.cpp
@@ -19,14 +19,6 @@
 
 #include "ignite/odbc/utility.h"
 
-BOOL INSTAPI ConfigDSN(HWND     hwndParent,
-                       WORD     req,
-                       LPCSTR   driver,
-                       LPCSTR   attributes)
-{
-    return ignite::ConfigDSN(hwndParent, req, driver, attributes);
-}
-
 SQLRETURN SQL_API SQLGetInfo(SQLHDBC        conn,
                              SQLUSMALLINT   infoType,
                              SQLPOINTER     infoValue,

http://git-wip-us.apache.org/repos/asf/ignite/blob/60afa372/modules/platforms/cpp/odbc/src/odbc.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc/src/odbc.cpp b/modules/platforms/cpp/odbc/src/odbc.cpp
index 9b4179e..fd35cba 100644
--- a/modules/platforms/cpp/odbc/src/odbc.cpp
+++ b/modules/platforms/cpp/odbc/src/odbc.cpp
@@ -28,70 +28,11 @@
 #include "ignite/odbc/environment.h"
 #include "ignite/odbc/connection.h"
 #include "ignite/odbc/statement.h"
+#include "ignite/odbc/dsn_config.h"
 #include "ignite/odbc.h"
 
 namespace ignite
 {
-
-    BOOL ConfigDSN(HWND     hwndParent,
-                   WORD     req,
-                   LPCSTR   driver,
-                   LPCSTR   attributes)
-    {
-        LOG_MSG("ConfigDSN called\n");
-
-        ignite::odbc::config::Configuration config;
-
-        try
-        {
-            config.FillFromConfigAttributes(attributes);
-        }
-        catch (IgniteError& e)
-        {
-            SQLPostInstallerError(e.GetCode(), e.GetText());
-
-            return SQL_FALSE;
-        }
-
-        if (!SQLValidDSN(config.GetDsn().c_str()))
-            return SQL_FALSE;
-
-        LOG_MSG("Driver: %s\n", driver);
-        LOG_MSG("Attributes: %s\n", attributes);
-
-        LOG_MSG("DSN: %s\n", config.GetDsn().c_str());
-
-        switch (req)
-        {
-            case ODBC_ADD_DSN:
-            {
-                LOG_MSG("ODBC_ADD_DSN\n");
-
-                return SQLWriteDSNToIni(config.GetDsn().c_str(), driver);
-            }
-
-            case ODBC_CONFIG_DSN:
-            {
-                LOG_MSG("ODBC_CONFIG_DSN\n");
-                break;
-            }
-
-            case ODBC_REMOVE_DSN:
-            {
-                LOG_MSG("ODBC_REMOVE_DSN\n");
-
-                return SQLRemoveDSNFromIni(config.GetDsn().c_str());
-            }
-
-            default:
-            {
-                return SQL_FALSE;
-            }
-        }
-
-        return SQL_TRUE;
-    }
-
     SQLRETURN SQLGetInfo(SQLHDBC        conn,
                          SQLUSMALLINT   infoType,
                          SQLPOINTER     infoValue,
@@ -315,10 +256,10 @@ namespace ignite
                                SQLSMALLINT* outConnectionStringLen,
                                SQLUSMALLINT driverCompletion)
     {
-        using ignite::odbc::Connection;
-        using ignite::odbc::diagnostic::DiagnosticRecordStorage;
-        using ignite::utility::SqlStringToString;
-        using ignite::utility::CopyStringToBuffer;
+        using odbc::Connection;
+        using odbc::diagnostic::DiagnosticRecordStorage;
+        using utility::SqlStringToString;
+        using utility::CopyStringToBuffer;
 
         UNREFERENCED_PARAMETER(windowHandle);
 
@@ -332,7 +273,16 @@ namespace ignite
 
         std::string connectStr = SqlStringToString(inConnectionString, inConnectionStringLen);
 
-        connection->Establish(connectStr);
+        odbc::config::Configuration config;
+
+        config.FillFromConnectString(connectStr);
+
+        std::string dsn = config.GetDsn();
+
+        if (!dsn.empty())
+            odbc::ReadDsnConfiguration(dsn.c_str(), config);
+
+        connection->Establish(config);
 
         const DiagnosticRecordStorage& diag = connection->GetDiagnosticRecords();
 
@@ -372,9 +322,11 @@ namespace ignite
         if (!connection)
             return SQL_INVALID_HANDLE;
 
-        //std::string server = SqlStringToString(serverName, serverNameLen);
+        odbc::config::Configuration config;
+
+        std::string dsn = SqlStringToString(serverName, serverNameLen);
 
-        Configuration config;
+        odbc::ReadDsnConfiguration(dsn.c_str(), config);
 
         connection->Establish(config);
 
@@ -1175,7 +1127,7 @@ namespace ignite
         SqlLen outResLen;
         ApplicationDataBuffer outBuffer(IGNITE_ODBC_C_TYPE_CHAR, msgBuffer, msgBufferLen, &outResLen);
 
-        outBuffer.PutString(record.GetMessage());
+        outBuffer.PutString(record.GetMessageText());
 
         *msgLen = static_cast<SQLSMALLINT>(outResLen);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/60afa372/modules/platforms/cpp/odbc/src/protocol_version.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc/src/protocol_version.cpp b/modules/platforms/cpp/odbc/src/protocol_version.cpp
index c65099d..ebd3b6a 100644
--- a/modules/platforms/cpp/odbc/src/protocol_version.cpp
+++ b/modules/platforms/cpp/odbc/src/protocol_version.cpp
@@ -14,12 +14,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-#include "ignite/odbc/protocol_version.h"
 #include <ignite/common/concurrent.h>
 #include <ignite/common/utils.h>
 #include <ignite/ignite_error.h>
 
+#include "ignite/odbc/protocol_version.h"
+#include "ignite/odbc/utility.h"
+
 namespace ignite
 {
     namespace odbc
@@ -50,10 +51,15 @@ namespace ignite
             // No-op.
         }
 
-        int64_t ProtocolVersion::MakeVersion(uint16_t major, uint16_t minor, uint16_t maintenance)
+        int64_t ProtocolVersion::MakeVersion(uint16_t major, uint16_t minor, uint16_t revision)
         {
             const static int64_t MASK = 0x000000000000FFFFLL;
-            return ((major & MASK) << 48) | ((minor & MASK) << 32) | ((maintenance & MASK) << 16);
+            return ((major & MASK) << 48) | ((minor & MASK) << 32) | ((revision & MASK) << 16);
+        }
+
+        const ProtocolVersion::StringToVersionMap& ProtocolVersion::GetMap()
+        {
+            return stringToVersionMap;
         }
 
         const ProtocolVersion& ProtocolVersion::GetCurrent()
@@ -68,8 +74,8 @@ namespace ignite
             if (it == stringToVersionMap.end())
             {
                 throw IgniteError(IgniteError::IGNITE_ERR_GENERIC,
-                    "Invalid version format. Valid format is X.Y.Z, where X, Y and Z are major, "
-                    "minor and maintenance versions of Ignite since which protocol is introduced.");
+                    "Invalid version format. Valid format is X.Y.Z, where X, Y and Z are major "
+                    "and minor versions and revision of Ignite since which protocol is introduced.");
             }
 
             return it->second;
@@ -100,6 +106,11 @@ namespace ignite
             return *this == VERSION_UNKNOWN;
         }
 
+        bool ProtocolVersion::IsDistributedJoinsSupported() const
+        {
+            return *this >= VERSION_1_8_0;
+        }
+
         bool operator==(const ProtocolVersion& val1, const ProtocolVersion& val2)
         {
             return val1.val == val2.val;