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:
Floris Bruynooghe
2019-08-11 15:03:02 +02:00
parent 8a73f84003
commit b2031f5bcd
13 changed files with 2428 additions and 562 deletions

View File

@@ -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())
}
}