IGNITE-3761: ODBC: Added tests for SQL_SQL92_VALUE_EXPRESSIONS. This closes #989.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6fd53ea5 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6fd53ea5 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6fd53ea5 Branch: refs/heads/master Commit: 6fd53ea5b50148e5a1156d83ea28acb8faf84035 Parents: ae0b5eb Author: Igor Sapego <[email protected]> Authored: Fri Aug 26 11:19:39 2016 +0300 Committer: vozerov-gridgain <[email protected]> Committed: Fri Aug 26 11:19:39 2016 +0300 ---------------------------------------------------------------------- modules/platforms/cpp/odbc-test/Makefile.am | 1 + .../cpp/odbc-test/project/vs/odbc-test.vcxproj | 1 + .../project/vs/odbc-test.vcxproj.filters | 3 + .../src/sql_function_test_suite_fixture.cpp | 7 +- .../odbc-test/src/sql_system_functions_test.cpp | 21 ----- .../cpp/odbc-test/src/sql_value_expressions.cpp | 94 ++++++++++++++++++++ modules/platforms/cpp/odbc/src/utility.cpp | 14 +-- 7 files changed, 112 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/6fd53ea5/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 1e00b6f..1f641be 100644 --- a/modules/platforms/cpp/odbc-test/Makefile.am +++ b/modules/platforms/cpp/odbc-test/Makefile.am @@ -67,6 +67,7 @@ ignite_odbc_tests_SOURCES = \ src/sql_numeric_functions_test.cpp \ src/sql_aggregate_functions_test.cpp \ src/sql_system_functions_test.cpp \ + src/sql_value_expressions.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/6fd53ea5/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 2a94a2a..4d3a9cc 100644 --- a/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj +++ b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj @@ -173,6 +173,7 @@ <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\sql_value_expressions.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/6fd53ea5/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 9ca51af..c4d70b7 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 @@ -94,6 +94,9 @@ <ClCompile Include="..\..\src\sql_system_functions_test.cpp"> <Filter>Code</Filter> </ClCompile> + <ClCompile Include="..\..\src\sql_value_expressions.cpp"> + <Filter>Code</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\include\test_type.h"> http://git-wip-us.apache.org/repos/asf/ignite/blob/6fd53ea5/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 f848dc5..4d8b919 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 @@ -139,7 +139,12 @@ namespace ignite CheckSingleResult0(request, SQL_C_CHAR, res, ODBC_BUFFER_SIZE, &resLen); - BOOST_CHECK_EQUAL(std::string(reinterpret_cast<char*>(res), static_cast<size_t>(resLen)), expected); + std::string actual; + + if (resLen > 0) + actual.assign(reinterpret_cast<char*>(res), static_cast<size_t>(resLen)); + + BOOST_CHECK_EQUAL(actual, expected); } template<> http://git-wip-us.apache.org/repos/asf/ignite/blob/6fd53ea5/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 index d369b0f..752925d 100644 --- a/modules/platforms/cpp/odbc-test/src/sql_system_functions_test.cpp +++ b/modules/platforms/cpp/odbc-test/src/sql_system_functions_test.cpp @@ -15,39 +15,18 @@ * 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) http://git-wip-us.apache.org/repos/asf/ignite/blob/6fd53ea5/modules/platforms/cpp/odbc-test/src/sql_value_expressions.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/src/sql_value_expressions.cpp b/modules/platforms/cpp/odbc-test/src/sql_value_expressions.cpp new file mode 100644 index 0000000..e7d6598 --- /dev/null +++ b/modules/platforms/cpp/odbc-test/src/sql_value_expressions.cpp @@ -0,0 +1,94 @@ +/* + * 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 _MSC_VER +# define BOOST_TEST_DYN_LINK +#endif + +#include <boost/test/unit_test.hpp> + +#include "sql_function_test_suite_fixture.h" + +using namespace ignite; + +using namespace boost::unit_test; + +BOOST_FIXTURE_TEST_SUITE(SqlValueExpressionTestSuite, ignite::SqlFunctionTestSuiteFixture) + +BOOST_AUTO_TEST_CASE(TestCase) +{ + TestType in; + + in.i32Field = 82; + + testCache.Put(1, in); + + CheckSingleResult<int32_t>( + "SELECT " + "CASE i32Field WHEN 82 " + "THEN (i32Field / 2) " + "ELSE (i32Field / 3) " + "END " + "FROM TestType", in.i32Field / 2); + + + CheckSingleResult<int32_t>( + "SELECT " + "CASE i32Field WHEN 22 " + "THEN (i32Field / 2) " + "ELSE (i32Field / 3) " + "END " + "FROM TestType", in.i32Field / 3);; +} + +BOOST_AUTO_TEST_CASE(TestCast) +{ + TestType in; + + in.i32Field = 12345; + in.strField = "54321"; + + testCache.Put(1, in); + + CheckSingleResult<int32_t>("SELECT CAST(strField AS INT) + i32Field FROM TestType", + common::LexicalCast<int32_t>(in.strField) + in.i32Field); + + CheckSingleResult<std::string>("SELECT CAST(i32Field AS VARCHAR) || strField FROM TestType", + common::LexicalCast<std::string>(in.i32Field) + in.strField); +} + +BOOST_AUTO_TEST_CASE(TestCoalesce) +{ + CheckSingleResult<std::string>("SELECT COALESCE('One', 'Two', 'Three')", "One"); + CheckSingleResult<std::string>("SELECT COALESCE(NULL, 'Two', 'Three')", "Two"); + CheckSingleResult<std::string>("SELECT COALESCE(NULL, 'Two', NULL)", "Two"); + CheckSingleResult<std::string>("SELECT COALESCE(NULL, NULL, 'Three')", "Three"); +} + +BOOST_AUTO_TEST_CASE(TestNullif) +{ + TestType in; + + in.strField = "SomeValue"; + + testCache.Put(1, in); + + CheckSingleResult<std::string>("SELECT NULLIF(strField, 'blablabla') FROM TestType", in.strField); + CheckSingleResult<std::string>("SELECT NULLIF(strField, 'SomeValue') FROM TestType", ""); +} + +BOOST_AUTO_TEST_SUITE_END() http://git-wip-us.apache.org/repos/asf/ignite/blob/6fd53ea5/modules/platforms/cpp/odbc/src/utility.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/src/utility.cpp b/modules/platforms/cpp/odbc/src/utility.cpp index 133f059..19be799 100644 --- a/modules/platforms/cpp/odbc/src/utility.cpp +++ b/modules/platforms/cpp/odbc/src/utility.cpp @@ -56,19 +56,19 @@ namespace ignite void ReadString(ignite::impl::binary::BinaryReaderImpl& reader, std::string& str) { int32_t strLen = reader.ReadString(0, 0); - if (!strLen) + if (strLen > 0) { - str.clear(); - - char dummy; + str.resize(strLen); - reader.ReadString(&dummy, sizeof(dummy)); + reader.ReadString(&str[0], static_cast<int32_t>(str.size())); } else { - str.resize(strLen); + str.clear(); - reader.ReadString(&str[0], static_cast<int32_t>(str.size())); + char dummy; + + reader.ReadString(&dummy, sizeof(dummy)); } }
