From 3420c2b8726ecb53e3a64e3728e15895e64d1fc8 Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 23 Aug 2013 09:58:27 +0900 Subject: [PATCH] Add example for sqlite3_with_extensions --- example/extension/extension.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 example/extension/extension.go diff --git a/example/extension/extension.go b/example/extension/extension.go new file mode 100644 index 0000000..3ec145a --- /dev/null +++ b/example/extension/extension.go @@ -0,0 +1,32 @@ +package main + +import ( + "database/sql" + "fmt" + _ "github.com/mattn/go-sqlite3" + "log" +) + +func main() { + db, err := sql.Open("sqlite3_with_extensions", ":memory:") + if err != nil { + log.Fatal(err) + } + defer db.Close() + + _, err = db.Exec("select load_extension('sqlite3_mod_regexp.dll')") + if err != nil { + log.Fatal(err) + } + + rows, err := db.Query("select 'hello world' where 'hello world' regexp '^hello.*d$'") + if err != nil { + log.Fatal(err) + } + defer rows.Close() + for rows.Next() { + var helloworld string + rows.Scan(&helloworld) + fmt.Println(helloworld) + } +}