mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-08 09:44:21 +01:00
remove parameter id assign logic from core
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
use std::num::NonZero;
|
||||
|
||||
pub const PARAM_PREFIX: &str = "__param_";
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Parameter {
|
||||
Anonymous(NonZero<usize>),
|
||||
@@ -78,17 +76,6 @@ impl Parameters {
|
||||
|
||||
pub fn push(&mut self, name: impl AsRef<str>) -> NonZero<usize> {
|
||||
match name.as_ref() {
|
||||
param if param.is_empty() || param.starts_with(PARAM_PREFIX) => {
|
||||
let index = self.next_index();
|
||||
let use_idx = if let Some(idx) = param.strip_prefix(PARAM_PREFIX) {
|
||||
idx.parse().unwrap()
|
||||
} else {
|
||||
index
|
||||
};
|
||||
self.list.push(Parameter::Anonymous(use_idx));
|
||||
tracing::trace!("anonymous parameter at {use_idx}");
|
||||
use_idx
|
||||
}
|
||||
name if name.starts_with(['$', ':', '@', '#']) => {
|
||||
match self
|
||||
.list
|
||||
|
||||
@@ -10,7 +10,6 @@ use super::plan::TableReferences;
|
||||
use crate::function::JsonFunc;
|
||||
use crate::function::{Func, FuncCtx, MathFuncArity, ScalarFunc, VectorFunc};
|
||||
use crate::functions::datetime;
|
||||
use crate::parameters::PARAM_PREFIX;
|
||||
use crate::schema::{affinity, Affinity, Table, Type};
|
||||
use crate::translate::optimizer::TakeOwnership;
|
||||
use crate::translate::plan::ResultSetColumn;
|
||||
@@ -3244,26 +3243,21 @@ where
|
||||
Ok(WalkControl::Continue)
|
||||
}
|
||||
|
||||
/// Context needed to walk all expressions in a INSERT|UPDATE|SELECT|DELETE body,
|
||||
/// in the order they are encountered, to ensure that the parameters are rewritten from
|
||||
/// anonymous ("?") to our internal named scheme so when the columns are re-ordered we are able
|
||||
/// to bind the proper parameter values.
|
||||
pub struct ParamState {
|
||||
/// ALWAYS starts at 1
|
||||
pub next_param_idx: usize,
|
||||
pub allowed: bool,
|
||||
}
|
||||
|
||||
impl Default for ParamState {
|
||||
fn default() -> Self {
|
||||
Self { next_param_idx: 1 }
|
||||
Self { allowed: true }
|
||||
}
|
||||
}
|
||||
impl ParamState {
|
||||
pub fn is_valid(&self) -> bool {
|
||||
self.next_param_idx > 0
|
||||
self.allowed
|
||||
}
|
||||
pub fn disallow() -> Self {
|
||||
Self { next_param_idx: 0 }
|
||||
Self { allowed: false }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3296,16 +3290,10 @@ pub fn bind_and_rewrite_expr<'a>(
|
||||
top_level_expr,
|
||||
&mut |expr: &mut ast::Expr| -> Result<WalkControl> {
|
||||
match expr {
|
||||
// Rewrite anonymous variables in encounter order.
|
||||
ast::Expr::Variable(var) if var.is_empty() => {
|
||||
ast::Expr::Variable(_) => {
|
||||
if !param_state.is_valid() {
|
||||
crate::bail_parse_error!("Parameters are not allowed in this context");
|
||||
}
|
||||
*expr = ast::Expr::Variable(format!(
|
||||
"{}{}",
|
||||
PARAM_PREFIX, param_state.next_param_idx
|
||||
));
|
||||
param_state.next_param_idx += 1;
|
||||
}
|
||||
ast::Expr::Between {
|
||||
lhs,
|
||||
|
||||
Reference in New Issue
Block a user