Skip to content

Commit 8d81c2f

Browse files
committed
fix race
1 parent 58ed4a0 commit 8d81c2f

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

sqlite3.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,10 +1018,7 @@ func (rc *SQLiteRows) Columns() []string {
10181018
return rc.cols
10191019
}
10201020

1021-
// DeclTypes return column types.
1022-
func (rc *SQLiteRows) DeclTypes() []string {
1023-
rc.s.mu.Lock()
1024-
defer rc.s.mu.Unlock()
1021+
func (rc *SQLiteRows) declTypes() []string {
10251022
if rc.s.s != nil && rc.decltype == nil {
10261023
rc.decltype = make([]string, rc.nc)
10271024
for i := 0; i < rc.nc; i++ {
@@ -1031,30 +1028,33 @@ func (rc *SQLiteRows) DeclTypes() []string {
10311028
return rc.decltype
10321029
}
10331030

1031+
// DeclTypes return column types.
1032+
func (rc *SQLiteRows) DeclTypes() []string {
1033+
rc.s.mu.Lock()
1034+
defer rc.s.mu.Unlock()
1035+
return rc.declTypes()
1036+
}
1037+
10341038
// Next move cursor to next.
10351039
func (rc *SQLiteRows) Next(dest []driver.Value) error {
10361040
if rc.s.closed {
10371041
return io.EOF
10381042
}
10391043
rc.s.mu.Lock()
1044+
defer rc.s.mu.Unlock()
10401045
rv := C.sqlite3_step(rc.s.s)
10411046
if rv == C.SQLITE_DONE {
1042-
rc.s.mu.Unlock()
10431047
return io.EOF
10441048
}
10451049
if rv != C.SQLITE_ROW {
1046-
defer rc.s.mu.Unlock()
10471050
rv = C.sqlite3_reset(rc.s.s)
10481051
if rv != C.SQLITE_OK {
10491052
return rc.s.c.lastError()
10501053
}
10511054
return nil
10521055
}
10531056

1054-
rc.DeclTypes()
1055-
1056-
rc.s.mu.Lock()
1057-
defer rc.s.mu.Unlock()
1057+
rc.declTypes()
10581058

10591059
for i := range dest {
10601060
switch C.sqlite3_column_type(rc.s.s, C.int(i)) {

0 commit comments

Comments
 (0)