ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [06/12] ignite git commit: IGNITE-6511: Fixed SQLGetDiagRec behaviour in ODBC
Date Thu, 26 Oct 2017 09:03:27 GMT
IGNITE-6511: Fixed SQLGetDiagRec behaviour in ODBC


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

Branch: refs/heads/ignite-3478
Commit: bbf48533ca8f29961510d370be617ebbbc5cd5c9
Parents: 70a57d5
Author: Igor Sapego <isapego@gridgain.com>
Authored: Wed Oct 25 15:07:06 2017 +0300
Committer: Igor Sapego <isapego@gridgain.com>
Committed: Wed Oct 25 15:07:06 2017 +0300

----------------------------------------------------------------------
 .../cpp/odbc-test/src/api_robustness_test.cpp   | 25 ++++++++++-------
 modules/platforms/cpp/odbc/src/odbc.cpp         | 29 ++++++++++++++++----
 2 files changed, 38 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/bbf48533/modules/platforms/cpp/odbc-test/src/api_robustness_test.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc-test/src/api_robustness_test.cpp b/modules/platforms/cpp/odbc-test/src/api_robustness_test.cpp
index 82f7274..c17e079 100644
--- a/modules/platforms/cpp/odbc-test/src/api_robustness_test.cpp
+++ b/modules/platforms/cpp/odbc-test/src/api_robustness_test.cpp
@@ -976,26 +976,31 @@ BOOST_AUTO_TEST_CASE(TestSQLGetDiagField)
 
 BOOST_AUTO_TEST_CASE(TestSQLGetDiagRec)
 {
-    // There are no checks because we do not really care what is the result of these
-    // calls as long as they do not cause segmentation fault.
-
     Connect("DRIVER={Apache Ignite};address=127.0.0.1:11110;schema=cache");
 
-    // Should fail.
-    SQLRETURN ret = SQLGetTypeInfo(stmt, SQL_INTERVAL_MONTH);
-
-    BOOST_REQUIRE_EQUAL(ret, SQL_ERROR);
-
     SQLCHAR state[ODBC_BUFFER_SIZE];
     SQLINTEGER nativeError = 0;
     SQLCHAR message[ODBC_BUFFER_SIZE];
     SQLSMALLINT messageLen = 0;
 
-    // Everithing is ok
-    ret = SQLGetDiagRec(SQL_HANDLE_STMT, stmt, 1, state, &nativeError, message, sizeof(message),
&messageLen);
+    // Generating error.
+    SQLRETURN ret = SQLGetTypeInfo(stmt, SQL_INTERVAL_MONTH);
+    BOOST_REQUIRE_EQUAL(ret, SQL_ERROR);
 
+    // Everithing is ok.
+    ret = SQLGetDiagRec(SQL_HANDLE_STMT, stmt, 1, state, &nativeError, message, sizeof(message),
&messageLen);
     BOOST_REQUIRE_EQUAL(ret, SQL_SUCCESS);
 
+    // Should return error.
+    ret = SQLGetDiagRec(SQL_HANDLE_STMT, stmt, 1, state, &nativeError, message, -1, &messageLen);
+    BOOST_REQUIRE_EQUAL(ret, SQL_ERROR);
+
+    // Should return message length.
+    ret = SQLGetDiagRec(SQL_HANDLE_STMT, stmt, 1, state, &nativeError, message, 1, &messageLen);
+    BOOST_REQUIRE_EQUAL(ret, SQL_SUCCESS_WITH_INFO);
+
+    // There are no checks because we do not really care what is the result of these
+    // calls as long as they do not cause segmentation fault.
     SQLGetDiagRec(SQL_HANDLE_STMT, stmt, 1, 0, &nativeError, message, sizeof(message),
&messageLen);
     SQLGetDiagRec(SQL_HANDLE_STMT, stmt, 1, state, 0, message, sizeof(message), &messageLen);
     SQLGetDiagRec(SQL_HANDLE_STMT, stmt, 1, state, &nativeError, 0, sizeof(message),
&messageLen);

http://git-wip-us.apache.org/repos/asf/ignite/blob/bbf48533/modules/platforms/cpp/odbc/src/odbc.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc/src/odbc.cpp b/modules/platforms/cpp/odbc/src/odbc.cpp
index baa276a..8121a3b 100644
--- a/modules/platforms/cpp/odbc/src/odbc.cpp
+++ b/modules/platforms/cpp/odbc/src/odbc.cpp
@@ -984,16 +984,22 @@ namespace ignite
             {
                 Diagnosable *diag = reinterpret_cast<Diagnosable*>(handle);
 
+                if (!diag)
+                    return SQL_INVALID_HANDLE;
+
                 records = &diag->GetDiagnosticRecords();
 
                 break;
             }
 
             default:
-                break;
+                return SQL_INVALID_HANDLE;
         }
 
-        if (!records || recNum < 1 || recNum > records->GetStatusRecordsNumber())
+        if (recNum < 1 || msgBufferLen < 0)
+            return SQL_ERROR;
+
+        if (!records || recNum > records->GetStatusRecordsNumber())
             return SQL_NO_DATA;
 
         const DiagnosticRecord& record = records->GetStatusRecord(recNum);
@@ -1004,13 +1010,24 @@ namespace ignite
         if (nativeError)
             *nativeError = 0;
 
-        SqlLen outResLen;
-        ApplicationDataBuffer outBuffer(OdbcNativeType::AI_CHAR, msgBuffer, msgBufferLen,
&outResLen);
+        const std::string& errMsg = record.GetMessageText();
 
-        outBuffer.PutString(record.GetMessageText());
+        if (!msgBuffer || msgBufferLen < static_cast<SQLSMALLINT>(errMsg.size()
+ 1))
+        {
+            if (!msgLen)
+                return SQL_ERROR;
+
+            CopyStringToBuffer(errMsg, reinterpret_cast<char*>(msgBuffer), static_cast<size_t>(msgBufferLen));
+
+            *msgLen = static_cast<SQLSMALLINT>(errMsg.size());
+
+            return SQL_SUCCESS_WITH_INFO;
+        }
+
+        CopyStringToBuffer(errMsg, reinterpret_cast<char*>(msgBuffer), static_cast<size_t>(msgBufferLen));
 
         if (msgLen)
-            *msgLen = static_cast<SQLSMALLINT>(outResLen);
+            *msgLen = static_cast<SQLSMALLINT>(errMsg.size());
 
         return SQL_SUCCESS;
     }


Mime
View raw message