Files
sqlite3/conn.go

518 lines
14 KiB
Go
Raw Permalink Normal View History

2023-01-12 05:57:09 +00:00
package sqlite3
2023-01-11 14:58:20 +00:00
import (
"context"
2023-02-28 16:03:31 +00:00
"fmt"
2024-02-02 23:41:34 +00:00
"math"
2024-12-13 10:23:43 +00:00
"math/rand"
2023-02-28 16:03:31 +00:00
"net/url"
2025-01-07 16:31:12 +00:00
"runtime"
2023-02-28 16:03:31 +00:00
"strings"
2024-02-02 23:41:34 +00:00
"time"
2023-03-29 15:01:25 +01:00
2024-10-18 12:20:32 +01:00
"github.com/tetratelabs/wazero/api"
2023-03-29 15:01:25 +01:00
"github.com/ncruces/go-sqlite3/internal/util"
"github.com/ncruces/go-sqlite3/vfs"
2023-01-11 14:58:20 +00:00
)
2023-02-09 16:40:48 +00:00
// Conn is a database connection handle.
2023-03-01 10:34:08 +00:00
// A Conn is not safe for concurrent use by multiple goroutines.
2023-02-09 16:40:48 +00:00
//
2023-11-09 16:35:45 +00:00
// https://sqlite.org/c3ref/sqlite3.html
2023-01-12 05:57:09 +00:00
type Conn struct {
2023-07-03 17:21:35 +01:00
*sqlite
2023-02-14 18:21:18 +00:00
2024-01-27 10:57:46 +00:00
interrupt context.Context
pending *Stmt
stmts []*Stmt
2024-09-27 12:33:57 +01:00
busy func(context.Context, int) bool
2024-01-27 10:57:46 +00:00
log func(xErrorCode, string)
collation func(*Conn, string)
wal func(*Conn, string, int) error
trace func(TraceEvent, any, any) error
2024-01-27 10:57:46 +00:00
authorizer func(AuthorizerActionCode, string, string, string, string) AuthorizerReturnCode
update func(AuthorizerActionCode, string, string, int64)
commit func() bool
rollback func()
arena arena
2023-04-11 15:33:38 +01:00
2024-12-13 16:04:37 +00:00
busy1st time.Time
busylst time.Time
2024-12-13 10:23:43 +00:00
handle uint32
2023-01-11 14:58:20 +00:00
}
2024-09-27 12:32:11 +01:00
// Open calls [OpenFlags] with [OPEN_READWRITE], [OPEN_CREATE] and [OPEN_URI].
func Open(filename string) (*Conn, error) {
2024-10-04 13:31:53 +01:00
return newConn(context.Background(), filename, OPEN_READWRITE|OPEN_CREATE|OPEN_URI)
}
// OpenContext is like [Open] but includes a context,
// which is used to interrupt the process of opening the connectiton.
func OpenContext(ctx context.Context, filename string) (*Conn, error) {
return newConn(ctx, filename, OPEN_READWRITE|OPEN_CREATE|OPEN_URI)
2023-01-16 12:54:24 +00:00
}
2023-02-09 16:40:48 +00:00
// OpenFlags opens an SQLite database file as specified by the filename argument.
//
2024-10-04 13:31:53 +01:00
// If none of the required flags are used, a combination of [OPEN_READWRITE] and [OPEN_CREATE] is used.
2023-02-28 16:03:31 +00:00
// If a URI filename is used, PRAGMA statements to execute can be specified using "_pragma":
//
2023-06-24 02:18:56 +01:00
// sqlite3.Open("file:demo.db?_pragma=busy_timeout(10000)")
2023-02-28 16:03:31 +00:00
//
2023-11-09 16:35:45 +00:00
// https://sqlite.org/c3ref/open.html
func OpenFlags(filename string, flags OpenFlag) (*Conn, error) {
2023-03-16 12:27:44 +00:00
if flags&(OPEN_READONLY|OPEN_READWRITE|OPEN_CREATE) == 0 {
flags |= OPEN_READWRITE | OPEN_CREATE
}
2024-10-04 13:31:53 +01:00
return newConn(context.Background(), filename, flags)
}
2023-10-25 12:56:52 +01:00
type connKey struct{}
2024-10-07 13:22:31 +01:00
func newConn(ctx context.Context, filename string, flags OpenFlag) (res *Conn, _ error) {
err := ctx.Err()
2024-10-04 13:31:53 +01:00
if err != nil {
return nil, err
}
2024-10-07 13:22:31 +01:00
c := &Conn{interrupt: ctx}
c.sqlite, err = instantiateSQLite()
2023-01-11 14:58:20 +00:00
if err != nil {
2023-01-12 05:57:09 +00:00
return nil, err
2023-01-11 14:58:20 +00:00
}
2023-01-12 13:43:35 +00:00
defer func() {
2024-10-07 13:22:31 +01:00
if res == nil {
c.Close()
c.sqlite.close()
} else {
c.interrupt = context.Background()
2023-01-12 13:43:35 +00:00
}
}()
2023-01-12 05:57:09 +00:00
2023-10-25 12:56:52 +01:00
c.ctx = context.WithValue(c.ctx, connKey{}, c)
2024-10-04 13:31:53 +01:00
c.arena = c.newArena(1024)
2023-03-03 14:48:56 +00:00
c.handle, err = c.openDB(filename, flags)
2024-07-08 12:06:57 +01:00
if err == nil {
err = initExtensions(c)
}
2024-10-07 13:22:31 +01:00
if err != nil {
return nil, err
}
return c, nil
2023-03-03 14:48:56 +00:00
}
2023-02-10 16:42:49 +00:00
2023-03-03 14:48:56 +00:00
func (c *Conn) openDB(filename string, flags OpenFlag) (uint32, error) {
2023-11-29 10:38:03 +00:00
defer c.arena.mark()()
2023-02-14 11:34:24 +00:00
connPtr := c.arena.new(ptrlen)
namePtr := c.arena.string(filename)
2023-01-12 13:43:35 +00:00
2023-03-15 13:29:09 +00:00
flags |= OPEN_EXRESCODE
2023-11-30 17:52:35 +00:00
r := c.call("sqlite3_open_v2", uint64(namePtr), uint64(connPtr), uint64(flags), 0)
2023-01-11 14:58:20 +00:00
2023-03-29 15:01:25 +01:00
handle := util.ReadUint32(c.mod, connPtr)
2023-07-03 17:21:35 +01:00
if err := c.sqlite.error(r, handle); err != nil {
2023-03-03 14:48:56 +00:00
c.closeDB(handle)
return 0, err
2023-01-12 05:57:09 +00:00
}
2023-02-28 16:03:31 +00:00
2024-10-04 13:31:53 +01:00
c.call("sqlite3_progress_handler_go", uint64(handle), 100)
2023-02-28 16:03:31 +00:00
if flags|OPEN_URI != 0 && strings.HasPrefix(filename, "file:") {
var pragmas strings.Builder
if _, after, ok := strings.Cut(filename, "?"); ok {
query, _ := url.ParseQuery(after)
for _, p := range query["_pragma"] {
pragmas.WriteString(`PRAGMA `)
pragmas.WriteString(p)
2023-12-06 15:39:26 +00:00
pragmas.WriteString(`;`)
2023-02-28 16:03:31 +00:00
}
}
2024-04-26 00:07:04 +01:00
if pragmas.Len() != 0 {
2024-10-04 13:31:53 +01:00
c.checkInterrupt(handle)
2024-04-26 00:07:04 +01:00
pragmaPtr := c.arena.string(pragmas.String())
r := c.call("sqlite3_exec", uint64(handle), uint64(pragmaPtr), 0, 0, 0)
if err := c.sqlite.error(r, handle, pragmas.String()); err != nil {
2023-03-10 15:50:11 +00:00
err = fmt.Errorf("sqlite3: invalid _pragma: %w", err)
2024-04-26 00:07:04 +01:00
c.closeDB(handle)
return 0, err
2023-03-10 15:50:11 +00:00
}
2023-02-28 16:03:31 +00:00
}
}
2023-03-03 14:48:56 +00:00
return handle, nil
}
func (c *Conn) closeDB(handle uint32) {
2023-11-30 17:52:35 +00:00
r := c.call("sqlite3_close_v2", uint64(handle))
2023-07-03 17:21:35 +01:00
if err := c.sqlite.error(r, handle); err != nil {
2023-03-03 14:48:56 +00:00
panic(err)
}
2023-01-12 05:57:09 +00:00
}
2023-02-10 14:14:19 +00:00
// Close closes the database connection.
//
2023-02-09 16:40:48 +00:00
// If the database connection is associated with unfinalized prepared statements,
// open blob handles, and/or unfinished backup objects,
// Close will leave the database connection open and return [BUSY].
//
2023-03-01 10:34:08 +00:00
// It is safe to close a nil, zero or closed Conn.
//
2023-11-09 16:35:45 +00:00
// https://sqlite.org/c3ref/close.html
2023-01-12 13:43:35 +00:00
func (c *Conn) Close() error {
2023-02-16 13:52:05 +00:00
if c == nil || c.handle == 0 {
2023-02-10 14:14:19 +00:00
return nil
}
2023-03-07 14:45:54 +00:00
c.pending.Close()
c.pending = nil
2023-02-14 18:21:18 +00:00
2023-11-30 17:52:35 +00:00
r := c.call("sqlite3_close", uint64(c.handle))
2023-05-25 13:17:44 +01:00
if err := c.error(r); err != nil {
2023-01-17 13:43:16 +00:00
return err
2023-01-12 13:43:35 +00:00
}
2023-02-10 14:14:19 +00:00
c.handle = 0
2023-07-03 17:21:35 +01:00
return c.close()
2023-01-11 14:58:20 +00:00
}
2023-02-24 15:06:19 +00:00
// Exec is a convenience function that allows an application to run
// multiple statements of SQL without having to use a lot of code.
//
2023-11-09 16:35:45 +00:00
// https://sqlite.org/c3ref/exec.html
2023-02-24 15:06:19 +00:00
func (c *Conn) Exec(sql string) error {
2023-11-29 10:38:03 +00:00
defer c.arena.mark()()
2023-02-24 15:06:19 +00:00
sqlPtr := c.arena.string(sql)
2024-10-04 13:31:53 +01:00
c.checkInterrupt(c.handle)
2023-11-30 17:52:35 +00:00
r := c.call("sqlite3_exec", uint64(c.handle), uint64(sqlPtr), 0, 0, 0)
2023-11-29 10:38:03 +00:00
return c.error(r, sql)
2023-02-24 15:06:19 +00:00
}
// Prepare calls [Conn.PrepareFlags] with no flags.
func (c *Conn) Prepare(sql string) (stmt *Stmt, tail string, err error) {
return c.PrepareFlags(sql, 0)
}
// PrepareFlags compiles the first SQL statement in sql;
// tail is left pointing to what remains uncompiled.
// If the input text contains no SQL (if the input is an empty string or a comment),
// both stmt and err will be nil.
//
2023-11-09 16:35:45 +00:00
// https://sqlite.org/c3ref/prepare.html
2023-02-24 15:06:19 +00:00
func (c *Conn) PrepareFlags(sql string, flags PrepareFlag) (stmt *Stmt, tail string, err error) {
2024-04-25 13:29:19 +01:00
if len(sql) > _MAX_SQL_LENGTH {
2023-11-24 17:25:02 +00:00
return nil, "", TOOBIG
}
2023-02-24 15:06:19 +00:00
2023-11-29 10:38:03 +00:00
defer c.arena.mark()()
2023-02-24 15:06:19 +00:00
stmtPtr := c.arena.new(ptrlen)
tailPtr := c.arena.new(ptrlen)
sqlPtr := c.arena.string(sql)
2024-10-08 16:38:57 +01:00
c.checkInterrupt(c.handle)
2023-11-30 17:52:35 +00:00
r := c.call("sqlite3_prepare_v3", uint64(c.handle),
2023-02-24 15:06:19 +00:00
uint64(sqlPtr), uint64(len(sql)+1), uint64(flags),
uint64(stmtPtr), uint64(tailPtr))
stmt = &Stmt{c: c}
2023-03-29 15:01:25 +01:00
stmt.handle = util.ReadUint32(c.mod, stmtPtr)
2023-11-30 12:26:15 +00:00
if sql := sql[util.ReadUint32(c.mod, tailPtr)-sqlPtr:]; sql != "" {
tail = sql
}
2023-02-24 15:06:19 +00:00
2023-05-25 13:17:44 +01:00
if err := c.error(r, sql); err != nil {
2023-02-24 15:06:19 +00:00
return nil, "", err
}
if stmt.handle == 0 {
return nil, "", nil
}
c.stmts = append(c.stmts, stmt)
2023-12-06 15:39:26 +00:00
return stmt, tail, nil
2023-02-24 15:06:19 +00:00
}
2024-01-17 15:39:13 +00:00
// DBName returns the schema name for n-th database on the database connection.
//
// https://sqlite.org/c3ref/db_name.html
func (c *Conn) DBName(n int) string {
r := c.call("sqlite3_db_name", uint64(c.handle), uint64(n))
ptr := uint32(r)
if ptr == 0 {
return ""
}
return util.ReadString(c.mod, ptr, _MAX_NAME)
}
// Filename returns the filename for a database.
//
// https://sqlite.org/c3ref/db_filename.html
func (c *Conn) Filename(schema string) *vfs.Filename {
var ptr uint32
if schema != "" {
defer c.arena.mark()()
ptr = c.arena.string(schema)
}
r := c.call("sqlite3_db_filename", uint64(c.handle), uint64(ptr))
2024-07-26 01:23:35 +01:00
return vfs.GetFilename(c.ctx, c.mod, uint32(r), vfs.OPEN_MAIN_DB)
}
2024-01-17 15:39:13 +00:00
// ReadOnly determines if a database is read-only.
//
// https://sqlite.org/c3ref/db_readonly.html
func (c *Conn) ReadOnly(schema string) (ro bool, ok bool) {
var ptr uint32
if schema != "" {
defer c.arena.mark()()
ptr = c.arena.string(schema)
}
r := c.call("sqlite3_db_readonly", uint64(c.handle), uint64(ptr))
2024-01-18 15:53:00 +00:00
return int32(r) > 0, int32(r) < 0
2024-01-17 15:39:13 +00:00
}
2023-02-24 14:31:41 +00:00
// GetAutocommit tests the connection for auto-commit mode.
//
2023-11-09 16:35:45 +00:00
// https://sqlite.org/c3ref/get_autocommit.html
2023-02-24 14:31:41 +00:00
func (c *Conn) GetAutocommit() bool {
2023-11-30 17:52:35 +00:00
r := c.call("sqlite3_get_autocommit", uint64(c.handle))
2023-05-25 13:17:44 +01:00
return r != 0
2023-02-24 14:31:41 +00:00
}
2023-02-24 15:06:19 +00:00
// LastInsertRowID returns the rowid of the most recent successful INSERT
// on the database connection.
//
2023-11-09 16:35:45 +00:00
// https://sqlite.org/c3ref/last_insert_rowid.html
2023-02-27 13:45:32 +00:00
func (c *Conn) LastInsertRowID() int64 {
2023-11-30 17:52:35 +00:00
r := c.call("sqlite3_last_insert_rowid", uint64(c.handle))
2023-05-25 13:17:44 +01:00
return int64(r)
2023-02-24 15:06:19 +00:00
}
2024-01-17 15:39:13 +00:00
// SetLastInsertRowID allows the application to set the value returned by
// [Conn.LastInsertRowID].
//
// https://sqlite.org/c3ref/set_last_insert_rowid.html
func (c *Conn) SetLastInsertRowID(id int64) {
c.call("sqlite3_set_last_insert_rowid", uint64(c.handle), uint64(id))
}
2023-02-24 15:06:19 +00:00
// Changes returns the number of rows modified, inserted or deleted
// by the most recently completed INSERT, UPDATE or DELETE statement
// on the database connection.
//
2023-11-09 16:35:45 +00:00
// https://sqlite.org/c3ref/changes.html
2023-02-27 13:45:32 +00:00
func (c *Conn) Changes() int64 {
2023-11-30 17:52:35 +00:00
r := c.call("sqlite3_changes64", uint64(c.handle))
2023-05-25 13:17:44 +01:00
return int64(r)
2023-02-24 15:06:19 +00:00
}
2024-01-17 15:39:13 +00:00
// TotalChanges returns the number of rows modified, inserted or deleted
// by all INSERT, UPDATE or DELETE statements completed
// since the database connection was opened.
//
// https://sqlite.org/c3ref/total_changes.html
func (c *Conn) TotalChanges() int64 {
r := c.call("sqlite3_total_changes64", uint64(c.handle))
return int64(r)
}
// ReleaseMemory frees memory used by a database connection.
//
// https://sqlite.org/c3ref/db_release_memory.html
func (c *Conn) ReleaseMemory() error {
r := c.call("sqlite3_db_release_memory", uint64(c.handle))
return c.error(r)
}
2024-10-04 13:31:53 +01:00
// GetInterrupt gets the context set with [Conn.SetInterrupt].
2024-04-12 14:57:13 +01:00
func (c *Conn) GetInterrupt() context.Context {
return c.interrupt
}
2023-02-24 14:56:49 +00:00
// SetInterrupt interrupts a long-running query when a context is done.
2023-02-14 18:21:18 +00:00
//
// Subsequent uses of the connection will return [INTERRUPT]
2023-02-24 14:56:49 +00:00
// until the context is reset by another call to SetInterrupt.
2023-02-14 18:21:18 +00:00
//
2023-03-01 10:34:08 +00:00
// To associate a timeout with a connection:
2023-02-14 18:21:18 +00:00
//
// ctx, cancel := context.WithTimeout(context.TODO(), 100*time.Millisecond)
2023-02-24 14:56:49 +00:00
// conn.SetInterrupt(ctx)
2023-02-14 18:21:18 +00:00
// defer cancel()
//
2023-02-24 14:56:49 +00:00
// SetInterrupt returns the old context assigned to the connection.
//
2023-11-09 16:35:45 +00:00
// https://sqlite.org/c3ref/interrupt.html
2023-02-24 14:56:49 +00:00
func (c *Conn) SetInterrupt(ctx context.Context) (old context.Context) {
2024-10-04 13:31:53 +01:00
old = c.interrupt
c.interrupt = ctx
if ctx == old || ctx.Done() == old.Done() {
return old
2023-09-20 02:41:09 +01:00
}
2023-12-15 00:42:12 +00:00
// A busy SQL statement prevents SQLite from ignoring an interrupt
// that comes before any other statements are started.
2023-10-25 12:56:52 +01:00
if c.pending == nil {
defer c.arena.mark()()
stmtPtr := c.arena.new(ptrlen)
loopPtr := c.arena.string(`WITH RECURSIVE c(x) AS (VALUES(0) UNION ALL SELECT x FROM c) SELECT x FROM c`)
2024-10-04 13:31:53 +01:00
c.call("sqlite3_prepare_v3", uint64(c.handle), uint64(loopPtr), math.MaxUint64,
uint64(PREPARE_PERSISTENT), uint64(stmtPtr), 0)
c.pending = &Stmt{c: c}
c.pending.handle = util.ReadUint32(c.mod, stmtPtr)
2023-03-07 14:45:54 +00:00
}
2023-02-14 18:21:18 +00:00
2024-10-04 13:31:53 +01:00
if old.Done() != nil && ctx.Err() == nil {
2024-01-16 15:08:26 +00:00
c.pending.Reset()
}
2024-10-04 13:31:53 +01:00
if ctx.Done() != nil {
2024-01-16 15:08:26 +00:00
c.pending.Step()
}
2023-10-25 12:56:52 +01:00
return old
}
2023-02-24 14:31:41 +00:00
2024-10-04 13:31:53 +01:00
func (c *Conn) checkInterrupt(handle uint32) {
if c.interrupt.Err() != nil {
c.call("sqlite3_interrupt", uint64(handle))
2023-12-27 14:06:44 +00:00
}
}
2024-10-04 13:31:53 +01:00
func progressCallback(ctx context.Context, mod api.Module, _ uint32) (interrupt uint32) {
2025-01-07 16:31:12 +00:00
if c, ok := ctx.Value(connKey{}).(*Conn); ok {
if c.interrupt.Done() != nil {
runtime.Gosched()
}
if c.interrupt.Err() != nil {
interrupt = 1
}
2023-10-25 12:56:52 +01:00
}
2024-04-12 14:57:13 +01:00
return interrupt
2023-02-14 18:21:18 +00:00
}
2024-02-02 23:41:34 +00:00
// BusyTimeout sets a busy timeout.
//
// https://sqlite.org/c3ref/busy_timeout.html
func (c *Conn) BusyTimeout(timeout time.Duration) error {
ms := min((timeout+time.Millisecond-1)/time.Millisecond, math.MaxInt32)
r := c.call("sqlite3_busy_timeout", uint64(c.handle), uint64(ms))
return c.error(r)
}
2024-10-04 13:31:53 +01:00
func timeoutCallback(ctx context.Context, mod api.Module, count, tmout int32) (retry uint32) {
2024-12-13 10:23:43 +00:00
// https://fractaledmind.github.io/2024/04/15/sqlite-on-rails-the-how-and-why-of-optimal-performance/
2024-10-04 13:31:53 +01:00
if c, ok := ctx.Value(connKey{}).(*Conn); ok && c.interrupt.Err() == nil {
2024-12-13 10:23:43 +00:00
switch {
case count == 0:
2024-12-13 16:04:37 +00:00
c.busy1st = time.Now()
case time.Since(c.busy1st) >= time.Duration(tmout)*time.Millisecond:
2024-12-13 10:23:43 +00:00
return 0
2024-05-19 01:04:56 +01:00
}
2024-12-13 16:04:37 +00:00
if time.Since(c.busylst) < time.Millisecond {
const sleepIncrement = 2*1024*1024 - 1 // power of two, ~2ms
time.Sleep(time.Duration(rand.Int63() & sleepIncrement))
}
c.busylst = time.Now()
2024-12-13 10:23:43 +00:00
return 1
2024-05-19 01:04:56 +01:00
}
2024-09-03 12:24:03 +01:00
return 0
2024-05-19 01:04:56 +01:00
}
2024-02-02 23:41:34 +00:00
// BusyHandler registers a callback to handle [BUSY] errors.
//
// https://sqlite.org/c3ref/busy_handler.html
2024-09-27 12:33:57 +01:00
func (c *Conn) BusyHandler(cb func(ctx context.Context, count int) (retry bool)) error {
2024-02-02 23:41:34 +00:00
var enable uint64
if cb != nil {
enable = 1
}
r := c.call("sqlite3_busy_handler_go", uint64(c.handle), enable)
if err := c.error(r); err != nil {
return err
}
c.busy = cb
return nil
}
2024-04-12 14:57:13 +01:00
func busyCallback(ctx context.Context, mod api.Module, pDB uint32, count int32) (retry uint32) {
2024-09-27 12:33:57 +01:00
if c, ok := ctx.Value(connKey{}).(*Conn); ok && c.handle == pDB && c.busy != nil {
interrupt := c.interrupt
if interrupt == nil {
interrupt = context.Background()
}
if interrupt.Err() == nil && c.busy(interrupt, int(count)) {
2024-04-12 14:57:13 +01:00
retry = 1
2024-02-02 23:41:34 +00:00
}
}
2024-04-12 14:57:13 +01:00
return retry
2024-02-02 23:41:34 +00:00
}
// Status retrieves runtime status information about a database connection.
//
// https://sqlite.org/c3ref/db_status.html
func (c *Conn) Status(op DBStatus, reset bool) (current, highwater int, err error) {
defer c.arena.mark()()
2024-10-22 13:08:31 +01:00
hiPtr := c.arena.new(intlen)
curPtr := c.arena.new(intlen)
var i uint64
if reset {
i = 1
}
r := c.call("sqlite3_db_status", uint64(c.handle),
uint64(op), uint64(curPtr), uint64(hiPtr), i)
if err = c.error(r); err == nil {
current = int(util.ReadUint32(c.mod, curPtr))
highwater = int(util.ReadUint32(c.mod, hiPtr))
}
return
}
// TableColumnMetadata extracts metadata about a column of a table.
//
// https://sqlite.org/c3ref/table_column_metadata.html
func (c *Conn) TableColumnMetadata(schema, table, column string) (declType, collSeq string, notNull, primaryKey, autoInc bool, err error) {
defer c.arena.mark()()
var schemaPtr, columnPtr uint32
declTypePtr := c.arena.new(ptrlen)
collSeqPtr := c.arena.new(ptrlen)
notNullPtr := c.arena.new(ptrlen)
autoIncPtr := c.arena.new(ptrlen)
2024-10-22 13:08:31 +01:00
primaryKeyPtr := c.arena.new(ptrlen)
if schema != "" {
schemaPtr = c.arena.string(schema)
}
tablePtr := c.arena.string(table)
if column != "" {
columnPtr = c.arena.string(column)
}
r := c.call("sqlite3_table_column_metadata", uint64(c.handle),
uint64(schemaPtr), uint64(tablePtr), uint64(columnPtr),
uint64(declTypePtr), uint64(collSeqPtr),
uint64(notNullPtr), uint64(primaryKeyPtr), uint64(autoIncPtr))
if err = c.error(r); err == nil && column != "" {
2024-12-09 19:26:47 +00:00
if ptr := util.ReadUint32(c.mod, declTypePtr); ptr != 0 {
declType = util.ReadString(c.mod, ptr, _MAX_NAME)
}
if ptr := util.ReadUint32(c.mod, collSeqPtr); ptr != 0 {
collSeq = util.ReadString(c.mod, ptr, _MAX_NAME)
}
notNull = util.ReadUint32(c.mod, notNullPtr) != 0
autoInc = util.ReadUint32(c.mod, autoIncPtr) != 0
primaryKey = util.ReadUint32(c.mod, primaryKeyPtr) != 0
}
return
}
2023-02-10 16:42:49 +00:00
func (c *Conn) error(rc uint64, sql ...string) error {
2023-07-03 17:21:35 +01:00
return c.sqlite.error(rc, c.handle, sql...)
2023-03-03 14:48:56 +00:00
}
func (c *Conn) stmtsIter(yield func(*Stmt) bool) {
for _, s := range c.stmts {
if !yield(s) {
break
}
}
}