(context)
| 1 | import * as SQLite from '../src/sqlite-api.js'; |
| 2 | |
| 3 | export function api_misc(context) { |
| 4 | describe('libversion', function() { |
| 5 | let proxy, sqlite3, db; |
| 6 | beforeEach(async function() { |
| 7 | proxy = await context.create(); |
| 8 | sqlite3 = proxy.sqlite3; |
| 9 | db = await sqlite3.open_v2('demo'); |
| 10 | }); |
| 11 | |
| 12 | afterEach(async function() { |
| 13 | await sqlite3.close(db); |
| 14 | await context.destroy(proxy); |
| 15 | }); |
| 16 | |
| 17 | it('should return the library version', async function() { |
| 18 | const versionString = await sqlite3.libversion(); |
| 19 | expect(versionString).toMatch(/^\d+\.\d+\.\d+$/); |
| 20 | |
| 21 | const components = versionString.split('.') |
| 22 | .map((component, i) => { |
| 23 | return i ? component.padStart(3, '0') : component; |
| 24 | }); |
| 25 | |
| 26 | const versionNumber = await sqlite3.libversion_number(); |
| 27 | expect(versionNumber.toString()).toEqual(components.join('')); |
| 28 | }); |
| 29 | }); |
| 30 | |
| 31 | describe('limit', function() { |
| 32 | let proxy, sqlite3, db; |
| 33 | beforeEach(async function() { |
| 34 | proxy = await context.create(); |
| 35 | sqlite3 = proxy.sqlite3; |
| 36 | db = await sqlite3.open_v2('demo'); |
| 37 | }); |
| 38 | |
| 39 | afterEach(async function() { |
| 40 | await sqlite3.close(db); |
| 41 | await context.destroy(proxy); |
| 42 | }); |
| 43 | |
| 44 | it('should constrain usage', async function() { |
| 45 | const sql = ` |
| 46 | SELECT 1, 2, 3, 4, 5, 6; |
| 47 | `.trim(); |
| 48 | |
| 49 | let rc; |
| 50 | await expectAsync(sqlite3.exec(db, sql)).toBeResolvedTo(SQLite.SQLITE_OK); |
| 51 | |
| 52 | rc = await sqlite3.limit(db, SQLite.SQLITE_LIMIT_COLUMN, 5); |
| 53 | expect(rc).toBeGreaterThan(0); |
| 54 | |
| 55 | await expectAsync(sqlite3.exec(db, sql)).toBeRejectedWithError(/too many columns/); |
| 56 | |
| 57 | rc = await sqlite3.limit(db, SQLite.SQLITE_LIMIT_COLUMN, rc); |
| 58 | expect(rc).toEqual(5); |
| 59 | |
| 60 | await expectAsync(sqlite3.exec(db, sql)).toBeResolvedTo(SQLite.SQLITE_OK); |
searching dependent graphs…