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
23b5fbc2
Commit
23b5fbc2
authored
Nov 23, 2013
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix scanning/binding of int on 64-bits machine.
parent
498b6a92
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
2 deletions
+65
-2
blob.go
blob.go
+2
-1
stmt.go
stmt.go
+45
-1
stmt_test.go
stmt_test.go
+18
-0
No files found.
blob.go
View file @
23b5fbc2
...
...
@@ -32,7 +32,7 @@ type BlobReadWriter struct {
}
// ZeroBlobLength is used to reserve space for a BLOB that is later written.
type
ZeroBlobLength
int
type
ZeroBlobLength
int
32
// NewBlobReader opens a BLOB for incremental I/O in read-only mode.
//
...
...
@@ -117,6 +117,7 @@ func (r *BlobReader) Read(v []byte) (int, error) {
}
// Seek sets the offset for the next Read or Write to offset.
// SQLite is limited to 32-bits offset.
func
(
r
*
BlobReader
)
Seek
(
offset
int64
,
whence
int
)
(
int64
,
error
)
{
switch
whence
{
case
0
:
// SEEK_SET
...
...
stmt.go
View file @
23b5fbc2
...
...
@@ -42,6 +42,10 @@ import (
"unsafe"
)
const
(
i64
=
unsafe
.
Sizeof
(
int
(
0
))
>
4
)
type
StmtError
struct
{
ConnError
s
*
Stmt
...
...
@@ -341,6 +345,12 @@ func (s *Stmt) BindByIndex(index int, value interface{}) error {
rv
=
C
.
my_bind_text
(
s
.
stmt
,
i
,
cs
,
l
)
}
case
int
:
if
i64
{
rv
=
C
.
sqlite3_bind_int64
(
s
.
stmt
,
i
,
C
.
sqlite3_int64
(
value
))
}
else
{
rv
=
C
.
sqlite3_bind_int
(
s
.
stmt
,
i
,
C
.
int
(
value
))
}
case
int32
:
rv
=
C
.
sqlite3_bind_int
(
s
.
stmt
,
i
,
C
.
int
(
value
))
case
int64
:
rv
=
C
.
sqlite3_bind_int64
(
s
.
stmt
,
i
,
C
.
sqlite3_int64
(
value
))
...
...
@@ -653,6 +663,18 @@ func (s *Stmt) ScanByIndex(index int, value interface{}) (bool, error) {
**
value
=
i
}
}
case
*
int32
:
*
value
,
isNull
,
err
=
s
.
ScanInt32
(
index
)
case
**
int32
:
var
i
int32
i
,
isNull
,
err
=
s
.
ScanInt32
(
index
)
if
err
==
nil
{
if
isNull
{
*
value
=
nil
}
else
{
**
value
=
i
}
}
case
*
int64
:
*
value
,
isNull
,
err
=
s
.
ScanInt64
(
index
)
case
**
int64
:
...
...
@@ -856,7 +878,29 @@ func (s *Stmt) ScanInt(index int) (value int, isNull bool, err error) {
if
s
.
CheckTypeMismatch
{
err
=
s
.
checkTypeMismatch
(
ctype
,
Integer
)
}
value
=
int
(
C
.
sqlite3_column_int
(
s
.
stmt
,
C
.
int
(
index
)))
if
i64
{
value
=
int
(
C
.
sqlite3_column_int64
(
s
.
stmt
,
C
.
int
(
index
)))
}
else
{
value
=
int
(
C
.
sqlite3_column_int
(
s
.
stmt
,
C
.
int
(
index
)))
}
}
return
}
// ScanInt32 scans result value from a query.
// The leftmost column/index is number 0.
// Returns true when column is null.
// (See sqlite3_column_int: http://sqlite.org/c3ref/column_blob.html)
// TODO Factorize with ScanByte, ScanBool
func
(
s
*
Stmt
)
ScanInt32
(
index
int
)
(
value
int32
,
isNull
bool
,
err
error
)
{
ctype
:=
s
.
ColumnType
(
index
)
if
ctype
==
Null
{
isNull
=
true
}
else
{
if
s
.
CheckTypeMismatch
{
err
=
s
.
checkTypeMismatch
(
ctype
,
Integer
)
}
value
=
int32
(
C
.
sqlite3_column_int
(
s
.
stmt
,
C
.
int
(
index
)))
}
return
}
...
...
stmt_test.go
View file @
23b5fbc2
...
...
@@ -7,9 +7,11 @@ package sqlite_test
import
(
"github.com/bmizerany/assert"
.
"github.com/gwenn/gosqlite"
"math"
"reflect"
"testing"
"time"
"unsafe"
)
func
checkFinalize
(
s
*
Stmt
,
t
*
testing
.
T
)
{
...
...
@@ -469,3 +471,19 @@ func TestColumnType(t *testing.T) {
assert
.
Equal
(
t
,
Null
,
s
.
ColumnType
(
col
),
"column type"
)
}
}
func
TestIntOnArch64
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
checkClose
(
db
,
t
)
createTable
(
db
,
t
)
if
unsafe
.
Sizeof
(
int
(
0
))
>
4
{
var
i
int
=
math
.
MaxInt64
err
:=
db
.
Exec
(
"INSERT INTO test (int_num) VALUES (?)"
,
i
)
checkNoError
(
t
,
err
,
"insert error: %s"
)
var
r
int
err
=
db
.
OneValue
(
"SELECT int_num FROM test"
,
&
r
)
checkNoError
(
t
,
err
,
"select error: %s"
)
assert
.
Equal
(
t
,
i
,
r
,
"int truncated"
)
}
}
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