sqlite3

package
v1.0.40 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

README

sqlite3 bindings

This package provides bindings for sqlite3 which I am sure is very similar to other bindings! In my defence :-) learning more about the internals of sqlite is a good exercise in itself.

The bindings do not add a lot of functionality beyond replicating the API in a more golang pattern. They are bindings afterall. It is assumed that a separate package would be used to provide a more useful API, including connection pooling, transaction and execution management, and so forth.

This package is part of a wider project, github.com/mutablelogic/go-sqlite. Please see the module documentation for more information.

Building

Unlike some of the other bindings I have seen, these do not include a full copy of sqlite as part of the build process, but expect a pkgconfig file called sqlite.pc to be present (and an existing set of header files and libraries to be available to link against, of course).

In order to locate the pkgconfig file in a non-standard location, use the PKG_CONFIG_PATH environment variable. For example, I have installed sqlite using brew install sqlite and this is how I run the tests:

[bash] git clone git@github.com:djthorpe/go-sqlite.git
[bash] cd go-sqlite
[bash] go mod tidy
[bash] PKG_CONFIG_PATH="/usr/local/opt/sqlite/lib/pkgconfig" go test -v ./sys/sqlite3

There are some examples in the cmd folder of the main repository on how to use the bindings, and various pseudo examples in this document.

Contributing & Distribution

Please do file feature requests and bugs here. The license is Apache 2 so feel free to redistribute. Redistributions in either source code or binary form must reproduce the copyright notice, and please link back to this repository for more information:

Copyright (c) 2021, David Thorpe, All rights reserved.

Connection

The Conn type is a wrapper around the sqlite3 C API, and the ConnEx type also implements various callback hooks. I recommend using the ConnEx type for full functionality. See the associated C API docmentation for more information about each method.

To open a connection to a database:

package main

import (
    "github.com/mutablelogic/go-sqlite/sys/sqlite3"
)

func main() {
    path := "..."
    db, err := sqlite3.OpenPathEx(path, sqlite3.SQLITE_OPEN_CREATE, "")
    if err != nil {
        t.Error(err)
    }
    defer db.Close()
    // ...
}

The OpenUrlEx version is also available which treats the first parameter as a URL rather than a path, and includes various options.

A default busy timeout for acquiring locks is set to five seconds. Change the busy timeout or set a custom busy handler using the SetBusyTimeout and SetBusyHandler methods. In addition, SetProgressHandler can be used to set a callback for progress during long running queries, which allows for cancellation mid-query.

Five methods will execute a query:

  • func (*ConnEx) Exec(string, func (row, cols []string) bool) error will execute one or more SQL queries (separated by a semi-colon) without bound parameters, and invoke a function callback with the results. Return true from this callback to abort any subsequent results being returned;
  • func (*ConnEx) ExecEx(string, func (row, cols []string) bool,...interface{}) error will execute one or more SQL queries (separated by a semi-colon) with bound parameters, and invoke a function callback with the results. Return true from this callback to abort any subsequent results being returned;
  • func (*ConnEx) Begin(SQTransaction) error will start a transaction. Include an argument sqlite3.SQLITE_TXN_DEFAULT, sqlite3.SQLITE_TXN_IMMEDIATE or sqlite3.SQLITE_TXN_EXCLUSIVE to set the transaction type;
  • func (*ConnEx) Commit() error will commit a transaction;
  • func (*ConnEx) Rollback() error will rollback a transaction.

The following methods return and set information about the connection. These can be used for both *Conn and *ConnEx types:

  • func (*Conn) Filename(string) string returns the filename for an attached database;
  • func (*Conn) Readonly(string) bool returns the readonly status for an attached database;
  • func (*Conn) Autocommit() bool returns false if the connection is in a transaction;
  • func (*Conn) LastInsertId() int64 returns the RowId of the last row inserted;
  • func (*Conn) Changes() int64 returns the number of rows affected by the last query;

Finally,

  • func (*Conn) Interrupt() interrupts any running queries for the connection.

When errors are returned from any methods, their error message is documented here. The result codes can be printed or cast to an integer or other numeric type as necessary.

Statements & Bindings

In order to execute a query or set of queries, they first need to be prepared. The method func (*ConnEx) Prepare(q string) (*StatementEx, error) returns a prepared statement. It is your responsibility to call func (*ConnEx) Close() error on the statement when you are finished with it. For example,

package main

import (
    "github.com/mutablelogic/go-sqlite/sys/sqlite3"
)

func main() {
    path := "..."
    db, err := sqlite3.OpenPathEx(path, sqlite3.SQLITE_OPEN_CREATE, "")
    // ...
    stmt, err := db.Prepare("SELECT * FROM table")
    if err != nil {
        // ...
    }
    defer stmt.Close()
    // ...
}

You can then either:

  • Set bound parameters using func (*StatementEx) Bind(...interface{}) error or func (*StatementEx) BindNamed(...interface{}) error to bind parameters to the statement, and then call func (*StatementEx) Exec() (*Results, error) with no arguments to execute the statement;
  • Or, call func (*StatementEx) Exec(...interface{}) (*Results, error) with bound parameters directly.

Any parameters which are not bound are assumed to be NULL. If your prepared statement has multiple queries, then you can call Exec repeatedly until no more results are returned. For example,

package main

import (
    "github.com/mutablelogic/go-sqlite/sys/sqlite3"
)

func main() {
    path := "..."
    db, err := sqlite3.OpenPathEx(path, sqlite3.SQLITE_OPEN_CREATE, "")
    // ...
    stmt, err := db.Prepare("SELECT * FROM table")
    if err != nil {
        // ...
    }
    defer stmt.Close()
    for {
        r, err := stmt.Exec()
        if err != nil {
            // Handle error
        } else if r == nil {
            // No more result queries to execute
            break
        } else {
            // Read results from query
        }
    }
}
Binding Values To Prepared Statements

Bound values are arguments in calls to the following methods:

  • func (*StatementEx) Bind(...interface{}) error to bind parameters in numerical order;
  • func (*StatementEx) BindNamed(...interface{}) error to bind parameters with name, value pairs;
  • func (*StatementEx) Exec(...interface{}) (*Results, error) to bind parameters in numerical order and execute the statement. If no argumet is given, previously bound parameters are used;
  • func (*ConnEx) ExecEx(string, func (row, cols []string) bool,...interface{}) error to execute a query directly with parameters in numerical order.

Each value is translated into an sqlite type as per the following table, where N can be 8 or 16 (in the case of integers) or 32 or 64 (in the case of integers and floats):

go sqlite
nil NULL
int,intN INTEGER
uint,uintN INTEGER
floatN FLOAT
string TEXT
bool INTEGER
[]byte BLOB

It might be extended to time.Time and custom types (using marshalling) later.

In the SQL statement text input literals may be replaced by a parameter that matches one of ?, ?N, :V, @V or $V where N is an integer and V is an alpha-numeric string. For example,

package main

import (
    "github.com/mutablelogic/go-sqlite/sys/sqlite3"
)

