@@ -198,6 +198,15 @@ suite('DatabaseSync limits', () => {
198198 } ) ;
199199 } ) ;
200200
201+ test ( 'throws on Infinity limit value in constructor' , ( t ) => {
202+ t . assert . throws ( ( ) => {
203+ new DatabaseSync ( ':memory:' , { limits : { length : Infinity } } ) ;
204+ } , {
205+ name : 'TypeError' ,
206+ message : / o p t i o n s \. l i m i t s \. l e n g t h .* m u s t b e a n i n t e g e r / ,
207+ } ) ;
208+ } ) ;
209+
201210 test ( 'partial limits in constructor' , ( t ) => {
202211 const db = new DatabaseSync ( ':memory:' , {
203212 limits : {
@@ -223,4 +232,73 @@ suite('DatabaseSync limits', () => {
223232 message : / t o o m a n y c o l u m n s / ,
224233 } ) ;
225234 } ) ;
235+
236+ test ( 'throws when exceeding attach limit' , ( t ) => {
237+ const db = new DatabaseSync ( ':memory:' , {
238+ limits : {
239+ attach : 0 ,
240+ }
241+ } ) ;
242+
243+ t . assert . throws ( ( ) => {
244+ db . exec ( "ATTACH DATABASE ':memory:' AS db1" ) ;
245+ } , {
246+ message : / t o o m a n y a t t a c h e d d a t a b a s e s / ,
247+ } ) ;
248+ } ) ;
249+
250+ test ( 'throws when exceeding variable number limit' , ( t ) => {
251+ const db = new DatabaseSync ( ':memory:' , {
252+ limits : {
253+ variableNumber : 2 ,
254+ }
255+ } ) ;
256+
257+ t . assert . throws ( ( ) => {
258+ const stmt = db . prepare ( 'SELECT ?, ?, ?' ) ;
259+ stmt . all ( 1 , 2 , 3 ) ;
260+ } , {
261+ message : / t o o m a n y S Q L v a r i a b l e s / ,
262+ } ) ;
263+ } ) ;
264+
265+ test ( 'throws when exceeding compound select limit' , ( t ) => {
266+ const db = new DatabaseSync ( ':memory:' , {
267+ limits : {
268+ compoundSelect : 1 ,
269+ }
270+ } ) ;
271+
272+ t . assert . throws ( ( ) => {
273+ db . exec ( 'SELECT 1 UNION SELECT 2 UNION SELECT 3' ) ;
274+ } , {
275+ message : / t o o m a n y t e r m s i n c o m p o u n d S E L E C T / ,
276+ } ) ;
277+ } ) ;
278+
279+ test ( 'throws when exceeding function arg limit' , ( t ) => {
280+ const db = new DatabaseSync ( ':memory:' , {
281+ limits : {
282+ functionArg : 2 ,
283+ }
284+ } ) ;
285+
286+ t . assert . throws ( ( ) => {
287+ db . exec ( 'SELECT max(1, 2, 3)' ) ;
288+ } , {
289+ message : / t o o m a n y a r g u m e n t s o n f u n c t i o n m a x / ,
290+ } ) ;
291+ } ) ;
292+
293+ test ( 'setter applies limit to SQLite immediately' , ( t ) => {
294+ const db = new DatabaseSync ( ':memory:' ) ;
295+
296+ db . limits . attach = 0 ;
297+
298+ t . assert . throws ( ( ) => {
299+ db . exec ( "ATTACH DATABASE ':memory:' AS db1" ) ;
300+ } , {
301+ message : / t o o m a n y a t t a c h e d d a t a b a s e s / ,
302+ } ) ;
303+ } ) ;
226304} ) ;
0 commit comments