Involved Source Files
Package sqlite is a CGo-free port of SQLite.
SQLite is an in-process implementation of a self-contained, serverless,
zero-configuration, transactional SQL database engine.
Builders
Builder results available at
https://modern-c.appspot.com/-/builder/?importpath=modernc.org%2fsqlite
Changelog
2021-06-23 v1.11.0:
Upgrade to use sqlite 3.36.0, release notes at https://www.sqlite.org/releaselog/3_36_0.html.
2021-05-06 v1.10.6:
Fixes a memory corruption issue
(https://gitlab.com/cznic/sqlite/-/issues/53). Versions since v1.8.6 were
affected and should be updated to v1.10.6.
2021-03-14 v1.10.0:
Update to use sqlite 3.35.0, release notes at https://www.sqlite.org/releaselog/3_35_0.html.
2021-03-11 v1.9.0:
Support darwin/arm64.
2021-01-08 v1.8.0:
Support darwin/amd64.
2020-09-13 v1.7.0:
Support linux/arm and linux/arm64.
2020-09-08 v1.6.0:
Support linux/386.
2020-09-03 v1.5.0:
This project is now completely CGo-free, including the Tcl tests.
2020-08-26 v1.4.0:
First stable release for linux/amd64. The database/sql driver and its tests
are CGo free. Tests of the translated sqlite3.c library still require CGo.
$ make full
...
SQLite 2020-08-14 13:23:32 fca8dc8b578f215a969cd899336378966156154710873e68b3d9ac5881b0ff3f
0 errors out of 928271 tests on 3900x Linux 64-bit little-endian
WARNING: Multi-threaded tests skipped: Linked against a non-threadsafe Tcl build
All memory allocations freed - no leaks
Maximum memory usage: 9156360 bytes
Current memory usage: 0 bytes
Number of malloc() : -1 calls
--- PASS: TestTclTest (1785.04s)
PASS
ok modernc.org/sqlite 1785.041s
$
2020-07-26 v1.4.0-beta1:
The project has reached beta status while supporting linux/amd64 only at the
moment. The 'extraquick' Tcl testsuite reports
630 errors out of 200177 tests on Linux 64-bit little-endian
and some memory leaks
Unfreed memory: 698816 bytes in 322 allocations
2019-12-28 v1.2.0-alpha.3: Third alpha fixes issue #19.
It also bumps the minor version as the repository was wrongly already tagged
with v1.1.0 before. Even though the tag was deleted there are proxies that
cached that tag. Thanks /u/garaktailor for detecting the problem and
suggesting this solution.
2019-12-26 v1.1.0-alpha.2: Second alpha release adds support for accessing a
database concurrently by multiple goroutines and/or processes. v1.1.0 is now
considered feature-complete. Next planed release should be a beta with a
proper test suite.
2019-12-18 v1.1.0-alpha.1: First alpha release using the new cc/v3, gocc,
qbe toolchain. Some primitive tests pass on linux_{amd64,386}. Not yet safe
for concurrent access by multiple goroutines. Next alpha release is planed
to arrive before the end of this year.
2017-06-10 Windows/Intel no more uses the VM (thanks Steffen Butzer).
2017-06-05 Linux/Intel no more uses the VM (cznic/virtual).
Connecting to a database
To access a Sqlite database do something like
import (
"database/sql"
_ "modernc.org/sqlite"
)
...
db, err := sql.Open("sqlite", dsnURI)
...
Supported platforms and architectures
These combinations of GOOS and GOARCH are currently supported
darwin amd64
darwin arm64
linux 386
linux amd64
linux arm
linux arm64
windows amd64
Planned platforms and architectures
windows 386
Debug and development versions
A comma separated list of options can be passed to `go generate` via the
environment variable GO_GENERATE. Some useful options include for example:
-DSQLITE_DEBUG
-DSQLITE_MEM_DEBUG
-ccgo-verify-structs
To create a debug/development version, issue for example:
$ GO_GENERATE=-DSQLITE_DEBUG,-DSQLITE_MEM_DEBUG go generate
Note: To run `go generate` you need to have modernc.org/ccgo/v3 installed.
Sqlite documentation
See https://sqlite.org/docs.html
mutex.gosqlite.gosqlite_go18.go
Package-Level Type Names (total 8, in which 2 are exported)
/* sort exporteds by: | */
Driver implements database/sql/driver.Driver.
Open returns a new connection to the database. The name is a string in a
driver-specific format.
Open may return a cached connection (one previously closed), but doing so is
unnecessary; the sql package maintains a pool of idle connections for
efficient re-use.
The returned connection is only used by one goroutine at a time.
*T : database/sql/driver.Driver
func newDriver() *Driver
var github.com/uptrace/bun/driver/sqliteshim.shimDriver *Driver
Error represents sqlite library error code.
codeintmsgstring
Code returns the sqlite result code for this error.
Error implements error.
*T : error
// *sqlite3.Xsqlite3
tls*libc.TLS
Begin starts a transaction.
Deprecated: Drivers should implement ConnBeginTx instead (or additionally).
BeginTx implements driver.ConnBeginTx
Close invalidates and potentially stops any current prepared statements and
transactions, marking this connection as no longer in use.
Because the sql package maintains a free pool of connections and only calls
Close when there's a surplus of idle connections, it shouldn't be necessary
for drivers to do their own connection caching.
Execer is an optional interface that may be implemented by a Conn.
If a Conn does not implement Execer, the sql package's DB.Exec will first
prepare a query, execute the statement, and then close the statement.
Exec may return ErrSkip.
Deprecated: Drivers should implement ExecerContext instead.
ExecContext implements driver.ExecerContext
Ping implements driver.Pinger
Prepare returns a prepared statement, bound to this connection.
PrepareContext implements driver.ConnPrepareContext
Queryer is an optional interface that may be implemented by a Conn.
If a Conn does not implement Queryer, the sql package's DB.Query will first
prepare a query, execute the statement, and then close the statement.
Query may return ErrSkip.
Deprecated: Drivers should implement QueryerContext instead.
QueryContext implements driver.QueryerContext
(*T) begin(ctx context.Context, opts driver.TxOptions) (t driver.Tx, err error)(*T) bind(pstmt uintptr, n int, args []driver.NamedValue) (allocs []uintptr, err error)
int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
int sqlite3_bind_double(sqlite3_stmt*, int, double);
int sqlite3_bind_int(sqlite3_stmt*, int, int);
int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
int sqlite3_bind_null(sqlite3_stmt*, int);
int sqlite3_bind_parameter_count(sqlite3_stmt*);
const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
int sqlite3_changes(sqlite3*);
int sqlite3_close_v2(sqlite3*);
const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
int sqlite3_column_count(sqlite3_stmt *pStmt);
const char *sqlite3_column_decltype(sqlite3_stmt*,int);
double sqlite3_column_double(sqlite3_stmt*, int iCol);
sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
const char *sqlite3_column_name(sqlite3_stmt*, int N);
const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
int sqlite3_column_type(sqlite3_stmt*, int iCol);
const char *sqlite3_errstr(int);
(*T) exec(ctx context.Context, query string, args []driver.NamedValue) (r driver.Result, err error)
int sqlite3_extended_result_codes(sqlite3*, int onoff);
int sqlite3_finalize(sqlite3_stmt *pStmt);
(*T) free(p uintptr)
void sqlite3_interrupt(sqlite3*);
sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
(*T) malloc(n int) (uintptr, error)
int sqlite3_open_v2(
const char *filename, /* Database filename (UTF-8) */
sqlite3 **ppDb, /* OUT: SQLite db handle */
int flags, /* Flags */
const char *zVfs /* Name of VFS module to use */
);
Attempt to parse s as a time. Return (s, false) if s is not
recognized as a valid time encoding.
Attempt to parse s as a time string produced by t.String(). If x > 0 it's
the index of substring "m=" within s. Return (s, false) if s is
not recognized as a valid time encoding.
(*T) prepare(ctx context.Context, query string) (s driver.Stmt, err error)
int sqlite3_prepare_v2(
sqlite3 *db, /* Database handle */
const char *zSql, /* SQL statement, UTF-8 encoded */
int nByte, /* Maximum length of zSql in bytes. */
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
const char **pzTail /* OUT: Pointer to unused portion of zSql */
);
(*T) query(ctx context.Context, query string, args []driver.NamedValue) (r driver.Rows, err error)(*T) retry(pstmt uintptr) error
int sqlite3_step(sqlite3_stmt*);
*T : database/sql/driver.Conn
*T : database/sql/driver.ConnBeginTx
*T : database/sql/driver.ConnPrepareContext
*T : database/sql/driver.Execer
*T : database/sql/driver.ExecerContext
*T : database/sql/driver.Pinger
*T : database/sql/driver.Queryer
*T : database/sql/driver.QueryerContext
*T : io.Closer
func newConn(name string) (*conn, error)
func newResult(c *conn) (_ *result, err error)
func newRows(c *conn, pstmt uintptr, allocs []uintptr, empty bool) (r *rows, err error)
func newStmt(c *conn, sql string) (*stmt, error)
func newTx(c *conn) (*tx, error)
Mutexsync.MutexMutex.semauint32Mutex.stateint32
Lock locks m.
If the lock is already in use, the calling goroutine
blocks until the mutex is available.
Unlock unlocks m.
It is a run-time error if m is not locked on entry to Unlock.
A locked Mutex is not associated with a particular goroutine.
It is allowed for one goroutine to lock a Mutex and then
arrange for another goroutine to unlock it.
(*T) lockSlow()(*T) unlockSlow(new int32)
*T : sync.Locker
lastInsertIDint64rowsAffectedint
LastInsertId returns the database's auto-generated ID after, for example, an
INSERT into a table with primary key.
RowsAffected returns the number of rows affected by the query.
*T : database/sql.Result
*T : database/sql/driver.Result
func newResult(c *conn) (_ *result, err error)
allocs[]uintptrc*conncolumns[]stringdoStepboolemptyboolpstmtuintptr
Close closes the rows iterator.
RowsColumnTypeDatabaseTypeName may be implemented by Rows. It should return
the database system type name without the length. Type names should be
uppercase. Examples of returned types: "VARCHAR", "NVARCHAR", "VARCHAR2",
"CHAR", "TEXT", "DECIMAL", "SMALLINT", "INT", "BIGINT", "BOOL", "[]BIGINT",
"JSONB", "XML", "TIMESTAMP".
RowsColumnTypeLength may be implemented by Rows. It should return the length
of the column type if the column is a variable length type. If the column is
not a variable length type ok should return false. If length is not limited
other than system limits, it should return math.MaxInt64. The following are
examples of returned values for various types:
TEXT (math.MaxInt64, true)
varchar(10) (10, true)
nvarchar(10) (10, true)
decimal (0, false)
int (0, false)
bytea(30) (30, true)
RowsColumnTypeNullable may be implemented by Rows. The nullable value should
be true if it is known the column may be null, or false if the column is
known to be not nullable. If the column nullability is unknown, ok should be
false.
RowsColumnTypePrecisionScale may be implemented by Rows. It should return
the precision and scale for decimal types. If not applicable, ok should be
false. The following are examples of returned values for various types:
decimal(38, 4) (38, 4, true)
int (0, 0, false)
decimal (math.MaxInt64, math.MaxInt64, true)
RowsColumnTypeScanType may be implemented by Rows. It should return the
value type that can be used to scan types into. For example, the database
column type "bigint" this should return "reflect.TypeOf(int64(0))".
Columns returns the names of the columns. The number of columns of the
result is inferred from the length of the slice. If a particular column name
isn't known, an empty string should be returned for that entry.
Next is called to populate the next row of data into the provided slice. The
provided slice will be the same size as the Columns() are wide.
Next should return io.EOF when there are no more rows.
*T : database/sql/driver.Rows
*T : database/sql/driver.RowsColumnTypeDatabaseTypeName
*T : database/sql/driver.RowsColumnTypeLength
*T : database/sql/driver.RowsColumnTypeNullable
*T : database/sql/driver.RowsColumnTypePrecisionScale
*T : database/sql/driver.RowsColumnTypeScanType
*T : io.Closer
func newRows(c *conn, pstmt uintptr, allocs []uintptr, empty bool) (r *rows, err error)
c*connpsqluintptr
Close closes the statement.
As of Go 1.1, a Stmt will not be closed if it's in use by any queries.
Exec executes a query that doesn't return rows, such as an INSERT or UPDATE.
Deprecated: Drivers should implement StmtExecContext instead (or
additionally).
ExecContext implements driver.StmtExecContext
NumInput returns the number of placeholder parameters.
If NumInput returns >= 0, the sql package will sanity check argument counts
from callers and return errors to the caller before the statement's Exec or
Query methods are called.
NumInput may also return -1, if the driver doesn't know its number of
placeholders. In that case, the sql package will not sanity check Exec or
Query argument counts.
Query executes a query that may return rows, such as a
SELECT.
Deprecated: Drivers should implement StmtQueryContext instead (or
additionally).
QueryContext implements driver.StmtQueryContext
(*T) exec(ctx context.Context, args []driver.NamedValue) (r driver.Result, err error)(*T) query(ctx context.Context, args []driver.NamedValue) (r driver.Rows, err error)
*T : database/sql/driver.Stmt
*T : database/sql/driver.StmtExecContext
*T : database/sql/driver.StmtQueryContext
*T : io.Closer
func newStmt(c *conn, sql string) (*stmt, error)
Package-Level Variables (total 2, in which 1 are exported)
ErrorCodeString maps Error.Code() to its string representation.
Inspired by mattn/go-sqlite3: https://github.com/mattn/go-sqlite3/blob/ab91e934/sqlite3.go#L210-L226
These time.Parse formats handle formats 1 through 7 listed at https://www.sqlite.org/lang_datefunc.html.
Package-Level Constants (total 3, none are exported)
The pages are generated with Goldsv0.3.6. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.