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