func main() {
    path := "..."
    db, err := sqlite3.OpenPathEx(path, sqlite3.SQLITE_OPEN_CREATE, "")
    // ...
    stmt, err := db.Prepare("SELECT * FROM table WHERE a=:A AND b=:B")
    if err != nil {
        // ...
    }
    defer stmt.Close()

    for {
        if err := stmt.BindNamed(":A", 100, ":B", 200); err != nil {
            // Handle error
        }
        r, err := stmt.Exec()
        if err != nil {
            // Handle error
        } else if r == nil {
            // No more result queries to execute
        } else if err := ReadResults(r); err != nil {
            // Handle error
        }
    }
}

Results

Results are returned from the Exec method after a statement is executed. If there are no results, then a call to func (*Results) Next() ([]interface{},error) will return nil in place of an array of values. You should repeatedly call the Next method until this occurs. For example,

func ReadResults(r *Results) error {
    for {
        row, err := r.Next()
        if err != nil {
            return err
        } else if row == nil {
            return nil
        }
        // Handle row
        // ...
    }
}

When Next is invoked without arguments, the values returned are interpreted as the above table but in reverse. For example, a NULL value is returned as nil. INTEGER values are returned as int64 and FLOAT values are returned as float64. If you invoke Next with a slice of reflect.Type then the values returned are converted to the types specified in the slice. For example,

func ReadResults(r *Results) error {
    cast := []reflect.Type{ reflect.TypeOf(bool), reflect.TypeOf(uint) }
    for {
        row, err := r.Next(cast...)
        if err != nil {
            return err
        } else if row == nil {
            return nil
        }
        // Handle row which has bool as first element and uint as second element
        // ...
    }
}

If a value cannot be cast by a call to Next, then an error is returned.

Will be extended to time.Time and custom types (using unmarshalling) later.

Reflection on the results can be used through the following method calls:

  • func (*Results) ColumnNames() []string returns column names for the results
  • func (*Results) ColumnCount() int returns column count
  • func (*Results) ColumnTypes() []Type returns column types for the results
  • func (*Results) ColumnDeclTypes() []string returns column decltypes for the results
  • func (*Results) ColumnDatabaseNames() []string returns the source database schema name for the results
  • func (*Results) ColumnTableNames() []string returns the source table name for the results
  • func (*Results) ColumnOriginNames() []string returns the origin for the results

These allocate new arrays on each call so you should use them sparingly.

User-Defined Functions

You can define scalar and aggregate user-defined functions (and override existing ones) for use in statement execution:

  • A scalar function takes zero or more argument values and returns a single value or an error;
  • An aggregate function is called for every result within the grouping and then returns a single value or an error.

The types for the function calls in go are:

  • Scalar function type StepFunc func(*Context, []*Value)
  • Aggregate function to collate each result type StepFunc func(*Context, []*Value)
  • Aggregate function to finalize type FinalFunc func(*Context)

To register a user-defined function use the following methods:

  • func (*ConnEx) CreateScalarFunction(string,int,bool,StepFunc) error where the first argument is the name of the function, the second is the number of arguments accepted (or -1 for variable number of arguments), the third flag indicates that the function returns the same value for the same input arguments, and the fourth argument is the callback.
  • func (*ConnEx) CreateAggregateFunction(string,int,bool,StepFunc,FinalFunc) error has the same arguments as above, but the fourth and fifth arguments are the step and final callbacks.

You can register multiple calls for the same function name. See the documentation for more information.

Values

Values are passed to the step function callbacks and include arguments to the function. See the documentation for more information. In addition the method func (*Value) Interface() interface{} can be used to convert the value to a go type.

Context

The *Context is passed to all the user-defined function callbacks. The context is used to store the return value and errors. See the documentation for more information. In addition, the method func (*Context) ResultInterface(v interface{}) error can be called to set a go value, and returns an error if the conversion could not be perfomed.

Commit, Update and Rollback Hooks

The func (*ConnEx) SetCommitHook(CommitHookFunc), func (*ConnEx) SetUpdateHook(UpdateHookFunc) and func (*ConnEx) SetRollbackHook(RollbackHookFunc) methods can be used to register callbacks. The signatures for these callback methods are:

  • type CommitHookFunc func() bool is invoked on commit. When it returns false, the COMMIT operation is allowed to continue normally or else the COMMIT is converted into a ROLLBACK;
  • type RollbackHookFunc func() is invoked whenever a transaction is rolled back;
  • type UpdateHookFunc func(SQAction, string, string, int64) is invoked whenever a row is updated, inserted or deleted. SQAction will be one of SQLITE_INSERT, SQLITE_DELETE or SQLITE_UPDATE. The other arguments are database name, table name and the rowid of the updated row.

You can pass nil to the methods to unregister a callback. More documentation is available on commit and rollback hooks and on update hooks.

Authentication and Authorization Hook

The func (*ConnEx) SetAuthorizerHook(AuthorizerHookFunc) method can be used to register an authentication and authorization callback. The signature for this callback is type AuthorizerHookFunc func(SQAction, [4]string) SQAuth and is invoked as SQL statements are being compiled by sqlite3_prepare.

The arguments are dependent on the action required, and are listed here with the 3rd and 4th parameters translated to the corresponding zero'th and first argument, with the third argument as the name of the database and the fourth argument as the name of the inner-most trigger or view that is responsible for the access attempt

The return value from the callback should be one of the following:

  • SQLITE_ALLOW Operation requested is ok
  • SQLITE_DENY Abort the SQL statement with an error
  • SQLITE_IGNORE Don't allow access, but don't generate an error

More documentation is available on authorization hooks.

Tracing

You can trace the execution of statements using the func (*ConnEx) SetTraceHook(TraceFunc,TraceType) method. The first argument is the callback with signature type TraceFunc func(TraceType, unsafe.Pointer, unsafe.Pointer) int and the second argument is logical OR'd value of trace types you are interested in. The callback will then be invoked with TraceType and two unsafe.Pointers:

TraceType First ptr Second ptr Interpretation of second ptr
SQLITE_TRACE_STMT (*Statement) (*C.char) Expanded SQL statement
SQLITE_TRACE_PROFILE (*Statement) (*C.int64) Nanoseconds elapsed
SQLITE_TRACE_ROW (*Statement) nil
SQLITE_TRACE_CLOSE (*Conn) nil

The return value from the callback is currently ignored. Call SetTraceHook with nil as the first argument to unregister the callback. Here's an example of what your trace function might look like, if you are interested in all trace events:

  func TraceHook(t TraceType, a, b unsafe.Pointer) int {
    switch t {
    case SQLITE_TRACE_STMT:
      fmt.Println("STMT => ", (*Statement)(a), C.GoString(b))
    case SQLITE_TRACE_PROFILE:
      ms := time.Duration(time.Duration(*(*int64)(b)) * time.Nanosecond)
      fmt.Println("PROF => ", (*Statement)(a), ms)
    case SQLITE_TRACE_ROW:
      fmt.Println("ROW  => ",(*Statement)(a))
    case SQLITE_TRACE_CLOSE:
      fmt.Println("CLSE => ", (*Conn)(a))
    }
    return 0
  }

