Commit ff7149ac authored by gwenn's avatar gwenn

Docs...

parent 4ece6b52
......@@ -16,7 +16,7 @@ import (
"unsafe"
)
// Backup/Copy the content of one database (source) to another (destination).
// NewBackup initializes the backup/copy of the content of one database (source) to another (destination).
// The database name is "main", "temp", or the name specified in an ATTACH statement.
//
// (See http://sqlite.org/c3ref/backup_finish.html#sqlite3backupinit)
......@@ -37,12 +37,13 @@ func NewBackup(dst *Conn, dstDbName string, src *Conn, srcDbName string) (*Backu
}
// Online backup
// (See http://sqlite.org/c3ref/backup.html)
type Backup struct {
sb *C.sqlite3_backup
dst, src *Conn
}
// Step copies up to N pages between the source and destination databases
// Step copies up to N pages between the source and destination databases.
// (See http://sqlite.org/c3ref/backup_finish.html#sqlite3backupstep)
func (b *Backup) Step(npage int) error {
if b == nil {
......@@ -67,6 +68,13 @@ func (b *Backup) Status() BackupStatus {
return BackupStatus{int(C.sqlite3_backup_remaining(b.sb)), int(C.sqlite3_backup_pagecount(b.sb))}
}
// Run starts the backup:
// - copying up to 'npage' pages between the source and destination at each step,
// - sleeping 'sleepNs' between steps,
// - notifying the caller of backup progress throw the channel 'c',
// - closing the backup when done or when an error happens.
// Sleeping is disabled if 'sleepNs' is zero or negative.
// Notification is disabled if 'c' is null.
// (See http://sqlite.org/c3ref/backup_finish.html#sqlite3backupstep, sqlite3_backup_remaining and sqlite3_backup_pagecount)
func (b *Backup) Run(npage int, sleepNs time.Duration, c chan<- BackupStatus) error {
var err error
......@@ -96,7 +104,7 @@ func (b *Backup) Run(npage int, sleepNs time.Duration, c chan<- BackupStatus) er
return nil
}
// Close finishes/stops the backup
// Close finishes/stops the backup.
// (See http://sqlite.org/c3ref/backup_finish.html#sqlite3backupfinish)
func (b *Backup) Close() error {
if b == nil {
......
......@@ -16,7 +16,7 @@ import (
"unsafe"
)
// Reader adapter to BLOB
// io.ReadCloser adapter to BLOB
type BlobReader struct {
c *Conn
bl *C.sqlite3_blob
......@@ -24,7 +24,7 @@ type BlobReader struct {
ReadOffset int
}
// ReadWriter adapter to BLOB
// io.ReadWriteCloser adapter to BLOB
type BlobReadWriter struct {
BlobReader
WriteOffset int
......@@ -33,7 +33,7 @@ type BlobReadWriter struct {
// Zeroblobs are used to reserve space for a BLOB that is later written.
type ZeroBlobLength int
// NewBlobReader opens a BLOB for incremental I/O
// NewBlobReader opens a BLOB for incremental I/O.
//
// (See http://sqlite.org/c3ref/blob_open.html)
func (c *Conn) NewBlobReader(db, table, column string, row int64) (*BlobReader, error) {
......@@ -44,7 +44,7 @@ func (c *Conn) NewBlobReader(db, table, column string, row int64) (*BlobReader,
return &BlobReader{c, bl, -1, 0}, nil
}
// NewBlobReadWriter open a BLOB for incremental I/O
// NewBlobReadWriter open a BLOB for incremental I/O.
// (See http://sqlite.org/c3ref/blob_open.html)
func (c *Conn) NewBlobReadWriter(db, table, column string, row int64) (*BlobReadWriter, error) {
bl, err := c.blob_open(db, table, column, row, true)
......@@ -75,7 +75,7 @@ func (c *Conn) blob_open(db, table, column string, row int64, write bool) (*C.sq
return bl, nil
}
// Close closes a BLOB handle
// Close closes a BLOB handle.
// (See http://sqlite.org/c3ref/blob_close.html)
func (r *BlobReader) Close() error {
if r == nil {
......@@ -89,7 +89,7 @@ func (r *BlobReader) Close() error {
return nil
}
// Read reads data from a BLOB incrementally
// Read reads data from a BLOB incrementally.
// (See http://sqlite.org/c3ref/blob_read.html)
func (r *BlobReader) Read(v []byte) (int, error) {
if len(v) == 0 {
......@@ -115,7 +115,7 @@ func (r *BlobReader) Read(v []byte) (int, error) {
return n, nil
}
// Size returns the size of an opened BLOB
// Size returns the size of an opened BLOB.
// (See http://sqlite.org/c3ref/blob_bytes.html)
func (r *BlobReader) Size() (int, error) {
if r.bl == nil {
......@@ -127,7 +127,7 @@ func (r *BlobReader) Size() (int, error) {
return r.size, nil
}
// Write writes data into a BLOB incrementally
// Write writes data into a BLOB incrementally.
// (See http://sqlite.org/c3ref/blob_write.html)
func (w *BlobReadWriter) Write(v []byte) (int, error) {
if len(v) == 0 {
......@@ -155,7 +155,7 @@ func (w *BlobReadWriter) Write(v []byte) (int, error) {
return n, err
}
// Reopen moves a BLOB handle to a new row
// Reopen moves a BLOB handle to a new row.
// (See http://sqlite.org/c3ref/blob_reopen.html)
func (r *BlobReader) Reopen(rowid int64) error {
rv := C.sqlite3_blob_reopen(r.bl, C.sqlite3_int64(rowid))
......@@ -167,6 +167,8 @@ func (r *BlobReader) Reopen(rowid int64) error {
return nil
}
// Reopen moves a BLOB handle to a new row.
// (See http://sqlite.org/c3ref/blob_reopen.html)
func (w *BlobReadWriter) Reopen(rowid int64) error {
if err := w.BlobReader.Reopen(rowid); err != nil {
return err
......
......@@ -38,6 +38,10 @@ type rowsImpl struct {
columnNames []string // cache
}
// Open opens a new database connection.
// ":memory:" for memory db
// "" for temp file db
// TODO How to specify open flags?
func (d *Driver) Open(name string) (driver.Conn, error) {
c, err := Open(name)
if err != nil {
......
......@@ -65,20 +65,26 @@ http://sqlite.org/c3ref/context_db_handle.html
sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
*/
// Context common to scalar and aggregate function
type Context struct {
sc *C.sqlite3_context
argv **C.sqlite3_value
}
// Context associated to scalar function
type ScalarContext struct {
Context
ad map[int]interface{} // Function Auxiliary Data
udf *sqliteFunction
}
// Context associated to aggregate function
type AggregateContext struct {
Context
Aggregate interface{}
}
// Result sets the result of an SQL function.
func (c *Context) Result(r interface{}) {
switch r := r.(type) {
case nil:
......@@ -110,7 +116,7 @@ func (c *Context) Result(r interface{}) {
}
}
// Set the result of an SQL function
// ResultBool sets the result of an SQL function.
func (c *Context) ResultBool(b bool) {
if b {
c.ResultInt(1)
......@@ -119,7 +125,7 @@ func (c *Context) ResultBool(b bool) {
}
}
// Set the result of an SQL function
// ResultBlob sets the result of an SQL function.
// (See sqlite3_result_blob, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultBlob(b []byte) {
var p *byte
......@@ -129,13 +135,13 @@ func (c *Context) ResultBlob(b []byte) {
C.my_result_blob(c.sc, unsafe.Pointer(p), C.int(len(b)))
}
// Set the result of an SQL function
// ResultDouble sets the result of an SQL function.
// (See sqlite3_result_double, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultDouble(d float64) {
C.sqlite3_result_double(c.sc, C.double(d))
}
// Set the result of an SQL function
// ResultError sets the result of an SQL function.
// (See sqlite3_result_error, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultError(msg string) {
cs := C.CString(msg)
......@@ -143,43 +149,43 @@ func (c *Context) ResultError(msg string) {
C.sqlite3_result_error(c.sc, cs, -1)
}
// Set the result of an SQL function
// ResultErrorTooBig sets the result of an SQL function.
// (See sqlite3_result_error_toobig, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultErrorTooBig() {
C.sqlite3_result_error_toobig(c.sc)
}
// Set the result of an SQL function
// ResultErrorNoMem sets the result of an SQL function.
// (See sqlite3_result_error_nomem, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultErrorNoMem() {
C.sqlite3_result_error_nomem(c.sc)
}
// Set the result of an SQL function
// ResultErrorCode sets the result of an SQL function.
// (See sqlite3_result_error_code, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultErrorCode(e Errno) {
C.sqlite3_result_error_code(c.sc, C.int(e))
}
// Set the result of an SQL function
// ResultInt sets the result of an SQL function.
// (See sqlite3_result_int, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultInt(i int) {
C.sqlite3_result_int(c.sc, C.int(i))
}
// Set the result of an SQL function
// ResultInt64 sets the result of an SQL function.
// (See sqlite3_result_int64, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultInt64(i int64) {
C.sqlite3_result_int64(c.sc, C.sqlite3_int64(i))
}
// Set the result of an SQL function
// ResultNull sets the result of an SQL function.
// (See sqlite3_result_null, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultNull() {
C.sqlite3_result_null(c.sc)
}
// Set the result of an SQL function
// ResultText sets the result of an SQL function.
// (See sqlite3_result_text, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultText(s string) {
cs := C.CString(s)
......@@ -187,27 +193,27 @@ func (c *Context) ResultText(s string) {
C.my_result_text(c.sc, cs, -1)
}
// Set the result of an SQL function
// ResultValue sets the result of an SQL function.
// The leftmost value is number 0.
// (See sqlite3_result_value, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultValue(i int) {
C.my_result_value(c.sc, c.argv, C.int(i))
}
// Set the result of an SQL function
// ResultZeroblob sets the result of an SQL function.
// (See sqlite3_result_zeroblob, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultZeroblob(n ZeroBlobLength) {
C.sqlite3_result_zeroblob(c.sc, C.int(n))
}
// User data for functions
// UserData returns the user data for functions.
// (See http://sqlite.org/c3ref/user_data.html)
func (c *Context) UserData() interface{} {
udf := (*sqliteFunction)(C.sqlite3_user_data(c.sc))
return udf.pApp
}
// Function auxiliary data
// GetAuxData returns function auxiliary data.
// (See sqlite3_get_auxdata, http://sqlite.org/c3ref/get_auxdata.html)
func (c *ScalarContext) GetAuxData(n int) interface{} {
if len(c.ad) == 0 {
......@@ -216,7 +222,7 @@ func (c *ScalarContext) GetAuxData(n int) interface{} {
return c.ad[n]
}
// Function auxiliary data
// SetAuxData sets function auxiliary data.
// No destructor is needed a priori
// (See sqlite3_set_auxdata, http://sqlite.org/c3ref/get_auxdata.html)
func (c *ScalarContext) SetAuxData(n int, ad interface{}) {
......@@ -226,11 +232,13 @@ func (c *ScalarContext) SetAuxData(n int, ad interface{}) {
c.ad[n] = ad
}
// Bool obtains a SQL function parameter value.
// The leftmost value is number 0.
func (c *Context) Bool(i int) bool {
return c.Int(i) == 1
}
// Blob obtains a SQL function parameter value.
// The leftmost value is number 0.
// (See sqlite3_value_blob and sqlite3_value_bytes, http://sqlite.org/c3ref/value_blob.html)
func (c *Context) Blob(i int) (value []byte) {
......@@ -242,24 +250,28 @@ func (c *Context) Blob(i int) (value []byte) {
return
}
// Double obtains a SQL function parameter value.
// The leftmost value is number 0.
// (See sqlite3_value_double, http://sqlite.org/c3ref/value_blob.html)
func (c *Context) Double(i int) float64 {
return float64(C.my_value_double(c.argv, C.int(i)))
}
// Int obtains a SQL function parameter value.
// The leftmost value is number 0.
// (See sqlite3_value_int, http://sqlite.org/c3ref/value_blob.html)
func (c *Context) Int(i int) int {
return int(C.my_value_int(c.argv, C.int(i)))
}
// Int64 obtains a SQL function parameter value.
// The leftmost value is number 0.
// (See sqlite3_value_int64, http://sqlite.org/c3ref/value_blob.html)
func (c *Context) Int64(i int) int64 {
return int64(C.my_value_int64(c.argv, C.int(i)))
}
// Text obtains a SQL function parameter value.
// The leftmost value is number 0.
// (See sqlite3_value_text, http://sqlite.org/c3ref/value_blob.html)
func (c *Context) Text(i int) string {
......@@ -271,20 +283,21 @@ func (c *Context) Text(i int) string {
return C.GoStringN((*C.char)(unsafe.Pointer(p)), n)
}
// Type obtains a SQL function parameter value type.
// The leftmost value is number 0.
// SQL function parameter value type
// (See sqlite3_value_type, http://sqlite.org/c3ref/value_blob.html)
func (c *Context) Type(i int) Type {
return Type(C.my_value_type(c.argv, C.int(i)))
}
// NumericType obtains a SQL function parameter value numeric type (with possible conversion).
// The leftmost value is number 0.
// SQL function parameter value numeric type (with possible conversion)
// (See sqlite3_value_numeric_type, http://sqlite.org/c3ref/value_blob.html)
func (c *Context) NumericType(i int) Type {
return Type(C.my_value_numeric_type(c.argv, C.int(i)))
}
// Value obtains a SQL function parameter value depending on its type.
func (c *Context) Value(i int) (value interface{}) {
switch c.Type(i) {
case Null:
......@@ -393,7 +406,7 @@ func goXDestroy(pApp unsafe.Pointer) {
}
}
// Create or redefine SQL functions
// CreateScalarFunction creates or redefines SQL scalar functions.
// TODO Make possible to specify the preferred encoding
// (See http://sqlite.org/c3ref/create_function.html)
func (c *Conn) CreateScalarFunction(functionName string, nArg int, pApp interface{}, f ScalarFunction, d DestroyFunctionData) error {
......@@ -414,7 +427,7 @@ func (c *Conn) CreateScalarFunction(functionName string, nArg int, pApp interfac
return c.error(C.goSqlite3CreateScalarFunction(c.db, fname, C.int(nArg), C.SQLITE_UTF8, unsafe.Pointer(udf)))
}
// Create or redefine SQL functions
// CreateAggregateFunction creates or redefines SQL aggregate functions.
// TODO Make possible to specify the preferred encoding
// (See http://sqlite.org/c3ref/create_function.html)
func (c *Conn) CreateAggregateFunction(functionName string, nArg int, pApp interface{},
......
......@@ -32,7 +32,7 @@ func goXCommitHook(udp unsafe.Pointer) C.int {
return btocint(arg.f(arg.udp))
}
// Commit notification callback
// CommitHook registers a callback function to be invoked whenever a transaction is committed.
// (See http://sqlite.org/c3ref/commit_hook.html)
func (c *Conn) CommitHook(f CommitHook, udp interface{}) {
if f == nil {
......@@ -58,7 +58,7 @@ func goXRollbackHook(udp unsafe.Pointer) {
arg.f(arg.udp)
}
// Register a callback to be invoked each time a transaction is rolled back by this database connection.
// RollbackHook registers a callback to be invoked each time a transaction is rolled back.
// (See http://sqlite.org/c3ref/commit_hook.html)
func (c *Conn) RollbackHook(f RollbackHook, udp interface{}) {
if f == nil {
......@@ -84,7 +84,7 @@ func goXUpdateHook(udp unsafe.Pointer, action int, dbName, tableName *C.char, ro
arg.f(arg.udp, Action(action), C.GoString(dbName), C.GoString(tableName), int64(rowId))
}
// Register a callback to be invoked each time a row is updated, inserted or deleted using this database connection.
// UpdateHook registers a callback to be invoked each time a row is updated, inserted or deleted using this database connection.
// (See http://sqlite.org/c3ref/update_hook.html)
func (c *Conn) UpdateHook(f UpdateHook, udp interface{}) {
if f == nil {
......
......@@ -37,7 +37,8 @@ import "C"
import "unsafe"
// Executes pragma 'database_list'
// Databases returns one couple (name, file) for each database attached to the current database connection.
// (See http://www.sqlite.org/pragma.html#pragma_database_list)
func (c *Conn) Databases() (map[string]string, error) {
s, err := c.prepare("PRAGMA database_list")
if err != nil {
......@@ -59,7 +60,8 @@ func (c *Conn) Databases() (map[string]string, error) {
return databases, nil
}
// Selects tables (no view) from 'sqlite_master' and filters system tables out.
// Tables returns tables (no view) from 'sqlite_master' and filters system tables out.
// TODO create Views method to return views...
func (c *Conn) Tables(dbName string) ([]string, error) {
var sql string
if len(dbName) == 0 {
......@@ -96,7 +98,9 @@ type Column struct {
CollSeq string
}
// Executes pragma 'table_info'
// Columns returns a description for each column in the named table.
// Column.Autoinc and Column.CollSeq are left unspecified.
// (See http://www.sqlite.org/pragma.html#pragma_table_info)
func (c *Conn) Columns(dbName, table string) ([]Column, error) {
var pragma string
if len(dbName) == 0 {
......@@ -124,7 +128,8 @@ func (c *Conn) Columns(dbName, table string) ([]Column, error) {
return columns, nil
}
// Extract metadata about a column of a table
// Column extracts metadata about a column of a table
// Column.Cid and Column.DfltValue are left unspecified.
// (See http://sqlite.org/c3ref/table_column_metadata.html)
func (c *Conn) Column(dbName, tableName, columnName string) (*Column, error) {
var zDbName *C.char
......@@ -147,25 +152,32 @@ func (c *Conn) Column(dbName, tableName, columnName string) (*Column, error) {
autoinc == 1, C.GoString(zCollSeq)}, nil
}
// The left-most column is column 0
// ColumnDatabaseName returns the database
// that is the origin of a particular result column in SELECT statement.
// The left-most column is column 0.
// (See http://www.sqlite.org/c3ref/column_database_name.html)
func (s *Stmt) ColumnDatabaseName(index int) string {
return C.GoString(C.sqlite3_column_database_name(s.stmt, C.int(index)))
}
// The left-most column is column 0
// ColumnTableName returns the original un-aliased table name
// that is the origin of a particular result column in SELECT statement.
// The left-most column is column 0.
// (See http://www.sqlite.org/c3ref/column_database_name.html)
func (s *Stmt) ColumnTableName(index int) string {
return C.GoString(C.sqlite3_column_table_name(s.stmt, C.int(index)))
}
// The left-most column is column 0
// ColumnOriginName returns the original un-aliased table column name
// that is the origin of a particular result column in SELECT statement.
// The left-most column is column 0.
// (See http://www.sqlite.org/c3ref/column_database_name.html)
func (s *Stmt) ColumnOriginName(index int) string {
return C.GoString(C.sqlite3_column_origin_name(s.stmt, C.int(index)))
}
// The left-most column is column 0
// ColumnDeclaredType returns the declared type of the table column of a particular result column in SELECT statement. If the result column is an expression or subquery, then a NULL pointer is returned.
// The left-most column is column 0.
// (See http://www.sqlite.org/c3ref/column_decltype.html)
func (s *Stmt) ColumnDeclaredType(index int) string {
return C.GoString(C.sqlite3_column_decltype(s.stmt, C.int(index)))
......@@ -178,7 +190,8 @@ type ForeignKey struct {
To []string
}
// Executes pragma 'foreign_key_list'
// ForeignKeys returns one description for each foreign key that references a column in the argument table.
// (See http://www.sqlite.org/pragma.html#pragma_foreign_key_list)
func (c *Conn) ForeignKeys(dbName, table string) (map[int]*ForeignKey, error) {
var pragma string
if len(dbName) == 0 {
......@@ -220,7 +233,8 @@ type Index struct {
Unique bool
}
// Executes pragma 'index_list'
// Indexes returns one description for each index associated with the given table.
// (See http://www.sqlite.org/pragma.html#pragma_index_list)
func (c *Conn) Indexes(dbName, table string) ([]Index, error) {
var pragma string
if len(dbName) == 0 {
......@@ -248,8 +262,9 @@ func (c *Conn) Indexes(dbName, table string) ([]Index, error) {
return indexes, nil
}
// Executes pragma 'index_info'
// IndexColumns returns one description for each column in the named index.
// Only Column.Cid and Column.Name are specified. All other fields are unspecifed.
// (See http://www.sqlite.org/pragma.html#pragma_index_info)
func (c *Conn) IndexColumns(dbName, index string) ([]Column, error) {
var pragma string
if len(dbName) == 0 {
......@@ -277,6 +292,8 @@ func (c *Conn) IndexColumns(dbName, index string) ([]Column, error) {
return columns, nil
}
// Mprintf is like fmt.Printf but implements some additional formatting options
// that are useful for constructing SQL statements.
// (See http://sqlite.org/c3ref/mprintf.html)
func Mprintf(format string, arg string) string {
cf := C.CString(format)
......@@ -287,6 +304,10 @@ func Mprintf(format string, arg string) string {
defer C.sqlite3_free(unsafe.Pointer(zSQL))
return C.GoString(zSQL)
}
// Mprintf2 is like fmt.Printf but implements some additional formatting options
// that are useful for constructing SQL statements.
// (See http://sqlite.org/c3ref/mprintf.html)
func Mprintf2(format string, arg1, arg2 string) string {
cf := C.CString(format)
defer C.free(unsafe.Pointer(cf))
......
......@@ -170,7 +170,7 @@ type Conn struct {
udfs map[string]*sqliteFunction
}
// Run-time library version number
// Version returns the run-time library version number
// (See http://sqlite.org/c3ref/libversion.html)
func Version() string {
p := C.sqlite3_libversion()
......@@ -191,7 +191,7 @@ const (
OpenPrivateCache OpenFlag = C.SQLITE_OPEN_PRIVATECACHE
)
// Open a new database connection.
// Open opens a new database connection.
// ":memory:" for memory db
// "" for temp file db
//
......@@ -200,7 +200,7 @@ func Open(filename string, flags ...OpenFlag) (*Conn, error) {
return OpenVfs(filename, "", flags...)
}
// Open a new database with a specified virtual file system.
// OpenVfs opens a new database with a specified virtual file system.
func OpenVfs(filename string, vfsname string, flags ...OpenFlag) (*Conn, error) {
if C.sqlite3_threadsafe() == 0 {
return nil, errors.New("sqlite library was not compiled for thread-safe operation")
......@@ -235,7 +235,7 @@ func OpenVfs(filename string, vfsname string, flags ...OpenFlag) (*Conn, error)
return &Conn{db: db, stmtCache: newCache()}, nil
}
// Set a busy timeout
// BusyTimeout sets a busy timeout.
// (See http://sqlite.org/c3ref/busy_timeout.html)
func (c *Conn) BusyTimeout(ms int) error { // TODO time.Duration ?
return c.error(C.sqlite3_busy_timeout(c.db, C.int(ms)))
......@@ -258,7 +258,7 @@ func (c *Conn) IsFKeyEnabled() (bool, error) {
return c.queryOrSetEnableDbConfig(C.SQLITE_DBCONFIG_ENABLE_FKEY, -1)
}
// Enable or disable triggers
// EnableTriggers enables or disables triggers.
// Calls sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_TRIGGER, b)
//
// (See http://sqlite.org/c3ref/c_dbconfig_enable_fkey.html)
......@@ -266,6 +266,7 @@ func (c *Conn) EnableTriggers(b bool) (bool, error) {
return c.queryOrSetEnableDbConfig(C.SQLITE_DBCONFIG_ENABLE_TRIGGER, btocint(b))
}
// AreTriggersEnabled checks if triggers are enabled.
// Calls sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_TRIGGER, -1)
//
// (See http://sqlite.org/c3ref/c_dbconfig_enable_fkey.html)
......@@ -370,7 +371,7 @@ func (c *Conn) OneValue(query string, value interface{}, args ...interface{}) er
return s.Scan(value)
}
// Count the number of rows modified.
// Changes counts the number of rows modified.
// If a separate thread makes changes on the same database connection while Changes() is running then the value returned is unpredictable and not meaningful.
// (See http://sqlite.org/c3ref/changes.html)
func (c *Conn) Changes() int {
......@@ -411,11 +412,14 @@ const (
Exclusive TransactionType = 2
)
// Begin transaction in deferred mode
// Begin begins a transaction in deferred mode.
// (See http://www.sqlite.org/lang_transaction.html)
func (c *Conn) Begin() error {
return c.BeginTransaction(Deferred)
}
// BeginTransaction begins a transaction of the specified type.
// (See http://www.sqlite.org/lang_transaction.html)
func (c *Conn) BeginTransaction(t TransactionType) error {
if t == Deferred {
return c.exec("BEGIN")
......@@ -428,13 +432,13 @@ func (c *Conn) BeginTransaction(t TransactionType) error {
return nil
}
// Commit transaction
// Commit commits transaction
func (c *Conn) Commit() error {
// TODO Check autocommit?
return c.exec("COMMIT")
}
// Rollback transaction
// Rollback rollbacks transaction
func (c *Conn) Rollback() error {
// TODO Check autocommit?
return c.exec("ROLLBACK")
......@@ -468,7 +472,7 @@ func (c *Conn) exec(cmd string) error {
return nil
}
// Close a database connection and any dangling statements.
// Close closes a database connection and any dangling statements.
// (See http://sqlite.org/c3ref/close.html)
func (c *Conn) Close() error {
if c == nil {
......@@ -526,7 +530,7 @@ func (c *Conn) LoadExtension(file string, proc ...string) error {
return nil
}
// Enable or disable shared pager cache
// EnableSharedCache enables or disables shared pager cache
// (See http://sqlite.org/c3ref/enable_shared_cache.html)
func EnableSharedCache(b bool) {
C.sqlite3_enable_shared_cache(btocint(b))
......
......@@ -41,7 +41,7 @@ func goXTrace(udp unsafe.Pointer, sql *C.char) {
arg.f(arg.udp, C.GoString(sql))
}
// Register or clear a trace function.
// Trace registers or clears a trace function.
// (See sqlite3_trace, http://sqlite.org/c3ref/profile.html)
func (c *Conn) Trace(f Tracer, udp interface{}) {
if f == nil {
......@@ -68,7 +68,7 @@ func goXProfile(udp unsafe.Pointer, sql *C.char, nanoseconds C.sqlite3_uint64) {
arg.f(arg.udp, C.GoString(sql), uint64(nanoseconds))
}
// Register or clear a profile function.
// Profile registers or clears a profile function.
// (See sqlite3_profile, http://sqlite.org/c3ref/profile.html)
func (c *Conn) Profile(f Profiler, udp interface{}) {
if f == nil {
......@@ -144,7 +144,7 @@ func goXAuth(udp unsafe.Pointer, action int, arg1, arg2, dbName, triggerName *C.
return C.int(result)
}
// Set or clear the access authorization function.
// SetAuthorizer sets or clears the access authorization function.
// (See http://sqlite.org/c3ref/set_authorizer.html)
func (c *Conn) SetAuthorizer(f Authorizer, udp interface{}) error {
if f == nil {
......@@ -172,7 +172,7 @@ func goXBusy(udp unsafe.Pointer, count int) C.int {
return btocint(result)
}
// Register a callback to handle SQLITE_BUSY errors
// BusyHandler registers a callback to handle SQLITE_BUSY errors.
// (See http://sqlite.org/c3ref/busy_handler.html)
func (c *Conn) BusyHandler(f BusyHandler, udp interface{}) error {
if f == nil {
......@@ -200,7 +200,7 @@ func goXProgress(udp unsafe.Pointer) C.int {
return btocint(result)
}
// Query progress callbacks
// ProgressHandler registers or clears a query progress callback.
// The progress callback will be invoked every numOps opcodes.
// (See http://sqlite.org/c3ref/progress_handler.html)
func (c *Conn) ProgressHandler(f ProgressHandler, numOps int, udp interface{}) {
......@@ -223,37 +223,37 @@ const (
StmtStatusAutoIndex StmtStatus = C.SQLITE_STMTSTATUS_AUTOINDEX
)
// Return the value of a status counter for a prepared statement
// Status returns the value of a status counter for a prepared statement.
// (See http://sqlite.org/c3ref/stmt_status.html)
func (s *Stmt) Status(op StmtStatus, reset bool) int {
return int(C.sqlite3_stmt_status(s.stmt, C.int(op), btocint(reset)))
}
// Memory allocator statistics
// MemoryUsed returns the number of bytes of memory currently outstanding (malloced but not freed).
// (See sqlite3_memory_used: http://sqlite.org/c3ref/memory_highwater.html)
func MemoryUsed() int64 {
return int64(C.sqlite3_memory_used())
}
// Memory allocator statistics
// MemoryHighwater returns the maximum value of MemoryUsed() since the high-water mark was last reset.
// (See sqlite3_memory_highwater: http://sqlite.org/c3ref/memory_highwater.html)
func MemoryHighwater(reset bool) int64 {
return int64(C.sqlite3_memory_highwater(btocint(reset)))
}
// Limit on heap size
// SoftHeapLimit returns the limit on heap size.
// (See http://sqlite.org/c3ref/soft_heap_limit64.html)
func SoftHeapLimit() int64 {
return SetSoftHeapLimit(-1)
}
// Impose a limit on heap size
// SetSoftHeapLimit imposes a limit on heap size.
// (See http://sqlite.org/c3ref/soft_heap_limit64.html)
func SetSoftHeapLimit(n int64) int64 {
return int64(C.sqlite3_soft_heap_limit64(C.sqlite3_int64(n)))
}
// Determine if an SQL statement is complete
// Complete determines if an SQL statement is complete.
// (See http://sqlite.org/c3ref/complete.html)
func Complete(sql string) bool {
cs := C.CString(sql)
......@@ -261,7 +261,7 @@ func Complete(sql string) bool {
return C.sqlite3_complete(cs) != 0
}
// Error logging interface
// Log writes a message into the error log established by ConfigLog method.
// (See http://sqlite.org/c3ref/log.html)
func Log(err /*Errno*/ int, msg string) {
cs := C.CString(msg)
......@@ -286,7 +286,9 @@ func goXLog(udp unsafe.Pointer, err int, msg *C.char) {
var logger *sqliteLogger
// Configure the logger of the SQLite library
// ConfigLog configures the logger of the SQLite library.
// Only one logger can be registered at a time for the whole program.
// The logger must be threadsafe.
// (See sqlite3_config(SQLITE_CONFIG_LOG,...): http://sqlite.org/c3ref/config.html)
func ConfigLog(f Logger, udp interface{}) error {
var rv C.int
......@@ -312,7 +314,7 @@ const (
Serialized ThreadingMode = C.SQLITE_CONFIG_SERIALIZED
)
// Alters threading mode
// ConfigThreadingMode alters threading mode.
// (See sqlite3_config(SQLITE_CONFIG_SINGLETHREAD|SQLITE_CONFIG_MULTITHREAD|SQLITE_CONFIG_SERIALIZED): http://sqlite.org/c3ref/config.html)
func ConfigThreadingMode(mode ThreadingMode) error {
rv := C.goSqlite3ConfigThreadMode(C.int(mode))
......@@ -322,7 +324,7 @@ func ConfigThreadingMode(mode ThreadingMode) error {
return Errno(rv)
}
// Enables or disables the collection of memory allocation statistics
// ConfigMemStatus enables or disables the collection of memory allocation statistics.
// (See sqlite3_config(SQLITE_CONFIG_MEMSTATUS): http://sqlite.org/c3ref/config.html)
func ConfigMemStatus(b bool) error {
rv := C.goSqlite3Config(C.SQLITE_CONFIG_MEMSTATUS, btocint(b))
......@@ -332,7 +334,7 @@ func ConfigMemStatus(b bool) error {
return Errno(rv)
}
// Enables or disables URI handling
// ConfigUri enables or disables URI handling.
// (See sqlite3_config(SQLITE_CONFIG_URI): http://sqlite.org/c3ref/config.html)
func ConfigUri(b bool) error {
rv := C.goSqlite3Config(C.SQLITE_CONFIG_URI, btocint(b))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment