From bec6161dce999c51dd1443c1ac7f2ce493bf800c Mon Sep 17 00:00:00 2001 From: Hugo Galan <42879623+HForGames@users.noreply.github.com> Date: Tue, 17 Oct 2023 01:08:58 +0200 Subject: fix(sqlite) Insert .all() does not return an array #5872 (#5946) * fixing #5872 * removing useless comment --- src/bun.js/bindings/sqlite/JSSQLStatement.cpp | 8 +------- test/js/bun/sqlite/sqlite.test.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/bun.js/bindings/sqlite/JSSQLStatement.cpp b/src/bun.js/bindings/sqlite/JSSQLStatement.cpp index 72c7d9a07..cad20df6f 100644 --- a/src/bun.js/bindings/sqlite/JSSQLStatement.cpp +++ b/src/bun.js/bindings/sqlite/JSSQLStatement.cpp @@ -1261,7 +1261,6 @@ static inline JSC::JSArray* constructResultRow(JSC::JSGlobalObject* lexicalGloba JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteStatementFunctionAll, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame)) { - JSC::VM& vm = lexicalGlobalObject->vm(); auto scope = DECLARE_THROW_SCOPE(vm); auto castedThis = jsDynamicCast(callFrame->thisValue()); @@ -1293,7 +1292,6 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteStatementFunctionAll, (JSC::JSGlob size_t columnCount = castedThis->columnNames->size(); JSValue result = jsUndefined(); - if (status == SQLITE_ROW) { // this is a count from UPDATE or another query like that if (columnCount == 0) { @@ -1315,11 +1313,7 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementExecuteStatementFunctionAll, (JSC::JSGlob result = resultArray; } } else if (status == SQLITE_DONE) { - if (columnCount == 0) { - result = jsNumber(sqlite3_changes(castedThis->version_db->db)); - } else { - result = JSC::constructEmptyArray(lexicalGlobalObject, nullptr, 0); - } + result = JSC::constructEmptyArray(lexicalGlobalObject, nullptr, 0); } if (UNLIKELY(status != SQLITE_DONE && status != SQLITE_OK)) { diff --git a/test/js/bun/sqlite/sqlite.test.js b/test/js/bun/sqlite/sqlite.test.js index 00e7d87a1..d065a521f 100644 --- a/test/js/bun/sqlite/sqlite.test.js +++ b/test/js/bun/sqlite/sqlite.test.js @@ -599,3 +599,13 @@ it("#3991", () => { expect(x.id).toBe("foobar"); }); + +it("#5872", () => { + const db = new Database(":memory:"); + db.run( + "CREATE TABLE foo (id INTEGER PRIMARY KEY AUTOINCREMENT, greeting TEXT)" + ); + const query = db.query("INSERT INTO foo (greeting) VALUES ($greeting);"); + const result = query.all({ $greeting: "sup" }); + expect(result).toEqual([]); +}); -- cgit v1.2.3