See the documentation for more information.

Binary Object (Blob IO) Interface

In addition to the standard interface which inserts, updates and deletes binary objects atomically, it's possible to read and write data to binary objects incrementally. The documentation is here.

In order to create a blob, use the SQL method INSERT INTO table VALUES ZEROBLOB(?) for example with a size parameter. Then use the last inserted rowid to read and write to the blob.

  • Use func (*Conn) OpenBlob(schema, table, column string, rowid int64, flags OpenFlags) (*Blob, error) to return a handle to a blob;
  • Use func (*Conn) OpenBlobEx(schema, table, column string, rowid int64, flags OpenFlags) (*BlobEx, error) to return a handle to a blob which provides an io.Reader and io.Writer interface;
  • Use func (*Blob) Close() error to close the blob on either a *Blob or *BlobEx handle;
  • The method func (*Blob) Bytes() int returns the size of the blob;
  • The method func (*Blob) Reopen(int64) error opens a new row with the existing blob handle.

See the documentation for the io.Reader and io.Writer interfaces for more information on Read, Write, Seek, ReadAt and WriteAt methods.

Backup Interface

The backup API is documented here:

  • Call func (*Conn) Backup(dest *Conn, destSchema, srcSchema string) (*Backup, error) on the source database with an opened destination database. If your database handle is a *ConnEx handle use dest.Conn as your argument;
  • Call func (*Backup) Step(n int) error to copy up to n pages from the source database to the destination until the error returned is SQLITE_DONE;
  • Call func (*Backup) Finish() error to finalize the backup process.

The methods func (*Backup) Remaining() int and func (*Backup) PageCount() int can be used to determine progress through the backup process. For example,

func BackupMainSchema(src, dest *ConnEx, n int) error {
	backup, err := src.OpenBackup(dest.Conn, "", "")
	if err != nil {
		return err
	}
	defer backup.Finish()
	for {
		if err := backup.Step(n); err == sqlite3.SQLITE_DONE {
			return nil
		} else if err != nil {
			return err
		} else {
			float64 pct = float64(backup.Remaining()) * 100.0 / float64(backup.PageCount())
			fmt.Printf("%d%% remaining\n", pct)
		}
	}
}

Status and Limits

The methods func (*Conn) GetLimit(key SQLimit) int and func (*Conn) SetLimit(key SQLimit, v int) int can be used to query and set the limits on the database. See the documentation key parameters. Both methods return the previous value of the limit. The following example enumerates all the limit values:

func PrintLimits(c *ConnEx) {
	for i := sqlite3.SQLITE_LIMIT_MIN; i <= sqlite3.SQLITE_LIMIT_MAX; i++ {
        fmt.Println("Limit %v => %d", i, c.GetLimit(i))
	}
}

Runtime counters and memory usage can also be enumerated:

