Skip to content

Commit 997b133

Browse files
committed
add sqlite_dbstat tag for the DBSTAT virtual table
Used to gather statistics information about table disk usage.
1 parent f76bae4 commit 997b133

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ go-sqlite3
33

44
[![Go Reference](https://pkg.go.dev/badge/github.com/mattn/go-sqlite3.svg)](https://pkg.go.dev/github.com/mattn/go-sqlite3)
55
[![GitHub Actions](https://github.com/mattn/go-sqlite3/workflows/Go/badge.svg)](https://github.com/mattn/go-sqlite3/actions?query=workflow%3AGo)
6-
[![Financial Contributors on Open Collective](https://opencollective.com/mattn-go-sqlite3/all/badge.svg?label=financial+contributors)](https://opencollective.com/mattn-go-sqlite3)
6+
[![Financial Contributors on Open Collective](https://opencollective.com/mattn-go-sqlite3/all/badge.svg?label=financial+contributors)](https://opencollective.com/mattn-go-sqlite3)
77
[![codecov](https://codecov.io/gh/mattn/go-sqlite3/branch/master/graph/badge.svg)](https://codecov.io/gh/mattn/go-sqlite3)
88
[![Go Report Card](https://goreportcard.com/badge/github.com/mattn/go-sqlite3)](https://goreportcard.com/report/github.com/mattn/go-sqlite3)
99

@@ -165,7 +165,7 @@ go build -tags "icu json1 fts5 secure_delete"
165165
| App Armor | sqlite_app_armor | When defined, this C-preprocessor macro activates extra code that attempts to detect misuse of the SQLite API, such as passing in NULL pointers to required parameters or using objects after they have been destroyed. <br><br>App Armor is not available under `Windows`. |
166166
| Disable Load Extensions | sqlite_omit_load_extension | Loading of external extensions is enabled by default.<br><br>To disable extension loading add the build tag `sqlite_omit_load_extension`. |
167167
| Enable Serialization with `libsqlite3` | sqlite_serialize | Serialization and deserialization of a SQLite database is available by default, unless the build tag `libsqlite3` is set.<br><br>To enable this functionality even if `libsqlite3` is set, add the build tag `sqlite_serialize`. |
168-
| Foreign Keys | sqlite_foreign_keys | This macro determines whether enforcement of foreign key constraints is enabled or disabled by default for new database connections.<br><br>Each database connection can always turn enforcement of foreign key constraints on and off and run-time using the foreign_keys pragma.<br><br>Enforcement of foreign key constraints is normally off by default, but if this compile-time parameter is set to 1, enforcement of foreign key constraints will be on by default |
168+
| Foreign Keys | sqlite_foreign_keys | This macro determines whether enforcement of foreign key constraints is enabled or disabled by default for new database connections.<br><br>Each database connection can always turn enforcement of foreign key constraints on and off and run-time using the foreign_keys pragma.<br><br>Enforcement of foreign key constraints is normally off by default, but if this compile-time parameter is set to 1, enforcement of foreign key constraints will be on by default |
169169
| Full Auto Vacuum | sqlite_vacuum_full | Set the default auto vacuum to full |
170170
| Incremental Auto Vacuum | sqlite_vacuum_incr | Set the default auto vacuum to incremental |
171171
| Full Text Search Engine | sqlite_fts5 | When this option is defined in the amalgamation, versions 5 of the full-text search engine (fts5) is added to the build automatically |
@@ -180,6 +180,7 @@ go build -tags "icu json1 fts5 secure_delete"
180180
| Tracing / Debug | sqlite_trace | Activate trace functions |
181181
| User Authentication | sqlite_userauth | SQLite User Authentication see [User Authentication](#user-authentication) for more information. |
182182
| Virtual Tables | sqlite_vtable | SQLite Virtual Tables see [SQLite Official VTABLE Documentation](https://www.sqlite.org/vtab.html) for more information, and a [full example here](https://github.com/mattn/go-sqlite3/tree/master/_example/vtable) |
183+
| The DBSTAT Virtual Table | sqlite_dbstat | The DBSTAT virtual table is a read-only virtual table that returns information about the amount of disk space used to store the content of an SQLite database. See [SQLite Official Documentation](https://www.sqlite.org/dbstat.html) for more information. |
183184

184185
# Compilation
185186

@@ -205,7 +206,7 @@ To compile for `ARM` use the following environment:
205206
```bash
206207
env CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ \
207208
CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 \
208-
go build -v
209+
go build -v
209210
```
210211

211212
Additional information:
@@ -298,7 +299,7 @@ go build -tags "darwin arm64"
298299
If you wish to link directly to libsqlite3, use the `libsqlite3` build tag:
299300

300301
```
301-
# x86
302+
# x86
302303
go build -tags "libsqlite3 darwin amd64"
303304
# ARM
304305
go build -tags "libsqlite3 darwin arm64"
@@ -508,9 +509,9 @@ For an example, see [dinedal/go-sqlite3-extension-functions](https://github.com/
508509
specified `":memory:"`, that connection will see a brand new database. A
509510
workaround is to use `"file::memory:?cache=shared"` (or `"file:foobar?mode=memory&cache=shared"`). Every
510511
connection to this string will point to the same in-memory database.
511-
512+
512513
Note that if the last database connection in the pool closes, the in-memory database is deleted. Make sure the [max idle connection limit](https://golang.org/pkg/database/sql/#DB.SetMaxIdleConns) is > 0, and the [connection lifetime](https://golang.org/pkg/database/sql/#DB.SetConnMaxLifetime) is infinite.
513-
514+
514515
For more information see:
515516
* [#204](https://github.com/mattn/go-sqlite3/issues/204)
516517
* [#511](https://github.com/mattn/go-sqlite3/issues/511)
@@ -544,7 +545,7 @@ For an example, see [dinedal/go-sqlite3-extension-functions](https://github.com/
544545
```
545546

546547
Next, please set the database connections of the SQL package to 1:
547-
548+
548549
```go
549550
db.SetMaxOpenConns(1)
550551
```

sqlite3_opt_dbstat.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (C) 2025 Yasuhiro Matsumoto <[email protected]>.
2+
// Copyright (C) 2025 Jakob Borg <[email protected]>.
3+
//
4+
// Use of this source code is governed by an MIT-style
5+
// license that can be found in the LICENSE file.
6+
7+
//go:build sqlite_dbstat
8+
// +build sqlite_dbstat
9+
10+
package sqlite3
11+
12+
/*
13+
#cgo CFLAGS: -DSQLITE_ENABLE_DBSTAT_VTAB
14+
*/
15+
import "C"

0 commit comments

Comments
 (0)