csqlite

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OK   = 0
	Row  = 100
	Done = 101

	OpenReadOnly     = 0x00000001
	OpenReadWrite    = 0x00000002
	OpenCreate       = 0x00000004
	OpenURI          = 0x00000040
	OpenMemory       = 0x00000080
	OpenNoMutex      = 0x00008000
	OpenFullMutex    = 0x00010000
	OpenSharedCache  = 0x00020000
	OpenPrivateCache = 0x00040000
	OpenExResCode    = 0x02000000

	TypeInteger = 1
	TypeFloat   = 2
	TypeText    = 3
	TypeBlob    = 4
	TypeNull    = 5
)

Result codes and flags of sqlite3.h.

View Source
const (
	FuncDeterministic = 0x000000800
	FuncDirectOnly    = 0x000080000
	FuncInnocuous     = 0x000200000
)

Flags of CreateFunction (sqlite3.h).

Variables

View Source
var ErrBroken = errors.New("sqlite: connection is broken")

ErrBroken is the error of a call on a connection a host callback panicked under. Test for it with errors.Is.

View Source
var ErrCollationPanic = errors.New("panic in a Go collation")

ErrCollationPanic is under the error of a statement in which a Go collation panicked.

View Source
var ErrRolledBack = errors.New("sqlite: the transaction of the statement was rolled back while it ran: what it wrote is gone")

ErrRolledBack is the error of a statement that wrote, at its end, when SQLite rolled back its transaction while it ran: another statement of the connection failed in a way that ends the transaction (out of memory, an I/O error, a full disk, a panic in a Go collation), or ROLLBACK ran.

Functions

func AdjustTree

func AdjustTree(a0 uintptr, a1 uintptr, a2 uintptr, a3 uintptr) uintptr

func ChooseLeaf

func ChooseLeaf(a0 uintptr, a1 uintptr, a2 uintptr, a3 uintptr, a4 uintptr) uintptr

func LibVersion

func LibVersion() (string, error)

LibVersion is the version of the SQLite in the engine.

func SortByDimension

func SortByDimension(a0 uintptr, a1 uintptr, a2 uintptr, a3 uintptr, a4 uintptr, a5 uintptr, a6 uintptr)

Types

type Agg

type Agg interface {
	Step(args []driver.Value) error
	Final() (driver.Value, error)
}

Agg is the state of one group of an aggregate function written in Go: Step for each row of the group, then Final once. Step's arguments are copies, like a Func's.

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn is a connection to a database.

func Open

func Open(name string, flags int, vfs string) (*Conn, error)

Open opens a connection. It does not take OpenFullMutex: a connection has one shadow stack, so two goroutines cannot run on it at once, and a mutex of SQLite could not tell them apart.

func (*Conn) AutoCommit

func (c *Conn) AutoCommit() bool

AutoCommit says whether no transaction is open.

func (*Conn) Broken

func (c *Conn) Broken() bool

Broken says a host callback panicked under the connection. It is safe to call from any goroutine.

func (*Conn) BusyTimeout

func (c *Conn) BusyTimeout(ms int) error

BusyTimeout sets how long a statement waits for a lock.

func (*Conn) Changes

func (c *Conn) Changes() int64

Changes is the number of rows the last statement changed.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection. Its statements must be finalized first: with one open, Close returns SQLITE_BUSY and the connection stays open and usable, since SQLite would otherwise keep a half-closed connection that runs on a shadow stack already given back. A broken connection runs no C: Close frees its stack and returns the error that says so.

func (*Conn) CreateAggregate

func (c *Conn) CreateAggregate(name string, nArg int, flags int, newAgg func() Agg) error

CreateAggregate makes an aggregate function name: newAgg makes the state of each group.

func (*Conn) CreateCollation

func (c *Conn) CreateCollation(name string, cmp func(a, b string) int) error

CreateCollation makes cmp the collation name. cmp returns a negative number, 0 or a positive number as a sorts before, with or after b.

func (*Conn) CreateFunction

func (c *Conn) CreateFunction(name string, nArg int, flags int, f Func) error

CreateFunction makes f the SQL function name of nArg arguments (-1 for any number) on the connection, in place of one of the same name and nArg.

func (*Conn) DeferredFKs

func (c *Conn) DeferredFKs() bool

DeferredFKs says foreign key constraints of the transaction are not resolved yet (SQLITE_DBSTATUS_DEFERRED_FKS).

func (*Conn) Exec

func (c *Conn) Exec(sql string) error

Exec runs one or more statements that return no rows.

func (*Conn) Filename

func (c *Conn) Filename(schema string) string

