session_raw_test.go 1008 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. "strconv"
  7. "testing"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestExecAndQuery(t *testing.T) {
  11. assert.NoError(t, prepareEngine())
  12. type UserinfoQuery struct {
  13. Uid int
  14. Name string
  15. }
  16. assert.NoError(t, testEngine.Sync2(new(UserinfoQuery)))
  17. res, err := testEngine.Exec("INSERT INTO "+testEngine.TableName("`userinfo_query`", true)+" (uid, name) VALUES (?, ?)", 1, "user")
  18. assert.NoError(t, err)
  19. cnt, err := res.RowsAffected()
  20. assert.NoError(t, err)
  21. assert.EqualValues(t, 1, cnt)
  22. results, err := testEngine.Query("select * from " + testEngine.TableName("userinfo_query", true))
  23. assert.NoError(t, err)
  24. assert.EqualValues(t, 1, len(results))
  25. id, err := strconv.Atoi(string(results[0]["uid"]))
  26. assert.NoError(t, err)
  27. assert.EqualValues(t, 1, id)
  28. assert.Equal(t, "user", string(results[0]["name"]))
  29. }