Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions enginetest/enginetests.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func TestQueryErrors(t *testing.T, harness Harness) {
t.Skipf("skipping query %s", tt.Query)
}
}
AssertErrWithBindings(t, engine, harness, tt.Query, tt.Bindings, tt.ExpectedErr)
AssertErrWithBindings(t, engine, harness, tt.Query, tt.Bindings, tt.ExpectedErr, tt.ExpectedErrStr)
})
}
}
Expand Down Expand Up @@ -2979,9 +2979,7 @@ func AssertErrWithBindings(t *testing.T, e *sqle.Engine, harness Harness, query
require.Error(t, err)
if expectedErrKind != nil {
require.True(t, expectedErrKind.Is(err), "Expected error of type %s but got %s", expectedErrKind, err)
}
// If there are multiple error strings then we only match against the first
if len(errStrs) >= 1 {
} else if len(errStrs) >= 1 {
require.Equal(t, errStrs[0], err.Error())
}

Expand Down
23 changes: 20 additions & 3 deletions enginetest/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -2704,6 +2704,14 @@ var QueryTests = []QueryTest{
Query: `SELECT JSON_UNQUOTE(JSON_EXTRACT('{"xid":null}', '$.xid'))`,
Expected: []sql.Row{{"null"}},
},
{
Query: `select JSON_EXTRACT('{"id":234}', '$.id')-1;`,
Expected: []sql.Row{{233.0}},
},
{
Query: `select JSON_EXTRACT('{"id":234}', '$.id') = 234;`,
Expected: []sql.Row{{true}},
},
{
Query: `SELECT CONNECTION_ID()`,
Expected: []sql.Row{{uint32(1)}},
Expand Down Expand Up @@ -5895,9 +5903,10 @@ var ExplodeQueries = []QueryTest{
}

type QueryErrorTest struct {
Query string
Bindings map[string]sql.Expression
ExpectedErr *errors.Kind
Query string
Bindings map[string]sql.Expression
ExpectedErr *errors.Kind
ExpectedErrStr string
}

var errorQueries = []QueryErrorTest{
Expand Down Expand Up @@ -6136,6 +6145,14 @@ var errorQueries = []QueryErrorTest{
Query: `SELECT JSON_OBJECT(1, 2) FROM dual`,
ExpectedErr: sql.ErrInvalidType,
},
{
Query: `select JSON_EXTRACT('{"id":"abc"}', '$.id')-1;`,
ExpectedErrStr: "unable to cast \"abc\" of type string to float64",
},
{
Query: `select JSON_EXTRACT('{"id":{"a": "abc"}}', '$.id')-1;`,
ExpectedErrStr: `unable to cast map[string]interface {}{"a":"abc"} of type map[string]interface {} to float64`,
},
}

// WriteQueryTest is a query test for INSERT, UPDATE, etc. statements. It has a query to run and a select query to
Expand Down
8 changes: 8 additions & 0 deletions sql/numbertype.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ func (t numberTypeImpl) Convert(v interface{}) (interface{}, error) {
v = ti.UTC().Unix()
}

if jv, ok := v.(JSONValue); ok {
jd, err := jv.Unmarshall(nil)
if err != nil {
return nil, err
}
v = jd.Val
}

switch t.baseType {
case sqltypes.Int8:
if dec, ok := v.(decimal.Decimal); ok {
Expand Down