You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by nt...@apache.org on 2017/08/15 18:00:08 UTC

[07/29] ignite git commit: IGNITE-5923: ODBC: SQLGetTypeInfo now works with SQL_ALL_TYPES

IGNITE-5923: ODBC: SQLGetTypeInfo now works with SQL_ALL_TYPES

(cherry picked from commit 48c914d)


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/0b3a9a71
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/0b3a9a71
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/0b3a9a71

Branch: refs/heads/ignite-5947
Commit: 0b3a9a7176f5ae44a96ecf700c8147193dfbf064
Parents: d1a74a4
Author: Igor Sapego <is...@gridgain.com>
Authored: Fri Aug 4 13:18:00 2017 +0300
Committer: Igor Sapego <is...@gridgain.com>
Committed: Fri Aug 4 17:46:10 2017 +0300

----------------------------------------------------------------------
 modules/platforms/cpp/odbc-test/Makefile.am     |   1 +
 .../cpp/odbc-test/include/complex_type.h        | 271 +++++++++----------
 .../cpp/odbc-test/project/vs/odbc-test.vcxproj  |   1 +
 .../project/vs/odbc-test.vcxproj.filters        |   3 +
 .../cpp/odbc-test/src/meta_queries_test.cpp     | 189 +++++++++++++
 modules/platforms/cpp/odbc/src/odbc.cpp         |   2 +-
 .../cpp/odbc/src/query/type_info_query.cpp      |   2 +-
 modules/platforms/cpp/odbc/src/statement.cpp    |   2 +-
 8 files changed, 332 insertions(+), 139 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/0b3a9a71/modules/platforms/cpp/odbc-test/Makefile.am
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc-test/Makefile.am b/modules/platforms/cpp/odbc-test/Makefile.am
index 56ae56a..1d65468 100644
--- a/modules/platforms/cpp/odbc-test/Makefile.am
+++ b/modules/platforms/cpp/odbc-test/Makefile.am
@@ -61,6 +61,7 @@ ignite_odbc_tests_SOURCES = \
     src/column_test.cpp \
     src/configuration_test.cpp \
     src/row_test.cpp \
