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

Expose sqlite3_db_status #701

Open
demaggus83 opened this issue Mar 13, 2019 · 6 comments
Open

Expose sqlite3_db_status #701

demaggus83 opened this issue Mar 13, 2019 · 6 comments

Comments

@demaggus83
Copy link

For expvar I need the status of sqlite.
sqlite delivers stats per sqlite3_db_status

I would try to implement it myself, but I have no experience in C and calling C from Go

Is there an workaround?

@rittneje
Copy link
Collaborator

Do you want sqlite3_db_status or sqlite3_status? The former is problematic, not because it's hard to implement, but because you wouldn't have a straightforward way of calling it. It would be implemented as a method on *sqlite3.SQLiteConn, and there's no way to get to that through the database/sql API, unless you pull some shenanigans with the ConnectHook or something.

@demaggus83
Copy link
Author

demaggus83 commented Mar 14, 2019

Both would be really great. I would be fine with a ConnectHook.
I am already using the ConnectHook for SetTrace in DEV environment.

@rittneje
Copy link
Collaborator

As of Go 1.13, you can actually access the *sqlite3.SQLiteConn via Conn.Raw. So both sqlite3_db_status and sqlite3_status could be exposed without too much difficulty. However, do be advised that a sql.DB from the standard library represents a pool of connections, so unless you've configured it specially, you could have multiple *sqlite3.SQLiteConn instances behind the scenes, and there is no mechanism at present for looping over all of them.

@carwyn
Copy link

carwyn commented Jun 13, 2020

I have a similar requirement to get at sqlite3_db_config() to lock down the use of SQLite3 when processing untrusted database files as per point 9 in section 1.2 here: https://www.sqlite.org/security.html

  1. If the application does not use triggers or views, consider disabling the unused capabilities with:
    sqlite3_db_config(db,SQLITE_DBCONFIG_ENABLE_TRIGGER,0,0);
    sqlite3_db_config(db,SQLITE_DBCONFIG_ENABLE_VIEW,0,0);

I'm guessing the "multiple *sqlite3.SQLiteConn instances" would be an issue here too?

@rittneje
Copy link
Collaborator

rittneje commented Jun 13, 2020

@carwyn For that you would want to use the ConnectHook.

go-sqlite3/sqlite3.go

Lines 294 to 297 in baaf8a9

type SQLiteDriver struct {
Extensions []string
ConnectHook func(*SQLiteConn) error
}
That would allow you to perform the requisite operation any time a new connection gets opened. That being said, sqlite3_db_config is not currently exposed, and so a new method on *SQLiteConn would have to be added.

@otoolep
Copy link
Contributor

otoolep commented Jun 12, 2024

Following up #701 (comment)

I came across this issue when looking into support for sqlite3_db_config. Because sqlite3_db_config is varadic it's tricky - Go doesn't support calling varadic functions directly. That said, I only needed a specific config option, so coded just that. Others may find what I did useful, in case they want to modify their own forks.

See rqlite#30

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

4 participants