mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 01:58:16 +00:00
core: Kill value type
We currently have two value types, `Value` and `OwnedValue`. The original thinking was that `Value` is external type and `OwnedValue` is internal type. However, this just results in unnecessary transformation between the types as data crosses the Limbo library boundary. Let's just follow SQLite here and consolidate on a single value type (where `sqlite3_value` is just an alias for the internal `Mem` type). The way this will eventually work is that we can have bunch of pre-allocated `OwnedValue` objects in `ProgramState` and basically return a reference to them all the way to the application itself, which extracts the actual value.
This commit is contained in:
parent
fe440b7b34
commit
936ae307b7
16 changed files with 220 additions and 243 deletions
|
@ -5,8 +5,9 @@ use crate::utils::set_err_msg_and_throw_exception;
|
|||
use jni::objects::{JByteArray, JObject, JObjectArray, JString, JValue};
|
||||
use jni::sys::{jdouble, jint, jlong};
|
||||
use jni::JNIEnv;
|
||||
use limbo_core::{Statement, StepResult, Value};
|
||||
use limbo_core::{OwnedValue, Statement, StepResult};
|
||||
use std::num::NonZero;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub const STEP_RESULT_ID_ROW: i32 = 10;
|
||||
#[allow(dead_code)]
|
||||
|
@ -105,17 +106,17 @@ fn row_to_obj_array<'local>(
|
|||
let obj_array = env.new_object_array(row.len() as i32, "java/lang/Object", JObject::null())?;
|
||||
|
||||
for (i, value) in row.get_values().iter().enumerate() {
|
||||
let value = value.to_value();
|
||||
let obj = match value {
|
||||
limbo_core::Value::Null => JObject::null(),
|
||||
limbo_core::Value::Integer(i) => {
|
||||
env.new_object("java/lang/Long", "(J)V", &[JValue::Long(i)])?
|
||||
limbo_core::OwnedValue::Null => JObject::null(),
|
||||
limbo_core::OwnedValue::Integer(i) => {
|
||||
env.new_object("java/lang/Long", "(J)V", &[JValue::Long(*i)])?
|
||||
}
|
||||
limbo_core::Value::Float(f) => {
|
||||
env.new_object("java/lang/Double", "(D)V", &[JValue::Double(f)])?
|
||||
limbo_core::OwnedValue::Float(f) => {
|
||||
env.new_object("java/lang/Double", "(D)V", &[JValue::Double(*f)])?
|
||||
}
|
||||
limbo_core::Value::Text(s) => env.new_string(s)?.into(),
|
||||
limbo_core::Value::Blob(b) => env.byte_array_from_slice(b)?.into(),
|
||||
limbo_core::OwnedValue::Text(s) => env.new_string(s.as_str())?.into(),
|
||||
limbo_core::OwnedValue::Blob(b) => env.byte_array_from_slice(&b)?.into(),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
if let Err(e) = env.set_object_array_element(&obj_array, i as i32, obj) {
|
||||
eprintln!("Error on parsing row: {:?}", e);
|
||||
|
@ -163,7 +164,7 @@ pub extern "system" fn Java_tech_turso_core_LimboStatement_bindNull<'local>(
|
|||
};
|
||||
|
||||
stmt.stmt
|
||||
.bind_at(NonZero::new(position as usize).unwrap(), Value::Null);
|
||||
.bind_at(NonZero::new(position as usize).unwrap(), OwnedValue::Null);
|
||||
SQLITE_OK
|
||||
}
|
||||
|
||||
|
@ -185,7 +186,7 @@ pub extern "system" fn Java_tech_turso_core_LimboStatement_bindLong<'local>(
|
|||
|
||||
stmt.stmt.bind_at(
|
||||
NonZero::new(position as usize).unwrap(),
|
||||
Value::Integer(value),
|
||||
OwnedValue::Integer(value),
|
||||
);
|
||||
SQLITE_OK
|
||||
}
|
||||
|
@ -208,7 +209,7 @@ pub extern "system" fn Java_tech_turso_core_LimboStatement_bindDouble<'local>(
|
|||
|
||||
stmt.stmt.bind_at(
|
||||
NonZero::new(position as usize).unwrap(),
|
||||
Value::Float(value),
|
||||
OwnedValue::Float(value),
|
||||
);
|
||||
SQLITE_OK
|
||||
}
|
||||
|
@ -236,7 +237,7 @@ pub extern "system" fn Java_tech_turso_core_LimboStatement_bindText<'local>(
|
|||
|
||||
stmt.stmt.bind_at(
|
||||
NonZero::new(position as usize).unwrap(),
|
||||
Value::Text(text.as_str()),
|
||||
OwnedValue::build_text(text.as_str()),
|
||||
);
|
||||
SQLITE_OK
|
||||
}
|
||||
|
@ -264,7 +265,7 @@ pub extern "system" fn Java_tech_turso_core_LimboStatement_bindBlob<'local>(
|
|||
|
||||
stmt.stmt.bind_at(
|
||||
NonZero::new(position as usize).unwrap(),
|
||||
Value::Blob(blob.as_ref()),
|
||||
OwnedValue::Blob(Rc::new(blob)),
|
||||
);
|
||||
SQLITE_OK
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue