@@ -252,8 +252,7 @@ describe('SQLite Connector Integration Tests', () => {
252252 SELECT COUNT(*) as total FROM users WHERE email LIKE 'multi%';
253253 ` , { } ) ;
254254
255- // Two writes then one read, matching both source order and SQLite's
256- // writes-then-reads execution order here.
255+ // Two writes then one read, in source order.
257256 expect ( result . resultSets ) . toHaveLength ( 3 ) ;
258257 expect ( result . resultSets [ 0 ] ) . toEqual ( {
259258 sql :
"INSERT INTO users (name, email, age) VALUES ('Multi User 1', '[email protected] ', 30)" , @@ -269,6 +268,30 @@ describe('SQLite Connector Integration Tests', () => {
269268 expect ( Number ( result . resultSets [ 2 ] . rows [ 0 ] . total ) ) . toBe ( 2 ) ;
270269 } ) ;
271270
271+ it ( 'should execute multi-statement batches in source order' , async ( ) => {
272+ await sqliteTest . connector . executeSQL ( `
273+ CREATE TABLE order_check (a INTEGER);
274+ INSERT INTO order_check VALUES (1), (2), (3);
275+ ` , { } ) ;
276+
277+ const result = await sqliteTest . connector . executeSQL ( `
278+ SELECT a AS before_delete FROM order_check ORDER BY a;
279+ DELETE FROM order_check;
280+ SELECT COUNT(*) AS after_delete FROM order_check;
281+ ` , { } ) ;
282+
283+ expect ( result . resultSets . map ( ( rs ) => rs . sql ) ) . toEqual ( [
284+ 'SELECT a AS before_delete FROM order_check ORDER BY a' ,
285+ 'DELETE FROM order_check' ,
286+ 'SELECT COUNT(*) AS after_delete FROM order_check' ,
287+ ] ) ;
288+ expect ( result . resultSets [ 0 ] . rows . map ( ( row ) => Number ( row . before_delete ) ) ) . toEqual ( [ 1 , 2 , 3 ] ) ;
289+ expect ( result . resultSets [ 1 ] . rowCount ) . toBe ( 3 ) ;
290+ expect ( Number ( result . resultSets [ 2 ] . rows [ 0 ] . after_delete ) ) . toBe ( 0 ) ;
291+
292+ await sqliteTest . connector . executeSQL ( 'DROP TABLE order_check' , { } ) ;
293+ } ) ;
294+
272295 it ( 'should handle SQLite foreign key constraints' , async ( ) => {
273296 // Enable foreign key constraints
274297 await sqliteTest . connector . executeSQL ( 'PRAGMA foreign_keys = ON' , { } ) ;
@@ -412,25 +435,23 @@ describe('SQLite Connector Integration Tests', () => {
412435 INSERT INTO users (name, email, age) VALUES ('Multi Test 2', '[email protected] ', 35); 413436 ` , { maxRows : 1 } ) ;
414437
415- // SQLite's connector executes all write statements first, then all
416- // read statements, regardless of source order - so resultSets order
417- // here is [INSERT 'Multi Test 1', INSERT 'Multi Test 2', SELECT],
418- // not the source order [INSERT, SELECT, INSERT]. Both inserts have
419- // already run by the time the SELECT executes.
438+ // Statements run in source order [INSERT, SELECT, INSERT], so only the
439+ // first insert has run by the time the SELECT executes.
420440 expect ( result . resultSets ) . toHaveLength ( 3 ) ;
421441 expect ( result . resultSets [ 0 ] ) . toEqual ( {
422442 sql :
"INSERT INTO users (name, email, age) VALUES ('Multi Test 1', '[email protected] ', 30)" , 423443 rows : [ ] ,
424444 rowCount : 1 ,
425445 } ) ;
426- expect ( result . resultSets [ 1 ] ) . toEqual ( {
446+ // Should return only 1 row from the SELECT statement
447+ expect ( result . resultSets [ 1 ] . sql ) . toBe ( "SELECT name FROM users WHERE email LIKE '%@test.com' ORDER BY name" ) ;
448+ expect ( result . resultSets [ 1 ] . rows ) . toHaveLength ( 1 ) ;
449+ expect ( result . resultSets [ 1 ] . rows [ 0 ] . name ) . toBe ( 'Multi Test 1' ) ;
450+ expect ( result . resultSets [ 2 ] ) . toEqual ( {
427451 sql :
"INSERT INTO users (name, email, age) VALUES ('Multi Test 2', '[email protected] ', 35)" , 428452 rows : [ ] ,
429453 rowCount : 1 ,
430454 } ) ;
431- // Should return only 1 row from the SELECT statement
432- expect ( result . resultSets [ 2 ] . rows ) . toHaveLength ( 1 ) ;
433- expect ( result . resultSets [ 2 ] . rows [ 0 ] . name ) . toBe ( 'Multi Test 1' ) ;
434455 } ) ;
435456
436457 } ) ;
0 commit comments