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
ec392678
Commit
ec392678
authored
Dec 09, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds helpers for pragma 'locking_mode' & 'synchronous'.
parent
3f04bdc0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
0 deletions
+77
-0
pragma.go
pragma.go
+43
-0
pragma_test.go
pragma_test.go
+34
-0
No files found.
pragma.go
View file @
ec392678
...
...
@@ -86,6 +86,49 @@ func (c *Conn) SetJournalMode(dbName, mode string) (string, error) {
return
newMode
,
nil
}
// LockingMode queries the database connection locking-mode.
// Database name is optional (default is 'main').
// (See http://sqlite.org/pragma.html#pragma_locking_mode)
func
(
c
*
Conn
)
LockingMode
(
dbName
string
)
(
string
,
error
)
{
var
mode
string
err
:=
c
.
OneValue
(
pragma
(
dbName
,
"locking_mode"
),
&
mode
)
if
err
!=
nil
{
return
""
,
err
}
return
mode
,
nil
}
// SetLockingMode changes the database connection locking-mode.
// Database name is optional (default is 'main').
// (See http://sqlite.org/pragma.html#pragma_locking_mode)
func
(
c
*
Conn
)
SetLockingMode
(
dbName
,
mode
string
)
(
string
,
error
)
{
var
newMode
string
err
:=
c
.
OneValue
(
pragma
(
dbName
,
Mprintf
(
"locking_mode=%Q"
,
mode
)),
&
newMode
)
if
err
!=
nil
{
return
""
,
err
}
return
newMode
,
nil
}
// Synchronous queries the synchronous flag.
// Database name is optional (default is 'main').
// (See http://sqlite.org/pragma.html#pragma_synchronous)
func
(
c
*
Conn
)
Synchronous
(
dbName
string
)
(
int
,
error
)
{
var
mode
int
err
:=
c
.
OneValue
(
pragma
(
dbName
,
"synchronous"
),
&
mode
)
if
err
!=
nil
{
return
-
1
,
err
}
return
mode
,
nil
}
// SetSynchronous changes the synchronous flag.
// Database name is optional (default is 'main').
// (See http://sqlite.org/pragma.html#pragma_synchronous)
func
(
c
*
Conn
)
SetSynchronous
(
dbName
string
,
mode
int
)
error
{
return
c
.
exec
(
pragma
(
dbName
,
fmt
.
Sprintf
(
"synchronous=%d"
,
mode
)))
}
func
pragma
(
dbName
,
pragmaName
string
)
string
{
if
len
(
dbName
)
==
0
{
return
"PRAGMA "
+
pragmaName
...
...
pragma_test.go
View file @
ec392678
...
...
@@ -45,3 +45,37 @@ func TestSetJournalMode(t *testing.T) {
checkNoError
(
t
,
err
,
"Error setting journaling mode of database: %s"
)
assertEquals
(
t
,
"expecting %s but got %s"
,
"off"
,
mode
)
}
func
TestLockingMode
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
db
.
Close
()
mode
,
err
:=
db
.
LockingMode
(
""
)
checkNoError
(
t
,
err
,
"Error reading locking-mode of database: %s"
)
assertEquals
(
t
,
"expecting %s but got %s"
,
"normal"
,
mode
)
}
func
TestSetLockingMode
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
db
.
Close
()
mode
,
err
:=
db
.
SetLockingMode
(
""
,
"exclusive"
)
checkNoError
(
t
,
err
,
"Error setting locking-mode of database: %s"
)
assertEquals
(
t
,
"expecting %s but got %s"
,
"exclusive"
,
mode
)
}
func
TestSynchronous
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
db
.
Close
()
mode
,
err
:=
db
.
Synchronous
(
""
)
checkNoError
(
t
,
err
,
"Error reading synchronous flag of database: %s"
)
assertEquals
(
t
,
"expecting %d but got %d"
,
2
,
mode
)
}
func
TestSetSynchronous
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
db
.
Close
()
err
:=
db
.
SetSynchronous
(
""
,
0
)
checkNoError
(
t
,
err
,
"Error setting synchronous flag of database: %s"
)
mode
,
err
:=
db
.
Synchronous
(
""
)
checkNoError
(
t
,
err
,
"Error reading synchronous flag of database: %s"
)
assertEquals
(
t
,
"expecting %d but got %d"
,
0
,
mode
)
}
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