mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-08 17:54:22 +01:00
Implement prepare
This commit is contained in:
@@ -7,13 +7,12 @@ use jni::objects::{JByteArray, JClass, JObject};
|
||||
use jni::sys::jlong;
|
||||
use jni::JNIEnv;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone)]
|
||||
pub struct Connection {
|
||||
pub(crate) conn: Rc<limbo_core::Connection>,
|
||||
pub(crate) io: Arc<dyn limbo_core::IO>,
|
||||
pub(crate) io: Rc<dyn limbo_core::IO>,
|
||||
}
|
||||
|
||||
/// Returns a pointer to a `Cursor` object.
|
||||
@@ -31,7 +30,7 @@ pub struct Connection {
|
||||
///
|
||||
/// A `jlong` representing the pointer to the newly created `Cursor` object.
|
||||
#[no_mangle]
|
||||
pub extern "system" fn Java_org_github_tursodatabase_limbo_LimboConnection_prepareUtf8<'local>(
|
||||
pub extern "system" fn Java_org_github_tursodatabase_core_LimboConnection_prepareUtf8<'local>(
|
||||
mut env: JNIEnv<'local>,
|
||||
obj: JObject<'local>,
|
||||
connection_ptr: jlong,
|
||||
@@ -91,11 +90,11 @@ pub unsafe extern "system" fn Java_org_github_tursodatabase_limbo_Connection_clo
|
||||
let _boxed_connection = Box::from_raw(connection_ptr as *mut Connection);
|
||||
}
|
||||
|
||||
fn to_connection(connection_ptr: jlong) -> Result<&'static mut Rc<Connection>> {
|
||||
fn to_connection(connection_ptr: jlong) -> Result<&'static mut Connection> {
|
||||
if connection_ptr == 0 {
|
||||
Err(LimboError::InvalidConnectionPointer)
|
||||
} else {
|
||||
unsafe { Ok(&mut *(connection_ptr as *mut Rc<Connection>)) }
|
||||
unsafe { Ok(&mut *(connection_ptr as *mut Connection)) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
use crate::connection::Connection;
|
||||
use crate::errors::{LimboError, Result};
|
||||
use crate::errors::{LimboError, Result, LIMBO_ETC};
|
||||
use jni::objects::{JByteArray, JObject};
|
||||
use jni::sys::{jint, jlong};
|
||||
use jni::JNIEnv;
|
||||
use limbo_core::Database;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
const ERROR_CODE_ETC: i32 = 9999;
|
||||
|
||||
#[no_mangle]
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
pub extern "system" fn Java_org_github_tursodatabase_core_LimboDB_openUtf8<'local>(
|
||||
@@ -19,7 +18,7 @@ pub extern "system" fn Java_org_github_tursodatabase_core_LimboDB_openUtf8<'loca
|
||||
let io = match limbo_core::PlatformIO::new() {
|
||||
Ok(io) => Arc::new(io),
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, ERROR_CODE_ETC, e.to_string());
|
||||
set_err_msg_and_throw_exception(&mut env, obj, LIMBO_ETC, e.to_string());
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
@@ -31,12 +30,12 @@ pub extern "system" fn Java_org_github_tursodatabase_core_LimboDB_openUtf8<'loca
|
||||
Ok(bytes) => match String::from_utf8(bytes) {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, ERROR_CODE_ETC, e.to_string());
|
||||
set_err_msg_and_throw_exception(&mut env, obj, LIMBO_ETC, e.to_string());
|
||||
return -1;
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, ERROR_CODE_ETC, e.to_string());
|
||||
set_err_msg_and_throw_exception(&mut env, obj, LIMBO_ETC, e.to_string());
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
@@ -44,7 +43,7 @@ pub extern "system" fn Java_org_github_tursodatabase_core_LimboDB_openUtf8<'loca
|
||||
let db = match Database::open_file(io.clone(), &path) {
|
||||
Ok(db) => db,
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, ERROR_CODE_ETC, e.to_string());
|
||||
set_err_msg_and_throw_exception(&mut env, obj, LIMBO_ETC, e.to_string());
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
@@ -53,7 +52,6 @@ pub extern "system" fn Java_org_github_tursodatabase_core_LimboDB_openUtf8<'loca
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
pub extern "system" fn Java_org_github_tursodatabase_core_LimboDB_connect0<'local>(
|
||||
mut env: JNIEnv<'local>,
|
||||
obj: JObject<'local>,
|
||||
@@ -63,7 +61,7 @@ pub extern "system" fn Java_org_github_tursodatabase_core_LimboDB_connect0<'loca
|
||||
let db = match to_db(db_pointer) {
|
||||
Ok(db) => db,
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, ERROR_CODE_ETC, e.to_string());
|
||||
set_err_msg_and_throw_exception(&mut env, obj, LIMBO_ETC, e.to_string());
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
@@ -75,28 +73,28 @@ pub extern "system" fn Java_org_github_tursodatabase_core_LimboDB_connect0<'loca
|
||||
Ok(bytes) => match String::from_utf8(bytes) {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, ERROR_CODE_ETC, e.to_string());
|
||||
set_err_msg_and_throw_exception(&mut env, obj, LIMBO_ETC, e.to_string());
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, ERROR_CODE_ETC, e.to_string());
|
||||
set_err_msg_and_throw_exception(&mut env, obj, LIMBO_ETC, e.to_string());
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
let io: Arc<dyn limbo_core::IO> = match path.as_str() {
|
||||
let io: Rc<dyn limbo_core::IO> = match path.as_str() {
|
||||
":memory:" => match limbo_core::MemoryIO::new() {
|
||||
Ok(io) => Arc::new(io),
|
||||
Ok(io) => Rc::new(io),
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, ERROR_CODE_ETC, e.to_string());
|
||||
set_err_msg_and_throw_exception(&mut env, obj, LIMBO_ETC, e.to_string());
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
_ => match limbo_core::PlatformIO::new() {
|
||||
Ok(io) => Arc::new(io),
|
||||
Ok(io) => Rc::new(io),
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, ERROR_CODE_ETC, e.to_string());
|
||||
set_err_msg_and_throw_exception(&mut env, obj, LIMBO_ETC, e.to_string());
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
@@ -109,7 +107,7 @@ pub extern "system" fn Java_org_github_tursodatabase_core_LimboDB_connect0<'loca
|
||||
Box::into_raw(Box::new(conn)) as jlong
|
||||
}
|
||||
|
||||
fn to_db(db_pointer: jlong) -> Result<&'static mut Arc<Database>> {
|
||||
pub fn to_db(db_pointer: jlong) -> Result<&'static mut Arc<Database>> {
|
||||
if db_pointer == 0 {
|
||||
Err(LimboError::InvalidDatabasePointer)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user