Skip to content

Commit d97ec68

Browse files
authored
fix prepared statement trim query
* tests and query trim * fix statement test
1 parent f63579a commit d97ec68

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sqlitecloud/drivers",
3-
"version": "1.0.345",
3+
"version": "1.0.354",
44
"description": "SQLiteCloud drivers for Typescript/Javascript in edge, web and node clients",
55
"main": "./lib/index.js",
66
"types": "./lib/index.d.ts",

src/drivers/protocol.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ export function popData(buffer: Buffer): { data: SQLiteCloudDataTypes | SQLiteCl
335335

336336
/** Format a command to be sent via SCSP protocol */
337337
export function formatCommand(command: SQLiteCloudCommand): string {
338+
// core returns null if there's a space after the semi column
339+
// we want to maintain a compatibility with the standard sqlite3 driver
340+
command.query = command.query.trim()
341+
338342
if (command.parameters && command.parameters.length > 0) {
339343
// by SCSP the string paramenters in the array are zero-terminated
340344
return serializeCommand([command.query, ...(command.parameters || [])], true)

test/statement.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ it('Statement.each without bindings', done => {
190190
statement.each(4, rowCallback, completeCallback)
191191
})
192192

193-
194193
it('Statement.get', done => {
195194
const chinook = getChinookDatabase()
196195
expect(chinook).toBeDefined()
@@ -226,7 +225,6 @@ it('Statement.get without bindings', done => {
226225
})
227226
})
228227

229-
230228
it('Statement.run', done => {
231229
const chinook = getChinookDatabase()
232230
expect(chinook).toBeDefined()
@@ -268,7 +266,7 @@ it('Statement.run - insert', done => {
268266
})
269267
})
270268

271-
it('Statement.run - insert with empty space after semicolon returns null', done => {
269+
it("Statement.run - insert with empty space after semicolon shouldn't return null", done => {
272270
// create simple "people" database that we can write in...
273271
const database = getTestingDatabase(error => {
274272
expect(error).toBeNull()
@@ -277,14 +275,15 @@ it('Statement.run - insert with empty space after semicolon returns null', done
277275

278276
// @ts-ignore
279277
statement.run('John Wayne', 73, 'Horse Riding', (error, results) => {
280-
expect(results).toBeNull()
278+
expect(results).not.toBeNull()
279+
expect(results.lastID).toBeGreaterThan(1)
280+
expect(results.changes).toBe(1)
281281

282282
done()
283283
})
284284
})
285285
})
286286

287-
288287
it('Statement.run - update', done => {
289288
const database = getTestingDatabase(error => {
290289
expect(error).toBeNull()
@@ -300,15 +299,16 @@ it('Statement.run - update', done => {
300299
})
301300
})
302301

303-
it('Statement.run - update with empty space after semicolon returns null', done => {
302+
it("Statement.run - update with empty space after semicolon shouldn't return null", done => {
304303
const database = getTestingDatabase(error => {
305304
expect(error).toBeNull()
306305

307306
const statement = database.prepare('UPDATE people SET name= ? WHERE id = ?; ')
308307

309308
// @ts-ignore
310309
statement.run('John Wayne', 1, (error, results) => {
311-
expect(results).toBeNull()
310+
expect(results).not.toBeNull()
311+
expect(results.changes).toBe(1)
312312

313313
done()
314314
})
@@ -330,18 +330,18 @@ it('Statement.run - delete', done => {
330330
})
331331
})
332332

333-
it('Statement.run - delete with empty space after semicolon returns null', done => {
333+
it("Statement.run - delete with empty space after semicolon shouldn't return null", done => {
334334
const database = getTestingDatabase(error => {
335335
expect(error).toBeNull()
336336

337337
const statement = database.prepare('DELETE FROM people WHERE id = ?; ')
338338

339339
// @ts-ignore
340340
statement.run(1, (error, results) => {
341-
expect(results).toBeNull()
341+
expect(results).not.toBeNull()
342+
expect(results.changes).toBe(1)
342343

343344
done()
344345
})
345346
})
346347
})
347-

0 commit comments

Comments
 (0)