Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Side by Side Diff: src/pkg/database/sql/sql_test.go

Issue 7399046: code review 7399046: database/sql: clarify that DB.Prepare's stmt is safe fo... (Closed)
Patch Set: diff -r bfb45be43e2b https://go.googlecode.com/hg/ Created 12 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/database/sql/sql.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 5 package sql
6 6
7 import ( 7 import (
8 "database/sql/driver" 8 "database/sql/driver"
9 "fmt" 9 "fmt"
10 "reflect" 10 "reflect"
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } { 266 } {
267 if err := stmt.QueryRow(tt.name).Scan(&age); err != nil { 267 if err := stmt.QueryRow(tt.name).Scan(&age); err != nil {
268 t.Errorf("%d: on %q, QueryRow/Scan: %v", n, tt.name, err ) 268 t.Errorf("%d: on %q, QueryRow/Scan: %v", n, tt.name, err )
269 } else if age != tt.want { 269 } else if age != tt.want {
270 t.Errorf("%d: age=%d, want %d", n, age, tt.want) 270 t.Errorf("%d: age=%d, want %d", n, age, tt.want)
271 } 271 }
272 } 272 }
273 273
274 } 274 }
275 275
276 // golang.org/issue/3734
277 func TestStatementQueryRowConcurrent(t *testing.T) {
278 db := newTestDB(t, "people")
279 defer closeDB(t, db)
280 stmt, err := db.Prepare("SELECT|people|age|name=?")
281 if err != nil {
282 t.Fatalf("Prepare: %v", err)
283 }
284 defer stmt.Close()
285
286 const n = 10
287 ch := make(chan error, n)
288 for i := 0; i < n; i++ {
289 go func() {
290 var age int
291 err := stmt.QueryRow("Alice").Scan(&age)
292 if err == nil && age != 1 {
293 err = fmt.Errorf("unexpected age %d", age)
294 }
295 ch <- err
296 }()
297 }
298 for i := 0; i < n; i++ {
299 if err := <-ch; err != nil {
300 t.Error(err)
301 }
302 }
303 }
304
276 // just a test of fakedb itself 305 // just a test of fakedb itself
277 func TestBogusPreboundParameters(t *testing.T) { 306 func TestBogusPreboundParameters(t *testing.T) {
278 db := newTestDB(t, "foo") 307 db := newTestDB(t, "foo")
279 defer closeDB(t, db) 308 defer closeDB(t, db)
280 exec(t, db, "CREATE|t1|name=string,age=int32,dead=bool") 309 exec(t, db, "CREATE|t1|name=string,age=int32,dead=bool")
281 _, err := db.Prepare("INSERT|t1|name=?,age=bogusconversion") 310 _, err := db.Prepare("INSERT|t1|name=?,age=bogusconversion")
282 if err == nil { 311 if err == nil {
283 t.Fatalf("expected error") 312 t.Fatalf("expected error")
284 } 313 }
285 if err.Error() != `fakedb: invalid conversion to int32 from "bogusconver sion"` { 314 if err.Error() != `fakedb: invalid conversion to int32 from "bogusconver sion"` {
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 id := i + 1 689 id := i + 1
661 if err := db.QueryRow("SELECT|t|nullf|id=?", id).Scan(bindVal); err != nil { 690 if err := db.QueryRow("SELECT|t|nullf|id=?", id).Scan(bindVal); err != nil {
662 t.Errorf("id=%d Scan: %v", id, err) 691 t.Errorf("id=%d Scan: %v", id, err)
663 } 692 }
664 bindValDeref := reflect.ValueOf(bindVal).Elem().Interface() 693 bindValDeref := reflect.ValueOf(bindVal).Elem().Interface()
665 if !reflect.DeepEqual(bindValDeref, spec.rows[i].scanNullVal) { 694 if !reflect.DeepEqual(bindValDeref, spec.rows[i].scanNullVal) {
666 t.Errorf("id=%d got %#v, want %#v", id, bindValDeref, sp ec.rows[i].scanNullVal) 695 t.Errorf("id=%d got %#v, want %#v", id, bindValDeref, sp ec.rows[i].scanNullVal)
667 } 696 }
668 } 697 }
669 } 698 }
OLDNEW
« no previous file with comments | « src/pkg/database/sql/sql.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b