Skip to content

Commit 8d4a09e

Browse files
committed
cache sqlite3 version
1 parent 49eacc4 commit 8d4a09e

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

sqlite3.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,22 @@ func init() {
470470
}
471471
}
472472

473+
var cachedVersion struct {
474+
once sync.Once
475+
number int
476+
version string
477+
sourceID string
478+
}
479+
473480
// Version returns SQLite library version information.
474481
func Version() (libVersion string, libVersionNumber int, sourceID string) {
475-
libVersion = C.GoString(C.sqlite3_libversion())
476-
libVersionNumber = int(C.sqlite3_libversion_number())
477-
sourceID = C.GoString(C.sqlite3_sourceid())
478-
return libVersion, libVersionNumber, sourceID
482+
v := &cachedVersion
483+
v.once.Do(func() {
484+
v.number = int(C.sqlite3_libversion_number())
485+
v.version = C.GoString(C.sqlite3_libversion())
486+
v.sourceID = C.GoString(C.sqlite3_sourceid())
487+
})
488+
return v.version, v.number, v.sourceID
479489
}
480490

481491
const (

0 commit comments

Comments
 (0)