func PrintCounters(c *ConnEx) {
	for i := sqlite3.SQLITE_DBSTATUS_MIN; i <= sqlite3.SQLITE_DBSTATUS_MAX; i++ {
		if cur, max, err := c.GetStatus(i); err == nil {
            fmt.Printf("Status %v => %d/%d\n", i, cur, max)
        }
    }
    cur, max := sqlite3.GetMemoryUsed()
    fmt.Printf("Memory Used => %d/%d\n", i, cur, max)

Calling func ResetStatus(StatusType) error and func ResetMemoryUsed() resets the highest instantaneous value (max) back to the current value for the given counter.

Miscellaneous

Some miscellaneous methods:

  • The method func Version() (string, int, string) returns the version of the SQLite library in use, as a string, an encoded integer and as a source string;
  • The method func IsComplete(string) bool returns true if the given string argument is a complete SQL statement (with trailing semi-colon);
  • The methods func KeywordCount() int, func KeywordName(int) string and func KeywordCheck(string) bool can be used for enumerating reserved keywords and checking an indentifier against the list of reserved keywords.

Documentation

Overview

Package sqlite3 provides bindings for sqlite 3.

Please see https://github.com/mutablelogic/go-sqlite/blob/master/sys/sqlite3/README.md for information on this package.

Index

Constants

View Source
const (
	DefaultSchema = "main"
	DefaultMemory = ":memory:"
	DefaultFlags  = SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE
)

Variables

This section is empty.

Functions

func GetMemoryUsed

func GetMemoryUsed() (int64, int64)

func IsComplete

func IsComplete(v string) bool

Determine If An SQL Statement Is Complete

func KeywordCheck

func KeywordCheck(v string) bool

Lookup keyword

func KeywordCount

func KeywordCount() int

Return number of keywords

func KeywordName

func KeywordName(index int) string

Return keyword

func ResetMemoryUsed

func ResetMemoryUsed()

func Sleep

func Sleep(d time.Duration)

Sleep

func Version

func Version() (string, int, string)

Return version

Types

type AuthorizerHookFunc

type AuthorizerHookFunc func(SQAction, [4]string) SQAuth

AuthorizerHookFunc is invoked as SQL statements are being compiled by sqlite3_prepare the arguments are dependent on the action required, and the return value should be SQLITE_ALLOW, SQLITE_DENY or SQLITE_IGNORE

type Backup

type Backup C.sqlite3_backup

func (*Backup) Finish

func (b *Backup) Finish() error

Finish releases all resources associated with the backup process

func (*Backup) PageCount

func (b *Backup) PageCount() int

PageCount returns the total number of pages in the source database at the conclusion of the most recent Step call

func (*Backup) Remaining

func (b *Backup) Remaining() int

Remaining returns the number of pages still to be backed up at the conclusion of the most recent Step call

func (*Backup) Step

func (b *Backup) Step(n int) error

Step copies up to n pages between the source and destination databases

func (*Backup) String

func (b *Backup) String() string

type Blob

type Blob C.sqlite3_blob

func (*Blob) Bytes

func (b *Blob) Bytes() int

Bytes returns the size of the blob

func (*Blob) Close

func (b *Blob) Close() error

Close a blob handle and release resources

func (*Blob) ReadAt

func (b *Blob) ReadAt(data []byte, offset int64) error

ReadAt reads data from a blob, starting at a specific byte offset within the blob

func (*Blob) Reopen

func (b *Blob) Reopen(rowid int64) error

Reopen moves the blob handle to a new rowid

func (*Blob) String

func (b *Blob) String() string

func (*Blob) WriteAt

func (b *Blob) WriteAt(data []byte, offset int64) error

WriteAt writes data into a blob, starting at a specific byte offset within the blob

type BlobEx

type BlobEx struct {
	io.ReadWriteSeeker
	io.ReaderAt
	io.WriterAt
	io.Closer
	*Blob
	// contains filtered or unexported fields
}

func (*BlobEx) Close

func (b *BlobEx) Close() error

Close a blob and release resources

func (*BlobEx) Read

func (b *BlobEx) Read(data []byte) (int, error)

io.Reader interface

func (*BlobEx) ReadAt

func (b *BlobEx) ReadAt(data []byte, offset int64) (int, error)

io.ReaderAt interface

func (*BlobEx) Reopen

func (b *BlobEx) Reopen(rowid int64) error

Reopen moves the blob handle to a new rowid

func (*BlobEx) Seek

func (b *BlobEx) Seek(offset int64, whence int) (int64, error)

io.ReadWriteSeeker interface

func (*BlobEx) String

func (b *BlobEx) String() string

func (*BlobEx) Write

func (b *BlobEx) Write(data []byte) (int, error)

io.Writer interface

func (*BlobEx) WriteAt

func (b *BlobEx) WriteAt(data []byte, offset int64) (int, error)

io.WriterAt interface

type BusyHandlerFunc

type BusyHandlerFunc func(int) bool

BusyHandlerFunc is invoked with the number of times that the busy handler has been invoked previously for the same locking event. If the busy callback returns false, then no additional attempts are made to access the database and error SQLITE_BUSY is returned to the application. If the callback returns true then another attempt is made to access the database and the cycle repeats.

type CommitHookFunc

type CommitHookFunc func() bool

CommitHookFunc is invoked on commit. When it returns false, the COMMIT operation is allowed to continue normally or else the COMMIT is converted into a ROLLBACK

type Conn

type Conn C.sqlite3

func OpenPath

func OpenPath(path string, flags OpenFlags, vfs string) (*Conn, error)

Open Path

func OpenUrl

func OpenUrl(url string, flags OpenFlags, vfs string) (*Conn, error)

Open URL

func (*Conn) Autocommit

func (c *Conn) Autocommit() bool

Return autocommit state

func (*Conn) CacheFlush

func (c *Conn) CacheFlush() error

Cache Flush

func (*Conn) Changes

func (c *Conn) Changes() int

Get number of changes (rows affected)

func (*Conn) Close

func (c *Conn) Close() error

Close Connection

func (*Conn) Filename

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

Get Filename

func (*Conn) GetLimit

func (c *Conn) GetLimit(key SQLimit) int

GetLimit returns the current value of a run-time limit

func (*Conn) GetStatus

func (c *Conn) GetStatus(v StatusType) (int, int, error)

func (*Conn) Interrupt

func (c *Conn) Interrupt()

Interrupt all queries for connection

func (*Conn) LastInsertId

func (c *Conn) LastInsertId() int64

Get last insert id

func (*Conn) NextStatement

func (c *Conn) NextStatement(s *Statement) *Statement

Return next prepared statement, or first is nil

func (*Conn) OpenBackup

func (c *Conn) OpenBackup(dest *Conn, destSchema, sourceSchema string) (*Backup, error)

func (*Conn) OpenBlob

func (c *Conn) OpenBlob(schema, table, column string, rowid int64, flags OpenFlags) (*Blob, error)

OpenBlob handle with specified schema, table, column and rowid. If called with flag SQLITE_OPEN_READWRITE then the blob handle is opened for read/write access, otherwise for read-only access.

func (*Conn) OpenBlobEx

func (c *Conn) OpenBlobEx(schema, table, column string, rowid int64, flags OpenFlags) (*BlobEx, error)

OpenBlobEx with specified schema, table, column and rowid. If called with flag SQLITE_OPEN_READWRITE then the blob handle is opened for read/write access, otherwise for read-only access.

func (*Conn) Prepare

func (c *Conn) Prepare(query string) (*Statement, string, error)

Prepare query

func (*Conn) Readonly

func (c *Conn) Readonly(schema string) bool

Get Read-only state. Also returns false if database not found

func (*Conn) ReleaseMemory

func (c *Conn) ReleaseMemory() error

Release Memory

func (*Conn) ResetStatus

func (c *Conn) ResetStatus(v StatusType) error

func (*Conn) SetExtendedResultCodes

func (c *Conn) SetExtendedResultCodes(v bool) error

Set extended result codes

func (*Conn) SetLastInsertId

func (c *Conn) SetLastInsertId(v int64)

Set last insert id

func (*Conn) SetLimit

func (c *Conn) SetLimit(key SQLimit, v int) int

SetLimit changes the value of a run-time limit

func (*Conn) String

func (c *Conn) String() string

type ConnEx

type ConnEx struct {
	*Conn

	// Callback functions
	BusyHandlerFunc
	ProgressHandlerFunc
	CommitHookFunc
	RollbackHookFunc
	UpdateHookFunc
	AuthorizerHookFunc
	ExecFunc
	TraceFunc
	// contains filtered or unexported fields
}

func OpenPathEx

func OpenPathEx(path string, flags OpenFlags, vfs string) (*ConnEx, error)

Open Path (with busy and progress handlers)

func OpenUrlEx

func OpenUrlEx(url string, flags OpenFlags, vfs string) (*ConnEx, error)

Open URL (with busy and progress handlers)

func (*ConnEx) Begin

func (c *ConnEx) Begin(t SQTransaction) error

func (*ConnEx) Close

func (c *ConnEx) Close() error

Close Connection

func (*ConnEx) Commit

func (c *ConnEx) Commit() error

func (*ConnEx) CreateScalarFunction

func (c *ConnEx) CreateScalarFunction(name string, nargs int, deterministic bool, fn StepFunc) error

Create a custom function

func (*ConnEx) Exec

func (c *ConnEx) Exec(q string, fn ExecFunc) error

Exec runs statements without preparing or accepting bind arguments. If you call with fn as nil then the statement is executed without a callback, otherwise return true from the callback to abort the transaction.

func (*ConnEx) ExecEx

func (c *ConnEx) ExecEx(q string, fn ExecFunc, v ...interface{}) error

ExecEx runs statements without preparing. If you call with fn as nil then the statement is executed without a callback, otherwise callback is invoked for each row of data returned, otherwise return true from the callback to abort the transaction.

func (*ConnEx) Prepare

func (c *ConnEx) Prepare(q string) (*StatementEx, error)

Prepare query string and return prepared statements

func (*ConnEx) Rollback

func (c *ConnEx) Rollback() error

func (*ConnEx) SetAuthorizerHook

func (c *ConnEx) SetAuthorizerHook(fn AuthorizerHookFunc) error

SetAuthorizerHook sets the callback for the authorizer hook, use nil to remove the handler.

func (*ConnEx) SetBusyHandler

func (c *ConnEx) SetBusyHandler(fn BusyHandlerFunc) error

Set Busy Handler, use nil to remove the handler

func (*ConnEx) SetBusyTimeout

func (c *ConnEx) SetBusyTimeout(t time.Duration) error

Set Busy Timeout

func (*ConnEx) SetCommitHook

func (c *ConnEx) SetCommitHook(fn CommitHookFunc) error

SetCommitHook sets the callback for the commit hook, use nil to remove the handler.

func (*ConnEx) SetProgressHandler

func (c *ConnEx) SetProgressHandler(n uint, fn ProgressHandlerFunc) error

Set Progress Handler, use nil to remove the handler. The parameter n is the approximate number of virtual machine instructions that are evaluated between successive invocations of the callback

func (*ConnEx) SetRollbackHook

func (c *ConnEx) SetRollbackHook(fn RollbackHookFunc) error

SetRollbackHook sets the callback for the rollback hook, use nil to remove the handler.

func (*ConnEx) SetTraceHook

func (c *ConnEx) SetTraceHook(fn TraceFunc, flags TraceType) error

SetTraceHook sets the callback for the trace hook, use nil to remove the handler.

func (*ConnEx) SetUpdateHook

func (c *ConnEx) SetUpdateHook(fn UpdateHookFunc) error

SetUpdateHook sets the callback for the update hook, use nil to remove the handler.

type Context

type Context C.sqlite3_context

func (*Context) Err

func (ctx *Context) Err(v string)

Set error from a string

func (*Context) ErrCode

func (ctx *Context) ErrCode(e SQError)

Set error from an SQError code

func (*Context) ErrNoMem

func (ctx *Context) ErrNoMem()

Set error to indicate that a memory allocation failed

func (*Context) ErrTooBig

func (ctx *Context) ErrTooBig()

Set error as too big, indicating that a string or BLOB is too long to represent

func (*Context) ResultBlob

func (ctx *Context) ResultBlob(data []byte)

Set result as a blob

func (*Context) ResultDouble

func (ctx *Context) ResultDouble(v float64)

Set result as a double value

func (*Context) ResultInt32

func (ctx *Context) ResultInt32(v int32)

Set result as a int32 value

func (*Context) ResultInt64

func (ctx *Context) ResultInt64(v int64)

Set result as a int64 value

func (*Context) ResultInterface

func (ctx *Context) ResultInterface(v interface{}) error

Set result as a interface value, return any errors from casting

func (*Context) ResultNull

func (ctx *Context) ResultNull()

Set result as NULL

func (*Context) ResultText

func (ctx *Context) ResultText(v string)

Set result as a text value

func (*Context) ResultValue

func (ctx *Context) ResultValue(v *Value)

Set result as a value

func (*Context) String

func (ctx *Context) String() string

func (*Context) UserData

func (ctx *Context) UserData() unsafe.Pointer

Return user data from context

type ExecFunc

type ExecFunc func(row, cols []string) bool

ExecFunc is invoked during an Exec call with row text values and column names. If an sqlite3_exec() callback returns true, the sqlite3_exec() routine returns SQLITE_ABORT without invoking the callback again and without running any subsequent SQL statements.

type FinalFunc

type FinalFunc func(*Context)

type OpenFlags

type OpenFlags C.int
const (
	SQLITE_OPEN_NONE         OpenFlags = 0
	SQLITE_OPEN_READONLY     OpenFlags = C.SQLITE_OPEN_READONLY     // The database is opened in read-only mode. If the database does not already exist, an error is returned.
	SQLITE_OPEN_READWRITE    OpenFlags = C.SQLITE_OPEN_READWRITE    // The database is opened for reading and writing if possible, or reading only if the file is write protected by the operating system. In either case the database must already exist, otherwise an error is returned.
	SQLITE_OPEN_CREATE       OpenFlags = C.SQLITE_OPEN_CREATE       // The database is created if it does not already exist
	SQLITE_OPEN_URI          OpenFlags = C.SQLITE_OPEN_URI          // The filename can be interpreted as a URI if this flag is set.
	SQLITE_OPEN_MEMORY       OpenFlags = C.SQLITE_OPEN_MEMORY       // The database will be opened as an in-memory database. The database is named by the "filename" argument for the purposes of cache-sharing, if shared cache mode is enabled, but the "filename" is otherwise ignored.
	SQLITE_OPEN_NOMUTEX      OpenFlags = C.SQLITE_OPEN_NOMUTEX      // The new database connection will use the "multi-thread" threading mode. This means that separate threads are allowed to use SQLite at the same time, as long as each thread is using a different database connection.
	SQLITE_OPEN_FULLMUTEX    OpenFlags = C.SQLITE_OPEN_FULLMUTEX    // The new database connection will use the "serialized" threading mode. This means the multiple threads can safely attempt to use the same database connection at the same time. (Mutexes will block any actual concurrency, but in this mode there is no harm in trying.)
	SQLITE_OPEN_SHAREDCACHE  OpenFlags = C.SQLITE_OPEN_SHAREDCACHE  // The database is opened shared cache enabled, overriding the default shared cache setting provided by sqlite3_enable_shared_cache().
	SQLITE_OPEN_PRIVATECACHE OpenFlags = C.SQLITE_OPEN_PRIVATECACHE // The database is opened shared cache disabled, overriding the default shared cache setting provided by sqlite3_enable_shared_cache().
	//	SQLITE_OPEN_NOFOLLOW     OpenFlags = C.SQLITE_OPEN_NOFOLLOW                         // The database filename is not allowed to be a symbolic link
	SQLITE_OPEN_MIN = SQLITE_OPEN_READONLY
	SQLITE_OPEN_MAX = SQLITE_OPEN_PRIVATECACHE
)

func (OpenFlags) String

func (v OpenFlags) String() string

func (OpenFlags) StringFlag

func (v OpenFlags) StringFlag() string

type ProgressHandlerFunc

type ProgressHandlerFunc func() bool

ProgressHandlerFunc is invoked periodically during long running calls. If the progress callback returns true, the operation is interrupted

type Results

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

func (*Results) ColumnCount

func (r *Results) ColumnCount() int

Return column count

func (*Results) ColumnDatabaseName

func (r *Results) ColumnDatabaseName(i int) string

Return the source database schema name

func (*Results) ColumnDeclType

func (r *Results) ColumnDeclType(i int) string

Return column decltype

func (*Results) ColumnName

func (r *Results) ColumnName(i int) string

Return column name

func (*Results) ColumnOriginName

func (r *Results) ColumnOriginName(i int) string

Return the origin

func (*Results) ColumnTableName

func (r *Results) ColumnTableName(i int) string

Return the source table name

func (*Results) ColumnType

func (r *Results) ColumnType(i int) Type

Return column type

func (*Results) ExpandedSQL

func (r *Results) ExpandedSQL() string

Return the expanded SQL statement

func (*Results) LastInsertId

func (r *Results) LastInsertId() int64

func (*Results) Next

func (r *Results) Next(t ...reflect.Type) ([]interface{}, error)

Return next row of values, or (nil, io.EOF) if there are no more rows. If arguments t are provided, then the values will be cast to the types in t if that is possible, or else an error will occur

func (*Results) RowsAffected

func (r *Results) RowsAffected() int

func (*Results) String

func (r *Results) String() string

type RollbackHookFunc

type RollbackHookFunc func()

RollbackHookFunc is invoked whenever a transaction is rolled back

type SQAction

type SQAction C.int
const (
	SQLITE_CREATE_INDEX        SQAction = C.SQLITE_CREATE_INDEX
	SQLITE_CREATE_TABLE        SQAction = C.SQLITE_CREATE_TABLE
	SQLITE_CREATE_TEMP_INDEX   SQAction = C.SQLITE_CREATE_TEMP_INDEX
	SQLITE_CREATE_TEMP_TABLE   SQAction = C.SQLITE_CREATE_TEMP_TABLE
	SQLITE_CREATE_TEMP_TRIGGER SQAction = C.SQLITE_CREATE_TEMP_TRIGGER
	SQLITE_CREATE_TEMP_VIEW    SQAction = C.SQLITE_CREATE_TEMP_VIEW
	SQLITE_CREATE_TRIGGER      SQAction = C.SQLITE_CREATE_TRIGGER
	SQLITE_CREATE_VIEW         SQAction = C.SQLITE_CREATE_VIEW
	SQLITE_DELETE              SQAction = C.SQLITE_DELETE
	SQLITE_DROP_INDEX          SQAction = C.SQLITE_DROP_INDEX
	SQLITE_DROP_TABLE          SQAction = C.SQLITE_DROP_TABLE
	SQLITE_DROP_TEMP_INDEX     SQAction = C.SQLITE_DROP_TEMP_INDEX
	SQLITE_DROP_TEMP_TABLE     SQAction = C.SQLITE_DROP_TEMP_TABLE
	SQLITE_DROP_TEMP_TRIGGER   SQAction = C.SQLITE_DROP_TEMP_TRIGGER
	SQLITE_DROP_TEMP_VIEW      SQAction = C.SQLITE_DROP_TEMP_VIEW
	SQLITE_DROP_TRIGGER        SQAction = C.SQLITE_DROP_TRIGGER
	SQLITE_DROP_VIEW           SQAction = C.SQLITE_DROP_VIEW
	SQLITE_INSERT              SQAction = C.SQLITE_INSERT
	SQLITE_PRAGMA              SQAction = C.SQLITE_PRAGMA
	SQLITE_READ                SQAction = C.SQLITE_READ
	SQLITE_SELECT              SQAction = C.SQLITE_SELECT
	SQLITE_TRANSACTION         SQAction = C.SQLITE_TRANSACTION
	SQLITE_UPDATE              SQAction = C.SQLITE_UPDATE
	SQLITE_ATTACH              SQAction = C.SQLITE_ATTACH
	SQLITE_DETACH              SQAction = C.SQLITE_DETACH
	SQLITE_ALTER_TABLE         SQAction = C.SQLITE_ALTER_TABLE
	SQLITE_REINDEX             SQAction = C.SQLITE_REINDEX
	SQLITE_ANALYZE             SQAction = C.SQLITE_ANALYZE
	SQLITE_CREATE_VTABLE       SQAction = C.SQLITE_CREATE_VTABLE
	SQLITE_DROP_VTABLE         SQAction = C.SQLITE_DROP_VTABLE
	SQLITE_FUNCTION            SQAction = C.SQLITE_FUNCTION
	SQLITE_SAVEPOINT           SQAction = C.SQLITE_SAVEPOINT
	SQLITE_COPY                SQAction = C.SQLITE_COPY
	SQLITE_RECURSIVE           SQAction = C.SQLITE_RECURSIVE
	SQLITE_ACTION_MIN                   = SQLITE_CREATE_INDEX
	SQLITE_ACTION_MAX                   = SQLITE_RECURSIVE
)

Ref: http://www.sqlite.org/c3ref/c_limit_attached.html

func (SQAction) String

func (v SQAction) String() string

type SQAuth

type SQAuth C.int
const (
	SQLITE_ALLOW  SQAuth = SQAuth(SQLITE_OK) /* Operation requested is ok */
	SQLITE_DENY   SQAuth = C.SQLITE_DENY     /* Abort the SQL statement with an error */
	SQLITE_IGNORE SQAuth = C.SQLITE_IGNORE   /* Don't allow access, but don't generate an error */
)

func (SQAuth) String

func (v SQAuth) String() string

type SQError

type SQError C.int
const (
	SQLITE_OK         SQError = C.SQLITE_OK         /* Successful result */
	SQLITE_ERROR      SQError = C.SQLITE_ERROR      /* Generic error */
	SQLITE_INTERNAL   SQError = C.SQLITE_INTERNAL   /* Internal logic error in SQLite */
	SQLITE_PERM       SQError = C.SQLITE_PERM       /* Access permission denied */
	SQLITE_ABORT      SQError = C.SQLITE_ABORT      /* Callback routine requested an abort */
	SQLITE_BUSY       SQError = C.SQLITE_BUSY       /* The database file is locked */
	SQLITE_LOCKED     SQError = C.SQLITE_LOCKED     /* A table in the database is locked */
	SQLITE_NOMEM      SQError = C.SQLITE_NOMEM      /* A malloc() failed */
	SQLITE_READONLY   SQError = C.SQLITE_READONLY   /* Attempt to write a readonly database */
	SQLITE_INTERRUPT  SQError = C.SQLITE_INTERRUPT  /* Operation terminated by sqlite3_interrupt()*/
	SQLITE_IOERR      SQError = C.SQLITE_IOERR      /* Some kind of disk I/O error occurred */
	SQLITE_CORRUPT    SQError = C.SQLITE_CORRUPT    /* The database disk image is malformed */
	SQLITE_NOTFOUND   SQError = C.SQLITE_NOTFOUND   /* Unknown opcode in sqlite3_file_control() */
	SQLITE_FULL       SQError = C.SQLITE_FULL       /* Insertion failed because database is full */
	SQLITE_CANTOPEN   SQError = C.SQLITE_CANTOPEN   /* Unable to open the database file */
	SQLITE_PROTOCOL   SQError = C.SQLITE_PROTOCOL   /* Database lock protocol error */
	SQLITE_EMPTY      SQError = C.SQLITE_EMPTY      /* Internal use only */
	SQLITE_SCHEMA     SQError = C.SQLITE_SCHEMA     /* The database schema changed */
	SQLITE_TOOBIG     SQError = C.SQLITE_TOOBIG     /* String or BLOB exceeds size limit */
	SQLITE_CONSTRAINT SQError = C.SQLITE_CONSTRAINT /* Abort due to constraint violation */
	SQLITE_MISMATCH   SQError = C.SQLITE_MISMATCH   /* Data type mismatch */
	SQLITE_MISUSE     SQError = C.SQLITE_MISUSE     /* Library used incorrectly */
	SQLITE_NOLFS      SQError = C.SQLITE_NOLFS      /* Uses OS features not supported on host */
	SQLITE_AUTH       SQError = C.SQLITE_AUTH       /* Authorization denied */
	SQLITE_FORMAT     SQError = C.SQLITE_FORMAT     /* Not used */
	SQLITE_RANGE      SQError = C.SQLITE_RANGE      /* 2nd parameter to sqlite3_bind out of range */
	SQLITE_NOTADB     SQError = C.SQLITE_NOTADB     /* File opened that is not a database file */
	SQLITE_NOTICE     SQError = C.SQLITE_NOTICE     /* Notifications from sqlite3_log() */
	SQLITE_WARNING    SQError = C.SQLITE_WARNING    /* Warnings from sqlite3_log() */
	SQLITE_ROW        SQError = C.SQLITE_ROW        /* sqlite3_step() has another row ready */
	SQLITE_DONE       SQError = C.SQLITE_DONE       /* sqlite3_step() has finished executing */
)

func (SQError) Error

func (e SQError) Error() string

func (SQError) With

func (e SQError) With(suffix string) error

type SQLimit

type SQLimit C.int
const (
	SQLITE_LIMIT_LENGTH              SQLimit = C.SQLITE_LIMIT_LENGTH              // The maximum size of any string or BLOB or table row, in bytes.
	SQLITE_LIMIT_SQL_LENGTH          SQLimit = C.SQLITE_LIMIT_SQL_LENGTH          // The maximum length of an SQL statement, in bytes.
	SQLITE_LIMIT_COLUMN              SQLimit = C.SQLITE_LIMIT_COLUMN              // The maximum number of columns in a table definition or in the result set of a SELECT or the maximum number of columns in an index or in an ORDER BY or GROUP BY clause.
	SQLITE_LIMIT_EXPR_DEPTH          SQLimit = C.SQLITE_LIMIT_EXPR_DEPTH          // The maximum depth of the parse tree on any expression.
	SQLITE_LIMIT_COMPOUND_SELECT     SQLimit = C.SQLITE_LIMIT_COMPOUND_SELECT     // The maximum number of terms in a compound SELECT statement.
	SQLITE_LIMIT_VDBE_OP             SQLimit = C.SQLITE_LIMIT_VDBE_OP             // The maximum number of instructions in a virtual machine program used to implement an SQL statement. If sqlite3_prepare_v2() or the equivalent tries to allocate space for more than this many opcodes in a single prepared statement, an SQLITE_NOMEM error is returned.
	SQLITE_LIMIT_FUNCTION_ARG        SQLimit = C.SQLITE_LIMIT_FUNCTION_ARG        // The maximum number of arguments on a function.
	SQLITE_LIMIT_ATTACHED            SQLimit = C.SQLITE_LIMIT_ATTACHED            // The maximum number of attached databases.
	SQLITE_LIMIT_LIKE_PATTERN_LENGTH SQLimit = C.SQLITE_LIMIT_LIKE_PATTERN_LENGTH // The maximum length of the pattern argument to the LIKE or GLOB operators.
	SQLITE_LIMIT_VARIABLE_NUMBER     SQLimit = C.SQLITE_LIMIT_VARIABLE_NUMBER     // The maximum index number of any parameter in an SQL statement.
	SQLITE_LIMIT_TRIGGER_DEPTH       SQLimit = C.SQLITE_LIMIT_TRIGGER_DEPTH       // The maximum depth of recursion for triggers.
	SQLITE_LIMIT_WORKER_THREADS      SQLimit = C.SQLITE_LIMIT_WORKER_THREADS      // The maximum number of auxiliary worker threads that a single prepared statement may start.
	SQLITE_LIMIT_MIN                         = SQLITE_LIMIT_LENGTH
	SQLITE_LIMIT_MAX                         = SQLITE_LIMIT_WORKER_THREADS
)

Ref: http://www.sqlite.org/c3ref/c_limit_attached.html

func (SQLimit) String

func (l SQLimit) String() string

type SQTransaction

type SQTransaction string

Transaction type

const (
	SQLITE_TXN_DEFAULT   SQTransaction = "DEFERRED"
	SQLITE_TXN_IMMEDIATE SQTransaction = "IMMEDIATE"
	SQLITE_TXN_EXCLUSIVE SQTransaction = "EXCLUSIVE"
)

type Statement

type Statement C.sqlite3_stmt

func (*Statement) Bind

func (s *Statement) Bind(v ...interface{}) error

Bind parameters

func (*Statement) BindBlob

func (s *Statement) BindBlob(index int, v []byte) error

Bind blob

func (*Statement) BindDouble

func (s *Statement) BindDouble(index int, v float64) error

Bind double

func (*Statement) BindInt32

func (s *Statement) BindInt32(index int, v int32) error

Bind int32

func (*Statement) BindInt64

func (s *Statement) BindInt64(index int, v int64) error

Bind int64

func (*Statement) BindInterface

func (s *Statement) BindInterface(index int, value interface{}) error

Bind int, uint, float, bool, string, []byte, time.Time or nil to a statement, return any errors TODO: Also accept custom types with Marshal and Unmarshal

func (*Statement) BindNamedInterface

func (s *Statement) BindNamedInterface(name string, value interface{}) error

Bind int, uint, float, bool, string, []byte, or nil to a statement with a named parameter, return any errors

func (*Statement) BindNull

func (s *Statement) BindNull(index int) error

Bind null

func (*Statement) BindPointer

func (s *Statement) BindPointer(index int, p unsafe.Pointer, t string) error

Bind pointer

func (*Statement) BindText

func (s *Statement) BindText(index int, v string) error

Bind text

func (*Statement) BindZeroBlob

func (s *Statement) BindZeroBlob(index int, len int) error

Bind zero-length-blob

func (*Statement) BindZeroBlob64

func (s *Statement) BindZeroBlob64(index int, len uint64) error

Bind zero-length-blob (uint64)

func (*Statement) ClearBindings

func (s *Statement) ClearBindings() error

Clear bindings

func (*Statement) ColumnBlob

func (s *Statement) ColumnBlob(index int) []byte

Return blob

func (*Statement) ColumnBytes

func (s *Statement) ColumnBytes(index int) int

Return length

func (*Statement) ColumnCount

func (s *Statement) ColumnCount() int

Return count

func (*Statement) ColumnDatabaseName

func (s *Statement) ColumnDatabaseName(index int) string

Return database name

func (*Statement) ColumnDeclType

func (s *Statement) ColumnDeclType(index int) string

Return declared type

func (*Statement) ColumnDouble

func (s *Statement) ColumnDouble(index int) float64

Return float64

func (*Statement) ColumnInt32

func (s *Statement) ColumnInt32(index int) int32

Return int32

func (*Statement) ColumnInt64

func (s *Statement) ColumnInt64(index int) int64

Return int64

func (*Statement) ColumnInterface

func (s *Statement) ColumnInterface(index int) interface{}

Return column as interface

func (*Statement) ColumnName

func (s *Statement) ColumnName(index int) string

Return column name

func (*Statement) ColumnOriginName

func (s *Statement) ColumnOriginName(index int) string

Return origin name

func (*Statement) ColumnTableName

func (s *Statement) ColumnTableName(index int) string

Return table name

func (*Statement) ColumnText

func (s *Statement) ColumnText(index int) string

Return string

func (*Statement) ColumnType

func (s *Statement) ColumnType(index int) Type

Return type

func (*Statement) Conn

func (s *Statement) Conn() *Conn

Return connection object from statement

func (*Statement) DataCount

func (s *Statement) DataCount() int

Return count

func (*Statement) ExpandedSQL

func (s *Statement) ExpandedSQL() string

Returns SQL associated with a statement, expanded with bound parameters

func (*Statement) Finalize

func (s *Statement) Finalize() error

Finalize prepared statement

func (*Statement) IsBusy

func (s *Statement) IsBusy() bool

IsBusy returns true if in middle of execution

func (*Statement) IsReadonly

func (s *Statement) IsReadonly() bool

IsReadonly returns true if the statement makes no direct changes to the content of the database file.

func (*Statement) NumParams

func (s *Statement) NumParams() int

Return number of parameters expected for a statement

func (*Statement) ParamIndex

func (s *Statement) ParamIndex(name string) int

Returns parameter index for a name, or zero

func (*Statement) ParamName

func (s *Statement) ParamName(index int) string

Returns parameter name for the nth parameter, which is an empty string if an unnamed parameter (?) or the parameter name otherwise (:a)

func (*Statement) Reset

func (s *Statement) Reset() error

Reset statement

func (*Statement) SQL

func (s *Statement) SQL() string

Returns SQL associated with a statement

func (*Statement) Step

func (s *Statement) Step() error

Step statement

func (*Statement) String

func (s *Statement) String() string

type StatementEx

type StatementEx struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*StatementEx) Close

