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

Delta Between Two Patch Sets: src/pkg/database/sql/convert.go

Issue 5630052: code review 5630052: database/sql: treat pointers as nullable types like enc...
Left Patch Set: diff -r d920eda8b6ac https://go.googlecode.com/hg/ Created 12 years, 1 month ago
Right Patch Set: diff -r 82bac8cdab6b50b9f42f1c203b694c0915be7fa6 https://go.googlecode.com/hg/ Created 12 years, 1 month 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/pkg/database/sql/convert_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 // Type conversions for Scan. 5 // Type conversions for Scan.
6 6
7 package sql 7 package sql
8 8
9 import ( 9 import (
10 "database/sql/driver" 10 "database/sql/driver"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 return nil 42 return nil
43 case *[]byte: 43 case *[]byte:
44 *d = []byte(s) 44 *d = []byte(s)
45 return nil 45 return nil
46 } 46 }
47 case []byte: 47 case []byte:
48 switch d := dest.(type) { 48 switch d := dest.(type) {
49 case *string: 49 case *string:
50 *d = string(s) 50 *d = string(s)
51 return nil 51 return nil
52 case *interface{}:
53 bcopy := make([]byte, len(s))
54 copy(bcopy, s)
55 *d = bcopy
56 return nil
52 case *[]byte: 57 case *[]byte:
53 *d = s 58 *d = s
54 return nil 59 return nil
55 } 60 }
56 case nil: 61 case nil:
57 switch d := dest.(type) { 62 switch d := dest.(type) {
58 case *[]byte: 63 case *[]byte:
59 *d = nil 64 *d = nil
60 return nil 65 return nil
61 } 66 }
(...skipping 11 matching lines...) Expand all
73 reflect.Float32, reflect.Float64: 78 reflect.Float32, reflect.Float64:
74 *d = fmt.Sprintf("%v", src) 79 *d = fmt.Sprintf("%v", src)
75 return nil 80 return nil
76 } 81 }
77 case *bool: 82 case *bool:
78 bv, err := driver.Bool.ConvertValue(src) 83 bv, err := driver.Bool.ConvertValue(src)
79 if err == nil { 84 if err == nil {
80 *d = bv.(bool) 85 *d = bv.(bool)
81 } 86 }
82 return err 87 return err
88 case *interface{}:
89 *d = src
90 return nil
83 } 91 }
84 92
85 if scanner, ok := dest.(ScannerInto); ok { 93 if scanner, ok := dest.(ScannerInto); ok {
86 return scanner.ScanInto(src) 94 return scanner.ScanInto(src)
87 } 95 }
88 96
89 dpv := reflect.ValueOf(dest) 97 dpv := reflect.ValueOf(dest)
90 if dpv.Kind() != reflect.Ptr { 98 if dpv.Kind() != reflect.Ptr {
91 return errors.New("destination not a pointer") 99 return errors.New("destination not a pointer")
92 } 100 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 149
142 func asString(src interface{}) string { 150 func asString(src interface{}) string {
143 switch v := src.(type) { 151 switch v := src.(type) {
144 case string: 152 case string:
145 return v 153 return v
146 case []byte: 154 case []byte:
147 return string(v) 155 return string(v)
148 } 156 }
149 return fmt.Sprintf("%v", src) 157 return fmt.Sprintf("%v", src)
150 } 158 }
LEFTRIGHT

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