You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2017/08/11 01:50:23 UTC
[26/50] calcite-avatica-go git commit: Fix regex that parses error
code and sql codes to accept alphanumeric sql codes.
Fix regex that parses error code and sql codes to accept alphanumeric sql codes.
Project: http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/commit/8d883c97
Tree: http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/tree/8d883c97
Diff: http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/diff/8d883c97
Branch: refs/heads/master
Commit: 8d883c97a4138002cdeaf2e6a6cde26567579854
Parents: 4e1ded8
Author: Francis Chuang <fr...@boostport.com>
Authored: Thu Oct 6 16:59:10 2016 +1100
Committer: Julian Hyde <jh...@apache.org>
Committed: Thu Aug 10 18:47:10 2017 -0700
----------------------------------------------------------------------
driver_test.go | 27 +++++++++++++++++++++++++++
errors.go | 2 +-
2 files changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/blob/8d883c97/driver_test.go
----------------------------------------------------------------------
diff --git a/driver_test.go b/driver_test.go
index 4cc1661..017920b 100644
--- a/driver_test.go
+++ b/driver_test.go
@@ -1006,3 +1006,30 @@ func TestMultipleSchemaSupport(t *testing.T) {
}
})
}
+
+func TestErrorCodeParsing(t *testing.T) {
+
+ db, err := sql.Open("avatica", dsn)
+
+ if err != nil {
+ t.Fatalf("error connecting: %s", err.Error())
+ }
+
+ defer db.Close()
+
+ _, err = db.Query("SELECT * FROM table_that_does_not_exist")
+
+ if err == nil {
+ t.Error("Expected error due to selecting from non-existent table, but there was no error.")
+ }
+
+ resErr := err.(ResponseError)
+
+ if resErr.ErrorCode != 1012 {
+ t.Errorf("Expected error code to be %d, got %d.", 1012, resErr.ErrorCode)
+ }
+
+ if resErr.SqlState != "42M03" {
+ t.Errorf("Expected SQL state to be %s, got %s.", "42M03", resErr.SqlState)
+ }
+}
http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/blob/8d883c97/errors.go
----------------------------------------------------------------------
diff --git a/errors.go b/errors.go
index abef290..52981e3 100644
--- a/errors.go
+++ b/errors.go
@@ -61,7 +61,7 @@ func errorResponseToResponseError(message *message.ErrorResponse) ResponseError
sqlState string
)
- re := regexp.MustCompile(`ERROR (\d+) \((\d+)\)`)
+ re := regexp.MustCompile(`ERROR (\d+) \(([0-9a-zA-Z]+)\)`)
codes := re.FindStringSubmatch(message.ErrorMessage)
if len(codes) > 1 {