func (s *StatementEx) Close() error

Release resources for statements

func (*StatementEx) Count

func (s *StatementEx) Count() uint32

Returns current count. Used to count the frequency of calls for caching purposes.

func (*StatementEx) Exec

func (s *StatementEx) Exec(n uint, v ...interface{}) (*Results, error)

Execute prepared statement n, when called with arguments, this calls Bind() first

func (*StatementEx) Inc

func (s *StatementEx) Inc(n uint32)

Increment adds n to the statement counter and updates the timestamp

func (*StatementEx) String

func (s *StatementEx) String() string

func (*StatementEx) Timestamp

func (s *StatementEx) Timestamp() int64

Returns last accessed timestamp for caching purposes as an int64

type StatusType

type StatusType int
const (
	SQLITE_DBSTATUS_LOOKASIDE_USED      StatusType = C.SQLITE_DBSTATUS_LOOKASIDE_USED
	SQLITE_DBSTATUS_CACHE_USED          StatusType = C.SQLITE_DBSTATUS_CACHE_USED
	SQLITE_DBSTATUS_SCHEMA_USED         StatusType = C.SQLITE_DBSTATUS_SCHEMA_USED
	SQLITE_DBSTATUS_STMT_USED           StatusType = C.SQLITE_DBSTATUS_STMT_USED
	SQLITE_DBSTATUS_LOOKASIDE_HIT       StatusType = C.SQLITE_DBSTATUS_LOOKASIDE_HIT
	SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE StatusType = C.SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE
	SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL StatusType = C.SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL
	SQLITE_DBSTATUS_CACHE_HIT           StatusType = C.SQLITE_DBSTATUS_CACHE_HIT
	SQLITE_DBSTATUS_CACHE_MISS          StatusType = C.SQLITE_DBSTATUS_CACHE_MISS
	SQLITE_DBSTATUS_CACHE_WRITE         StatusType = C.SQLITE_DBSTATUS_CACHE_WRITE
	SQLITE_DBSTATUS_DEFERRED_FKS        StatusType = C.SQLITE_DBSTATUS_DEFERRED_FKS
	SQLITE_DBSTATUS_CACHE_USED_SHARED   StatusType = C.SQLITE_DBSTATUS_CACHE_USED_SHARED
	SQLITE_DBSTATUS_CACHE_SPILL         StatusType = C.SQLITE_DBSTATUS_CACHE_SPILL
	SQLITE_DBSTATUS_MIN                            = SQLITE_DBSTATUS_LOOKASIDE_USED
	SQLITE_DBSTATUS_MAX                 StatusType = C.SQLITE_DBSTATUS_MAX
)

