CLI supports PRAGMA directives

Add a doc about rqlite and PRAGMA.
This commit is contained in:
Philip O'Toole
2021-08-10 13:16:05 -04:00
parent 143713d84f
commit e1e239888a
3 changed files with 63 additions and 3 deletions

62
DOC/PRAGMA.md Normal file
View File

@@ -0,0 +1,62 @@
# PRAGMA Directives
You can issue [`PRAGMA`](https://www.sqlite.org/pragma.html) directives to rqlite, and they will be passed to the underlying SQLite database. Certain `PRAGMA` directives, which alter the operation of the SQLite database, may not make sense in the context of rqlite (since rqlite does not given direct control over its connections to the SQLite database). Furthermore some `PRAGMA` directives may even break rqlite. If you have questions about a specific `PRAGMA` directive, the [rqlite Google Group](https://groups.google.com/group/rqlite) is a good place to start the discussion.
`PRAGMA` directives which just return information about the SQLite database, without changing its operation, are always safe.
## Issuing a `PRAGMA` directive
The rqlite CLI supports issuing `PRAGMA` directives. For example:
```
127.0.0.1:4001> pragma compile_options
+----------------------------+
| compile_options |
+----------------------------+
| COMPILER=gcc-7.5.0 |
+----------------------------+
| DEFAULT_WAL_SYNCHRONOUS=1 |
+----------------------------+
| ENABLE_DBSTAT_VTAB |
+----------------------------+
| ENABLE_FTS3 |
+----------------------------+
| ENABLE_FTS3_PARENTHESIS |
+----------------------------+
| ENABLE_JSON1 |
+----------------------------+
| ENABLE_RTREE |
+----------------------------+
| ENABLE_UPDATE_DELETE_LIMIT |
+----------------------------+
| OMIT_DEPRECATED |
+----------------------------+
| OMIT_SHARED_CACHE |
+----------------------------+
| SYSTEM_MALLOC |
+----------------------------+
| THREADSAFE=1 |
+----------------------------+
```
`PRAGMA` directives may also be issued using the `/db/execute` or `/db/query` endpoint. For example:
```
$ curl -G 'localhost:4001/db/query?pretty&timings' --data-urlencode 'q=PRAGMA foreign_keys'
{
"results": [
{
"columns": [
"foreign_keys"
],
"types": [
""
],
"values": [
[
0
]
],
"time": 0.000070499
}
],
"time": 0.000540857
}$
```

View File

@@ -157,6 +157,7 @@ func main() {
case ".QUIT", "QUIT", "EXIT":
break FOR_READ
case "SELECT":
case "PRAGMA":
err = queryWithClient(ctx, client, argv, timer, line)
default:
err = executeWithClient(ctx, client, argv, timer, line)

View File

@@ -56,9 +56,6 @@ func (r *Rows) validate() error {
if r.Error != "" {
return fmt.Errorf(r.Error)
}
if r.Columns == nil || r.Types == nil {
return fmt.Errorf("unexpected result")
}
return nil
}