Commit 7e0fdf5c authored by gwenn's avatar gwenn

Golint applied.

parent 703414bf
...@@ -17,7 +17,7 @@ import ( ...@@ -17,7 +17,7 @@ import (
"unsafe" "unsafe"
) )
// io.ReadCloser adapter to BLOB // BlobReader is an io.ReadCloser adapter for BLOB
// (See http://sqlite.org/c3ref/blob.html) // (See http://sqlite.org/c3ref/blob.html)
type BlobReader struct { type BlobReader struct {
c *Conn c *Conn
...@@ -26,7 +26,7 @@ type BlobReader struct { ...@@ -26,7 +26,7 @@ type BlobReader struct {
offset int offset int
} }
// io.ReadWriteCloser adapter to BLOB // BlobReadWriter is an io.ReadWriteCloser adapter for BLOB
type BlobReadWriter struct { type BlobReadWriter struct {
BlobReader BlobReader
} }
...@@ -38,7 +38,7 @@ type ZeroBlobLength int ...@@ -38,7 +38,7 @@ type ZeroBlobLength int
// //
// (See http://sqlite.org/c3ref/blob_open.html) // (See http://sqlite.org/c3ref/blob_open.html)
func (c *Conn) NewBlobReader(db, table, column string, row int64) (*BlobReader, error) { func (c *Conn) NewBlobReader(db, table, column string, row int64) (*BlobReader, error) {
bl, err := c.blob_open(db, table, column, row, false) bl, err := c.blobOpen(db, table, column, row, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -48,14 +48,14 @@ func (c *Conn) NewBlobReader(db, table, column string, row int64) (*BlobReader, ...@@ -48,14 +48,14 @@ func (c *Conn) NewBlobReader(db, table, column string, row int64) (*BlobReader,
// NewBlobReadWriter opens a BLOB for incremental I/O. // NewBlobReadWriter opens a BLOB for incremental I/O.
// (See http://sqlite.org/c3ref/blob_open.html) // (See 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.blobOpen(db, table, column, row, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &BlobReadWriter{BlobReader{c, bl, -1, 0}}, nil return &BlobReadWriter{BlobReader{c, bl, -1, 0}}, nil
} }
func (c *Conn) blob_open(db, table, column string, row int64, write bool) (*C.sqlite3_blob, error) { func (c *Conn) blobOpen(db, table, column string, row int64, write bool) (*C.sqlite3_blob, error) {
zDb := C.CString(db) zDb := C.CString(db)
defer C.free(unsafe.Pointer(zDb)) defer C.free(unsafe.Pointer(zDb))
zTable := C.CString(table) zTable := C.CString(table)
...@@ -68,7 +68,7 @@ func (c *Conn) blob_open(db, table, column string, row int64, write bool) (*C.sq ...@@ -68,7 +68,7 @@ func (c *Conn) blob_open(db, table, column string, row int64, write bool) (*C.sq
if bl != nil { if bl != nil {
C.sqlite3_blob_close(bl) C.sqlite3_blob_close(bl)
} }
return nil, c.error(rv, fmt.Sprintf("Conn.blob_open(db: %q, tbl: %q, col: %q, row: %d)", db, table, column, row)) return nil, c.error(rv, fmt.Sprintf("Conn.blobOpen(db: %q, tbl: %q, col: %q, row: %d)", db, table, column, row))
} }
if bl == nil { if bl == nil {
return nil, errors.New("sqlite succeeded without returning a blob") return nil, errors.New("sqlite succeeded without returning a blob")
......
...@@ -26,7 +26,7 @@ func init() { ...@@ -26,7 +26,7 @@ func init() {
ConfigMemStatus(false) ConfigMemStatus(false)
} }
// Adapter to database/sql/driver // Driver is an adapter to database/sql/driver
type Driver struct { type Driver struct {
} }
type connImpl struct { type connImpl struct {
......
...@@ -91,9 +91,9 @@ func ExampleStmt_Insert() { ...@@ -91,9 +91,9 @@ func ExampleStmt_Insert() {
defer s.Finalize() defer s.Finalize()
data := []string{"Go", "SQLite", "Driver"} data := []string{"Go", "SQLite", "Driver"}
for _, d := range data { for _, d := range data {
rowId, err := s.Insert(d) rowID, err := s.Insert(d)
check(err) check(err)
fmt.Println(rowId) fmt.Println(rowID)
} }
// Output: 1 // Output: 1
// 2 // 2
......
...@@ -48,7 +48,7 @@ func (c *Conn) Databases() (map[string]string, error) { ...@@ -48,7 +48,7 @@ func (c *Conn) Databases() (map[string]string, error) {
return nil, err return nil, err
} }
defer s.finalize() defer s.finalize()
var databases map[string]string = make(map[string]string) var databases = make(map[string]string)
var name, file string var name, file string
err = s.Select(func(s *Stmt) (err error) { err = s.Select(func(s *Stmt) (err error) {
if err = s.Scan(nil, &name, &file); err != nil { if err = s.Scan(nil, &name, &file); err != nil {
...@@ -77,7 +77,7 @@ func (c *Conn) Tables(dbName string) ([]string, error) { ...@@ -77,7 +77,7 @@ func (c *Conn) Tables(dbName string) ([]string, error) {
return nil, err return nil, err
} }
defer s.finalize() defer s.finalize()
var tables []string = make([]string, 0, 20) var tables = make([]string, 0, 20)
err = s.Select(func(s *Stmt) (err error) { err = s.Select(func(s *Stmt) (err error) {
name, _ := s.ScanText(0) name, _ := s.ScanText(0)
tables = append(tables, name) tables = append(tables, name)
...@@ -116,7 +116,7 @@ func (c *Conn) Columns(dbName, table string) ([]Column, error) { ...@@ -116,7 +116,7 @@ func (c *Conn) Columns(dbName, table string) ([]Column, error) {
return nil, err return nil, err
} }
defer s.finalize() defer s.finalize()
var columns []Column = make([]Column, 0, 20) var columns = make([]Column, 0, 20)
err = s.Select(func(s *Stmt) (err error) { err = s.Select(func(s *Stmt) (err error) {
c := Column{} c := Column{}
if err = s.Scan(&c.Cid, &c.Name, &c.DataType, &c.NotNull, &c.DfltValue, &c.Pk); err != nil { if err = s.Scan(&c.Cid, &c.Name, &c.DataType, &c.NotNull, &c.DfltValue, &c.Pk); err != nil {
...@@ -251,7 +251,7 @@ func (c *Conn) Indexes(dbName, table string) ([]Index, error) { ...@@ -251,7 +251,7 @@ func (c *Conn) Indexes(dbName, table string) ([]Index, error) {
return nil, err return nil, err
} }
defer s.finalize() defer s.finalize()
var indexes []Index = make([]Index, 0, 5) var indexes = make([]Index, 0, 5)
err = s.Select(func(s *Stmt) (err error) { err = s.Select(func(s *Stmt) (err error) {
i := Index{} i := Index{}
if err = s.Scan(nil, &i.Name, &i.Unique); err != nil { if err = s.Scan(nil, &i.Name, &i.Unique); err != nil {
...@@ -281,7 +281,7 @@ func (c *Conn) IndexColumns(dbName, index string) ([]Column, error) { ...@@ -281,7 +281,7 @@ func (c *Conn) IndexColumns(dbName, index string) ([]Column, error) {
return nil, err return nil, err
} }
defer s.finalize() defer s.finalize()
var columns []Column = make([]Column, 0, 5) var columns = make([]Column, 0, 5)
err = s.Select(func(s *Stmt) (err error) { err = s.Select(func(s *Stmt) (err error) {
c := Column{} c := Column{}
if err = s.Scan(nil, &c.Cid, &c.Name); err != nil { if err = s.Scan(nil, &c.Cid, &c.Name); err != nil {
......
...@@ -168,7 +168,7 @@ func (c *Conn) ForeignKeyCheck(dbName, table string) ([]FkViolation, error) { ...@@ -168,7 +168,7 @@ func (c *Conn) ForeignKeyCheck(dbName, table string) ([]FkViolation, error) {
} }
defer s.finalize() defer s.finalize()
// table|rowid|parent|fkid // table|rowid|parent|fkid
var violations []FkViolation = make([]FkViolation, 0, 20) var violations = make([]FkViolation, 0, 20)
err = s.Select(func(s *Stmt) (err error) { err = s.Select(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 {
......
...@@ -75,36 +75,36 @@ func (e Errno) Error() string { ...@@ -75,36 +75,36 @@ func (e Errno) Error() string {
return s return s
} }
var ( const (
ErrError error = Errno(C.SQLITE_ERROR) /* SQL error or missing database */ ErrError = Errno(C.SQLITE_ERROR) /* SQL error or missing database */
ErrInternal error = Errno(C.SQLITE_INTERNAL) /* Internal logic error in SQLite */ ErrInternal = Errno(C.SQLITE_INTERNAL) /* Internal logic error in SQLite */
ErrPerm error = Errno(C.SQLITE_PERM) /* Access permission denied */ ErrPerm = Errno(C.SQLITE_PERM) /* Access permission denied */
ErrAbort error = Errno(C.SQLITE_ABORT) /* Callback routine requested an abort */ ErrAbort = Errno(C.SQLITE_ABORT) /* Callback routine requested an abort */
ErrBusy error = Errno(C.SQLITE_BUSY) /* The database file is locked */ ErrBusy = Errno(C.SQLITE_BUSY) /* The database file is locked */
ErrLocked error = Errno(C.SQLITE_LOCKED) /* A table in the database is locked */ ErrLocked = Errno(C.SQLITE_LOCKED) /* A table in the database is locked */
ErrNoMem error = Errno(C.SQLITE_NOMEM) /* A malloc() failed */ ErrNoMem = Errno(C.SQLITE_NOMEM) /* A malloc() failed */
ErrReadOnly error = Errno(C.SQLITE_READONLY) /* Attempt to write a readonly database */ ErrReadOnly = Errno(C.SQLITE_READONLY) /* Attempt to write a readonly database */
ErrInterrupt error = Errno(C.SQLITE_INTERRUPT) /* Operation terminated by sqlite3_interrupt()*/ ErrInterrupt = Errno(C.SQLITE_INTERRUPT) /* Operation terminated by sqlite3_interrupt()*/
ErrIOErr error = Errno(C.SQLITE_IOERR) /* Some kind of disk I/O error occurred */ ErrIOErr = Errno(C.SQLITE_IOERR) /* Some kind of disk I/O error occurred */
ErrCorrupt error = Errno(C.SQLITE_CORRUPT) /* The database disk image is malformed */ ErrCorrupt = Errno(C.SQLITE_CORRUPT) /* The database disk image is malformed */
ErrNotFound error = Errno(C.SQLITE_NOTFOUND) /* Unknown opcode in sqlite3_file_control() */ ErrNotFound = Errno(C.SQLITE_NOTFOUND) /* Unknown opcode in sqlite3_file_control() */
ErrFull error = Errno(C.SQLITE_FULL) /* Insertion failed because database is full */ ErrFull = Errno(C.SQLITE_FULL) /* Insertion failed because database is full */
ErrCantOpen error = Errno(C.SQLITE_CANTOPEN) /* Unable to open the database file */ ErrCantOpen = Errno(C.SQLITE_CANTOPEN) /* Unable to open the database file */
ErrProtocol error = Errno(C.SQLITE_PROTOCOL) /* Database lock protocol error */ ErrProtocol = Errno(C.SQLITE_PROTOCOL) /* Database lock protocol error */
ErrEmpty error = Errno(C.SQLITE_EMPTY) /* Database is empty */ ErrEmpty = Errno(C.SQLITE_EMPTY) /* Database is empty */
ErrSchema error = Errno(C.SQLITE_SCHEMA) /* The database schema changed */ ErrSchema = Errno(C.SQLITE_SCHEMA) /* The database schema changed */
ErrTooBig error = Errno(C.SQLITE_TOOBIG) /* String or BLOB exceeds size limit */ ErrTooBig = Errno(C.SQLITE_TOOBIG) /* String or BLOB exceeds size limit */
ErrConstraint error = Errno(C.SQLITE_CONSTRAINT) /* Abort due to constraint violation */ ErrConstraint = Errno(C.SQLITE_CONSTRAINT) /* Abort due to constraint violation */
ErrMismatch error = Errno(C.SQLITE_MISMATCH) /* Data type mismatch */ ErrMismatch = Errno(C.SQLITE_MISMATCH) /* Data type mismatch */
ErrMisuse error = Errno(C.SQLITE_MISUSE) /* Library used incorrectly */ ErrMisuse = Errno(C.SQLITE_MISUSE) /* Library used incorrectly */
ErrNolfs error = Errno(C.SQLITE_NOLFS) /* Uses OS features not supported on host */ ErrNolfs = Errno(C.SQLITE_NOLFS) /* Uses OS features not supported on host */
ErrAuth error = Errno(C.SQLITE_AUTH) /* Authorization denied */ ErrAuth = Errno(C.SQLITE_AUTH) /* Authorization denied */
ErrFormat error = Errno(C.SQLITE_FORMAT) /* Auxiliary database format error */ ErrFormat = Errno(C.SQLITE_FORMAT) /* Auxiliary database format error */
ErrRange error = Errno(C.SQLITE_RANGE) /* 2nd parameter to sqlite3_bind out of range */ ErrRange = Errno(C.SQLITE_RANGE) /* 2nd parameter to sqlite3_bind out of range */
ErrNotDB error = Errno(C.SQLITE_NOTADB) /* File opened that is not a database file */ ErrNotDB = Errno(C.SQLITE_NOTADB) /* File opened that is not a database file */
Row = Errno(C.SQLITE_ROW) /* sqlite3_step() has another row ready */ Row = Errno(C.SQLITE_ROW) /* sqlite3_step() has another row ready */
Done = Errno(C.SQLITE_DONE) /* sqlite3_step() has finished executing */ Done = Errno(C.SQLITE_DONE) /* sqlite3_step() has finished executing */
ErrSpecific = Errno(-1) /* Wrapper specific error */ ErrSpecific = Errno(-1) /* Wrapper specific error */
) )
func (c *Conn) error(rv C.int, details ...string) error { func (c *Conn) error(rv C.int, details ...string) error {
......
...@@ -139,8 +139,8 @@ func TestInsert(t *testing.T) { ...@@ -139,8 +139,8 @@ func TestInsert(t *testing.T) {
} }
checkNoError(t, db.Commit(), "Error: %s") checkNoError(t, db.Commit(), "Error: %s")
lastId := db.LastInsertRowid() lastID := db.LastInsertRowid()
assertEquals(t, "last insert row id error: expected %d but got %d", int64(1000), lastId) assertEquals(t, "last insert row id error: expected %d but got %d", int64(1000), lastID)
cs, _ := db.Prepare("SELECT COUNT(*) FROM test") cs, _ := db.Prepare("SELECT COUNT(*) FROM test")
defer checkFinalize(cs, t) defer checkFinalize(cs, t)
......
...@@ -315,10 +315,10 @@ func (s *Stmt) Bind(args ...interface{}) error { ...@@ -315,10 +315,10 @@ func (s *Stmt) Bind(args ...interface{}) error {
} }
// NullIfEmpty transforms empty string to null when true (true by default) // NullIfEmpty transforms empty string to null when true (true by default)
var NullIfEmptyString bool = true var NullIfEmptyString = true
// NullIfZeroTime transforms zero time (time.Time.IsZero) to null when true (true by default) // NullIfZeroTime transforms zero time (time.Time.IsZero) to null when true (true by default)
var NullIfZeroTime bool = true var NullIfZeroTime = true
// BindByIndex binds value to the specified host parameter of the prepared statement. // BindByIndex binds value to the specified host parameter of the prepared statement.
// The leftmost SQL parameter has an index of 1. // The leftmost SQL parameter has an index of 1.
...@@ -485,12 +485,12 @@ func (t Type) String() string { ...@@ -485,12 +485,12 @@ func (t Type) String() string {
return typeText[t] return typeText[t]
} }
var ( const (
Integer Type = Type(C.SQLITE_INTEGER) Integer = Type(C.SQLITE_INTEGER)
Float Type = Type(C.SQLITE_FLOAT) Float = Type(C.SQLITE_FLOAT)
Blob Type = Type(C.SQLITE_BLOB) Blob = Type(C.SQLITE_BLOB)
Null Type = Type(C.SQLITE_NULL) Null = Type(C.SQLITE_NULL)
Text Type = Type(C.SQLITE3_TEXT) Text = Type(C.SQLITE3_TEXT)
) )
var typeText = map[Type]string{ var typeText = map[Type]string{
...@@ -785,10 +785,9 @@ func (s *Stmt) ScanValue(index int, blob bool) (interface{}, bool) { ...@@ -785,10 +785,9 @@ func (s *Stmt) ScanValue(index int, blob bool) (interface{}, bool) {
p := C.sqlite3_column_blob(s.stmt, C.int(index)) p := C.sqlite3_column_blob(s.stmt, C.int(index))
n := C.sqlite3_column_bytes(s.stmt, C.int(index)) n := C.sqlite3_column_bytes(s.stmt, C.int(index))
return C.GoBytes(p, n), false return C.GoBytes(p, n), false
} else {
p := C.sqlite3_column_text(s.stmt, C.int(index))
return C.GoString((*C.char)(unsafe.Pointer(p))), false
} }
p := C.sqlite3_column_text(s.stmt, C.int(index))
return C.GoString((*C.char)(unsafe.Pointer(p))), false
case Integer: case Integer:
return int64(C.sqlite3_column_int64(s.stmt, C.int(index))), false return int64(C.sqlite3_column_int64(s.stmt, C.int(index))), false
case Float: case Float:
......
...@@ -167,11 +167,11 @@ func TestScanNull(t *testing.T) { ...@@ -167,11 +167,11 @@ func TestScanNull(t *testing.T) {
if !Must(s.Next()) { if !Must(s.Next()) {
t.Fatal("no result") t.Fatal("no result")
} }
var pi *int = new(int) var pi = new(int)
null := Must(s.ScanByIndex(0, &pi)) null := Must(s.ScanByIndex(0, &pi))
assert(t, "expected null value", null) assert(t, "expected null value", null)
assertEquals(t, "expected nil (%p) but got %p", (*int)(nil), pi) assertEquals(t, "expected nil (%p) but got %p", (*int)(nil), pi)
var ps *string = new(string) var ps = new(string)
null = Must(s.ScanByIndex(0, &ps)) null = Must(s.ScanByIndex(0, &ps))
assert(t, "expected null value", null) assert(t, "expected null value", null)
assertEquals(t, "expected nil (%p) but got %p", (*string)(nil), ps) assertEquals(t, "expected nil (%p) but got %p", (*string)(nil), ps)
...@@ -187,11 +187,11 @@ func TestScanNotNull(t *testing.T) { ...@@ -187,11 +187,11 @@ func TestScanNotNull(t *testing.T) {
if !Must(s.Next()) { if !Must(s.Next()) {
t.Fatal("no result") t.Fatal("no result")
} }
var pi *int = new(int) var pi = new(int)
null := Must(s.ScanByIndex(0, &pi)) null := Must(s.ScanByIndex(0, &pi))
assert(t, "expected not null value", !null) assert(t, "expected not null value", !null)
assertEquals(t, "expected %d but got %d", 1, *pi) assertEquals(t, "expected %d but got %d", 1, *pi)
var ps *string = new(string) var ps = new(string)
null = Must(s.ScanByIndex(0, &ps)) null = Must(s.ScanByIndex(0, &ps))
assert(t, "expected not null value", !null) assert(t, "expected not null value", !null)
assertEquals(t, "expected %s but got %s", "1", *ps) assertEquals(t, "expected %s but got %s", "1", *ps)
......
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