func (StatusType) String

func (s StatusType) String() string

type StepFunc

type StepFunc func(*Context, []*Value)

type TraceFunc

type TraceFunc func(TraceType, unsafe.Pointer, unsafe.Pointer) int

TraceFunc is invoked for tracing. That's all I can say right now.

type TraceType

type TraceType uint
const (
	SQLITE_TRACE_STMT    TraceType = C.SQLITE_TRACE_STMT
	SQLITE_TRACE_PROFILE TraceType = C.SQLITE_TRACE_PROFILE
	SQLITE_TRACE_ROW     TraceType = C.SQLITE_TRACE_ROW
	SQLITE_TRACE_CLOSE   TraceType = C.SQLITE_TRACE_CLOSE
	SQLITE_TRACE_MIN               = SQLITE_TRACE_STMT
	SQLITE_TRACE_MAX               = SQLITE_TRACE_CLOSE
	SQLITE_TRACE_NONE    TraceType = 0
)

func (TraceType) String

func (v TraceType) String() string

func (TraceType) StringFlag

func (v TraceType) StringFlag() string

type Type

type Type int
const (
	SQLITE_INTEGER Type = C.SQLITE_INTEGER
	SQLITE_FLOAT   Type = C.SQLITE_FLOAT
	SQLITE_TEXT    Type = C.SQLITE_TEXT
	SQLITE_BLOB    Type = C.SQLITE_BLOB
	SQLITE_NULL    Type = C.SQLITE_NULL
)

