mirror of
https://github.com/hanzoai/xorm.git
synced 2026-10-01 00:49:40 +00:00
Corrected a bug where statement GenExistSQL did not append the Alias when only the table name was present and no RefTable was specified. --------- Co-authored-by: Lunny Xiao <[email protected]> Reviewed-on: https://gitea.com/xorm/xorm/pulls/2505 Reviewed-by: Lunny Xiao <[email protected]> Co-authored-by: hsfish <[email protected]> Co-committed-by: hsfish <[email protected]>
25 lines
604 B
Go
25 lines
604 B
Go
// Copyright 2026 The Xorm Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package statements
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGenExistSQL(t *testing.T) {
|
|
statement, err := createTestStatement()
|
|
assert.NoError(t, err)
|
|
|
|
statement.RefTable = nil
|
|
statement.SetTable("testDB")
|
|
statement.Alias("tdb")
|
|
statement.Where(`tdb.id=1`)
|
|
sql, _, err := statement.GenExistSQL()
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, "SELECT 1 FROM `testDB` AS `tdb` WHERE (tdb.id=1) LIMIT 1", sql)
|
|
}
|