xorm/session_cols_test.go

38 lines
760 B
Go
Raw Normal View History

2017-03-23 06:05:32 +00:00
// Copyright 2017 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 xorm
2017-05-27 09:31:39 +00:00
import (
"testing"
"github.com/go-xorm/core"
2017-05-27 09:31:39 +00:00
"github.com/stretchr/testify/assert"
)
2017-03-23 06:05:32 +00:00
func TestSetExpr(t *testing.T) {
2017-05-27 09:31:39 +00:00
assert.NoError(t, prepareEngine())
2017-03-23 06:05:32 +00:00
type User struct {
Id int64
Show bool
}
2017-05-27 09:31:39 +00:00
assert.NoError(t, testEngine.Sync2(new(User)))
cnt, err := testEngine.Insert(&User{
Show: true,
})
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)
var not = "NOT"
if testEngine.dialect.DBType() == core.MSSQL {
not = "~"
}
cnt, err = testEngine.SetExpr("show", not+" `show`").Id(1).Update(new(User))
2017-05-27 09:31:39 +00:00
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)
2017-03-23 06:05:32 +00:00
}