mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-09 18:24:20 +01:00
Code refactor
This commit is contained in:
@@ -72,18 +72,6 @@ impl OwnedValue {
|
||||
pub fn build_text(text: Rc<String>) -> Self {
|
||||
Self::Text(LimboText::new(text))
|
||||
}
|
||||
|
||||
pub fn value_to_string(value: &OwnedValue) -> String {
|
||||
match value {
|
||||
OwnedValue::Text(text) => text.value.as_ref().clone(),
|
||||
OwnedValue::Integer(i) => i.to_string(),
|
||||
OwnedValue::Float(f) => f.to_string(),
|
||||
OwnedValue::Agg(aggctx) => aggctx.final_value().to_string(),
|
||||
OwnedValue::Null => String::new(),
|
||||
OwnedValue::Blob(_) => todo!("TODO: Handle Blob conversion to String"),
|
||||
OwnedValue::Record(_) => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
||||
@@ -1118,7 +1118,7 @@ pub fn insn_to_str(
|
||||
*dest as i32,
|
||||
OwnedValue::build_text(Rc::new("".to_string())),
|
||||
0,
|
||||
format!("r[{}]=r[{}] << r[{}]", dest, lhs, rhs)
|
||||
format!("r[{}]=r[{}] + r[{}]", dest, lhs, rhs),
|
||||
),
|
||||
};
|
||||
format!(
|
||||
|
||||
@@ -895,13 +895,63 @@ pub fn exec_boolean_not(mut reg: &OwnedValue) -> OwnedValue {
|
||||
}
|
||||
|
||||
pub fn exec_concat(lhs: &OwnedValue, rhs: &OwnedValue) -> OwnedValue {
|
||||
let lhs_value = OwnedValue::value_to_string(lhs);
|
||||
let rhs_value = OwnedValue::value_to_string(rhs);
|
||||
match (lhs, rhs) {
|
||||
(OwnedValue::Text(lhs_text), OwnedValue::Text(rhs_text)) => {
|
||||
OwnedValue::build_text(Rc::new(lhs_text.value.as_ref().clone() + &rhs_text.value))
|
||||
}
|
||||
(OwnedValue::Text(lhs_text), OwnedValue::Integer(rhs_int)) => OwnedValue::build_text(
|
||||
Rc::new(lhs_text.value.as_ref().clone() + &rhs_int.to_string()),
|
||||
),
|
||||
(OwnedValue::Text(lhs_text), OwnedValue::Float(rhs_float)) => OwnedValue::build_text(
|
||||
Rc::new(lhs_text.value.as_ref().clone() + &rhs_float.to_string()),
|
||||
),
|
||||
(OwnedValue::Text(lhs_text), OwnedValue::Agg(rhs_agg)) => OwnedValue::build_text(Rc::new(
|
||||
lhs_text.value.as_ref().clone() + &rhs_agg.final_value().to_string(),
|
||||
)),
|
||||
|
||||
if lhs_value.is_empty() || rhs_value.is_empty() {
|
||||
OwnedValue::Null
|
||||
} else {
|
||||
let result = lhs_value + &rhs_value;
|
||||
OwnedValue::build_text(Rc::new(result))
|
||||
(OwnedValue::Integer(lhs_int), OwnedValue::Text(rhs_text)) => {
|
||||
OwnedValue::build_text(Rc::new(lhs_int.to_string() + &rhs_text.value))
|
||||
}
|
||||
(OwnedValue::Integer(lhs_int), OwnedValue::Integer(rhs_int)) => {
|
||||
OwnedValue::build_text(Rc::new(lhs_int.to_string() + &rhs_int.to_string()))
|
||||
}
|
||||
(OwnedValue::Integer(lhs_int), OwnedValue::Float(rhs_float)) => {
|
||||
OwnedValue::build_text(Rc::new(lhs_int.to_string() + &rhs_float.to_string()))
|
||||
}
|
||||
(OwnedValue::Integer(lhs_int), OwnedValue::Agg(rhs_agg)) => OwnedValue::build_text(
|
||||
Rc::new(lhs_int.to_string() + &rhs_agg.final_value().to_string()),
|
||||
),
|
||||
|
||||
(OwnedValue::Float(lhs_float), OwnedValue::Text(rhs_text)) => {
|
||||
OwnedValue::build_text(Rc::new(lhs_float.to_string() + &rhs_text.value))
|
||||
}
|
||||
(OwnedValue::Float(lhs_float), OwnedValue::Integer(rhs_int)) => {
|
||||
OwnedValue::build_text(Rc::new(lhs_float.to_string() + &rhs_int.to_string()))
|
||||
}
|
||||
(OwnedValue::Float(lhs_float), OwnedValue::Float(rhs_float)) => {
|
||||
OwnedValue::build_text(Rc::new(lhs_float.to_string() + &rhs_float.to_string()))
|
||||
}
|
||||
(OwnedValue::Float(lhs_float), OwnedValue::Agg(rhs_agg)) => OwnedValue::build_text(
|
||||
Rc::new(lhs_float.to_string() + &rhs_agg.final_value().to_string()),
|
||||
),
|
||||
|
||||
(OwnedValue::Agg(lhs_agg), OwnedValue::Text(rhs_text)) => {
|
||||
OwnedValue::build_text(Rc::new(lhs_agg.final_value().to_string() + &rhs_text.value))
|
||||
}
|
||||
(OwnedValue::Agg(lhs_agg), OwnedValue::Integer(rhs_int)) => OwnedValue::build_text(
|
||||
Rc::new(lhs_agg.final_value().to_string() + &rhs_int.to_string()),
|
||||
),
|
||||
(OwnedValue::Agg(lhs_agg), OwnedValue::Float(rhs_float)) => OwnedValue::build_text(
|
||||
Rc::new(lhs_agg.final_value().to_string() + &rhs_float.to_string()),
|
||||
),
|
||||
(OwnedValue::Agg(lhs_agg), OwnedValue::Agg(rhs_agg)) => OwnedValue::build_text(Rc::new(
|
||||
lhs_agg.final_value().to_string() + &rhs_agg.final_value().to_string(),
|
||||
)),
|
||||
|
||||
(OwnedValue::Null, _) | (_, OwnedValue::Null) => OwnedValue::Null,
|
||||
(OwnedValue::Blob(_), _) | (_, OwnedValue::Blob(_)) => {
|
||||
todo!("TODO: Handle Blob conversion to String")
|
||||
}
|
||||
(OwnedValue::Record(_), _) | (_, OwnedValue::Record(_)) => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,9 +46,8 @@ use crate::{
|
||||
use crate::{resolve_ext_path, Connection, Result, Rows, TransactionState, DATABASE_VERSION};
|
||||
use datetime::{exec_date, exec_datetime_full, exec_julianday, exec_time, exec_unixepoch};
|
||||
use insn::{
|
||||
exec_add, exec_bit_and, exec_bit_not, exec_bit_or, exec_boolean_not, exec_divide,
|
||||
exec_add, exec_bit_and, exec_bit_not, exec_bit_or, exec_boolean_not, exec_concat, exec_divide,
|
||||
exec_multiply, exec_remainder, exec_shift_left, exec_shift_right, exec_subtract,
|
||||
exec_concat
|
||||
};
|
||||
use likeop::{construct_like_escape_arg, exec_glob, exec_like_with_escape};
|
||||
use rand::distributions::{Distribution, Uniform};
|
||||
@@ -2343,7 +2342,8 @@ impl Program {
|
||||
state.pc += 1;
|
||||
}
|
||||
Insn::Concat { lhs, rhs, dest } => {
|
||||
state.registers[*dest] = exec_concat(&state.registers[*lhs], &state.registers[*rhs]);
|
||||
state.registers[*dest] =
|
||||
exec_concat(&state.registers[*lhs], &state.registers[*rhs]);
|
||||
state.pc += 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user