go-sqlite3 icon indicating copy to clipboard operation
go-sqlite3 copied to clipboard

Add sqlite3_db_readonly support to sqlite3.go

Open nclv opened this issue 2 years ago • 4 comments

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
}

nclv avatar Feb 23 '23 08:02 nclv

What is the use case for adding this?

rittneje avatar Feb 23 '23 17:02 rittneje

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.

nclv avatar Feb 24 '23 07:02 nclv

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

innomon avatar May 08 '24 14:05 innomon

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.

nclv avatar May 22 '24 14:05 nclv