Skip to content

Commit 3fd205c

Browse files
geeksilva97aduh95
authored andcommitted
sqlite: enable common flags
PR-URL: #57621 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 00fbe64 commit 3fd205c

File tree

3 files changed

+147
-11
lines changed

3 files changed

+147
-11
lines changed

deps/sqlite/sqlite.gyp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@
1515
'defines': [
1616
'SQLITE_DEFAULT_MEMSTATUS=0',
1717
'SQLITE_ENABLE_COLUMN_METADATA',
18+
'SQLITE_ENABLE_DBSTAT_VTAB',
19+
'SQLITE_ENABLE_FTS3',
20+
'SQLITE_ENABLE_FTS3_PARENTHESIS',
21+
'SQLITE_ENABLE_FTS5',
22+
'SQLITE_ENABLE_GEOPOLY',
1823
'SQLITE_ENABLE_MATH_FUNCTIONS',
24+
'SQLITE_ENABLE_PREUPDATE_HOOK',
25+
'SQLITE_ENABLE_RBU',
26+
'SQLITE_ENABLE_RTREE',
1927
'SQLITE_ENABLE_SESSION',
20-
'SQLITE_ENABLE_PREUPDATE_HOOK'
2128
],
2229
'include_dirs': ['.'],
2330
'sources': [

deps/sqlite/unofficial.gni

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ template("sqlite_gn_build") {
99
include_dirs = [ "." ]
1010
defines = [
1111
"SQLITE_ENABLE_COLUMN_METADATA",
12+
"SQLITE_ENABLE_DBSTAT_VTAB",
13+
"SQLITE_ENABLE_FTS3",
14+
"SQLITE_ENABLE_FTS3_PARENTHESIS",
15+
"SQLITE_ENABLE_FTS5",
16+
"SQLITE_ENABLE_GEOPOLY",
1217
"SQLITE_ENABLE_MATH_FUNCTIONS",
13-
"SQLITE_ENABLE_SESSION",
1418
"SQLITE_ENABLE_PREUPDATE_HOOK",
19+
"SQLITE_ENABLE_RBU",
20+
"SQLITE_ENABLE_RTREE",
21+
"SQLITE_ENABLE_SESSION",
1522
]
1623
}
1724

test/parallel/test-sqlite.js

Lines changed: 131 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,6 @@ test('PRAGMAs are supported', (t) => {
105105
);
106106
});
107107

