LEFT | RIGHT |
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 Loading... |
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 Loading... |
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 Loading... |
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 } |
LEFT | RIGHT |