+    src/meta_queries_test.cpp \
     src/utility_test.cpp \
     src/queries_test.cpp \
     src/test_utils.cpp \

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b3a9a71/modules/platforms/cpp/odbc-test/include/complex_type.h
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc-test/include/complex_type.h b/modules/platforms/cpp/odbc-test/include/complex_type.h
index 8a1bd59..ea01554 100644
--- a/modules/platforms/cpp/odbc-test/include/complex_type.h
+++ b/modules/platforms/cpp/odbc-test/include/complex_type.h
@@ -1,137 +1,136 @@
-/*
- * 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_TEST_COMPLEX_TYPE
-#define _IGNITE_ODBC_TEST_COMPLEX_TYPE
-
-#include <string>
-
-#include "ignite/ignite.h"
-#include "ignite/ignition.h"
-
-namespace ignite
-{
-    struct TestObject
-    {
-        TestObject() :
-            f1(412),
-            f2("Lorem ipsum")
-        {
-            // No-op.
-        }
-
-        int32_t f1;
-        std::string f2;
-    };
-
-    struct ComplexType
-    {
-        ComplexType() :
-            i32Field(0)
-        {
-            // No-op.
-        }
-
-        int32_t i32Field;
-        TestObject objField;
-        std::string strField;
-    };
-
-    bool operator==(TestObject const& lhs, TestObject const& rhs)
-    {
-        return lhs.f1 == rhs.f1 && lhs.f2 == rhs.f2;
-    }
-
-    bool operator==(ComplexType const& lhs, ComplexType const& rhs)
-    {
-        return lhs.i32Field == rhs.i32Field && lhs.objField == rhs.objField && lhs.strField == rhs.strField;
-    }
-
-    std::ostream& operator<<(std::ostream& str, TestObject const& obj)
-    {
-        str << "TestObject::f1: " << obj.f1
-            << "TestObject::f2: " << obj.f2;
-        return str;
-    }
-
-    std::ostream& operator<<(std::ostream& str, ComplexType const& obj)
+/*
+ * 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_TEST_COMPLEX_TYPE
+#define _IGNITE_ODBC_TEST_COMPLEX_TYPE
+
+#include <string>
+
+#include "ignite/ignite.h"
+
+namespace ignite
+{
+    struct TestObject
     {
-        str << "ComplexType::i32Field: " << obj.i32Field
-            << "ComplexType::objField: " << obj.objField
-            << "ComplexType::strField: " << obj.strField;
-        return str;
-    }
-}
-
-namespace ignite
-{
-    namespace binary
-    {
-
-        IGNITE_BINARY_TYPE_START(ignite::TestObject)
-
-            typedef ignite::TestObject TestObject;
-
-            IGNITE_BINARY_GET_TYPE_ID_AS_HASH(TestObject)
-            IGNITE_BINARY_GET_TYPE_NAME_AS_IS(TestObject)
-            IGNITE_BINARY_GET_FIELD_ID_AS_HASH
-            IGNITE_BINARY_IS_NULL_FALSE(TestObject)
-            IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(TestObject)
-
-            static void Write(BinaryWriter& writer, const TestObject& obj)
-            {
-                writer.WriteInt32("f1", obj.f1);
-                writer.WriteString("f2", obj.f2);
-            }
-
-            static void Read(BinaryReader& reader, TestObject& dst)
-            {
-                dst.f1 = reader.ReadInt32("f1");
-                dst.f2 = reader.ReadString("f2");
-            }
-
-        IGNITE_BINARY_TYPE_END
-
-        IGNITE_BINARY_TYPE_START(ignite::ComplexType)
-
-            typedef ignite::ComplexType ComplexType;
-
-            IGNITE_BINARY_GET_TYPE_ID_AS_HASH(ComplexType)
-            IGNITE_BINARY_GET_TYPE_NAME_AS_IS(ComplexType)
-            IGNITE_BINARY_GET_FIELD_ID_AS_HASH
-            IGNITE_BINARY_IS_NULL_FALSE(ComplexType)
-            IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(ComplexType)
-
-            static void Write(BinaryWriter& writer, const ComplexType& obj)
-            {
-                writer.WriteInt32("i32Field", obj.i32Field);
-                writer.WriteObject("objField", obj.objField);
-                writer.WriteString("strField", obj.strField);
-            }
-
-            static void Read(BinaryReader& reader, ComplexType& dst)
-            {
-                dst.i32Field = reader.ReadInt32("i32Field");
-                dst.objField = reader.ReadObject<TestObject>("objField");
-                dst.strField = reader.ReadString("strField");
-            }
-
-        IGNITE_BINARY_TYPE_END
-    }
-};
-
-#endif // _IGNITE_ODBC_TEST_COMPLEX_TYPE
+        TestObject() :
+            f1(412),
+            f2("Lorem ipsum")
+        {
+            // No-op.
+        }
+
+        friend bool operator==(TestObject const& lhs, TestObject const& rhs)
+        {
+            return lhs.f1 == rhs.f1 && lhs.f2 == rhs.f2;
+        }
+
+        friend std::ostream& operator<<(std::ostream& str, TestObject const& obj)
+        {
+            str << "TestObject::f1: " << obj.f1
+                << "TestObject::f2: " << obj.f2;
+            return str;
+        }
+
+        int32_t f1;
+        std::string f2;
+    };
+
+    struct ComplexType
+    {
+        ComplexType() :
+            i32Field(0)
+        {
+            // No-op.
+        }
+
+        friend bool operator==(ComplexType const& lhs, ComplexType const& rhs)
+        {
+            return lhs.i32Field == rhs.i32Field && lhs.objField == rhs.objField && lhs.strField == rhs.strField;
+        }
+
+        friend std::ostream& operator<<(std::ostream& str, ComplexType const& obj)
+        {
+            str << "ComplexType::i32Field: " << obj.i32Field
+                << "ComplexType::objField: " << obj.objField
+                << "ComplexType::strField: " << obj.strField;
+            return str;
+        }
+
+        int32_t i32Field;
+        TestObject objField;
+        std::string strField;
+    };
+}
+
+namespace ignite
+{
+    namespace binary
+    {
+
+        IGNITE_BINARY_TYPE_START(ignite::TestObject)
+
+            typedef ignite::TestObject TestObject;
+
+            IGNITE_BINARY_GET_TYPE_ID_AS_HASH(TestObject)
+            IGNITE_BINARY_GET_TYPE_NAME_AS_IS(TestObject)
+            IGNITE_BINARY_GET_FIELD_ID_AS_HASH
+            IGNITE_BINARY_IS_NULL_FALSE(TestObject)
+            IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(TestObject)
+
+            static void Write(BinaryWriter& writer, const TestObject& obj)
+            {
+                writer.WriteInt32("f1", obj.f1);
+                writer.WriteString("f2", obj.f2);
+            }
+
+            static void Read(BinaryReader& reader, TestObject& dst)
+            {
+                dst.f1 = reader.ReadInt32("f1");
+                dst.f2 = reader.ReadString("f2");
+            }
+
+        IGNITE_BINARY_TYPE_END
+
+        IGNITE_BINARY_TYPE_START(ignite::ComplexType)
+
+            typedef ignite::ComplexType ComplexType;
+
+            IGNITE_BINARY_GET_TYPE_ID_AS_HASH(ComplexType)
+            IGNITE_BINARY_GET_TYPE_NAME_AS_IS(ComplexType)
+            IGNITE_BINARY_GET_FIELD_ID_AS_HASH
+            IGNITE_BINARY_IS_NULL_FALSE(ComplexType)
+            IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(ComplexType)
+
+            static void Write(BinaryWriter& writer, const ComplexType& obj)
+            {
+                writer.WriteInt32("i32Field", obj.i32Field);
+                writer.WriteObject("objField", obj.objField);
+                writer.WriteString("strField", obj.strField);
+            }
+
+            static void Read(BinaryReader& reader, ComplexType& dst)
+            {
+                dst.i32Field = reader.ReadInt32("i32Field");
+                dst.objField = reader.ReadObject<TestObject>("objField");
+                dst.strField = reader.ReadString("strField");
+            }
+
+        IGNITE_BINARY_TYPE_END
+    }
+};
+
+#endif // _IGNITE_ODBC_TEST_COMPLEX_TYPE

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b3a9a71/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj
index c332aad..ceecb3d 100644
--- a/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj
+++ b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj
@@ -168,6 +168,7 @@
     <ClCompile Include="..\..\src\configuration_test.cpp" />
     <ClCompile Include="..\..\src\connection_info_test.cpp" />
     <ClCompile Include="..\..\src\cursor_test.cpp" />
+    <ClCompile Include="..\..\src\meta_queries_test.cpp" />
     <ClCompile Include="..\..\src\queries_test.cpp" />
     <ClCompile Include="..\..\src\parser_test.cpp" />
     <ClCompile Include="..\..\src\row_test.cpp" />

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b3a9a71/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj.filters
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj.filters b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj.filters
index 65f2ebf..91c029e 100644
--- a/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj.filters
+++ b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj.filters
@@ -121,6 +121,9 @@
     <ClCompile Include="..\..\..\odbc\src\log.cpp">
       <Filter>Externals</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\meta_queries_test.cpp">
+      <Filter>Code</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\include\test_type.h">

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b3a9a71/modules/platforms/cpp/odbc-test/src/meta_queries_test.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc-test/src/meta_queries_test.cpp b/modules/platforms/cpp/odbc-test/src/meta_queries_test.cpp
new file mode 100644
index 0000000..5b7ae59
--- /dev/null
+++ b/modules/platforms/cpp/odbc-test/src/meta_queries_test.cpp
@@ -0,0 +1,189 @@
+/*
+ * 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.
+ */
+
+#ifdef _WIN32
+#   include <windows.h>
+#endif
+
+#include <sql.h>
+#include <sqlext.h>
+
+#include <vector>
+#include <string>
+#include <algorithm>
+
+#ifndef _MSC_VER
+#   define BOOST_TEST_DYN_LINK
+#endif
+
+#include <boost/test/unit_test.hpp>
+
+#include "ignite/ignition.h"
+
+#include "ignite/common/fixed_size_array.h"
+#include "ignite/impl/binary/binary_utils.h"
+
+#include "test_type.h"
+#include "complex_type.h"
+#include "test_utils.h"
+
+using namespace ignite;
+using namespace ignite::cache;
+using namespace ignite::cache::query;
+using namespace ignite::common;
+using namespace ignite_test;
+using namespace ignite::binary;
+using namespace ignite::impl::binary;
+using namespace ignite::impl::interop;
+
+using namespace boost::unit_test;
+
+/**
+ * Test setup fixture.
+ */
+struct MetaQueriesTestSuiteFixture 
+{
+    /**
+     * Establish connection to node.
+     *
+     * @param connectStr Connection string.
+     */
+    void Connect(const std::string& connectStr)
+    {
+        // Allocate an environment handle
+        SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
+
+        BOOST_REQUIRE(env != NULL);
+
+        // We want ODBC 3 support
+        SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, reinterpret_cast<void*>(SQL_OV_ODBC3), 0);
+
+        // Allocate a connection handle
+        SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc);
+
+        BOOST_REQUIRE(dbc != NULL);
+
+        // Connect string
+        std::vector<SQLCHAR> connectStr0;
+
+        connectStr0.reserve(connectStr.size() + 1);
+        std::copy(connectStr.begin(), connectStr.end(), std::back_inserter(connectStr0));
+
+        SQLCHAR outstr[ODBC_BUFFER_SIZE];
+        SQLSMALLINT outstrlen;
+
+        // Connecting to ODBC server.
+        SQLRETURN ret = SQLDriverConnect(dbc, NULL, &connectStr0[0], static_cast<SQLSMALLINT>(connectStr0.size()),
+            outstr, sizeof(outstr), &outstrlen, SQL_DRIVER_COMPLETE);
+
+        if (!SQL_SUCCEEDED(ret))
+        {
+            Ignition::Stop(grid.GetName(), true);
+
+            BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_DBC, dbc));
+        }
+
+        // Allocate a statement handle
+        SQLAllocHandle(SQL_HANDLE_STMT, dbc, &stmt);
+
+        BOOST_REQUIRE(stmt != NULL);
+    }
+
+    void Disconnect()
+    {
+        // Releasing statement handle.
+        SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+
+        // Disconneting from the server.
+        SQLDisconnect(dbc);
+
+        // Releasing allocated handles.
+        SQLFreeHandle(SQL_HANDLE_DBC, dbc);
+        SQLFreeHandle(SQL_HANDLE_ENV, env);
+    }
+
+    static Ignite StartAdditionalNode(const char* name)
+    {
+#ifdef IGNITE_TESTS_32
+        return StartNode("queries-test-noodbc-32.xml", name);
+#else
+        return StartNode("queries-test-noodbc.xml", name);
+#endif
+    }
+
+    /**
+     * Constructor.
+     */
+    MetaQueriesTestSuiteFixture() :
+        cache1(0),
+        cache2(0),
+        env(NULL),
+        dbc(NULL),
+        stmt(NULL)
+    {
+#ifdef IGNITE_TESTS_32
+        grid = StartNode("queries-test-32.xml", "NodeMain");
+#else
+        grid = StartNode("queries-test.xml", "NodeMain");
+#endif
+
+        cache1 = grid.GetCache<int64_t, TestType>("cache");
+        cache2 = grid.GetCache<int64_t, ComplexType>("cache2");
+    }
+
+    /**
+     * Destructor.
+     */
+    ~MetaQueriesTestSuiteFixture()
+    {
+        Disconnect();
+
+        Ignition::StopAll(true);
+    }
+
+    /** Node started during the test. */
+    Ignite grid;
+
+    /** Frist cache instance. */
+    Cache<int64_t, TestType> cache1;
+
+    /** Second cache instance. */
+    Cache<int64_t, ComplexType> cache2;
+
+    /** ODBC Environment. */
+    SQLHENV env;
+
+    /** ODBC Connect. */
+    SQLHDBC dbc;
+
+    /** ODBC Statement. */
+    SQLHSTMT stmt;
+};
+
+BOOST_FIXTURE_TEST_SUITE(MetaQueriesTestSuite, MetaQueriesTestSuiteFixture)
+
+BOOST_AUTO_TEST_CASE(TestGetTypeInfoAllTypes)
+{
+    Connect("DRIVER={Apache Ignite};ADDRESS=127.0.0.1:11110;SCHEMA=cache");
+
+    SQLRETURN ret = SQLGetTypeInfo(stmt, SQL_ALL_TYPES);
+
+    if (!SQL_SUCCEEDED(ret))
+        BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
+}
+
+BOOST_AUTO_TEST_SUITE_END()

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b3a9a71/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 b450903..1862465 100644
--- a/modules/platforms/cpp/odbc/src/odbc.cpp
+++ b/modules/platforms/cpp/odbc/src/odbc.cpp
@@ -1019,7 +1019,7 @@ namespace ignite
     {
         using odbc::Statement;
 
-        LOG_MSG("SQLGetTypeInfo called");
+        LOG_MSG("SQLGetTypeInfo called: [type=" << type << ']');
 
         Statement *statement = reinterpret_cast<Statement*>(stmt);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b3a9a71/modules/platforms/cpp/odbc/src/query/type_info_query.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc/src/query/type_info_query.cpp b/modules/platforms/cpp/odbc/src/query/type_info_query.cpp
index 280477b..f6b3990 100644
--- a/modules/platforms/cpp/odbc/src/query/type_info_query.cpp
+++ b/modules/platforms/cpp/odbc/src/query/type_info_query.cpp
@@ -155,7 +155,7 @@ namespace ignite
                 columnsMeta.push_back(ColumnMeta(sch, tbl, "NUM_PREC_RADIX",     IGNITE_TYPE_INT));
                 columnsMeta.push_back(ColumnMeta(sch, tbl, "INTERVAL_PRECISION", IGNITE_TYPE_SHORT));
 
-                assert(IsSqlTypeSupported(sqlType));
+                assert(IsSqlTypeSupported(sqlType) || sqlType == SQL_ALL_TYPES);
 
                 if (sqlType == SQL_ALL_TYPES)
                 {

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b3a9a71/modules/platforms/cpp/odbc/src/statement.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc/src/statement.cpp b/modules/platforms/cpp/odbc/src/statement.cpp
index adc7d6b..38a1e2e 100644
--- a/modules/platforms/cpp/odbc/src/statement.cpp
+++ b/modules/platforms/cpp/odbc/src/statement.cpp
@@ -671,7 +671,7 @@ namespace ignite
 
         SqlResult::Type Statement::InternalExecuteGetTypeInfoQuery(int16_t sqlType)
         {
-            if (!type_traits::IsSqlTypeSupported(sqlType))
+            if (sqlType != SQL_ALL_TYPES && !type_traits::IsSqlTypeSupported(sqlType))
             {
                 std::stringstream builder;
                 builder << "Data type is not supported. [typeId=" << sqlType << ']';