diff options
author | 2023-10-17 01:08:58 +0200 | |
---|---|---|
committer | 2023-10-16 16:08:58 -0700 | |
commit | bec6161dce999c51dd1443c1ac7f2ce493bf800c (patch) | |
tree | fb21cdb696a97881bfb203750e6c6e10c74be5dd | |
parent | 8c580e67645d9718960f930849cbd1841057d7c5 (diff) | |
download | bun-bec6161dce999c51dd1443c1ac7f2ce493bf800c.tar.gz bun-bec6161dce999c51dd1443c1ac7f2ce493bf800c.tar.zst bun-bec6161dce999c51dd1443c1ac7f2ce493bf800c.zip |
fix(sqlite) Insert .all() does not return an array #5872 (#5946)
* fixing #5872
* removing useless comment
-rw-r--r-- | src/bun.js/bindings/sqlite/JSSQLStatement.cpp | 8 | ||||
-rw-r--r-- | 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<JSSQLStatement*>(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([]); +}); |