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
d7bba9c3
Commit
d7bba9c3
authored
May 14, 2013
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add suppport to standard sql.Scanner in Scan methods.
parent
e5176627
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
9 deletions
+17
-9
example_test.go
example_test.go
+12
-7
stmt.go
stmt.go
+5
-2
No files found.
example_test.go
View file @
d7bba9c3
...
@@ -38,6 +38,7 @@ func Example() {
...
@@ -38,6 +38,7 @@ func Example() {
fmt
.
Println
(
name
)
fmt
.
Println
(
name
)
return
return
})
})
check
(
err
)
// Output: gosqlite driver
// Output: gosqlite driver
}
}
...
@@ -117,10 +118,18 @@ func ExampleStmt_NamedScan() {
...
@@ -117,10 +118,18 @@ func ExampleStmt_NamedScan() {
fmt
.
Println
(
id
,
name
)
fmt
.
Println
(
id
,
name
)
return
return
})
})
check
(
err
)
// Output: 1 Go
// Output: 1 Go
// 2 SQLite
// 2 SQLite
}
}
type
YesOrNo
bool
func
(
b
*
YesOrNo
)
Scan
(
src
interface
{})
error
{
*
b
=
YesOrNo
(
src
==
"Y"
||
src
==
"yes"
)
return
nil
}
func
ExampleStmt_Scan
()
{
func
ExampleStmt_Scan
()
{
db
,
err
:=
sqlite
.
Open
(
":memory:"
)
db
,
err
:=
sqlite
.
Open
(
":memory:"
)
check
(
err
)
check
(
err
)
...
@@ -132,20 +141,16 @@ func ExampleStmt_Scan() {
...
@@ -132,20 +141,16 @@ func ExampleStmt_Scan() {
var
id
int
var
id
int
var
name
string
var
name
string
var
status
bool
var
status
YesOrNo
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
,
converter
);
err
!=
nil
{
if
err
=
s
.
Scan
(
&
id
,
&
name
,
&
status
);
err
!=
nil
{
return
return
}
}
fmt
.
Println
(
id
,
name
,
status
)
fmt
.
Println
(
id
,
name
,
status
)
return
return
})
})
check
(
err
)
// Output: 1 Go true
// Output: 1 Go true
// 2 SQLite true
// 2 SQLite true
}
}
...
...
stmt.go
View file @
d7bba9c3
...
@@ -32,6 +32,7 @@ static int my_prepare_v2(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt
...
@@ -32,6 +32,7 @@ static int my_prepare_v2(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt
import
"C"
import
"C"
import
(
import
(
"database/sql"
"errors"
"errors"
"fmt"
"fmt"
"time"
"time"
...
@@ -682,11 +683,13 @@ func (s *Stmt) ScanByIndex(index int, value interface{}) (bool, error) {
...
@@ -682,11 +683,13 @@ func (s *Stmt) ScanByIndex(index int, value interface{}) (bool, error) {
}
}
case
*
time
.
Time
:
// go fix doesn't like this type!
case
*
time
.
Time
:
// go fix doesn't like this type!
*
value
,
isNull
,
err
=
s
.
ScanTime
(
index
)
*
value
,
isNull
,
err
=
s
.
ScanTime
(
index
)
case
sql
.
Scanner
:
v
:=
s
.
ScanValue
(
index
,
false
)
err
=
value
.
Scan
(
v
)
isNull
=
v
==
nil
case
*
interface
{}
:
case
*
interface
{}
:
*
value
=
s
.
ScanValue
(
index
,
false
)
*
value
=
s
.
ScanValue
(
index
,
false
)
isNull
=
*
value
==
nil
isNull
=
*
value
==
nil
case
func
(
interface
{})
(
bool
,
error
)
:
isNull
,
err
=
value
(
s
.
ScanValue
(
index
,
false
))
default
:
default
:
return
false
,
s
.
specificError
(
"unsupported type in Scan: %T"
,
value
)
return
false
,
s
.
specificError
(
"unsupported type in Scan: %T"
,
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