Commit 498b6a92 authored by gwenn's avatar gwenn

Add support to query_only and application_id pragmas.

parent 3f54283a
......@@ -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
......
......@@ -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())
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment