From 614d7c1fdab4a85687ef72e5e0a35c8c1e1de071 Mon Sep 17 00:00:00 2001 From: James C Kimble Date: Wed, 31 Jan 2018 22:24:37 -0600 Subject: [PATCH] Add static_mock.go to allow building with CGO_ENABLED=0 --- sqlite3.go | 2 ++ sqlite3_go18.go | 2 ++ static_mock.go | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 static_mock.go diff --git a/sqlite3.go b/sqlite3.go index 739f91d..a081893 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -1,3 +1,5 @@ +// +build cgo + // Copyright (C) 2014 Yasuhiro Matsumoto . // // Use of this source code is governed by an MIT-style diff --git a/sqlite3_go18.go b/sqlite3_go18.go index f9e08e1..dd0f5a7 100644 --- a/sqlite3_go18.go +++ b/sqlite3_go18.go @@ -1,3 +1,5 @@ +// +build cgo + // Copyright (C) 2014 Yasuhiro Matsumoto . // // Use of this source code is governed by an MIT-style diff --git a/static_mock.go b/static_mock.go new file mode 100644 index 0000000..48629d1 --- /dev/null +++ b/static_mock.go @@ -0,0 +1,21 @@ +// +build !cgo + +package sqlite3 + +import ( + "database/sql" + "database/sql/driver" + "errors" +) + +func init() { + sql.Register("sqlite3", &SQLiteDriverMock{}) +} + +type SQLiteDriverMock struct{} + +var errorMsg = errors.New("Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub") + +func (SQLiteDriverMock) Open(s string) (driver.Conn, error) { + return nil, errorMsg +}