This commit is contained in:
Yasuhiro Matsumoto 2017-08-30 19:37:57 +09:00
parent 58ed4a0810
commit 8d81c2f1f8
1 changed files with 10 additions and 10 deletions

View File

@ -1018,10 +1018,7 @@ func (rc *SQLiteRows) Columns() []string {
return rc.cols return rc.cols
} }
// DeclTypes return column types. func (rc *SQLiteRows) declTypes() []string {
func (rc *SQLiteRows) DeclTypes() []string {
rc.s.mu.Lock()
defer rc.s.mu.Unlock()
if rc.s.s != nil && rc.decltype == nil { if rc.s.s != nil && rc.decltype == nil {
rc.decltype = make([]string, rc.nc) rc.decltype = make([]string, rc.nc)
for i := 0; i < rc.nc; i++ { for i := 0; i < rc.nc; i++ {
@ -1031,19 +1028,25 @@ func (rc *SQLiteRows) DeclTypes() []string {
return rc.decltype return rc.decltype
} }
// DeclTypes return column types.
func (rc *SQLiteRows) DeclTypes() []string {
rc.s.mu.Lock()
defer rc.s.mu.Unlock()
return rc.declTypes()
}
// Next move cursor to next. // Next move cursor to next.
func (rc *SQLiteRows) Next(dest []driver.Value) error { func (rc *SQLiteRows) Next(dest []driver.Value) error {
if rc.s.closed { if rc.s.closed {
return io.EOF return io.EOF
} }
rc.s.mu.Lock() rc.s.mu.Lock()
defer rc.s.mu.Unlock()
rv := C.sqlite3_step(rc.s.s) rv := C.sqlite3_step(rc.s.s)
if rv == C.SQLITE_DONE { if rv == C.SQLITE_DONE {
rc.s.mu.Unlock()
return io.EOF return io.EOF
} }
if rv != C.SQLITE_ROW { if rv != C.SQLITE_ROW {
defer rc.s.mu.Unlock()
rv = C.sqlite3_reset(rc.s.s) rv = C.sqlite3_reset(rc.s.s)
if rv != C.SQLITE_OK { if rv != C.SQLITE_OK {
return rc.s.c.lastError() return rc.s.c.lastError()
@ -1051,10 +1054,7 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error {
return nil return nil
} }
rc.DeclTypes() rc.declTypes()
rc.s.mu.Lock()
defer rc.s.mu.Unlock()
for i := range dest { for i := range dest {
switch C.sqlite3_column_type(rc.s.s, C.int(i)) { switch C.sqlite3_column_type(rc.s.s, C.int(i)) {