Skip to content

Commit

Permalink
fix: issue gogf#4106
Browse files Browse the repository at this point in the history
  • Loading branch information
sanrentai committed Jan 9, 2025
1 parent a233eca commit 972734b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions contrib/drivers/mssql/mssql_do_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func (d *Driver) parseSql(toBeCommittedSql string) (string, error) {
}

func (d *Driver) handleSelectSqlReplacement(toBeCommittedSql string) (newSql string, err error) {
toBeCommittedSql, err = gdb.FormatMultiLineSqlToSingle(toBeCommittedSql)
if err != nil {
return "", err
}
// SELECT * FROM USER WHERE ID=1 LIMIT 1
match, err := gregex.MatchString(`^SELECT(.+?)LIMIT\s+1$`, toBeCommittedSql)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions contrib/drivers/mssql/mssql_do_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ func TestDriver_handleSelectSqlReplacement(t *testing.T) {
d := &Driver{}

// LIMIT 1
inputSql := "SELECT * FROM User WHERE ID = 1 LIMIT 1"
expectedSql := "SELECT TOP 1 * FROM User WHERE ID = 1"
inputSql := `SELECT a,
b
FROM User WHERE ID = 1 LIMIT 1`
expectedSql := `SELECT TOP 1 a, b FROM User WHERE ID = 1`
resultSql, err := d.handleSelectSqlReplacement(inputSql)
t.AssertNil(err)
t.Assert(resultSql, expectedSql)
Expand Down

0 comments on commit 972734b

Please sign in to comment.