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
498b6a92
Commit
498b6a92
authored
Nov 10, 2013
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support to query_only and application_id pragmas.
parent
3f54283a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
0 deletions
+51
-0
pragma.go
pragma.go
+38
-0
pragma_test.go
pragma_test.go
+13
-0
No files found.
pragma.go
View file @
498b6a92
...
...
@@ -184,6 +184,44 @@ func (c *Conn) ForeignKeyCheck(dbName, table string) ([]FkViolation, error) {
return
violations
,
nil
}
// QueryOnly queries the status of the database.
// Database name is optional (default is 'main').
// (See http://sqlite.org/pragma.html#pragma_query_only)
func
(
c
*
Conn
)
QueryOnly
(
dbName
string
)
(
bool
,
error
)
{
var
queryOnly
bool
err
:=
c
.
oneValue
(
pragma
(
dbName
,
"query_only"
),
&
queryOnly
)
if
err
!=
nil
{
return
false
,
err
}
return
queryOnly
,
nil
}
// SetQueryOnly prevents all changes to database files when enabled.
// Database name is optional (default is 'main').
// (See http://sqlite.org/pragma.html#pragma_query_only)
func
(
c
*
Conn
)
SetQueryOnly
(
dbName
string
,
mode
bool
)
error
{
return
c
.
exec
(
pragma
(
dbName
,
fmt
.
Sprintf
(
"query_only=%t"
,
mode
)))
}
// ApplicationId queries the "Application ID" integer located into the database header.
// Database name is optional (default is 'main').
// (See http://sqlite.org/pragma.html#pragma_application_id)
func
(
c
*
Conn
)
ApplicationId
(
dbName
string
)
(
int
,
error
)
{
var
id
int
err
:=
c
.
oneValue
(
pragma
(
dbName
,
"application_id"
),
&
id
)
if
err
!=
nil
{
return
-
1
,
err
}
return
id
,
nil
}
// SetApplicationId changes the "Application ID".
// Database name is optional (default is 'main').
// (See http://sqlite.org/pragma.html#pragma_application_id)
func
(
c
*
Conn
)
SetApplicationId
(
dbName
string
,
id
int
)
error
{
return
c
.
exec
(
pragma
(
dbName
,
fmt
.
Sprintf
(
"application_id=%d"
,
id
)))
}
func
pragma
(
dbName
,
pragmaName
string
)
string
{
if
len
(
dbName
)
==
0
{
return
"PRAGMA "
+
pragmaName
...
...
pragma_test.go
View file @
498b6a92
...
...
@@ -80,3 +80,16 @@ func TestSetSynchronous(t *testing.T) {
checkNoError
(
t
,
err
,
"Error reading synchronous flag of database: %s"
)
assert
.
Equal
(
t
,
0
,
mode
)
}
func
TestQueryOnly
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
checkClose
(
db
,
t
)
mode
,
err
:=
db
.
QueryOnly
(
""
)
checkNoError
(
t
,
err
,
"Error reading query_only status of database: %s"
)
assert
.
T
(
t
,
!
mode
,
"expecting query_only to be false by default"
)
err
=
db
.
SetQueryOnly
(
""
,
true
)
checkNoError
(
t
,
err
,
"Error setting query_only status of database: %s"
)
err
=
db
.
Exec
(
"CREATE TABLE test (data TEXT)"
)
assert
.
T
(
t
,
err
!=
nil
,
"expected error"
)
//println(err.Error())
}
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