Merge pull request #279 from otoolep/src_dst_swapped

Source and destination are reversed
This commit is contained in:
mattn 2017-03-01 15:57:43 +09:00 committed by GitHub
commit c2ab9a4ac8
1 changed files with 26 additions and 25 deletions

View File

@ -2,9 +2,10 @@ package main
import ( import (
"database/sql" "database/sql"
"github.com/mattn/go-sqlite3"
"log" "log"
"os" "os"
"github.com/mattn/go-sqlite3"
) )
func main() { func main() {
@ -19,36 +20,36 @@ func main() {
os.Remove("./foo.db") os.Remove("./foo.db")
os.Remove("./bar.db") os.Remove("./bar.db")
destDb, err := sql.Open("sqlite3_with_hook_example", "./foo.db") srcDb, err := sql.Open("sqlite3_with_hook_example", "./foo.db")
if err != nil {
log.Fatal(err)
}
defer destDb.Close()
destDb.Ping()
_, err = destDb.Exec("create table foo(id int, value text)")
if err != nil {
log.Fatal(err)
}
_, err = destDb.Exec("insert into foo values(1, 'foo')")
if err != nil {
log.Fatal(err)
}
_, err = destDb.Exec("insert into foo values(2, 'bar')")
if err != nil {
log.Fatal(err)
}
_, err = destDb.Query("select * from foo")
if err != nil {
log.Fatal(err)
}
srcDb, err := sql.Open("sqlite3_with_hook_example", "./bar.db")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
defer srcDb.Close() defer srcDb.Close()
srcDb.Ping() srcDb.Ping()
_, err = srcDb.Exec("create table foo(id int, value text)")
if err != nil {
log.Fatal(err)
}
_, err = srcDb.Exec("insert into foo values(1, 'foo')")
if err != nil {
log.Fatal(err)
}
_, err = srcDb.Exec("insert into foo values(2, 'bar')")
if err != nil {
log.Fatal(err)
}
_, err = srcDb.Query("select * from foo")
if err != nil {
log.Fatal(err)
}
destDb, err := sql.Open("sqlite3_with_hook_example", "./bar.db")
if err != nil {
log.Fatal(err)
}
defer destDb.Close()
destDb.Ping()
bk, err := sqlite3conn[1].Backup("main", sqlite3conn[0], "main") bk, err := sqlite3conn[1].Backup("main", sqlite3conn[0], "main")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)