mirror of
https://github.com/chatmail/core.git
synced 2026-04-19 22:46:29 +03:00
Remove dc_open() from the Rust API
This means the Context becomes a struct following the normal Rust conventions where when it is created it is usable. This will over time allow removing a lot of runtime checks and simplify code. Many members will no longer need to be Options or similar. The C API needs to remain compatible so hides the implementation of this behind another struct which can be opened and closed.
This commit is contained in:
22
src/sql.rs
22
src/sql.rs
@@ -38,16 +38,13 @@ impl Sql {
|
||||
info!(context, 0, "Database closed.");
|
||||
}
|
||||
|
||||
// return true on success, false on failure
|
||||
pub fn open(&self, context: &Context, dbfile: &std::path::Path, flags: libc::c_int) -> bool {
|
||||
match open(context, self, dbfile, flags) {
|
||||
Ok(_) => true,
|
||||
Err(Error::SqlAlreadyOpen) => false,
|
||||
Err(_) => {
|
||||
self.close(context);
|
||||
false
|
||||
}
|
||||
}
|
||||
pub fn open(
|
||||
&self,
|
||||
context: &Context,
|
||||
dbfile: &std::path::Path,
|
||||
flags: libc::c_int,
|
||||
) -> Result<()> {
|
||||
open(context, self, dbfile, flags)
|
||||
}
|
||||
|
||||
pub fn execute<P>(&self, sql: &str, params: P) -> Result<usize>
|
||||
@@ -227,7 +224,10 @@ impl Sql {
|
||||
match res {
|
||||
Ok(_) => Ok(()),
|
||||
Err(err) => {
|
||||
error!(context, 0, "set_config(): Cannot change value. {:?}", &err);
|
||||
error!(
|
||||
context,
|
||||
0, "set_config(): Cannot change value for {}: {:?}", key, &err
|
||||
);
|
||||
Err(err.into())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user