Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
9d52fe22
Commit
9d52fe22
authored
Dec 08, 2011
by
David Symonds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exp/sql: simplify some string conversions.
R=bradfitz CC=golang-dev
https://golang.org/cl/5451112
parent
5e98505b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
13 deletions
+4
-13
src/pkg/exp/sql/convert.go
src/pkg/exp/sql/convert.go
+3
-12
src/pkg/exp/sql/convert_test.go
src/pkg/exp/sql/convert_test.go
+1
-1
No files found.
src/pkg/exp/sql/convert.go
View file @
9d52fe22
...
...
@@ -95,35 +95,26 @@ func convertAssign(dest, src interface{}) error {
switch
dv
.
Kind
()
{
case
reflect
.
Int
,
reflect
.
Int8
,
reflect
.
Int16
,
reflect
.
Int32
,
reflect
.
Int64
:
s
:=
asString
(
src
)
i64
,
err
:=
strconv
.
ParseInt
(
s
,
10
,
64
)
i64
,
err
:=
strconv
.
ParseInt
(
s
,
10
,
dv
.
Type
()
.
Bits
()
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"converting string %q to a %s: %v"
,
s
,
dv
.
Kind
(),
err
)
}
if
dv
.
OverflowInt
(
i64
)
{
return
fmt
.
Errorf
(
"string %q overflows %s"
,
s
,
dv
.
Kind
())
}
dv
.
SetInt
(
i64
)
return
nil
case
reflect
.
Uint
,
reflect
.
Uint8
,
reflect
.
Uint16
,
reflect
.
Uint32
,
reflect
.
Uint64
:
s
:=
asString
(
src
)
u64
,
err
:=
strconv
.
ParseUint
(
s
,
10
,
64
)
u64
,
err
:=
strconv
.
ParseUint
(
s
,
10
,
dv
.
Type
()
.
Bits
()
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"converting string %q to a %s: %v"
,
s
,
dv
.
Kind
(),
err
)
}
if
dv
.
OverflowUint
(
u64
)
{
return
fmt
.
Errorf
(
"string %q overflows %s"
,
s
,
dv
.
Kind
())
}
dv
.
SetUint
(
u64
)
return
nil
case
reflect
.
Float32
,
reflect
.
Float64
:
s
:=
asString
(
src
)
f64
,
err
:=
strconv
.
ParseFloat
(
s
,
64
)
f64
,
err
:=
strconv
.
ParseFloat
(
s
,
dv
.
Type
()
.
Bits
()
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"converting string %q to a %s: %v"
,
s
,
dv
.
Kind
(),
err
)
}
if
dv
.
OverflowFloat
(
f64
)
{
return
fmt
.
Errorf
(
"value %q overflows %s"
,
s
,
dv
.
Kind
())
}
dv
.
SetFloat
(
f64
)
return
nil
}
...
...
src/pkg/exp/sql/convert_test.go
View file @
9d52fe22
...
...
@@ -55,7 +55,7 @@ var conversionTests = []conversionTest{
// Strings to integers
{
s
:
"255"
,
d
:
&
scanuint8
,
wantuint
:
255
},
{
s
:
"256"
,
d
:
&
scanuint8
,
wanterr
:
`
string "256" overflows uint8
`
},
{
s
:
"256"
,
d
:
&
scanuint8
,
wanterr
:
`
converting string "256" to a uint8: parsing "256": value out of range
`
},
{
s
:
"256"
,
d
:
&
scanuint16
,
wantuint
:
256
},
{
s
:
"-1"
,
d
:
&
scanint
,
wantint
:
-
1
},
{
s
:
"foo"
,
d
:
&
scanint
,
wanterr
:
`converting string "foo" to a int: parsing "foo": invalid syntax`
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment