http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc-test/src/teamcity_boost.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/src/teamcity_boost.cpp b/modules/platforms/cpp/odbc-test/src/teamcity_boost.cpp new file mode 100644 index 0000000..45c666d --- /dev/null +++ b/modules/platforms/cpp/odbc-test/src/teamcity_boost.cpp @@ -0,0 +1,159 @@ +/* Copyright 2011 JetBrains s.r.o. + * + * Licensed 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. + * + * $Revision: 88625 $ +*/ + +#define BOOST_TEST_MODULE IgniteCoreTest + +#include <sstream> + +#include <boost/test/unit_test_suite_impl.hpp> +#include <boost/test/results_collector.hpp> +#include <boost/test/utils/basic_cstring/io.hpp> +#include <boost/test/unit_test_log.hpp> +#include <boost/test/included/unit_test.hpp> + +#include "teamcity_messages.h" + +using namespace boost::unit_test; +using namespace std; + +namespace JetBrains { + +// Custom formatter for TeamCity messages +class TeamcityBoostLogFormatter: public boost::unit_test::unit_test_log_formatter { + TeamcityMessages messages; + std::string currentDetails; + std::string flowId; + +public: + TeamcityBoostLogFormatter(const std::string &_flowId); + TeamcityBoostLogFormatter(); + + void log_start(std::ostream&, boost::unit_test::counter_t test_cases_amount); + void log_finish(std::ostream&); + void log_build_info(std::ostream&); + + void test_unit_start(std::ostream&, boost::unit_test::test_unit const& tu); + void test_unit_finish(std::ostream&, + boost::unit_test::test_unit const& tu, + unsigned long elapsed); + void test_unit_skipped(std::ostream&, boost::unit_test::test_unit const& tu); + + void log_exception(std::ostream&, + boost::unit_test::log_checkpoint_data const&, + boost::unit_test::const_string explanation); + + void log_entry_start(std::ostream&, + boost::unit_test::log_entry_data const&, + log_entry_types let); + void log_entry_value(std::ostream&, boost::unit_test::const_string value); + void log_entry_finish(std::ostream&); +}; + +// Fake fixture to register formatter +struct TeamcityFormatterRegistrar { + TeamcityFormatterRegistrar() { + if (JetBrains::underTeamcity()) { + boost::unit_test::unit_test_log.set_formatter(new JetBrains::TeamcityBoostLogFormatter()); + boost::unit_test::unit_test_log.set_threshold_level(boost::unit_test::log_successful_tests); + } + } +}; +BOOST_GLOBAL_FIXTURE(TeamcityFormatterRegistrar); + +// Formatter implementation +string toString(const_string bstr) { + stringstream ss; + + ss << bstr; + + return ss.str(); +} + +TeamcityBoostLogFormatter::TeamcityBoostLogFormatter(const std::string &_flowId) +: flowId(_flowId) +{} + +TeamcityBoostLogFormatter::TeamcityBoostLogFormatter() +: flowId(getFlowIdFromEnvironment()) +{} + +void TeamcityBoostLogFormatter::log_start(ostream &out, counter_t test_cases_amount) +{} + +void TeamcityBoostLogFormatter::log_finish(ostream &out) +{} + +void TeamcityBoostLogFormatter::log_build_info(ostream &out) +{} + +void TeamcityBoostLogFormatter::test_unit_start(ostream &out, test_unit const& tu) { + messages.setOutput(out); + + if (tu.p_type == tut_case) { + messages.testStarted(tu.p_name, flowId); + } else { + messages.suiteStarted(tu.p_name, flowId); + } + + currentDetails.clear(); +} + +void TeamcityBoostLogFormatter::test_unit_finish(ostream &out, test_unit const& tu, unsigned long elapsed) { + messages.setOutput(out); + + test_results const& tr = results_collector.results(tu.p_id); + if (tu.p_type == tut_case) { + if(!tr.passed()) { + if(tr.p_skipped) { + messages.testIgnored(tu.p_name, "ignored", flowId); + } else if (tr.p_aborted) { + messages.testFailed(tu.p_name, "aborted", currentDetails, flowId); + } else { + messages.testFailed(tu.p_name, "failed", currentDetails, flowId); + } + } + + messages.testFinished(tu.p_name, elapsed / 1000, flowId); + } else { + messages.suiteFinished(tu.p_name, flowId); + } +} + +void TeamcityBoostLogFormatter::test_unit_skipped(ostream &out, test_unit const& tu) +{} + +void TeamcityBoostLogFormatter::log_exception(ostream &out, log_checkpoint_data const&, const_string explanation) { + string what = toString(explanation); + + out << what << endl; + currentDetails += what + "\n"; +} + +void TeamcityBoostLogFormatter::log_entry_start(ostream&, log_entry_data const&, log_entry_types let) +{} + +void TeamcityBoostLogFormatter::log_entry_value(ostream &out, const_string value) { + out << value; + currentDetails += toString(value); +} + +void TeamcityBoostLogFormatter::log_entry_finish(ostream &out) { + out << endl; + currentDetails += "\n"; +} + +}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc-test/src/teamcity_messages.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/src/teamcity_messages.cpp b/modules/platforms/cpp/odbc-test/src/teamcity_messages.cpp new file mode 100644 index 0000000..087409e --- /dev/null +++ b/modules/platforms/cpp/odbc-test/src/teamcity_messages.cpp @@ -0,0 +1,150 @@ +/* Copyright 2011 JetBrains s.r.o. + * + * Licensed 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. + * + * $Revision: 88625 $ +*/ + +#include <stdlib.h> +#include <sstream> + +#include "teamcity_messages.h" + +using namespace std; + +namespace JetBrains { + +std::string getFlowIdFromEnvironment() { + const char *flowId = getenv("TEAMCITY_PROCESS_FLOW_ID"); + return flowId == NULL ? "" : flowId; +} + +bool underTeamcity() { + return getenv("TEAMCITY_PROJECT_NAME") != NULL; +} + +TeamcityMessages::TeamcityMessages() +: m_out(&cout) +{} + +void TeamcityMessages::setOutput(ostream &out) { + m_out = &out; +} + +string TeamcityMessages::escape(string s) { + string result; + + for (size_t i = 0; i < s.length(); i++) { + char c = s[i]; + + switch (c) { + case '\n': result.append("|n"); break; + case '\r': result.append("|r"); break; + case '\'': result.append("|'"); break; + case '|': result.append("||"); break; + case ']': result.append("|]"); break; + default: result.append(&c, 1); + } + } + + return result; +} + +void TeamcityMessages::openMsg(const string &name) { + // endl for http://jetbrains.net/tracker/issue/TW-4412 + *m_out << endl << "##teamcity[" << name; +} + +void TeamcityMessages::closeMsg() { + *m_out << "]"; + // endl for http://jetbrains.net/tracker/issue/TW-4412 + *m_out << endl; + m_out->flush(); +} + +void TeamcityMessages::writeProperty(string name, string value) { + *m_out << " " << name << "='" << escape(value) << "'"; +} + +void TeamcityMessages::suiteStarted(string name, string flowid) { + openMsg("testSuiteStarted"); + writeProperty("name", name); + if(flowid.length() > 0) { + writeProperty("flowId", flowid); + } + + closeMsg(); +} + +void TeamcityMessages::suiteFinished(string name, string flowid) { + openMsg("testSuiteFinished"); + writeProperty("name", name); + if(flowid.length() > 0) { + writeProperty("flowId", flowid); + } + + closeMsg(); +} + +void TeamcityMessages::testStarted(string name, string flowid) { + openMsg("testStarted"); + writeProperty("name", name); + if(flowid.length() > 0) { + writeProperty("flowId", flowid); + } + + closeMsg(); +} + +void TeamcityMessages::testFinished(string name, int durationMs, string flowid) { + openMsg("testFinished"); + + writeProperty("name", name); + + if(flowid.length() > 0) { + writeProperty("flowId", flowid); + } + + if(durationMs >= 0) { + stringstream out; + out << durationMs; + writeProperty("duration", out.str()); + } + + closeMsg(); +} + +void TeamcityMessages::testFailed(string name, string message, string details, string flowid) { + openMsg("testFailed"); + writeProperty("name", name); + writeProperty("message", message); + writeProperty("details", details); + if(flowid.length() > 0) { + writeProperty("flowId", flowid); + } + + closeMsg(); +} + +void TeamcityMessages::testIgnored(std::string name, std::string message, string flowid) { + openMsg("testIgnored"); + writeProperty("name", name); + writeProperty("message", message); + if(flowid.length() > 0) { + writeProperty("flowId", flowid); + } + + closeMsg(); +} + +} http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc-test/src/utility_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/src/utility_test.cpp b/modules/platforms/cpp/odbc-test/src/utility_test.cpp new file mode 100644 index 0000000..6c4d104 --- /dev/null +++ b/modules/platforms/cpp/odbc-test/src/utility_test.cpp @@ -0,0 +1,81 @@ +/* + * 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 <ignite/impl/binary/binary_writer_impl.h> + +#include <ignite/odbc/utility.h> + +using namespace ignite::utility; + +BOOST_AUTO_TEST_SUITE(UtilityTestSuite) + +BOOST_AUTO_TEST_CASE(TestUtilityRemoveSurroundingSpaces) +{ + std::string inStr(" \r \n \t some meaningfull data \n\n \t \r "); + std::string expectedOutStr("some meaningfull data"); + + std::string realOutStr(RemoveSurroundingSpaces(inStr.begin(), inStr.end())); + + BOOST_REQUIRE(expectedOutStr == realOutStr); +} + +BOOST_AUTO_TEST_CASE(TestUtilityCopyStringToBuffer) +{ + char buffer[1024]; + + std::string str("Some data. And some more data here."); + + CopyStringToBuffer(str, buffer, sizeof(buffer)); + + BOOST_REQUIRE(!strcmp(buffer, str.c_str())); + + CopyStringToBuffer(str, buffer, 11); + + BOOST_REQUIRE(!strcmp(buffer, str.substr(0, 10).c_str())); +} + +BOOST_AUTO_TEST_CASE(TestUtilityReadString) +{ + using namespace ignite::impl::binary; + using namespace ignite::impl::interop; + + std::string inputStr("Hello World!"); + std::string outputStr; + + ignite::impl::interop::InteropUnpooledMemory mem(1024); + InteropOutputStream outStream(&mem); + BinaryWriterImpl writer(&outStream, 0); + + writer.WriteString(inputStr.data(), static_cast<int32_t>(inputStr.size())); + + outStream.Synchronize(); + + InteropInputStream inStream(&mem); + BinaryReaderImpl reader(&inStream); + + ReadString(reader, outputStr); + + BOOST_REQUIRE(inputStr == outputStr); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/Makefile.am b/modules/platforms/cpp/odbc/Makefile.am new file mode 100644 index 0000000..09f35fd --- /dev/null +++ b/modules/platforms/cpp/odbc/Makefile.am @@ -0,0 +1,67 @@ +## +## 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. +## + +ACLOCAL_AMFLAGS = "-Im4" + +SUBDIRS = . +DIST_SUBDIRS = . + +AM_CPPFLAGS = -I$(srcdir)/include -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -DIGNITE_IMPL +AM_CXXFLAGS = -Wall -std=c++0x +LIB_LDFLAGS = -no-undefined -version-info 1 + +COMMON_SRC = os/linux/src/system/socket_client.cpp \ + src/app/application_data_buffer.cpp \ + src/app/parameter.cpp \ + src/common_types.cpp \ + src/config/configuration.cpp \ + src/config/connection_info.cpp \ + src/connection.cpp \ + src/cursor.cpp \ + src/decimal.cpp \ + src/diagnostic/diagnosable_adapter.cpp \ + src/diagnostic/diagnostic_record.cpp \ + src/diagnostic/diagnostic_record_storage.cpp \ + src/environment.cpp \ + src/meta/column_meta.cpp \ + src/meta/table_meta.cpp \ + src/odbc.cpp \ + src/query/column_metadata_query.cpp \ + src/query/data_query.cpp \ + src/query/foreign_keys_query.cpp \ + src/query/primary_keys_query.cpp \ + src/query/table_metadata_query.cpp \ + src/query/type_info_query.cpp \ + src/result_page.cpp \ + src/row.cpp \ + src/statement.cpp \ + src/type_traits.cpp \ + src/utility.cpp + + +lib_LTLIBRARIES = libignite-odbc.la +libignite_odbc_la_SOURCES = $(COMMON_SRC) +libignite_odbc_la_LDFLAGS = $(LIB_LDFLAGS) -L/usr/local/lib -lignite-common -lignite-binary -ldl -version-info 0:0:0 -release $(PACKAGE_VERSION) + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = ignite-odbc.pc + +clean-local: + $(RM) *.gcno *.gcda + +clean-docs: + $(RM) $(DX_CLEANFILES) http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc/configure.ac ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/configure.ac b/modules/platforms/cpp/odbc/configure.ac new file mode 100644 index 0000000..e69d73c --- /dev/null +++ b/modules/platforms/cpp/odbc/configure.ac @@ -0,0 +1,62 @@ +# +# 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. +# + +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ([2.69]) +AC_INIT([Apache Ignite ODBC driver], [1.5.1.7927], [[email protected]], [ignite], [ignite.apache.org]) +AC_CONFIG_SRCDIR(src) + +AC_CANONICAL_SYSTEM +AC_CONFIG_MACRO_DIR([m4]) +AC_LANG([C++]) + +# Initialize automake +AM_INIT_AUTOMAKE([-Wall foreign subdir-objects]) +AC_CONFIG_HEADER(config.h) + +AM_PROG_AR + +# Checks for programs. +GXX="-g -O2" + +AC_PROG_CXX + +# Initialize Libtool +LT_INIT + +# Checks for libraries. +AC_CHECK_LIB([pthread], [pthread_mutex_lock]) + +# Checks for header files. + +# Checks for typedefs, structures, and compiler characteristics. +AC_C_INLINE +AC_TYPE_INT16_T +AC_TYPE_INT32_T +AC_TYPE_INT64_T +AC_TYPE_INT8_T +AC_TYPE_PID_T +AC_TYPE_SIZE_T + +# Checks for library functions. +AC_FUNC_ERROR_AT_LINE + +AC_CONFIG_FILES(Makefile ignite-odbc.pc) + +AC_OUTPUT http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc/ignite-odbc.pc.in ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/ignite-odbc.pc.in b/modules/platforms/cpp/odbc/ignite-odbc.pc.in new file mode 100644 index 0000000..13cd7e9 --- /dev/null +++ b/modules/platforms/cpp/odbc/ignite-odbc.pc.in @@ -0,0 +1,9 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: ignite-odbc +Description: Apache Ignite ODBC driver. +Version: @PACKAGE_VERSION@ +Libs: -L${libdir} -lignite-odbc http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc/include/ignite/odbc/app/application_data_buffer.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/app/application_data_buffer.h b/modules/platforms/cpp/odbc/include/ignite/odbc/app/application_data_buffer.h new file mode 100644 index 0000000..051f459 --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/app/application_data_buffer.h @@ -0,0 +1,342 @@ +/* + * 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_DRIVER_APPLICATION_DATA_BUFFER +#define _IGNITE_ODBC_DRIVER_APPLICATION_DATA_BUFFER + +#include <stdint.h> + +#include <map> + +#include <ignite/guid.h> + +#include "ignite/odbc/decimal.h" +#include "ignite/odbc/common_types.h" +#include "ignite/odbc/type_traits.h" + +namespace ignite +{ + namespace odbc + { + namespace app + { + /** + * User application data buffer. + */ + class ApplicationDataBuffer + { + public: + /** + * Default constructor. + */ + ApplicationDataBuffer(); + + /** + * Constructor. + * + * @param type Underlying data type. + * @param buffer Data buffer pointer. + * @param buflen Data buffer length. + * @param reslen Resulting data length. + * @param offset Pointer to buffer and reslen offset pointer. + */ + ApplicationDataBuffer(type_traits::IgniteSqlType type, void* buffer, SqlLen buflen, SqlLen* reslen, size_t** offset = 0); + + /** + * Copy constructor. + * + * @param other Other instance. + */ + ApplicationDataBuffer(const ApplicationDataBuffer& other); + + /** + * Destructor. + */ + ~ApplicationDataBuffer(); + + /** + * Copy assigment operator. + * + * @param other Other instance. + * @return This. + */ + ApplicationDataBuffer& operator=(const ApplicationDataBuffer& other); + + /** + * Set pointer to offset pointer. + * + * @param offset Pointer to offset pointer. + */ + void SetPtrToOffsetPtr(size_t** offset) + { + this->offset = offset; + } + + /** + * Put in buffer value of type int8_t. + * + * @param value Value. + */ + void PutInt8(int8_t value); + + /** + * Put in buffer value of type int16_t. + * + * @param value Value. + */ + void PutInt16(int16_t value); + + /** + * Put in buffer value of type int32_t. + * + * @param value Value. + */ + void PutInt32(int32_t value); + + /** + * Put in buffer value of type int64_t. + * + * @param value Value. + */ + void PutInt64(int64_t value); + + /** + * Put in buffer value of type float. + * + * @param value Value. + */ + void PutFloat(float value); + + /** + * Put in buffer value of type double. + * + * @param value Value. + */ + void PutDouble(double value); + + /** + * Put in buffer value of type string. + * + * @param value Value. + * @return Number of bytes that have been put in buffer. + */ + int32_t PutString(const std::string& value); + + /** + * Put in buffer value of type GUID. + * + * @param value Value. + */ + void PutGuid(const Guid& value); + + /** + * Put binary data in buffer. + * + * @param data Data pointer. + * @param len Data length. + * @return Number of bytes that have been put in buffer. + */ + int32_t PutBinaryData(void* data, size_t len); + + /** + * Put NULL. + */ + void PutNull(); + + /** + * Put decimal value to buffer. + * + * @param value Value to put. + */ + void PutDecimal(const Decimal& value); + + /** + * Get string. + * + * @return String value of buffer. + */ + std::string GetString(size_t maxLen) const; + + /** + * Get value of type int8_t. + * + * @return Integer value of type int8_t. + */ + int8_t GetInt8() const; + + /** + * Get value of type int16_t. + * + * @return Integer value of type int16_t. + */ + int16_t GetInt16() const; + + /** + * Get value of type int32_t. + * + * @return Integer value of type int32_t. + */ + int32_t GetInt32() const; + + /** + * Get value of type int64_t. + * + * @return Integer value of type int64_t. + */ + int64_t GetInt64() const; + + /** + * Get value of type float. + * + * @return Integer value of type float. + */ + float GetFloat() const; + + /** + * Get value of type double. + * + * @return Integer value of type double. + */ + double GetDouble() const; + + /** + * Get raw data. + * + * @return Buffer data. + */ + const void* GetData() const; + + /** + * Get result data length. + * + * @return Data length pointer. + */ + const SqlLen* GetResLen() const; + + /** + * Get buffer size in bytes. + * + * @return Buffer size. + */ + SqlLen GetSize() const + { + return buflen; + } + + private: + /** + * Get raw data. + * + * @return Buffer data. + */ + void* GetData(); + + /** + * Get result data length. + * + * @return Data length pointer. + */ + SqlLen* GetResLen(); + + /** + * Put value of numeric type in the buffer. + * + * @param value Numeric value to put. + */ + template<typename T> + void PutNum(T value); + + /** + * Put numeric value to numeric buffer. + * + * @param value Numeric value. + */ + template<typename Tbuf, typename Tin> + void PutNumToNumBuffer(Tin value); + + /** + * Put value to string buffer. + * + * @param value Value that can be converted to string. + */ + template<typename CharT, typename Tin> + void PutValToStrBuffer(const Tin& value); + + /** + * Put value to string buffer. + * Specialisation for int8_t. + * @param value Value that can be converted to string. + */ + template<typename CharT> + void PutValToStrBuffer(const int8_t & value); + + /** + * Put string to string buffer. + * + * @param value String value. + */ + template<typename OutCharT, typename InCharT> + void PutStrToStrBuffer(const std::basic_string<InCharT>& value); + + /** + * Put raw data to any buffer. + * + * @param data Data pointer. + * @param len Data length. + */ + void PutRawDataToBuffer(void *data, size_t len); + + /** + * Get int of type T. + * + * @return Integer value of specified type. + */ + template<typename T> + T GetNum() const; + + /** + * Apply buffer offset to pointer. + * Adds offset to pointer if offset pointer is not null. + * @param ptr Pointer. + * @return Pointer with applied offset. + */ + template<typename T> + T* ApplyOffset(T* ptr) const; + + /** Underlying data type. */ + type_traits::IgniteSqlType type; + + /** Buffer pointer. */ + void* buffer; + + /** Buffer length. */ + SqlLen buflen; + + /** Result length. */ + SqlLen* reslen; + + /** Pointer to implementation pointer to application offset */ + size_t** offset; + }; + + /** Column binging map type alias. */ + typedef std::map<uint16_t, ApplicationDataBuffer> ColumnBindingMap; + } + } +} + +#endif \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc/include/ignite/odbc/app/parameter.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/app/parameter.h b/modules/platforms/cpp/odbc/include/ignite/odbc/app/parameter.h new file mode 100644 index 0000000..8756f48 --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/app/parameter.h @@ -0,0 +1,113 @@ +/* + * 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_DRIVER_APP_PARAMETER +#define _IGNITE_ODBC_DRIVER_APP_PARAMETER + +#include <stdint.h> + +#include <map> + +#include <ignite/guid.h> +#include <ignite/impl/binary/binary_writer_impl.h> +#include <ignite/impl/binary/binary_reader_impl.h> + +#include "ignite/odbc/app/application_data_buffer.h" +#include "ignite/odbc/type_traits.h" + +namespace ignite +{ + namespace odbc + { + namespace app + { + /** + * Statement parameter. + */ + class Parameter + { + public: + /** + * Default constructor. + */ + Parameter(); + + /** + * Constructor. + * + * @param buffer Underlying data buffer. + * @param sqlType IPD type. + * @param columnSize IPD column size. + * @param decDigits IPD decimal digits. + */ + Parameter(const ApplicationDataBuffer& buffer, int16_t sqlType, + size_t columnSize, int16_t decDigits); + + /** + * Copy constructor. + * + * @param other Other instance. + */ + Parameter(const Parameter& other); + + /** + * Destructor. + */ + ~Parameter(); + + /** + * Copy assigment operator. + * + * @param other Other instance. + * @return This. + */ + Parameter& operator=(const Parameter& other); + + /** + * Write request using provided writer. + * @param writer Writer. + */ + void Write(ignite::impl::binary::BinaryWriterImpl& writer) const; + + /** + * Get data buffer. + * + * @return underlying ApplicationDataBuffer instance. + */ + ApplicationDataBuffer& GetBuffer(); + + private: + /** Underlying data buffer. */ + ApplicationDataBuffer buffer; + + /** IPD type. */ + int16_t sqlType; + + /** IPD column size. */ + size_t columnSize; + + /** IPD decimal digits. */ + int16_t decDigits; + }; + + /** Parameter binging map type alias. */ + typedef std::map<uint16_t, Parameter> ParameterBindingMap; + } + } +} + +#endif \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc/include/ignite/odbc/column.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/column.h b/modules/platforms/cpp/odbc/include/ignite/odbc/column.h new file mode 100644 index 0000000..dc0b6d9 --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/column.h @@ -0,0 +1,149 @@ +/* + * 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_DRIVER_COLUMN +#define _IGNITE_ODBC_DRIVER_COLUMN + +#include <stdint.h> + +#include <ignite/impl/binary/binary_reader_impl.h> + +#include "ignite/odbc/app/application_data_buffer.h" + +namespace ignite +{ + namespace odbc + { + /** + * Result set column. + */ + class Column + { + public: + /** + * Default constructor. + */ + Column(); + + /** + * Copy constructor. + * + * @param other Another instance. + */ + Column(const Column& other); + + /** + * Copy operator. + * + * @param other Another instance. + * @return This. + */ + Column& operator=(const Column& other); + + /** + * Destructor. + */ + ~Column(); + + /** + * Constructor. + * + * @param reader Reader to be used to retrieve column data. + */ + Column(ignite::impl::binary::BinaryReaderImpl& reader); + + /** + * Get column size in bytes. + * + * @return Column size. + */ + int32_t GetSize() const + { + return size; + } + + /** + * Read column data and store it in application data buffer. + * + * @param dataBuf Application data buffer. + * @return Operation result. + */ + SqlResult ReadToBuffer(ignite::impl::binary::BinaryReaderImpl& reader, + app::ApplicationDataBuffer& dataBuf); + + /** + * Check if the column is in valid state. + * + * @return True if valid. + */ + bool IsValid() const + { + return startPos >= 0; + } + + /** + * Get unread data length. + * Find out how many bytes of data are left unread. + * + * @return Lengh of unread data in bytes. + */ + int32_t GetUnreadDataLength() const + { + return size - offset; + } + + /** + * Get unread data length. + * Find out how many bytes of data are left unread. + * + * @return Lengh of unread data in bytes. + */ + int32_t GetEndPosition() const + { + return endPos; + } + + private: + /** + * Increase offset. + * + * Increases offset on specified value and makes sure resulting + * offset does not exceed column size. + * + * @param value Offset is incremented on this value. + */ + void IncreaseOffset(int32_t value); + + /** Column type */ + int8_t type; + + /** Column position in current row. */ + int32_t startPos; + + /** Column end position in current row. */ + int32_t endPos; + + /** Current offset in column. */ + int32_t offset; + + /** Column data size in bytes. */ + int32_t size; + }; + } +} + +#endif \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc/include/ignite/odbc/common_types.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/common_types.h b/modules/platforms/cpp/odbc/include/ignite/odbc/common_types.h new file mode 100644 index 0000000..8e1dbf2 --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/common_types.h @@ -0,0 +1,225 @@ +/* + * 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_DRIVER_COMMON_TYPES +#define _IGNITE_ODBC_DRIVER_COMMON_TYPES + +#include <stdint.h> + +namespace ignite +{ + namespace odbc + { + +#ifdef _WIN64 + typedef long long SqlLen; +#else + typedef long SqlLen; +#endif + + /** + * SQL result. + */ + enum SqlResult + { + /** Success. */ + SQL_RESULT_SUCCESS, + + /** Success with info. */ + SQL_RESULT_SUCCESS_WITH_INFO, + + /** Error. */ + SQL_RESULT_ERROR, + + /** No more data. */ + SQL_RESULT_NO_DATA + }; + + /** + * Provides detailed information about the cause of a warning or error. + */ + enum SqlState + { + /** Undefined state. Internal, should never be exposed to user. */ + SQL_STATE_UNKNOWN, + + /** Output data has been truncated. */ + SQL_STATE_01004_DATA_TRUNCATED, + + /** Error in row. */ + SQL_STATE_01S01_ERROR_IN_ROW, + + /** + * The driver did not support the specified value and + * substituted a similar value. + */ + SQL_STATE_01S02_OPTION_VALUE_CHANGED, + + /** Invalid cursor state. */ + SQL_STATE_24000_INVALID_CURSOR_STATE, + + /** + * The driver was unable to establish a connection with the data + * source. + */ + SQL_STATE_08001_CANNOT_CONNECT, + + /** + * The specified ConnectionHandle had already been used + * to establish a connection with a data source, and the connection + * was still open. + */ + SQL_STATE_08002_ALREADY_CONNECTED, + + /** The connection specified was not open. */ + SQL_STATE_08003_NOT_CONNECTED, + + /** + * An error occurred for which there was no specific SQLSTATE + * and for which no implementation-specific SQLSTATE was defined. + */ + SQL_STATE_HY000_GENERAL_ERROR, + + /** + * The driver was unable to allocate memory for the specified + * handle. + */ + SQL_STATE_HY001_MEMORY_ALLOCATION, + + /** Function sequence error. */ + SQL_STATE_HY010_SEQUENCE_ERROR, + + /** Column type out of range. */ + SQL_STATE_HY097_COLUMN_TYPE_OUT_OF_RANGE, + + /** + * The driver does not support the feature of ODBC behavior that + * the application requested. + */ + SQL_STATE_HYC00_OPTIONAL_FEATURE_NOT_IMPLEMENTED, + + /** + * The connection timeout period expired before the data source + * responded to the request. + */ + SQL_STATE_HYT01_CONNECTIOIN_TIMEOUT + }; + + /** + * Diagnostic field type. + */ + enum DiagnosticField + { + /** Field type is unknown to the driver. */ + IGNITE_SQL_DIAG_UNKNOWN, + + /** Header record field: Count of rows in the cursor. */ + IGNITE_SQL_DIAG_HEADER_CURSOR_ROW_COUNT, + + /** + * Header record field: String that describes the SQL statement + * that the underlying function executed. + */ + IGNITE_SQL_DIAG_HEADER_DYNAMIC_FUNCTION, + + /** + * Header record field: Numeric code that describes the SQL + * statement that was executed by the underlying function. + */ + IGNITE_SQL_DIAG_HEADER_DYNAMIC_FUNCTION_CODE, + + /** Header record field: Number of status records. */ + IGNITE_SQL_DIAG_HEADER_NUMBER, + + /** Header record field: Last operation return code. */ + IGNITE_SQL_DIAG_HEADER_RETURNCODE, + + /** Header record field: Row count. */ + IGNITE_SQL_DIAG_HEADER_ROW_COUNT, + + /** Status record field: Class origin. */ + IGNITE_SQL_DIAG_STATUS_CLASS_ORIGIN, + + /** Status record field: Column number. */ + IGNITE_SQL_DIAG_STATUS_COLUMN_NUMBER, + + /** Status record field: Connection name. */ + IGNITE_SQL_DIAG_STATUS_CONNECTION_NAME, + + /** Status record field: Message text. */ + IGNITE_SQL_DIAG_STATUS_MESSAGE_TEXT, + + /** Status record field: Native result code. */ + IGNITE_SQL_DIAG_STATUS_NATIVE, + + /** Status record field: Row number. */ + IGNITE_SQL_DIAG_STATUS_ROW_NUMBER, + + /** Status record field: Server name. */ + IGNITE_SQL_DIAG_STATUS_SERVER_NAME, + + /** Status record field: SQLSTATE. */ + IGNITE_SQL_DIAG_STATUS_SQLSTATE, + + /** Status record field: Subclass origin. */ + IGNITE_SQL_DIAG_STATUS_SUBCLASS_ORIGIN + }; + + /** + * Environment attribute. + */ + enum EnvironmentAttribute + { + /** ODBC attribute is unknown to the driver. */ + IGNITE_SQL_ENV_ATTR_UNKNOWN, + + /** ODBC version. */ + IGNITE_SQL_ENV_ATTR_ODBC_VERSION, + + /** Null-termination of strings. */ + IGNITE_SQL_ENV_ATTR_OUTPUT_NTS + }; + + /** + * Convert internal Ignite type into ODBC SQL return code. + * + * @param result Internal result type. + * @return ODBC result type. + */ + int SqlResultToReturnCode(SqlResult result); + + /** + * Convert ODBC field type to internal DiagnosticField type value. + * + * @param field ODBC field type. + * @return Internal DiagnosticField type value. + */ + DiagnosticField DiagnosticFieldToInternal(int16_t field); + + /** + * Convert environment attribute to internal EnvironmentAttribute type value. + * + * @param attr Environment attribute. + * @return Internal EnvironmentAttribute type value. + */ + EnvironmentAttribute EnvironmentAttributeToInternal(int32_t attr); + + + } +} + +#endif \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc/include/ignite/odbc/config/configuration.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/config/configuration.h b/modules/platforms/cpp/odbc/include/ignite/odbc/config/configuration.h new file mode 100644 index 0000000..f85a5de --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/config/configuration.h @@ -0,0 +1,164 @@ +/* + * 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_DRIVER_CONFIGURATION +#define _IGNITE_ODBC_DRIVER_CONFIGURATION + +#include <stdint.h> +#include <string> +#include <map> + +#include <ignite/common/common.h> + +namespace ignite +{ + namespace odbc + { + namespace config + { + /** + * ODBC configuration abstraction. + */ + class Configuration + { + public: + /** + * Default constructor. + */ + Configuration(); + + /** + * Destructor. + */ + ~Configuration(); + + /** + * Fill configuration data using connection string. + * + * @param str Pointer to string data. + * @param len String length. + */ + void FillFromConnectString(const char* str, size_t len); + + /** + * Fill configuration data using connection string. + * + * @param str Connect string. + */ + void FillFromConnectString(const std::string& str); + + /** + * Convert configure to connect string. + * + * @return Connect string. + */ + std::string ToConnectString() const; + + /** + * Fill configuration data using config attributes string. + * + * @param str Pointer to list of zero-terminated strings. + * Terminated by two zero bytes. + */ + void FillFromConfigAttributes(const char* attributes); + + /** + * Get server port. + * + * @return Server port. + */ + uint16_t GetPort() const + { + return port; + } + + /** + * Get DSN. + * + * @return Data Source Name. + */ + const std::string& GetDsn() const + { + return dsn; + } + + /** + * Get Driver. + * + * @return Driver name. + */ + const std::string& GetDriver() const + { + return driver; + } + + /** + * Get server host. + * + * @return Server host. + */ + const std::string& GetHost() const + { + return host; + } + + /** + * Get cache. + * + * @return Cache name. + */ + const std::string& GetCache() const + { + return cache; + } + + private: + IGNITE_NO_COPY_ASSIGNMENT(Configuration); + + /** Map containing connect arguments. */ + typedef std::map<std::string, std::string> ArgumentMap; + + /** + * Parse connect string into key-value storage. + * + * @param str String to parse. + * @param len String length. + * @param params Parsing result. + */ + void ParseAttributeList(const char* str, size_t len, char delimeter, ArgumentMap& args) const; + + /** Data Source Name. */ + std::string dsn; + + /** Driver name. */ + std::string driver; + + /** Server hostname. */ + std::string host; + + /** Port of the server. */ + uint16_t port; + + /** Cache name. */ + std::string cache; + }; + } + + } +} + +#endif \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc/include/ignite/odbc/config/connection_info.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/config/connection_info.h b/modules/platforms/cpp/odbc/include/ignite/odbc/config/connection_info.h new file mode 100644 index 0000000..7f2738c --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/config/connection_info.h @@ -0,0 +1,98 @@ +/* + * 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_DRIVER_CONNECTION_INFO +#define _IGNITE_ODBC_DRIVER_CONNECTION_INFO + +#include <stdint.h> + +#include <map> + +#include <ignite/common/common.h> +#include <ignite/odbc/common_types.h> + +namespace ignite +{ + namespace odbc + { + namespace config + { + /** + * Connection info. + */ + class ConnectionInfo + { + public: + /** Info type. */ + typedef unsigned short InfoType; + +#ifdef ODBC_DEBUG + /** + * Convert type to string containing its name. + * Debug function. + * @param type Info type. + * @return Null-terminated string containing types name. + */ + static const char* InfoTypeToString(InfoType type); +#endif + + /** + * Constructor. + */ + ConnectionInfo(); + + /** + * Destructor. + */ + ~ConnectionInfo(); + + /** + * Get info of any type. + * @param type Info type. + * @param buf Result buffer pointer. + * @param buflen Result buffer length. + * @param reslen Result value length pointer. + * @return True on success. + */ + SqlResult GetInfo(InfoType type, void* buf, short buflen, short* reslen) const; + + private: + IGNITE_NO_COPY_ASSIGNMENT(ConnectionInfo); + + /** Associative array of string parameters. */ + typedef std::map<InfoType, std::string> StringInfoMap; + + /** Associative array of unsigned integer parameters. */ + typedef std::map<InfoType, unsigned int> UintInfoMap; + + /** Associative array of unsigned short parameters. */ + typedef std::map<InfoType, unsigned short> UshortInfoMap; + + /** String parameters. */ + StringInfoMap strParams; + + /** Integer parameters. */ + UintInfoMap intParams; + + /** Short parameters. */ + UshortInfoMap shortParams; + }; + } + } +} + +#endif \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc/include/ignite/odbc/connection.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/connection.h b/modules/platforms/cpp/odbc/include/ignite/odbc/connection.h new file mode 100644 index 0000000..56037f5 --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/connection.h @@ -0,0 +1,258 @@ +/* + * 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_DRIVER_CONNECTION +#define _IGNITE_ODBC_DRIVER_CONNECTION + +#include <stdint.h> + +#include <vector> + +#include "ignite/odbc/parser.h" +#include "ignite/odbc/system/socket_client.h" +#include "ignite/odbc/config/connection_info.h" +#include "ignite/odbc/diagnostic/diagnosable_adapter.h" + +namespace ignite +{ + namespace odbc + { + class Statement; + + /** + * ODBC node connection. + */ + class Connection : public diagnostic::DiagnosableAdapter + { + friend class Environment; + public: + /** + * Destructor. + */ + ~Connection(); + + /** + * Get connection info. + * + * @return Connection info. + */ + const config::ConnectionInfo& GetInfo() const; + + /** + * Get info of any type. + * + * @param type Info type. + * @param buf Result buffer pointer. + * @param buflen Result buffer length. + * @param reslen Result value length pointer. + */ + void GetInfo(config::ConnectionInfo::InfoType type, void* buf, short buflen, short* reslen); + + /** + * Establish connection to ODBC server. + * + * @param server Server (DSN). + */ + void Establish(const std::string& server); + + /** + * Establish connection to ODBC server. + * + * @param host Host. + * @param port Port. + * @param cache Cache name to connect to. + */ + void Establish(const std::string& host, uint16_t port, const std::string& cache); + + /** + * Release established connection. + * + * @return Operation result. + */ + void Release(); + + /** + * Create statement associated with the connection. + * + * @return Pointer to valid instance on success and NULL on failure. + */ + Statement* CreateStatement(); + + /** + * Send data by established connection. + * + * @param data Data buffer. + * @param len Data length. + * @return True on success. + */ + bool Send(const int8_t* data, size_t len); + + /** + * Receive next message. + * + * @param msg Buffer for message. + * @return True on success. + */ + bool Receive(std::vector<int8_t>& msg); + + /** + * Get name of the assotiated cache. + * + * @return Cache name. + */ + const std::string& GetCache() const; + + /** + * Create diagnostic record associated with the Connection instance. + * + * @param sqlState SQL state. + * @param message Message. + * @param rowNum Associated row number. + * @param columnNum Associated column number. + * @return DiagnosticRecord associated with the instance. + */ + diagnostic::DiagnosticRecord CreateStatusRecord(SqlState sqlState, + const std::string& message, int32_t rowNum = 0, int32_t columnNum = 0) const; + + /** + * Synchronously send request message and receive response. + * + * @param req Request message. + * @param rsp Response message. + * @return True on success. + */ + template<typename ReqT, typename RspT> + bool SyncMessage(const ReqT& req, RspT& rsp) + { + std::vector<int8_t> tempBuffer; + + parser.Encode(req, tempBuffer); + + bool requestSent = Send(tempBuffer.data(), tempBuffer.size()); + + if (!requestSent) + return false; + + bool responseReceived = Receive(tempBuffer); + + if (!responseReceived) + return false; + + parser.Decode(rsp, tempBuffer); + + return true; + } + + /** + * Perform transaction commit. + */ + void TransactionCommit(); + + /** + * Perform transaction rollback. + */ + void TransactionRollback(); + + private: + IGNITE_NO_COPY_ASSIGNMENT(Connection); + + /** + * Establish connection to ODBC server. + * Internal call. + * + * @param server Server (DNS). + * @return Operation result. + */ + SqlResult InternalEstablish(const std::string& server); + + /** + * Establish connection to ODBC server. + * Internal call. + * + * @param host Host. + * @param port Port. + * @param cache Cache name to connect to. + * @return Operation result. + */ + SqlResult InternalEstablish(const std::string& host, uint16_t port, const std::string& cache); + + /** + * Release established connection. + * Internal call. + * + * @return Operation result. + */ + SqlResult InternalRelease(); + + /** + * Get info of any type. + * Internal call. + * + * @param type Info type. + * @param buf Result buffer pointer. + * @param buflen Result buffer length. + * @param reslen Result value length pointer. + * @return Operation result. + */ + SqlResult InternalGetInfo(config::ConnectionInfo::InfoType type, void* buf, short buflen, short* reslen); + + /** + * Create statement associated with the connection. + * Internal call. + * + * @param Pointer to valid instance on success and NULL on failure. + * @return Operation result. + */ + SqlResult InternalCreateStatement(Statement*& statement); + + /** + * Perform transaction commit on all the associated connections. + * Internal call. + * + * @return Operation result. + */ + SqlResult InternalTransactionCommit(); + + /** + * Perform transaction rollback on all the associated connections. + * Internal call. + * + * @return Operation result. + */ + SqlResult InternalTransactionRollback(); + + /** + * Constructor. + */ + Connection(); + + /** Socket. */ + tcp::SocketClient socket; + + /** State flag. */ + bool connected; + + /** Cache name. */ + std::string cache; + + /** Message parser. */ + Parser parser; + }; + } +} + +#endif \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc/include/ignite/odbc/cursor.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/cursor.h b/modules/platforms/cpp/odbc/include/ignite/odbc/cursor.h new file mode 100644 index 0000000..7d4c925 --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/cursor.h @@ -0,0 +1,108 @@ +/* + * 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_DRIVER_CURSOR +#define _IGNITE_ODBC_DRIVER_CURSOR + +#include <stdint.h> + +#include <map> +#include <memory> + +#include "ignite/odbc/result_page.h" +#include "ignite/odbc/common_types.h" +#include "ignite/odbc/row.h" + +namespace ignite +{ + namespace odbc + { + /** + * Query result cursor. + */ + class Cursor + { + public: + /** + * Constructor. + * @param queryId ID of the executed query. + */ + Cursor(int64_t queryId); + + /** + * Destructor. + */ + ~Cursor(); + + /** + * Move cursor to the next result row. + * @return False if data update required or no more data. + */ + bool Increment(); + + /** + * Check if the cursor needs data update. + * @return True if the cursor needs data update. + */ + bool NeedDataUpdate() const; + + /** + * Check if the cursor has next row row. + * @return True if the cursor has next row row. + */ + bool HasNext() const; + + /** + * Get query ID. + * @return Query ID. + */ + int64_t GetQueryId() const + { + return queryId; + } + + /** + * Update current cursor page data. + * @param newPage New result page. + */ + void UpdateData(std::auto_ptr<ResultPage>& newPage); + + /** + * Get current row. + * @return Current row. + */ + Row* GetRow(); + + private: + IGNITE_NO_COPY_ASSIGNMENT(Cursor); + + /** Cursor id. */ + int64_t queryId; + + /** Current page. */ + std::auto_ptr<ResultPage> currentPage; + + /** Row position in current page. */ + int32_t currentPagePos; + + /** Current row. */ + std::auto_ptr<Row> currentRow; + }; + } +} + +#endif http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc/include/ignite/odbc/decimal.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/decimal.h b/modules/platforms/cpp/odbc/include/ignite/odbc/decimal.h new file mode 100644 index 0000000..abf7f34 --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/decimal.h @@ -0,0 +1,126 @@ +/* + * 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_DECIMAL +#define _IGNITE_DECIMAL + +#include <stdint.h> + +namespace ignite +{ + //TODO: move to binary or common library. + class Decimal + { + friend void swap(Decimal& first, Decimal& second); + public: + /** + * Default constructor. + */ + Decimal(); + + /** + * Constructor. + * + * @param scale Scale. + * @param mag Magnitude. Value is copied. + * @param len Magnitude length in bytes. + */ + Decimal(int32_t scale, const int8_t* mag, int32_t len); + + /** + * Copy constructor. + * + * @param other Other instance. + */ + Decimal(const Decimal& other); + + /** + * Destructor. + */ + ~Decimal(); + + /** + * Copy operator. + * + * @param other Other instance. + * @return This. + */ + Decimal& operator=(const Decimal& other); + + /** + * Convert to double. + */ + operator double() const; + + /** + * Get scale. + * + * @return Scale. + */ + int32_t GetScale() const; + + /** + * Get sign. + * + * @return Sign: -1 if negative and 1 if positive. + */ + int32_t GetSign() const; + + /** + * Check if the value is negative. + * + * @return True if negative and false otherwise. + */ + bool IsNegative() const; + + /** + * Get magnitude length. + * + * @return Magnitude length. + */ + int32_t GetLength() const; + + /** + * Get magnitude pointer. + * + * @return Magnitude pointer. + */ + const int8_t* GetMagnitude() const; + + private: + /** Scale. */ + int32_t scale; + + /** Magnitude lenght. */ + int32_t len; + + /** Magnitude. */ + int8_t* magnitude; + }; + + /** + * Swap function for the Decimal type. + * + * @param first First instance. + * @param second Second instance. + */ + void swap(Decimal& first, Decimal& second); +} + + + +#endif \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnosable.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnosable.h b/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnosable.h new file mode 100644 index 0000000..2afd819 --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnosable.h @@ -0,0 +1,82 @@ +/* + * 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_DRIVER_DIAGNOSABLE +#define _IGNITE_ODBC_DRIVER_DIAGNOSABLE + +#include "ignite/odbc/diagnostic/diagnostic_record_storage.h" + +namespace ignite +{ + namespace odbc + { + namespace diagnostic + { + /** + * Diagnosable interface. + */ + class Diagnosable + { + public: + /** + * Destructor. + */ + virtual ~Diagnosable() + { + // No-op. + } + + /** + * Get diagnostic record. + * + * @return Diagnostic record. + */ + virtual const diagnostic::DiagnosticRecordStorage& GetDiagnosticRecords() const = 0; + + /** + * Add new status record. + * + * @param sqlState SQL state. + * @param message Message. + * @param rowNum Associated row number. + * @param columnNum Associated column number. + */ + virtual void AddStatusRecord(SqlState sqlState, const std::string& message, + int32_t rowNum, int32_t columnNum) = 0; + + /** + * Add new status record. + * + * @param sqlState SQL state. + * @param message Message. + */ + virtual void AddStatusRecord(SqlState sqlState, const std::string& message) = 0; + + protected: + /** + * Default constructor. + */ + Diagnosable() + { + // No-op. + } + }; + } + } +} + +#endif \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnosable_adapter.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnosable_adapter.h b/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnosable_adapter.h new file mode 100644 index 0000000..5b01f49 --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnosable_adapter.h @@ -0,0 +1,107 @@ +/* + * 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_DRIVER_DIAGNOSABLE_ADAPTER +#define _IGNITE_ODBC_DRIVER_DIAGNOSABLE_ADAPTER + +#include "ignite/odbc/diagnostic/diagnosable.h" + +#define IGNITE_ODBC_API_CALL(...) \ + diagnosticRecords.Reset(); \ + SqlResult result = (__VA_ARGS__); \ + diagnosticRecords.SetHeaderRecord(result) + +#define IGNITE_ODBC_API_CALL_ALWAYS_SUCCESS \ + diagnosticRecords.Reset(); \ + diagnosticRecords.SetHeaderRecord(SQL_RESULT_SUCCESS) + +namespace ignite +{ + namespace odbc + { + class Connection; + + namespace diagnostic + { + /** + * Diagnosable interface. + */ + class DiagnosableAdapter : public Diagnosable + { + public: + /** + * Destructor. + */ + virtual ~DiagnosableAdapter() + { + // No-op. + } + + /** + * Get diagnostic record. + * + * @return Diagnostic record. + */ + virtual const diagnostic::DiagnosticRecordStorage& GetDiagnosticRecords() const + { + return diagnosticRecords; + } + + /** + * Add new status record. + * + * @param sqlState SQL state. + * @param message Message. + * @param rowNum Associated row number. + * @param columnNum Associated column number. + */ + virtual void AddStatusRecord(SqlState sqlState, const std::string& message, + int32_t rowNum, int32_t columnNum); + + /** + * Add new status record. + * + * @param sqlState SQL state. + * @param message Message. + */ + virtual void AddStatusRecord(SqlState sqlState, const std::string& message); + + protected: + /** + * Constructor. + * + * @param connection Pointer to connection. Used to create + * diagnostic records with connection info. + */ + DiagnosableAdapter(const Connection* connection = 0) : + connection(connection) + { + // No-op. + } + + /** Diagnostic records. */ + diagnostic::DiagnosticRecordStorage diagnosticRecords; + + private: + /** Connection. */ + const Connection* connection; + }; + } + } +} + +#endif \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnostic_record.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnostic_record.h b/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnostic_record.h new file mode 100644 index 0000000..87d29c1 --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnostic_record.h @@ -0,0 +1,165 @@ +/* + * 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_DRIVER_DIAGNOSTIC_RECORD +#define _IGNITE_ODBC_DRIVER_DIAGNOSTIC_RECORD + +#include <stdint.h> + +#include <vector> + +#include <ignite/common/common.h> +#include "ignite/odbc/common_types.h" +#include "ignite/odbc/app/application_data_buffer.h" + +namespace ignite +{ + namespace odbc + { + namespace diagnostic + { + /** + * Status diagnostic record. + */ + class DiagnosticRecord + { + public: + /** + * Default constructor. + */ + DiagnosticRecord(); + + /** + * Constructor. + * + * @param sqlState SQL state code. + * @param message Message. + * @param connectionName Connection name. + * @param serverName Server name. + * @param rowNum Associated row number. + * @param columnNum Associated column number. + */ + DiagnosticRecord(SqlState sqlState, const std::string& message, + const std::string& connectionName, const std::string& serverName, + int32_t rowNum = 0, int32_t columnNum = 0); + + /** + * Destructor. + */ + ~DiagnosticRecord(); + + /** + * Get class origin. + * + * @return A string that indicates the document that defines the + * class portion of the SQLSTATE value in this record. + */ + const std::string& GetClassOrigin() const; + + /** + * Get subclass origin. + * + * @return A string with the same format and valid values as origin, + * that identifies the defining portion of the subclass + * portion of the SQLSTATE code. + */ + const std::string& GetSubclassOrigin() const; + + /** + * Get record message text. + * + * @return An informational message on the error or warning. + */ + const std::string& GetMessage() const; + + /** + * Get connection name. + * + * @return A string that indicates the name of the connection that + * the diagnostic record relates to. + */ + const std::string& GetConnectionName() const; + + /** + * Get server name. + * + * @return A string that indicates the server name that the + * diagnostic record relates to. + */ + const std::string& GetServerName() const; + + /** + * Get SQL state of the record. + * + * @return A five-character SQLSTATE diagnostic code. + */ + const std::string& GetSqlState() const; + + /** + * Get row number. + * + * @return The row number in the rowset, or the parameter number in + * the set of parameters, with which the status record is + * associated. + */ + int32_t GetRowNumber() const; + + /** + * Get column number. + * + * @return Contains the value that represents the column number + * in the result set or the parameter number in the set + * of parameters. + */ + int32_t GetColumnNumber() const; + + private: + /** SQL state diagnostic code. */ + SqlState sqlState; + + /** An informational message on the error or warning. */ + std::string message; + + /** + * A string that indicates the name of the connection that + * the diagnostic record relates to. + */ + std::string connectionName; + + /** + * A string that indicates the server name that the + * diagnostic record relates to. + */ + std::string serverName; + + /** + * The row number in the rowset, or the parameter number in the + * set of parameters, with which the status record is associated. + */ + int32_t rowNum; + + /** + * Contains the value that represents the column number in the + * result set or the parameter number in the set of parameters. + */ + int32_t columnNum; + }; + } + } +} + +#endif \ No newline at end of file
