Skip to content

Commit

Permalink
fix breaking compatibility.
Browse files Browse the repository at this point in the history
revert cf4bd56

close #394
  • Loading branch information
mattn committed Mar 21, 2017
1 parent bd7fdb6 commit 866c329
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions backup.go
Expand Up @@ -48,7 +48,7 @@ func (b *SQLiteBackup) Step(p int) (bool, error) {
if ret == C.SQLITE_DONE {
return true, nil
} else if ret != 0 && ret != C.SQLITE_LOCKED && ret != C.SQLITE_BUSY {
return false, &Error{Code: ErrNo(ret)}
return false, Error{Code: ErrNo(ret)}
}
return false, nil
}
Expand Down Expand Up @@ -79,7 +79,7 @@ func (b *SQLiteBackup) Close() error {
runtime.SetFinalizer(b, nil)

if ret != 0 {
return &Error{Code: ErrNo(ret)}
return Error{Code: ErrNo(ret)}
}
return nil
}
7 changes: 3 additions & 4 deletions error.go
Expand Up @@ -58,7 +58,7 @@ var (

// Error return error message from errno.
func (err ErrNo) Error() string {
return (&Error{Code: err}).Error()
return Error{Code: err}.Error()
}

// Extend return extended errno.
Expand All @@ -68,11 +68,10 @@ func (err ErrNo) Extend(by int) ErrNoExtended {

// Error return error message that is extended code.
func (err ErrNoExtended) Error() string {
return (&Error{Code: ErrNo(C.int(err) & ErrNoMask), ExtendedCode: err}).Error()
return Error{Code: ErrNo(C.int(err) & ErrNoMask), ExtendedCode: err}.Error()
}

// Error return error message.
func (err *Error) Error() string {
func (err Error) Error() string {
if err.err != "" {
return err.err
}
Expand Down
8 changes: 4 additions & 4 deletions error_test.go
Expand Up @@ -40,7 +40,7 @@ func TestCorruptDbErrors(t *testing.T) {
_, err = db.Exec("drop table foo")
}

sqliteErr := err.(*Error)
sqliteErr := err.(Error)
if sqliteErr.Code != ErrNotADB {
t.Error("wrong error code for corrupted DB")
}
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestExtendedErrorCodes_ForeignKey(t *testing.T) {
if err == nil {
t.Error("No error!")
} else {
sqliteErr := err.(*Error)
sqliteErr := err.(Error)
if sqliteErr.Code != ErrConstraint {
t.Errorf("Wrong basic error code: %d != %d",
sqliteErr.Code, ErrConstraint)
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestExtendedErrorCodes_NotNull(t *testing.T) {
if err == nil {
t.Error("No error!")
} else {
sqliteErr := err.(*Error)
sqliteErr := err.(Error)
if sqliteErr.Code != ErrConstraint {
t.Errorf("Wrong basic error code: %d != %d",
sqliteErr.Code, ErrConstraint)
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestExtendedErrorCodes_Unique(t *testing.T) {
if err == nil {
t.Error("No error!")
} else {
sqliteErr := err.(*Error)
sqliteErr := err.(Error)
if sqliteErr.Code != ErrConstraint {
t.Errorf("Wrong basic error code: %d != %d",
sqliteErr.Code, ErrConstraint)
Expand Down
12 changes: 6 additions & 6 deletions sqlite3.go
Expand Up @@ -298,7 +298,7 @@ func (ai *aggInfo) Done(ctx *C.sqlite3_context) {
// Commit transaction.
func (tx *SQLiteTx) Commit() error {
_, err := tx.c.exec(context.Background(), "COMMIT", nil)
if err != nil && err.(*Error).Code == C.SQLITE_BUSY {
if err != nil && err.(Error).Code == C.SQLITE_BUSY {
// sqlite3 will leave the transaction open in this scenario.
// However, database/sql considers the transaction complete once we
// return from Commit() - we must clean up to honour its semantics.
Expand Down Expand Up @@ -399,12 +399,12 @@ func (c *SQLiteConn) AutoCommit() bool {
return int(C.sqlite3_get_autocommit(c.db)) != 0
}

func (c *SQLiteConn) lastError() *Error {
func (c *SQLiteConn) lastError() error {
rv := C.sqlite3_errcode(c.db)
if rv == C.SQLITE_OK {
return nil
}
return &Error{
return Error{
Code: ErrNo(rv),
ExtendedCode: ErrNoExtended(C.sqlite3_extended_errcode(c.db)),
err: C.GoString(C.sqlite3_errmsg(c.db)),
Expand Down Expand Up @@ -519,7 +519,7 @@ func (c *SQLiteConn) begin(ctx context.Context) (driver.Tx, error) {
return &SQLiteTx{c}, nil
}

func errorString(err *Error) string {
func errorString(err Error) string {
return C.GoString(C.sqlite3_errstr(C.int(err.Code)))
}

Expand Down Expand Up @@ -601,15 +601,15 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
C.SQLITE_OPEN_CREATE,
nil)
if rv != 0 {
return nil, &Error{Code: ErrNo(rv)}
return nil, Error{Code: ErrNo(rv)}
}
if db == nil {
return nil, errors.New("sqlite succeeded without returning a database")
}

rv = C.sqlite3_busy_timeout(db, C.int(busyTimeout))
if rv != C.SQLITE_OK {
return nil, &Error{Code: ErrNo(rv)}
return nil, Error{Code: ErrNo(rv)}
}

conn := &SQLiteConn{db: db, loc: loc, txlock: txlock}
Expand Down

0 comments on commit 866c329

Please sign in to comment.