go vet && golint

csv
Yasuhiro Matsumoto 2016-11-05 00:40:06 +09:00
parent a9ad8a09c9
commit 0d1d1a644e
6 changed files with 44 additions and 29 deletions

View File

@ -19,10 +19,12 @@ import (
"unsafe"
)
// SQLiteBackup implement interface of Backup.
type SQLiteBackup struct {
b *C.sqlite3_backup
}
// Backup make backup from src to dest.
func (c *SQLiteConn) Backup(dest string, conn *SQLiteConn, src string) (*SQLiteBackup, error) {
destptr := C.CString(dest)
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()
}
// Backs up for one step. Calls the underlying `sqlite3_backup_step` function.
// This function returns a boolean indicating if the backup is done and
// an error signalling any other error. Done is returned if the underlying C
// function returns SQLITE_DONE (Code 101)
// Step to backs up for one step. Calls the underlying `sqlite3_backup_step`
// function. This function returns a boolean indicating if the backup is done
// and an error signalling any other error. Done is returned if the underlying
// C function returns SQLITE_DONE (Code 101)
func (b *SQLiteBackup) Step(p int) (bool, error) {
ret := C.sqlite3_backup_step(b.b, C.int(p))
if ret == C.SQLITE_DONE {
@ -51,18 +53,22 @@ func (b *SQLiteBackup) Step(p int) (bool, error) {
return false, nil
}
// Remaining return whether have the rest for backup.
func (b *SQLiteBackup) Remaining() int {
return int(C.sqlite3_backup_remaining(b.b))
}
// PageCount return count of pages.
func (b *SQLiteBackup) PageCount() int {
return int(C.sqlite3_backup_pagecount(b.b))
}
// Finish close backup.
func (b *SQLiteBackup) Finish() error {
return b.Close()
}
// Close close backup.
func (b *SQLiteBackup) Close() error {
ret := C.sqlite3_backup_finish(b.b)

View File

@ -7,6 +7,7 @@ package sqlite3
import "C"
// ErrNo inherit errno.
type ErrNo int
const ErrNoMask C.int = 0xff

View File

@ -118,10 +118,10 @@ import (
"golang.org/x/net/context"
)
// Timestamp formats understood by both this module and SQLite.
// The first format in the slice will be used when saving time values
// into the database. When parsing a string from a timestamp or
// datetime column, the formats are tried in order.
// SQLiteTimestampFormats is timestamp formats understood by both this module
// and SQLite. The first format in the slice will be used when saving time
// values into the database. When parsing a string from a timestamp or datetime
// column, the formats are tried in order.
var SQLiteTimestampFormats = []string{
// By default, store timestamps with whatever timezone they come with.
// When parsed, they will be returned with the same timezone.
@ -141,20 +141,20 @@ func init() {
}
// 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())
libVersionNumber = int(C.sqlite3_libversion_number())
sourceId = C.GoString(C.sqlite3_sourceid())
return libVersion, libVersionNumber, sourceId
sourceID = C.GoString(C.sqlite3_sourceid())
return libVersion, libVersionNumber, sourceID
}
// Driver struct.
// SQLiteDriver implement sql.Driver.
type SQLiteDriver struct {
Extensions []string
ConnectHook func(*SQLiteConn) error
}
// Conn struct.
// SQLiteConn implement sql.Conn.
type SQLiteConn struct {
db *C.sqlite3
loc *time.Location
@ -163,12 +163,12 @@ type SQLiteConn struct {
aggregators []*aggInfo
}
// Tx struct.
// SQLiteTx implemen sql.Tx.
type SQLiteTx struct {
c *SQLiteConn
}
// Stmt struct.
// SQLiteStmt implement sql.Stmt.
type SQLiteStmt struct {
c *SQLiteConn
s *C.sqlite3_stmt
@ -177,13 +177,13 @@ type SQLiteStmt struct {
cls bool
}
// Result struct.
// SQLiteResult implement sql.Result.
type SQLiteResult struct {
id int64
changes int64
}
// Rows struct.
// SQLiteRows implement sql.Rows.
type SQLiteRows struct {
s *SQLiteStmt
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) {
if len(args) == 0 {
return c.execQuery(query)
@ -456,7 +456,7 @@ type namedValue struct {
Value driver.Value
}
// Implements Queryer
// Query implements Queryer.
func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, error) {
list := make([]namedValue, len(args))
for i, v := range args {
@ -549,7 +549,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
var loc *time.Location
txlock := "BEGIN"
busy_timeout := 5000
busyTimeout := 5000
pos := strings.IndexRune(dsn, '?')
if 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 {
return nil, fmt.Errorf("Invalid _busy_timeout: %v: %v", val, err)
}
busy_timeout = int(iv)
busyTimeout = int(iv)
}
// _txlock
@ -612,7 +612,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
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 {
return nil, Error{Code: ErrNo(rv)}
}
@ -686,7 +686,7 @@ func (s *SQLiteStmt) Close() error {
return nil
}
// Return a number of parameters.
// NumInput return a number of parameters.
func (s *SQLiteStmt) NumInput() int {
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 last inserted ID.
// LastInsertId teturn last inserted ID.
func (r *SQLiteResult) LastInsertId() (int64, error) {
return r.id, nil
}
// Return how many rows affected.
// RowsAffected return how many rows affected.
func (r *SQLiteResult) RowsAffected() (int64, error) {
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) {
list := make([]namedValue, len(args))
for i, v := range args {
@ -823,7 +823,7 @@ func (rc *SQLiteRows) Close() error {
return nil
}
// Return column names.
// Columns return column names.
func (rc *SQLiteRows) Columns() []string {
if rc.nc != len(rc.cols) {
rc.cols = make([]string, rc.nc)
@ -834,7 +834,7 @@ func (rc *SQLiteRows) Columns() []string {
return rc.cols
}
// Return column types.
// DeclTypes return column types.
func (rc *SQLiteRows) DeclTypes() []string {
if rc.decltype == nil {
rc.decltype = make([]string, rc.nc)
@ -845,7 +845,7 @@ func (rc *SQLiteRows) DeclTypes() []string {
return rc.decltype
}
// Move cursor to next.
// Next move cursor to next.
func (rc *SQLiteRows) Next(dest []driver.Value) error {
rv := C.sqlite3_step(rc.s.s)
if rv == C.SQLITE_DONE {

View File

@ -17,6 +17,7 @@ func (c *SQLiteConn) Ping(ctx context.Context) error {
return nil
}
// QueryContext implement QueryerContext.
func (c *SQLiteConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
list := make([]namedValue, len(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)
}
// ExecContext implement ExecerContext.
func (c *SQLiteConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
list := make([]namedValue, len(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)
}
// PrepareContext implement ConnPrepareContext.
func (c *SQLiteConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) {
return c.prepare(ctx, query)
}
// BeginContext implement ConnBeginContext.
func (c *SQLiteConn) BeginContext(ctx context.Context) (driver.Tx, error) {
return c.begin(ctx)
}
// QueryContext implement QueryerContext.
func (s *SQLiteStmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) {
list := make([]namedValue, len(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)
}
// ExecContext implement ExecerContext.
func (s *SQLiteStmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) {
list := make([]namedValue, len(args))
for i, nv := range args {

View File

@ -42,6 +42,7 @@ func (c *SQLiteConn) loadExtensions(extensions []string) error {
return nil
}
// LoadExtension load the sqlite3 extension.
func (c *SQLiteConn) LoadExtension(lib string, entry string) error {
rv := C.sqlite3_enable_load_extension(c.db, 1)
if rv != C.SQLITE_OK {

View File

@ -4,6 +4,7 @@ package sqlite3
import "errors"
// RegisterAggregator register the aggregator.
func (c *SQLiteConn) RegisterAggregator(name string, impl interface{}, pure bool) error {
return errors.New("This feature is not implemented")
}