1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 18:20:43 +09:00

LibSQL: Remove infallible type conversions from SQL::Value

Force the callers to either know that the type is convertible, or to
handle the conversion failure.
This commit is contained in:
Timothy Flynn 2022-09-22 08:35:47 -04:00 committed by Ali Mohammad Pur
parent af3980384b
commit 7d41b46a7d
Notes: sideshowbarker 2024-07-17 05:48:30 +09:00
8 changed files with 22 additions and 64 deletions

View file

@ -126,23 +126,23 @@ ResultOr<Value> UnaryOperatorExpression::evaluate(ExecutionContext& context) con
return Result { SQLCommand::Unknown, SQLErrorCode::NumericOperatorTypeMismatch, UnaryOperator_name(type()) };
case UnaryOperator::Minus:
if (expression_value.type() == SQLType::Integer) {
expression_value = -int(expression_value);
expression_value = -expression_value.to_int().value();
return expression_value;
}
if (expression_value.type() == SQLType::Float) {
expression_value = -double(expression_value);
expression_value = -expression_value.to_double().value();
return expression_value;
}
return Result { SQLCommand::Unknown, SQLErrorCode::NumericOperatorTypeMismatch, UnaryOperator_name(type()) };
case UnaryOperator::Not:
if (expression_value.type() == SQLType::Boolean) {
expression_value = !bool(expression_value);
expression_value = !expression_value.to_bool().value();
return expression_value;
}
return Result { SQLCommand::Unknown, SQLErrorCode::BooleanOperatorTypeMismatch, UnaryOperator_name(type()) };
case UnaryOperator::BitwiseNot:
if (expression_value.type() == SQLType::Integer) {
expression_value = ~u32(expression_value);
expression_value = ~expression_value.to_u32().value();
return expression_value;
}
return Result { SQLCommand::Unknown, SQLErrorCode::IntegerOperatorTypeMismatch, UnaryOperator_name(type()) };

View file

@ -92,8 +92,8 @@ ResultOr<ResultSet> Select::execute(ExecutionContext& context) const
context.current_row = &row;
if (where_clause()) {
auto where_result = TRY(where_clause()->evaluate(context));
if (!where_result)
auto where_result = TRY(where_clause()->evaluate(context)).to_bool();
if (!where_result.has_value() || !where_result.value())
continue;
}

View file

@ -183,9 +183,10 @@ void TableDef::append_column(String name, SQLType sql_type)
void TableDef::append_column(Key const& column)
{
append_column(
(String)column["column_name"],
(SQLType)((int)column["column_type"]));
auto column_type = column["column_type"].to_int();
VERIFY(column_type.has_value());
append_column(column["column_name"].to_string(), static_cast<SQLType>(*column_type));
}
Key TableDef::make_key(SchemaDef const& schema_def)

View file

@ -189,39 +189,6 @@ Optional<Vector<Value>> Value::to_vector() const
return {};
}
Value::operator String() const
{
return to_string();
}
Value::operator int() const
{
auto i = to_int();
VERIFY(i.has_value());
return i.value();
}
Value::operator u32() const
{
auto i = to_u32();
VERIFY(i.has_value());
return i.value();
}
Value::operator double() const
{
auto d = to_double();
VERIFY(d.has_value());
return d.value();
}
Value::operator bool() const
{
auto b = to_bool();
VERIFY(b.has_value());
return b.value();
}
void Value::assign(Value const& other_value)
{
m_impl.visit([&](auto& impl) { impl.assign(other_value); });

View file

@ -78,12 +78,6 @@ public:
[[nodiscard]] Optional<bool> to_bool() const;
[[nodiscard]] Optional<Vector<Value>> to_vector() const;
explicit operator String() const;
explicit operator int() const;
explicit operator u32() const;
explicit operator double() const;
explicit operator bool() const;
void assign(Value const& other_value);
void assign(String const& string_value);
void assign(int int_value);