Commit b5ce2308 authored by gwenn's avatar gwenn

Add some doc.

parent da7e25e1
...@@ -45,12 +45,13 @@ func NewBackup(dst *Conn, dstDbName string, src *Conn, srcDbName string) (*Backu ...@@ -45,12 +45,13 @@ func NewBackup(dst *Conn, dstDbName string, src *Conn, srcDbName string) (*Backu
return &Backup{sb, dst, src}, nil return &Backup{sb, dst, src}, nil
} }
// Encapsulates backup API // Online backup
type Backup struct { type Backup struct {
sb *C.sqlite3_backup sb *C.sqlite3_backup
dst, src *Conn dst, src *Conn
} }
// Copy up to N pages between the source and destination databases
// Calls http://sqlite.org/c3ref/backup_finish.html#sqlite3backupstep // Calls http://sqlite.org/c3ref/backup_finish.html#sqlite3backupstep
func (b *Backup) Step(npage int) error { func (b *Backup) Step(npage int) error {
rv := C.sqlite3_backup_step(b.sb, C.int(npage)) rv := C.sqlite3_backup_step(b.sb, C.int(npage))
...@@ -66,6 +67,7 @@ type BackupStatus struct { ...@@ -66,6 +67,7 @@ type BackupStatus struct {
PageCount int PageCount int
} }
// Return the number of pages still to be backed up and the total number of pages in the source database file.
// Calls http://sqlite.org/c3ref/backup_finish.html#sqlite3backupremaining // Calls http://sqlite.org/c3ref/backup_finish.html#sqlite3backupremaining
func (b *Backup) Status() BackupStatus { 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))}
...@@ -89,6 +91,7 @@ func (b *Backup) Run(npage int, sleepNs int64, c chan<- BackupStatus) error { ...@@ -89,6 +91,7 @@ func (b *Backup) Run(npage int, sleepNs int64, c chan<- BackupStatus) error {
return b.dst.error(C.sqlite3_errcode(b.dst.db)) return b.dst.error(C.sqlite3_errcode(b.dst.db))
} }
// Finish/stop the backup
// Calls http://sqlite.org/c3ref/backup_finish.html#sqlite3backupfinish // Calls http://sqlite.org/c3ref/backup_finish.html#sqlite3backupfinish
func (b *Backup) Close() error { func (b *Backup) Close() error {
if b.sb == nil { if b.sb == nil {
......
...@@ -17,12 +17,14 @@ import ( ...@@ -17,12 +17,14 @@ import (
"unsafe" "unsafe"
) )
// Reader adapter to BLOB
type BlobReader struct { type BlobReader struct {
c *Conn c *Conn
bl *C.sqlite3_blob bl *C.sqlite3_blob
ReadOffset int ReadOffset int
} }
// ReadWriter adapter to BLOB
type BlobReadWriter struct { type BlobReadWriter struct {
BlobReader BlobReader
WriteOffset int WriteOffset int
...@@ -38,6 +40,7 @@ type BlobReadWriter struct { ...@@ -38,6 +40,7 @@ type BlobReadWriter struct {
// // check err // // check err
type ZeroBlobLength int type ZeroBlobLength int
// Open a BLOB for incremental I/O
// Example: // Example:
// br, err := db.NewBlobReader("db_name", "table_name", "column_name", rowid) // br, err := db.NewBlobReader("db_name", "table_name", "column_name", rowid)
// // check err // // check err
...@@ -57,6 +60,7 @@ func (c *Conn) NewBlobReader(db, table, column string, row int64) (*BlobReader, ...@@ -57,6 +60,7 @@ func (c *Conn) NewBlobReader(db, table, column string, row int64) (*BlobReader,
return &BlobReader{c, bl, 0}, nil return &BlobReader{c, bl, 0}, nil
} }
// Open a BLOB For incremental I/O
// Calls http://sqlite.org/c3ref/blob_open.html // Calls 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)
...@@ -87,6 +91,7 @@ func (c *Conn) blob_open(db, table, column string, row int64, write bool) (*C.sq ...@@ -87,6 +91,7 @@ func (c *Conn) blob_open(db, table, column string, row int64, write bool) (*C.sq
return bl, nil return bl, nil
} }
// Close a BLOB handle
// Calls http://sqlite.org/c3ref/blob_close.html // Calls http://sqlite.org/c3ref/blob_close.html
func (r *BlobReader) Close() error { func (r *BlobReader) Close() error {
rv := C.sqlite3_blob_close(r.bl) rv := C.sqlite3_blob_close(r.bl)
...@@ -97,6 +102,7 @@ func (r *BlobReader) Close() error { ...@@ -97,6 +102,7 @@ func (r *BlobReader) Close() error {
return nil return nil
} }
// Read data from a BLOB incrementally
// Calls http://sqlite.org/c3ref/blob_read.html // Calls http://sqlite.org/c3ref/blob_read.html
func (r *BlobReader) Read(v []byte) (int, error) { func (r *BlobReader) Read(v []byte) (int, error) {
var p *byte var p *byte
...@@ -111,12 +117,14 @@ func (r *BlobReader) Read(v []byte) (int, error) { ...@@ -111,12 +117,14 @@ func (r *BlobReader) Read(v []byte) (int, error) {
return len(v), nil return len(v), nil
} }
// Return the size of an open BLOB
// Calls http://sqlite.org/c3ref/blob_bytes.html // Calls http://sqlite.org/c3ref/blob_bytes.html
func (r *BlobReader) Size() (int, error) { func (r *BlobReader) Size() (int, error) {
s := C.sqlite3_blob_bytes(r.bl) s := C.sqlite3_blob_bytes(r.bl)
return int(s), nil return int(s), nil
} }
// Write data into a BLOB incrementally
// Calls http://sqlite.org/c3ref/blob_write.html // Calls http://sqlite.org/c3ref/blob_write.html
func (w *BlobReadWriter) Write(v []byte) (int, error) { func (w *BlobReadWriter) Write(v []byte) (int, error) {
var p *byte var p *byte
...@@ -131,6 +139,7 @@ func (w *BlobReadWriter) Write(v []byte) (int, error) { ...@@ -131,6 +139,7 @@ func (w *BlobReadWriter) Write(v []byte) (int, error) {
return len(v), nil return len(v), nil
} }
// Move a BLOB handle to a new row
// Calls http://sqlite.org/c3ref/blob_reopen.html // Calls 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))
......
...@@ -47,6 +47,7 @@ func goXCommitHook(udp unsafe.Pointer) C.int { ...@@ -47,6 +47,7 @@ func goXCommitHook(udp unsafe.Pointer) C.int {
return C.int(arg.f(arg.udp)) return C.int(arg.f(arg.udp))
} }
// Commit notification callback
// Calls http://sqlite.org/c3ref/commit_hook.html // Calls 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 {
...@@ -72,6 +73,7 @@ func goXRollbackHook(udp unsafe.Pointer) { ...@@ -72,6 +73,7 @@ func goXRollbackHook(udp unsafe.Pointer) {
arg.f(arg.udp) arg.f(arg.udp)
} }
// Rollback notification callback
// Calls http://sqlite.org/c3ref/commit_hook.html // Calls 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 {
...@@ -97,6 +99,7 @@ func goXUpdateHook(udp unsafe.Pointer, action C.int, dbName, tableName *C.char, ...@@ -97,6 +99,7 @@ func goXUpdateHook(udp unsafe.Pointer, action C.int, dbName, tableName *C.char,
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))
} }
// Data change notification callbacks
// Calls http://sqlite.org/c3ref/update_hook.html // Calls 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 {
......
This diff is collapsed.
...@@ -72,6 +72,7 @@ func goXTrace(udp unsafe.Pointer, sql *C.char) { ...@@ -72,6 +72,7 @@ func goXTrace(udp unsafe.Pointer, sql *C.char) {
arg.f(arg.udp, C.GoString(sql)) arg.f(arg.udp, C.GoString(sql))
} }
// Tracing function
// Calls sqlite3_trace, http://sqlite.org/c3ref/profile.html // Calls 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 {
...@@ -98,6 +99,7 @@ func goXProfile(udp unsafe.Pointer, sql *C.char, nanoseconds C.sqlite3_uint64) { ...@@ -98,6 +99,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))
} }
// Profiling Function
// Calls sqlite3_profile, http://sqlite.org/c3ref/profile.html // Calls 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 {
...@@ -110,7 +112,7 @@ func (c *Conn) Profile(f Profiler, udp interface{}) { ...@@ -110,7 +112,7 @@ func (c *Conn) Profile(f Profiler, udp interface{}) {
C.goSqlite3Profile(c.db, unsafe.Pointer(c.profile)) C.goSqlite3Profile(c.db, unsafe.Pointer(c.profile))
} }
// See Authorizer // Authorizer return codes
type Auth int type Auth int
const ( const (
...@@ -119,7 +121,7 @@ const ( ...@@ -119,7 +121,7 @@ const (
AUTH_IGNORE Auth = C.SQLITE_IGNORE AUTH_IGNORE Auth = C.SQLITE_IGNORE
) )
// See Authorizer // Authorizer action codes
type Action int type Action int
const ( const (
...@@ -173,6 +175,7 @@ func goXAuth(udp unsafe.Pointer, action C.int, arg1, arg2, dbName, triggerName * ...@@ -173,6 +175,7 @@ func goXAuth(udp unsafe.Pointer, action C.int, arg1, arg2, dbName, triggerName *
return C.int(result) return C.int(result)
} }
// Compile-time authorization callbacks
// Calls http://sqlite.org/c3ref/set_authorizer.html // Calls 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 {
...@@ -199,6 +202,7 @@ func goXBusy(udp unsafe.Pointer, count C.int) C.int { ...@@ -199,6 +202,7 @@ func goXBusy(udp unsafe.Pointer, count C.int) C.int {
return C.int(result) return C.int(result)
} }
// Register a callback to handle SQLITE_BUSY errors
// TODO NOT TESTED // TODO NOT TESTED
// Calls http://sqlite.org/c3ref/busy_handler.html // Calls 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 {
...@@ -227,6 +231,7 @@ func goXProgress(udp unsafe.Pointer) C.int { ...@@ -227,6 +231,7 @@ func goXProgress(udp unsafe.Pointer) C.int {
return C.int(result) return C.int(result)
} }
// Query progress callbacks
// Calls http://sqlite.org/c3ref/progress_handler.html // Calls 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{}) {
if f == nil { if f == nil {
...@@ -239,7 +244,7 @@ func (c *Conn) ProgressHandler(f ProgressHandler, numOps int, udp interface{}) { ...@@ -239,7 +244,7 @@ func (c *Conn) ProgressHandler(f ProgressHandler, numOps int, udp interface{}) {
C.goSqlite3ProgressHandler(c.db, C.int(numOps), unsafe.Pointer(c.progressHandler)) C.goSqlite3ProgressHandler(c.db, C.int(numOps), unsafe.Pointer(c.progressHandler))
} }
// See Stmt.Status // Status parameters for prepared statements
type StmtStatus int type StmtStatus int
const ( const (
...@@ -248,29 +253,35 @@ const ( ...@@ -248,29 +253,35 @@ const (
STMTSTATUS_AUTOINDEX StmtStatus = C.SQLITE_STMTSTATUS_AUTOINDEX STMTSTATUS_AUTOINDEX StmtStatus = C.SQLITE_STMTSTATUS_AUTOINDEX
) )
// Prepared statement status
// Calls http://sqlite.org/c3ref/stmt_status.html // Calls 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
// Calls sqlite3_memory_used: http://sqlite.org/c3ref/memory_highwater.html // Calls 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
// Calls sqlite3_memory_highwater: http://sqlite.org/c3ref/memory_highwater.html // Calls 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
// Calls http://sqlite.org/c3ref/soft_heap_limit64.html // Calls 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
// Calls http://sqlite.org/c3ref/soft_heap_limit64.html // Calls 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
// Calls http://sqlite.org/c3ref/complete.html // Calls http://sqlite.org/c3ref/complete.html
func Complete(sql string) bool { func Complete(sql string) bool {
cs := C.CString(sql) cs := C.CString(sql)
...@@ -278,6 +289,7 @@ func Complete(sql string) bool { ...@@ -278,6 +289,7 @@ func Complete(sql string) bool {
return C.sqlite3_complete(cs) != 0 return C.sqlite3_complete(cs) != 0
} }
// Error logging interface
// Calls http://sqlite.org/c3ref/log.html // Calls 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)
...@@ -302,6 +314,7 @@ func goXLog(udp unsafe.Pointer, err C.int, msg *C.char) { ...@@ -302,6 +314,7 @@ func goXLog(udp unsafe.Pointer, err C.int, msg *C.char) {
var logger *sqliteLogger var logger *sqliteLogger
// Configuring the logger of the SQLite library
// Calls sqlite3_config(SQLITE_CONFIG_LOG,...) // Calls sqlite3_config(SQLITE_CONFIG_LOG,...)
func ConfigLog(f Logger, udp interface{}) error { func ConfigLog(f Logger, udp interface{}) error {
var rv C.int var rv C.int
......
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