This is an automated email from the ASF dual-hosted git repository.

isapego pushed a commit to branch ignite-19216
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit c6c4c13b110367d645de5b6fa615300e774aeb05
Author: Igor Sapego <[email protected]>
AuthorDate: Tue Sep 19 03:51:50 2023 +0400

    IGNITE-19216 Fix meta
---
 .../cpp/ignite/odbc/app/application_data_buffer.h  |   2 +-
 .../cpp/ignite/odbc/query/type_info_query.cpp      |  86 ++++++--------
 .../cpp/ignite/odbc/query/type_info_query.h        |   8 +-
 .../platforms/cpp/ignite/odbc/sql_statement.cpp    |   5 +-
 modules/platforms/cpp/ignite/odbc/type_traits.cpp  | 131 ++++++++++++---------
 modules/platforms/cpp/ignite/odbc/type_traits.h    |  19 ++-
 6 files changed, 137 insertions(+), 114 deletions(-)

diff --git a/modules/platforms/cpp/ignite/odbc/app/application_data_buffer.h 
b/modules/platforms/cpp/ignite/odbc/app/application_data_buffer.h
index 98a2ffcb74..fd7ea6ee8d 100644
--- a/modules/platforms/cpp/ignite/odbc/app/application_data_buffer.h
+++ b/modules/platforms/cpp/ignite/odbc/app/application_data_buffer.h
@@ -522,6 +522,6 @@ private:
 };
 
 /** Column binging map type alias. */
-typedef std::map<uint16_t, application_data_buffer> column_binding_map;
+typedef std::map<std::uint16_t, application_data_buffer> column_binding_map;
 
 } // namespace ignite
