mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-06 17:54:20 +01:00
move to new parser
This commit is contained in:
@@ -1552,8 +1552,8 @@ pub fn emit_cdc_insns(
|
||||
fn init_limit(
|
||||
program: &mut ProgramBuilder,
|
||||
t_ctx: &mut TranslateCtx,
|
||||
limit: Option<Expr>,
|
||||
offset: Option<Expr>,
|
||||
limit: Option<Box<Expr>>,
|
||||
offset: Option<Box<Expr>>,
|
||||
) {
|
||||
if t_ctx.limit_ctx.is_none() && limit.is_some() {
|
||||
t_ctx.limit_ctx = Some(LimitCtx::new(program));
|
||||
|
||||
@@ -154,8 +154,8 @@ pub enum Plan {
|
||||
CompoundSelect {
|
||||
left: Vec<(SelectPlan, ast::CompoundOperator)>,
|
||||
right_most: SelectPlan,
|
||||
limit: Option<Expr>,
|
||||
offset: Option<Expr>,
|
||||
limit: Option<Box<Expr>>,
|
||||
offset: Option<Box<Expr>>,
|
||||
order_by: Option<Vec<(ast::Expr, SortOrder)>>,
|
||||
},
|
||||
Delete(DeletePlan),
|
||||
@@ -292,9 +292,9 @@ pub struct SelectPlan {
|
||||
/// all the aggregates collected from the result columns, order by, and (TODO) having clauses
|
||||
pub aggregates: Vec<Aggregate>,
|
||||
/// limit clause
|
||||
pub limit: Option<Expr>,
|
||||
pub limit: Option<Box<Expr>>,
|
||||
/// offset clause
|
||||
pub offset: Option<Expr>,
|
||||
pub offset: Option<Box<Expr>>,
|
||||
/// query contains a constant condition that is always false
|
||||
pub contains_constant_false_condition: bool,
|
||||
/// the destination of the resulting rows from this plan.
|
||||
@@ -378,9 +378,9 @@ pub struct DeletePlan {
|
||||
/// order by clause
|
||||
pub order_by: Vec<(Box<ast::Expr>, SortOrder)>,
|
||||
/// limit clause
|
||||
pub limit: Option<Expr>,
|
||||
pub limit: Option<Box<Expr>>,
|
||||
/// offset clause
|
||||
pub offset: Option<Expr>,
|
||||
pub offset: Option<Box<Expr>>,
|
||||
/// query contains a constant condition that is always false
|
||||
pub contains_constant_false_condition: bool,
|
||||
/// Indexes that must be updated by the delete operation.
|
||||
@@ -394,8 +394,8 @@ pub struct UpdatePlan {
|
||||
pub set_clauses: Vec<(usize, Box<ast::Expr>)>,
|
||||
pub where_clause: Vec<WhereTerm>,
|
||||
pub order_by: Vec<(Box<ast::Expr>, SortOrder)>,
|
||||
pub limit: Option<Expr>,
|
||||
pub offset: Option<Expr>,
|
||||
pub limit: Option<Box<Expr>>,
|
||||
pub offset: Option<Box<Expr>>,
|
||||
// TODO: optional RETURNING clause
|
||||
pub returning: Option<Vec<ResultSetColumn>>,
|
||||
// whether the WHERE clause is always false
|
||||
|
||||
@@ -1106,7 +1106,7 @@ fn parse_join(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn parse_limit(limit: &Limit) -> Result<(Option<Expr>, Option<Expr>)> {
|
||||
pub fn parse_limit(limit: &Limit) -> Result<(Option<Box<Expr>>, Option<Box<Expr>>)> {
|
||||
let limit_expr = Some(limit.expr.clone());
|
||||
|
||||
let offset_expr = limit.offset.clone();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use turso_sqlite3_parser::ast::{Expr, Literal, Name, Operator, UnaryOperator};
|
||||
use turso_parser::ast::{Expr, Literal, Name, Operator, UnaryOperator};
|
||||
|
||||
use crate::{
|
||||
error::SQLITE_CONSTRAINT,
|
||||
@@ -171,7 +171,7 @@ pub fn emit_offset(
|
||||
return;
|
||||
};
|
||||
|
||||
if let Some(val) = try_fold_expr_to_i64(offset_expr) {
|
||||
if let Some(val) = try_fold_expr_to_i64(&offset_expr.clone()) {
|
||||
if val > 0 {
|
||||
program.add_comment(program.offset(), "OFFSET const");
|
||||
program.emit_insn(Insn::IfPos {
|
||||
@@ -332,12 +332,10 @@ pub fn build_limit_offset_expr(program: &mut ProgramBuilder, r: usize, expr: &Ex
|
||||
}
|
||||
}
|
||||
|
||||
pub fn try_fold_expr_to_i64(expr: &Expr) -> Option<i64> {
|
||||
match expr {
|
||||
pub fn try_fold_expr_to_i64(expr: &Box<Expr>) -> Option<i64> {
|
||||
match expr.as_ref() {
|
||||
Expr::Literal(Literal::Numeric(n)) => n.parse::<i64>().ok(),
|
||||
Expr::Literal(Literal::Null) => {
|
||||
Some(0)
|
||||
}
|
||||
Expr::Literal(Literal::Null) => Some(0),
|
||||
Expr::Id(Name::Ident(s)) => {
|
||||
let lowered = s.to_ascii_lowercase();
|
||||
if lowered == "true" {
|
||||
|
||||
Reference in New Issue
Block a user