Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

1
test/sqlite/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
build

View File

@ -0,0 +1,7 @@
prefix sqlite
# To mark a test as flaky, list the test name in the appropriate section
# below, without ".js", followed by ": PASS,FLAKY". Example:
# sample-test : PASS,FLAKY
[true] # This section applies to all platforms

View File

@ -0,0 +1,10 @@
{
"targets": [
{
"target_name": "sqlite_extension",
"type": "shared_library",
"sources": [ "extension.c" ],
"include_dirs": [ "../../../deps/sqlite" ]
}
]
}

View File

@ -0,0 +1,94 @@
/*
** 2020-01-08
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This SQLite extension implements a noop() function used for testing.
**
** Variants:
**
** noop(X) The default. Deterministic.
** noop_i(X) Deterministic and innocuous.
** noop_do(X) Deterministic and direct-only.
** noop_nd(X) Non-deterministic.
*/
#include <assert.h>
#include <sqlite3ext.h>
#include <stdio.h>
#include <string.h>
SQLITE_EXTENSION_INIT1
/*
** Implementation of the noop() function.
**
** The function returns its argument, unchanged.
*/
static void noopfunc(sqlite3_context* context, int argc, sqlite3_value** argv) {
assert(argc == 1);
sqlite3_result_value(context, argv[0]);
}
/*
** Implementation of the multitype_text() function.
**
** The function returns its argument. The result will always have a
** TEXT value. But if the original input is numeric, it will also
** have that numeric value.
*/
static void multitypeTextFunc(sqlite3_context* context,
int argc,
sqlite3_value** argv) {
assert(argc == 1);
(void)argc;
(void)sqlite3_value_text(argv[0]);
sqlite3_result_value(context, argv[0]);
}
#ifdef _WIN32
__declspec(dllexport)
#endif
int sqlite3_extension_init(sqlite3* db,
char** pzErrMsg,
const sqlite3_api_routines* pApi) {
int rc = SQLITE_OK;
SQLITE_EXTENSION_INIT2(pApi);
rc = sqlite3_create_function(
db, "noop", 1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, noopfunc, 0, 0);
if (rc) return rc;
rc = sqlite3_create_function(
db,
"noop_i",
1,
SQLITE_UTF8 | SQLITE_DETERMINISTIC | SQLITE_INNOCUOUS,
0,
noopfunc,
0,
0);
if (rc) return rc;
rc = sqlite3_create_function(
db,
"noop_do",
1,
SQLITE_UTF8 | SQLITE_DETERMINISTIC | SQLITE_DIRECTONLY,
0,
noopfunc,
0,
0);
if (rc) return rc;
rc =
sqlite3_create_function(db, "noop_nd", 1, SQLITE_UTF8, 0, noopfunc, 0, 0);
if (rc) return rc;
rc = sqlite3_create_function(
db, "multitype_text", 1, SQLITE_UTF8, 0, multitypeTextFunc, 0, 0);
return rc;
}

View File

@ -0,0 +1,114 @@
'use strict';
const common = require('../../common');
const assert = require('node:assert');
const path = require('node:path');
const sqlite = require('node:sqlite');
const test = require('node:test');
const fs = require('node:fs');
const childProcess = require('node:child_process');
if (process.config.variables.node_shared_sqlite) {
common.skip('Missing libsqlite_extension binary');
}
// Lib extension binary is named differently on different platforms
function resolveBuiltBinary() {
const buildDir = `${__dirname}/build/${common.buildType}`;
const lib = 'sqlite_extension';
const targetFile = fs.readdirSync(buildDir).find((file) => file.startsWith(lib));
return path.join(buildDir, targetFile);
}
const binary = resolveBuiltBinary();
test('should load extension successfully', () => {
const db = new sqlite.DatabaseSync(':memory:', {
allowExtension: true,
});
db.loadExtension(binary);
db.exec('SELECT noop(\'Hello, world!\');');
const query = db.prepare('SELECT noop(\'Hello, World!\') AS result');
const { result } = query.get();
assert.strictEqual(result, 'Hello, World!');
});
test('should not load extension', () => {
const db = new sqlite.DatabaseSync(':memory:', {
allowExtension: false,
});
assert.throws(() => {
db.exec('SELECT noop(\'Hello, world!\');');
}, {
message: 'no such function: noop',
code: 'ERR_SQLITE_ERROR',
});
assert.throws(() => {
db.loadExtension(binary);
}, {
message: 'extension loading is not allowed',
code: 'ERR_INVALID_STATE',
});
assert.throws(() => {
const query = db.prepare('SELECT load_extension(?)');
query.run(binary);
}, {
message: 'not authorized',
code: 'ERR_SQLITE_ERROR',
});
assert.throws(() => {
db.enableLoadExtension();
}, {
message: 'The "allow" argument must be a boolean.',
code: 'ERR_INVALID_ARG_TYPE',
});
assert.throws(() => {
db.enableLoadExtension(true);
}, {
message: 'Cannot enable extension loading because it was disabled at database creation.',
});
});
test('should load extension successfully with enableLoadExtension', () => {
const db = new sqlite.DatabaseSync(':memory:', {
allowExtension: true,
});
db.loadExtension(binary);
db.enableLoadExtension(false);
db.exec('SELECT noop(\'Hello, world!\');');
const query = db.prepare('SELECT noop(\'Hello, World!\') AS result');
const { result } = query.get();
assert.strictEqual(result, 'Hello, World!');
});
test('should not load extension with enableLoadExtension', () => {
const db = new sqlite.DatabaseSync(':memory:', {
allowExtension: true,
});
db.enableLoadExtension(false);
assert.throws(() => {
db.loadExtension(binary);
}, {
message: 'extension loading is not allowed',
});
});
test('should throw error if permission is enabled', async () => {
const [cmd, opts] = common.escapePOSIXShell`"${process.execPath}" `;
const code = `const sqlite = require('node:sqlite');
const db = new sqlite.DatabaseSync(':memory:', { allowExtension: true });`;
return new Promise((resolve) => {
childProcess.exec(
`${cmd} --permission -e "${code}"`,
{
...opts,
},
common.mustCall((err, _, stderr) => {
assert.strictEqual(err.code, 1);
assert.match(stderr, /Error: Cannot load SQLite extensions when the permission model is enabled/);
assert.match(stderr, /code: 'ERR_LOAD_SQLITE_EXTENSION'/);
resolve();
}),
);
});
});

6
test/sqlite/testcfg.py Normal file
View File

@ -0,0 +1,6 @@
import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import testpy
def GetConfiguration(context, root):
return testpy.AddonTestConfiguration(context, root, 'sqlite')