Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for sqlite3_status64 #1270

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
6 changes: 6 additions & 0 deletions sqlite3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down