diff --git a/modules/platforms/cpp/ignite/odbc/query/type_info_query.cpp 
b/modules/platforms/cpp/ignite/odbc/query/type_info_query.cpp
index 5f6276af67..4819f1b646 100644
--- a/modules/platforms/cpp/ignite/odbc/query/type_info_query.cpp
+++ b/modules/platforms/cpp/ignite/odbc/query/type_info_query.cpp
@@ -111,6 +111,7 @@ enum class result_column
 
 namespace ignite
 {
+
 type_info_query::type_info_query(diagnosable_adapter &diag, std::int16_t 
sql_type) :
     query(diag, query_type::TYPE_INFO)
 {
@@ -143,17 +144,25 @@ type_info_query::type_info_query(diagnosable_adapter 
&diag, std::int16_t sql_typ
 
     if (sql_type == SQL_ALL_TYPES)
     {
-        m_types.push_back(ignite_type::STRING);
+        m_types.push_back(ignite_type::BOOLEAN);
+        m_types.push_back(ignite_type::INT8);
         m_types.push_back(ignite_type::INT16);
         m_types.push_back(ignite_type::INT32);
-        m_types.push_back(ignite_type::DECIMAL);
+        m_types.push_back(ignite_type::INT64);
         m_types.push_back(ignite_type::FLOAT);
         m_types.push_back(ignite_type::DOUBLE);
-        m_types.push_back(ignite_type::BOOLEAN);
-        m_types.push_back(ignite_type::INT8);
-        m_types.push_back(ignite_type::INT64);
+        m_types.push_back(ignite_type::DECIMAL);
+        m_types.push_back(ignite_type::DATE);
+        m_types.push_back(ignite_type::TIME);
+        m_types.push_back(ignite_type::DATETIME);
+        m_types.push_back(ignite_type::TIMESTAMP);
         m_types.push_back(ignite_type::UUID);
+        m_types.push_back(ignite_type::BITMASK);
+        m_types.push_back(ignite_type::STRING);
         m_types.push_back(ignite_type::BYTE_ARRAY);
+        m_types.push_back(ignite_type::PERIOD);
+        m_types.push_back(ignite_type::DURATION);
+        m_types.push_back(ignite_type::NUMBER);
     }
     else
         m_types.push_back(sql_type_to_ignite_type(sql_type));
@@ -169,17 +178,10 @@ sql_result type_info_query::execute()
     return sql_result::AI_SUCCESS;
 }
 
-const column_meta_vector* type_info_query::get_meta()
+sql_result type_info_query::fetch_next_row(column_binding_map &column_bindings)
 {
-    return &m_columns_meta;
-}
-
-sql_result type_info_query::fetch_next_row(column_binding_map & columnBindings)
-{
-    if (!m_executed)
-    {
-        m_diag.add_status_record(sql_state::SHY010_SEQUENCE_ERROR, "Query was 
not m_executed.");
-
+    if (!m_executed) {
+        m_diag.add_status_record(sql_state::SHY010_SEQUENCE_ERROR, "Query was 
not executed.");
         return sql_result::AI_ERROR;
     }
 
@@ -191,27 +193,21 @@ sql_result 
type_info_query::fetch_next_row(column_binding_map & columnBindings)
     if (m_cursor == m_types.end())
         return sql_result::AI_NO_DATA;
 
-    column_binding_map::iterator it;
-
-    for (it = columnBindings.begin(); it != columnBindings.end(); ++it)
-        get_column(it->first, it->second);
+    for (auto& pair : column_bindings)
+        get_column(pair.first, pair.second);
 
     return sql_result::AI_SUCCESS;
 }
 
 sql_result type_info_query::get_column(std::uint16_t column_idx, 
application_data_buffer &buffer)
 {
-    if (!m_executed)
-    {
-        m_diag.add_status_record(sql_state::SHY010_SEQUENCE_ERROR, "Query was 
not m_executed.");
-
+    if (!m_executed) {
+        m_diag.add_status_record(sql_state::SHY010_SEQUENCE_ERROR, "Query was 
not executed.");
         return sql_result::AI_ERROR;
     }
 
-    if (m_cursor == m_types.end())
-    {
+    if (m_cursor == m_types.end()) {
         m_diag.add_status_record(sql_state::S24000_INVALID_CURSOR_STATE, 
"Cursor has reached end of the result set.");
-
         return sql_result::AI_ERROR;
     }
 
@@ -236,36 +232,39 @@ sql_result type_info_query::get_column(std::uint16_t 
column_idx, application_dat
 
         case result_column::COLUMN_SIZE:
         {
-            buffer.put_int32(ignite_type_column_size(current_type));
+            buffer.put_int32(ignite_type_max_column_size(current_type));
 
             break;
         }
 
         case result_column::LITERAL_PREFIX:
         {
-            if (current_type == ignite_type::STRING)
-                buffer.put_string("'");
-            else if (current_type == ignite_type::BYTE_ARRAY)
-                buffer.put_string("0x");
-            else
+            auto prefix = ignite_type_literal_prefix(current_type);
+            if (!prefix)
                 buffer.put_null();
+            else
+                buffer.put_string(*prefix);
 
             break;
         }
 
         case result_column::LITERAL_SUFFIX:
         {
-            if (current_type == ignite_type::STRING)
-                buffer.put_string("'");
-            else
+            auto suffix = ignite_type_literal_suffix(current_type);
+            if (!suffix)
                 buffer.put_null();
+            else
+                buffer.put_string(*suffix);
 
             break;
         }
 
         case result_column::CREATE_PARAMS:
         {
-            buffer.put_null();
+            if (current_type == ignite_type::DECIMAL || current_type == 
ignite_type::NUMBER)
+                buffer.put_string("precision,scale");
+            else
+                buffer.put_null();
 
             break;
         }
@@ -361,20 +360,5 @@ sql_result type_info_query::close()
     return sql_result::AI_SUCCESS;
 }
 
-bool type_info_query::is_data_available() const
-{
-    return m_cursor != m_types.end();
-}
-
-int64_t type_info_query::affected_rows() const
-{
-    return 0;
-}
-
-sql_result type_info_query::next_result_set()
-{
-    return sql_result::AI_NO_DATA;
-}
-
 } // namespace ignite
 
diff --git a/modules/platforms/cpp/ignite/odbc/query/type_info_query.h 
b/modules/platforms/cpp/ignite/odbc/query/type_info_query.h
index bfe273a068..d3593d8ba8 100644
--- a/modules/platforms/cpp/ignite/odbc/query/type_info_query.h
+++ b/modules/platforms/cpp/ignite/odbc/query/type_info_query.h
@@ -52,7 +52,7 @@ public:
      *
      * @return Column metadata.
      */
-    const column_meta_vector* get_meta() override;
+    const column_meta_vector* get_meta() override { return &m_columns_meta; }
 
     /**
      * Fetch next result row to application buffers.
@@ -82,21 +82,21 @@ public:
      *
      * @return True if data is available.
      */
-    bool is_data_available() const override;
+    bool is_data_available() const override { return m_cursor != 
m_types.end(); }
 
     /**
      * Get number of rows affected by the statement.
      *
      * @return Number of rows affected by the statement.
      */
-    std::int64_t affected_rows() const override;
+    std::int64_t affected_rows() const override { return 0; }
 
     /**
      * Move to the next result set.
      *
      * @return Operation result.
      */
-    sql_result next_result_set() override;
+    sql_result next_result_set() override { return sql_result::AI_NO_DATA; }
 
 private:
     /** Columns metadata. */
diff --git a/modules/platforms/cpp/ignite/odbc/sql_statement.cpp 
b/modules/platforms/cpp/ignite/odbc/sql_statement.cpp
index 690030af47..e29512ae98 100644
--- a/modules/platforms/cpp/ignite/odbc/sql_statement.cpp
+++ b/modules/platforms/cpp/ignite/odbc/sql_statement.cpp
@@ -1007,12 +1007,15 @@ sql_result sql_statement::internal_describe_param(
     if (data_type)
         *data_type = ignite_type_to_sql_type(type);
 
+    // TODO: IGNITE-19854 Implement meta fetching for a parameter
     if (param_size)
-        *param_size = ignite_type_column_size(type);
+        *param_size = ignite_type_max_column_size(type);
 
+    // TODO: IGNITE-19854 Implement meta fetching for a parameter
     if (decimal_digits)
         *decimal_digits = int16_t(ignite_type_decimal_digits(type));
 
+    // TODO: IGNITE-19854 Implement meta fetching for a parameter
     if (nullable)
         *nullable = ignite_type_nullability(type);
 
diff --git a/modules/platforms/cpp/ignite/odbc/type_traits.cpp 
b/modules/platforms/cpp/ignite/odbc/type_traits.cpp
index 9fc1075f29..f0b1bd21cf 100644
--- a/modules/platforms/cpp/ignite/odbc/type_traits.cpp
+++ b/modules/platforms/cpp/ignite/odbc/type_traits.cpp
@@ -76,8 +76,11 @@ const char *statement_attr_id_to_string(long id) {
  */
 namespace sql_type_name {
 
-/** VARCHAR SQL type name constant. */
-const inline std::string VARCHAR("VARCHAR");
+/** BOOLEAN SQL type name constant. */
+const inline std::string BOOLEAN("BOOLEAN");
+
+/** TINYINT SQL type name constant. */
+const inline std::string TINYINT("TINYINT");
 
 /** SMALLINT SQL type name constant. */
 const inline std::string SMALLINT("SMALLINT");
@@ -85,45 +88,45 @@ const inline std::string SMALLINT("SMALLINT");
 /** INTEGER SQL type name constant. */
 const inline std::string INTEGER("INTEGER");
 
-/** DECIMAL SQL type name constant. */
-const inline std::string DECIMAL("DECIMAL");
+/** BIGINT SQL type name constant. */
+const inline std::string BIGINT("BIGINT");
 
 /** FLOAT SQL type name constant. */
-const inline std::string FLOAT("FLOAT");
+const inline std::string REAL("REAL");
 
 /** DOUBLE SQL type name constant. */
 const inline std::string DOUBLE("DOUBLE");
 
-/** BIT SQL type name constant. */
-const inline std::string BIT("BIT");
-
-/** TINYINT SQL type name constant. */
-const inline std::string TINYINT("TINYINT");
-
-/** BIGINT SQL type name constant. */
-const inline std::string BIGINT("BIGINT");
+/** VARCHAR SQL type name constant. */
+const inline std::string VARCHAR("VARCHAR");
 
 /** BINARY SQL type name constant. */
 const inline std::string BINARY("VARBINARY");
 
-/** DATE SQL type name constant. */
-const inline std::string DATE("DATE");
+/** TIME SQL type name constant. */
+const inline std::string TIME("TIME");
 
 /** TIMESTAMP SQL type name constant. */
 const inline std::string TIMESTAMP("TIMESTAMP");
 
-/** TIME SQL type name constant. */
-const inline std::string TIME("TIME");
+/** DATE SQL type name constant. */
+const inline std::string DATE("DATE");
 
-/** GUID SQL type name constant. */
-const inline std::string GUID("GUID");
+/** DECIMAL SQL type name constant. */
+const inline std::string DECIMAL("DECIMAL");
+
+/** UUID SQL type name constant. */
+const inline std::string UUID("UUID");
 
-}; // namespace sql_type_name
+} // namespace sql_type_name
 
 const std::string &ignite_type_to_sql_type_name(ignite_type typ) {
     switch (typ) {
-        case ignite_type::STRING:
-            return sql_type_name::VARCHAR;
+        case ignite_type::BOOLEAN:
+            return sql_type_name::BOOLEAN;
+
+        case ignite_type::INT8:
+            return sql_type_name::TINYINT;
 
         case ignite_type::INT16:
             return sql_type_name::SMALLINT;
@@ -134,24 +137,21 @@ const std::string 
&ignite_type_to_sql_type_name(ignite_type typ) {
         case ignite_type::INT64:
             return sql_type_name::BIGINT;
 
-        case ignite_type::DECIMAL:
-        case ignite_type::NUMBER:
-            return sql_type_name::DECIMAL;
-
         case ignite_type::FLOAT:
-            return sql_type_name::FLOAT;
+            return sql_type_name::REAL;
 
         case ignite_type::DOUBLE:
             return sql_type_name::DOUBLE;
 
-        case ignite_type::BOOLEAN:
-            return sql_type_name::BIT;
+        case ignite_type::STRING:
+            return sql_type_name::VARCHAR;
 
-        case ignite_type::INT8:
-            return sql_type_name::TINYINT;
+        case ignite_type::DECIMAL:
+        case ignite_type::NUMBER:
+            return sql_type_name::DECIMAL;
 
         case ignite_type::UUID:
-            return sql_type_name::GUID;
+            return sql_type_name::UUID;
 
         case ignite_type::DATE:
             return sql_type_name::DATE;
@@ -263,7 +263,7 @@ ignite_type sql_type_to_ignite_type(std::int16_t sql_type) {
             return ignite_type::DATE;
 
         case SQL_TYPE_TIMESTAMP:
-            return ignite_type::TIMESTAMP;
+            return ignite_type::DATETIME;
 
         case SQL_TYPE_TIME:
             return ignite_type::TIME;
@@ -405,14 +405,11 @@ std::int16_t ignite_type_to_sql_type(ignite_type typ) {
 }
 
 std::int16_t ignite_type_nullability(ignite_type typ) {
-    // TODO: IGNITE-19854 Remove once parameters meta fetching is implemented
     UNUSED_VALUE(typ);
-
-    return SQL_NULLABLE_UNKNOWN;
+    return SQL_NULLABLE;
 }
 
 std::int32_t sql_type_display_size(std::int16_t type) {
-    // TODO: IGNITE-19854 Remove once parameters meta fetching is implemented
     switch (type) {
         case SQL_VARCHAR:
         case SQL_CHAR:
@@ -465,26 +462,12 @@ std::int32_t sql_type_display_size(std::int16_t type) {
 }
 
 std::int32_t ignite_type_display_size(ignite_type typ) {
-    // TODO: IGNITE-19854 Remove once parameters meta fetching is implemented
     std::int16_t sql_type = ignite_type_to_sql_type(typ);
-
     return sql_type_display_size(sql_type);
 }
 
 std::int32_t sql_type_column_size(std::int16_t type) {
-    // TODO: IGNITE-19854 Remove once parameters meta fetching is implemented
     switch (type) {
-        case SQL_VARCHAR:
-        case SQL_CHAR:
-        case SQL_WCHAR:
-        case SQL_LONGVARBINARY:
-        case SQL_BINARY:
-        case SQL_VARBINARY:
-        case SQL_LONGVARCHAR:
-        case SQL_DECIMAL:
-        case SQL_NUMERIC:
-            return SQL_NO_TOTAL;
-
         case SQL_BIT:
             return 1;
 
@@ -519,20 +502,26 @@ std::int32_t sql_type_column_size(std::int16_t type) {
         case SQL_GUID:
             return 36;
 
+        case SQL_VARCHAR:
+        case SQL_CHAR:
+        case SQL_WCHAR:
+        case SQL_LONGVARBINARY:
+        case SQL_BINARY:
+        case SQL_VARBINARY:
+        case SQL_LONGVARCHAR:
+        case SQL_DECIMAL:
+        case SQL_NUMERIC:
         default:
             return SQL_NO_TOTAL;
     }
 }
 
-std::int32_t ignite_type_column_size(ignite_type typ) {
-    // TODO: IGNITE-19854 Remove once parameters meta fetching is implemented
+std::int32_t ignite_type_max_column_size(ignite_type typ) {
     std::int16_t sql_type = ignite_type_to_sql_type(typ);
-
     return sql_type_column_size(sql_type);
 }
 
 std::int32_t sql_type_transfer_length(std::int16_t type) {
-    // TODO: IGNITE-19854 Remove once parameters meta fetching is implemented
     switch (type) {
         case SQL_VARCHAR:
         case SQL_CHAR:
@@ -582,7 +571,6 @@ std::int32_t ignite_type_transfer_length(ignite_type typ) {
 }
 
 std::int32_t sql_type_num_precision_radix(std::int16_t type) {
-    // TODO: IGNITE-19854 Remove once parameters meta fetching is implemented
     switch (type) {
         case SQL_REAL:
         case SQL_FLOAT:
@@ -642,4 +630,35 @@ bool is_ignite_type_unsigned(ignite_type typ) {
     return is_sql_type_unsigned(sql_type);
 }
 
+std::optional<std::string> ignite_type_literal_prefix(ignite_type typ) {
+    switch (typ) {
+        case ignite_type::STRING:
+            return "'";
+        case ignite_type::BYTE_ARRAY:
+            return "0x";
+        case ignite_type::DATE:
+            return "DATE '";
+        case ignite_type::TIME:
+            return "TIME '";
+        case ignite_type::TIMESTAMP:
+            return "TIMESTAMP '";
+        default:
+            break;
+    }
+    return {};
+}
+
+std::optional<std::string> ignite_type_literal_suffix(ignite_type typ) {
+    switch (typ) {
+        case ignite_type::STRING:
+        case ignite_type::DATE:
+        case ignite_type::TIME:
+        case ignite_type::TIMESTAMP:
+            return "'";
+        default:
+            break;
+    }
+    return {};
+}
+
 } // namespace ignite
diff --git a/modules/platforms/cpp/ignite/odbc/type_traits.h 
b/modules/platforms/cpp/ignite/odbc/type_traits.h
index 727af18d26..f60a0dd532 100644
--- a/modules/platforms/cpp/ignite/odbc/type_traits.h
+++ b/modules/platforms/cpp/ignite/odbc/type_traits.h
@@ -21,6 +21,7 @@
 
 #include <cstdint>
 #include <string>
+#include <optional>
 
 namespace ignite {
 
@@ -189,7 +190,7 @@ int32_t sql_type_column_size(int16_t type);
  * @param typ Ignite type.
  * @return Column size.
  */
-int32_t ignite_type_column_size(ignite_type typ);
+int32_t ignite_type_max_column_size(ignite_type typ);
 
 /**
  * Get SQL type transfer octet length.
@@ -255,4 +256,20 @@ bool is_sql_type_unsigned(int16_t type);
  */
 bool is_ignite_type_unsigned(ignite_type typ);
 
+/**
+ * Get literal prefix for an ignite type.
+ *
+ * @param typ Type.
+ * @return Prefix.
+ */
+std::optional<std::string> ignite_type_literal_prefix(ignite_type typ);
+
+/**
+ * Get literal suffix for an ignite type.
+ *
+ * @param typ Type.
+ * @return Suffix.
+ */
+std::optional<std::string> ignite_type_literal_suffix(ignite_type typ);
+
 } // namespace ignite

Reply via email to