Commit ff7149ac authored by gwenn's avatar gwenn

Docs...

parent 4ece6b52
...@@ -16,7 +16,7 @@ import ( ...@@ -16,7 +16,7 @@ import (
"unsafe" "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. // The database name is "main", "temp", or the name specified in an ATTACH statement.
// //
// (See http://sqlite.org/c3ref/backup_finish.html#sqlite3backupinit) // (See http://sqlite.org/c3ref/backup_finish.html#sqlite3backupinit)
...@@ -37,12 +37,13 @@ func NewBackup(dst *Conn, dstDbName string, src *Conn, srcDbName string) (*Backu ...@@ -37,12 +37,13 @@ func NewBackup(dst *Conn, dstDbName string, src *Conn, srcDbName string) (*Backu
} }
// Online backup // Online backup
// (See http://sqlite.org/c3ref/backup.html)
type Backup struct { type Backup struct {
sb *C.sqlite3_backup sb *C.sqlite3_backup
dst, src *Conn 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) // (See http://sqlite.org/c3ref/backup_finish.html#sqlite3backupstep)
func (b *Backup) Step(npage int) error { func (b *Backup) Step(npage int) error {
if b == nil { if b == nil {
...@@ -67,6 +68,13 @@ func (b *Backup) Status() BackupStatus { ...@@ -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))} 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) // (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 { func (b *Backup) Run(npage int, sleepNs time.Duration, c chan<- BackupStatus) error {
var err error var err error
...@@ -96,7 +104,7 @@ func (b *Backup) Run(npage int, sleepNs time.Duration, c chan<- BackupStatus) er ...@@ -96,7 +104,7 @@ func (b *Backup) Run(npage int, sleepNs time.Duration, c chan<- BackupStatus) er
return nil return nil
} }
// Close finishes/stops the backup // Close finishes/stops the backup.
// (See http://sqlite.org/c3ref/backup_finish.html#sqlite3backupfinish) // (See http://sqlite.org/c3ref/backup_finish.html#sqlite3backupfinish)
func (b *Backup) Close() error { func (b *Backup) Close() error {
if b == nil { if b == nil {
......
...@@ -16,7 +16,7 @@ import ( ...@@ -16,7 +16,7 @@ import (
"unsafe" "unsafe"
) )
// Reader adapter to BLOB // io.ReadCloser adapter to BLOB
type BlobReader struct { type BlobReader struct {
c *Conn c *Conn
bl *C.sqlite3_blob bl *C.sqlite3_blob
...@@ -24,7 +24,7 @@ type BlobReader struct { ...@@ -24,7 +24,7 @@ type BlobReader struct {
ReadOffset int ReadOffset int
} }
// ReadWriter adapter to BLOB // io.ReadWriteCloser adapter to BLOB
type BlobReadWriter struct { type BlobReadWriter struct {
BlobReader BlobReader
WriteOffset int WriteOffset int
...@@ -33,7 +33,7 @@ type BlobReadWriter struct { ...@@ -33,7 +33,7 @@ type BlobReadWriter struct {
// Zeroblobs are used to reserve space for a BLOB that is later written. // Zeroblobs are used to reserve space for a BLOB that is later written.
type ZeroBlobLength int 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) // (See http://sqlite.org/c3ref/blob_open.html)
func (c *Conn) NewBlobReader(db, table, column string, row int64) (*BlobReader, error) { 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, ...@@ -44,7 +44,7 @@ func (c *Conn) NewBlobReader(db, table, column string, row int64) (*BlobReader,
return &BlobReader{c, bl, -1, 0}, nil 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) // (See http://sqlite.org/c3ref/blob_open.html)
func (c *Conn) NewBlobReadWriter(db, table, column string, row int64) (*BlobReadWriter, error) { func (c *Conn) NewBlobReadWriter(db, table, column string, row int64) (*BlobReadWriter, error) {
bl, err := c.blob_open(db, table, column, row, true) 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 ...@@ -75,7 +75,7 @@ func (c *Conn) blob_open(db, table, column string, row int64, write bool) (*C.sq
return bl, nil return bl, nil
} }
// Close closes a BLOB handle // Close closes a BLOB handle.
// (See http://sqlite.org/c3ref/blob_close.html) // (See http://sqlite.org/c3ref/blob_close.html)
func (r *BlobReader) Close() error { func (r *BlobReader) Close() error {
if r == nil { if r == nil {
...@@ -89,7 +89,7 @@ func (r *BlobReader) Close() error { ...@@ -89,7 +89,7 @@ func (r *BlobReader) Close() error {
return nil return nil
} }
// Read reads data from a BLOB incrementally // Read reads data from a BLOB incrementally.
// (See http://sqlite.org/c3ref/blob_read.html) // (See http://sqlite.org/c3ref/blob_read.html)
func (r *BlobReader) Read(v []byte) (int, error) { func (r *BlobReader) Read(v []byte) (int, error) {
if len(v) == 0 { if len(v) == 0 {
...@@ -115,7 +115,7 @@ func (r *BlobReader) Read(v []byte) (int, error) { ...@@ -115,7 +115,7 @@ func (r *BlobReader) Read(v []byte) (int, error) {
return n, nil 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) // (See http://sqlite.org/c3ref/blob_bytes.html)
func (r *BlobReader) Size() (int, error) { func (r *BlobReader) Size() (int, error) {
if r.bl == nil { if r.bl == nil {
...@@ -127,7 +127,7 @@ func (r *BlobReader) Size() (int, error) { ...@@ -127,7 +127,7 @@ func (r *BlobReader) Size() (int, error) {
return r.size, nil 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) // (See http://sqlite.org/c3ref/blob_write.html)
func (w *BlobReadWriter) Write(v []byte) (int, error) { func (w *BlobReadWriter) Write(v []byte) (int, error) {
if len(v) == 0 { if len(v) == 0 {
...@@ -155,7 +155,7 @@ func (w *BlobReadWriter) Write(v []byte) (int, error) { ...@@ -155,7 +155,7 @@ func (w *BlobReadWriter) Write(v []byte) (int, error) {
return n, err 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) // (See http://sqlite.org/c3ref/blob_reopen.html)
func (r *BlobReader) Reopen(rowid int64) error { func (r *BlobReader) Reopen(rowid int64) error {
rv := C.sqlite3_blob_reopen(r.bl, C.sqlite3_int64(rowid)) rv := C.sqlite3_blob_reopen(r.bl, C.sqlite3_int64(rowid))
...@@ -167,6 +167,8 @@ func (r *BlobReader) Reopen(rowid int64) error { ...@@ -167,6 +167,8 @@ func (r *BlobReader) Reopen(rowid int64) error {
return nil 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 { func (w *BlobReadWriter) Reopen(rowid int64) error {
if err := w.BlobReader.Reopen(rowid); err != nil { if err := w.BlobReader.Reopen(rowid); err != nil {
return err return err
......
...@@ -38,6 +38,10 @@ type rowsImpl struct { ...@@ -38,6 +38,10 @@ type rowsImpl struct {
columnNames []string // cache 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) { func (d *Driver) Open(name string) (driver.Conn, error) {
c, err := Open(name) c, err := Open(name)
if err != nil { if err != nil {
......
...@@ -65,20 +65,26 @@ http://sqlite.org/c3ref/context_db_handle.html ...@@ -65,20 +65,26 @@ http://sqlite.org/c3ref/context_db_handle.html
sqlite3 *sqlite3_context_db_handle(sqlite3_context*); sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
*/ */
// Context common to scalar and aggregate function
type Context struct { type Context struct {
sc *C.sqlite3_context sc *C.sqlite3_context
argv **C.sqlite3_value argv **C.sqlite3_value
} }
// Context associated to scalar function
type ScalarContext struct { type ScalarContext struct {
Context Context
ad map[int]interface{} // Function Auxiliary Data ad map[int]interface{} // Function Auxiliary Data
udf *sqliteFunction udf *sqliteFunction
} }
// Context associated to aggregate function
type AggregateContext struct { type AggregateContext struct {
Context Context
Aggregate interface{} Aggregate interface{}
} }
// Result sets the result of an SQL function.
func (c *Context) Result(r interface{}) { func (c *Context) Result(r interface{}) {
switch r := r.(type) { switch r := r.(type) {
case nil: case nil:
...@@ -110,7 +116,7 @@ func (c *Context) Result(r interface{}) { ...@@ -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) { func (c *Context) ResultBool(b bool) {
if b { if b {
c.ResultInt(1) c.ResultInt(1)
...@@ -119,7 +125,7 @@ func (c *Context) ResultBool(b bool) { ...@@ -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) // (See sqlite3_result_blob, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultBlob(b []byte) { func (c *Context) ResultBlob(b []byte) {
var p *byte var p *byte
...@@ -129,13 +135,13 @@ func (c *Context) ResultBlob(b []byte) { ...@@ -129,13 +135,13 @@ func (c *Context) ResultBlob(b []byte) {
C.my_result_blob(c.sc, unsafe.Pointer(p), C.int(len(b))) 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) // (See sqlite3_result_double, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultDouble(d float64) { func (c *Context) ResultDouble(d float64) {
C.sqlite3_result_double(c.sc, C.double(d)) 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) // (See sqlite3_result_error, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultError(msg string) { func (c *Context) ResultError(msg string) {
cs := C.CString(msg) cs := C.CString(msg)
...@@ -143,43 +149,43 @@ func (c *Context) ResultError(msg string) { ...@@ -143,43 +149,43 @@ func (c *Context) ResultError(msg string) {
C.sqlite3_result_error(c.sc, cs, -1) 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) // (See sqlite3_result_error_toobig, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultErrorTooBig() { func (c *Context) ResultErrorTooBig() {
C.sqlite3_result_error_toobig(c.sc) 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) // (See sqlite3_result_error_nomem, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultErrorNoMem() { func (c *Context) ResultErrorNoMem() {
C.sqlite3_result_error_nomem(c.sc) 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) // (See sqlite3_result_error_code, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultErrorCode(e Errno) { func (c *Context) ResultErrorCode(e Errno) {
C.sqlite3_result_error_code(c.sc, C.int(e)) 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) // (See sqlite3_result_int, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultInt(i int) { func (c *Context) ResultInt(i int) {
C.sqlite3_result_int(c.sc, C.int(i)) 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) // (See sqlite3_result_int64, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultInt64(i int64) { func (c *Context) ResultInt64(i int64) {
C.sqlite3_result_int64(c.sc, C.sqlite3_int64(i)) 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) // (See sqlite3_result_null, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultNull() { func (c *Context) ResultNull() {
C.sqlite3_result_null(c.sc) 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) // (See sqlite3_result_text, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultText(s string) { func (c *Context) ResultText(s string) {
cs := C.CString(s) cs := C.CString(s)
...@@ -187,27 +193,27 @@ func (c *Context) ResultText(s string) { ...@@ -187,27 +193,27 @@ func (c *Context) ResultText(s string) {
C.my_result_text(c.sc, cs, -1) 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. // The leftmost value is number 0.
// (See sqlite3_result_value, http://sqlite.org/c3ref/result_blob.html) // (See sqlite3_result_value, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultValue(i int) { func (c *Context) ResultValue(i int) {
C.my_result_value(c.sc, c.argv, C.int(i)) 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) // (See sqlite3_result_zeroblob, http://sqlite.org/c3ref/result_blob.html)
func (c *Context) ResultZeroblob(n ZeroBlobLength) { func (c *Context) ResultZeroblob(n ZeroBlobLength) {
C.sqlite3_result_zeroblob(c.sc, C.int(n)) 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) // (See http://sqlite.org/c3ref/user_data.html)
func (c *Context) UserData() interface{} { func (c *Context) UserData() interface{} {
udf := (*sqliteFunction)(C.sqlite3_user_data(c.sc)) udf := (*sqliteFunction)(C.sqlite3_user_data(c.sc))
return udf.pApp return udf.pApp
} }
// Function auxiliary data // GetAuxData returns function auxiliary data.
// (See sqlite3_get_auxdata, http://sqlite.org/c3ref/get_auxdata.html) // (See sqlite3_get_auxdata, http://sqlite.org/c3ref/get_auxdata.html)
func (c *ScalarContext) GetAuxData(n int) interface{} { func (c *ScalarContext) GetAuxData(n int) interface{} {
if len(c.ad) == 0 { if len(c.ad) == 0 {
...@@ -216,7 +222,7 @@ func (c *ScalarContext) GetAuxData(n int) interface{} { ...@@ -216,7 +222,7 @@ func (c *ScalarContext) GetAuxData(n int) interface{} {
return c.ad[n] return c.ad[n]
} }
// Function auxiliary data // SetAuxData sets function auxiliary data.
// No destructor is needed a priori // No destructor is needed a priori
// (See sqlite3_set_auxdata, http://sqlite.org/c3ref/get_auxdata.html) // (See sqlite3_set_auxdata, http://sqlite.org/c3ref/get_auxdata.html)
func (c *ScalarContext) SetAuxData(n int, ad interface{}) { func (c *ScalarContext) SetAuxData(n int, ad interface{}) {
...@@ -226,11 +232,13 @@ func (c *ScalarContext) SetAuxData(n int, ad interface{}) { ...@@ -226,11 +232,13 @@ func (c *ScalarContext) SetAuxData(n int, ad interface{}) {
c.ad[n] = ad c.ad[n] = ad
} }
// Bool obtains a SQL function parameter value.
// The leftmost value is number 0. // The leftmost value is number 0.
func (c *Context) Bool(i int) bool { func (c *Context) Bool(i int) bool {
return c.Int(i) == 1 return c.Int(i) == 1
} }
// Blob obtains a SQL function parameter value.
// The leftmost value is number 0. // The leftmost value is number 0.
// (See sqlite3_value_blob and sqlite3_value_bytes, http://sqlite.org/c3ref/value_blob.html) // (See sqlite3_value_blob and sqlite3_value_bytes, http://sqlite.org/c3ref/value_blob.html)
func (c *Context) Blob(i int) (value []byte) { func (c *Context) Blob(i int) (value []byte) {
...@@ -242,24 +250,28 @@ func (c *Context) Blob(i int) (value []byte) { ...@@ -242,24 +250,28 @@ func (c *Context) Blob(i int) (value []byte) {
return return
} }
// Double obtains a SQL function parameter value.
// The leftmost value is number 0. // The leftmost value is number 0.
// (See sqlite3_value_double, http://sqlite.org/c3ref/value_blob.html) // (See sqlite3_value_double, http://sqlite.org/c3ref/value_blob.html)
func (c *Context) Double(i int) float64 { func (c *Context) Double(i int) float64 {
return float64(C.my_value_double(c.argv, C.int(i))) return float64(C.my_value_double(c.argv, C.int(i)))
} }
// Int obtains a SQL function parameter value.
// The leftmost value is number 0. // The leftmost value is number 0.
// (See sqlite3_value_int, http://sqlite.org/c3ref/value_blob.html) // (See sqlite3_value_int, http://sqlite.org/c3ref/value_blob.html)
func (c *Context) Int(i int) int { func (c *Context) Int(i int) int {
return int(C.my_value_int(c.argv, C.int(i))) return int(C.my_value_int(c.argv, C.int(i)))
} }
// Int64 obtains a SQL function parameter value.
// The leftmost value is number 0. // The leftmost value is number 0.
// (See sqlite3_value_int64, http://sqlite.org/c3ref/value_blob.html) // (See sqlite3_value_int64, http://sqlite.org/c3ref/value_blob.html)
func (c *Context) Int64(i int) int64 { func (c *Context) Int64(i int) int64 {
return int64(C.my_value_int64(c.argv, C.int(i))) return int64(C.my_value_int64(c.argv, C.int(i)))
} }
// Text obtains a SQL function parameter value.
// The leftmost value is number 0. // The leftmost value is number 0.
// (See sqlite3_value_text, http://sqlite.org/c3ref/value_blob.html) // (See sqlite3_value_text, http://sqlite.org/c3ref/value_blob.html)
func (c *Context) Text(i int) string { func (c *Context) Text(i int) string {
...@@ -271,20 +283,21 @@ 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) return C.GoStringN((*C.char)(unsafe.Pointer(p)), n)
} }
// Type obtains a SQL function parameter value type.
// The leftmost value is number 0. // The leftmost value is number 0.
// SQL function parameter value type
// (See sqlite3_value_type, http://sqlite.org/c3ref/value_blob.html) // (See sqlite3_value_type, http://sqlite.org/c3ref/value_blob.html)
func (c *Context) Type(i int) Type { func (c *Context) Type(i int) Type {
return Type(C.my_value_type(c.argv, C.int(i))) 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. // 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) // (See sqlite3_value_numeric_type, http://sqlite.org/c3ref/value_blob.html)
func (c *Context) NumericType(i int) Type { func (c *Context) NumericType(i int) Type {
return Type(C.my_value_numeric_type(c.argv, C.int(i))) 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{}) { func (c *Context) Value(i int) (value interface{}) {
switch c.Type(i) { switch c.Type(i) {
case Null: case Null:
...@@ -393,7 +406,7 @@ func goXDestroy(pApp unsafe.Pointer) { ...@@ -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 // TODO Make possible to specify the preferred encoding
// (See http://sqlite.org/c3ref/create_function.html) // (See http://sqlite.org/c3ref/create_function.html)
func (c *Conn) CreateScalarFunction(functionName string, nArg int, pApp interface{}, f ScalarFunction, d DestroyFunctionData) error { 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 ...@@ -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))) 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 // TODO Make possible to specify the preferred encoding
// (See http://sqlite.org/c3ref/create_function.html) // (See http://sqlite.org/c3ref/create_function.html)
func (c *Conn) CreateAggregateFunction(functionName string, nArg int, pApp interface{}, func (c *Conn) CreateAggregateFunction(functionName string, nArg int, pApp interface{},
......
...@@ -32,7 +32,7 @@ func goXCommitHook(udp unsafe.Pointer) C.int { ...@@ -32,7 +32,7 @@ func goXCommitHook(udp unsafe.Pointer) C.int {
return btocint(arg.f(arg.udp)) 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) // (See http://sqlite.org/c3ref/commit_hook.html)
func (c *Conn) CommitHook(f CommitHook, udp interface{}) { func (c *Conn) CommitHook(f CommitHook, udp interface{}) {
if f == nil { if f == nil {
...@@ -58,7 +58,7 @@ func goXRollbackHook(udp unsafe.Pointer) { ...@@ -58,7 +58,7 @@ func goXRollbackHook(udp unsafe.Pointer) {
arg.f(arg.udp) 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) // (See http://sqlite.org/c3ref/commit_hook.html)
func (c *Conn) RollbackHook(f RollbackHook, udp interface{}) { func (c *Conn) RollbackHook(f RollbackHook, udp interface{}) {
if f == nil { if f == nil {
...@@ -84,7 +84,7 @@ func goXUpdateHook(udp unsafe.Pointer, action int, dbName, tableName *C.char, ro ...@@ -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)) 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) // (See http://sqlite.org/c3ref/update_hook.html)
func (c *Conn) UpdateHook(f UpdateHook, udp interface{}) { func (c *Conn) UpdateHook(f UpdateHook, udp interface{}) {
if f == nil { if f == nil {
......
...@@ -37,7 +37,8 @@ import "C" ...@@ -37,7 +37,8 @@ import "C"
import "unsafe" 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) { func (c *Conn) Databases() (map[string]string, error) {
s, err := c.prepare("PRAGMA database_list") s, err := c.prepare("PRAGMA database_list")
if err != nil { if err != nil {
...@@ -59,7 +60,8 @@ func (c *Conn) Databases() (map[string]string, error) { ...@@ -59,7 +60,8 @@ func (c *Conn) Databases() (map[string]string, error) {
return databases, nil 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) { func (c *Conn) Tables(dbName string) ([]string, error) {
var sql string var sql string
if len(dbName) == 0 { if len(dbName) == 0 {
...@@ -96,7 +98,9 @@ type Column struct { ...@@ -96,7 +98,9 @@ type Column struct {
CollSeq string 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) { func (c *Conn) Columns(dbName, table string) ([]Column, error) {
var pragma string var pragma string
if len(dbName) == 0 { if len(dbName) == 0 {
...@@ -124,7 +128,8 @@ func (c *Conn) Columns(dbName, table string) ([]Column, error) { ...@@ -124,7 +128,8 @@ func (c *Conn) Columns(dbName, table string) ([]Column, error) {
return columns, nil 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) // (See http://sqlite.org/c3ref/table_column_metadata.html)
func (c *Conn) Column(dbName, tableName, columnName string) (*Column, error) { func (c *Conn) Column(dbName, tableName, columnName string) (*Column, error) {
var zDbName *C.char var zDbName *C.char
...@@ -147,25 +152,32 @@ func (c *Conn) Column(dbName, tableName, columnName string) (*Column, error) { ...@@ -147,25 +152,32 @@ func (c *Conn) Column(dbName, tableName, columnName string) (*Column, error) {
autoinc == 1, C.GoString(zCollSeq)}, nil 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) // (See http://www.sqlite.org/c3ref/column_database_name.html)
func (s *Stmt) ColumnDatabaseName(index int) string { func (s *Stmt) ColumnDatabaseName(index int) string {
return C.GoString(C.sqlite3_column_database_name(s.stmt, C.int(index))) 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) // (See http://www.sqlite.org/c3ref/column_database_name.html)
func (s *Stmt) ColumnTableName(index int) string { func (s *Stmt) ColumnTableName(index int) string {
return C.GoString(C.sqlite3_column_table_name(s.stmt, C.int(index))) 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) // (See http://www.sqlite.org/c3ref/column_database_name.html)
func (s *Stmt) ColumnOriginName(index int) string { func (s *Stmt) ColumnOriginName(index int) string {
return C.GoString(C.sqlite3_column_origin_name(s.stmt, C.int(index))) 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) // (See http://www.sqlite.org/c3ref/column_decltype.html)
func (s *Stmt) ColumnDeclaredType(index int) string { func (s *Stmt) ColumnDeclaredType(index int) string {
return C.GoString(C.sqlite3_column_decltype(s.stmt, C.int(index))) return C.GoString(C.sqlite3_column_decltype(s.stmt, C.int(index)))
...@@ -178,7 +190,8 @@ type ForeignKey struct { ...@@ -178,7 +190,8 @@ type ForeignKey struct {
To []string 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) { func (c *Conn) ForeignKeys(dbName, table string) (map[int]*ForeignKey, error) {
var pragma string var pragma string
if len(dbName) == 0 { if len(dbName) == 0 {
...@@ -220,7 +233,8 @@ type Index struct { ...@@ -220,7 +233,8 @@ type Index struct {
Unique bool 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) { func (c *Conn) Indexes(dbName, table string) ([]Index, error) {
var pragma string var pragma string
if len(dbName) == 0 { if len(dbName) == 0 {
...@@ -248,8 +262,9 @@ func (c *Conn) Indexes(dbName, table string) ([]Index, error) { ...@@ -248,8 +262,9 @@ func (c *Conn) Indexes(dbName, table string) ([]Index, error) {
return indexes, nil 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. // 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) { func (c *Conn) IndexColumns(dbName, index string) ([]Column, error) {
var pragma string var pragma string
if len(dbName) == 0 { if len(dbName) == 0 {
...@@ -277,6 +292,8 @@ func (c *Conn) IndexColumns(dbName, index string) ([]Column, error) { ...@@ -277,6 +292,8 @@ func (c *Conn) IndexColumns(dbName, index string) ([]Column, error) {
return columns, nil 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) // (See http://sqlite.org/c3ref/mprintf.html)
func Mprintf(format string, arg string) string { func Mprintf(format string, arg string) string {
cf := C.CString(format) cf := C.CString(format)
...@@ -287,6 +304,10 @@ func Mprintf(format string, arg string) string { ...@@ -287,6 +304,10 @@ func Mprintf(format string, arg string) string {
defer C.sqlite3_free(unsafe.Pointer(zSQL)) defer C.sqlite3_free(unsafe.Pointer(zSQL))
return C.GoString(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 { func Mprintf2(format string, arg1, arg2 string) string {
cf := C.CString(format) cf := C.CString(format)
defer C.free(unsafe.Pointer(cf)) defer C.free(unsafe.Pointer(cf))
......
...@@ -170,7 +170,7 @@ type Conn struct { ...@@ -170,7 +170,7 @@ type Conn struct {
udfs map[string]*sqliteFunction udfs map[string]*sqliteFunction
} }
// Run-time library version number // Version returns the run-time library version number
// (See http://sqlite.org/c3ref/libversion.html) // (See http://sqlite.org/c3ref/libversion.html)
func Version() string { func Version() string {
p := C.sqlite3_libversion() p := C.sqlite3_libversion()
...@@ -191,7 +191,7 @@ const ( ...@@ -191,7 +191,7 @@ const (
OpenPrivateCache OpenFlag = C.SQLITE_OPEN_PRIVATECACHE OpenPrivateCache OpenFlag = C.SQLITE_OPEN_PRIVATECACHE
) )
// Open a new database connection. // Open opens a new database connection.
// ":memory:" for memory db // ":memory:" for memory db
// "" for temp file db // "" for temp file db
// //
...@@ -200,7 +200,7 @@ func Open(filename string, flags ...OpenFlag) (*Conn, error) { ...@@ -200,7 +200,7 @@ func Open(filename string, flags ...OpenFlag) (*Conn, error) {
return OpenVfs(filename, "", flags...) 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) { func OpenVfs(filename string, vfsname string, flags ...OpenFlag) (*Conn, error) {
if C.sqlite3_threadsafe() == 0 { if C.sqlite3_threadsafe() == 0 {
return nil, errors.New("sqlite library was not compiled for thread-safe operation") 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) ...@@ -235,7 +235,7 @@ func OpenVfs(filename string, vfsname string, flags ...OpenFlag) (*Conn, error)
return &Conn{db: db, stmtCache: newCache()}, nil return &Conn{db: db, stmtCache: newCache()}, nil
} }
// Set a busy timeout // BusyTimeout sets a busy timeout.
// (See http://sqlite.org/c3ref/busy_timeout.html) // (See http://sqlite.org/c3ref/busy_timeout.html)
func (c *Conn) BusyTimeout(ms int) error { // TODO time.Duration ? func (c *Conn) BusyTimeout(ms int) error { // TODO time.Duration ?
return c.error(C.sqlite3_busy_timeout(c.db, C.int(ms))) return c.error(C.sqlite3_busy_timeout(c.db, C.int(ms)))
...@@ -258,7 +258,7 @@ func (c *Conn) IsFKeyEnabled() (bool, error) { ...@@ -258,7 +258,7 @@ func (c *Conn) IsFKeyEnabled() (bool, error) {
return c.queryOrSetEnableDbConfig(C.SQLITE_DBCONFIG_ENABLE_FKEY, -1) 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) // Calls sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_TRIGGER, b)
// //
// (See http://sqlite.org/c3ref/c_dbconfig_enable_fkey.html) // (See http://sqlite.org/c3ref/c_dbconfig_enable_fkey.html)
...@@ -266,6 +266,7 @@ func (c *Conn) EnableTriggers(b bool) (bool, error) { ...@@ -266,6 +266,7 @@ func (c *Conn) EnableTriggers(b bool) (bool, error) {
return c.queryOrSetEnableDbConfig(C.SQLITE_DBCONFIG_ENABLE_TRIGGER, btocint(b)) 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) // Calls sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_TRIGGER, -1)
// //
// (See http://sqlite.org/c3ref/c_dbconfig_enable_fkey.html) // (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 ...@@ -370,7 +371,7 @@ func (c *Conn) OneValue(query string, value interface{}, args ...interface{}) er
return s.Scan(value) 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. // 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) // (See http://sqlite.org/c3ref/changes.html)
func (c *Conn) Changes() int { func (c *Conn) Changes() int {
...@@ -411,11 +412,14 @@ const ( ...@@ -411,11 +412,14 @@ const (
Exclusive TransactionType = 2 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 { func (c *Conn) Begin() error {
return c.BeginTransaction(Deferred) 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 { func (c *Conn) BeginTransaction(t TransactionType) error {
if t == Deferred { if t == Deferred {
return c.exec("BEGIN") return c.exec("BEGIN")
...@@ -428,13 +432,13 @@ func (c *Conn) BeginTransaction(t TransactionType) error { ...@@ -428,13 +432,13 @@ func (c *Conn) BeginTransaction(t TransactionType) error {
return nil return nil
} }
// Commit transaction // Commit commits transaction
func (c *Conn) Commit() error { func (c *Conn) Commit() error {
// TODO Check autocommit? // TODO Check autocommit?
return c.exec("COMMIT") return c.exec("COMMIT")
} }
// Rollback transaction // Rollback rollbacks transaction
func (c *Conn) Rollback() error { func (c *Conn) Rollback() error {
// TODO Check autocommit? // TODO Check autocommit?
return c.exec("ROLLBACK") return c.exec("ROLLBACK")
...@@ -468,7 +472,7 @@ func (c *Conn) exec(cmd string) error { ...@@ -468,7 +472,7 @@ func (c *Conn) exec(cmd string) error {
return nil 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) // (See http://sqlite.org/c3ref/close.html)
func (c *Conn) Close() error { func (c *Conn) Close() error {
if c == nil { if c == nil {
...@@ -526,7 +530,7 @@ func (c *Conn) LoadExtension(file string, proc ...string) error { ...@@ -526,7 +530,7 @@ func (c *Conn) LoadExtension(file string, proc ...string) error {
return nil return nil
} }
// Enable or disable shared pager cache // EnableSharedCache enables or disables shared pager cache
// (See http://sqlite.org/c3ref/enable_shared_cache.html) // (See http://sqlite.org/c3ref/enable_shared_cache.html)
func EnableSharedCache(b bool) { func EnableSharedCache(b bool) {
C.sqlite3_enable_shared_cache(btocint(b)) C.sqlite3_enable_shared_cache(btocint(b))
......
...@@ -41,7 +41,7 @@ func goXTrace(udp unsafe.Pointer, sql *C.char) { ...@@ -41,7 +41,7 @@ func goXTrace(udp unsafe.Pointer, sql *C.char) {
arg.f(arg.udp, C.GoString(sql)) 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) // (See sqlite3_trace, http://sqlite.org/c3ref/profile.html)
func (c *Conn) Trace(f Tracer, udp interface{}) { func (c *Conn) Trace(f Tracer, udp interface{}) {
if f == nil { if f == nil {
...@@ -68,7 +68,7 @@ func goXProfile(udp unsafe.Pointer, sql *C.char, nanoseconds C.sqlite3_uint64) { ...@@ -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)) 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) // (See sqlite3_profile, http://sqlite.org/c3ref/profile.html)
func (c *Conn) Profile(f Profiler, udp interface{}) { func (c *Conn) Profile(f Profiler, udp interface{}) {
if f == nil { if f == nil {
...@@ -144,7 +144,7 @@ func goXAuth(udp unsafe.Pointer, action int, arg1, arg2, dbName, triggerName *C. ...@@ -144,7 +144,7 @@ func goXAuth(udp unsafe.Pointer, action int, arg1, arg2, dbName, triggerName *C.
return C.int(result) 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) // (See http://sqlite.org/c3ref/set_authorizer.html)
func (c *Conn) SetAuthorizer(f Authorizer, udp interface{}) error { func (c *Conn) SetAuthorizer(f Authorizer, udp interface{}) error {
if f == nil { if f == nil {
...@@ -172,7 +172,7 @@ func goXBusy(udp unsafe.Pointer, count int) C.int { ...@@ -172,7 +172,7 @@ func goXBusy(udp unsafe.Pointer, count int) C.int {
return btocint(result) 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) // (See http://sqlite.org/c3ref/busy_handler.html)
func (c *Conn) BusyHandler(f BusyHandler, udp interface{}) error { func (c *Conn) BusyHandler(f BusyHandler, udp interface{}) error {
if f == nil { if f == nil {
...@@ -200,7 +200,7 @@ func goXProgress(udp unsafe.Pointer) C.int { ...@@ -200,7 +200,7 @@ func goXProgress(udp unsafe.Pointer) C.int {
return btocint(result) return btocint(result)
} }
// Query progress callbacks // ProgressHandler registers or clears a query progress callback.
// The progress callback will be invoked every numOps opcodes. // The progress callback will be invoked every numOps opcodes.
// (See http://sqlite.org/c3ref/progress_handler.html) // (See http://sqlite.org/c3ref/progress_handler.html)
func (c *Conn) ProgressHandler(f ProgressHandler, numOps int, udp interface{}) { func (c *Conn) ProgressHandler(f ProgressHandler, numOps int, udp interface{}) {
...@@ -223,37 +223,37 @@ const ( ...@@ -223,37 +223,37 @@ const (
StmtStatusAutoIndex StmtStatus = C.SQLITE_STMTSTATUS_AUTOINDEX 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) // (See http://sqlite.org/c3ref/stmt_status.html)
func (s *Stmt) Status(op StmtStatus, reset bool) int { func (s *Stmt) Status(op StmtStatus, reset bool) int {
return int(C.sqlite3_stmt_status(s.stmt, C.int(op), btocint(reset))) 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) // (See sqlite3_memory_used: http://sqlite.org/c3ref/memory_highwater.html)
func MemoryUsed() int64 { func MemoryUsed() int64 {
return int64(C.sqlite3_memory_used()) 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) // (See sqlite3_memory_highwater: http://sqlite.org/c3ref/memory_highwater.html)
func MemoryHighwater(reset bool) int64 { func MemoryHighwater(reset bool) int64 {
return int64(C.sqlite3_memory_highwater(btocint(reset))) 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) // (See http://sqlite.org/c3ref/soft_heap_limit64.html)
func SoftHeapLimit() int64 { func SoftHeapLimit() int64 {
return SetSoftHeapLimit(-1) 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) // (See http://sqlite.org/c3ref/soft_heap_limit64.html)
func SetSoftHeapLimit(n int64) int64 { func SetSoftHeapLimit(n int64) int64 {
return int64(C.sqlite3_soft_heap_limit64(C.sqlite3_int64(n))) 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) // (See http://sqlite.org/c3ref/complete.html)
func Complete(sql string) bool { func Complete(sql string) bool {
cs := C.CString(sql) cs := C.CString(sql)
...@@ -261,7 +261,7 @@ func Complete(sql string) bool { ...@@ -261,7 +261,7 @@ func Complete(sql string) bool {
return C.sqlite3_complete(cs) != 0 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) // (See http://sqlite.org/c3ref/log.html)
func Log(err /*Errno*/ int, msg string) { func Log(err /*Errno*/ int, msg string) {
cs := C.CString(msg) cs := C.CString(msg)
...@@ -286,7 +286,9 @@ func goXLog(udp unsafe.Pointer, err int, msg *C.char) { ...@@ -286,7 +286,9 @@ func goXLog(udp unsafe.Pointer, err int, msg *C.char) {
var logger *sqliteLogger 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) // (See sqlite3_config(SQLITE_CONFIG_LOG,...): http://sqlite.org/c3ref/config.html)
func ConfigLog(f Logger, udp interface{}) error { func ConfigLog(f Logger, udp interface{}) error {
var rv C.int var rv C.int
...@@ -312,7 +314,7 @@ const ( ...@@ -312,7 +314,7 @@ const (
Serialized ThreadingMode = C.SQLITE_CONFIG_SERIALIZED 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) // (See sqlite3_config(SQLITE_CONFIG_SINGLETHREAD|SQLITE_CONFIG_MULTITHREAD|SQLITE_CONFIG_SERIALIZED): http://sqlite.org/c3ref/config.html)
func ConfigThreadingMode(mode ThreadingMode) error { func ConfigThreadingMode(mode ThreadingMode) error {
rv := C.goSqlite3ConfigThreadMode(C.int(mode)) rv := C.goSqlite3ConfigThreadMode(C.int(mode))
...@@ -322,7 +324,7 @@ func ConfigThreadingMode(mode ThreadingMode) error { ...@@ -322,7 +324,7 @@ func ConfigThreadingMode(mode ThreadingMode) error {
return Errno(rv) 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) // (See sqlite3_config(SQLITE_CONFIG_MEMSTATUS): http://sqlite.org/c3ref/config.html)
func ConfigMemStatus(b bool) error { func ConfigMemStatus(b bool) error {
rv := C.goSqlite3Config(C.SQLITE_CONFIG_MEMSTATUS, btocint(b)) rv := C.goSqlite3Config(C.SQLITE_CONFIG_MEMSTATUS, btocint(b))
...@@ -332,7 +334,7 @@ func ConfigMemStatus(b bool) error { ...@@ -332,7 +334,7 @@ func ConfigMemStatus(b bool) error {
return Errno(rv) 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) // (See sqlite3_config(SQLITE_CONFIG_URI): http://sqlite.org/c3ref/config.html)
func ConfigUri(b bool) error { func ConfigUri(b bool) error {
rv := C.goSqlite3Config(C.SQLITE_CONFIG_URI, btocint(b)) 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