mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 18:18:03 +00:00
add function parse_signed_number
This commit is contained in:
parent
d9d3a5ecbb
commit
2f82762ca2
3 changed files with 26 additions and 15 deletions
|
@ -10,7 +10,7 @@ use crate::fast_lock::SpinLock;
|
|||
use crate::schema::Schema;
|
||||
use crate::storage::sqlite3_ondisk::{DatabaseHeader, MIN_PAGE_CACHE_SIZE};
|
||||
use crate::storage::wal::CheckpointMode;
|
||||
use crate::util::{normalize_ident, parse_numeric_literal};
|
||||
use crate::util::{normalize_ident, parse_signed_number};
|
||||
use crate::vdbe::builder::{ProgramBuilder, ProgramBuilderOpts, QueryMode};
|
||||
use crate::vdbe::insn::{Cookie, Insn};
|
||||
use crate::{bail_parse_error, Pager, Value};
|
||||
|
@ -142,19 +142,7 @@ fn update_pragma(
|
|||
Ok(())
|
||||
}
|
||||
PragmaName::UserVersion => {
|
||||
let data = match value {
|
||||
ast::Expr::Literal(ast::Literal::Numeric(numeric_value)) => {
|
||||
parse_numeric_literal(&numeric_value)?
|
||||
}
|
||||
ast::Expr::Unary(ast::UnaryOperator::Negative, expr) => match *expr {
|
||||
ast::Expr::Literal(ast::Literal::Numeric(numeric_value)) => {
|
||||
let data = "-".to_owned() + numeric_value.as_str();
|
||||
parse_numeric_literal(&data)?
|
||||
}
|
||||
_ => bail_parse_error!("Not a valid value"),
|
||||
},
|
||||
_ => bail_parse_error!("Not a valid value"),
|
||||
};
|
||||
let data = parse_signed_number(&value)?;
|
||||
let version_value = match data {
|
||||
Value::Integer(i) => i as i32,
|
||||
Value::Float(f) => f as i32,
|
||||
|
|
25
core/util.rs
25
core/util.rs
|
@ -4,7 +4,9 @@ use crate::{
|
|||
types::{Value, ValueType},
|
||||
LimboError, OpenFlags, Result, Statement, StepResult, SymbolTable, IO,
|
||||
};
|
||||
use limbo_sqlite3_parser::ast::{self, CreateTableBody, Expr, FunctionTail, Literal};
|
||||
use limbo_sqlite3_parser::ast::{
|
||||
self, CreateTableBody, Expr, FunctionTail, Literal, UnaryOperator,
|
||||
};
|
||||
use std::{rc::Rc, sync::Arc};
|
||||
|
||||
pub trait RoundToPrecision {
|
||||
|
@ -1011,6 +1013,27 @@ pub fn parse_numeric_literal(text: &str) -> Result<Value> {
|
|||
Ok(Value::Float(float_value))
|
||||
}
|
||||
|
||||
pub fn parse_signed_number(expr: &Expr) -> Result<Value> {
|
||||
match expr {
|
||||
Expr::Literal(Literal::Numeric(num)) => parse_numeric_literal(num),
|
||||
Expr::Unary(op, expr) => match (op, expr.as_ref()) {
|
||||
(UnaryOperator::Negative, Expr::Literal(Literal::Numeric(num))) => {
|
||||
let data = "-".to_owned() + &num.to_string();
|
||||
parse_numeric_literal(&data)
|
||||
}
|
||||
(UnaryOperator::Positive, Expr::Literal(Literal::Numeric(num))) => {
|
||||
parse_numeric_literal(num)
|
||||
}
|
||||
_ => Err(LimboError::InvalidArgument(
|
||||
"signed-number must follow the format: ([+|-] numeric-literal)".to_string(),
|
||||
)),
|
||||
},
|
||||
_ => Err(LimboError::InvalidArgument(
|
||||
"signed-number must follow the format: ([+|-] numeric-literal)".to_string(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
// for TVF's we need these at planning time so we cannot emit translate_expr
|
||||
pub fn vtable_args(args: &[ast::Expr]) -> Vec<limbo_ext::Value> {
|
||||
let mut vtable_args = Vec::new();
|
||||
|
|
BIN
database
Normal file
BIN
database
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue