rustsqlite icon indicating copy to clipboard operation
rustsqlite copied to clipboard

Database::get_errmsg() is not threadsafe

Open apoelstra opened this issue 11 years ago • 1 comments

The function sqlite3_errmsg returns the error message from "the most recent call". If this is going to be exposed then every single function calling a sqlite3_* function needs to take a mutable self, otherwise this function will be racy.

Probably the better thing is to not expose this message and instead bundle its result into any Errs that are returned from SqliteResult-returning function, since it is not very Rustic to have error reporting be separated from error occurance like this.

apoelstra avatar Jul 30 '14 06:07 apoelstra

Ditto for Database::get_changes() and Database::get_last_insert_rowid(), which are the kind of functions that should be safe to call from multiple threads, provided that no thread has mutable access. Rust can enforce this (allowing the Database to be both Send and Share) but every method which modifies the underlying database (exec at least) would need to take a &mut self, as per my other bug report(s).

I think the correct model for mapping between the Rust Database and the database is that anything that might mutate the database should require mutable access to the Database, exactly so that these functions can work in a threadsafe way.

apoelstra avatar Jul 30 '14 17:07 apoelstra