func (Type) String

func (t Type) String() string

type UpdateHookFunc

type UpdateHookFunc func(SQAction, string, string, int64)

UpdateHookFunc is invoked whenever a row is updated, inserted or deleted SQOperation will be one of SQLITE_INSERT, SQLITE_DELETE, or SQLITE_UPDATE. The other arguments are database name, table name and the rowid of the row. In the case of an update, this is the rowid after the update takes place.

type Value

type Value C.sqlite3_value

func (*Value) Blob

func (v *Value) Blob() []byte

func (*Value) Bytes

func (v *Value) Bytes() int

Bytes returns value length in bytes

func (*Value) Copy

func (v *Value) Copy() *Value

Copy duplicates a value which needs to be released by the caller with Free

func (*Value) Double

func (v *Value) Double() float64

func (*Value) Free

func (v *Value) Free()

Free a duplicate value

func (*Value) Int32

func (v *Value) Int32() int32

func (*Value) Int64

func (v *Value) Int64() int64

func (*Value) Interface

func (v *Value) Interface() interface{}

Interface returns a go value from a sqlite value

func (*Value) NoChange

func (v *Value) NoChange() bool

NoChange returns true if the value is unchanged in an UPDATE against a virtual table.

func (*Value) String

func (v *Value) String() string

func (*Value) Text

func (v *Value) Text() string

func (*Value) Type

func (v *Value) Type() Type

Type returns value type

Jump to

Keyboard shortcuts

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