| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a9a6891 commit 4e24456
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1887,13 +1887,9 @@ void StatementSync::Run(const FunctionCallbackInfo<Value>& args) { | |||
| 1887 | 1887 | return; | |
| 1888 | 1888 | } | |
| 1889 | 1889 | ||
| 1890 | - auto reset = OnScopeLeave([&]() { sqlite3_reset(stmt->statement_); }); | ||
| 1891 | - r = sqlite3_step(stmt->statement_); | ||
| 1892 | - if (r != SQLITE_ROW && r != SQLITE_DONE) { | ||
| 1893 | - THROW_ERR_SQLITE_ERROR(env->isolate(), stmt->db_.get()); | ||
| 1894 | - return; | ||
| 1895 | - } | ||
| 1896 | - | ||
| 1890 | + sqlite3_step(stmt->statement_); | ||
| 1891 | + r = sqlite3_reset(stmt->statement_); | ||
| 1892 | + CHECK_ERROR_OR_THROW(env->isolate(), stmt->db_.get(), r, SQLITE_OK, void()); | ||
| 1897 | 1893 | Local<Object> result = Object::New(env->isolate()); | |
| 1898 | 1894 | sqlite3_int64 last_insert_rowid = | |
| 1899 | 1895 | sqlite3_last_insert_rowid(stmt->db_->Connection()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -169,6 +169,25 @@ suite('StatementSync.prototype.run()', () => { | |||
| 169 | 169 | errstr: 'constraint failed', | |
| 170 | 170 | }); | |
| 171 | 171 | }); | |
| 172 | + | ||
| 173 | + test('returns correct metadata when using RETURNING', (t) => { | ||
| 174 | + const db = new DatabaseSync(':memory:'); | ||
| 175 | + const setup = db.exec( | ||
| 176 | + 'CREATE TABLE data(key INTEGER PRIMARY KEY, val INTEGER NOT NULL) STRICT;' | ||
| 177 | + ); | ||
| 178 | + t.assert.strictEqual(setup, undefined); | ||
| 179 | + const sql = 'INSERT INTO data (key, val) VALUES ($k, $v) RETURNING key'; | ||
| 180 | + const stmt = db.prepare(sql); | ||
| 181 | + t.assert.deepStrictEqual( | ||
| 182 | + stmt.run({ k: 1, v: 10 }), { changes: 1, lastInsertRowid: 1 } | ||
| 183 | + ); | ||
| 184 | + t.assert.deepStrictEqual( | ||
| 185 | + stmt.run({ k: 2, v: 20 }), { changes: 1, lastInsertRowid: 2 } | ||
| 186 | + ); | ||
| 187 | + t.assert.deepStrictEqual( | ||
| 188 | + stmt.run({ k: 3, v: 30 }), { changes: 1, lastInsertRowid: 3 } | ||
| 189 | + ); | ||
| 190 | + }); | ||
| 172 | 191 | }); | |
| 173 | 192 | ||
| 174 | 193 | suite('StatementSync.prototype.sourceSQL', () => { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments