add support for sqlite3_status64

This commit is contained in:
Michael Stürmer 2024-08-12 11:55:45 +02:00
parent 3c0390b77c
commit 6fdf9a58d5
2 changed files with 41 additions and 0 deletions

View File

@ -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. // Begin transaction.
func (c *SQLiteConn) Begin() (driver.Tx, error) { func (c *SQLiteConn) Begin() (driver.Tx, error) {
return c.begin(context.Background()) return c.begin(context.Background())

View File

@ -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 var customFunctionOnce sync.Once
func BenchmarkCustomFunctions(b *testing.B) { func BenchmarkCustomFunctions(b *testing.B) {