mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-23 08:55:40 +01:00
bind/java: Rename to Turso
This commit is contained in:
@@ -2,7 +2,7 @@ use jni::errors::{Error, JniError};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum LimboError {
|
||||
pub enum TursoError {
|
||||
#[error("Custom error: `{0}`")]
|
||||
CustomError(String),
|
||||
|
||||
@@ -16,19 +16,19 @@ pub enum LimboError {
|
||||
JNIErrors(Error),
|
||||
}
|
||||
|
||||
impl From<turso_core::LimboError> for LimboError {
|
||||
impl From<turso_core::LimboError> for TursoError {
|
||||
fn from(_value: turso_core::LimboError) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LimboError> for JniError {
|
||||
fn from(value: LimboError) -> Self {
|
||||
impl From<TursoError> for JniError {
|
||||
fn from(value: TursoError) -> Self {
|
||||
match value {
|
||||
LimboError::CustomError(_)
|
||||
| LimboError::InvalidDatabasePointer
|
||||
| LimboError::InvalidConnectionPointer
|
||||
| LimboError::JNIErrors(_) => {
|
||||
TursoError::CustomError(_)
|
||||
| TursoError::InvalidDatabasePointer
|
||||
| TursoError::InvalidConnectionPointer
|
||||
| TursoError::JNIErrors(_) => {
|
||||
eprintln!("Error occurred: {:?}", value);
|
||||
JniError::Other(-1)
|
||||
}
|
||||
@@ -36,13 +36,13 @@ impl From<LimboError> for JniError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<jni::errors::Error> for LimboError {
|
||||
impl From<jni::errors::Error> for TursoError {
|
||||
fn from(value: jni::errors::Error) -> Self {
|
||||
LimboError::JNIErrors(value)
|
||||
TursoError::JNIErrors(value)
|
||||
}
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, LimboError>;
|
||||
pub type Result<T> = std::result::Result<T, TursoError>;
|
||||
|
||||
pub const SQLITE_OK: i32 = 0; // Successful result
|
||||
pub const SQLITE_ERROR: i32 = 1; // Generic error
|
||||
@@ -106,6 +106,6 @@ pub const SQLITE_BLOB: i32 = 4;
|
||||
#[allow(dead_code)]
|
||||
pub const SQLITE_NULL: i32 = 5;
|
||||
|
||||
pub const LIMBO_FAILED_TO_PARSE_BYTE_ARRAY: i32 = 1100;
|
||||
pub const LIMBO_FAILED_TO_PREPARE_STATEMENT: i32 = 1200;
|
||||
pub const LIMBO_ETC: i32 = 9999;
|
||||
pub const TURSO_FAILED_TO_PARSE_BYTE_ARRAY: i32 = 1100;
|
||||
pub const TURSO_FAILED_TO_PREPARE_STATEMENT: i32 = 1200;
|
||||
pub const TURSO_ETC: i32 = 9999;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
mod errors;
|
||||
mod limbo_connection;
|
||||
mod limbo_db;
|
||||
mod limbo_statement;
|
||||
mod turso_connection;
|
||||
mod turso_db;
|
||||
mod turso_statement;
|
||||
mod utils;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::errors::{
|
||||
LimboError, Result, LIMBO_ETC, LIMBO_FAILED_TO_PARSE_BYTE_ARRAY,
|
||||
LIMBO_FAILED_TO_PREPARE_STATEMENT,
|
||||
Result, TursoError, TURSO_ETC, TURSO_FAILED_TO_PARSE_BYTE_ARRAY,
|
||||
TURSO_FAILED_TO_PREPARE_STATEMENT,
|
||||
};
|
||||
use crate::limbo_statement::LimboStatement;
|
||||
use crate::turso_statement::TursoStatement;
|
||||
use crate::utils::{set_err_msg_and_throw_exception, utf8_byte_arr_to_str};
|
||||
use jni::objects::{JByteArray, JObject};
|
||||
use jni::sys::jlong;
|
||||
@@ -11,14 +11,14 @@ use std::sync::Arc;
|
||||
use turso_core::Connection;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct LimboConnection {
|
||||
pub struct TursoConnection {
|
||||
pub(crate) conn: Arc<Connection>,
|
||||
pub(crate) io: Arc<dyn turso_core::IO>,
|
||||
}
|
||||
|
||||
impl LimboConnection {
|
||||
impl TursoConnection {
|
||||
pub fn new(conn: Arc<Connection>, io: Arc<dyn turso_core::IO>) -> Self {
|
||||
LimboConnection { conn, io }
|
||||
TursoConnection { conn, io }
|
||||
}
|
||||
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
@@ -27,38 +27,38 @@ impl LimboConnection {
|
||||
}
|
||||
|
||||
pub fn drop(ptr: jlong) {
|
||||
let _boxed = unsafe { Box::from_raw(ptr as *mut LimboConnection) };
|
||||
let _boxed = unsafe { Box::from_raw(ptr as *mut TursoConnection) };
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_limbo_connection(ptr: jlong) -> Result<&'static mut LimboConnection> {
|
||||
pub fn to_turso_connection(ptr: jlong) -> Result<&'static mut TursoConnection> {
|
||||
if ptr == 0 {
|
||||
Err(LimboError::InvalidConnectionPointer)
|
||||
Err(TursoError::InvalidConnectionPointer)
|
||||
} else {
|
||||
unsafe { Ok(&mut *(ptr as *mut LimboConnection)) }
|
||||
unsafe { Ok(&mut *(ptr as *mut TursoConnection)) }
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "system" fn Java_tech_turso_core_LimboConnection__1close<'local>(
|
||||
pub extern "system" fn Java_tech_turso_core_TursoConnection__1close<'local>(
|
||||
_env: JNIEnv<'local>,
|
||||
_obj: JObject<'local>,
|
||||
connection_ptr: jlong,
|
||||
) {
|
||||
LimboConnection::drop(connection_ptr);
|
||||
TursoConnection::drop(connection_ptr);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "system" fn Java_tech_turso_core_LimboConnection_prepareUtf8<'local>(
|
||||
pub extern "system" fn Java_tech_turso_core_TursoConnection_prepareUtf8<'local>(
|
||||
mut env: JNIEnv<'local>,
|
||||
obj: JObject<'local>,
|
||||
connection_ptr: jlong,
|
||||
sql_bytes: JByteArray<'local>,
|
||||
) -> jlong {
|
||||
let connection = match to_limbo_connection(connection_ptr) {
|
||||
let connection = match to_turso_connection(connection_ptr) {
|
||||
Ok(conn) => conn,
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, LIMBO_ETC, e.to_string());
|
||||
set_err_msg_and_throw_exception(&mut env, obj, TURSO_ETC, e.to_string());
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
@@ -69,7 +69,7 @@ pub extern "system" fn Java_tech_turso_core_LimboConnection_prepareUtf8<'local>(
|
||||
set_err_msg_and_throw_exception(
|
||||
&mut env,
|
||||
obj,
|
||||
LIMBO_FAILED_TO_PARSE_BYTE_ARRAY,
|
||||
TURSO_FAILED_TO_PARSE_BYTE_ARRAY,
|
||||
e.to_string(),
|
||||
);
|
||||
return 0;
|
||||
@@ -77,12 +77,12 @@ pub extern "system" fn Java_tech_turso_core_LimboConnection_prepareUtf8<'local>(
|
||||
};
|
||||
|
||||
match connection.conn.prepare(sql) {
|
||||
Ok(stmt) => LimboStatement::new(stmt, connection.clone()).to_ptr(),
|
||||
Ok(stmt) => TursoStatement::new(stmt, connection.clone()).to_ptr(),
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(
|
||||
&mut env,
|
||||
obj,
|
||||
LIMBO_FAILED_TO_PREPARE_STATEMENT,
|
||||
TURSO_FAILED_TO_PREPARE_STATEMENT,
|
||||
e.to_string(),
|
||||
);
|
||||
0
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::errors::{LimboError, Result, LIMBO_ETC};
|
||||
use crate::limbo_connection::LimboConnection;
|
||||
use crate::errors::{Result, TursoError, TURSO_ETC};
|
||||
use crate::turso_connection::TursoConnection;
|
||||
use crate::utils::set_err_msg_and_throw_exception;
|
||||
use jni::objects::{JByteArray, JObject};
|
||||
use jni::sys::{jint, jlong};
|
||||
@@ -7,14 +7,14 @@ use jni::JNIEnv;
|
||||
use std::sync::Arc;
|
||||
use turso_core::Database;
|
||||
|
||||
struct LimboDB {
|
||||
struct TursoDB {
|
||||
db: Arc<Database>,
|
||||
io: Arc<dyn turso_core::IO>,
|
||||
}
|
||||
|
||||
impl LimboDB {
|
||||
impl TursoDB {
|
||||
pub fn new(db: Arc<Database>, io: Arc<dyn turso_core::IO>) -> Self {
|
||||
LimboDB { db, io }
|
||||
TursoDB { db, io }
|
||||
}
|
||||
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
@@ -23,21 +23,21 @@ impl LimboDB {
|
||||
}
|
||||
|
||||
pub fn drop(ptr: jlong) {
|
||||
let _boxed = unsafe { Box::from_raw(ptr as *mut LimboDB) };
|
||||
let _boxed = unsafe { Box::from_raw(ptr as *mut TursoDB) };
|
||||
}
|
||||
}
|
||||
|
||||
fn to_limbo_db(ptr: jlong) -> Result<&'static mut LimboDB> {
|
||||
fn to_turso_db(ptr: jlong) -> Result<&'static mut TursoDB> {
|
||||
if ptr == 0 {
|
||||
Err(LimboError::InvalidDatabasePointer)
|
||||
Err(TursoError::InvalidDatabasePointer)
|
||||
} else {
|
||||
unsafe { Ok(&mut *(ptr as *mut LimboDB)) }
|
||||
unsafe { Ok(&mut *(ptr as *mut TursoDB)) }
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
pub extern "system" fn Java_tech_turso_core_LimboDB_openUtf8<'local>(
|
||||
pub extern "system" fn Java_tech_turso_core_TursoDB_openUtf8<'local>(
|
||||
mut env: JNIEnv<'local>,
|
||||
obj: JObject<'local>,
|
||||
file_path_byte_arr: JByteArray<'local>,
|
||||
@@ -46,7 +46,7 @@ pub extern "system" fn Java_tech_turso_core_LimboDB_openUtf8<'local>(
|
||||
let io = match turso_core::PlatformIO::new() {
|
||||
Ok(io) => Arc::new(io),
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, LIMBO_ETC, e.to_string());
|
||||
set_err_msg_and_throw_exception(&mut env, obj, TURSO_ETC, e.to_string());
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
@@ -58,12 +58,12 @@ pub extern "system" fn Java_tech_turso_core_LimboDB_openUtf8<'local>(
|
||||
Ok(bytes) => match String::from_utf8(bytes) {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, LIMBO_ETC, e.to_string());
|
||||
set_err_msg_and_throw_exception(&mut env, obj, TURSO_ETC, e.to_string());
|
||||
return -1;
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, LIMBO_ETC, e.to_string());
|
||||
set_err_msg_and_throw_exception(&mut env, obj, TURSO_ETC, e.to_string());
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
@@ -71,43 +71,43 @@ pub extern "system" fn Java_tech_turso_core_LimboDB_openUtf8<'local>(
|
||||
let db = match Database::open_file(io.clone(), &path, false, false) {
|
||||
Ok(db) => db,
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, LIMBO_ETC, e.to_string());
|
||||
set_err_msg_and_throw_exception(&mut env, obj, TURSO_ETC, e.to_string());
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
LimboDB::new(db, io).to_ptr()
|
||||
TursoDB::new(db, io).to_ptr()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "system" fn Java_tech_turso_core_LimboDB_connect0<'local>(
|
||||
pub extern "system" fn Java_tech_turso_core_TursoDB_connect0<'local>(
|
||||
mut env: JNIEnv<'local>,
|
||||
obj: JObject<'local>,
|
||||
db_pointer: jlong,
|
||||
) -> jlong {
|
||||
let db = match to_limbo_db(db_pointer) {
|
||||
let db = match to_turso_db(db_pointer) {
|
||||
Ok(db) => db,
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, LIMBO_ETC, e.to_string());
|
||||
set_err_msg_and_throw_exception(&mut env, obj, TURSO_ETC, e.to_string());
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
let conn = LimboConnection::new(db.db.connect().unwrap(), db.io.clone());
|
||||
let conn = TursoConnection::new(db.db.connect().unwrap(), db.io.clone());
|
||||
conn.to_ptr()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "system" fn Java_tech_turso_core_LimboDB_close0<'local>(
|
||||
pub extern "system" fn Java_tech_turso_core_TursoDB_close0<'local>(
|
||||
_env: JNIEnv<'local>,
|
||||
_obj: JObject<'local>,
|
||||
db_pointer: jlong,
|
||||
) {
|
||||
LimboDB::drop(db_pointer);
|
||||
TursoDB::drop(db_pointer);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "system" fn Java_tech_turso_core_LimboDB_throwJavaException<'local>(
|
||||
pub extern "system" fn Java_tech_turso_core_TursoDB_throwJavaException<'local>(
|
||||
mut env: JNIEnv<'local>,
|
||||
obj: JObject<'local>,
|
||||
error_code: jint,
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::errors::{LimboError, LIMBO_ETC};
|
||||
use crate::errors::{Result, SQLITE_ERROR, SQLITE_OK};
|
||||
use crate::limbo_connection::LimboConnection;
|
||||
use crate::errors::{TursoError, TURSO_ETC};
|
||||
use crate::turso_connection::TursoConnection;
|
||||
use crate::utils::set_err_msg_and_throw_exception;
|
||||
use jni::objects::{JByteArray, JObject, JObjectArray, JString, JValue};
|
||||
use jni::sys::{jdouble, jint, jlong};
|
||||
@@ -16,14 +16,14 @@ pub const STEP_RESULT_ID_INTERRUPT: i32 = 40;
|
||||
pub const STEP_RESULT_ID_BUSY: i32 = 50;
|
||||
pub const STEP_RESULT_ID_ERROR: i32 = 60;
|
||||
|
||||
pub struct LimboStatement {
|
||||
pub struct TursoStatement {
|
||||
pub(crate) stmt: Statement,
|
||||
pub(crate) connection: LimboConnection,
|
||||
pub(crate) connection: TursoConnection,
|
||||
}
|
||||
|
||||
impl LimboStatement {
|
||||
pub fn new(stmt: Statement, connection: LimboConnection) -> Self {
|
||||
LimboStatement { stmt, connection }
|
||||
impl TursoStatement {
|
||||
pub fn new(stmt: Statement, connection: TursoConnection) -> Self {
|
||||
TursoStatement { stmt, connection }
|
||||
}
|
||||
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
@@ -32,71 +32,71 @@ impl LimboStatement {
|
||||
}
|
||||
|
||||
pub fn drop(ptr: jlong) {
|
||||
let _boxed = unsafe { Box::from_raw(ptr as *mut LimboStatement) };
|
||||
let _boxed = unsafe { Box::from_raw(ptr as *mut TursoStatement) };
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_limbo_statement(ptr: jlong) -> Result<&'static mut LimboStatement> {
|
||||
pub fn to_turso_statement(ptr: jlong) -> Result<&'static mut TursoStatement> {
|
||||
if ptr == 0 {
|
||||
Err(LimboError::InvalidConnectionPointer)
|
||||
Err(TursoError::InvalidConnectionPointer)
|
||||
} else {
|
||||
unsafe { Ok(&mut *(ptr as *mut LimboStatement)) }
|
||||
unsafe { Ok(&mut *(ptr as *mut TursoStatement)) }
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "system" fn Java_tech_turso_core_LimboStatement_step<'local>(
|
||||
pub extern "system" fn Java_tech_turso_core_TursoStatement_step<'local>(
|
||||
mut env: JNIEnv<'local>,
|
||||
obj: JObject<'local>,
|
||||
stmt_ptr: jlong,
|
||||
) -> JObject<'local> {
|
||||
let stmt = match to_limbo_statement(stmt_ptr) {
|
||||
let stmt = match to_turso_statement(stmt_ptr) {
|
||||
Ok(stmt) => stmt,
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, LIMBO_ETC, e.to_string());
|
||||
return to_limbo_step_result(&mut env, STEP_RESULT_ID_ERROR, None);
|
||||
set_err_msg_and_throw_exception(&mut env, obj, TURSO_ETC, e.to_string());
|
||||
return to_turso_step_result(&mut env, STEP_RESULT_ID_ERROR, None);
|
||||
}
|
||||
};
|
||||
|
||||
loop {
|
||||
let step_result = match stmt.stmt.step() {
|
||||
Ok(result) => result,
|
||||
Err(_) => return to_limbo_step_result(&mut env, STEP_RESULT_ID_ERROR, None),
|
||||
Err(_) => return to_turso_step_result(&mut env, STEP_RESULT_ID_ERROR, None),
|
||||
};
|
||||
|
||||
match step_result {
|
||||
StepResult::Row => {
|
||||
let row = stmt.stmt.row().unwrap();
|
||||
return match row_to_obj_array(&mut env, row) {
|
||||
Ok(row) => to_limbo_step_result(&mut env, STEP_RESULT_ID_ROW, Some(row)),
|
||||
Ok(row) => to_turso_step_result(&mut env, STEP_RESULT_ID_ROW, Some(row)),
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, LIMBO_ETC, e.to_string());
|
||||
to_limbo_step_result(&mut env, STEP_RESULT_ID_ERROR, None)
|
||||
set_err_msg_and_throw_exception(&mut env, obj, TURSO_ETC, e.to_string());
|
||||
to_turso_step_result(&mut env, STEP_RESULT_ID_ERROR, None)
|
||||
}
|
||||
};
|
||||
}
|
||||
StepResult::IO => {
|
||||
if let Err(e) = stmt.connection.io.run_once() {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, LIMBO_ETC, e.to_string());
|
||||
return to_limbo_step_result(&mut env, STEP_RESULT_ID_ERROR, None);
|
||||
set_err_msg_and_throw_exception(&mut env, obj, TURSO_ETC, e.to_string());
|
||||
return to_turso_step_result(&mut env, STEP_RESULT_ID_ERROR, None);
|
||||
}
|
||||
}
|
||||
StepResult::Done => return to_limbo_step_result(&mut env, STEP_RESULT_ID_DONE, None),
|
||||
StepResult::Done => return to_turso_step_result(&mut env, STEP_RESULT_ID_DONE, None),
|
||||
StepResult::Interrupt => {
|
||||
return to_limbo_step_result(&mut env, STEP_RESULT_ID_INTERRUPT, None)
|
||||
return to_turso_step_result(&mut env, STEP_RESULT_ID_INTERRUPT, None)
|
||||
}
|
||||
StepResult::Busy => return to_limbo_step_result(&mut env, STEP_RESULT_ID_BUSY, None),
|
||||
StepResult::Busy => return to_turso_step_result(&mut env, STEP_RESULT_ID_BUSY, None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "system" fn Java_tech_turso_core_LimboStatement__1close<'local>(
|
||||
pub extern "system" fn Java_tech_turso_core_TursoStatement__1close<'local>(
|
||||
_env: JNIEnv<'local>,
|
||||
_obj: JObject<'local>,
|
||||
stmt_ptr: jlong,
|
||||
) {
|
||||
LimboStatement::drop(stmt_ptr);
|
||||
TursoStatement::drop(stmt_ptr);
|
||||
}
|
||||
|
||||
fn row_to_obj_array<'local>(
|
||||
@@ -126,12 +126,12 @@ fn row_to_obj_array<'local>(
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "system" fn Java_tech_turso_core_LimboStatement_columns<'local>(
|
||||
pub extern "system" fn Java_tech_turso_core_TursoStatement_columns<'local>(
|
||||
mut env: JNIEnv<'local>,
|
||||
_obj: JObject<'local>,
|
||||
stmt_ptr: jlong,
|
||||
) -> JObject<'local> {
|
||||
let stmt = to_limbo_statement(stmt_ptr).unwrap();
|
||||
let stmt = to_turso_statement(stmt_ptr).unwrap();
|
||||
let num_columns = stmt.stmt.num_columns();
|
||||
let obj_arr: JObjectArray = env
|
||||
.new_object_array(num_columns as i32, "java/lang/String", JObject::null())
|
||||
@@ -148,13 +148,13 @@ pub extern "system" fn Java_tech_turso_core_LimboStatement_columns<'local>(
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "system" fn Java_tech_turso_core_LimboStatement_bindNull<'local>(
|
||||
pub extern "system" fn Java_tech_turso_core_TursoStatement_bindNull<'local>(
|
||||
mut env: JNIEnv<'local>,
|
||||
obj: JObject<'local>,
|
||||
stmt_ptr: jlong,
|
||||
position: jint,
|
||||
) -> jint {
|
||||
let stmt = match to_limbo_statement(stmt_ptr) {
|
||||
let stmt = match to_turso_statement(stmt_ptr) {
|
||||
Ok(stmt) => stmt,
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, SQLITE_ERROR, e.to_string());
|
||||
@@ -168,14 +168,14 @@ pub extern "system" fn Java_tech_turso_core_LimboStatement_bindNull<'local>(
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "system" fn Java_tech_turso_core_LimboStatement_bindLong<'local>(
|
||||
pub extern "system" fn Java_tech_turso_core_TursoStatement_bindLong<'local>(
|
||||
mut env: JNIEnv<'local>,
|
||||
obj: JObject<'local>,
|
||||
stmt_ptr: jlong,
|
||||
position: jint,
|
||||
value: jlong,
|
||||
) -> jint {
|
||||
let stmt = match to_limbo_statement(stmt_ptr) {
|
||||
let stmt = match to_turso_statement(stmt_ptr) {
|
||||
Ok(stmt) => stmt,
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, SQLITE_ERROR, e.to_string());
|
||||
@@ -191,14 +191,14 @@ pub extern "system" fn Java_tech_turso_core_LimboStatement_bindLong<'local>(
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "system" fn Java_tech_turso_core_LimboStatement_bindDouble<'local>(
|
||||
pub extern "system" fn Java_tech_turso_core_TursoStatement_bindDouble<'local>(
|
||||
mut env: JNIEnv<'local>,
|
||||
obj: JObject<'local>,
|
||||
stmt_ptr: jlong,
|
||||
position: jint,
|
||||
value: jdouble,
|
||||
) -> jint {
|
||||
let stmt = match to_limbo_statement(stmt_ptr) {
|
||||
let stmt = match to_turso_statement(stmt_ptr) {
|
||||
Ok(stmt) => stmt,
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, SQLITE_ERROR, e.to_string());
|
||||
@@ -214,14 +214,14 @@ pub extern "system" fn Java_tech_turso_core_LimboStatement_bindDouble<'local>(
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "system" fn Java_tech_turso_core_LimboStatement_bindText<'local>(
|
||||
pub extern "system" fn Java_tech_turso_core_TursoStatement_bindText<'local>(
|
||||
mut env: JNIEnv<'local>,
|
||||
obj: JObject<'local>,
|
||||
stmt_ptr: jlong,
|
||||
position: jint,
|
||||
value: JString<'local>,
|
||||
) -> jint {
|
||||
let stmt = match to_limbo_statement(stmt_ptr) {
|
||||
let stmt = match to_turso_statement(stmt_ptr) {
|
||||
Ok(stmt) => stmt,
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, SQLITE_ERROR, e.to_string());
|
||||
@@ -242,14 +242,14 @@ pub extern "system" fn Java_tech_turso_core_LimboStatement_bindText<'local>(
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "system" fn Java_tech_turso_core_LimboStatement_bindBlob<'local>(
|
||||
pub extern "system" fn Java_tech_turso_core_TursoStatement_bindBlob<'local>(
|
||||
mut env: JNIEnv<'local>,
|
||||
obj: JObject<'local>,
|
||||
stmt_ptr: jlong,
|
||||
position: jint,
|
||||
value: JByteArray<'local>,
|
||||
) -> jint {
|
||||
let stmt = match to_limbo_statement(stmt_ptr) {
|
||||
let stmt = match to_turso_statement(stmt_ptr) {
|
||||
Ok(stmt) => stmt,
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, SQLITE_ERROR, e.to_string());
|
||||
@@ -268,12 +268,12 @@ pub extern "system" fn Java_tech_turso_core_LimboStatement_bindBlob<'local>(
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "system" fn Java_tech_turso_core_LimboStatement_totalChanges<'local>(
|
||||
pub extern "system" fn Java_tech_turso_core_TursoStatement_totalChanges<'local>(
|
||||
mut env: JNIEnv<'local>,
|
||||
obj: JObject<'local>,
|
||||
stmt_ptr: jlong,
|
||||
) -> jlong {
|
||||
let stmt = match to_limbo_statement(stmt_ptr) {
|
||||
let stmt = match to_turso_statement(stmt_ptr) {
|
||||
Ok(stmt) => stmt,
|
||||
Err(e) => {
|
||||
set_err_msg_and_throw_exception(&mut env, obj, SQLITE_ERROR, e.to_string());
|
||||
@@ -284,10 +284,10 @@ pub extern "system" fn Java_tech_turso_core_LimboStatement_totalChanges<'local>(
|
||||
stmt.connection.conn.total_changes()
|
||||
}
|
||||
|
||||
/// Converts an optional `JObject` into Java's `LimboStepResult`.
|
||||
/// Converts an optional `JObject` into Java's `TursoStepResult`.
|
||||
///
|
||||
/// This function takes an optional `JObject` and converts it into a Java object
|
||||
/// of type `LimboStepResult`. The conversion is done by creating a new Java object with the
|
||||
/// of type `TursoStepResult`. The conversion is done by creating a new Java object with the
|
||||
/// appropriate constructor arguments.
|
||||
///
|
||||
/// # Arguments
|
||||
@@ -298,9 +298,9 @@ pub extern "system" fn Java_tech_turso_core_LimboStatement_totalChanges<'local>(
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// A `JObject` representing the `LimboStepResult` in Java. If the object creation fails,
|
||||
/// A `JObject` representing the `TursoStepResult` in Java. If the object creation fails,
|
||||
/// a null `JObject` is returned
|
||||
fn to_limbo_step_result<'local>(
|
||||
fn to_turso_step_result<'local>(
|
||||
env: &mut JNIEnv<'local>,
|
||||
id: i32,
|
||||
result: Option<JObject<'local>>,
|
||||
@@ -309,12 +309,12 @@ fn to_limbo_step_result<'local>(
|
||||
if let Some(res) = result {
|
||||
ctor_args.push(JValue::Object(&res));
|
||||
env.new_object(
|
||||
"tech/turso/core/LimboStepResult",
|
||||
"tech/turso/core/TursoStepResult",
|
||||
"(I[Ljava/lang/Object;)V",
|
||||
&ctor_args,
|
||||
)
|
||||
} else {
|
||||
env.new_object("tech/turso/core/LimboStepResult", "(I)V", &ctor_args)
|
||||
env.new_object("tech/turso/core/TursoStepResult", "(I)V", &ctor_args)
|
||||
}
|
||||
.unwrap_or_else(|_| JObject::null())
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::errors::LimboError;
|
||||
use crate::errors::TursoError;
|
||||
use jni::objects::{JByteArray, JObject};
|
||||
use jni::JNIEnv;
|
||||
|
||||
@@ -8,9 +8,9 @@ pub(crate) fn utf8_byte_arr_to_str(
|
||||
) -> crate::errors::Result<String> {
|
||||
let bytes = env
|
||||
.convert_byte_array(bytes)
|
||||
.map_err(|_| LimboError::CustomError("Failed to retrieve bytes".to_string()))?;
|
||||
.map_err(|_| TursoError::CustomError("Failed to retrieve bytes".to_string()))?;
|
||||
let str = String::from_utf8(bytes).map_err(|_| {
|
||||
LimboError::CustomError("Failed to convert utf8 byte array into string".to_string())
|
||||
TursoError::CustomError("Failed to convert utf8 byte array into string".to_string())
|
||||
})?;
|
||||
Ok(str)
|
||||
}
|
||||
@@ -18,7 +18,7 @@ pub(crate) fn utf8_byte_arr_to_str(
|
||||
/// Sets the error message and throws a Java exception.
|
||||
///
|
||||
/// This function converts the provided error message to a byte array and calls the
|
||||
/// `throwLimboException` method on the provided Java object to throw an exception.
|
||||
/// `throwTursoException` method on the provided Java object to throw an exception.
|
||||
///
|
||||
/// # Parameters
|
||||
/// - `env`: The JNI environment.
|
||||
@@ -41,7 +41,7 @@ pub fn set_err_msg_and_throw_exception<'local>(
|
||||
.expect("Failed to convert to byte array");
|
||||
match env.call_method(
|
||||
obj,
|
||||
"throwLimboException",
|
||||
"throwTursoException",
|
||||
"(I[B)V",
|
||||
&[err_code.into(), (&error_message_bytes).into()],
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user