ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From isap...@apache.org
Subject ignite git commit: IGNITE-3987: ODBC: Improved error output when query parsing failed.
Date Mon, 04 Sep 2017 13:20:57 GMT
Repository: ignite
Updated Branches:
  refs/heads/master dc6b73b94 -> 29ce1fa81


IGNITE-3987: ODBC: Improved error output when query parsing failed.


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

Branch: refs/heads/master
Commit: 29ce1fa8190c806c0d041be6ead8c76f785fcf08
Parents: dc6b73b
Author: Igor Sapego <isapego@gridgain.com>
Authored: Mon Sep 4 16:20:20 2017 +0300
Committer: Igor Sapego <isapego@gridgain.com>
Committed: Mon Sep 4 16:20:20 2017 +0300

----------------------------------------------------------------------
 .../odbc/odbc/OdbcRequestHandler.java           | 17 ++++++--------
 .../processors/odbc/odbc/OdbcUtils.java         | 22 ++++++++++++++++++
 modules/platforms/cpp/odbc-test/Makefile.am     |  3 ++-
 .../cpp/odbc-test/project/vs/odbc-test.vcxproj  |  8 +++----
 .../cpp/odbc-test/src/queries_test.cpp          | 24 ++++++++++++++++++--
 5 files changed, 57 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/29ce1fa8/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/odbc/OdbcRequestHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/odbc/OdbcRequestHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/odbc/OdbcRequestHandler.java
index 692043c..679a2e6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/odbc/OdbcRequestHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/odbc/OdbcRequestHandler.java
@@ -57,9 +57,6 @@ public class OdbcRequestHandler implements SqlListenerRequestHandler {
     /** Query ID sequence. */
     private static final AtomicLong QRY_ID_GEN = new AtomicLong();
 
-    /** Batch query ID sequence. */
-    private static final AtomicLong BATCH_QRY_ID_GEN = new AtomicLong();
-
     /** Kernel context. */
     private final GridKernalContext ctx;
 
@@ -210,7 +207,7 @@ public class OdbcRequestHandler implements SqlListenerRequestHandler {
 
             U.error(log, "Failed to execute SQL query [reqId=" + req.requestId() + ", req="
+ req + ']', e);
 
-            return new OdbcResponse(SqlListenerResponse.STATUS_FAILED, e.toString());
+            return new OdbcResponse(SqlListenerResponse.STATUS_FAILED, OdbcUtils.retrieveH2ErrorMessage(e));
         }
     }
 
@@ -265,7 +262,7 @@ public class OdbcRequestHandler implements SqlListenerRequestHandler {
             U.error(log, "Failed to execute SQL query [reqId=" + req.requestId() + ", req="
+ req + ']', e);
 
             OdbcQueryExecuteBatchResult res = new OdbcQueryExecuteBatchResult(rowsAffected,
currentSet,
-                    e.getMessage());
+                    OdbcUtils.retrieveH2ErrorMessage(e));
 
             return new OdbcResponse(res);
         }
@@ -334,7 +331,7 @@ public class OdbcRequestHandler implements SqlListenerRequestHandler {
 
             U.error(log, "Failed to close SQL query [reqId=" + req.requestId() + ", req="
+ queryId + ']', e);
 
-            return new OdbcResponse(SqlListenerResponse.STATUS_FAILED, e.toString());
+            return new OdbcResponse(SqlListenerResponse.STATUS_FAILED, OdbcUtils.retrieveH2ErrorMessage(e));
         }
     }
 