108-
test('math functions are enabled', (t) => {
109-
const db = new DatabaseSync(':memory:');
110-
t.assert.deepStrictEqual(
111-
db.prepare('SELECT PI() AS pi').get(),
112-
{ __proto__: null, pi: 3.141592653589793 },
113-
);
114-
});
115-
116108
test('Buffer is supported as the database path', (t) => {
117109
const db = new DatabaseSync(Buffer.from(nextDb()));
118110
t.after(() => { db.close(); });
@@ -142,7 +134,6 @@ test('URL is supported as the database path', (t) => {
142134
);
143135
});
144136

145-
146137
suite('URI query params', () => {
147138
const baseDbPath = nextDb();
148139
const baseDb = new DatabaseSync(baseDbPath);
@@ -210,3 +201,134 @@ suite('URI query params', () => {
210201
});
211202
});
212203
});
204+
205+
suite('SQL APIs enabled at build time', () => {
206+
test('math functions are enabled', (t) => {
207+
const db = new DatabaseSync(':memory:');
208+
t.assert.deepStrictEqual(
209+
db.prepare('SELECT PI() AS pi').get(),
210+
{ __proto__: null, pi: 3.141592653589793 },
211+
);
212+
});
213+
214+
test('dbstat is enabled', (t) => {
215+
const db = new DatabaseSync(nextDb());
216+
t.after(() => { db.close(); });
217+
db.exec(`
218+
CREATE TABLE t1 (key INTEGER PRIMARY KEY);
219+
`);
220+
221+
t.assert.deepStrictEqual(
222+
db.prepare('SELECT * FROM dbstat WHERE name = \'t1\'').get(),
223+
{
224+
__proto__: null,
225+
mx_payload: 0,
226+
name: 't1',
227+
ncell: 0,
228+
pageno: 2,
229+
pagetype: 'leaf',
230+
path: '/',
231+
payload: 0,
232+
pgoffset: 4096,
233+
pgsize: 4096,
234+
unused: 4088
235+
},
236+
);
237+
});
238+
239+
test('fts3 is enabled', (t) => {
240+
const db = new DatabaseSync(':memory:');
241+
db.exec(`
242+
CREATE VIRTUAL TABLE t1 USING fts3(content TEXT);
243+
INSERT INTO t1 (content) VALUES ('hello world');
244+
`);
245+
246+
t.assert.deepStrictEqual(
247+
db.prepare('SELECT * FROM t1 WHERE t1 MATCH \'hello\'').all(),
248+
[
249+
{ __proto__: null, content: 'hello world' },
250+
],
251+
);
252+
});
253+
254+
test('fts3 parenthesis', (t) => {
255+
const db = new DatabaseSync(':memory:');
256+
db.exec(`
257+
CREATE VIRTUAL TABLE t1 USING fts3(content TEXT);
258+
INSERT INTO t1 (content) VALUES ('hello world');
259+
`);
260+
261+
t.assert.deepStrictEqual(
262+
db.prepare('SELECT * FROM t1 WHERE content MATCH \'(groupedterm1 OR groupedterm2) OR hello world\'').all(),
263+
[
264+
{ __proto__: null, content: 'hello world' },
265+
],
266+
);
267+
});
268+
269+
test('fts4 is enabled', (t) => {
270+
const db = new DatabaseSync(':memory:');
271+
db.exec(`
272+
CREATE VIRTUAL TABLE t1 USING fts4(content TEXT);
273+
INSERT INTO t1 (content) VALUES ('hello world');
274+
`);
275+
276+
t.assert.deepStrictEqual(
277+
db.prepare('SELECT * FROM t1 WHERE t1 MATCH \'hello\'').all(),
278+
[
279+
{ __proto__: null, content: 'hello world' },
280+
],
281+
);
282+
});
283+
284+
test('fts5 is enabled', (t) => {
285+
const db = new DatabaseSync(':memory:');
286+
db.exec(`
287+
CREATE VIRTUAL TABLE t1 USING fts5(content);
288+
INSERT INTO t1 (content) VALUES ('hello world');
289+
`);
290+
291+
t.assert.deepStrictEqual(
292+
db.prepare('SELECT * FROM t1 WHERE t1 MATCH \'hello\'').all(),
293+
[
294+
{ __proto__: null, content: 'hello world' },
295+
],
296+
);
297+
});
298+
299+
test('rtree is enabled', (t) => {
300+
const db = new DatabaseSync(':memory:');
301+
db.exec(`
302+
CREATE VIRTUAL TABLE t1 USING rtree(id, minX, maxX, minY, maxY);
303+
INSERT INTO t1 (id, minX, maxX, minY, maxY) VALUES (1, 0, 1, 0, 1);
304+
`);
305+
306+
t.assert.deepStrictEqual(
307+
db.prepare('SELECT * FROM t1 WHERE minX < 0.5').all(),
308+
[
309+
{ __proto__: null, id: 1, minX: 0, maxX: 1, minY: 0, maxY: 1 },
310+
],
311+
);
312+
});
313+
314+
test('rbu is enabled', (t) => {
315+
const db = new DatabaseSync(':memory:');
316+
t.assert.deepStrictEqual(
317+
db.prepare('SELECT sqlite_compileoption_used(\'SQLITE_ENABLE_RBU\') as rbu_enabled;').get(),
318+
{ __proto__: null, rbu_enabled: 1 },
319+
);
320+
});
321+
322+
test('geopoly is enabled', (t) => {
323+
const db = new DatabaseSync(':memory:');
324+
db.exec(`
325+
CREATE VIRTUAL TABLE t1 USING geopoly(a,b,c);
326+
INSERT INTO t1(_shape) VALUES('[[0,0],[1,0],[0.5,1],[0,0]]');
327+
`);
328+
329+
t.assert.deepStrictEqual(
330+
db.prepare('SELECT rowid FROM t1 WHERE geopoly_contains_point(_shape, 0, 0)').get(),
331+
{ __proto__: null, rowid: 1 },
332+
);
333+
});
334+
});

0 commit comments

Comments
 (0)