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
989ed582
Commit
989ed582
authored
May 13, 2014
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix some potential int overflows on 64-bit arch.
parent
8967236c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
9 deletions
+24
-9
backup.go
backup.go
+2
-2
function.go
function.go
+12
-3
sqlite.go
sqlite.go
+1
-1
stmt.go
stmt.go
+7
-1
trace.go
trace.go
+2
-2
No files found.
backup.go
View file @
989ed582
...
@@ -45,7 +45,7 @@ type Backup struct {
...
@@ -45,7 +45,7 @@ type Backup struct {
// Step copies up to N pages between the source and destination databases.
// Step copies up to N pages between the source and destination databases.
// (See http://sqlite.org/c3ref/backup_finish.html#sqlite3backupstep)
// (See http://sqlite.org/c3ref/backup_finish.html#sqlite3backupstep)
func
(
b
*
Backup
)
Step
(
npage
int
)
error
{
func
(
b
*
Backup
)
Step
(
npage
int
32
)
error
{
if
b
==
nil
{
if
b
==
nil
{
return
errors
.
New
(
"nil sqlite backup"
)
return
errors
.
New
(
"nil sqlite backup"
)
}
}
...
@@ -78,7 +78,7 @@ func (b *Backup) Status() BackupStatus {
...
@@ -78,7 +78,7 @@ func (b *Backup) Status() BackupStatus {
// Sleeping is disabled if 'sleepNs' is zero or negative.
// Sleeping is disabled if 'sleepNs' is zero or negative.
// Notification is disabled if 'c' is null.
// Notification is disabled if 'c' is null.
// (See http://sqlite.org/c3ref/backup_finish.html#sqlite3backupstep, sqlite3_backup_remaining and sqlite3_backup_pagecount)
// (See http://sqlite.org/c3ref/backup_finish.html#sqlite3backupstep, sqlite3_backup_remaining and sqlite3_backup_pagecount)
func
(
b
*
Backup
)
Run
(
npage
int
,
sleepNs
time
.
Duration
,
c
chan
<-
BackupStatus
)
error
{
func
(
b
*
Backup
)
Run
(
npage
int
32
,
sleepNs
time
.
Duration
,
c
chan
<-
BackupStatus
)
error
{
var
err
error
var
err
error
for
{
for
{
err
=
b
.
Step
(
npage
)
err
=
b
.
Step
(
npage
)
...
...
function.go
View file @
989ed582
...
@@ -54,6 +54,7 @@ import "C"
...
@@ -54,6 +54,7 @@ import "C"
import
(
import
(
"fmt"
"fmt"
"math"
"reflect"
"reflect"
"unsafe"
"unsafe"
)
)
...
@@ -138,6 +139,10 @@ func (c *FunctionContext) ResultBool(b bool) {
...
@@ -138,6 +139,10 @@ func (c *FunctionContext) ResultBool(b bool) {
// ResultBlob sets the result of an SQL function.
// ResultBlob sets the result of an SQL function.
// (See sqlite3_result_blob, http://sqlite.org/c3ref/result_blob.html)
// (See sqlite3_result_blob, http://sqlite.org/c3ref/result_blob.html)
func
(
c
*
Context
)
ResultBlob
(
b
[]
byte
)
{
func
(
c
*
Context
)
ResultBlob
(
b
[]
byte
)
{
if
i64
&&
len
(
b
)
>
math
.
MaxInt32
{
C
.
sqlite3_result_error_toobig
((
*
C
.
sqlite3_context
)(
c
))
return
}
var
p
*
byte
var
p
*
byte
if
len
(
b
)
>
0
{
if
len
(
b
)
>
0
{
p
=
&
b
[
0
]
p
=
&
b
[
0
]
...
@@ -189,7 +194,11 @@ func (c *FunctionContext) ResultErrorCode(e Errno) {
...
@@ -189,7 +194,11 @@ func (c *FunctionContext) ResultErrorCode(e Errno) {
// ResultInt sets the result of an SQL function.
// ResultInt sets the result of an SQL function.
// (See sqlite3_result_int, http://sqlite.org/c3ref/result_blob.html)
// (See sqlite3_result_int, http://sqlite.org/c3ref/result_blob.html)
func
(
c
*
Context
)
ResultInt
(
i
int
)
{
func
(
c
*
Context
)
ResultInt
(
i
int
)
{
C
.
sqlite3_result_int
((
*
C
.
sqlite3_context
)(
c
),
C
.
int
(
i
))
if
i64
&&
(
i
>
math
.
MaxInt32
||
i
<
math
.
MinInt32
)
{
C
.
sqlite3_result_int64
((
*
C
.
sqlite3_context
)(
c
),
C
.
sqlite3_int64
(
i
))
}
else
{
C
.
sqlite3_result_int
((
*
C
.
sqlite3_context
)(
c
),
C
.
int
(
i
))
}
}
}
// ResultInt sets the result of an SQL function.
// ResultInt sets the result of an SQL function.
...
@@ -463,7 +472,7 @@ const sqliteDeterministic = 0x800 // C.SQLITE_DETERMINISTIC
...
@@ -463,7 +472,7 @@ const sqliteDeterministic = 0x800 // C.SQLITE_DETERMINISTIC
// CreateScalarFunction creates or redefines SQL scalar functions.
// CreateScalarFunction creates or redefines SQL scalar functions.
// TODO Make possible to specify the preferred encoding
// TODO Make possible to specify the preferred encoding
// (See http://sqlite.org/c3ref/create_function.html)
// (See http://sqlite.org/c3ref/create_function.html)
func
(
c
*
Conn
)
CreateScalarFunction
(
functionName
string
,
nArg
int
,
deterministic
bool
,
pApp
interface
{},
func
(
c
*
Conn
)
CreateScalarFunction
(
functionName
string
,
nArg
int
32
,
deterministic
bool
,
pApp
interface
{},
f
ScalarFunction
,
d
DestroyDataFunction
)
error
{
f
ScalarFunction
,
d
DestroyDataFunction
)
error
{
var
eTextRep
C
.
int
=
C
.
SQLITE_UTF8
var
eTextRep
C
.
int
=
C
.
SQLITE_UTF8
if
deterministic
{
if
deterministic
{
...
@@ -491,7 +500,7 @@ func (c *Conn) CreateScalarFunction(functionName string, nArg int, deterministic
...
@@ -491,7 +500,7 @@ func (c *Conn) CreateScalarFunction(functionName string, nArg int, deterministic
// CreateAggregateFunction creates or redefines SQL aggregate functions.
// CreateAggregateFunction creates or redefines SQL aggregate functions.
// TODO Make possible to specify the preferred encoding
// TODO Make possible to specify the preferred encoding
// (See http://sqlite.org/c3ref/create_function.html)
// (See http://sqlite.org/c3ref/create_function.html)
func
(
c
*
Conn
)
CreateAggregateFunction
(
functionName
string
,
nArg
int
,
pApp
interface
{},
func
(
c
*
Conn
)
CreateAggregateFunction
(
functionName
string
,
nArg
int
32
,
pApp
interface
{},
step
StepFunction
,
final
FinalFunction
,
d
DestroyDataFunction
)
error
{
step
StepFunction
,
final
FinalFunction
,
d
DestroyDataFunction
)
error
{
fname
:=
C
.
CString
(
functionName
)
fname
:=
C
.
CString
(
functionName
)
defer
C
.
free
(
unsafe
.
Pointer
(
fname
))
defer
C
.
free
(
unsafe
.
Pointer
(
fname
))
...
...
sqlite.go
View file @
989ed582
...
@@ -534,7 +534,7 @@ func (c *Conn) Close() error {
...
@@ -534,7 +534,7 @@ func (c *Conn) Close() error {
rv
:=
C
.
sqlite3_close
(
c
.
db
)
rv
:=
C
.
sqlite3_close
(
c
.
db
)
if
rv
!=
C
.
SQLITE_OK
{
if
rv
!=
C
.
SQLITE_OK
{
Log
(
int
(
rv
),
"error while closing Conn"
)
Log
(
int
32
(
rv
),
"error while closing Conn"
)
return
c
.
error
(
rv
,
"Conn.Close"
)
return
c
.
error
(
rv
,
"Conn.Close"
)
}
}
c
.
db
=
nil
c
.
db
=
nil
...
...
stmt.go
View file @
989ed582
...
@@ -347,6 +347,9 @@ func (s *Stmt) BindByIndex(index int, value interface{}) error {
...
@@ -347,6 +347,9 @@ func (s *Stmt) BindByIndex(index int, value interface{}) error {
if
NullIfEmptyString
&&
len
(
value
)
==
0
{
if
NullIfEmptyString
&&
len
(
value
)
==
0
{
rv
=
C
.
sqlite3_bind_null
(
s
.
stmt
,
i
)
rv
=
C
.
sqlite3_bind_null
(
s
.
stmt
,
i
)
}
else
{
}
else
{
if
i64
&&
len
(
value
)
>
math
.
MaxInt32
{
return
s
.
specificError
(
"string too big: %d at index %d"
,
len
(
value
),
index
)
}
cs
,
l
:=
cstring
(
value
)
cs
,
l
:=
cstring
(
value
)
rv
=
C
.
my_bind_text
(
s
.
stmt
,
i
,
cs
,
l
)
rv
=
C
.
my_bind_text
(
s
.
stmt
,
i
,
cs
,
l
)
}
}
...
@@ -369,6 +372,9 @@ func (s *Stmt) BindByIndex(index int, value interface{}) error {
...
@@ -369,6 +372,9 @@ func (s *Stmt) BindByIndex(index int, value interface{}) error {
case
float64
:
case
float64
:
rv
=
C
.
sqlite3_bind_double
(
s
.
stmt
,
i
,
C
.
double
(
value
))
rv
=
C
.
sqlite3_bind_double
(
s
.
stmt
,
i
,
C
.
double
(
value
))
case
[]
byte
:
case
[]
byte
:
if
i64
&&
len
(
value
)
>
math
.
MaxInt32
{
return
s
.
specificError
(
"blob too big: %d at index %d"
,
len
(
value
),
index
)
}
var
p
*
byte
var
p
*
byte
if
len
(
value
)
>
0
{
if
len
(
value
)
>
0
{
p
=
&
value
[
0
]
p
=
&
value
[
0
]
...
@@ -1139,7 +1145,7 @@ func (s *Stmt) finalize() error {
...
@@ -1139,7 +1145,7 @@ func (s *Stmt) finalize() error {
}
}
rv
:=
C
.
sqlite3_finalize
(
s
.
stmt
)
rv
:=
C
.
sqlite3_finalize
(
s
.
stmt
)
if
rv
!=
C
.
SQLITE_OK
{
if
rv
!=
C
.
SQLITE_OK
{
Log
(
int
(
rv
),
"error while finalizing Stmt"
)
Log
(
int
32
(
rv
),
"error while finalizing Stmt"
)
return
s
.
error
(
rv
,
"Stmt.finalize"
)
return
s
.
error
(
rv
,
"Stmt.finalize"
)
}
}
s
.
stmt
=
nil
s
.
stmt
=
nil
...
...
trace.go
View file @
989ed582
...
@@ -285,7 +285,7 @@ func goXProgress(udp unsafe.Pointer) C.int {
...
@@ -285,7 +285,7 @@ func goXProgress(udp unsafe.Pointer) C.int {
// ProgressHandler registers or clears a query progress callback.
// ProgressHandler registers or clears a query progress callback.
// The progress callback will be invoked every numOps opcodes.
// The progress callback will be invoked every numOps opcodes.
// (See http://sqlite.org/c3ref/progress_handler.html)
// (See http://sqlite.org/c3ref/progress_handler.html)
func
(
c
*
Conn
)
ProgressHandler
(
f
ProgressHandler
,
numOps
int
,
udp
interface
{})
{
func
(
c
*
Conn
)
ProgressHandler
(
f
ProgressHandler
,
numOps
int
32
,
udp
interface
{})
{
if
f
==
nil
{
if
f
==
nil
{
c
.
progressHandler
=
nil
c
.
progressHandler
=
nil
C
.
sqlite3_progress_handler
(
c
.
db
,
0
,
nil
,
nil
)
C
.
sqlite3_progress_handler
(
c
.
db
,
0
,
nil
,
nil
)
...
@@ -347,7 +347,7 @@ func Complete(sql string) bool {
...
@@ -347,7 +347,7 @@ func Complete(sql string) bool {
// Log writes a message into the error log established by ConfigLog method.
// Log writes a message into the error log established by ConfigLog method.
// (See http://sqlite.org/c3ref/log.html)
// (See http://sqlite.org/c3ref/log.html)
func
Log
(
err
/*Errno*/
int
,
msg
string
)
{
func
Log
(
err
/*Errno*/
int
32
,
msg
string
)
{
cs
:=
C
.
CString
(
msg
)
cs
:=
C
.
CString
(
msg
)
defer
C
.
free
(
unsafe
.
Pointer
(
cs
))
defer
C
.
free
(
unsafe
.
Pointer
(
cs
))
C
.
my_log
(
C
.
int
(
err
),
cs
)
C
.
my_log
(
C
.
int
(
err
),
cs
)
...
...
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