Skip to content

Commit 17f6553

Browse files
lggruspenkt-dk
andauthored
Add support for sqlite_math_functions tag (#1059)
Add support for SQLITE_ENABLE_MATH_FUNCTIONS compile-time option via the sqlite_math_functions build tag. Co-authored-by: Dominik Kraus <dominik.kraus@nktek.de>
1 parent 7476442 commit 17f6553

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

.github/workflows/go.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
run: go-acc . -- -race -v -tags "libsqlite3"
4545

4646
- name: 'Tags: full'
47-
run: go-acc . -- -race -v -tags "sqlite_allow_uri_authority sqlite_app_armor sqlite_foreign_keys sqlite_fts5 sqlite_icu sqlite_introspect sqlite_json sqlite_os_trace sqlite_preupdate_hook sqlite_secure_delete sqlite_see sqlite_stat4 sqlite_trace sqlite_userauth sqlite_vacuum_incr sqlite_vtable sqlite_unlock_notify sqlite_column_metadata"
47+
run: go-acc . -- -race -v -tags "sqlite_allow_uri_authority sqlite_app_armor sqlite_column_metadata sqlite_foreign_keys sqlite_fts5 sqlite_icu sqlite_introspect sqlite_json sqlite_math_functions sqlite_os_trace sqlite_preupdate_hook sqlite_secure_delete sqlite_see sqlite_stat4 sqlite_trace sqlite_unlock_notify sqlite_userauth sqlite_vacuum_incr sqlite_vtable"
4848

4949
- name: 'Tags: vacuum'
5050
run: go-acc . -- -race -v -tags "sqlite_vacuum_full"
@@ -99,7 +99,7 @@ jobs:
9999
- name: 'Tags: full'
100100
run: |
101101
echo 'skip this test'
102-
echo go build -race -v -tags "sqlite_allow_uri_authority sqlite_app_armor sqlite_foreign_keys sqlite_fts5 sqlite_icu sqlite_introspect sqlite_json sqlite_preupdate_hook sqlite_secure_delete sqlite_see sqlite_stat4 sqlite_trace sqlite_userauth sqlite_vacuum_incr sqlite_vtable sqlite_unlock_notify"
102+
echo go build -race -v -tags "sqlite_allow_uri_authority sqlite_app_armor sqlite_column_metadata sqlite_foreign_keys sqlite_fts5 sqlite_icu sqlite_introspect sqlite_json sqlite_math_functions sqlite_preupdate_hook sqlite_secure_delete sqlite_see sqlite_stat4 sqlite_trace sqlite_unlock_notify sqlite_userauth sqlite_vacuum_incr sqlite_vtable"
103103
shell: msys2 {0}
104104

105105
- name: 'Tags: vacuum'

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ go build --tags "icu json1 fts5 secure_delete"
172172
| International Components for Unicode | sqlite_icu | This option causes the International Components for Unicode or "ICU" extension to SQLite to be added to the build |
173173
| Introspect PRAGMAS | sqlite_introspect | This option adds some extra PRAGMA statements. <ul><li>PRAGMA function_list</li><li>PRAGMA module_list</li><li>PRAGMA pragma_list</li></ul> |
174174
| JSON SQL Functions | sqlite_json | When this option is defined in the amalgamation, the JSON SQL functions are added to the build automatically |
175+
| Math Functions | sqlite_math_functions | This compile-time option enables built-in scalar math functions. For more information see [Built-In Mathematical SQL Functions](https://www.sqlite.org/lang_mathfunc.html) |
175176
| OS Trace | sqlite_os_trace | This option enables OSTRACE() debug logging. This can be verbose and should not be used in production. |
176177
| Pre Update Hook | sqlite_preupdate_hook | Registers a callback function that is invoked prior to each INSERT, UPDATE, and DELETE operation on a database table. |
177178
| Secure Delete | sqlite_secure_delete | This compile-time option changes the default setting of the secure_delete pragma.<br><br>When this option is not used, secure_delete defaults to off. When this option is present, secure_delete defaults to on.<br><br>The secure_delete setting causes deleted content to be overwritten with zeros. There is a small performance penalty since additional I/O must occur.<br><br>On the other hand, secure_delete can prevent fragments of sensitive information from lingering in unused parts of the database file after it has been deleted. See the documentation on the secure_delete pragma for additional information |

sqlite3_opt_math_functions.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (C) 2022 Yasuhiro Matsumoto <mattn.jp@gmail.com>.
2+
//
3+
// Use of this source code is governed by an MIT-style
4+
// license that can be found in the LICENSE file.
5+
6+
// +build sqlite_math_functions
7+
8+
package sqlite3
9+
10+
/*
11+
#cgo CFLAGS: -DSQLITE_ENABLE_MATH_FUNCTIONS
12+
#cgo LDFLAGS: -lm
13+
*/
14+
import "C"

sqlite3_opt_math_functions_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// +build sqlite_math_functions
2+
3+
package sqlite3
4+
5+
import (
6+
"database/sql"
7+
"testing"
8+
)
9+
10+
func TestMathFunctions(t *testing.T) {
11+
db, err := sql.Open("sqlite3", ":memory:")
12+
if err != nil {
13+
t.Fatal("Failed to open database:", err)
14+
}
15+
defer db.Close()
16+
17+
queries := []string{
18+
`SELECT acos(1)`,
19+
`SELECT log(10, 100)`,
20+
`SELECT power(2, 2)`,
21+
}
22+
23+
for _, query := range queries {
24+
var result float64
25+
if err := db.QueryRow(query).Scan(&result); err != nil {
26+
t.Errorf("invoking math function query %q: %v", query, err)
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)