@@ -778,6 +778,66 @@ func TestTransaction(t *testing.T) {
778
778
}
779
779
}
780
780
781
+ func TestTableLockedError (t * testing.T ) {
782
+ tempFilename := TempFilename (t )
783
+ defer os .Remove (tempFilename )
784
+ dsn := fmt .Sprintf ("file:%s?cache=shared&mode=rwc&_busy_timeout=%d" , tempFilename , 500 )
785
+ db , err := sql .Open ("sqlite3" , dsn )
786
+ if err != nil {
787
+ t .Fatal ("Failed to open database:" , err )
788
+ }
789
+ defer db .Close ()
790
+
791
+ _ , err = db .Exec ("CREATE TABLE foo(id INTEGER, status INTEGER)" )
792
+ if err != nil {
793
+ t .Fatal ("Failed to create table:" , err )
794
+ }
795
+
796
+ tx , err := db .Begin ()
797
+ if err != nil {
798
+ t .Fatal ("Failed to begin transaction:" , err )
799
+ }
800
+
801
+ _ , err = tx .Exec ("INSERT INTO foo(id, status) VALUES(1, 100)" )
802
+ if err != nil {
803
+ t .Fatal ("Failed to insert null:" , err )
804
+ }
805
+
806
+ _ , err = tx .Exec ("UPDATE foo SET status = 200 WHERE id = 1" )
807
+ if err != nil {
808
+ t .Fatal ("Failed to update table:" , err )
809
+ }
810
+
811
+ wg := sync.WaitGroup {}
812
+ wg .Add (1 )
813
+ timer := time .NewTimer (500 * time .Millisecond )
814
+ go func () {
815
+ <- timer .C
816
+ err := tx .Commit ()
817
+ if err != nil {
818
+ t .Fatal ("Failed to commit transaction:" , err )
819
+ }
820
+ wg .Done ()
821
+ }()
822
+
823
+ rows , err := db .Query ("SELECT count(*) from foo" )
824
+ if err != nil {
825
+ t .Fatal ("Unable to query foo table:" , err )
826
+ }
827
+
828
+ if rows .Next () {
829
+ var count int
830
+ if err := rows .Scan (& count ); err != nil {
831
+ t .Fatal ("Failed to Scan rows" , err )
832
+ }
833
+ }
834
+ if err := rows .Err (); err != nil {
835
+ t .Fatal ("Failed at the call to Next:" , err )
836
+ }
837
+ wg .Wait ()
838
+
839
+ }
840
+
781
841
func TestWAL (t * testing.T ) {
782
842
tempFilename := TempFilename (t )
783
843
defer os .Remove (tempFilename )
0 commit comments