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
e10dbb7e
Commit
e10dbb7e
authored
Nov 22, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A conversion func can be passed to Scan methods.
parent
fe6e2908
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
5 deletions
+16
-5
example_test.go
example_test.go
+12
-5
stmt.go
stmt.go
+4
-0
No files found.
example_test.go
View file @
e10dbb7e
...
@@ -125,21 +125,28 @@ func ExampleStmt_Scan() {
...
@@ -125,21 +125,28 @@ func ExampleStmt_Scan() {
check
(
err
)
check
(
err
)
defer
db
.
Close
()
defer
db
.
Close
()
s
,
err
:=
db
.
Prepare
(
"SELECT 1 as id, 'Go' as name
UNION SELECT 2, 'SQLite
'"
)
s
,
err
:=
db
.
Prepare
(
"SELECT 1 as id, 'Go' as name
, 'Y' as status UNION SELECT 2, 'SQLite', 'yes
'"
)
check
(
err
)
check
(
err
)
defer
s
.
Finalize
()
defer
s
.
Finalize
()
var
id
int
var
id
int
var
name
string
var
name
string
var
status
bool
converter
:=
func
(
value
interface
{})
(
bool
,
error
)
{
status
=
value
==
"Y"
||
value
==
"yes"
return
false
,
nil
}
err
=
s
.
Select
(
func
(
s
*
sqlite
.
Stmt
)
(
err
error
)
{
err
=
s
.
Select
(
func
(
s
*
sqlite
.
Stmt
)
(
err
error
)
{
if
err
=
s
.
Scan
(
&
id
,
&
name
);
err
!=
nil
{
if
err
=
s
.
Scan
(
&
id
,
&
name
,
converter
);
err
!=
nil
{
return
return
}
}
fmt
.
Println
(
id
,
name
)
fmt
.
Println
(
id
,
name
,
status
)
return
return
})
})
// Output: 1 Go
// Output: 1 Go
true
// 2 SQLite
// 2 SQLite
true
}
}
func
ExampleNewBackup
()
{
func
ExampleNewBackup
()
{
...
...
stmt.go
View file @
e10dbb7e
...
@@ -68,6 +68,7 @@ func (s *Stmt) specificError(msg string, a ...interface{}) error {
...
@@ -68,6 +68,7 @@ func (s *Stmt) specificError(msg string, a ...interface{}) error {
}
}
// SQL statement
// SQL statement
// (See http://sqlite.org/c3ref/stmt.html)
type
Stmt
struct
{
type
Stmt
struct
{
c
*
Conn
c
*
Conn
stmt
*
C
.
sqlite3_stmt
stmt
*
C
.
sqlite3_stmt
...
@@ -562,6 +563,7 @@ func (s *Stmt) ScanByName(name string, value interface{}) (bool, error) {
...
@@ -562,6 +563,7 @@ func (s *Stmt) ScanByName(name string, value interface{}) (bool, error) {
// (*)*float64
// (*)*float64
// (*)*[]byte
// (*)*[]byte
// *interface{}
// *interface{}
// func(interface{}) (bool, error)
//
//
// Returns true when column is null.
// Returns true when column is null.
// Calls sqlite3_column_(blob|double|int|int64|text) depending on arg type.
// Calls sqlite3_column_(blob|double|int|int64|text) depending on arg type.
...
@@ -656,6 +658,8 @@ func (s *Stmt) ScanByIndex(index int, value interface{}) (bool, error) {
...
@@ -656,6 +658,8 @@ func (s *Stmt) ScanByIndex(index int, value interface{}) (bool, error) {
case
*
interface
{}
:
case
*
interface
{}
:
*
value
=
s
.
ScanValue
(
index
)
*
value
=
s
.
ScanValue
(
index
)
isNull
=
*
value
==
nil
isNull
=
*
value
==
nil
case
func
(
interface
{})
(
bool
,
error
)
:
isNull
,
err
=
value
(
s
.
ScanValue
(
index
))
default
:
default
:
return
false
,
s
.
specificError
(
"unsupported type in Scan: %s"
,
reflect
.
TypeOf
(
value
))
return
false
,
s
.
specificError
(
"unsupported type in Scan: %s"
,
reflect
.
TypeOf
(
value
))
}
}
...
...
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