Skip to content

Commit

Permalink
Fix incorrect implementation of cast_text_to_numerical()
Browse files Browse the repository at this point in the history
  • Loading branch information
jussisaurio committed Feb 16, 2025
1 parent 686ed2f commit a6a92d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
12 changes: 5 additions & 7 deletions core/vdbe/insn.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::num::NonZero;

use super::{AggFunc, BranchOffset, CursorID, FuncCtx, PageIdx};
use super::{cast_text_to_integer, AggFunc, BranchOffset, CursorID, FuncCtx, PageIdx};
use crate::storage::wal::CheckpointMode;
use crate::types::{OwnedValue, Record};
use crate::vdbe::cast_text_to_real;
Expand Down Expand Up @@ -689,13 +689,11 @@ pub enum Cookie {
UserVersion = 6,
}

fn cast_text_to_numerical(value: &str) -> OwnedValue {
if let Ok(x) = value.parse::<i64>() {
OwnedValue::Integer(x)
} else if let Ok(x) = value.parse::<f64>() {
OwnedValue::Float(x)
pub fn cast_text_to_numerical(value: &str) -> OwnedValue {
if value.contains('.') || value.contains('e') || value.contains('E') {
cast_text_to_real(value)
} else {
OwnedValue::Integer(0)
cast_text_to_integer(value)
}
}

Expand Down
12 changes: 4 additions & 8 deletions core/vdbe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ use crate::{
};
use crate::{resolve_ext_path, Connection, Result, TransactionState, DATABASE_VERSION};
use insn::{
exec_add, exec_and, exec_bit_and, exec_bit_not, exec_bit_or, exec_boolean_not, exec_concat,
exec_divide, exec_multiply, exec_or, exec_remainder, exec_shift_left, exec_shift_right,
exec_subtract, Cookie,
cast_text_to_numerical, exec_add, exec_and, exec_bit_and, exec_bit_not, exec_bit_or,
exec_boolean_not, exec_concat, exec_divide, exec_multiply, exec_or, exec_remainder,
exec_shift_left, exec_shift_right, exec_subtract, Cookie,
};
use likeop::{construct_like_escape_arg, exec_glob, exec_like_with_escape};
use rand::distributions::{Distribution, Uniform};
Expand Down Expand Up @@ -3583,11 +3583,7 @@ fn exec_cast(value: &OwnedValue, datatype: &str) -> OwnedValue {
OwnedValue::Text(t) => {
let text = t.as_str();
// Looks like a float
if text.contains('.') || text.contains('e') || text.contains('E') {
cast_text_to_real(text)
} else {
cast_text_to_integer(text)
}
cast_text_to_numerical(text)
}
OwnedValue::Integer(i) => OwnedValue::Integer(*i),
OwnedValue::Float(f) => OwnedValue::Float(*f),
Expand Down

0 comments on commit a6a92d6

Please sign in to comment.