Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
report actual error message if sqlite3_load_extension fails (#800)
* report actual error message if sqlite3_load_extension fails * more fixes and test cases Co-authored-by: Jesse Rittner <jrittner@lutron.com>
- Loading branch information
Showing
5 changed files
with
112 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,27 @@ | ||
ifeq ($(OS),Windows_NT) | ||
EXE=extension.exe | ||
EXT=sqlite3_mod_regexp.dll | ||
LIB_EXT=dll | ||
RM=cmd /c del | ||
LDFLAG= | ||
else | ||
EXE=extension | ||
EXT=sqlite3_mod_regexp.so | ||
RM=rm | ||
ifeq ($(shell uname -s),Darwin) | ||
LIB_EXT=dylib | ||
else | ||
LIB_EXT=so | ||
endif | ||
RM=rm -f | ||
LDFLAG=-fPIC | ||
endif | ||
LIB=sqlite3_mod_regexp.$(LIB_EXT) | ||
|
||
all : $(EXE) $(EXT) | ||
all : $(EXE) $(LIB) | ||
|
||
$(EXE) : extension.go | ||
go build $< | ||
|
||
$(EXT) : sqlite3_mod_regexp.c | ||
$(LIB) : sqlite3_mod_regexp.c | ||
gcc $(LDFLAG) -shared -o $@ $< -lsqlite3 -lpcre | ||
|
||
clean : | ||
@-$(RM) $(EXE) $(EXT) | ||
@-$(RM) $(EXE) $(LIB) |
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 |
---|---|---|
@@ -1,24 +1,29 @@ | ||
ifeq ($(OS),Windows_NT) | ||
EXE=extension.exe | ||
EXT=sqlite3_mod_vtable.dll | ||
LIB_EXT=dll | ||
RM=cmd /c del | ||
LIBCURL=-lcurldll | ||
LDFLAG= | ||
else | ||
EXE=extension | ||
EXT=sqlite3_mod_vtable.so | ||
RM=rm | ||
ifeq ($(shell uname -s),Darwin) | ||
LIB_EXT=dylib | ||
else | ||
LIB_EXT=so | ||
endif | ||
RM=rm -f | ||
LDFLAG=-fPIC | ||
LIBCURL=-lcurl | ||
endif | ||
LIB=sqlite3_mod_vtable.$(LIB_EXT) | ||
|
||
all : $(EXE) $(EXT) | ||
all : $(EXE) $(LIB) | ||
|
||
$(EXE) : extension.go | ||
go build $< | ||
|
||
$(EXT) : sqlite3_mod_vtable.cc | ||
$(LIB) : sqlite3_mod_vtable.cc | ||
g++ $(LDFLAG) -shared -o $@ $< -lsqlite3 $(LIBCURL) | ||
|
||
clean : | ||
@-$(RM) $(EXE) $(EXT) | ||
@-$(RM) $(EXE) $(LIB) |
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,63 @@ | ||
// Copyright (C) 2019 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_omit_load_extension | ||
|
||
package sqlite3 | ||
|
||
import ( | ||
"database/sql" | ||
"testing" | ||
) | ||
|
||
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") | ||
} | ||
} |