Skip to content

Commit a6a92d6

Browse files
committed
Fix incorrect implementation of cast_text_to_numerical()
1 parent 686ed2f commit a6a92d6

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

core/vdbe/insn.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::num::NonZero;
22

3-
use super::{AggFunc, BranchOffset, CursorID, FuncCtx, PageIdx};
3+
use super::{cast_text_to_integer, AggFunc, BranchOffset, CursorID, FuncCtx, PageIdx};
44
use crate::storage::wal::CheckpointMode;
55
use crate::types::{OwnedValue, Record};
66
use crate::vdbe::cast_text_to_real;
@@ -689,13 +689,11 @@ pub enum Cookie {
689689
UserVersion = 6,
690690
}
691691

692-
fn cast_text_to_numerical(value: &str) -> OwnedValue {
693-
if let Ok(x) = value.parse::<i64>() {
694-
OwnedValue::Integer(x)
695-
} else if let Ok(x) = value.parse::<f64>() {
696-
OwnedValue::Float(x)
692+
pub fn cast_text_to_numerical(value: &str) -> OwnedValue {
693+
if value.contains('.') || value.contains('e') || value.contains('E') {
694+
cast_text_to_real(value)
697695
} else {
698-
OwnedValue::Integer(0)
696+
cast_text_to_integer(value)
699697
}
700698
}
701699

core/vdbe/mod.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ use crate::{
5353
};
5454
use crate::{resolve_ext_path, Connection, Result, TransactionState, DATABASE_VERSION};
5555
use insn::{
56-
exec_add, exec_and, exec_bit_and, exec_bit_not, exec_bit_or, exec_boolean_not, exec_concat,
57-
exec_divide, exec_multiply, exec_or, exec_remainder, exec_shift_left, exec_shift_right,
58-
exec_subtract, Cookie,
56+
cast_text_to_numerical, exec_add, exec_and, exec_bit_and, exec_bit_not, exec_bit_or,
57+
exec_boolean_not, exec_concat, exec_divide, exec_multiply, exec_or, exec_remainder,
58+
exec_shift_left, exec_shift_right, exec_subtract, Cookie,
5959
};
6060
use likeop::{construct_like_escape_arg, exec_glob, exec_like_with_escape};
6161
use rand::distributions::{Distribution, Uniform};
@@ -3583,11 +3583,7 @@ fn exec_cast(value: &OwnedValue, datatype: &str) -> OwnedValue {
35833583
OwnedValue::Text(t) => {
35843584
let text = t.as_str();
35853585
// Looks like a float
3586-
if text.contains('.') || text.contains('e') || text.contains('E') {
3587-
cast_text_to_real(text)
3588-
} else {
3589-
cast_text_to_integer(text)
3590-
}
3586+
cast_text_to_numerical(text)
35913587
}
35923588
OwnedValue::Integer(i) => OwnedValue::Integer(*i),
35933589
OwnedValue::Float(f) => OwnedValue::Float(*f),

0 commit comments

Comments
 (0)