2023-12-23 14:53:15 +00:00
|
|
|
package sqlite3
|
|
|
|
|
|
2023-12-27 14:06:44 +00:00
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"github.com/ncruces/go-sqlite3/internal/util"
|
|
|
|
|
"github.com/tetratelabs/wazero/api"
|
|
|
|
|
)
|
2023-12-23 14:53:15 +00:00
|
|
|
|
|
|
|
|
// Config makes configuration changes to a database connection.
|
2023-12-27 14:06:44 +00:00
|
|
|
// Only boolean configuration options are supported.
|
2023-12-23 14:53:15 +00:00
|
|
|
// Called with no arg reads the current configuration value,
|
|
|
|
|
// called with one arg sets and returns the new value.
|
|
|
|
|
//
|
|
|
|
|
// https://sqlite.org/c3ref/db_config.html
|
|
|
|
|
func (c *Conn) Config(op DBConfig, arg ...bool) (bool, error) {
|
|
|
|
|
defer c.arena.mark()()
|
|
|
|
|
argsPtr := c.arena.new(2 * ptrlen)
|
|
|
|
|
|
|
|
|
|
var flag int
|
|
|
|
|
switch {
|
|
|
|
|
case len(arg) == 0:
|
|
|
|
|
flag = -1
|
|
|
|
|
case arg[0]:
|
|
|
|
|
flag = 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
util.WriteUint32(c.mod, argsPtr+0*ptrlen, uint32(flag))
|
|
|
|
|
util.WriteUint32(c.mod, argsPtr+1*ptrlen, argsPtr)
|
|
|
|
|
|
|
|
|
|
r := c.call("sqlite3_db_config", uint64(c.handle),
|
|
|
|
|
uint64(op), uint64(argsPtr))
|
|
|
|
|
return util.ReadUint32(c.mod, argsPtr) != 0, c.error(r)
|
|
|
|
|
}
|
2023-12-27 14:06:44 +00:00
|
|
|
|
2024-01-08 19:23:32 +00:00
|
|
|
// ConfigLog sets up the error logging callback for the connection.
|
2023-12-27 14:06:44 +00:00
|
|
|
//
|
2024-01-18 15:53:00 +00:00
|
|
|
// https://sqlite.org/errlog.html
|
2023-12-27 14:06:44 +00:00
|
|
|
func (c *Conn) ConfigLog(cb func(code ExtendedErrorCode, msg string)) error {
|
|
|
|
|
var enable uint64
|
|
|
|
|
if cb != nil {
|
|
|
|
|
enable = 1
|
|
|
|
|
}
|
|
|
|
|
r := c.call("sqlite3_config_log_go", enable)
|
|
|
|
|
if err := c.error(r); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
c.log = cb
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func logCallback(ctx context.Context, mod api.Module, _, iCode, zMsg uint32) {
|
|
|
|
|
if c, ok := ctx.Value(connKey{}).(*Conn); ok && c.log != nil {
|
|
|
|
|
msg := util.ReadString(mod, zMsg, _MAX_LENGTH)
|
|
|
|
|
c.log(xErrorCode(iCode), msg)
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-18 15:53:00 +00:00
|
|
|
|
|
|
|
|
// Limit allows the size of various constructs to be
|
|
|
|
|
// limited on a connection by connection basis.
|
|
|
|
|
//
|
|
|
|
|
// https://sqlite.org/c3ref/limit.html
|
|
|
|
|
func (c *Conn) Limit(id LimitCategory, value int) int {
|
|
|
|
|
r := c.call("sqlite3_limit", uint64(c.handle), uint64(id), uint64(value))
|
|
|
|
|
return int(int32(r))
|
|
|
|
|
}
|
2024-01-26 15:41:36 +00:00
|
|
|
|
|
|
|
|
func authorizerCallback(ctx context.Context, mod api.Module, pDB, action, zName3d, zName4th, zSchema, zInnerName uint32) uint32 {
|
|
|
|
|
return 0
|
|
|
|
|
}
|