Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gosqlite
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
gosqlite
Commits
7beeeaa5
Commit
7beeeaa5
authored
Apr 25, 2013
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changes Stmt.ScanValue method signature for driver.
parent
440c681f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
14 deletions
+31
-14
driver.go
driver.go
+4
-7
stmt.go
stmt.go
+13
-7
stmt_test.go
stmt_test.go
+14
-0
No files found.
driver.go
View file @
7beeeaa5
...
...
@@ -175,13 +175,10 @@ func (r *rowsImpl) Next(dest []driver.Value) error {
return
io
.
EOF
}
for
i
:=
range
dest
{
value
:=
r
.
s
.
s
.
ScanValue
(
i
)
switch
value
:=
value
.
(
type
)
{
case
string
:
// "All string values must be converted to []byte."
dest
[
i
]
=
[]
byte
(
value
)
default
:
dest
[
i
]
=
value
}
dest
[
i
]
=
r
.
s
.
s
.
ScanValue
(
i
,
true
)
/*if !driver.IsScanValue(dest[i]) {
panic("Invalid type returned by ScanValue")
}*/
}
return
nil
}
...
...
stmt.go
View file @
7beeeaa5
...
...
@@ -656,10 +656,10 @@ func (s *Stmt) ScanByIndex(index int, value interface{}) (bool, error) {
case
*
time
.
Time
:
// go fix doesn't like this type!
*
value
,
isNull
,
err
=
s
.
ScanTime
(
index
)
case
*
interface
{}
:
*
value
=
s
.
ScanValue
(
index
)
*
value
=
s
.
ScanValue
(
index
,
false
)
isNull
=
*
value
==
nil
case
func
(
interface
{})
(
bool
,
error
)
:
isNull
,
err
=
value
(
s
.
ScanValue
(
index
))
isNull
,
err
=
value
(
s
.
ScanValue
(
index
,
false
))
default
:
return
false
,
s
.
specificError
(
"unsupported type in Scan: %T"
,
value
)
}
...
...
@@ -672,20 +672,26 @@ func (s *Stmt) ScanByIndex(index int, value interface{}) (bool, error) {
// Destination type is decided by SQLite.
// The returned value will be of one of the following types:
// nil
// string
// string
(exception if blob is true)
// int64
// float64
// []byte
//
// Calls sqlite3_column_(blob|double|int|int64|text) depending on columns type.
// (See http://sqlite.org/c3ref/column_blob.html)
func
(
s
*
Stmt
)
ScanValue
(
index
int
)
(
value
interface
{})
{
func
(
s
*
Stmt
)
ScanValue
(
index
int
,
blob
bool
)
(
value
interface
{})
{
switch
s
.
ColumnType
(
index
)
{
case
Null
:
value
=
nil
case
Text
:
p
:=
C
.
sqlite3_column_text
(
s
.
stmt
,
C
.
int
(
index
))
value
=
C
.
GoString
((
*
C
.
char
)(
unsafe
.
Pointer
(
p
)))
if
blob
{
p
:=
C
.
sqlite3_column_blob
(
s
.
stmt
,
C
.
int
(
index
))
n
:=
C
.
sqlite3_column_bytes
(
s
.
stmt
,
C
.
int
(
index
))
value
=
C
.
GoBytes
(
p
,
n
)
}
else
{
p
:=
C
.
sqlite3_column_text
(
s
.
stmt
,
C
.
int
(
index
))
value
=
C
.
GoString
((
*
C
.
char
)(
unsafe
.
Pointer
(
p
)))
}
case
Integer
:
value
=
int64
(
C
.
sqlite3_column_int64
(
s
.
stmt
,
C
.
int
(
index
)))
case
Float
:
...
...
@@ -704,7 +710,7 @@ func (s *Stmt) ScanValue(index int) (value interface{}) {
// ScanValues is like ScanValue on several columns.
func
(
s
*
Stmt
)
ScanValues
(
values
[]
interface
{})
{
for
i
:=
range
values
{
values
[
i
]
=
s
.
ScanValue
(
i
)
values
[
i
]
=
s
.
ScanValue
(
i
,
false
)
}
}
...
...
stmt_test.go
View file @
7beeeaa5
...
...
@@ -384,3 +384,17 @@ func TestScanValues(t *testing.T) {
assertEquals
(
t
,
"expected %v but got %v"
,
nil
,
values
[
1
])
assertEquals
(
t
,
"expected %v but got %v"
,
int64
(
0
),
values
[
2
])
}
func
TestScanBytes
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
checkClose
(
db
,
t
)
s
,
err
:=
db
.
Prepare
(
"SELECT 'test'"
)
checkNoError
(
t
,
err
,
"prepare error: %s"
)
defer
checkFinalize
(
s
,
t
)
if
!
Must
(
s
.
Next
())
{
t
.
Fatal
(
"no result"
)
}
blob
,
_
:=
s
.
ScanBlob
(
0
)
assertEquals
(
t
,
"expected %v but got %v"
,
"test"
,
string
(
blob
))
}
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