mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-28 21:44:21 +01:00
Merge 'Fix ScalarFunc::Glob to handle NULL and other value types' from Krishna Vishal
Previously `ScalarFunc::Glob` only handled Text based values. After this
fix it will be able to handle all types of values.
Now:
```SQL
turso> CREATE TABLE IF NOT EXISTS t0 (c0 REAL );
turso> UPDATE t0 SET c0='C2IS*24', c0=0Xffffffffbfc4330f, c0=0.6463854797956918 WHERE ((((((((t0.c0)AND(t0.c0)))AND(0.23913649834358142)))OR(CASE t0.c0 WHEN t0.c0 THEN 'j2' WHEN t0.c0 THEN t0.c0 WHEN t0.c0 THEN t0.c0 END)))OR(((((((((t0.c0)AND(t0.c0)))AND(t0.c0)))OR(t0.c0)))AND(t0.c0))));
turso> INSERT INTO t0 VALUES (NULL);
INSERT INTO t0 VALUES ('0&');
UPDATE t0 SET c0=2352448 WHERE ((((t0.c0)GLOB(t0.c0))) NOT NULL);
turso> SELECT * from t0;
┌───────────┐
│ c0 │
├───────────┤
│ │
├───────────┤
│ 2352448.0 │
└───────────┘
```
Fixes: https://github.com/tursodatabase/turso/issues/1953
Closes #1955
This commit is contained in:
@@ -3454,6 +3454,7 @@ pub fn op_function(
|
||||
let pattern = &state.registers[*start_reg];
|
||||
let text = &state.registers[*start_reg + 1];
|
||||
let result = match (pattern.get_owned_value(), text.get_owned_value()) {
|
||||
(Value::Null, _) | (_, Value::Null) => Value::Null,
|
||||
(Value::Text(pattern), Value::Text(text)) => {
|
||||
let cache = if *constant_mask > 0 {
|
||||
Some(&mut state.regex_cache.glob)
|
||||
@@ -3462,8 +3463,16 @@ pub fn op_function(
|
||||
};
|
||||
Value::Integer(exec_glob(cache, pattern.as_str(), text.as_str()) as i64)
|
||||
}
|
||||
_ => {
|
||||
unreachable!("Like on non-text registers");
|
||||
// Convert any other value types to text for GLOB comparison
|
||||
(pattern_val, text_val) => {
|
||||
let pattern_str = pattern_val.to_string();
|
||||
let text_str = text_val.to_string();
|
||||
let cache = if *constant_mask > 0 {
|
||||
Some(&mut state.regex_cache.glob)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
Value::Integer(exec_glob(cache, &pattern_str, &text_str) as i64)
|
||||
}
|
||||
};
|
||||
state.registers[*dest] = Register::Value(result);
|
||||
|
||||
@@ -69,6 +69,19 @@ do_execsql_test where-glob-impossible {
|
||||
select * from products where 'foobar' glob 'fooba';
|
||||
} {}
|
||||
|
||||
do_execsql_test glob-null-other-types {
|
||||
DROP TABLE IF EXISTS t0;
|
||||
CREATE TABLE IF NOT EXISTS t0 (c0 REAL);
|
||||
UPDATE t0 SET c0='C2IS*24', c0=0Xffffffffbfc4330f, c0=0.6463854797956918 WHERE ((((((((t0.c0)AND(t0.c0)))AND(0.23913649834358142)))OR(CASE t0.c0 WHEN t0.c0 THEN 'j2' WHEN t0.c0 THEN t0.c0 WHEN t0.c0 THEN t0.c0 END)))OR(((((((((t0.c0)AND(t0.c0)))AND(t0.c0)))OR(t0.c0)))AND(t0.c0))));
|
||||
INSERT INTO t0 VALUES (NULL);
|
||||
INSERT INTO t0 VALUES ('0&');
|
||||
UPDATE t0 SET c0=2352448 WHERE ((((t0.c0)GLOB(t0.c0))) NOT NULL);
|
||||
SELECT * from t0;
|
||||
} {
|
||||
{}
|
||||
2352448.0
|
||||
}
|
||||
|
||||
foreach {testnum pattern text ans} {
|
||||
1 abcdefg abcdefg 1
|
||||
2 abcdefG abcdefg 0
|
||||
|
||||
Reference in New Issue
Block a user