aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-10-04 18:28:34 -0300
committerEuAndreh <eu@euandre.org>2024-10-05 03:03:29 -0300
commitc7f1ec84eba5213ef5927b8c6300f43c47884da1 (patch)
tree3b2934d53fb4f13d6da07be5daccb9c3db0b4e43 /tests
parentMakefile: Store and return bench timing data (diff)
downloadgolite-c7f1ec84eba5213ef5927b8c6300f43c47884da1.tar.gz
golite-c7f1ec84eba5213ef5927b8c6300f43c47884da1.tar.xz
Remove support for dynamically loading extensions
Defer to the user to (statically) include the extension with the rest of the code, and manually registering it, as described in [0]. If support for dynamic libraries and run-time dynamism in general is desired, one shouldn't be looking for it in C or Go, who aren't the greatest bastions of such dynamism, and instead consider more appropriate languages, like Common Lisp or Smalltalk. [0]: https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension
Diffstat (limited to 'tests')
-rw-r--r--tests/functional/extension.go79
-rw-r--r--tests/functional/streq.c37
-rw-r--r--tests/golite.go52
3 files changed, 0 insertions, 168 deletions
diff --git a/tests/functional/extension.go b/tests/functional/extension.go
deleted file mode 100644
index 81c4494..0000000
--- a/tests/functional/extension.go
+++ /dev/null
@@ -1,79 +0,0 @@
-package main
-
-import (
- "database/sql"
- "fmt"
- "log"
- "os"
- "reflect"
-
- "golite"
-)
-
-
-
-func fatalif(err error) {
- if err != nil {
- log.Fatal(err)
- }
-}
-
-func eq(given any, expected any) {
- if !reflect.DeepEqual(given, expected) {
- fmt.Fprintf(os.Stderr, "given != expected\n")
- fmt.Fprintf(os.Stderr, "given: %#v\n", given)
- fmt.Fprintf(os.Stderr, "expected: %#v\n", expected)
- }
-}
-
-
-
-func main() {
- driver := golite.SQLiteDriver{
- Extensions: []string{
- "streq",
- },
- }
- sql.Register("sqlite3-streq", &driver)
-
- db, err := sql.Open("sqlite3-streq", ":memory:")
- fatalif(err)
- defer db.Close()
-
- rows, err := db.Query(`
- SELECT str, n FROM (
- SELECT 'hello' as str, 1 as n
- UNION
- SELECT 'not' as str, 2 as n
- UNION
- SELECT 'hello' as str, 3 as n
- ) WHERE streq(str, 'hello');
- `)
- fatalif(err)
- defer rows.Close()
-
- type pairT struct{
- str string
- id int
- }
- var pairs []pairT
- for rows.Next() {
- var pair pairT
- err := rows.Scan(&pair.str, &pair.id)
- fatalif(err)
- pairs = append(pairs, pair)
- }
- fatalif(rows.Err())
-
- expected := []pairT{
- pairT{
- str: "hello",
- id: 1,
- },
- pairT{
- str: "hello",
- id: 3,
- },
- }
- eq(pairs, expected)
-}
diff --git a/tests/functional/streq.c b/tests/functional/streq.c
deleted file mode 100644
index 70a6aa8..0000000
--- a/tests/functional/streq.c
+++ /dev/null
@@ -1,37 +0,0 @@
-#include <assert.h>
-#include <stdbool.h>
-#include <string.h>
-#include <sqlite3ext.h>
-
-
-
-SQLITE_EXTENSION_INIT1
-static void
-streq(sqlite3_context *const ctx, const int argc, sqlite3_value **const argv) {
- assert(argc == 2);
- const char *const str1 = (const char *)sqlite3_value_text(argv[0]);
- const char *const str2 = (const char *)sqlite3_value_text(argv[1]);
- const bool equal = strcmp(str1, str2) == 0;
- const int result = equal ? 1 : 0;
- sqlite3_result_int(ctx, result);
-}
-
-int
-sqlite3_extension_init(
- sqlite3 *const db,
- const char *const *const errmsg,
- const sqlite3_api_routines *const api
-) {
- SQLITE_EXTENSION_INIT2(api);
- (void)errmsg;
- return sqlite3_create_function(
- db,
- "streq",
- 2,
- SQLITE_UTF8,
- (void *)db,
- streq,
- NULL,
- NULL
- );
-}
diff --git a/tests/golite.go b/tests/golite.go
index 0747bce..aabe83c 100644
--- a/tests/golite.go
+++ b/tests/golite.go
@@ -1214,56 +1214,6 @@ func TestFileCopyTruncate(t *testing.T) {
}
}
-func TestExtensionsError(t *testing.T) {
- sql.Register("sqlite3_TestExtensionsError",
- &SQLiteDriver{
- Extensions: []string{
- "foobar",
- },
- },
- )
-
- db, err := sql.Open("sqlite3_TestExtensionsError", ":memory:")
- if err != nil {
- t.Fatal(err)
- }
- defer db.Close()
-
- err = db.Ping()
- if err == nil {
- t.Fatal("expected error loading non-existent extension")
- }
-
- if err.Error() == "not an error" {
- t.Fatal("expected error from sqlite3_enable_load_extension to be returned")
- }
-}
-
-func TestLoadExtensionError(t *testing.T) {
- sql.Register("sqlite3_TestLoadExtensionError",
- &SQLiteDriver{
- ConnectHook: func(c *SQLiteConn) error {
- return c.LoadExtension("foobar", "")
- },
- },
- )
-
- db, err := sql.Open("sqlite3_TestLoadExtensionError", ":memory:")
- if err != nil {
- t.Fatal(err)
- }
- defer db.Close()
-
- err = db.Ping()
- if err == nil {
- t.Fatal("expected error loading non-existent extension")
- }
-
- if err.Error() == "not an error" {
- t.Fatal("expected error from sqlite3_enable_load_extension to be returned")
- }
-}
-
func TestColumnTableName(t *testing.T) {
d := SQLiteDriver{}
conn, err := d.Open(":memory:")
@@ -3914,8 +3864,6 @@ func MainTest() {
{ "TestExecCancel", TestExecCancel },
{ "TestOpenContext", TestOpenContext },
{ "TestFileCopyTruncate", TestFileCopyTruncate },
- { "TestExtensionsError", TestExtensionsError },
- { "TestLoadExtensionError", TestLoadExtensionError },
{ "TestColumnTableName", TestColumnTableName },
{ "TestFTS3", TestFTS3 },
{ "TestFTS4", TestFTS4 },