Skip to content

Commit 1c4141e

Browse files
authored
Merge pull request #3 from actiontech/fix_refid_not_found_panic
fix panic when refid not found
2 parents 8d94d78 + 0bf0c9e commit 1c4141e

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

ast/include.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ func (i *IncludeNode) GetStmt(ctx *Context) (string, error) {
6969
refId = variable
7070
}
7171
sql, ok := ctx.GetSql(refId)
72-
if ok {
73-
fmt.Errorf("sql %s is not exist", refId)
72+
if !ok {
73+
return "", fmt.Errorf("sql %s is not exist", refId)
7474
}
7575
data, err := sql.GetStmt(ctx)
7676
if err != nil {

parser_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,3 +550,25 @@ func TestParseInvalidInput(t *testing.T) {
550550
t.Error("expect has error, but no error")
551551
}
552552
}
553+
554+
// fix issue: https://github.com/actiontech/sqle/issues/189
555+
func TestParserSQLRefIdNotFound(t *testing.T) {
556+
_, err := ParseXML(
557+
`
558+
<mapper namespace="Test">
559+
<sql id="someinclude">
560+
*
561+
</sql>
562+
<select id="select" resultType="map">
563+
select
564+
<include refid="someinclude2" />
565+
from t
566+
</select>
567+
</mapper>`)
568+
if err == nil {
569+
t.Errorf("expect has error, but no error")
570+
}
571+
if err.Error() != "sql someinclude2 is not exist" {
572+
t.Errorf("actual error is [%s]", err.Error())
573+
}
574+
}

0 commit comments

Comments
 (0)