go-sqlite3-hak5/_example/mod_regexp/extension.go

44 lines
798 B
Go
Raw Normal View History

package main
import (
"database/sql"
"fmt"
2013-08-23 04:58:54 +00:00
"github.com/mattn/go-sqlite3"
"log"
)
func main() {
2013-08-23 05:26:33 +00:00
sql.Register("sqlite3_with_extensions",
&sqlite3.SQLiteDriver{
Extensions: []string{
2013-08-28 05:46:33 +00:00
"sqlite3_mod_regexp",
},
2013-08-23 05:26:33 +00:00
})
2013-08-23 04:58:54 +00:00
db, err := sql.Open("sqlite3_with_extensions", ":memory:")
if err != nil {
log.Fatal(err)
}
defer db.Close()
// Force db to make a new connection in pool
// by putting the original in a transaction
tx, err := db.Begin()
if err != nil {
log.Fatal(err)
}
defer tx.Commit()
// New connection works (hopefully!)
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)
}
}