Skip to content

Commit

Permalink
Merge pull request #3 from actiontech/fix_refid_not_found_panic
Browse files Browse the repository at this point in the history
fix panic when refid not found
  • Loading branch information
sjjian authored Jan 26, 2022
2 parents 8d94d78 + 0bf0c9e commit 1c4141e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ast/include.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func (i *IncludeNode) GetStmt(ctx *Context) (string, error) {
refId = variable
}
sql, ok := ctx.GetSql(refId)
if ok {
fmt.Errorf("sql %s is not exist", refId)
if !ok {
return "", fmt.Errorf("sql %s is not exist", refId)
}
data, err := sql.GetStmt(ctx)
if err != nil {
Expand Down
22 changes: 22 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,3 +550,25 @@ func TestParseInvalidInput(t *testing.T) {
t.Error("expect has error, but no error")
}
}

// fix issue: https://github.com/actiontech/sqle/issues/189
func TestParserSQLRefIdNotFound(t *testing.T) {
_, err := ParseXML(
`
<mapper namespace="Test">
<sql id="someinclude">
*
</sql>
<select id="select" resultType="map">
select
<include refid="someinclude2" />
from t
</select>
</mapper>`)
if err == nil {
t.Errorf("expect has error, but no error")
}
if err.Error() != "sql someinclude2 is not exist" {
t.Errorf("actual error is [%s]", err.Error())
}
}

0 comments on commit 1c4141e

Please sign in to comment.