Let's say you have written an extension to find the cube root of a number. Here is how to submit it to the incubator:
-
Fork the incubator branch.
-
Add the extension source:
// src/cbrt.c
// Cube root function.
#include <assert.h>
#include <math.h>
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1
// cbrt(X)
// Calculates cube root of X for integer or real X.
// Returns NULL for other types.
static void sqlite3_cbrt(sqlite3_context* context, int argc, sqlite3_value** argv) {
// implementation
}
#ifdef _WIN32
__declspec(dllexport)
#endif
int sqlite3_cbrt_init(sqlite3* db, char** pzErrMsg, const sqlite3_api_routines* pApi) {
// initialization
}
- Add some tests:
-- test/cbrt.sql
.load dist/cbrt
select '01', cbrt(27) = 3.0;
select '02', cbrt(-27) = -3.0;
select '03', cbrt(8.0) = 2.0;
select '04', cbrt(1) = 1;
select '05', cbrt(0) = 0;
select '06', cbrt('whatever') is null;
- Add compilation and test steps to the Makefile:
compile-linux:
make compile-linux-extension name=cbrt
compile-windows:
make compile-windows-extension name=cbrt
compile-macos:
make compile-macos-extension name=cbrt
test-all:
make test suite=cbrt
- Compile for you OS and run tests to verify that everything is OK:
make prepare-dist
make download-sqlite
make compile-linux-extension name=cbrt
make test suite=cbrt
- Submit a pull request with a short description:
cbrt
Cube root function.
Created by Anton Zhiyanov, MIT License.
Please follow these rules:
- Auto-format the code according to the provided clang-format specification.
- Use descriptive names. No
z
,cc
,pSvRt
and other cryptic variables, please. - Use
snake_case
for variable and function names.