OLD | NEW |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Package sql provides a generic interface around SQL (or SQL-like) | 5 // Package sql provides a generic interface around SQL (or SQL-like) |
6 // databases. | 6 // databases. |
7 package sql | 7 package sql |
8 | 8 |
9 import ( | 9 import ( |
10 "errors" | 10 "errors" |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 if err != nil { | 542 if err != nil { |
543 return nil, err | 543 return nil, err |
544 } | 544 } |
545 return result{resi}, nil | 545 return result{resi}, nil |
546 } | 546 } |
547 | 547 |
548 // connStmt returns a free driver connection on which to execute the | 548 // connStmt returns a free driver connection on which to execute the |
549 // statement, a function to call to release the connection, and a | 549 // statement, a function to call to release the connection, and a |
550 // statement bound to that connection. | 550 // statement bound to that connection. |
551 func (s *Stmt) connStmt() (ci driver.Conn, releaseConn func(), si driver.Stmt, e
rr error) { | 551 func (s *Stmt) connStmt() (ci driver.Conn, releaseConn func(), si driver.Stmt, e
rr error) { |
552 » if s.stickyErr != nil { | 552 » if err = s.stickyErr; err != nil { |
553 » » return nil, nil, nil, s.stickyErr | 553 » » return |
554 } | 554 } |
555 s.mu.Lock() | 555 s.mu.Lock() |
556 if s.closed { | 556 if s.closed { |
557 s.mu.Unlock() | 557 s.mu.Unlock() |
558 err = errors.New("sql: statement is closed") | 558 err = errors.New("sql: statement is closed") |
559 return | 559 return |
560 } | 560 } |
561 | 561 |
562 // In a transaction, we always use the connection that the | 562 // In a transaction, we always use the connection that the |
563 // transaction was created on. | 563 // transaction was created on. |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 if rs.closed { | 719 if rs.closed { |
720 return false | 720 return false |
721 } | 721 } |
722 if rs.lasterr != nil { | 722 if rs.lasterr != nil { |
723 return false | 723 return false |
724 } | 724 } |
725 if rs.lastcols == nil { | 725 if rs.lastcols == nil { |
726 rs.lastcols = make([]interface{}, len(rs.rowsi.Columns())) | 726 rs.lastcols = make([]interface{}, len(rs.rowsi.Columns())) |
727 } | 727 } |
728 rs.lasterr = rs.rowsi.Next(rs.lastcols) | 728 rs.lasterr = rs.rowsi.Next(rs.lastcols) |
| 729 if rs.lasterr == io.EOF { |
| 730 rs.Close() |
| 731 } |
729 return rs.lasterr == nil | 732 return rs.lasterr == nil |
730 } | 733 } |
731 | 734 |
732 // Err returns the error, if any, that was encountered during iteration. | 735 // Err returns the error, if any, that was encountered during iteration. |
733 func (rs *Rows) Err() error { | 736 func (rs *Rows) Err() error { |
734 if rs.lasterr == io.EOF { | 737 if rs.lasterr == io.EOF { |
735 return nil | 738 return nil |
736 } | 739 } |
737 return rs.lasterr | 740 return rs.lasterr |
738 } | 741 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 | 820 |
818 // A Result summarizes an executed SQL command. | 821 // A Result summarizes an executed SQL command. |
819 type Result interface { | 822 type Result interface { |
820 LastInsertId() (int64, error) | 823 LastInsertId() (int64, error) |
821 RowsAffected() (int64, error) | 824 RowsAffected() (int64, error) |
822 } | 825 } |
823 | 826 |
824 type result struct { | 827 type result struct { |
825 driver.Result | 828 driver.Result |
826 } | 829 } |
OLD | NEW |