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
02b7f855
Commit
02b7f855
authored
Feb 04, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support to pointer to pointer in ScanByIndex.
parent
fed8fd1d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
6 deletions
+96
-6
sqlite.go
sqlite.go
+70
-6
sqlite_test.go
sqlite_test.go
+26
-0
No files found.
sqlite.go
View file @
02b7f855
...
...
@@ -790,7 +790,7 @@ func (s *Stmt) ColumnType(index int) Type {
// var id int
// var name string
// for sqlite.Must(stmt.Next()) {
// stmt.NamedScan("name", &name, "id", &id)
//
err =
stmt.NamedScan("name", &name, "id", &id)
// // TODO error handling
// fmt.Println(id, name)
// }
...
...
@@ -909,18 +909,84 @@ func (s *Stmt) ScanByIndex(index int, value interface{}) (bool, error) {
case
nil
:
case
*
string
:
*
value
,
isNull
=
s
.
ScanText
(
index
)
case
**
string
:
var
st
string
st
,
isNull
=
s
.
ScanText
(
index
)
if
isNull
{
*
value
=
nil
}
else
{
**
value
=
st
}
case
*
int
:
*
value
,
isNull
,
err
=
s
.
ScanInt
(
index
)
case
**
int
:
var
i
int
i
,
isNull
,
err
=
s
.
ScanInt
(
index
)
if
err
==
nil
{
if
isNull
{
*
value
=
nil
}
else
{
**
value
=
i
}
}
case
*
int64
:
*
value
,
isNull
,
err
=
s
.
ScanInt64
(
index
)
case
**
int64
:
var
i
int64
i
,
isNull
,
err
=
s
.
ScanInt64
(
index
)
if
err
==
nil
{
if
isNull
{
*
value
=
nil
}
else
{
**
value
=
i
}
}
case
*
byte
:
*
value
,
isNull
,
err
=
s
.
ScanByte
(
index
)
case
**
byte
:
var
b
byte
b
,
isNull
,
err
=
s
.
ScanByte
(
index
)
if
err
==
nil
{
if
isNull
{
*
value
=
nil
}
else
{
**
value
=
b
}
}
case
*
bool
:
*
value
,
isNull
,
err
=
s
.
ScanBool
(
index
)
case
**
bool
:
var
b
bool
b
,
isNull
,
err
=
s
.
ScanBool
(
index
)
if
err
==
nil
{
if
isNull
{
*
value
=
nil
}
else
{
**
value
=
b
}
}
case
*
float64
:
*
value
,
isNull
,
err
=
s
.
ScanDouble
(
index
)
case
**
float64
:
var
f
float64
f
,
isNull
,
err
=
s
.
ScanDouble
(
index
)
if
err
==
nil
{
if
isNull
{
*
value
=
nil
}
else
{
**
value
=
f
}
}
case
*
[]
byte
:
*
value
,
isNull
=
s
.
ScanBlob
(
index
)
case
**
[]
byte
:
var
bs
[]
byte
bs
,
isNull
=
s
.
ScanBlob
(
index
)
if
isNull
{
*
value
=
nil
}
else
{
**
value
=
bs
}
case
*
interface
{}
:
*
value
=
s
.
ScanValue
(
index
)
isNull
=
*
value
==
nil
...
...
@@ -948,8 +1014,7 @@ func (s *Stmt) ScanValue(index int) (value interface{}) {
value
=
nil
case
Text
:
p
:=
C
.
sqlite3_column_text
(
s
.
stmt
,
C
.
int
(
index
))
n
:=
C
.
sqlite3_column_bytes
(
s
.
stmt
,
C
.
int
(
index
))
value
=
C
.
GoStringN
((
*
C
.
char
)(
unsafe
.
Pointer
(
p
)),
n
)
value
=
C
.
GoString
((
*
C
.
char
)(
unsafe
.
Pointer
(
p
)))
case
Integer
:
value
=
int64
(
C
.
sqlite3_column_int64
(
s
.
stmt
,
C
.
int
(
index
)))
case
Float
:
...
...
@@ -966,7 +1031,7 @@ func (s *Stmt) ScanValue(index int) (value interface{}) {
// Like ScanValue on several columns
func
(
s
*
Stmt
)
ScanValues
(
values
[]
interface
{})
{
for
i
:=
0
;
i
<
len
(
values
);
i
++
{
for
i
:=
range
values
{
values
[
i
]
=
s
.
ScanValue
(
i
)
}
}
...
...
@@ -980,8 +1045,7 @@ func (s *Stmt) ScanText(index int) (value string, isNull bool) {
if
p
==
nil
{
isNull
=
true
}
else
{
n
:=
C
.
sqlite3_column_bytes
(
s
.
stmt
,
C
.
int
(
index
))
value
=
C
.
GoStringN
((
*
C
.
char
)(
unsafe
.
Pointer
(
p
)),
n
)
value
=
C
.
GoString
((
*
C
.
char
)(
unsafe
.
Pointer
(
p
)))
}
return
}
...
...
sqlite_test.go
View file @
02b7f855
...
...
@@ -379,3 +379,29 @@ func TestLoadExtension(t *testing.T) {
checkNoError(t, err, "load extension error: %s")
}
*/
func
TestScanNull
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
db
.
Close
()
s
,
err
:=
db
.
Prepare
(
"select null"
)
checkNoError
(
t
,
err
,
"prepare error: %s"
)
defer
s
.
Finalize
()
if
!
Must
(
s
.
Next
())
{
t
.
Fatal
(
"no result"
)
}
var
pi
*
int
null
:=
Must
(
s
.
ScanByIndex
(
0
,
&
pi
))
if
!
null
{
t
.
Errorf
(
"Expected null value"
)
}
else
if
pi
!=
nil
{
t
.
Errorf
(
"Expected nil but got %p
\n
"
,
pi
)
}
var
ps
*
string
null
=
Must
(
s
.
ScanByIndex
(
0
,
&
ps
))
if
!
null
{
t
.
Errorf
(
"Expected null value"
)
}
else
if
ps
!=
nil
{
t
.
Errorf
(
"Expected nil but got %p
\n
"
,
ps
)
}
}
\ No newline at end of file
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