From 5bf69350b38f6db761206ccb686cd85c208a19a3 Mon Sep 17 00:00:00 2001 From: Nikita Sivukhin Date: Fri, 26 Sep 2025 15:08:40 +0400 Subject: [PATCH] add simple tests for offset/limit binding --- .../packages/native/promise.test.ts | 14 ++++++++ .../query_processing/test_read_path.rs | 34 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/bindings/javascript/packages/native/promise.test.ts b/bindings/javascript/packages/native/promise.test.ts index 190fa23c5..0d05a4b11 100644 --- a/bindings/javascript/packages/native/promise.test.ts +++ b/bindings/javascript/packages/native/promise.test.ts @@ -103,6 +103,20 @@ test('avg-bug', async () => { expect(await db.prepare(`select avg(distinct "b") from "aggregate_table";`).get()).toEqual({ 'avg (DISTINCT aggregate_table.b)': 42.5 }); }) +test('offset-bug', async () => { + const db = await connect(":memory:"); + await db.exec(`CREATE TABLE users ( + id INTEGER PRIMARY KEY, + name TEXT NOT NULL, + verified integer not null default 0 + );`); + const insert = db.prepare(`INSERT INTO users (name) VALUES (?),(?);`); + await insert.run('John', 'John1'); + + const stmt = db.prepare(`SELECT * FROM users LIMIT ? OFFSET ?;`); + expect(await stmt.all(1, 1)).toEqual([{ id: 2, name: 'John1', verified: 0 }]) +}) + test('on-disk db', async () => { const path = `test-${(Math.random() * 10000) | 0}.db`; try { diff --git a/tests/integration/query_processing/test_read_path.rs b/tests/integration/query_processing/test_read_path.rs index 452ca1c85..2319aada6 100644 --- a/tests/integration/query_processing/test_read_path.rs +++ b/tests/integration/query_processing/test_read_path.rs @@ -784,3 +784,37 @@ fn test_avg_agg() -> anyhow::Result<()> { Ok(()) } + +#[test] +fn test_offset_limit_bind() -> anyhow::Result<()> { + let tmp_db = TempDatabase::new_with_rusqlite("CREATE TABLE test (i INTEGER);", false); + let conn = tmp_db.connect_limbo(); + + conn.execute("INSERT INTO test VALUES (5), (4), (3), (2), (1)")?; + + let mut stmt = conn.prepare("SELECT * FROM test LIMIT ? OFFSET ?")?; + stmt.bind_at(1.try_into()?, Value::Integer(2)); + stmt.bind_at(2.try_into()?, Value::Integer(1)); + + let mut rows = Vec::new(); + loop { + match stmt.step()? { + StepResult::Row => { + let row = stmt.row().unwrap(); + rows.push(row.get_values().cloned().collect::>()); + } + StepResult::IO => stmt.run_once()?, + _ => break, + } + } + + assert_eq!( + rows, + vec![ + vec![turso_core::Value::Integer(4)], + vec![turso_core::Value::Integer(3)] + ] + ); + + Ok(()) +}