Implement where and

This commit is contained in:
Bennett Clement
2024-07-15 23:36:35 +08:00
parent d1288cacef
commit f955187b70
2 changed files with 115 additions and 0 deletions

View File

@@ -603,6 +603,20 @@ impl Program {
state.pc += 1;
}
}
(OwnedValue::Integer(lhs), OwnedValue::Float(rhs)) => {
if (*lhs as f64) == *rhs {
state.pc = target_pc;
} else {
state.pc += 1;
}
}
(OwnedValue::Float(lhs), OwnedValue::Integer(rhs)) => {
if *lhs == (*rhs as f64) {
state.pc = target_pc;
} else {
state.pc += 1;
}
}
(OwnedValue::Text(lhs), OwnedValue::Text(rhs)) => {
if lhs == rhs {
state.pc = target_pc;
@@ -610,6 +624,9 @@ impl Program {
state.pc += 1;
}
}
(_, OwnedValue::Null) | (OwnedValue::Null, _) => {
state.pc = target_pc;
}
_ => {
todo!();
}
@@ -639,6 +656,20 @@ impl Program {
state.pc += 1;
}
}
(OwnedValue::Integer(lhs), OwnedValue::Float(rhs)) => {
if (*lhs as f64) != *rhs {
state.pc = target_pc;
} else {
state.pc += 1;
}
}
(OwnedValue::Float(lhs), OwnedValue::Integer(rhs)) => {
if *lhs != (*rhs as f64) {
state.pc = target_pc;
} else {
state.pc += 1;
}
}
(OwnedValue::Text(lhs), OwnedValue::Text(rhs)) => {
if lhs != rhs {
state.pc = target_pc;
@@ -646,6 +677,9 @@ impl Program {
state.pc += 1;
}
}
(_, OwnedValue::Null) | (OwnedValue::Null, _) => {
state.pc = target_pc;
}
_ => {
todo!();
}
@@ -675,6 +709,23 @@ impl Program {
state.pc += 1;
}
}
(OwnedValue::Integer(lhs), OwnedValue::Float(rhs)) => {
if (*lhs as f64) < *rhs {
state.pc = target_pc;
} else {
state.pc += 1;
}
}
(OwnedValue::Float(lhs), OwnedValue::Integer(rhs)) => {
if *lhs < (*rhs as f64) {
state.pc = target_pc;
} else {
state.pc += 1;
}
}
(_, OwnedValue::Null) | (OwnedValue::Null, _) => {
state.pc = target_pc;
}
_ => {
todo!();
}
@@ -704,6 +755,23 @@ impl Program {
state.pc += 1;
}
}
(OwnedValue::Integer(lhs), OwnedValue::Float(rhs)) => {
if (*lhs as f64) <= *rhs {
state.pc = target_pc;
} else {
state.pc += 1;
}
}
(OwnedValue::Float(lhs), OwnedValue::Integer(rhs)) => {
if *lhs <= (*rhs as f64) {
state.pc = target_pc;
} else {
state.pc += 1;
}
}
(_, OwnedValue::Null) | (OwnedValue::Null, _) => {
state.pc = target_pc;
}
_ => {
todo!();
}
@@ -733,6 +801,23 @@ impl Program {
state.pc += 1;
}
}
(OwnedValue::Integer(lhs), OwnedValue::Float(rhs)) => {
if (*lhs as f64) > *rhs {
state.pc = target_pc;
} else {
state.pc += 1;
}
}
(OwnedValue::Float(lhs), OwnedValue::Integer(rhs)) => {
if *lhs > (*rhs as f64) {
state.pc = target_pc;
} else {
state.pc += 1;
}
}
(_, OwnedValue::Null) | (OwnedValue::Null, _) => {
state.pc = target_pc;
}
_ => {
todo!();
}
@@ -762,6 +847,23 @@ impl Program {
state.pc += 1;
}
}
(OwnedValue::Integer(lhs), OwnedValue::Float(rhs)) => {
if (*lhs as f64) >= *rhs {
state.pc = target_pc;
} else {
state.pc += 1;
}
}
(OwnedValue::Float(lhs), OwnedValue::Integer(rhs)) => {
if *lhs >= (*rhs as f64) {
state.pc = target_pc;
} else {
state.pc += 1;
}
}
(_, OwnedValue::Null) | (OwnedValue::Null, _) => {
state.pc = target_pc;
}
_ => {
todo!();
}

View File

@@ -108,6 +108,19 @@ do_execsql_test where-clause-lte {
select count(1) from users where id <= 2000;
} {2000}
do_execsql_test where-and {
select * from products where price > 50 and name != 'hat';
} {2|cap|82.0
5|sweatshirt|74.0
6|shorts|70.0
7|jeans|78.0
8|sneakers|82.0
11|accessories|81.0}
do_execsql_test where-multiple-and {
select * from products where price > 50 and name != 'boots' and price <= 70;
} {6|shorts|70.0}
do_execsql_test where-clause-unary-true {
select count(1) from users where 1;
} {10000}