mirror of https://github.com/mattn/go-sqlite3.git
add support for sqlite3_status64
This commit is contained in:
parent
3c0390b77c
commit
6fdf9a58d5
35
sqlite3.go
35
sqlite3.go
|
@ -959,6 +959,41 @@ func (c *SQLiteConn) query(ctx context.Context, query string, args []driver.Name
|
|||
}
|
||||
}
|
||||
|
||||
type SqliteStatus64Option int
|
||||
|
||||
const (
|
||||
SQLITE_STATUS_MEMORY_USED SqliteStatus64Option = 0
|
||||
SQLITE_STATUS_PAGECACHE_USED SqliteStatus64Option = 1
|
||||
SQLITE_STATUS_PAGECACHE_OVERFLOW SqliteStatus64Option = 2
|
||||
SQLITE_STATUS_MALLOC_SIZE SqliteStatus64Option = 5
|
||||
SQLITE_STATUS_PARSER_STACK SqliteStatus64Option = 6
|
||||
SQLITE_STATUS_PAGECACHE_SIZE SqliteStatus64Option = 7
|
||||
SQLITE_STATUS_MALLOC_COUNT SqliteStatus64Option = 9
|
||||
)
|
||||
|
||||
// GetStatus64 retrieves runtime status information about the performance of SQLite,
|
||||
// and optionally resets various high-water marks.
|
||||
func GetStatus64(op SqliteStatus64Option, resetFlag bool) (current, highWater int64, err error) {
|
||||
var curr C.sqlite_int64
|
||||
var hiwtr C.sqlite_int64
|
||||
|
||||
reset := C.int(0)
|
||||
if resetFlag {
|
||||
reset = C.int(1)
|
||||
}
|
||||
|
||||
rv := C.sqlite3_status64(C.int(op), &curr, &hiwtr, reset)
|
||||
if rv != C.SQLITE_OK {
|
||||
errStr := C.GoString(C.sqlite3_errstr(rv))
|
||||
return 0, 0, Error{
|
||||
Code: ErrNo(rv),
|
||||
err: errStr,
|
||||
}
|
||||
}
|
||||
|
||||
return int64(curr), int64(hiwtr), nil
|
||||
}
|
||||
|
||||
// Begin transaction.
|
||||
func (c *SQLiteConn) Begin() (driver.Tx, error) {
|
||||
return c.begin(context.Background())
|
||||
|
|
|
@ -1997,6 +1997,12 @@ func TestNamedParam(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestStatus64(t *testing.T) {
|
||||
if _, _, err := GetStatus64(SQLITE_STATUS_MEMORY_USED, false); err != nil {
|
||||
t.Fatal("Failed to get status64:", err)
|
||||
}
|
||||
}
|
||||
|
||||
var customFunctionOnce sync.Once
|
||||
|
||||
func BenchmarkCustomFunctions(b *testing.B) {
|
||||
|
|
Loading…
Reference in New Issue