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 "database/sql/driver" | 10 "database/sql/driver" |
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1245 } | 1245 } |
1246 if len(dest) != len(rs.lastcols) { | 1246 if len(dest) != len(rs.lastcols) { |
1247 return fmt.Errorf("sql: expected %d destination arguments in Sca
n, not %d", len(rs.lastcols), len(dest)) | 1247 return fmt.Errorf("sql: expected %d destination arguments in Sca
n, not %d", len(rs.lastcols), len(dest)) |
1248 } | 1248 } |
1249 for i, sv := range rs.lastcols { | 1249 for i, sv := range rs.lastcols { |
1250 err := convertAssign(dest[i], sv) | 1250 err := convertAssign(dest[i], sv) |
1251 if err != nil { | 1251 if err != nil { |
1252 return fmt.Errorf("sql: Scan error on column index %d: %
v", i, err) | 1252 return fmt.Errorf("sql: Scan error on column index %d: %
v", i, err) |
1253 } | 1253 } |
1254 } | 1254 } |
1255 for _, dp := range dest { | |
1256 b, ok := dp.(*[]byte) | |
1257 if !ok { | |
1258 continue | |
1259 } | |
1260 if *b == nil { | |
1261 // If the []byte is now nil (for a NULL value), | |
1262 // don't fall through to below which would | |
1263 // turn it into a non-nil 0-length byte slice | |
1264 continue | |
1265 } | |
1266 if _, ok = dp.(*RawBytes); ok { | |
1267 continue | |
1268 } | |
1269 clone := make([]byte, len(*b)) | |
1270 copy(clone, *b) | |
1271 *b = clone | |
1272 } | |
1273 return nil | 1255 return nil |
1274 } | 1256 } |
1275 | 1257 |
1276 // Close closes the Rows, preventing further enumeration. If the | 1258 // Close closes the Rows, preventing further enumeration. If the |
1277 // end is encountered, the Rows are closed automatically. Close | 1259 // end is encountered, the Rows are closed automatically. Close |
1278 // is idempotent. | 1260 // is idempotent. |
1279 func (rs *Rows) Close() error { | 1261 func (rs *Rows) Close() error { |
1280 if rs.closed { | 1262 if rs.closed { |
1281 return nil | 1263 return nil |
1282 } | 1264 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1363 var buf [1024]byte | 1345 var buf [1024]byte |
1364 return string(buf[:runtime.Stack(buf[:], false)]) | 1346 return string(buf[:runtime.Stack(buf[:], false)]) |
1365 } | 1347 } |
1366 | 1348 |
1367 // withLock runs while holding lk. | 1349 // withLock runs while holding lk. |
1368 func withLock(lk sync.Locker, fn func()) { | 1350 func withLock(lk sync.Locker, fn func()) { |
1369 lk.Lock() | 1351 lk.Lock() |
1370 fn() | 1352 fn() |
1371 lk.Unlock() | 1353 lk.Unlock() |
1372 } | 1354 } |
OLD | NEW |