aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile11
-rw-r--r--deps.mk9
-rwxr-xr-xmkdeps.sh1
-rw-r--r--src/golite.go70
-rw-r--r--tests/functional/extension.go79
-rw-r--r--tests/functional/streq.c37
-rw-r--r--tests/golite.go52
7 files changed, 1 insertions, 258 deletions
diff --git a/Makefile b/Makefile
index ca56d53..d2545b1 100644
--- a/Makefile
+++ b/Makefile
@@ -70,7 +70,6 @@ derived-assets = \
tests/main.bin \
$(functional-tests.a) \
$(functional-tests.bin) \
- tests/functional/streq.so \
$(fuzz-targets.a) \
$(fuzz-targets.bin) \
$(benchmarks.a) \
@@ -127,16 +126,9 @@ $(fuzz-targets.a):
$(functional-tests.bin) $(fuzz-targets.bin) $(benchmarks.bin):
go tool link $(GOLDFLAGS) -o $@ -L src --extldflags '$(LDLIBS)' $*.a
-tests/functional/streq.so: tests/functional/streq.c
- $(CC) $(CFLAGS) $(LDFLAGS) -fPIC --shared -o $@ $*.c
-
-tests/functional/extension.bin-check: tests/functional/streq.so
- LD_LIBRARY_PATH=$(@D) $(EXEC)$*.bin
-
-functional-tests.bin-check = $(functional-tests-butone.go:.go=.bin-check)
-
+functional-tests.bin-check = $(functional-tests.go:.go=.bin-check)
tests.bin-check = \
tests/main.bin-check \
$(functional-tests.bin-check) \
@@ -146,7 +138,6 @@ $(tests.bin-check):
$(EXEC)$*.bin
check-unit: $(tests.bin-check)
-check-unit: tests/functional/extension.bin-check
integration-tests = \
diff --git a/deps.mk b/deps.mk
index b2b43fe..8818497 100644
--- a/deps.mk
+++ b/deps.mk
@@ -1,10 +1,4 @@
-functional-tests-butone.go = \
- tests/functional/json.go \
- tests/functional/libbuild.go \
- tests/functional/limit.go \
-
functional-tests.go = \
- tests/functional/extension.go \
tests/functional/json.go \
tests/functional/libbuild.go \
tests/functional/limit.go \
@@ -18,21 +12,18 @@ benchmarks.go = \
tests/benchmarks/exec.a: tests/benchmarks/exec.go
tests/benchmarks/query.a: tests/benchmarks/query.go
-tests/functional/extension.a: tests/functional/extension.go
tests/functional/json.a: tests/functional/json.go
tests/functional/libbuild.a: tests/functional/libbuild.go
tests/functional/limit.a: tests/functional/limit.go
tests/fuzz/api.a: tests/fuzz/api.go
tests/benchmarks/exec.bin: tests/benchmarks/exec.a
tests/benchmarks/query.bin: tests/benchmarks/query.a
-tests/functional/extension.bin: tests/functional/extension.a
tests/functional/json.bin: tests/functional/json.a
tests/functional/libbuild.bin: tests/functional/libbuild.a
tests/functional/limit.bin: tests/functional/limit.a
tests/fuzz/api.bin: tests/fuzz/api.a
tests/benchmarks/exec.bin-check: tests/benchmarks/exec.bin
tests/benchmarks/query.bin-check: tests/benchmarks/query.bin
-tests/functional/extension.bin-check: tests/functional/extension.bin
tests/functional/json.bin-check: tests/functional/json.bin
tests/functional/libbuild.bin-check: tests/functional/libbuild.bin
tests/functional/limit.bin-check: tests/functional/limit.bin
diff --git a/mkdeps.sh b/mkdeps.sh
index 1ff0acb..92427c6 100755
--- a/mkdeps.sh
+++ b/mkdeps.sh
@@ -4,7 +4,6 @@ set -eu
export LANG=POSIX.UTF-8
-find tests/functional/*.go -not -name extension.go | varlist 'functional-tests-butone.go'
find tests/functional/*.go | varlist 'functional-tests.go'
find tests/fuzz/*.go | varlist 'fuzz-targets.go'
find tests/benchmarks/*.go | varlist 'benchmarks.go'
diff --git a/src/golite.go b/src/golite.go
index cfc1484..d40d393 100644
--- a/src/golite.go
+++ b/src/golite.go
@@ -1128,7 +1128,6 @@ const (
// SQLiteDriver implements driver.Driver.
type SQLiteDriver struct {
- Extensions []string
ConnectHook func(*SQLiteConn) error
}
@@ -2134,13 +2133,6 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
}
}
- if len(d.Extensions) > 0 {
- if err := conn.loadExtensions(d.Extensions); err != nil {
- conn.Close()
- return nil, err
- }
- }
-
if d.ConnectHook != nil {
if err := d.ConnectHook(conn); err != nil {
conn.Close()
@@ -2791,68 +2783,6 @@ func (s *SQLiteStmt) ExecContext(ctx context.Context, args []driver.NamedValue)
return s.exec(ctx, args)
}
-func (c *SQLiteConn) loadExtensions(extensions []string) error {
- rv := C.sqlite3_enable_load_extension(c.db, 1)
- if rv != C.SQLITE_OK {
- return errors.New(C.GoString(C.sqlite3_errmsg(c.db)))
- }
-
- for _, extension := range extensions {
- if err := c.loadExtension(extension, nil); err != nil {
- C.sqlite3_enable_load_extension(c.db, 0)
- return err
- }
- }
-
- rv = C.sqlite3_enable_load_extension(c.db, 0)
- if rv != C.SQLITE_OK {
- return errors.New(C.GoString(C.sqlite3_errmsg(c.db)))
- }
-
- return nil
-}
-
-// LoadExtension load the sqlite3 extension.
-func (c *SQLiteConn) LoadExtension(lib string, entry string) error {
- rv := C.sqlite3_enable_load_extension(c.db, 1)
- if rv != C.SQLITE_OK {
- return errors.New(C.GoString(C.sqlite3_errmsg(c.db)))
- }
-
- if err := c.loadExtension(lib, &entry); err != nil {
- C.sqlite3_enable_load_extension(c.db, 0)
- return err
- }
-
- rv = C.sqlite3_enable_load_extension(c.db, 0)
- if rv != C.SQLITE_OK {
- return errors.New(C.GoString(C.sqlite3_errmsg(c.db)))
- }
-
- return nil
-}
-
-func (c *SQLiteConn) loadExtension(lib string, entry *string) error {
- clib := C.CString(lib)
- defer C.free(unsafe.Pointer(clib))
-
- var centry *C.char
- if entry != nil {
- centry = C.CString(*entry)
- defer C.free(unsafe.Pointer(centry))
- }
-
- var errMsg *C.char
- defer C.sqlite3_free(unsafe.Pointer(errMsg))
-
- rv := C.sqlite3_load_extension(c.db, clib, centry, &errMsg)
- if rv != C.SQLITE_OK {
- return errors.New(C.GoString(errMsg))
- }
-
- return nil
-}
-
// ColumnTableName returns the table that is the origin of a particular result
// column in a SELECT statement.
//
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 },