Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gosqlite
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gosqlite
Commits
b5ce2308
Commit
b5ce2308
authored
Nov 29, 2011
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some doc.
parent
da7e25e1
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
10 deletions
+80
-10
backup.go
backup.go
+4
-1
blob.go
blob.go
+9
-0
hook.go
hook.go
+3
-0
sqlite.go
sqlite.go
+48
-6
trace.go
trace.go
+16
-3
No files found.
backup.go
View file @
b5ce2308
...
...
@@ -45,12 +45,13 @@ func NewBackup(dst *Conn, dstDbName string, src *Conn, srcDbName string) (*Backu
return
&
Backup
{
sb
,
dst
,
src
},
nil
}
//
Encapsulates backup API
//
Online backup
type
Backup
struct
{
sb
*
C
.
sqlite3_backup
dst
,
src
*
Conn
}
// Copy up to N pages between the source and destination databases
// Calls http://sqlite.org/c3ref/backup_finish.html#sqlite3backupstep
func
(
b
*
Backup
)
Step
(
npage
int
)
error
{
rv
:=
C
.
sqlite3_backup_step
(
b
.
sb
,
C
.
int
(
npage
))
...
...
@@ -66,6 +67,7 @@ type BackupStatus struct {
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
func
(
b
*
Backup
)
Status
()
BackupStatus
{
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 {
return
b
.
dst
.
error
(
C
.
sqlite3_errcode
(
b
.
dst
.
db
))
}
// Finish/stop the backup
// Calls http://sqlite.org/c3ref/backup_finish.html#sqlite3backupfinish
func
(
b
*
Backup
)
Close
()
error
{
if
b
.
sb
==
nil
{
...
...
blob.go
View file @
b5ce2308
...
...
@@ -17,12 +17,14 @@ import (
"unsafe"
)
// Reader adapter to BLOB
type
BlobReader
struct
{
c
*
Conn
bl
*
C
.
sqlite3_blob
ReadOffset
int
}
// ReadWriter adapter to BLOB
type
BlobReadWriter
struct
{
BlobReader
WriteOffset
int
...
...
@@ -38,6 +40,7 @@ type BlobReadWriter struct {
// // check err
type
ZeroBlobLength
int
// Open a BLOB for incremental I/O
// Example:
// br, err := db.NewBlobReader("db_name", "table_name", "column_name", rowid)
// // check err
...
...
@@ -57,6 +60,7 @@ func (c *Conn) NewBlobReader(db, table, column string, row int64) (*BlobReader,
return
&
BlobReader
{
c
,
bl
,
0
},
nil
}
// Open a BLOB For incremental I/O
// Calls 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
)
...
...
@@ -87,6 +91,7 @@ func (c *Conn) blob_open(db, table, column string, row int64, write bool) (*C.sq
return
bl
,
nil
}
// Close a BLOB handle
// Calls http://sqlite.org/c3ref/blob_close.html
func
(
r
*
BlobReader
)
Close
()
error
{
rv
:=
C
.
sqlite3_blob_close
(
r
.
bl
)
...
...
@@ -97,6 +102,7 @@ func (r *BlobReader) Close() error {
return
nil
}
// Read data from a BLOB incrementally
// Calls http://sqlite.org/c3ref/blob_read.html
func
(
r
*
BlobReader
)
Read
(
v
[]
byte
)
(
int
,
error
)
{
var
p
*
byte
...
...
@@ -111,12 +117,14 @@ func (r *BlobReader) Read(v []byte) (int, error) {
return
len
(
v
),
nil
}
// Return the size of an open BLOB
// Calls http://sqlite.org/c3ref/blob_bytes.html
func
(
r
*
BlobReader
)
Size
()
(
int
,
error
)
{
s
:=
C
.
sqlite3_blob_bytes
(
r
.
bl
)
return
int
(
s
),
nil
}
// Write data into a BLOB incrementally
// Calls http://sqlite.org/c3ref/blob_write.html
func
(
w
*
BlobReadWriter
)
Write
(
v
[]
byte
)
(
int
,
error
)
{
var
p
*
byte
...
...
@@ -131,6 +139,7 @@ func (w *BlobReadWriter) Write(v []byte) (int, error) {
return
len
(
v
),
nil
}
// Move a BLOB handle to a new row
// Calls 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
))
...
...
hook.go
View file @
b5ce2308
...
...
@@ -47,6 +47,7 @@ func goXCommitHook(udp unsafe.Pointer) C.int {
return
C
.
int
(
arg
.
f
(
arg
.
udp
))
}
// Commit notification callback
// Calls http://sqlite.org/c3ref/commit_hook.html
func
(
c
*
Conn
)
CommitHook
(
f
CommitHook
,
udp
interface
{})
{
if
f
==
nil
{
...
...
@@ -72,6 +73,7 @@ func goXRollbackHook(udp unsafe.Pointer) {
arg
.
f
(
arg
.
udp
)
}
// Rollback notification callback
// Calls http://sqlite.org/c3ref/commit_hook.html
func
(
c
*
Conn
)
RollbackHook
(
f
RollbackHook
,
udp
interface
{})
{
if
f
==
nil
{
...
...
@@ -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
))
}
// Data change notification callbacks
// Calls http://sqlite.org/c3ref/update_hook.html
func
(
c
*
Conn
)
UpdateHook
(
f
UpdateHook
,
udp
interface
{})
{
if
f
==
nil
{
...
...
sqlite.go
View file @
b5ce2308
This diff is collapsed.
Click to expand it.
trace.go
View file @
b5ce2308
...
...
@@ -72,6 +72,7 @@ func goXTrace(udp unsafe.Pointer, sql *C.char) {
arg
.
f
(
arg
.
udp
,
C
.
GoString
(
sql
))
}
// Tracing function
// Calls sqlite3_trace, http://sqlite.org/c3ref/profile.html
func
(
c
*
Conn
)
Trace
(
f
Tracer
,
udp
interface
{})
{
if
f
==
nil
{
...
...
@@ -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
))
}
// Profiling Function
// Calls sqlite3_profile, http://sqlite.org/c3ref/profile.html
func
(
c
*
Conn
)
Profile
(
f
Profiler
,
udp
interface
{})
{
if
f
==
nil
{
...
...
@@ -110,7 +112,7 @@ func (c *Conn) Profile(f Profiler, udp interface{}) {
C
.
goSqlite3Profile
(
c
.
db
,
unsafe
.
Pointer
(
c
.
profile
))
}
//
See Authorizer
//
Authorizer return codes
type
Auth
int
const
(
...
...
@@ -119,7 +121,7 @@ const (
AUTH_IGNORE
Auth
=
C
.
SQLITE_IGNORE
)
//
See Authorizer
//
Authorizer action codes
type
Action
int
const
(
...
...
@@ -173,6 +175,7 @@ func goXAuth(udp unsafe.Pointer, action C.int, arg1, arg2, dbName, triggerName *
return
C
.
int
(
result
)
}
// Compile-time authorization callbacks
// Calls http://sqlite.org/c3ref/set_authorizer.html
func
(
c
*
Conn
)
SetAuthorizer
(
f
Authorizer
,
udp
interface
{})
error
{
if
f
==
nil
{
...
...
@@ -199,6 +202,7 @@ func goXBusy(udp unsafe.Pointer, count C.int) C.int {
return
C
.
int
(
result
)
}
// Register a callback to handle SQLITE_BUSY errors
// TODO NOT TESTED
// Calls http://sqlite.org/c3ref/busy_handler.html
func
(
c
*
Conn
)
BusyHandler
(
f
BusyHandler
,
udp
interface
{})
error
{
...
...
@@ -227,6 +231,7 @@ func goXProgress(udp unsafe.Pointer) C.int {
return
C
.
int
(
result
)
}
// Query progress callbacks
// Calls http://sqlite.org/c3ref/progress_handler.html
func
(
c
*
Conn
)
ProgressHandler
(
f
ProgressHandler
,
numOps
int
,
udp
interface
{})
{
if
f
==
nil
{
...
...
@@ -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
))
}
// S
ee Stmt.Statu
s
// S
tatus parameters for prepared statement
s
type
StmtStatus
int
const
(
...
...
@@ -248,29 +253,35 @@ const (
STMTSTATUS_AUTOINDEX
StmtStatus
=
C
.
SQLITE_STMTSTATUS_AUTOINDEX
)
// Prepared statement status
// Calls 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
// Calls sqlite3_memory_used: http://sqlite.org/c3ref/memory_highwater.html
func
MemoryUsed
()
int64
{
return
int64
(
C
.
sqlite3_memory_used
())
}
// Memory allocator statistics
// Calls 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
// Calls http://sqlite.org/c3ref/soft_heap_limit64.html
func
SoftHeapLimit
()
int64
{
return
SetSoftHeapLimit
(
-
1
)
}
// Impose a limit on heap size
// Calls 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
// Calls http://sqlite.org/c3ref/complete.html
func
Complete
(
sql
string
)
bool
{
cs
:=
C
.
CString
(
sql
)
...
...
@@ -278,6 +289,7 @@ func Complete(sql string) bool {
return
C
.
sqlite3_complete
(
cs
)
!=
0
}
// Error logging interface
// Calls http://sqlite.org/c3ref/log.html
func
Log
(
err
/*Errno*/
int
,
msg
string
)
{
cs
:=
C
.
CString
(
msg
)
...
...
@@ -302,6 +314,7 @@ func goXLog(udp unsafe.Pointer, err C.int, msg *C.char) {
var
logger
*
sqliteLogger
// Configuring the logger of the SQLite library
// Calls sqlite3_config(SQLITE_CONFIG_LOG,...)
func
ConfigLog
(
f
Logger
,
udp
interface
{})
error
{
var
rv
C
.
int
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment