From 26da0d2be4824348313f3f6d8deb3f6a17c28537 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 28 Aug 2011 22:16:58 +0400 Subject: [PATCH] db: make stmt.Exec also return Results Change-Id: I5f32e77fbae7db0e9f601b7f581fd55dc261e67f --- lib/go/camli/db/db.go | 19 +++++++++---------- lib/go/camli/db/db_test.go | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/go/camli/db/db.go b/lib/go/camli/db/db.go index 1d6019cdc..8c574b240 100644 --- a/lib/go/camli/db/db.go +++ b/lib/go/camli/db/db.go @@ -294,15 +294,15 @@ func todo() string { return fmt.Sprintf("%s:%d: TODO: implement", file, line) } -func (s *Stmt) Exec(args ...interface{}) os.Error { +func (s *Stmt) Exec(args ...interface{}) (Result, os.Error) { ci, si, err := s.connStmt() if err != nil { - return err + return nil, err } defer s.db.putConn(ci) if want := si.NumInput(); len(args) != want { - return fmt.Errorf("db: expected %d arguments, got %d", want, len(args)) + return nil, fmt.Errorf("db: expected %d arguments, got %d", want, len(args)) } // Convert args if the driver knows its own types. @@ -310,7 +310,7 @@ func (s *Stmt) Exec(args ...interface{}) os.Error { for n, arg := range args { args[n], err = cc.ColumnCoverter(n).ConvertValue(arg) if err != nil { - return fmt.Errorf("db: converting Exec column index %d: %v", n, err) + return nil, fmt.Errorf("db: converting Exec column index %d: %v", n, err) } } } @@ -322,16 +322,15 @@ func (s *Stmt) Exec(args ...interface{}) os.Error { var err os.Error args[n], err = dbimpl.SubsetValue(arg) if err != nil { - return fmt.Errorf("db: error converting index %d: %v", n, err) + return nil, fmt.Errorf("db: error converting index %d: %v", n, err) } } resi, err := si.Exec(args) if err != nil { - return err + return nil, err } - _ = resi // TODO(bradfitz): return these stats, converted to pkg db type - return nil + return result{resi}, nil } func (s *Stmt) connStmt(args ...interface{}) (dbimpl.Conn, dbimpl.Stmt, os.Error) { @@ -408,9 +407,9 @@ func (s *Stmt) QueryRow(args ...interface{}) *Row { func (s *Stmt) Close() os.Error { s.mu.Lock() - defer s.mu.Unlock() + defer s.mu.Unlock() // TODO(bradfitz): move this unlock after 'closed = true'? if s.closed { - return os.NewError("db: statement already closed") + return nil } s.closed = true for _, v := range s.css { diff --git a/lib/go/camli/db/db_test.go b/lib/go/camli/db/db_test.go index 1d28487b6..a4e885f1e 100644 --- a/lib/go/camli/db/db_test.go +++ b/lib/go/camli/db/db_test.go @@ -141,7 +141,7 @@ func TestDb(t *testing.T) { {[]interface{}{1, 2, 3}, "db: expected 2 arguments, got 3"}, } for n, et := range execTests { - err := stmt.Exec(et.args...) + _, err := stmt.Exec(et.args...) errStr := "" if err != nil { errStr = err.String()