-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
4 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (C) 2022 Yasuhiro Matsumoto <mattn.jp@gmail.com>. | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// +build sqlite_math_functions | ||
|
||
package sqlite3 | ||
|
||
/* | ||
#cgo CFLAGS: -DSQLITE_ENABLE_MATH_FUNCTIONS | ||
#cgo LDFLAGS: -lm | ||
*/ | ||
import "C" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// +build sqlite_math_functions | ||
|
||
package sqlite3 | ||
|
||
import ( | ||
"database/sql" | ||
"testing" | ||
) | ||
|
||
func TestMathFunctions(t *testing.T) { | ||
db, err := sql.Open("sqlite3", ":memory:") | ||
if err != nil { | ||
t.Fatal("Failed to open database:", err) | ||
} | ||
defer db.Close() | ||
|
||
queries := []string{ | ||
`SELECT acos(1)`, | ||
`SELECT log(10, 100)`, | ||
`SELECT power(2, 2)`, | ||
} | ||
|
||
for _, query := range queries { | ||
var result float64 | ||
if err := db.QueryRow(query).Scan(&result); err != nil { | ||
t.Errorf("invoking math function query %q: %v", query, err) | ||
} | ||
} | ||
} |