@@ -383,7 +380,7 @@ public class OdbcRequestHandler implements SqlListenerRequestHandler {
         catch (Exception e) {
             U.error(log, "Failed to fetch SQL query result [reqId=" + req.requestId() + ",
req=" + req + ']', e);
 
-            return new OdbcResponse(SqlListenerResponse.STATUS_FAILED, e.toString());
+            return new OdbcResponse(SqlListenerResponse.STATUS_FAILED, OdbcUtils.retrieveH2ErrorMessage(e));
         }
     }
 
@@ -448,7 +445,7 @@ public class OdbcRequestHandler implements SqlListenerRequestHandler {
         catch (Exception e) {
             U.error(log, "Failed to get columns metadata [reqId=" + req.requestId() + ",
req=" + req + ']', e);
 
-            return new OdbcResponse(SqlListenerResponse.STATUS_FAILED, e.toString());
+            return new OdbcResponse(SqlListenerResponse.STATUS_FAILED, OdbcUtils.retrieveH2ErrorMessage(e));
         }
     }
 
@@ -496,7 +493,7 @@ public class OdbcRequestHandler implements SqlListenerRequestHandler {
         catch (Exception e) {
             U.error(log, "Failed to get tables metadata [reqId=" + req.requestId() + ", req="
+ req + ']', e);
 
-            return new OdbcResponse(SqlListenerResponse.STATUS_FAILED, e.toString());
+            return new OdbcResponse(SqlListenerResponse.STATUS_FAILED, OdbcUtils.retrieveH2ErrorMessage(e));
         }
     }
 
@@ -527,7 +524,7 @@ public class OdbcRequestHandler implements SqlListenerRequestHandler {
         catch (Exception e) {
             U.error(log, "Failed to get params metadata [reqId=" + req.requestId() + ", req="
+ req + ']', e);
 
-            return new OdbcResponse(SqlListenerResponse.STATUS_FAILED, e.toString());
+            return new OdbcResponse(SqlListenerResponse.STATUS_FAILED, OdbcUtils.retrieveH2ErrorMessage(e));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/29ce1fa8/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/odbc/OdbcUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/odbc/OdbcUtils.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/odbc/OdbcUtils.java
index 9bdd0c7..3578145 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/odbc/OdbcUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/odbc/OdbcUtils.java
@@ -139,4 +139,26 @@ public class OdbcUtils {
                 throw new IgniteException("Invalid ODBC data type '" + odbcDataType + "'");
         }
     }
+
+    /**
+     * Retrieves error message from exception.
+     * @param err Exception.
+     * @return Error message.
+     */
+    public static String retrieveH2ErrorMessage(Throwable err) {
+        String msg = err.getMessage();
+
+        Throwable e = err.getCause();
+        while (e != null) {
+            if (e.getClass().getCanonicalName().equals("org.h2.jdbc.JdbcSQLException")) {
+                msg = e.getMessage();
+
+                break;
+            }
+
+            e = e.getCause();
+        }
+
+        return msg;
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/29ce1fa8/modules/platforms/cpp/odbc-test/Makefile.am
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc-test/Makefile.am b/modules/platforms/cpp/odbc-test/Makefile.am
index 1d65468..7756181 100644
--- a/modules/platforms/cpp/odbc-test/Makefile.am
+++ b/modules/platforms/cpp/odbc-test/Makefile.am
@@ -46,7 +46,8 @@ ignite_odbc_tests_LDADD = \
     @top_srcdir@/core/libignite.la \
     -ldl \
     -lodbc \
-    -lpthread
+    -lpthread \
+    -lboost_regex
 
 ignite_odbc_tests_LDFLAGS = \
     -static-libtool-libs

http://git-wip-us.apache.org/repos/asf/ignite/blob/29ce1fa8/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj
index ceecb3d..d06064b 100644
--- a/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj
+++ b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj
@@ -97,7 +97,7 @@
     </ClCompile>
     <Link>
       <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>$(JAVA_HOME)\lib\jvm.lib;$(BOOST_HOME)\lib32-msvc-10.0\libboost_unit_test_framework-vc100-mt-gd-1_58.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>$(JAVA_HOME)\lib\jvm.lib;$(BOOST_HOME)\lib32-msvc-10.0\libboost_unit_test_framework-vc100-mt-gd-1_58.lib;$(BOOST_HOME)\lib32-msvc-10.0\libboost_regex-vc100-mt-gd-1_58.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -111,7 +111,7 @@
     </ClCompile>
     <Link>
       <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>$(JAVA_HOME)\lib\jvm.lib;$(BOOST_HOME)\lib64-msvc-10.0\libboost_unit_test_framework-vc100-mt-gd-1_58.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>$(JAVA_HOME)\lib\jvm.lib;$(BOOST_HOME)\lib64-msvc-10.0\libboost_unit_test_framework-vc100-mt-gd-1_58.lib;$(BOOST_HOME)\lib64-msvc-10.0\libboost_regex-vc100-mt-gd-1_58.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <SubSystem>Console</SubSystem>
     </Link>
   </ItemDefinitionGroup>
@@ -130,7 +130,7 @@
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
-      <AdditionalDependencies>$(JAVA_HOME)\lib\jvm.lib;$(BOOST_HOME)\lib32-msvc-10.0\libboost_unit_test_framework-vc100-mt-1_58.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>$(JAVA_HOME)\lib\jvm.lib;$(BOOST_HOME)\lib32-msvc-10.0\libboost_unit_test_framework-vc100-mt-1_58.lib;$(BOOST_HOME)\lib32-msvc-10.0\libboost_regex-vc100-mt-1_58.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -148,7 +148,7 @@
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
-      <AdditionalDependencies>$(JAVA_HOME)\lib\jvm.lib;$(BOOST_HOME)\lib64-msvc-10.0\libboost_unit_test_framework-vc100-mt-1_58.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>$(JAVA_HOME)\lib\jvm.lib;$(BOOST_HOME)\lib64-msvc-10.0\libboost_unit_test_framework-vc100-mt-1_58.lib;$(BOOST_HOME)\lib64-msvc-10.0\libboost_regex-vc100-mt-1_58.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>

http://git-wip-us.apache.org/repos/asf/ignite/blob/29ce1fa8/modules/platforms/cpp/odbc-test/src/queries_test.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/odbc-test/src/queries_test.cpp b/modules/platforms/cpp/odbc-test/src/queries_test.cpp
index c7892ac..3dc538b 100644
--- a/modules/platforms/cpp/odbc-test/src/queries_test.cpp
+++ b/modules/platforms/cpp/odbc-test/src/queries_test.cpp
@@ -30,6 +30,7 @@
 #   define BOOST_TEST_DYN_LINK
 #endif
 
+#include <boost/regex.hpp>
 #include <boost/test/unit_test.hpp>
 
 #include "ignite/ignite.h"
@@ -1650,7 +1651,7 @@ BOOST_AUTO_TEST_CASE(TestInsertBatchSelect1000)
 
 BOOST_AUTO_TEST_CASE(TestInsertBatchSelect1023)
 {
-    InsertBatchSelect(1024);
+    InsertBatchSelect(1023);
 }
 
 BOOST_AUTO_TEST_CASE(TestInsertBatchSelect1024)
@@ -1670,7 +1671,7 @@ BOOST_AUTO_TEST_CASE(TestInsertBatchSelect2000)
 
 BOOST_AUTO_TEST_CASE(TestInsertBatchSelect2047)
 {
-    InsertBatchSelect(2048);
+    InsertBatchSelect(2047);
 }
 
 BOOST_AUTO_TEST_CASE(TestInsertBatchSelect2048)
@@ -2098,4 +2099,23 @@ BOOST_AUTO_TEST_CASE(TestBindNullParameter)
     BOOST_CHECK_EQUAL(strFieldLen, SQL_NULL_DATA);
 }
 
+BOOST_AUTO_TEST_CASE(TestErrorMessage)
+{
+    Connect("DRIVER={Apache Ignite};ADDRESS=127.0.0.1:11110;SCHEMA=cache");
+
+    // Just selecting everything to make sure everything is OK
+    SQLCHAR selectReq[] = "SELECT a FROM B";
+
+    SQLRETURN ret = SQLExecDirect(stmt, selectReq, sizeof(selectReq));
+
+    BOOST_REQUIRE_EQUAL(ret, SQL_ERROR);
+
+    std::string error = GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt);
+    std::string pattern = "HY000: Table \"B\" not found; SQL statement:\\vSELECT a FROM B.*";
+
+    boost::cmatch what;
+    if (!boost::regex_match(error.c_str(), what, boost::regex(pattern)))
+        BOOST_FAIL("'" + error + "' does not match '" + pattern + "'");
+}
+
 BOOST_AUTO_TEST_SUITE_END()


Mime
View raw message