mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-12-01 21:40:25 +08:00
fix: 使用最新版 vitess sqlparser 解析 SQL 语句
解决 xwb1989/sqlparser 不支持 current_timestamp() 的问题
This commit is contained in:
@@ -3,7 +3,6 @@ package api
|
||||
import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -54,37 +53,3 @@ func Test_escapeSql(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_SplitSqls(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "create table with current_timestamp",
|
||||
input: "create table tbl (\n\tcreate_at datetime default current_timestamp()\n)",
|
||||
},
|
||||
{
|
||||
name: "create table with current_date",
|
||||
input: "create table tbl (\n\tcreate_at date default current_date()\n)",
|
||||
},
|
||||
{
|
||||
name: "select with ';\n'",
|
||||
input: "select 'the first line;\nthe second line;\n'",
|
||||
// SplitSqls split statements by ';\n'
|
||||
want: "select 'the first line;\n",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
scanner := SplitSqls(strings.NewReader(test.input))
|
||||
require.True(t, scanner.Scan())
|
||||
got := scanner.Text()
|
||||
if len(test.want) == 0 {
|
||||
test.want = test.input
|
||||
}
|
||||
require.Equal(t, test.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user