Filename is the absolute name of the file of database schema ("main"), or "" for a memory or temporary database.

func (*Conn) Interrupt

func (c *Conn) Interrupt() error

Interrupt stops the statement running on the connection, from any goroutine. The statement returns SQLITE_INTERRUPT.

func (*Conn) LastInsertRowID

func (c *Conn) LastInsertRowID() int64

LastInsertRowID is the rowid of the last row inserted.

func (*Conn) Prepare

func (c *Conn) Prepare(sql string) (s *Stmt, tail string, err error)

Prepare compiles the first statement of sql. tail is the rest of sql. A nil statement with no error is sql with no statement in it.

func (*Conn) ReadOnly

func (c *Conn) ReadOnly() bool

ReadOnly says the main database is open read-only.

func (*Conn) SetLastInsertRowID

func (c *Conn) SetLastInsertRowID(id int64)

SetLastInsertRowID sets what LastInsertRowID and last_insert_rowid() give.

func (*Conn) VirtualTablesInTx

func (c *Conn) VirtualTablesInTx() bool

VirtualTablesInTx says virtual tables take part in the open transaction: one was written since it began.

type Error

type Error struct {
	Code int // the extended result code
	Msg  string
	// contains filtered or unexported fields
}

Error is a result code of SQLite with its message.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Primary

func (e *Error) Primary() int

Primary is the primary result code.

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Func

type Func func(args []driver.Value) (driver.Value, error)

Func is a SQL function written in Go. Its arguments are copies, of the types int64, float64, string, []byte and nil. It returns one of those, an int or a bool, or an error that becomes the error of the statement. A panic in it is recovered and becomes the error of the statement too.

type Stmt

type Stmt struct {
	// contains filtered or unexported fields
}

Stmt is a prepared statement.

func (*Stmt) BindBlob

func (s *Stmt) BindBlob(i int, v []byte) error

func (*Stmt) BindDouble

func (s *Stmt) BindDouble(i int, v float64) error

func (*Stmt) BindInt64

func (s *Stmt) BindInt64(i int, v int64) error

func (*Stmt) BindNull

func (s *Stmt) BindNull(i int) error

func (*Stmt) BindText

func (s *Stmt) BindText(i int, v string) error

func (*Stmt) ChangesConn

func (s *Stmt) ChangesConn() bool

ChangesConn says the statement changes the connection itself: a PRAGMA that sets something, ATTACH, DETACH, or a temporary table, index, view or trigger.

func (*Stmt) ClearBindings

func (s *Stmt) ClearBindings() error

ClearBindings sets every parameter to NULL.

func (*Stmt) ColumnBlob

func (s *Stmt) ColumnBlob(i int) []byte

ColumnBlob is the bytes of column i, copied: nil for NULL.

func (*Stmt) ColumnCount

func (s *Stmt) ColumnCount() int

ColumnCount is the number of columns of a row.

func (*Stmt) ColumnDeclType

func (s *Stmt) ColumnDeclType(i int) string

ColumnDeclType is the declared type of column i, or "".

func (*Stmt) ColumnDouble

func (s *Stmt) ColumnDouble(i int) float64

func (*Stmt) ColumnInt64

func (s *Stmt) ColumnInt64(i int) int64

func (*Stmt) ColumnName

func (s *Stmt) ColumnName(i int) string

func (*Stmt) ColumnText

func (s *Stmt) ColumnText(i int) string

ColumnText is the text of column i, copied.

func (*Stmt) ColumnType

func (s *Stmt) ColumnType(i int) int

func (*Stmt) Finalize

func (s *Stmt) Finalize() error

Finalize frees the statement.

func (*Stmt) Mergeable

func (s *Stmt) Mergeable() bool

Mergeable says the statement changes tables of the main database and touches nothing only its connection has: run on another connection of the same file, it does the same.

func (*Stmt) ParamCount

func (s *Stmt) ParamCount() int

ParamCount is the number of the largest parameter.

func (*Stmt) ParamName

func (s *Stmt) ParamName(i int) string

ParamName is the name of parameter i (from 1), with its prefix, or "".

func (*Stmt) ReadOnly

func (s *Stmt) ReadOnly() bool

ReadOnly says whether the statement writes nothing.

func (*Stmt) Reprepares

func (s *Stmt) Reprepares() int

Reprepares is how many times SQLite prepared the statement again, after a change of the schema.

func (*Stmt) Reset

func (s *Stmt) Reset() error

Reset makes the statement ready to run again. Bindings stay.

func (*Stmt) Step

func (s *Stmt) Step() (bool, error)

Step runs the statement to its next row: true when there is one.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL