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
b166e40d
Commit
b166e40d
authored
Oct 15, 2014
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce methods to change memory-mapped IO region.
parent
9d18f063
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
79 additions
and
4 deletions
+79
-4
busy_test.go
busy_test.go
+1
-0
config.c
config.c
+1
-1
config_extra.go
config_extra.go
+14
-0
config_extra_test.go
config_extra_test.go
+5
-0
config_test.go
config_test.go
+4
-1
pragma.go
pragma.go
+27
-0
pragma_test.go
pragma_test.go
+23
-0
trace.go
trace.go
+4
-2
No files found.
busy_test.go
View file @
b166e40d
...
...
@@ -38,6 +38,7 @@ func TestInterrupt(t *testing.T) {
func
openTwoConnSameDb
(
t
*
testing
.
T
)
(
*
os
.
File
,
*
Conn
,
*
Conn
)
{
f
,
err
:=
ioutil
.
TempFile
(
""
,
"gosqlite-test"
)
checkNoError
(
t
,
err
,
"couldn't create temp file: %s"
)
checkNoError
(
t
,
f
.
Close
(),
"couldn't close temp file: %s"
)
db1
,
err
:=
Open
(
f
.
Name
(),
OpenReadWrite
,
OpenCreate
,
OpenFullMutex
)
checkNoError
(
t
,
err
,
"couldn't open database file: %s"
)
...
...
config.c
View file @
b166e40d
config_extra.go
View file @
b166e40d
...
...
@@ -10,6 +10,10 @@ package sqlite
/*
#include <sqlite3.h>
#include <stdlib.h>
static int goSqlite3ConfigMMapSize(sqlite3_int64 defaultSize, sqlite3_int64 maxSize) {
return sqlite3_config(SQLITE_CONFIG_MMAP_SIZE, defaultSize, maxSize);
}
*/
import
"C"
...
...
@@ -45,3 +49,13 @@ func (c *Conn) LoadExtension(file string, proc ...string) error {
}
return
nil
}
// ConfigMMapSize decreases or increases the default mmap_size/reduces the hard upper bound at start time.
// (See http://www.sqlite.org/c3ref/c_config_covering_index_scan.html#sqliteconfigmmapsize)
func
ConfigMMapSize
(
defaultSize
,
maxSize
int64
)
error
{
rv
:=
C
.
goSqlite3ConfigMMapSize
(
C
.
sqlite3_int64
(
defaultSize
),
C
.
sqlite3_int64
(
maxSize
))
if
rv
==
C
.
SQLITE_OK
{
return
nil
}
return
Errno
(
rv
)
}
config_extra_test.go
View file @
b166e40d
...
...
@@ -9,6 +9,7 @@ package sqlite_test
import
(
"fmt"
"testing"
.
"github.com/gwenn/gosqlite"
)
...
...
@@ -17,6 +18,10 @@ func init() {
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"couldn't disable shared cache: '%s'"
,
err
))
}
err
=
ConfigMMapSize
(
0
,
268435456
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"cannot change mmap size: '%s'"
,
err
))
}
}
func
TestEnableLoadExtension
(
t
*
testing
.
T
)
{
...
...
config_test.go
View file @
b166e40d
...
...
@@ -66,5 +66,8 @@ func TestConnSettings(t *testing.T) {
func
TestCompileOptionUsed
(
t
*
testing
.
T
)
{
b
:=
CompileOptionUsed
(
"SQLITE_ENABLE_COLUMN_METADATA"
)
assert
.
T
(
t
,
b
,
"COLUMN_METADATA disabled"
)
if
!
b
{
t
.
Log
(
"COLUMN_METADATA disabled"
)
}
//assert.T(t, b, "COLUMN_METADATA disabled")
}
pragma.go
View file @
b166e40d
...
...
@@ -222,6 +222,33 @@ func (c *Conn) SetApplicationID(dbName string, id int) error {
return
c
.
FastExec
(
pragma
(
dbName
,
fmt
.
Sprintf
(
"application_id=%d"
,
id
)))
}
// MMapSize queries the maximum number of bytes that are set aside for memory-mapped I/O.
// Database name is optional (default is 'main').
// (See http://www.sqlite.org/pragma.html#pragma_mmap_size and http://sqlite.org/mmap.html)
func
(
c
*
Conn
)
MMapSize
(
dbName
string
)
(
int64
,
error
)
{
var
size
int64
err
:=
c
.
oneValue
(
pragma
(
dbName
,
"mmap_size"
),
&
size
)
if
err
!=
nil
{
return
-
1
,
err
}
return
size
,
nil
}
// SetMMapSize changes the maximum number of bytes that are set aside for memory-mapped I/O.
// Database name is optional (default is 'main').
// If the specified size is zero then memory mapped I/O is disabled.
// If the specified size is negative, then the limit reverts to the default value.
// The size of the memory-mapped I/O region cannot be changed while the memory-mapped I/O region is in active use.
// (See http://www.sqlite.org/pragma.html#pragma_mmap_size and http://sqlite.org/mmap.html)
func
(
c
*
Conn
)
SetMMapSize
(
dbName
string
,
size
int64
)
(
int64
,
error
)
{
var
newSize
int64
err
:=
c
.
oneValue
(
pragma
(
dbName
,
fmt
.
Sprintf
(
"mmap_size=%d"
,
size
)),
&
newSize
)
if
err
!=
nil
{
return
-
1
,
err
}
return
newSize
,
nil
}
func
pragma
(
dbName
,
pragmaName
string
)
string
{
if
len
(
dbName
)
==
0
{
return
"PRAGMA "
+
pragmaName
...
...
pragma_test.go
View file @
b166e40d
...
...
@@ -6,6 +6,8 @@ package sqlite_test
import
(
"io"
"io/ioutil"
"os"
"testing"
"github.com/bmizerany/assert"
...
...
@@ -195,3 +197,24 @@ func TestForeignKeyCheck(t *testing.T) {
checkNoError
(
t
,
err
,
"error while checking FK: %s"
)
assert
.
Equal
(
t
,
vs
,
mvs
)
}
func
TestMMapSize
(
t
*
testing
.
T
)
{
if
VersionNumber
()
<
3007017
{
return
}
f
,
err
:=
ioutil
.
TempFile
(
""
,
"gosqlite.db."
)
checkNoError
(
t
,
err
,
"couldn't create temp file: %s"
)
checkNoError
(
t
,
f
.
Close
(),
"couldn't close temp file: %s"
)
defer
os
.
Remove
(
f
.
Name
())
db
,
err
:=
Open
(
f
.
Name
(),
OpenReadWrite
,
OpenCreate
,
OpenFullMutex
)
checkNoError
(
t
,
err
,
"couldn't open database file: %s"
)
size
,
err
:=
db
.
MMapSize
(
""
)
checkNoError
(
t
,
err
,
"error while getting mmap size: %s"
)
assert
.
Equal
(
t
,
int64
(
0
),
size
)
newSize
,
err
:=
db
.
SetMMapSize
(
""
,
1048576
)
checkNoError
(
t
,
err
,
"error while setting mmap size: %s"
)
assert
.
Equal
(
t
,
int64
(
1048576
),
newSize
)
}
trace.go
View file @
b166e40d
...
...
@@ -366,7 +366,9 @@ func Complete(sql string) (bool, error) {
}
// 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 and http://www.sqlite.org/errlog.html)
//
// Applications can use the sqlite3_log(E,F,..) API to send new messages to the log, if desired, but this is discouraged.
func
Log
(
err
/*Errno*/
int32
,
msg
string
)
{
cs
:=
C
.
CString
(
msg
)
defer
C
.
free
(
unsafe
.
Pointer
(
cs
))
...
...
@@ -394,7 +396,7 @@ var logger *sqliteLogger
// ConfigLog configures the logger of the SQLite library.
// Only one logger can be registered at a time for the whole program.
// The logger must be threadsafe.
// (See sqlite3_config(SQLITE_CONFIG_LOG,...): http://sqlite.org/c3ref/config.html)
// (See sqlite3_config(SQLITE_CONFIG_LOG,...): http://sqlite.org/c3ref/config.html
and http://www.sqlite.org/errlog.html
)
func
ConfigLog
(
f
Logger
,
udp
interface
{})
error
{
var
rv
C
.
int
if
f
==
nil
{
...
...
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