@@ -67,6 +67,18 @@ suite('StatementSync.prototype.get()', () => {
6767 __proto__ : null , key : 'key1' , val : 'val1' ,
6868 } ) ;
6969 } ) ;
70+
71+ test ( 'throws if the statement is already finalized' , ( t ) => {
72+ using db = new DatabaseSync ( ':memory:' ) ;
73+ const stmt = db . prepare ( 'CREATE TABLE storage(key TEXT, val TEXT)' ) ;
74+ stmt . close ( ) ;
75+ t . assert . throws ( ( ) => {
76+ stmt . get ( ) ;
77+ } , {
78+ code : 'ERR_INVALID_STATE' ,
79+ message : / s t a t e m e n t h a s b e e n f i n a l i z e d / ,
80+ } ) ;
81+ } ) ;
7082} ) ;
7183
7284suite ( 'StatementSync.prototype.all()' , ( ) => {
@@ -120,6 +132,18 @@ suite('StatementSync.prototype.all()', () => {
120132 { __proto__ : null , key : 'key1' , val : 'val1' } ,
121133 ] ) ;
122134 } ) ;
135+
136+ test ( 'throws if the statement is already finalized' , ( t ) => {
137+ using db = new DatabaseSync ( ':memory:' ) ;
138+ const stmt = db . prepare ( 'CREATE TABLE storage(key TEXT, val TEXT)' ) ;
139+ stmt . close ( ) ;
140+ t . assert . throws ( ( ) => {
141+ stmt . all ( ) ;
142+ } , {
143+ code : 'ERR_INVALID_STATE' ,
144+ message : / s t a t e m e n t h a s b e e n f i n a l i z e d / ,
145+ } ) ;
146+ } ) ;
123147} ) ;
124148
125149suite ( 'StatementSync.prototype.iterate()' , ( ) => {
@@ -286,6 +310,18 @@ suite('StatementSync.prototype.iterate()', () => {
286310 stmt2 . get ( ) ;
287311 it . next ( ) ;
288312 } ) ;
313+
314+ test ( 'throws if the statement is already finalized' , ( t ) => {
315+ using db = new DatabaseSync ( ':memory:' ) ;
316+ const stmt = db . prepare ( 'CREATE TABLE storage(key TEXT, val TEXT)' ) ;
317+ stmt . close ( ) ;
318+ t . assert . throws ( ( ) => {
319+ stmt . iterate ( ) ;
320+ } , {
321+ code : 'ERR_INVALID_STATE' ,
322+ message : / s t a t e m e n t h a s b e e n f i n a l i z e d / ,
323+ } ) ;
324+ } ) ;
289325} ) ;
290326
291327suite ( 'StatementSync.prototype.run()' , ( ) => {
@@ -385,6 +421,18 @@ suite('StatementSync.prototype.run()', () => {
385421 const stmt = db . prepare ( 'INSERT INTO data (key, val) VALUES (?1, ?2)' ) ;
386422 t . assert . deepStrictEqual ( stmt . run ( 1 , 2 ) , { changes : 1 , lastInsertRowid : 1 } ) ;
387423 } ) ;
424+
425+ test ( 'throws if the statement is already finalized' , ( t ) => {
426+ using db = new DatabaseSync ( ':memory:' ) ;
427+ const stmt = db . prepare ( 'CREATE TABLE storage(key TEXT, val TEXT)' ) ;
428+ stmt . close ( ) ;
429+ t . assert . throws ( ( ) => {
430+ stmt . run ( ) ;
431+ } , {
432+ code : 'ERR_INVALID_STATE' ,
433+ message : / s t a t e m e n t h a s b e e n f i n a l i z e d / ,
434+ } ) ;
435+ } ) ;
388436} ) ;
389437
390438suite ( 'StatementSync.prototype.sourceSQL' , ( ) => {
@@ -399,6 +447,16 @@ suite('StatementSync.prototype.sourceSQL', () => {
399447 const stmt = db . prepare ( sql ) ;
400448 t . assert . strictEqual ( stmt . sourceSQL , sql ) ;
401449 } ) ;
450+
451+ test ( 'throws if the statement is already finalized' , ( t ) => {
452+ using db = new DatabaseSync ( ':memory:' ) ;
453+ const stmt = db . prepare ( 'CREATE TABLE storage(key TEXT, val TEXT)' ) ;
454+ stmt . close ( ) ;
455+ t . assert . throws ( ( ) => stmt . sourceSQL , {
456+ code : 'ERR_INVALID_STATE' ,
457+ message : / s t a t e m e n t h a s b e e n f i n a l i z e d / ,
458+ } ) ;
459+ } ) ;
402460} ) ;
403461
404462suite ( 'StatementSync.prototype.expandedSQL' , ( ) => {
@@ -418,6 +476,16 @@ suite('StatementSync.prototype.expandedSQL', () => {
418476 ) ;
419477 t . assert . strictEqual ( stmt . expandedSQL , expanded ) ;
420478 } ) ;
479+
480+ test ( 'throws if the statement is already finalized' , ( t ) => {
481+ using db = new DatabaseSync ( ':memory:' ) ;
482+ const stmt = db . prepare ( 'CREATE TABLE storage(key TEXT, val TEXT)' ) ;
483+ stmt . close ( ) ;
484+ t . assert . throws ( ( ) => stmt . expandedSQL , {
485+ code : 'ERR_INVALID_STATE' ,
486+ message : / s t a t e m e n t h a s b e e n f i n a l i z e d / ,
487+ } ) ;
488+ } ) ;
421489} ) ;
422490
423491suite ( 'StatementSync.prototype.setReadBigInts()' , ( ) => {
@@ -487,6 +555,18 @@ suite('StatementSync.prototype.setReadBigInts()', () => {
487555 [ `${ Number . MAX_SAFE_INTEGER } + 1` ] : 2n ** 53n ,
488556 } ) ;
489557 } ) ;
558+
559+ test ( 'throws if the statement is already finalized' , ( t ) => {
560+ using db = new DatabaseSync ( ':memory:' ) ;
561+ const stmt = db . prepare ( 'CREATE TABLE storage(key TEXT, val TEXT)' ) ;
562+ stmt . close ( ) ;
563+ t . assert . throws ( ( ) => {
564+ stmt . setReadBigInts ( true ) ;
565+ } , {
566+ code : 'ERR_INVALID_STATE' ,
567+ message : / s t a t e m e n t h a s b e e n f i n a l i z e d / ,
568+ } ) ;
569+ } ) ;
490570} ) ;
491571
492572suite ( 'StatementSync.prototype.setReturnArrays()' , ( ) => {
@@ -505,6 +585,18 @@ suite('StatementSync.prototype.setReturnArrays()', () => {
505585 message : / T h e " r e t u r n A r r a y s " a r g u m e n t m u s t b e a b o o l e a n / ,
506586 } ) ;
507587 } ) ;
588+
589+ test ( 'throws if the statement is already finalized' , ( t ) => {
590+ using db = new DatabaseSync ( ':memory:' ) ;
591+ const stmt = db . prepare ( 'CREATE TABLE storage(key TEXT, val TEXT)' ) ;
592+ stmt . close ( ) ;
593+ t . assert . throws ( ( ) => {
594+ stmt . setReturnArrays ( true ) ;
595+ } , {
596+ code : 'ERR_INVALID_STATE' ,
597+ message : / s t a t e m e n t h a s b e e n f i n a l i z e d / ,
598+ } ) ;
599+ } ) ;
508600} ) ;
509601
510602suite ( 'StatementSync.prototype.get() with array output' , ( ) => {
@@ -723,6 +815,18 @@ suite('StatementSync.prototype.setAllowBareNamedParameters()', () => {
723815 message : / T h e " a l l o w B a r e N a m e d P a r a m e t e r s " a r g u m e n t m u s t b e a b o o l e a n / ,
724816 } ) ;
725817 } ) ;
818+
819+ test ( 'throws if the statement is already finalized' , ( t ) => {
820+ using db = new DatabaseSync ( ':memory:' ) ;
821+ const stmt = db . prepare ( 'CREATE TABLE storage(key TEXT, val TEXT)' ) ;
822+ stmt . close ( ) ;
823+ t . assert . throws ( ( ) => {
824+ stmt . setAllowBareNamedParameters ( true ) ;
825+ } , {
826+ code : 'ERR_INVALID_STATE' ,
827+ message : / s t a t e m e n t h a s b e e n f i n a l i z e d / ,
828+ } ) ;
829+ } ) ;
726830} ) ;
727831
728832suite ( 'options.readBigInts' , ( ) => {
@@ -971,6 +1075,31 @@ suite('options.allowBareNamedParameters', () => {
9711075} ) ;
9721076
9731077
1078+ suite ( 'StatementSync.prototype.close()' , ( ) => {
1079+ test ( 'finalizes an open statement' , ( t ) => {
1080+ using db = new DatabaseSync ( ':memory:' ) ;
1081+ db . exec ( 'CREATE TABLE storage(key TEXT, val TEXT)' ) ;
1082+ const stmt = db . prepare ( 'SELECT * FROM storage' ) ;
1083+ t . assert . strictEqual ( stmt . close ( ) , undefined ) ;
1084+ t . assert . throws ( ( ) => stmt . get ( ) , {
1085+ code : 'ERR_INVALID_STATE' ,
1086+ message : / s t a t e m e n t h a s b e e n f i n a l i z e d / ,
1087+ } ) ;
1088+ } ) ;
1089+
1090+ test ( 'throws if the statement is already finalized' , ( t ) => {
1091+ using db = new DatabaseSync ( ':memory:' ) ;
1092+ const stmt = db . prepare ( 'CREATE TABLE storage(key TEXT, val TEXT)' ) ;
1093+ stmt . close ( ) ;
1094+ t . assert . throws ( ( ) => {
1095+ stmt . close ( ) ;
1096+ } , {
1097+ code : 'ERR_INVALID_STATE' ,
1098+ message : / s t a t e m e n t h a s b e e n f i n a l i z e d / ,
1099+ } ) ;
1100+ } ) ;
1101+ } ) ;
1102+
9741103suite ( 'StatementSync.prototype[Symbol.dispose]()' , ( ) => {
9751104 test ( 'finalizes an open statement' , ( t ) => {
9761105 using db = new DatabaseSync ( ':memory:' ) ;
0 commit comments