Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sqlite3_db_readonly support to sqlite3.go #1137

Open
nclv opened this issue Feb 23, 2023 · 3 comments
Open

Add sqlite3_db_readonly support to sqlite3.go #1137

nclv opened this issue Feb 23, 2023 · 3 comments

Comments

@nclv
Copy link

nclv commented Feb 23, 2023

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
}
@rittneje
Copy link
Collaborator

What is the use case for adding this?

@nclv
Copy link
Author

nclv commented Feb 24, 2023

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.

@innomon
Copy link

innomon commented May 8, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants