go vet && golint
This commit is contained in:
parent
a9ad8a09c9
commit
0d1d1a644e
14
backup.go
14
backup.go
|
@ -19,10 +19,12 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// SQLiteBackup implement interface of Backup.
|
||||||
type SQLiteBackup struct {
|
type SQLiteBackup struct {
|
||||||
b *C.sqlite3_backup
|
b *C.sqlite3_backup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Backup make backup from src to dest.
|
||||||
func (c *SQLiteConn) Backup(dest string, conn *SQLiteConn, src string) (*SQLiteBackup, error) {
|
func (c *SQLiteConn) Backup(dest string, conn *SQLiteConn, src string) (*SQLiteBackup, error) {
|
||||||
destptr := C.CString(dest)
|
destptr := C.CString(dest)
|
||||||
defer C.free(unsafe.Pointer(destptr))
|
defer C.free(unsafe.Pointer(destptr))
|
||||||
|
@ -37,10 +39,10 @@ func (c *SQLiteConn) Backup(dest string, conn *SQLiteConn, src string) (*SQLiteB
|
||||||
return nil, c.lastError()
|
return nil, c.lastError()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backs up for one step. Calls the underlying `sqlite3_backup_step` function.
|
// Step to backs up for one step. Calls the underlying `sqlite3_backup_step`
|
||||||
// This function returns a boolean indicating if the backup is done and
|
// function. This function returns a boolean indicating if the backup is done
|
||||||
// an error signalling any other error. Done is returned if the underlying C
|
// and an error signalling any other error. Done is returned if the underlying
|
||||||
// function returns SQLITE_DONE (Code 101)
|
// C function returns SQLITE_DONE (Code 101)
|
||||||
func (b *SQLiteBackup) Step(p int) (bool, error) {
|
func (b *SQLiteBackup) Step(p int) (bool, error) {
|
||||||
ret := C.sqlite3_backup_step(b.b, C.int(p))
|
ret := C.sqlite3_backup_step(b.b, C.int(p))
|
||||||
if ret == C.SQLITE_DONE {
|
if ret == C.SQLITE_DONE {
|
||||||
|
@ -51,18 +53,22 @@ func (b *SQLiteBackup) Step(p int) (bool, error) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remaining return whether have the rest for backup.
|
||||||
func (b *SQLiteBackup) Remaining() int {
|
func (b *SQLiteBackup) Remaining() int {
|
||||||
return int(C.sqlite3_backup_remaining(b.b))
|
return int(C.sqlite3_backup_remaining(b.b))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PageCount return count of pages.
|
||||||
func (b *SQLiteBackup) PageCount() int {
|
func (b *SQLiteBackup) PageCount() int {
|
||||||
return int(C.sqlite3_backup_pagecount(b.b))
|
return int(C.sqlite3_backup_pagecount(b.b))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Finish close backup.
|
||||||
func (b *SQLiteBackup) Finish() error {
|
func (b *SQLiteBackup) Finish() error {
|
||||||
return b.Close()
|
return b.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close close backup.
|
||||||
func (b *SQLiteBackup) Close() error {
|
func (b *SQLiteBackup) Close() error {
|
||||||
ret := C.sqlite3_backup_finish(b.b)
|
ret := C.sqlite3_backup_finish(b.b)
|
||||||
|
|
||||||
|
|
1
error.go
1
error.go
|
@ -7,6 +7,7 @@ package sqlite3
|
||||||
|
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
|
// ErrNo inherit errno.
|
||||||
type ErrNo int
|
type ErrNo int
|
||||||
|
|
||||||
const ErrNoMask C.int = 0xff
|
const ErrNoMask C.int = 0xff
|
||||||
|
|
50
sqlite3.go
50
sqlite3.go
|
@ -118,10 +118,10 @@ import (
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Timestamp formats understood by both this module and SQLite.
|
// SQLiteTimestampFormats is timestamp formats understood by both this module
|
||||||
// The first format in the slice will be used when saving time values
|
// and SQLite. The first format in the slice will be used when saving time
|
||||||
// into the database. When parsing a string from a timestamp or
|
// values into the database. When parsing a string from a timestamp or datetime
|
||||||
// datetime column, the formats are tried in order.
|
// column, the formats are tried in order.
|
||||||
var SQLiteTimestampFormats = []string{
|
var SQLiteTimestampFormats = []string{
|
||||||
// By default, store timestamps with whatever timezone they come with.
|
// By default, store timestamps with whatever timezone they come with.
|
||||||
// When parsed, they will be returned with the same timezone.
|
// When parsed, they will be returned with the same timezone.
|
||||||
|
@ -141,20 +141,20 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version returns SQLite library version information.
|
// Version returns SQLite library version information.
|
||||||
func Version() (libVersion string, libVersionNumber int, sourceId string) {
|
func Version() (libVersion string, libVersionNumber int, sourceID string) {
|
||||||
libVersion = C.GoString(C.sqlite3_libversion())
|
libVersion = C.GoString(C.sqlite3_libversion())
|
||||||
libVersionNumber = int(C.sqlite3_libversion_number())
|
libVersionNumber = int(C.sqlite3_libversion_number())
|
||||||
sourceId = C.GoString(C.sqlite3_sourceid())
|
sourceID = C.GoString(C.sqlite3_sourceid())
|
||||||
return libVersion, libVersionNumber, sourceId
|
return libVersion, libVersionNumber, sourceID
|
||||||
}
|
}
|
||||||
|
|
||||||
// Driver struct.
|
// SQLiteDriver implement sql.Driver.
|
||||||
type SQLiteDriver struct {
|
type SQLiteDriver struct {
|
||||||
Extensions []string
|
Extensions []string
|
||||||
ConnectHook func(*SQLiteConn) error
|
ConnectHook func(*SQLiteConn) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Conn struct.
|
// SQLiteConn implement sql.Conn.
|
||||||
type SQLiteConn struct {
|
type SQLiteConn struct {
|
||||||
db *C.sqlite3
|
db *C.sqlite3
|
||||||
loc *time.Location
|
loc *time.Location
|
||||||
|
@ -163,12 +163,12 @@ type SQLiteConn struct {
|
||||||
aggregators []*aggInfo
|
aggregators []*aggInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tx struct.
|
// SQLiteTx implemen sql.Tx.
|
||||||
type SQLiteTx struct {
|
type SQLiteTx struct {
|
||||||
c *SQLiteConn
|
c *SQLiteConn
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stmt struct.
|
// SQLiteStmt implement sql.Stmt.
|
||||||
type SQLiteStmt struct {
|
type SQLiteStmt struct {
|
||||||
c *SQLiteConn
|
c *SQLiteConn
|
||||||
s *C.sqlite3_stmt
|
s *C.sqlite3_stmt
|
||||||
|
@ -177,13 +177,13 @@ type SQLiteStmt struct {
|
||||||
cls bool
|
cls bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Result struct.
|
// SQLiteResult implement sql.Result.
|
||||||
type SQLiteResult struct {
|
type SQLiteResult struct {
|
||||||
id int64
|
id int64
|
||||||
changes int64
|
changes int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rows struct.
|
// SQLiteRows implement sql.Rows.
|
||||||
type SQLiteRows struct {
|
type SQLiteRows struct {
|
||||||
s *SQLiteStmt
|
s *SQLiteStmt
|
||||||
nc int
|
nc int
|
||||||
|
@ -401,7 +401,7 @@ func (c *SQLiteConn) lastError() Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements Execer
|
// Exec implements Execer.
|
||||||
func (c *SQLiteConn) Exec(query string, args []driver.Value) (driver.Result, error) {
|
func (c *SQLiteConn) Exec(query string, args []driver.Value) (driver.Result, error) {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return c.execQuery(query)
|
return c.execQuery(query)
|
||||||
|
@ -456,7 +456,7 @@ type namedValue struct {
|
||||||
Value driver.Value
|
Value driver.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements Queryer
|
// Query implements Queryer.
|
||||||
func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, error) {
|
func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, error) {
|
||||||
list := make([]namedValue, len(args))
|
list := make([]namedValue, len(args))
|
||||||
for i, v := range args {
|
for i, v := range args {
|
||||||
|
@ -549,7 +549,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
|
||||||
|
|
||||||
var loc *time.Location
|
var loc *time.Location
|
||||||
txlock := "BEGIN"
|
txlock := "BEGIN"
|
||||||
busy_timeout := 5000
|
busyTimeout := 5000
|
||||||
pos := strings.IndexRune(dsn, '?')
|
pos := strings.IndexRune(dsn, '?')
|
||||||
if pos >= 1 {
|
if pos >= 1 {
|
||||||
params, err := url.ParseQuery(dsn[pos+1:])
|
params, err := url.ParseQuery(dsn[pos+1:])
|
||||||
|
@ -575,7 +575,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Invalid _busy_timeout: %v: %v", val, err)
|
return nil, fmt.Errorf("Invalid _busy_timeout: %v: %v", val, err)
|
||||||
}
|
}
|
||||||
busy_timeout = int(iv)
|
busyTimeout = int(iv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// _txlock
|
// _txlock
|
||||||
|
@ -612,7 +612,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
|
||||||
return nil, errors.New("sqlite succeeded without returning a database")
|
return nil, errors.New("sqlite succeeded without returning a database")
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = C.sqlite3_busy_timeout(db, C.int(busy_timeout))
|
rv = C.sqlite3_busy_timeout(db, C.int(busyTimeout))
|
||||||
if rv != C.SQLITE_OK {
|
if rv != C.SQLITE_OK {
|
||||||
return nil, Error{Code: ErrNo(rv)}
|
return nil, Error{Code: ErrNo(rv)}
|
||||||
}
|
}
|
||||||
|
@ -686,7 +686,7 @@ func (s *SQLiteStmt) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a number of parameters.
|
// NumInput return a number of parameters.
|
||||||
func (s *SQLiteStmt) NumInput() int {
|
func (s *SQLiteStmt) NumInput() int {
|
||||||
return int(C.sqlite3_bind_parameter_count(s.s))
|
return int(C.sqlite3_bind_parameter_count(s.s))
|
||||||
}
|
}
|
||||||
|
@ -769,17 +769,17 @@ func (s *SQLiteStmt) query(ctx context.Context, args []namedValue) (driver.Rows,
|
||||||
return &SQLiteRows{s, int(C.sqlite3_column_count(s.s)), nil, nil, s.cls}, nil
|
return &SQLiteRows{s, int(C.sqlite3_column_count(s.s)), nil, nil, s.cls}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return last inserted ID.
|
// LastInsertId teturn last inserted ID.
|
||||||
func (r *SQLiteResult) LastInsertId() (int64, error) {
|
func (r *SQLiteResult) LastInsertId() (int64, error) {
|
||||||
return r.id, nil
|
return r.id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return how many rows affected.
|
// RowsAffected return how many rows affected.
|
||||||
func (r *SQLiteResult) RowsAffected() (int64, error) {
|
func (r *SQLiteResult) RowsAffected() (int64, error) {
|
||||||
return r.changes, nil
|
return r.changes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute the statement with arguments. Return result object.
|
// Exec execute the statement with arguments. Return result object.
|
||||||
func (s *SQLiteStmt) Exec(args []driver.Value) (driver.Result, error) {
|
func (s *SQLiteStmt) Exec(args []driver.Value) (driver.Result, error) {
|
||||||
list := make([]namedValue, len(args))
|
list := make([]namedValue, len(args))
|
||||||
for i, v := range args {
|
for i, v := range args {
|
||||||
|
@ -823,7 +823,7 @@ func (rc *SQLiteRows) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return column names.
|
// Columns return column names.
|
||||||
func (rc *SQLiteRows) Columns() []string {
|
func (rc *SQLiteRows) Columns() []string {
|
||||||
if rc.nc != len(rc.cols) {
|
if rc.nc != len(rc.cols) {
|
||||||
rc.cols = make([]string, rc.nc)
|
rc.cols = make([]string, rc.nc)
|
||||||
|
@ -834,7 +834,7 @@ func (rc *SQLiteRows) Columns() []string {
|
||||||
return rc.cols
|
return rc.cols
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return column types.
|
// DeclTypes return column types.
|
||||||
func (rc *SQLiteRows) DeclTypes() []string {
|
func (rc *SQLiteRows) DeclTypes() []string {
|
||||||
if rc.decltype == nil {
|
if rc.decltype == nil {
|
||||||
rc.decltype = make([]string, rc.nc)
|
rc.decltype = make([]string, rc.nc)
|
||||||
|
@ -845,7 +845,7 @@ func (rc *SQLiteRows) DeclTypes() []string {
|
||||||
return rc.decltype
|
return rc.decltype
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move cursor to next.
|
// Next move cursor to next.
|
||||||
func (rc *SQLiteRows) Next(dest []driver.Value) error {
|
func (rc *SQLiteRows) Next(dest []driver.Value) error {
|
||||||
rv := C.sqlite3_step(rc.s.s)
|
rv := C.sqlite3_step(rc.s.s)
|
||||||
if rv == C.SQLITE_DONE {
|
if rv == C.SQLITE_DONE {
|
||||||
|
|
|
@ -17,6 +17,7 @@ func (c *SQLiteConn) Ping(ctx context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QueryContext implement QueryerContext.
|
||||||
func (c *SQLiteConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
|
func (c *SQLiteConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
|
||||||
list := make([]namedValue, len(args))
|
list := make([]namedValue, len(args))
|
||||||
for i, nv := range args {
|
for i, nv := range args {
|
||||||
|
@ -25,6 +26,7 @@ func (c *SQLiteConn) QueryContext(ctx context.Context, query string, args []driv
|
||||||
return c.query(ctx, query, list)
|
return c.query(ctx, query, list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExecContext implement ExecerContext.
|
||||||
func (c *SQLiteConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
|
func (c *SQLiteConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
|
||||||
list := make([]namedValue, len(args))
|
list := make([]namedValue, len(args))
|
||||||
for i, nv := range args {
|
for i, nv := range args {
|
||||||
|
@ -33,14 +35,17 @@ func (c *SQLiteConn) ExecContext(ctx context.Context, query string, args []drive
|
||||||
return c.exec(ctx, query, list)
|
return c.exec(ctx, query, list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PrepareContext implement ConnPrepareContext.
|
||||||
func (c *SQLiteConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) {
|
func (c *SQLiteConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) {
|
||||||
return c.prepare(ctx, query)
|
return c.prepare(ctx, query)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BeginContext implement ConnBeginContext.
|
||||||
func (c *SQLiteConn) BeginContext(ctx context.Context) (driver.Tx, error) {
|
func (c *SQLiteConn) BeginContext(ctx context.Context) (driver.Tx, error) {
|
||||||
return c.begin(ctx)
|
return c.begin(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QueryContext implement QueryerContext.
|
||||||
func (s *SQLiteStmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) {
|
func (s *SQLiteStmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) {
|
||||||
list := make([]namedValue, len(args))
|
list := make([]namedValue, len(args))
|
||||||
for i, nv := range args {
|
for i, nv := range args {
|
||||||
|
@ -49,6 +54,7 @@ func (s *SQLiteStmt) QueryContext(ctx context.Context, args []driver.NamedValue)
|
||||||
return s.query(ctx, list)
|
return s.query(ctx, list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExecContext implement ExecerContext.
|
||||||
func (s *SQLiteStmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) {
|
func (s *SQLiteStmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) {
|
||||||
list := make([]namedValue, len(args))
|
list := make([]namedValue, len(args))
|
||||||
for i, nv := range args {
|
for i, nv := range args {
|
||||||
|
|
|
@ -42,6 +42,7 @@ func (c *SQLiteConn) loadExtensions(extensions []string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadExtension load the sqlite3 extension.
|
||||||
func (c *SQLiteConn) LoadExtension(lib string, entry string) error {
|
func (c *SQLiteConn) LoadExtension(lib string, entry string) error {
|
||||||
rv := C.sqlite3_enable_load_extension(c.db, 1)
|
rv := C.sqlite3_enable_load_extension(c.db, 1)
|
||||||
if rv != C.SQLITE_OK {
|
if rv != C.SQLITE_OK {
|
||||||
|
|
|
@ -4,6 +4,7 @@ package sqlite3
|
||||||
|
|
||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
|
// RegisterAggregator register the aggregator.
|
||||||
func (c *SQLiteConn) RegisterAggregator(name string, impl interface{}, pure bool) error {
|
func (c *SQLiteConn) RegisterAggregator(name string, impl interface{}, pure bool) error {
|
||||||
return errors.New("This feature is not implemented")
|
return errors.New("This feature is not implemented")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue