|
3 | 3 | */ |
4 | 4 |
|
5 | 5 | import { SQLiteCloudRowset } from '../src' |
6 | | -import { RowCallback, RowCountCallback } from '../src/types' |
| 6 | +import { RowCallback, RowCountCallback, SQLiteCloudError } from '../src/types' |
7 | 7 | import { getChinookDatabase } from './shared' |
8 | 8 |
|
9 | | -it('Database.prepare without initial bindings', done => { |
| 9 | +describe('Database.prepare', () => { |
| 10 | + it('without incorrect bindings', done => { |
| 11 | + const chinook = getChinookDatabase() |
| 12 | + expect(chinook).toBeDefined() |
| 13 | + |
| 14 | + // two bindings, but only one is provided... |
| 15 | + const statement = chinook.prepare('SELECT * FROM tracks WHERE albumId = ? and trackId = ?;', 1, (err: Error, results: any) => { |
| 16 | + expect(err).toBeInstanceOf(SQLiteCloudError) |
| 17 | + |
| 18 | + chinook.close() |
| 19 | + done() |
| 20 | + }) |
| 21 | + }) |
| 22 | + |
| 23 | + it('without initial bindings', done => { |
| 24 | + const chinook = getChinookDatabase() |
| 25 | + expect(chinook).toBeDefined() |
| 26 | + const statement = chinook.prepare('SELECT * FROM tracks WHERE albumId = ?;', (err: Error, results: any) => { |
| 27 | + expect(err).toBeNull() |
| 28 | + }) |
| 29 | + |
| 30 | + statement.all(3, (error, rows) => { |
| 31 | + expect(error).toBeNull() |
| 32 | + expect(rows).toBeDefined() |
| 33 | + expect(rows).toHaveLength(3) |
| 34 | + expect(rows).toBeInstanceOf(SQLiteCloudRowset) |
| 35 | + expect(rows).toMatchObject([ |
| 36 | + { |
| 37 | + AlbumId: 3, |
| 38 | + Bytes: 3990994, |
| 39 | + Composer: 'F. Baltes, S. Kaufman, U. Dirkscneider & W. Hoffman', |
| 40 | + GenreId: 1, |
| 41 | + MediaTypeId: 2, |
| 42 | + Milliseconds: 230619, |
| 43 | + Name: 'Fast As a Shark', |
| 44 | + TrackId: 3, |
| 45 | + UnitPrice: 0.99 |
| 46 | + }, |
| 47 | + { |
| 48 | + AlbumId: 3, |
| 49 | + Bytes: 4331779, |
| 50 | + Composer: 'F. Baltes, R.A. Smith-Diesel, S. Kaufman, U. Dirkscneider & W. Hoffman', |
| 51 | + GenreId: 1, |
| 52 | + MediaTypeId: 2, |
| 53 | + Milliseconds: 252051, |
| 54 | + Name: 'Restless and Wild', |
| 55 | + TrackId: 4, |
| 56 | + UnitPrice: 0.99 |
| 57 | + }, |
| 58 | + { |
| 59 | + AlbumId: 3, |
| 60 | + Bytes: 6290521, |
| 61 | + Composer: 'Deaffy & R.A. Smith-Diesel', |
| 62 | + GenreId: 1, |
| 63 | + MediaTypeId: 2, |
| 64 | + Milliseconds: 375418, |
| 65 | + Name: 'Princess of the Dawn', |
| 66 | + TrackId: 5, |
| 67 | + UnitPrice: 0.99 |
| 68 | + } |
| 69 | + ]) |
| 70 | + |
| 71 | + chinook.close(error => { |
| 72 | + expect(error).toBeNull() |
| 73 | + done() |
| 74 | + }) |
| 75 | + }) |
| 76 | + }) |
| 77 | +}) |
| 78 | + |
| 79 | +it('Statement.bind', done => { |
10 | 80 | const chinook = getChinookDatabase() |
11 | 81 | expect(chinook).toBeDefined() |
12 | 82 | const statement = chinook.prepare('SELECT * FROM tracks WHERE albumId = ?;', (err: Error, results: any) => { |
13 | 83 | expect(err).toBeNull() |
14 | 84 | }) |
15 | 85 |
|
16 | | - statement.all(3, (error, rows) => { |
| 86 | + statement.bind(3, (error: Error) => { |
17 | 87 | expect(error).toBeNull() |
18 | | - expect(rows).toBeDefined() |
19 | | - expect(rows).toHaveLength(3) |
20 | | - expect(rows).toBeInstanceOf(SQLiteCloudRowset) |
21 | | - expect(rows).toMatchObject([ |
22 | | - { |
23 | | - AlbumId: 3, |
24 | | - Bytes: 3990994, |
25 | | - Composer: 'F. Baltes, S. Kaufman, U. Dirkscneider & W. Hoffman', |
26 | | - GenreId: 1, |
27 | | - MediaTypeId: 2, |
28 | | - Milliseconds: 230619, |
29 | | - Name: 'Fast As a Shark', |
30 | | - TrackId: 3, |
31 | | - UnitPrice: 0.99 |
32 | | - }, |
33 | | - { |
34 | | - AlbumId: 3, |
35 | | - Bytes: 4331779, |
36 | | - Composer: 'F. Baltes, R.A. Smith-Diesel, S. Kaufman, U. Dirkscneider & W. Hoffman', |
37 | | - GenreId: 1, |
38 | | - MediaTypeId: 2, |
39 | | - Milliseconds: 252051, |
40 | | - Name: 'Restless and Wild', |
41 | | - TrackId: 4, |
42 | | - UnitPrice: 0.99 |
43 | | - }, |
44 | | - { |
45 | | - AlbumId: 3, |
46 | | - Bytes: 6290521, |
47 | | - Composer: 'Deaffy & R.A. Smith-Diesel', |
48 | | - GenreId: 1, |
49 | | - MediaTypeId: 2, |
50 | | - Milliseconds: 375418, |
51 | | - Name: 'Princess of the Dawn', |
52 | | - TrackId: 5, |
53 | | - UnitPrice: 0.99 |
54 | | - } |
55 | | - ]) |
56 | 88 |
|
57 | | - chinook.close(error => { |
| 89 | + statement.all((error, rows) => { |
58 | 90 | expect(error).toBeNull() |
59 | | - done() |
| 91 | + expect(rows).toBeDefined() |
| 92 | + expect(rows).toHaveLength(3) |
| 93 | + expect(rows).toBeInstanceOf(SQLiteCloudRowset) |
| 94 | + |
| 95 | + // missing binding |
| 96 | + statement.bind((error: Error) => { |
| 97 | + expect(error).toBeInstanceOf(SQLiteCloudError) |
| 98 | + |
| 99 | + chinook.close(error => { |
| 100 | + expect(error).toBeNull() |
| 101 | + done() |
| 102 | + }) |
| 103 | + }) |
60 | 104 | }) |
61 | 105 | }) |
62 | 106 | }) |
@@ -148,7 +192,12 @@ it('Statement.run', done => { |
148 | 192 | statement.run(1, error => { |
149 | 193 | expect(error).toBeNull() |
150 | 194 |
|
151 | | - chinook.close() |
152 | | - done() |
| 195 | + // run again but use same binding this time |
| 196 | + statement.run(error => { |
| 197 | + expect(error).toBeNull() |
| 198 | + |
| 199 | + chinook.close() |
| 200 | + done() |
| 201 | + }) |
153 | 202 | }) |
154 | 203 | }) |
0 commit comments