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
3f04bdc0
Commit
3f04bdc0
authored
Dec 09, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds helpers for pragma 'journal_mode'.
parent
0f8a7605
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
0 deletions
+40
-0
pragma.go
pragma.go
+24
-0
pragma_test.go
pragma_test.go
+16
-0
No files found.
pragma.go
View file @
3f04bdc0
...
...
@@ -62,6 +62,30 @@ func (c *Conn) SetRecursiveTriggers(dbName string, on bool) error {
return
c
.
exec
(
pragma
(
dbName
,
fmt
.
Sprintf
(
"recursive_triggers=%t"
,
on
)))
}
// JournalMode queries the current journaling mode for database.
// Database name is optional (default is 'main').
// (See http://sqlite.org/pragma.html#pragma_journal_mode)
func
(
c
*
Conn
)
JournalMode
(
dbName
string
)
(
string
,
error
)
{
var
mode
string
err
:=
c
.
OneValue
(
pragma
(
dbName
,
"journal_mode"
),
&
mode
)
if
err
!=
nil
{
return
""
,
err
}
return
mode
,
nil
}
// SetJournalMode changes the journaling mode for database.
// Database name is optional (default is 'main').
// (See http://sqlite.org/pragma.html#pragma_journal_mode)
func
(
c
*
Conn
)
SetJournalMode
(
dbName
,
mode
string
)
(
string
,
error
)
{
var
newMode
string
err
:=
c
.
OneValue
(
pragma
(
dbName
,
Mprintf
(
"journal_mode=%Q"
,
mode
)),
&
newMode
)
if
err
!=
nil
{
return
""
,
err
}
return
newMode
,
nil
}
func
pragma
(
dbName
,
pragmaName
string
)
string
{
if
len
(
dbName
)
==
0
{
return
"PRAGMA "
+
pragmaName
...
...
pragma_test.go
View file @
3f04bdc0
...
...
@@ -29,3 +29,19 @@ func TestSchemaVersion(t *testing.T) {
checkNoError
(
t
,
err
,
"Error reading schema version of database: %s"
)
assertEquals
(
t
,
"expecting %d but got %d"
,
0
,
version
)
}
func
TestJournalMode
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
db
.
Close
()
mode
,
err
:=
db
.
JournalMode
(
""
)
checkNoError
(
t
,
err
,
"Error reading journaling mode of database: %s"
)
assertEquals
(
t
,
"expecting %s but got %s"
,
"memory"
,
mode
)
}
func
TestSetJournalMode
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
db
.
Close
()
mode
,
err
:=
db
.
SetJournalMode
(
""
,
"OFF"
)
checkNoError
(
t
,
err
,
"Error setting journaling mode of database: %s"
)
assertEquals
(
t
,
"expecting %s but got %s"
,
"off"
,
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