session_cols_test.go 761 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2017 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package xorm
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. "github.com/xormplus/core"
  9. )
  10. func TestSetExpr(t *testing.T) {
  11. assert.NoError(t, prepareEngine())
  12. type User struct {
  13. Id int64
  14. Show bool
  15. }
  16. assert.NoError(t, testEngine.Sync2(new(User)))
  17. cnt, err := testEngine.Insert(&User{
  18. Show: true,
  19. })
  20. assert.NoError(t, err)
  21. assert.EqualValues(t, 1, cnt)
  22. var not = "NOT"
  23. if testEngine.dialect.DBType() == core.MSSQL {
  24. not = "~"
  25. }
  26. cnt, err = testEngine.SetExpr("show", not+" `show`").Id(1).Update(new(User))
  27. assert.NoError(t, err)
  28. assert.EqualValues(t, 1, cnt)
  29. }