-
Notifications
You must be signed in to change notification settings - Fork 1
/
bool_test.go
69 lines (48 loc) · 1.71 KB
/
bool_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package sqle
import (
"database/sql"
"testing"
"github.com/stretchr/testify/require"
)
func TestBool(t *testing.T) {
d, err := sql.Open("sqlite3", "file::memory:")
require.NoError(t, err)
_, err = d.Exec("CREATE TABLE `users` (`id` int NOT NULL,`status` BIT(1), PRIMARY KEY (`id`))")
require.NoError(t, err)
result, err := d.Exec("INSERT INTO `users`(`id`, `status`) VALUES(?, ?)", 10, Bool(true))
require.NoError(t, err)
rows, err := result.RowsAffected()
require.NoError(t, err)
require.Equal(t, int64(1), rows)
result, err = d.Exec("INSERT INTO `users`(`id`, `status`) VALUES(?, ?)", 11, Bool(false))
require.NoError(t, err)
rows, err = result.RowsAffected()
require.NoError(t, err)
require.Equal(t, int64(1), rows)
result, err = d.Exec("INSERT INTO `users`(`id`, `status`) VALUES(?, ?)", 12, true)
require.NoError(t, err)
rows, err = result.RowsAffected()
require.NoError(t, err)
require.Equal(t, int64(1), rows)
result, err = d.Exec("INSERT INTO `users`(`id`, `status`) VALUES(?, ?)", 13, false)
require.NoError(t, err)
rows, err = result.RowsAffected()
require.NoError(t, err)
require.Equal(t, int64(1), rows)
var b1 Bool
err = d.QueryRow("SELECT `status` FROM `users` WHERE id=?", 10).Scan(&b1)
require.NoError(t, err)
require.EqualValues(t, true, b1)
var b2 Bool
err = d.QueryRow("SELECT `status` FROM `users` WHERE id=?", 11).Scan(&b2)
require.NoError(t, err)
require.EqualValues(t, false, b2)
var b3 Bool
err = d.QueryRow("SELECT `status` FROM `users` WHERE id=?", 12).Scan(&b3)
require.NoError(t, err)
require.EqualValues(t, true, b3)
var b4 Bool
err = d.QueryRow("SELECT `status` FROM `users` WHERE id=?", 13).Scan(&b4)
require.NoError(t, err)
require.EqualValues(t, false, b4)
}