File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -1101,3 +1101,50 @@ func TestLocked(T *testing.T) {
1101
1101
t .Fatalf ("expected SQLITE_LOCKED" )
1102
1102
}
1103
1103
}
1104
+
1105
+ func TestWithTx (T * testing.T ) {
1106
+ t := begin (T )
1107
+ conn , err := Open (":memory:" , OPEN_READWRITE )
1108
+ if err != nil {
1109
+ t .Fatalf ("failed to open" )
1110
+ }
1111
+
1112
+ err = conn .Exec (`CREATE TABLE student(name STRING, age INTEGER)` )
1113
+ if err != nil {
1114
+ t .Fatalf ("failed to create table" )
1115
+ }
1116
+
1117
+ conn .WithTx (func () error {
1118
+ err = conn .Exec (`INSERT INTO student VALUES (?, ?)` , "Bob" , 18 )
1119
+ if err != nil {
1120
+ return err
1121
+ }
1122
+ return nil
1123
+ })
1124
+ if err != nil {
1125
+ t .Fatalf ("failed to insert student" )
1126
+ }
1127
+
1128
+ conn .WithTxExclusive (func () error {
1129
+ err = conn .Exec (`INSERT INTO student VALUES (?, ?)` , "Bob" , 18 )
1130
+ if err != nil {
1131
+ return err
1132
+ }
1133
+ return nil
1134
+ })
1135
+ if err != nil {
1136
+ t .Fatalf ("failed to insert student" )
1137
+ }
1138
+
1139
+ conn .WithTxImmediate (func () error {
1140
+ err = conn .Exec (`INSERT INTO student VALUES (?, ?)` , "Bob" , 18 )
1141
+ if err != nil {
1142
+ return err
1143
+ }
1144
+ return nil
1145
+ })
1146
+ if err != nil {
1147
+ t .Fatalf ("failed to insert student" )
1148
+ }
1149
+
1150
+ }
You can’t perform that action at this time.
0 commit comments