mattn/go-sqlite3

Add sqlite3_db_readonly support to sqlite3.go

nclv opened this issue · 4 comments

nclv commented

Add support for sqlite3_db_readonly().

// Readonly determines if a database is read-only.
// (See http://sqlite.org/c3ref/db_readonly.html)
func (c *Conn) Readonly(dbName string) (bool, error) {
    cname := C.CString(dbName)
    rv := C.sqlite3_db_readonly(c.db, cname)
    C.free(unsafe.Pointer(cname))

    if rv == -1 {
        return false, c.lastError()
    }

    return rv == 1, nil
}

What is the use case for adding this?

nclv commented

I am developing an application using the ATTACH feature of SQLite. I am attaching some databases in read-only mode for data viewing and others in writing mode for merging the contents of some tables.

I do not detach databases from the connection if not necessary. I need to check that a database is attached in read-only mode and then detach and reattach it for writing.

Read only mode is already supported see: open function in URI as the filename

nclv commented

Read only mode is already supported see: open function in URI as the filename

That's not really what I want to achieve. I want to detect that a given database was attached in read-only mode.