Skip to content
This repository has been archived by the owner on Jul 25, 2020. It is now read-only.

Database::get_errmsg() is not threadsafe #102

Open
apoelstra opened this issue Jul 30, 2014 · 1 comment
Open

Database::get_errmsg() is not threadsafe #102

apoelstra opened this issue Jul 30, 2014 · 1 comment

Comments

@apoelstra
Copy link

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.

lifthrasiir added a commit to lifthrasiir/rustsqlite that referenced this issue Jul 30, 2014
- fixed a mistake that `Database` was accidentally `Send`able.
- made `Cursor::{reset, clear_bindings, step, step_row,
  get_blob, get_int, get_i64, get_f64, get_text, bind_param,
  bind_params}` receive `&mut self`.
- made `Database::set_busy_timeout` receive `&mut self`.
  `Database::{prepare, exec}` has been left as is, since it is
  perfectly safe to have multiple cursors. the associated
  thread safety issue is separately handled.

closes linuxfood#98, linuxfood#99, linuxfood#100, linuxfood#101, linuxfood#102 and linuxfood#103.
@apoelstra
Copy link
Author

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.

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

No branches or pull requests

1 participant