Expand description
This create implements an API for interacting with Mimer SQL databases from Rust.
The Mimer SQL Rust API is built as a wrapper around the Mimer C API. It consists of two crates:
mimerrust
: Implements the Mimer SQL Rust API. It uses the wrappers frommimerrust-sys
to create a high level, safe interface.mimerrust-sys
: Handles low-level wrapping of the C library into Rust-compatible concepts. It is not intended for direct use, but rather as an intermediary wrapping step. To reduce build time and avoid requiring LLVM and Clang on Windows a pre-generated binding is used by default. To generate and use a new binding, pass the--features run_bindgen
flag when building.
Example usage:
use mimerrust::{Connection, ToSql, CursorMode};
fn main() {
print!("Connecting to database\n");
let mut conn =
Connection::open("", "RUSTUSER", "RUSTPASSWORD").unwrap_or_else(|ec| panic!("{}", ec));
conn.execute_statement("DROP TABLE test_table").ok();
println!("Creating table");
conn.execute_statement("CREATE TABLE test_table (id INT primary key, text NVARCHAR(30))")
.expect("Error creating table");
println!("Inserting rows");
let insert_stmt = conn.prepare("INSERT INTO test_table (id, text) VALUES(:id, :text)",
CursorMode::Forward).expect("Error preparing statement");
let mut text = "Hello";
let mut id = 1;
let params: &[&dyn ToSql] = &[&id,&text];
insert_stmt.execute_bind(params).expect("Error inserting first row");
text = "World!";
id = 2;
let params: &[&dyn ToSql] = &[&id,&text];
insert_stmt.execute_bind(params).expect("Error inserting second row");
let stmt = conn
.prepare("SELECT * from test_table", CursorMode::Forward)
.unwrap();
let mut cursor = stmt.open_cursor().unwrap();
println!("Fetching all rows");
while let Some(row) = cursor.next_row().unwrap() {
let id: i32 = row.get(1).unwrap().unwrap();
let text: String = row.get(2).unwrap().unwrap();
println!("id: {}, text: {}", id, text);
}
}
All examples and tests uses an ident called RUSTUSER
with the password RUSTPASSWORD
. To create the user in Mimer SQL, run bsql
or DbVisualizer as SYSADM, or an other ident with proper privileges, and create the ident as follows:
create ident RUSTUSER as user using 'RUSTPASSWORD';
grant databank to RUSTUSER;
To run the examples you need a databank as well. Log into Mimer SQL using bsql
or DbVisualizer as RUSTUSER
and run:
create datank rustdb
The tests create the databanks needed.
§Requirements
This API requires the Mimer SQL C API to be installed on the system. The API is tested with Mimer SQL 11.0.8D.
Furthermore, bindings to the Mimer SQL C API are generated at compile time using bindgen, which requires clang to be installed on the system.
The bindings are not re-built automatically, instead a pre-generated binding is used. This is to avoid requirements on having Clang on for example Windows.
To generate new bindings, go into the mimerrust-bindings
and run cargo build
.
Re-exports§
pub use types::*;
Modules§
- types
- Handles datatypes and their conversions between Rust and Mimer SQL.
Structs§
- Connection
- Represents a connection to a MimerSQL database.
- Cursor
- An iterator for result sets from MimerSQL databases.
- Mimer
Error - Represents an error occurring during communication with a MimerSQL database.
- Row
- Represents a row in a result set.
- Statement
- A prepared statement.
- Transaction
- Represents a transaction on a database connection. A Transaction will roll back by default if the object is dropped.
Use the
commit
method to commit the changes made in the transaction.
Enums§
- Cursor
Mode - Cursor mode options.
- EndTransaction
Mode - End transaction mode options.
- Parameter
Mode - Parametermodes used in routines
- Scroll
Option - Scroll options used in scroll.
- Transaction
Mode - Transaction mode options.
Constants§
- BSI_4K
- Option for get_statistics.
- BSI_
4K_ USED - Option for get_statistics.
- BSI_32K
- Option for get_statistics.
- BSI_
32K_ USED - Option for get_statistics.
- BSI_
128K - Option for get_statistics.
- BSI_
128K_ USED - Option for get_statistics.
- BSI_
PAGES_ USED - Option for get_statistics.
- MIMER_
SUCCESS