Skip to content

Commit ecb8e49

Browse files
committed
added another test
1 parent abd1c3f commit ecb8e49

File tree

4 files changed

+98
-2
lines changed

4 files changed

+98
-2
lines changed

TODO

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ compare tests to node-sqlite3
55
Int64 tests should cover the default safeIntegers state for statements and transactions
66

77
a second database#close test file should test every statement and transaction method on a closed database
8-
9-
.run tests should test the accuracy of the "changes" property in INSERT, DELETE, UPDATE, CREATE TABLE, and DROP TABLE operations

test/30.transaction.run.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ describe('Transaction#run()', function () {
167167
.run('foo', {low: 25, high: 25}, 25, Buffer.alloc(8).fill(0xdd));
168168
}).to.throw(Error);
169169

170+
expect(function () {
171+
db.transaction(['INSERT INTO entries VALUES (?, ?, ?, ?)', "INSERT INTO entries VALUES ('foo', 25, 25, x'dddddddd')", 'INSERT INTO entries VALUES (?, ?, ?, ?)'])
172+
.run('foo', 25, 25, Buffer.alloc(8).fill(0xdd));
173+
}).to.throw(Error);
174+
170175
function Foo() {
171176
this.a = 'foo';
172177
this.b = 25;

test/31.transaction.bind.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
'use strict';
2+
var expect = require('chai').expect;
3+
var Database = require('../.');
4+
var db;
5+
6+
before(function (done) {
7+
db = new Database('temp/' + require('path').basename(__filename).split('.')[0] + '.db');
8+
db.on('open', done);
9+
});
10+
11+
describe('Transaction#bind()', function () {
12+
it('should permanently bind the given parameters', function () {
13+
db.transaction(['CREATE TABLE entries (a TEXT, b INTEGER, c BLOB)']).run();
14+
var trans = db.transaction(['INSERT INTO entries VALUES (?, ?, ?)']);
15+
var buffer = Buffer.alloc(4).fill(0xdd);
16+
trans.bind('foobar', 25, buffer)
17+
trans.run();
18+
buffer.fill(0xaa);
19+
trans.run();
20+
var row1 = db.prepare('SELECT * FROM entries WHERE rowid=1').get();
21+
var row2 = db.prepare('SELECT * FROM entries WHERE rowid=2').get();
22+
expect(row1.a).to.equal(row2.a);
23+
expect(row1.b).to.equal(row2.b);
24+
expect(row1.c).to.deep.equal(row2.c);
25+
});
26+
it('should not allow you to bind temporary parameters afterwards', function () {
27+
var trans = db.transaction(['INSERT INTO entries VALUES (?, ?, ?)']);
28+
var buffer = Buffer.alloc(4).fill(0xdd);
29+
trans.bind('foobar', 25, buffer)
30+
expect(function () {trans.run(null);}).to.throw(TypeError);
31+
expect(function () {trans.run(buffer);}).to.throw(TypeError);
32+
expect(function () {trans.run('foobar', 25, buffer);}).to.throw(TypeError);
33+
});
34+
it('should throw an exception when invoked twice on the same transaction', function () {
35+
var trans = db.transaction(['INSERT INTO entries VALUES (?, ?, ?)']);
36+
trans.bind('foobar', 25, null);
37+
expect(function () {trans.bind('foobar', 25, null);}).to.throw(TypeError);
38+
expect(function () {trans.bind();}).to.throw(TypeError);
39+
40+
trans = db.transaction(["INSERT INTO entries VALUES ('foobar', 25, null)"]);
41+
trans.bind();
42+
expect(function () {trans.bind();}).to.throw(TypeError);
43+
});
44+
it('should throw an exception when invoked after the first execution', function () {
45+
var trans = db.transaction(["INSERT INTO entries VALUES ('foobar', 25, NULL)"]);
46+
trans.run();
47+
expect(function () {trans.bind();}).to.throw(TypeError);
48+
49+
trans = db.transaction(["INSERT INTO entries VALUES ('foobar', 25, NULL)"]);
50+
trans.bind();
51+
});
52+
it('should throw an exception when invalid parameters are given', function () {
53+
var trans = db.transaction(['INSERT INTO entries VALUES (?, ?, ?)']);
54+
55+
expect(function () {
56+
trans.bind('foo', 25);
57+
}).to.throw(Error);
58+
59+
expect(function () {
60+
trans.bind('foo', 25, null, null);
61+
}).to.throw(Error);
62+
63+
expect(function () {
64+
trans.bind('foo', new Number(25), null);
65+
}).to.throw(Error);
66+
67+
expect(function () {
68+
trans.bind();
69+
}).to.throw(Error);
70+
71+
trans.bind('foo', 25, null);
72+
73+
trans = db.transaction(['INSERT INTO entries VALUES (@a, @a, ?)']);
74+
75+
expect(function () {
76+
trans.bind({a: '123'});
77+
}).to.throw(Error);
78+
79+
expect(function () {
80+
trans.bind({a: '123', 1: null});
81+
}).to.throw(Error);
82+
83+
expect(function () {
84+
trans.bind({a: '123', b: null}, null);
85+
}).to.throw(Error);
86+
87+
expect(function () {
88+
trans.bind({a: '123'}, null, null);
89+
}).to.throw(Error);
90+
91+
trans.bind({a: '123'}, null);
92+
});
93+
});
File renamed without changes.

0 commit comments

Comments
 (0)