Skip to content

Commit 01c5e87

Browse files
committed
tests and query trim
1 parent f63579a commit 01c5e87

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

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: 9 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,14 @@ 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).toBe('OK')
281280

282281
done()
283282
})
284283
})
285284
})
286285

287-
288286
it('Statement.run - update', done => {
289287
const database = getTestingDatabase(error => {
290288
expect(error).toBeNull()
@@ -300,15 +298,16 @@ it('Statement.run - update', done => {
300298
})
301299
})
302300

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

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

309307
// @ts-ignore
310308
statement.run('John Wayne', 1, (error, results) => {
311-
expect(results).toBeNull()
309+
expect(results).not.toBeNull()
310+
expect(results).toBe('OK')
312311

313312
done()
314313
})
@@ -330,18 +329,18 @@ it('Statement.run - delete', done => {
330329
})
331330
})
332331

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

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

339338
// @ts-ignore
340339
statement.run(1, (error, results) => {
341-
expect(results).toBeNull()
340+
expect(results).not.toBeNull()
341+
expect(results).toBe('OK')
342342

343343
done()
344344
})
345345
})
346346
})
347-

0 commit comments

Comments
 (0)