IGNITE-2223: Implementation of Decimal type.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e5a2bfb6 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e5a2bfb6 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e5a2bfb6 Branch: refs/heads/ignite-1786 Commit: e5a2bfb62ea5ce3f8027ca55a15b3a516f845172 Parents: 2a1f1c0 Author: isapego <[email protected]> Authored: Mon Jan 11 21:08:54 2016 +0300 Committer: isapego <[email protected]> Committed: Mon Jan 11 21:08:54 2016 +0300 ---------------------------------------------------------------------- .../include/ignite/odbc/common_types.h | 47 ++++++++ .../odbc-driver/include/ignite/odbc/decimal.h | 107 +++++++++++++++++++ .../odbc-driver/project/vs/odbc-driver.vcxproj | 2 + .../project/vs/odbc-driver.vcxproj.filters | 6 ++ .../cpp/odbc/odbc-driver/src/decimal.cpp | 85 +++++++++++++++ 5 files changed, 247 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/e5a2bfb6/modules/platforms/cpp/odbc/odbc-driver/include/ignite/odbc/common_types.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/odbc-driver/include/ignite/odbc/common_types.h b/modules/platforms/cpp/odbc/odbc-driver/include/ignite/odbc/common_types.h index f503654..c656fae 100644 --- a/modules/platforms/cpp/odbc/odbc-driver/include/ignite/odbc/common_types.h +++ b/modules/platforms/cpp/odbc/odbc-driver/include/ignite/odbc/common_types.h @@ -44,6 +44,9 @@ namespace ignite /** * Convert internal Ignite type into ODBC SQL return code. + * + * @param result Internal result type. + * @return ODBC result type. */ int SqlResultToReturnCode(SqlResult result); @@ -110,28 +113,72 @@ namespace ignite SQL_STATE_HYT01_CONNECTIOIN_TIMEOUT }; + /** + * Diagnostic field type. + */ enum DiagnosticField { + /** 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, + /** Field type is unknown to the driver. */ IGNITE_SQL_DIAG_UNKNOWN }; + /** + * Convert ODBC field type to internal DiagnosticField type value. + * + * @param field ODBC field type. + * @return Internal DiagnosticField type value. + */ DiagnosticField DiagnosticFieldToInternal(int16_t field); } } http://git-wip-us.apache.org/repos/asf/ignite/blob/e5a2bfb6/modules/platforms/cpp/odbc/odbc-driver/include/ignite/odbc/decimal.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/odbc-driver/include/ignite/odbc/decimal.h b/modules/platforms/cpp/odbc/odbc-driver/include/ignite/odbc/decimal.h new file mode 100644 index 0000000..7b5188b --- /dev/null +++ b/modules/platforms/cpp/odbc/odbc-driver/include/ignite/odbc/decimal.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_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); + + /** + * Get scale. + * + * @return Scale. + */ + int32_t GetScale() 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/e5a2bfb6/modules/platforms/cpp/odbc/odbc-driver/project/vs/odbc-driver.vcxproj ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/odbc-driver/project/vs/odbc-driver.vcxproj b/modules/platforms/cpp/odbc/odbc-driver/project/vs/odbc-driver.vcxproj index 55587df..a85adf3 100644 --- a/modules/platforms/cpp/odbc/odbc-driver/project/vs/odbc-driver.vcxproj +++ b/modules/platforms/cpp/odbc/odbc-driver/project/vs/odbc-driver.vcxproj @@ -157,6 +157,7 @@ <ClCompile Include="..\..\src\config\connection_info.cpp" /> <ClCompile Include="..\..\src\connection.cpp" /> <ClCompile Include="..\..\src\cursor.cpp" /> + <ClCompile Include="..\..\src\decimal.cpp" /> <ClCompile Include="..\..\src\diagnostic\diagnosable_adapter.cpp" /> <ClCompile Include="..\..\src\diagnostic\diagnostic_record.cpp" /> <ClCompile Include="..\..\src\diagnostic\diagnostic_record_storage.cpp" /> @@ -186,6 +187,7 @@ <ClInclude Include="..\..\include\ignite\odbc\config\connection_info.h" /> <ClInclude Include="..\..\include\ignite\odbc\connection.h" /> <ClInclude Include="..\..\include\ignite\odbc\cursor.h" /> + <ClInclude Include="..\..\include\ignite\odbc\decimal.h" /> <ClInclude Include="..\..\include\ignite\odbc\diagnostic\diagnosable.h" /> <ClInclude Include="..\..\include\ignite\odbc\diagnostic\diagnosable_adapter.h" /> <ClInclude Include="..\..\include\ignite\odbc\diagnostic\diagnostic_record.h" /> http://git-wip-us.apache.org/repos/asf/ignite/blob/e5a2bfb6/modules/platforms/cpp/odbc/odbc-driver/project/vs/odbc-driver.vcxproj.filters ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/odbc-driver/project/vs/odbc-driver.vcxproj.filters b/modules/platforms/cpp/odbc/odbc-driver/project/vs/odbc-driver.vcxproj.filters index 9631946..650bfe4 100644 --- a/modules/platforms/cpp/odbc/odbc-driver/project/vs/odbc-driver.vcxproj.filters +++ b/modules/platforms/cpp/odbc/odbc-driver/project/vs/odbc-driver.vcxproj.filters @@ -103,6 +103,9 @@ <ClCompile Include="..\..\os\win\src\system\socket_client.cpp"> <Filter>Code\system</Filter> </ClCompile> + <ClCompile Include="..\..\src\decimal.cpp"> + <Filter>Code</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <None Include="module.def"> @@ -201,5 +204,8 @@ <ClInclude Include="..\..\include\ignite\odbc\system\socket_client.h"> <Filter>Code\system</Filter> </ClInclude> + <ClInclude Include="..\..\include\ignite\odbc\decimal.h"> + <Filter>Code</Filter> + </ClInclude> </ItemGroup> </Project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e5a2bfb6/modules/platforms/cpp/odbc/odbc-driver/src/decimal.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/odbc-driver/src/decimal.cpp b/modules/platforms/cpp/odbc/odbc-driver/src/decimal.cpp new file mode 100644 index 0000000..2df48d8 --- /dev/null +++ b/modules/platforms/cpp/odbc/odbc-driver/src/decimal.cpp @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <cstring> +#include <utility> + +#include "ignite/odbc/decimal.h" + +namespace ignite +{ + + Decimal::Decimal() : + scale(0), len(0), magnitude(0) + { + } + + Decimal::Decimal(int32_t scale, const int8_t * mag, int32_t len) : + scale(scale), len(len), magnitude(0) + { + magnitude = new int8_t[len]; + + memcpy(magnitude, mag, len); + } + + Decimal::Decimal(const Decimal & other) : + scale(other.scale), len(other.len), magnitude(0) + { + magnitude = new int8_t[len]; + + memcpy(magnitude, other.magnitude, len); + } + + Decimal::~Decimal() + { + if (magnitude) + delete[] magnitude; + } + + Decimal& Decimal::operator=(const Decimal& other) + { + Decimal tmp(other); + + swap(tmp, *this); + + return *this; + } + + int32_t Decimal::GetScale() const + { + return scale; + } + + int32_t Decimal::GetLength() const + { + return scale; + } + + const int8_t * Decimal::GetMagnitude() const + { + return magnitude; + } + + void swap(Decimal & first, Decimal & second) + { + using std::swap; + + std::swap(first.scale, second.scale); + std::swap(first.len, second.len); + std::swap(first.magnitude, second.magnitude); + } +}
