ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject [09/38] ignite git commit: IGNITE-3751: ODBC: Added system functions support. This closes #985.
Date Wed, 31 Aug 2016 06:32:59 GMT
IGNITE-3751: ODBC: Added system functions support. This closes #985.


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

Branch: refs/heads/ignite-3443
Commit: 8aabd6ea65d883d3bbcf37c05c146105dff8a6e2
Parents: e21111f
Author: isapego <igorsapg@gmail.com>
Authored: Thu Aug 25 16:30:20 2016 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Thu Aug 25 16:30:20 2016 +0300

----------------------------------------------------------------------
 modules/platforms/cpp/odbc-test/Makefile.am     |  1 +
 .../include/sql_function_test_suite_fixture.h   | 49 +++++++++++++-
 .../cpp/odbc-test/project/vs/odbc-test.vcxproj  |  1 +
 .../project/vs/odbc-test.vcxproj.filters        |  3 +
 .../src/sql_function_test_suite_fixture.cpp     | 49 ++++++++++++++
 .../odbc-test/src/sql_system_functions_test.cpp | 68 ++++++++++++++++++++
 .../cpp/odbc/src/config/connection_info.cpp     |  2 +-
 7 files changed, 171 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/8aabd6ea/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 6288637..1e00b6f 100644
--- a/modules/platforms/cpp/odbc-test/Makefile.am
+++ b/modules/platforms/cpp/odbc-test/Makefile.am
@@ -66,6 +66,7 @@ ignite_odbc_tests_SOURCES = \
     src/sql_string_functions_test.cpp \
     src/sql_numeric_functions_test.cpp \
     src/sql_aggregate_functions_test.cpp \
+    src/sql_system_functions_test.cpp \
     ../odbc/src/cursor.cpp \
     ../odbc/src/config/connection_info.cpp \
     ../odbc/src/app/application_data_buffer.cpp \

http://git-wip-us.apache.org/repos/asf/ignite/blob/8aabd6ea/modules/platforms/cpp/odbc-test/include/sql_function_test_suite_fixture.h
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc-test/include/sql_function_test_suite_fixture.h b/modules/platforms/cpp/odbc-test/include/sql_function_test_suite_fixture.h
index c09c1ae..eef0a9b 100644
--- a/modules/platforms/cpp/odbc-test/include/sql_function_test_suite_fixture.h
+++ b/modules/platforms/cpp/odbc-test/include/sql_function_test_suite_fixture.h
@@ -78,7 +78,18 @@ namespace ignite
         {
             BOOST_FAIL("Function is not defined for the type.");
         }
-    
+
+        /**
+         * Run query returning single result and check it to be successful.
+         *
+         * @param request SQL request.
+         */
+        template<typename T>
+        void CheckSingleResult(const char* request)
+        {
+            BOOST_FAIL("Function is not defined for the type.");
+        }
+
         /**
          * Run query returning single result and check it to be equal to expected.
          *
@@ -96,6 +107,21 @@ namespace ignite
             BOOST_CHECK_EQUAL(res, expected);
         }
 
+        /**
+         * Run query returning single result and check it to be equal to expected.
+         *
+         * @param request SQL request.
+         * @param expected Expected result.
+         * @param type Result type.
+         */
+        template<typename T>
+        void CheckSingleResultNum0(const char* request, SQLSMALLINT type)
+        {
+            T res = 0;
+
+            CheckSingleResult0(request, type, &res, 0, 0);
+        }
+
 
         /** Node started during the test. */
         Ignite grid;
@@ -133,6 +159,27 @@ namespace ignite
 
     template<>
     void SqlFunctionTestSuiteFixture::CheckSingleResult<double>(const char* request,
const double& expected);
+
+    template<>
+    void SqlFunctionTestSuiteFixture::CheckSingleResult<std::string>(const char* request);
+
+    template<>
+    void SqlFunctionTestSuiteFixture::CheckSingleResult<int64_t>(const char* request);
+
+    template<>
+    void SqlFunctionTestSuiteFixture::CheckSingleResult<int32_t>(const char* request);
+
+    template<>
+    void SqlFunctionTestSuiteFixture::CheckSingleResult<int16_t>(const char* request);
+
+    template<>
+    void SqlFunctionTestSuiteFixture::CheckSingleResult<int8_t>(const char* request);
+
+    template<>
+    void SqlFunctionTestSuiteFixture::CheckSingleResult<float>(const char* request);
+
+    template<>
+    void SqlFunctionTestSuiteFixture::CheckSingleResult<double>(const char* request);
 }
 
 #endif //_IGNITE_ODBC_TEST_SQL_FUNCTION_TEST_FIXTURE

http://git-wip-us.apache.org/repos/asf/ignite/blob/8aabd6ea/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 e0b786a..2a94a2a 100644
--- a/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj
+++ b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj
@@ -172,6 +172,7 @@
     <ClCompile Include="..\..\src\sql_function_test_suite_fixture.cpp" />
     <ClCompile Include="..\..\src\sql_numeric_functions_test.cpp" />
     <ClCompile Include="..\..\src\sql_string_functions_test.cpp" />
+    <ClCompile Include="..\..\src\sql_system_functions_test.cpp" />
     <ClCompile Include="..\..\src\teamcity\teamcity_boost.cpp" />
     <ClCompile Include="..\..\src\teamcity\teamcity_messages.cpp" />
     <ClCompile Include="..\..\src\test_utils.cpp" />

http://git-wip-us.apache.org/repos/asf/ignite/blob/8aabd6ea/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 763a364..9ca51af 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
@@ -91,6 +91,9 @@
     <ClCompile Include="..\..\src\sql_aggregate_functions_test.cpp">
       <Filter>Code</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\sql_system_functions_test.cpp">
