Documentation ¶
Overview ¶
Package sqlite3 implements a Go interface to the SQLite database.
Index ¶
- Constants
- func Initialize()
- func LibVersion() string
- func SQLiteError(code C.int) (e error)
- func Session(filename string, f func(db *Database))
- func Shutdown()
- func TransientSession(f func(db *Database))
- type Backup
- type BackupParameters
- type Blob
- type DBFlag
- type Database
- func (db *Database) Backup(p BackupParameters) (r Reporter, e error)
- func (db *Database) Begin() (e error)
- func (db *Database) Changes() int
- func (db *Database) Close()
- func (db *Database) Commit() (e error)
- func (db *Database) Error() error
- func (db *Database) Execute(sql string, f ...func(*Statement, ...interface{})) (c int, e error)
- func (db *Database) LastInsertRowID() int64
- func (db *Database) Load(source *Database, dbname string) (e error)
- func (db *Database) Mark(id interface{}) (e error)
- func (db *Database) MergeSteps(id interface{}) (e error)
- func (db *Database) Open(flags ...DBFlag) (e error)
- func (db *Database) Prepare(sql string, values ...interface{}) (s *Statement, e error)
- func (db *Database) Release(id interface{}) (e error)
- func (db *Database) Rollback() (e error)
- func (db *Database) Save(target *Database, dbname string) (e error)
- func (db *Database) SavePoints() (s []interface{})
- func (db *Database) TotalChanges() int
- type Errno
- type ProgressReport
- type QueryParameter
- type Reporter
- type ResultColumn
- type Statement
- func (s *Statement) All(f ...func(*Statement, ...interface{})) (c int, e error)
- func (s *Statement) Bind(start_column int, values ...interface{}) (e error, index int)
- func (s *Statement) BindAll(values ...interface{}) (e error, index int)
- func (s *Statement) ClearBindings() error
- func (s *Statement) Column(column int) (value interface{})
- func (s *Statement) ColumnName(column int) string
- func (s *Statement) ColumnType(column int) int
- func (s *Statement) Columns() int
- func (s *Statement) Finalize() (e error)
- func (s *Statement) Parameters() int
- func (s *Statement) Reset() error
- func (s *Statement) Row() (values []interface{})
- func (s *Statement) SQLSource() (sql string)
- func (s *Statement) Step(f ...func(*Statement, ...interface{})) (e error)
- type Table
- type Value
Constants ¶
const ( OK = Errno(iota) ERROR INTERNAL PERM ABORT BUSY LOCKED NOMEM READONLY INTERRUPT IOERR CORRUPT NOTFOUND FULL CANTOPEN PROTOCOL EMPTY SCHEMA TOOBIG CONSTRAINT MISMATCH MISUSE NOLFS AUTH FORMAT RANGE NOTDB ROW = Errno(100) DONE = Errno(101) ENCODER = Errno(1000) SAVEPOINT = Errno(1001) )
const ( INTEGER = 1 FLOAT = 2 TEXT = 3 BLOB = 4 NULL = 5 )
Variables ¶
This section is empty.
Functions ¶
func SQLiteError ¶
func TransientSession ¶
func TransientSession(f func(db *Database))
TransientDatabase initializes a in-memory database and calls `f` to access it.
Types ¶
type Backup ¶
type Backup struct {
// contains filtered or unexported fields
}
Backup implements the SQLite Online Backup API.
The backup API copies the content of one database to another. It is useful either for creating backups of databases or for copying in-memory databases to or from persistent files.
func (*Backup) Finish ¶
Finish should be called when the backup is done, an error occured or when the application wants to abandon the backup operation.
type BackupParameters ¶
type Blob ¶
type Blob struct {
// contains filtered or unexported fields
}
Blob represents the SQLite3 blob type.
type DBFlag ¶
type DBFlag int
const ( O_READONLY DBFlag = 0x00000001 O_READWRITE DBFlag = 0x00000002 O_CREATE DBFlag = 0x00000004 O_DELETEONCLOSE DBFlag = 0x00000008 O_EXCLUSIVE DBFlag = 0x00000010 O_AUTOPROXY DBFlag = 0x00000020 O_URI DBFlag = 0x00000040 O_MAIN_DB DBFlag = 0x00000100 O_TEMP_DB DBFlag = 0x00000200 O_TRANSIENT_DB DBFlag = 0x00000400 O_MAIN_JOURNAL DBFlag = 0x00000800 O_TEMP_JOURNAL DBFlag = 0x00001000 O_SUBJOURNAL DBFlag = 0x00002000 O_MASTER_JOURNAL DBFlag = 0x00004000 O_NOMUTEX DBFlag = 0x00008000 O_FULLMUTEX DBFlag = 0x00010000 O_SHAREDCACHE DBFlag = 0x00020000 O_PRIVATECACHE DBFlag = 0x00040000 O_WAL DBFlag = 0x00080000 )
type Database ¶
type Database struct { Filename string DBFlag Savepoints []interface{} // contains filtered or unexported fields }
Database implements high level view of the underlying database.
func TransientDatabase ¶
func TransientDatabase() (db *Database)
TransientDatabase returns a handle to an in-memory database.
func (*Database) Backup ¶
func (db *Database) Backup(p BackupParameters) (r Reporter, e error)
Backup creates a copy (backup) of the current database to the target file specified in BackupParameters.
func (*Database) Changes ¶
Changes returns the number of database rows that were changed or inserted or deleted by the most recently completed SQL statement.
func (*Database) Commit ¶
Commit ends the current transaction and makes all changes performed in the transaction permanent.
func (*Database) Error ¶
Error returns the numeric result code for the most recently failed database call.
func (*Database) LastInsertRowID ¶
LastInsertRowID returns the id of the most recently successful INSERT.
Each entry in an SQLite table has a unique 64-bit signed integer key called the "rowid". The rowid is always available as an undeclared column named ROWID, OID, or _ROWID_ as long as those names are not also used by explicitly declared columns. If the table has a column of type INTEGER PRIMARY KEY then that column is another alias for the rowid.
This routine returns the rowid of the most recently successful INSERT into the database from the database connection in the first argument. As of SQLite version 3.7.7, this routines records the last insert rowid of both ordinary tables and virtual tables. If no successful INSERTs have ever occurred on that database connection, zero is returned.
func (*Database) Mark ¶
Mark creates a SAVEPOINT.
A SAVEPOINT is a method of creating transactions, similar to BEGIN and COMMIT, except that Mark and MergeSteps are named and may be nested.
func (*Database) MergeSteps ¶
MergeSteps can be seen as the equivalent of COMMIT for a Mark command.
func (*Database) Prepare ¶
Prepare compiles the SQL query into a byte-code program and binds the supplied values.
func (*Database) Release ¶
Release rolls back all transactions to the specified SAVEPOINT (Mark).
More specificly ... - Some people view RELEASE as the equivalent of COMMIT for a SAVEPOINT. This is an acceptable point of view as long as one remembers that the changes committed by an inner transaction might later be undone by a rollback in an outer transaction. - Another view of RELEASE is that it merges a named transaction into its parent transaction, so that the named transaction and its parent become the same transaction. After RELEASE, the named transaction and its parent will commit or rollback together, whatever their fate may be. - One can also think of savepoints as "marks" in the transaction timeline. In this view, the SAVEPOINT command creates a new mark, the ROLLBACK TO command rewinds the timeline back to a point just after the named mark, and the RELEASE command erases marks from the timeline without actually making any changes to the database.
func (*Database) SavePoints ¶
func (db *Database) SavePoints() (s []interface{})
SavePoints returns the currently active SAVEPOINTs created using Mark.
func (*Database) TotalChanges ¶
TotalChanges retruns the number of row changes.
This function returns the number of row changes caused by INSERT, UPDATE or DELETE statements since the database connection was opened. The count returned by TotalChanges includes all changes from all trigger contexts and changes made by foreign key actions. However, the count does not include changes used to implement REPLACE constraints, do rollbacks or ABORT processing, or DROP TABLE processing. The count does not include rows of views that fire an INSTEAD OF trigger, though if the INSTEAD OF trigger makes changes of its own, those changes are counted. The TotalChanges function counts the changes as soon as the statement that makes them is completed.
type ProgressReport ¶
type QueryParameter ¶
type QueryParameter int
func (QueryParameter) Bind ¶
func (p QueryParameter) Bind(s *Statement, value interface{}) (e error)
Bind replaces the literals placed in the SQL statement with the actual values supplied to the function.
The following templates may be replaced by the values:
- ?
- ?NNN
- :VVV
- @VVV
- $VVV
In the templates above, NNN represents an integer literal, VVV represents an alphanumeric identifier.
type Reporter ¶
type Reporter chan *ProgressReport
type ResultColumn ¶
type ResultColumn int
ResultColumn implements the high level view of the SQLite result column.
func (ResultColumn) ByteCount ¶
func (c ResultColumn) ByteCount(s *Statement) int
ByteCount returns the number of bytes of the BLOB or string without the zero terminators at the end of the string.
func (ResultColumn) Name ¶
func (c ResultColumn) Name(s *Statement) string
Name returns the name assigned to a particular column in the result set of a SELECT statement.
func (ResultColumn) Type ¶
func (c ResultColumn) Type(s *Statement) int
Type returns the datatype code for the initial data type of the column.
func (ResultColumn) Value ¶
func (c ResultColumn) Value(s *Statement) (value interface{})
Value returns the value of the ResultColumn converted to a Go type.
type Statement ¶
type Statement struct {
// contains filtered or unexported fields
}
Statement represents a "SQL prepared Statement" also known as "compiled SQL statement".
func (*Statement) All ¶
All can be used to return all rows of a prepared statement after the statement has been prepared.
func (*Statement) ClearBindings ¶
ClearBindings is used to reset all parameters to NULL.
func (*Statement) ColumnName ¶
ColumnName returns the name of the column.
func (*Statement) ColumnType ¶
ColumnType returns the type of the column.
func (*Statement) Columns ¶
Columns returns the number of columns in the result set of the prepared statement.
func (*Statement) Parameters ¶
Parameters returns the number of SQL parameters.
This routine actually returns the index of the largest (rightmost) parameter. For all forms except ?NNN, this will correspond to the number of unique parameters. If parameters of the ?NNN form are used, there may be gaps in the list.
func (*Statement) Reset ¶
Reset may be used to reset the statement to its initial state, ready to be re-executed.
Any SQL statement variables that had values bound to them retain their values. Use `ClearBindings` to reset the bindings.
func (*Statement) Row ¶
func (s *Statement) Row() (values []interface{})
Row returns all values of the row.