pub mod connection;
pub mod options;
pub mod error;
use std::collections::HashMap;
use std::ops::Deref;
use rusqlite::{Rows, TransactionBehavior};
use crate::connection::SqliteConnectionMetadata;
use rusqlite::Error as RusqliteError;
use std::sync::{Arc, Mutex};
use std::rc::Rc;
use rsdbc_core::connection::{Batch, ConnectionMetadata, IsolationLevel, SQLResult, Statement, ValidationDepth};
use rsdbc_core::{DatabaseMetadata, Result, ResultSetMetaData};
fn to_rsdbc_err(e: rusqlite::Error) -> rsdbc_core::error::RsdbcErrors {
rsdbc_core::error::RsdbcErrors::General(format!("{:?}", e))
}
pub struct SqliteConnection {
conn: Option<Arc<Mutex<rusqlite::Connection>>>,
}
impl SqliteConnection {
pub fn new(conn: rusqlite::Connection) -> Self {
Self {
conn: Some(Arc::new(Mutex::new(conn))),
}
}
fn drop(&mut self) {
}
}
impl rsdbc_core::connection::Connection for SqliteConnection {
fn begin_transaction(&mut self) -> Result<()> {
Ok(())
}
fn close(&mut self) -> Result<()> {
let mut _c = self.conn.take();
_c = None;
Ok(())
}
fn commit_transaction(&mut self) {
}
fn create_batch(&mut self) -> Result<Box<dyn Batch>> {
todo!()
}
fn create_savepoint(&mut self, name: &str) {
}
fn create_statement(&mut self, sql: &str) -> Result<Box<dyn Statement<'_> + '_>> {
todo!()
}
fn is_auto_commit(&mut self) -> bool {
let connection = self.conn.take().unwrap();
connection.clone().deref().lock().unwrap().is_autocommit()
}
fn metadata(&mut self) -> Result<Box<dyn ConnectionMetadata>> {
todo!()
}
fn transaction_isolation_level(&mut self) -> IsolationLevel {
todo!()
}
fn release_savepoint(&mut self, name: &str) {
todo!()
}
fn rollback_transaction(&mut self) {
todo!()
}
fn rollback_transaction_to_savepoint(&mut self, name: String) {
todo!()
}
fn auto_commit(&mut self, commit: bool) {
todo!()
}
fn set_transaction_isolation_level(&mut self, isolation_level: IsolationLevel) {
}
fn validate(&mut self, depth: ValidationDepth) -> bool {
todo!()
}
}
pub struct SqliteStatement<'a> {
stmt: rusqlite::Statement<'a>,
}
impl rsdbc_core::connection::Statement<'_> for SqliteStatement<'_> {
fn add(&mut self) -> &mut Self where Self: Sized {
todo!()
}
fn bind_index<T>(&mut self, index: u32, value: T) -> &mut Self where Self: Sized {
todo!()
}
fn bind_name<T>(&mut self, name: &str, value: T) -> &mut Self where Self: Sized {
todo!()
}
fn bind_null_index(&mut self, index: u32) -> &mut Self where Self: Sized {
todo!()
}
fn bind_null_name(&mut self, name: &str) -> &mut Self where Self: Sized {
todo!()
}
fn execute<T: SQLResult>(&self) -> Result<T> where Self: Sized {
todo!()
}
fn return_generated_values(&mut self, columns: &[&str]) -> &mut Self where Self: Sized {
todo!()
}
fn fetch_size(&mut self, rows: u32) -> &mut Self where Self: Sized {
todo!()
}
}
struct SqliteResultSet<'stmt> {
rows: Rows<'stmt>,
}
struct SqliteDatabaseMetadata {
}
impl DatabaseMetadata for SqliteDatabaseMetadata {
}
impl<'stmt> rsdbc_core::ResultSet for SqliteResultSet<'stmt> {
fn meta_data(&self) -> Result<Box<dyn ResultSetMetaData>> {
todo!()
}
fn next(&mut self) -> bool {
todo!()
}
fn get_bool(&self, i: u64) -> Result<Option<bool>> {
todo!()
}
fn get_i8(&self, i: u64) -> Result<Option<i8>> {
todo!()
}
fn get_i16(&self, i: u64) -> Result<Option<i16>> {
todo!()
}
fn get_i32(&self, i: u64) -> Result<Option<i32>> {
todo!()
}
fn get_i64(&self, i: u64) -> Result<Option<i64>> {
todo!()
}
fn get_f32(&self, i: u64) -> Result<Option<f32>> {
todo!()
}
fn get_f64(&self, i: u64) -> Result<Option<f64>> {
todo!()
}
fn get_string(&self, i: u64) -> Result<Option<String>> {
todo!()
}
fn get_bytes(&self, i: u64) -> Result<Option<Vec<u8>>> {
todo!()
}
}
fn to_rsdbc_type(t: Option<&str>) -> rsdbc_core::DataType {
match t {
Some("INT") => rsdbc_core::DataType::Integer,
_ => rsdbc_core::DataType::Utf8,
}
}
struct Values<'a>(&'a [rsdbc_core::Value]);
struct ValuesIter<'a>(std::slice::Iter<'a, rsdbc_core::Value>);
impl<'a> IntoIterator for &'a Values<'a> {
type Item = &'a dyn rusqlite::types::ToSql;
type IntoIter = ValuesIter<'a>;
fn into_iter(self) -> ValuesIter<'a> {
ValuesIter(self.0.iter())
}
}
impl<'a> Iterator for ValuesIter<'a> {
type Item = &'a dyn rusqlite::types::ToSql;
fn next(&mut self) -> Option<&'a dyn rusqlite::types::ToSql> {
self.0.next().map(|v| match v {
rsdbc_core::Value::String(ref s) => s as &dyn rusqlite::types::ToSql,
rsdbc_core::Value::Int32(ref n) => n as &dyn rusqlite::types::ToSql,
rsdbc_core::Value::UInt32(ref n) => n as &dyn rusqlite::types::ToSql,
})
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::{collections::HashMap, sync::Arc};
use crate::options::SqliteConnectOptions;
#[test]
fn execute_query() -> rsdbc_core::Result<()> {
Ok(())
}
}