Stat4: Add Test
parent
204cdb4d49
commit
4c7a9b4b81
|
@ -0,0 +1,52 @@
|
|||
// Copyright (C) 2014 Yasuhiro Matsumoto <mattn.jp@gmail.com>.
|
||||
// Copyright (C) 2018 G.J.R. Timmer <gjr.timmer@gmail.com>.
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build sqlite_stat4
|
||||
|
||||
package sqlite3
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStat4(t *testing.T) {
|
||||
tempFilename := TempFilename(t)
|
||||
defer os.Remove(tempFilename)
|
||||
|
||||
db, err := sql.Open("sqlite3", "file:"+tempFilename)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
_, err = db.Exec("drop table foo")
|
||||
_, err = db.Exec("create table foo (id integer)")
|
||||
_, err = db.Exec("create index idx_id on foo(id)")
|
||||
if err != nil {
|
||||
t.Fatal("Failed to create table:", err)
|
||||
}
|
||||
|
||||
tx, err := db.Begin()
|
||||
for i := 0; i < 10000; i++ {
|
||||
tx.Exec("insert into foo(id) VALUES(?)", i)
|
||||
}
|
||||
tx.Commit()
|
||||
|
||||
if _, err := db.Exec("ANALYZE"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
exists := 0
|
||||
if err := db.QueryRow("select count(type) from sqlite_master where type = 'table' and name = 'sqlite_stat4';").Scan(&exists); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if exists != 1 {
|
||||
t.Fatal("Failed to enabled STAT4")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue