Commit ebcb34c3 authored by gwenn's avatar gwenn

Golint

parent 3178e848
...@@ -24,6 +24,7 @@ import "unsafe" ...@@ -24,6 +24,7 @@ import "unsafe"
// See ConfigThreadingMode // See ConfigThreadingMode
type ThreadingMode int32 type ThreadingMode int32
// SQLite threading modes
const ( const (
SingleThread ThreadingMode = C.SQLITE_CONFIG_SINGLETHREAD SingleThread ThreadingMode = C.SQLITE_CONFIG_SINGLETHREAD
MultiThread ThreadingMode = C.SQLITE_CONFIG_MULTITHREAD MultiThread ThreadingMode = C.SQLITE_CONFIG_MULTITHREAD
......
...@@ -210,7 +210,7 @@ func (vc *csvTabCursor) Next() error { ...@@ -210,7 +210,7 @@ func (vc *csvTabCursor) Next() error {
} }
return err return err
} }
func (vc *csvTabCursor) Eof() bool { func (vc *csvTabCursor) EOF() bool {
return vc.vTab.eof return vc.vTab.eof
} }
func (vc *csvTabCursor) Column(c *Context, col int) error { func (vc *csvTabCursor) Column(c *Context, col int) error {
...@@ -254,7 +254,7 @@ func (db *Conn) ExportTableToCSV(dbName, table string, nullvalue string, headers ...@@ -254,7 +254,7 @@ func (db *Conn) ExportTableToCSV(dbName, table string, nullvalue string, headers
return s.ExportToCSV(nullvalue, headers, w) return s.ExportToCSV(nullvalue, headers, w)
} }
// ExportTableToCSV export statement result to CSV. // ExportToCSV export statement result to CSV.
// 'headers' flag turns output of headers on or off. // 'headers' flag turns output of headers on or off.
// NULL values are output as specified by 'nullvalue' parameter. // NULL values are output as specified by 'nullvalue' parameter.
func (s *Stmt) ExportToCSV(nullvalue string, headers bool, w *yacr.Writer) error { func (s *Stmt) ExportToCSV(nullvalue string, headers bool, w *yacr.Writer) error {
...@@ -283,6 +283,7 @@ func (s *Stmt) ExportToCSV(nullvalue string, headers bool, w *yacr.Writer) error ...@@ -283,6 +283,7 @@ func (s *Stmt) ExportToCSV(nullvalue string, headers bool, w *yacr.Writer) error
return w.Err() return w.Err()
} }
// ImportConfig gathers import parameters.
type ImportConfig struct { type ImportConfig struct {
Name string // the name of the input; used only for error reports Name string // the name of the input; used only for error reports
Separator byte // CSV separator Separator byte // CSV separator
......
...@@ -18,7 +18,7 @@ void* goSqlite3RollbackHook(sqlite3 *db, void *udp) { ...@@ -18,7 +18,7 @@ void* goSqlite3RollbackHook(sqlite3 *db, void *udp) {
return sqlite3_rollback_hook(db, goXRollbackHook, udp); return sqlite3_rollback_hook(db, goXRollbackHook, udp);
} }
extern void goXUpdateHook(void *udp, int action, char const *dbName, char const *tableName, sqlite3_int64 rowId); extern void goXUpdateHook(void *udp, int action, char const *dbName, char const *tableName, sqlite3_int64 rowID);
void* goSqlite3UpdateHook(sqlite3 *db, void *udp) { void* goSqlite3UpdateHook(sqlite3 *db, void *udp) {
return sqlite3_update_hook(db, goXUpdateHook, udp); return sqlite3_update_hook(db, goXUpdateHook, udp);
......
...@@ -74,7 +74,7 @@ func (c *Conn) RollbackHook(f RollbackHook, udp interface{}) { ...@@ -74,7 +74,7 @@ func (c *Conn) RollbackHook(f RollbackHook, udp interface{}) {
} }
// UpdateHook is the callback function signature. // UpdateHook is the callback function signature.
type UpdateHook func(udp interface{}, a Action, dbName, tableName string, rowId int64) type UpdateHook func(udp interface{}, a Action, dbName, tableName string, rowID int64)
type sqliteUpdateHook struct { type sqliteUpdateHook struct {
f UpdateHook f UpdateHook
...@@ -82,9 +82,9 @@ type sqliteUpdateHook struct { ...@@ -82,9 +82,9 @@ type sqliteUpdateHook struct {
} }
//export goXUpdateHook //export goXUpdateHook
func goXUpdateHook(udp unsafe.Pointer, action int, dbName, tableName *C.char, rowId C.sqlite3_int64) { func goXUpdateHook(udp unsafe.Pointer, action int, dbName, tableName *C.char, rowID C.sqlite3_int64) {
arg := (*sqliteUpdateHook)(udp) arg := (*sqliteUpdateHook)(udp)
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))
} }
// UpdateHook registers a callback to be invoked each time a row is updated, // UpdateHook registers a callback to be invoked each time a row is updated,
......
...@@ -27,11 +27,11 @@ func rollbackHook(d interface{}) { ...@@ -27,11 +27,11 @@ func rollbackHook(d interface{}) {
} }
} }
func updateHook(d interface{}, a Action, dbName, tableName string, rowId int64) { func updateHook(d interface{}, a Action, dbName, tableName string, rowID int64) {
if t, ok := d.(*testing.T); ok { if t, ok := d.(*testing.T); ok {
t.Logf("UPD: %d, %s.%s.%d\n", a, dbName, tableName, rowId) t.Logf("UPD: %d, %s.%s.%d\n", a, dbName, tableName, rowID)
} else { } else {
fmt.Printf("%s: %d, %s.%s.%d\n", d, a, dbName, tableName, rowId) fmt.Printf("%s: %d, %s.%s.%d\n", d, a, dbName, tableName, rowID)
} }
} }
......
...@@ -8,7 +8,7 @@ package sqlite ...@@ -8,7 +8,7 @@ package sqlite
import "fmt" import "fmt"
// This is the Go-language interface definition for the "intarray" or // IntArray is the Go-language interface definition for the "intarray" or
// integer array virtual table for SQLite. // integer array virtual table for SQLite.
// //
// The intarray virtual table is designed to facilitate using an // The intarray virtual table is designed to facilitate using an
...@@ -89,17 +89,17 @@ func (m *intArray) Connect(c *Conn, args []string) (VTab, error) { ...@@ -89,17 +89,17 @@ func (m *intArray) Connect(c *Conn, args []string) (VTab, error) {
func (m *intArray) DestroyModule() { func (m *intArray) DestroyModule() {
} }
func (v *intArray) BestIndex() error { func (m *intArray) BestIndex() error {
return nil return nil
} }
func (v *intArray) Disconnect() error { func (m *intArray) Disconnect() error {
return nil return nil
} }
func (v *intArray) Destroy() error { func (m *intArray) Destroy() error {
return nil return nil
} }
func (v *intArray) Open() (VTabCursor, error) { func (m *intArray) Open() (VTabCursor, error) {
return &intArrayVTabCursor{v, 0}, nil return &intArrayVTabCursor{m, 0}, nil
} }
type intArrayVTabCursor struct { type intArrayVTabCursor struct {
...@@ -118,7 +118,7 @@ func (vc *intArrayVTabCursor) Next() error { ...@@ -118,7 +118,7 @@ func (vc *intArrayVTabCursor) Next() error {
vc.i++ vc.i++
return nil return nil
} }
func (vc *intArrayVTabCursor) Eof() bool { func (vc *intArrayVTabCursor) EOF() bool {
return vc.i >= len(vc.vTab.content) return vc.i >= len(vc.vTab.content)
} }
func (vc *intArrayVTabCursor) Column(c *Context, col int) error { func (vc *intArrayVTabCursor) Column(c *Context, col int) error {
...@@ -157,6 +157,6 @@ func (c *Conn) CreateIntArray(name string) (IntArray, error) { ...@@ -157,6 +157,6 @@ func (c *Conn) CreateIntArray(name string) (IntArray, error) {
// The array of integers bound must be unchanged for the duration of // The array of integers bound must be unchanged for the duration of
// any query against the corresponding virtual table. If the integer // any query against the corresponding virtual table. If the integer
// array does change or is deallocated undefined behavior will result. // array does change or is deallocated undefined behavior will result.
func (ia *intArray) Bind(elements []int64) { func (m *intArray) Bind(elements []int64) {
ia.content = elements m.content = elements
} }
...@@ -15,6 +15,7 @@ import "C" ...@@ -15,6 +15,7 @@ import "C"
// (See http://www.sqlite.org/c3ref/c_limit_attached.html) // (See http://www.sqlite.org/c3ref/c_limit_attached.html)
type Limit int32 type Limit int32
// Run-time limit categories
const ( const (
LimitLength Limit = C.SQLITE_LIMIT_LENGTH // The maximum size of any string or BLOB or table row, in bytes. LimitLength Limit = C.SQLITE_LIMIT_LENGTH // The maximum size of any string or BLOB or table row, in bytes.
LimitColumn Limit = C.SQLITE_LIMIT_COLUMN LimitColumn Limit = C.SQLITE_LIMIT_COLUMN
......
...@@ -228,6 +228,7 @@ func (s *Stmt) ColumnDeclaredType(index int) string { ...@@ -228,6 +228,7 @@ func (s *Stmt) ColumnDeclaredType(index int) string {
// Affinity enumerates SQLite column type affinity // Affinity enumerates SQLite column type affinity
type Affinity string type Affinity string
// SQLite column type affinities
const ( const (
Integral = Affinity("INTEGER") // Integer affinity Integral = Affinity("INTEGER") // Integer affinity
Real = Affinity("REAL") Real = Affinity("REAL")
......
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
"time" "time"
) )
// Adapted from https://code.google.com/p/vitess/source/browse/go/pools/roundrobin.go // Pool adapted from https://code.google.com/p/vitess/source/browse/go/pools/roundrobin.go
type Pool struct { type Pool struct {
mu sync.Mutex mu sync.Mutex
available *sync.Cond available *sync.Cond
...@@ -144,7 +144,7 @@ func (p *Pool) IsClosed() bool { ...@@ -144,7 +144,7 @@ func (p *Pool) IsClosed() bool {
return p.factory == nil return p.factory == nil
} }
// Set capacity changes the capacity of the pool. // SetCapacity changes the capacity of the pool.
// You can use it to expand or shrink. // You can use it to expand or shrink.
func (p *Pool) SetCapacity(capacity int) { func (p *Pool) SetCapacity(capacity int) {
p.mu.Lock() p.mu.Lock()
......
...@@ -138,9 +138,9 @@ func (c *Conn) SetSynchronous(dbName string, mode int) error { ...@@ -138,9 +138,9 @@ func (c *Conn) SetSynchronous(dbName string, mode int) error {
// FkViolation is the description of one foreign key constraint violation. // FkViolation is the description of one foreign key constraint violation.
type FkViolation struct { type FkViolation struct {
Table string Table string
RowId int64 RowID int64
Parent string Parent string
FkId int FkID int
} }
// ForeignKeyCheck checks the database, or the table, for foreign key constraints that are violated // ForeignKeyCheck checks the database, or the table, for foreign key constraints that are violated
...@@ -172,7 +172,7 @@ func (c *Conn) ForeignKeyCheck(dbName, table string) ([]FkViolation, error) { ...@@ -172,7 +172,7 @@ func (c *Conn) ForeignKeyCheck(dbName, table string) ([]FkViolation, error) {
var violations = make([]FkViolation, 0, 20) var violations = make([]FkViolation, 0, 20)
err = s.execQuery(func(s *Stmt) (err error) { err = s.execQuery(func(s *Stmt) (err error) {
v := FkViolation{} v := FkViolation{}
if err = s.Scan(&v.Table, &v.RowId, &v.Parent, &v.FkId); err != nil { if err = s.Scan(&v.Table, &v.RowID, &v.Parent, &v.FkID); err != nil {
return return
} }
violations = append(violations, v) violations = append(violations, v)
...@@ -203,10 +203,10 @@ func (c *Conn) SetQueryOnly(dbName string, mode bool) error { ...@@ -203,10 +203,10 @@ func (c *Conn) SetQueryOnly(dbName string, mode bool) error {
return c.FastExec(pragma(dbName, fmt.Sprintf("query_only=%t", mode))) return c.FastExec(pragma(dbName, fmt.Sprintf("query_only=%t", mode)))
} }
// ApplicationId queries the "Application ID" integer located into the database header. // ApplicationID queries the "Application ID" integer located into the database header.
// Database name is optional (default is 'main'). // Database name is optional (default is 'main').
// (See http://sqlite.org/pragma.html#pragma_application_id) // (See http://sqlite.org/pragma.html#pragma_application_id)
func (c *Conn) ApplicationId(dbName string) (int, error) { func (c *Conn) ApplicationID(dbName string) (int, error) {
var id int var id int
err := c.oneValue(pragma(dbName, "application_id"), &id) err := c.oneValue(pragma(dbName, "application_id"), &id)
if err != nil { if err != nil {
...@@ -215,10 +215,10 @@ func (c *Conn) ApplicationId(dbName string) (int, error) { ...@@ -215,10 +215,10 @@ func (c *Conn) ApplicationId(dbName string) (int, error) {
return id, nil return id, nil
} }
// SetApplicationId changes the "Application ID". // SetApplicationID changes the "Application ID".
// Database name is optional (default is 'main'). // Database name is optional (default is 'main').
// (See http://sqlite.org/pragma.html#pragma_application_id) // (See http://sqlite.org/pragma.html#pragma_application_id)
func (c *Conn) SetApplicationId(dbName string, id int) error { func (c *Conn) SetApplicationID(dbName string, id int) error {
return c.FastExec(pragma(dbName, fmt.Sprintf("application_id=%d", id))) return c.FastExec(pragma(dbName, fmt.Sprintf("application_id=%d", id)))
} }
......
...@@ -128,7 +128,7 @@ func TestQueryOnly(t *testing.T) { ...@@ -128,7 +128,7 @@ func TestQueryOnly(t *testing.T) {
assert.T(t, err != nil) assert.T(t, err != nil)
} }
func TestApplicationId(t *testing.T) { func TestApplicationID(t *testing.T) {
if VersionNumber() < 3007017 { if VersionNumber() < 3007017 {
return return
} }
...@@ -136,18 +136,18 @@ func TestApplicationId(t *testing.T) { ...@@ -136,18 +136,18 @@ func TestApplicationId(t *testing.T) {
db := open(t) db := open(t)
defer checkClose(db, t) defer checkClose(db, t)
appId, err := db.ApplicationId("") appID, err := db.ApplicationID("")
checkNoError(t, err, "error getting application Id: %s") checkNoError(t, err, "error getting application Id: %s")
assert.Equalf(t, 0, appId, "got: %d; want: %d", appId, 0) assert.Equalf(t, 0, appID, "got: %d; want: %d", appID, 0)
err = db.SetApplicationId("", 123) err = db.SetApplicationID("", 123)
checkNoError(t, err, "error setting application Id: %s") checkNoError(t, err, "error setting application Id: %s")
appId, err = db.ApplicationId("") appID, err = db.ApplicationID("")
checkNoError(t, err, "error getting application Id: %s") checkNoError(t, err, "error getting application Id: %s")
assert.Equalf(t, 123, appId, "got: %d; want: %d", appId, 123) assert.Equalf(t, 123, appID, "got: %d; want: %d", appID, 123)
_, err = db.ApplicationId("bim") _, err = db.ApplicationID("bim")
assert.T(t, err != nil) assert.T(t, err != nil)
} }
...@@ -176,11 +176,11 @@ func TestForeignKeyCheck(t *testing.T) { ...@@ -176,11 +176,11 @@ func TestForeignKeyCheck(t *testing.T) {
checkNoError(t, err, "error while checking FK: %s") checkNoError(t, err, "error while checking FK: %s")
assert.Equal(t, 1, len(vs), "one FK violation expected") assert.Equal(t, 1, len(vs), "one FK violation expected")
v := vs[0] v := vs[0]
assert.Equal(t, FkViolation{Table: "tree", RowId: 4, Parent: "tree", FkId: 0}, v) assert.Equal(t, FkViolation{Table: "tree", RowID: 4, Parent: "tree", FkID: 0}, v)
fks, err := db.ForeignKeys("", "tree") fks, err := db.ForeignKeys("", "tree")
checkNoError(t, err, "error while loading FK: %s") checkNoError(t, err, "error while loading FK: %s")
fk, ok := fks[v.FkId] fk, ok := fks[v.FkID]
assert.Tf(t, ok, "no FK with id: %d", v.FkId) assert.Tf(t, ok, "no FK with id: %d", v.FkID)
assert.Equal(t, &ForeignKey{Table: "tree", From: []string{"parentId"}, To: []string{"id"}}, fk) assert.Equal(t, &ForeignKey{Table: "tree", From: []string{"parentId"}, To: []string{"id"}}, fk)
mvs, err := db.ForeignKeyCheck("main", "tree") mvs, err := db.ForeignKeyCheck("main", "tree")
......
...@@ -73,6 +73,7 @@ func (e Errno) Error() string { ...@@ -73,6 +73,7 @@ func (e Errno) Error() string {
return s return s
} }
// SQLite result codes
const ( const (
ErrError = Errno(C.SQLITE_ERROR) /* SQL error or missing database */ ErrError = Errno(C.SQLITE_ERROR) /* SQL error or missing database */
ErrInternal = Errno(C.SQLITE_INTERNAL) /* Internal logic error in SQLite */ ErrInternal = Errno(C.SQLITE_INTERNAL) /* Internal logic error in SQLite */
...@@ -180,6 +181,7 @@ func VersionNumber() int32 { ...@@ -180,6 +181,7 @@ func VersionNumber() int32 {
// OpenFlag enumerates flags for file open operations // OpenFlag enumerates flags for file open operations
type OpenFlag int32 type OpenFlag int32
// Flags for file open operations
const ( const (
OpenReadOnly OpenFlag = C.SQLITE_OPEN_READONLY OpenReadOnly OpenFlag = C.SQLITE_OPEN_READONLY
OpenReadWrite OpenFlag = C.SQLITE_OPEN_READWRITE OpenReadWrite OpenFlag = C.SQLITE_OPEN_READWRITE
...@@ -386,6 +388,7 @@ func (c *Conn) GetAutocommit() bool { ...@@ -386,6 +388,7 @@ func (c *Conn) GetAutocommit() bool {
// See Conn.BeginTransaction // See Conn.BeginTransaction
type TransactionType uint8 type TransactionType uint8
// Transaction types
const ( const (
Deferred TransactionType = 0 Deferred TransactionType = 0
Immediate TransactionType = 1 Immediate TransactionType = 1
......
...@@ -514,6 +514,7 @@ func (t Type) String() string { ...@@ -514,6 +514,7 @@ func (t Type) String() string {
return typeText[t] return typeText[t]
} }
// SQLite fundamental datatypes
const ( const (
Integer = Type(C.SQLITE_INTEGER) Integer = Type(C.SQLITE_INTEGER)
Float = Type(C.SQLITE_FLOAT) Float = Type(C.SQLITE_FLOAT)
......
...@@ -481,9 +481,9 @@ func TestInsertMisuse(t *testing.T) { ...@@ -481,9 +481,9 @@ func TestInsertMisuse(t *testing.T) {
ois, err := db.Prepare("PRAGMA shrink_memory") ois, err := db.Prepare("PRAGMA shrink_memory")
checkNoError(t, err, "prepare error: %s") checkNoError(t, err, "prepare error: %s")
defer checkFinalize(ois, t) defer checkFinalize(ois, t)
rowId, err := ois.Insert() rowID, err := ois.Insert()
checkNoError(t, err, "insert error: %s") checkNoError(t, err, "insert error: %s")
assert.Equal(t, int64(-1), rowId) assert.Equal(t, int64(-1), rowID)
} }
func TestScanValues(t *testing.T) { func TestScanValues(t *testing.T) {
......
...@@ -91,6 +91,7 @@ func (c *Conn) Profile(f Profiler, udp interface{}) { ...@@ -91,6 +91,7 @@ func (c *Conn) Profile(f Profiler, udp interface{}) {
// Auth enumerates Authorizer return codes // Auth enumerates Authorizer return codes
type Auth int32 type Auth int32
// Authorizer return codes
const ( const (
AuthOk Auth = C.SQLITE_OK AuthOk Auth = C.SQLITE_OK
AuthDeny Auth = C.SQLITE_DENY AuthDeny Auth = C.SQLITE_DENY
...@@ -100,6 +101,7 @@ const ( ...@@ -100,6 +101,7 @@ const (
// Action enumerates Authorizer action codes // Action enumerates Authorizer action codes
type Action int32 type Action int32
// Authorizer action codes
const ( const (
CreateIndex Action = C.SQLITE_CREATE_INDEX CreateIndex Action = C.SQLITE_CREATE_INDEX
CreateTable Action = C.SQLITE_CREATE_TABLE CreateTable Action = C.SQLITE_CREATE_TABLE
...@@ -299,6 +301,7 @@ func (c *Conn) ProgressHandler(f ProgressHandler, numOps int32, udp interface{}) ...@@ -299,6 +301,7 @@ func (c *Conn) ProgressHandler(f ProgressHandler, numOps int32, udp interface{})
// StmtStatus enumerates status parameters for prepared statements // StmtStatus enumerates status parameters for prepared statements
type StmtStatus int32 type StmtStatus int32
// status counters for prepared statements
const ( const (
StmtStatusFullScanStep StmtStatus = C.SQLITE_STMTSTATUS_FULLSCAN_STEP StmtStatusFullScanStep StmtStatus = C.SQLITE_STMTSTATUS_FULLSCAN_STEP
StmtStatusSort StmtStatus = C.SQLITE_STMTSTATUS_SORT StmtStatusSort StmtStatus = C.SQLITE_STMTSTATUS_SORT
......
...@@ -151,7 +151,7 @@ func goVNext(pCursor unsafe.Pointer) *C.char { ...@@ -151,7 +151,7 @@ func goVNext(pCursor unsafe.Pointer) *C.char {
//export goVEof //export goVEof
func goVEof(pCursor unsafe.Pointer) C.int { func goVEof(pCursor unsafe.Pointer) C.int {
vtc := (*sqliteVTabCursor)(pCursor) vtc := (*sqliteVTabCursor)(pCursor)
return btocint(vtc.vTabCursor.Eof()) return btocint(vtc.vTabCursor.EOF())
} }
//export goVColumn //export goVColumn
...@@ -218,7 +218,7 @@ type VTabCursor interface { ...@@ -218,7 +218,7 @@ type VTabCursor interface {
Close() error // See http://sqlite.org/vtab.html#xclose Close() error // See http://sqlite.org/vtab.html#xclose
Filter( /*idxNum int, idxStr string, int argc, sqlite3_value **argv*/ ) error // See http://sqlite.org/vtab.html#xfilter Filter( /*idxNum int, idxStr string, int argc, sqlite3_value **argv*/ ) error // See http://sqlite.org/vtab.html#xfilter
Next() error // See http://sqlite.org/vtab.html#xnext Next() error // See http://sqlite.org/vtab.html#xnext
Eof() bool // See http://sqlite.org/vtab.html#xeof EOF() bool // See http://sqlite.org/vtab.html#xeof
// col is zero-based so the first column is numbered 0 // col is zero-based so the first column is numbered 0
Column(c *Context, col int) error // See http://sqlite.org/vtab.html#xcolumn Column(c *Context, col int) error // See http://sqlite.org/vtab.html#xcolumn
Rowid() (int64, error) // See http://sqlite.org/vtab.html#xrowid Rowid() (int64, error) // See http://sqlite.org/vtab.html#xrowid
......
...@@ -81,8 +81,8 @@ func (vc *testVTabCursor) Next() error { ...@@ -81,8 +81,8 @@ func (vc *testVTabCursor) Next() error {
vc.index++ vc.index++
return nil return nil
} }
func (vc *testVTabCursor) Eof() bool { func (vc *testVTabCursor) EOF() bool {
//fmt.Printf("testVTabCursor.Eof: %v\n", vc) //fmt.Printf("testVTabCursor.EOF: %v\n", vc)
return vc.index >= len(vc.vTab.intarray) return vc.index >= len(vc.vTab.intarray)
} }
func (vc *testVTabCursor) Column(c *Context, col int) error { func (vc *testVTabCursor) Column(c *Context, col int) error {
......
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