bingding/mysql: add select JSON_EXTRACT LONGTEXT column type to special case (#1486)
Signed-off-by: zdianjiang <zdianjiang@gmail.com> Co-authored-by: Bernd Verst <4535280+berndverst@users.noreply.github.com>
This commit is contained in:
parent
625f955fee
commit
4302917ee5
|
|
@ -339,7 +339,7 @@ func (m *Mysql) convert(columnTypes []*sql.ColumnType, values []interface{}) map
|
||||||
case *sql.RawBytes:
|
case *sql.RawBytes:
|
||||||
// special case for sql.RawBytes, see https://github.com/go-sql-driver/mysql/blob/master/fields.go#L178
|
// special case for sql.RawBytes, see https://github.com/go-sql-driver/mysql/blob/master/fields.go#L178
|
||||||
switch ct.DatabaseTypeName() {
|
switch ct.DatabaseTypeName() {
|
||||||
case "VARCHAR", "CHAR", "TEXT":
|
case "VARCHAR", "CHAR", "TEXT", "LONGTEXT":
|
||||||
value = string(*v)
|
value = string(*v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ const (
|
||||||
testDelete = "DELETE FROM foo"
|
testDelete = "DELETE FROM foo"
|
||||||
testUpdate = "UPDATE foo SET ts = '%v' WHERE id = %d"
|
testUpdate = "UPDATE foo SET ts = '%v' WHERE id = %d"
|
||||||
testSelect = "SELECT * FROM foo WHERE id < 3"
|
testSelect = "SELECT * FROM foo WHERE id < 3"
|
||||||
|
testSelectJSONExtract = "SELECT JSON_EXTRACT(data, '$.key') AS `key` FROM foo WHERE id < 3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestOperations(t *testing.T) {
|
func TestOperations(t *testing.T) {
|
||||||
|
|
@ -140,6 +141,22 @@ func TestMysqlIntegration(t *testing.T) {
|
||||||
t.Logf("time stamp is: %v", tt)
|
t.Logf("time stamp is: %v", tt)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("Invoke select JSON_EXTRACT", func(t *testing.T) {
|
||||||
|
req.Operation = queryOperation
|
||||||
|
req.Metadata[commandSQLKey] = testSelectJSONExtract
|
||||||
|
res, err := b.Invoke(req)
|
||||||
|
assertResponse(t, res, err)
|
||||||
|
t.Logf("received result: %s", res.Data)
|
||||||
|
|
||||||
|
// verify json extract number
|
||||||
|
assert.Contains(t, string(res.Data), "{\"key\":\"\\\"val\\\"\"}")
|
||||||
|
|
||||||
|
result := make([]interface{}, 0)
|
||||||
|
err = json.Unmarshal(res.Data, &result)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, 3, len(result))
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("Invoke delete", func(t *testing.T) {
|
t.Run("Invoke delete", func(t *testing.T) {
|
||||||
req.Operation = execOperation
|
req.Operation = execOperation
|
||||||
req.Metadata[commandSQLKey] = testDelete
|
req.Metadata[commandSQLKey] = testDelete
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue