From f6dadd82d81a644eb5b7c212a6f1770c0c87ba41 Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 23 Aug 2013 09:57:22 +0900 Subject: [PATCH] Add new driver name 'sqlite3_with_extensions' --- sqlite3.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sqlite3.go b/sqlite3.go index b95f290..0aba2db 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -72,11 +72,13 @@ var SQLiteTimestampFormats = []string{ } func init() { - sql.Register("sqlite3", &SQLiteDriver{}) + sql.Register("sqlite3", &SQLiteDriver{false}) + sql.Register("sqlite3_with_extensions", &SQLiteDriver{true}) } // Driver struct. type SQLiteDriver struct { + enableLoadExtentions bool } // Conn struct. @@ -176,6 +178,15 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { return nil, errors.New(C.GoString(C.sqlite3_errmsg(db))) } + enableLoadExtentions := 0 + if d.enableLoadExtentions { + enableLoadExtentions = 1 + } + rv = C.sqlite3_enable_load_extension(db, C.int(enableLoadExtentions)) + if rv != C.SQLITE_OK { + return nil, errors.New(C.GoString(C.sqlite3_errmsg(db))) + } + return &SQLiteConn{db}, nil }