You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2016/01/25 12:55:08 UTC

[06/50] ignite git commit: IGNITE-2223: Better support for the NUMERIC type.

IGNITE-2223: Better support for the NUMERIC type.


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

Branch: refs/heads/ignite-1786
Commit: 2a1f1c0f5f32c56ba5a44588d6ed4702c9678a1d
Parents: 0ea8e06
Author: isapego <is...@gridgain.com>
Authored: Mon Jan 11 18:52:36 2016 +0300
Committer: isapego <is...@gridgain.com>
Committed: Mon Jan 11 18:52:36 2016 +0300

----------------------------------------------------------------------
 .../include/ignite/odbc/type_traits.h           | 30 ++++++++++----------
 .../src/app/application_data_buffer.cpp         | 26 +++++++++++++++++
 2 files changed, 41 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/2a1f1c0f/modules/platforms/cpp/odbc/odbc-driver/include/ignite/odbc/type_traits.h
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc/odbc-driver/include/ignite/odbc/type_traits.h b/modules/platforms/cpp/odbc/odbc-driver/include/ignite/odbc/type_traits.h
index 0bdb5ab..7dac73f 100644
--- a/modules/platforms/cpp/odbc/odbc-driver/include/ignite/odbc/type_traits.h
+++ b/modules/platforms/cpp/odbc/odbc-driver/include/ignite/odbc/type_traits.h
@@ -55,49 +55,49 @@ namespace ignite
                 /** Alias for the SQL_C_USHORT type. */
                 IGNITE_ODBC_C_TYPE_UNSIGNED_SHORT,
 
-                /** Alias for the SQL_C_WCHAR type. */
+                /** Alias for the SQL_C_SLONG type. */
                 IGNITE_ODBC_C_TYPE_SIGNED_LONG,
 
-                /** Alias for the SQL_C_WCHAR type. */
+                /** Alias for the SQL_C_ULONG type. */
                 IGNITE_ODBC_C_TYPE_UNSIGNED_LONG,
 
-                /** Alias for the SQL_C_WCHAR type. */
+                /** Alias for the SQL_C_FLOAT type. */
                 IGNITE_ODBC_C_TYPE_FLOAT,
 
-                /** Alias for the SQL_C_WCHAR type. */
+                /** Alias for the SQL_C_DOUBLE type. */
                 IGNITE_ODBC_C_TYPE_DOUBLE,
 
-                /** Alias for the SQL_C_WCHAR type. */
+                /** Alias for the SQL_C_BIT type. */
                 IGNITE_ODBC_C_TYPE_BIT,
 
-                /** Alias for the SQL_C_WCHAR type. */
+                /** Alias for the SQL_C_STINYINT type. */
                 IGNITE_ODBC_C_TYPE_SIGNED_TINYINT,
 
-                /** Alias for the SQL_C_WCHAR type. */
+                /** Alias for the SQL_C_UTINYINT type. */
                 IGNITE_ODBC_C_TYPE_UNSIGNED_TINYINT,
 
-                /** Alias for the SQL_C_WCHAR type. */
+                /** Alias for the SQL_C_SBIGINT type. */
                 IGNITE_ODBC_C_TYPE_SIGNED_BIGINT,
 
-                /** Alias for the SQL_C_WCHAR type. */
+                /** Alias for the SQL_C_UBIGINT type. */
                 IGNITE_ODBC_C_TYPE_UNSIGNED_BIGINT,
 
-                /** Alias for the SQL_C_WCHAR type. */
+                /** Alias for the SQL_C_BINARY type. */
                 IGNITE_ODBC_C_TYPE_BINARY,
 
-                /** Alias for the SQL_C_WCHAR type. */
+                /** Alias for the SQL_C_TDATE type. */
                 IGNITE_ODBC_C_TYPE_TDATE,
 
-                /** Alias for the SQL_C_WCHAR type. */
+                /** Alias for the SQL_C_TTIME type. */
                 IGNITE_ODBC_C_TYPE_TTIME,
 
-                /** Alias for the SQL_C_WCHAR type. */
+                /** Alias for the SQL_C_TTIMESTAMP type. */
                 IGNITE_ODBC_C_TYPE_TTIMESTAMP,
 
-                /** Alias for the SQL_C_WCHAR type. */
+                /** Alias for the SQL_C_NUMERIC type. */
                 IGNITE_ODBC_C_TYPE_NUMERIC,
 
-                /** Alias for the SQL_C_WCHAR type. */
+                /** Alias for the SQL_C_GUID type. */
                 IGNITE_ODBC_C_TYPE_GUID,
 
                 /** Alias for the SQL_DEFAULT. */

http://git-wip-us.apache.org/repos/asf/ignite/blob/2a1f1c0f/modules/platforms/cpp/odbc/odbc-driver/src/app/application_data_buffer.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc/odbc-driver/src/app/application_data_buffer.cpp b/modules/platforms/cpp/odbc/odbc-driver/src/app/application_data_buffer.cpp
index 36204cb..e3e4400 100644
--- a/modules/platforms/cpp/odbc/odbc-driver/src/app/application_data_buffer.cpp
+++ b/modules/platforms/cpp/odbc/odbc-driver/src/app/application_data_buffer.cpp
@@ -154,6 +154,8 @@ namespace ignite
                             out->scale = 0;
                             out->sign = value > 0 ? 1 : 0;
 
+                            memset(out->val, 0, SQL_MAX_NUMERIC_LEN);
+
                             // TODO: implement propper conversation to numeric type.
                             int64_t intVal = static_cast<int64_t>(std::abs(value));
 
@@ -541,6 +543,7 @@ namespace ignite
                         break;
                     }
 
+                    case IGNITE_ODBC_C_TYPE_NUMERIC:
                     case IGNITE_ODBC_C_TYPE_DOUBLE:
                     {
                         std::stringstream converter;
@@ -701,6 +704,29 @@ namespace ignite
                         break;
                     }
 
+                    case IGNITE_ODBC_C_TYPE_NUMERIC:
+                    {
+                        const SQL_NUMERIC_STRUCT* numeric =
+                            reinterpret_cast<const SQL_NUMERIC_STRUCT*>(GetData());
+
+                        int64_t resInt;
+
+                        // TODO: implement propper conversation from numeric type.
+                        memcpy(&resInt, numeric->val, std::min<int>(SQL_MAX_NUMERIC_LEN, sizeof(resInt)));
+
+                        if (numeric->sign)
+                            resInt *= -1;
+
+                        double resDouble = static_cast<double>(resInt);
+
+                        for (SQLSCHAR scale = numeric->scale; scale > 0; --scale)
+                            resDouble /= 10.0;
+
+                        res = static_cast<T>(resDouble);
+
+                        break;
+                    }
+
                     default:
                         break;
                 }