+      <Filter>Code</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\include\test_type.h">

http://git-wip-us.apache.org/repos/asf/ignite/blob/8aabd6ea/modules/platforms/cpp/odbc-test/src/sql_function_test_suite_fixture.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc-test/src/sql_function_test_suite_fixture.cpp b/modules/platforms/cpp/odbc-test/src/sql_function_test_suite_fixture.cpp
index 2398393..f848dc5 100644
--- a/modules/platforms/cpp/odbc-test/src/sql_function_test_suite_fixture.cpp
+++ b/modules/platforms/cpp/odbc-test/src/sql_function_test_suite_fixture.cpp
@@ -185,4 +185,53 @@ namespace ignite
 
         BOOST_CHECK_CLOSE(static_cast<double>(res), expected, 1E-6);
     }
+
+    template<>
+    void SqlFunctionTestSuiteFixture::CheckSingleResult<std::string>(const char* request)
+    {
+        SQLCHAR res[ODBC_BUFFER_SIZE] = { 0 };
+        SQLLEN resLen = 0;
+
+        CheckSingleResult0(request, SQL_C_CHAR, res, ODBC_BUFFER_SIZE, &resLen);
+    }
+
+    template<>
+    void SqlFunctionTestSuiteFixture::CheckSingleResult<int64_t>(const char* request)
+    {
+        CheckSingleResultNum0<int64_t>(request, SQL_C_SBIGINT);
+    }
+
+    template<>
+    void SqlFunctionTestSuiteFixture::CheckSingleResult<int32_t>(const char* request)
+    {
+        CheckSingleResultNum0<int32_t>(request, SQL_C_SLONG);
+    }
+
+    template<>
+    void SqlFunctionTestSuiteFixture::CheckSingleResult<int16_t>(const char* request)
+    {
+        CheckSingleResultNum0<int16_t>(request, SQL_C_SSHORT);
+    }
+
+    template<>
+    void SqlFunctionTestSuiteFixture::CheckSingleResult<int8_t>(const char* request)
+    {
+        CheckSingleResultNum0<int8_t>(request, SQL_C_STINYINT);
+    }
+
+    template<>
+    void SqlFunctionTestSuiteFixture::CheckSingleResult<float>(const char* request)
+    {
+        SQLFLOAT res = 0;
+
+        CheckSingleResult0(request, SQL_C_FLOAT, &res, 0, 0);
+    }
+
+    template<>
+    void SqlFunctionTestSuiteFixture::CheckSingleResult<double>(const char* request)
+    {
+        SQLDOUBLE res = 0;
+
+        CheckSingleResult0(request, SQL_C_DOUBLE, &res, 0, 0);
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/8aabd6ea/modules/platforms/cpp/odbc-test/src/sql_system_functions_test.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc-test/src/sql_system_functions_test.cpp b/modules/platforms/cpp/odbc-test/src/sql_system_functions_test.cpp
new file mode 100644
index 0000000..d369b0f
--- /dev/null
+++ b/modules/platforms/cpp/odbc-test/src/sql_system_functions_test.cpp
@@ -0,0 +1,68 @@
+/*
+ * 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>
+
+#ifndef _MSC_VER
+#   define BOOST_TEST_DYN_LINK
+#endif
+
+#include <boost/test/unit_test.hpp>
+
+#include "ignite/ignite.h"
+#include "ignite/ignition.h"
+#include "ignite/impl/binary/binary_utils.h"
+
+#include "test_type.h"
+#include "test_utils.h"
+#include "sql_function_test_suite_fixture.h"
+
+using namespace ignite;
+using namespace ignite::cache;
+using namespace ignite::cache::query;
+using namespace ignite::common;
+
+using namespace boost::unit_test;
+
+using ignite::impl::binary::BinaryUtils;
+
+BOOST_FIXTURE_TEST_SUITE(SqlSystemFunctionTestSuite, ignite::SqlFunctionTestSuiteFixture)
+
+BOOST_AUTO_TEST_CASE(TestSystemFunctionDatabase)
+{
+    CheckSingleResult<std::string>("SELECT {fn DATABASE()}");
+}
+
+BOOST_AUTO_TEST_CASE(TestSystemFunctionUser)
+{
+    CheckSingleResult<std::string>("SELECT {fn USER()}");
+}
+
+BOOST_AUTO_TEST_CASE(TestSystemFunctionIfnull)
+{
+    CheckSingleResult<int32_t>("SELECT {fn IFNULL(NULL, 42)}", 42);
+}
+
+BOOST_AUTO_TEST_SUITE_END()

http://git-wip-us.apache.org/repos/asf/ignite/blob/8aabd6ea/modules/platforms/cpp/odbc/src/config/connection_info.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc/src/config/connection_info.cpp b/modules/platforms/cpp/odbc/src/config/connection_info.cpp
index b2480c2..cff48cf 100644
--- a/modules/platforms/cpp/odbc/src/config/connection_info.cpp
+++ b/modules/platforms/cpp/odbc/src/config/connection_info.cpp
@@ -286,7 +286,7 @@ namespace ignite
 #ifdef SQL_SYSTEM_FUNCTIONS
                 // Bitmask enumerating the scalar system functions supported by the
                 // driver and associated data source.
-                intParams[SQL_SYSTEM_FUNCTIONS] = 0;
+                intParams[SQL_SYSTEM_FUNCTIONS] = SQL_FN_SYS_USERNAME | SQL_FN_SYS_DBNAME
| SQL_FN_SYS_IFNULL;
 #endif // SQL_SYSTEM_FUNCTIONS
 
 #ifdef SQL_CONVERT_FUNCTIONS


Mime
View raw message