chore: fix clippy warnings

This commit is contained in:
Nils Koch
2025-06-13 21:20:26 +01:00
parent 1a0d4f500f
commit 2827b86917
95 changed files with 902 additions and 992 deletions

View File

@@ -105,18 +105,15 @@ impl Stmt {
match self {
Self::AlterTable(alter_table) => {
let (_, body) = &**alter_table;
match body {
AlterTableBody::AddColumn(cd) => {
for c in cd {
if let ColumnConstraint::PrimaryKey { .. } = c {
return Err(custom_err!("Cannot add a PRIMARY KEY column"));
}
if let ColumnConstraint::Unique(..) = c {
return Err(custom_err!("Cannot add a UNIQUE column"));
}
if let AlterTableBody::AddColumn(cd) = body {
for c in cd {
if let ColumnConstraint::PrimaryKey { .. } = c {
return Err(custom_err!("Cannot add a PRIMARY KEY column"));
}
if let ColumnConstraint::Unique(..) = c {
return Err(custom_err!("Cannot add a UNIQUE column"));
}
}
_ => {}
}
Ok(())
}
@@ -164,10 +161,8 @@ impl Stmt {
let Delete {
order_by, limit, ..
} = &**delete;
if let Some(_) = order_by {
if limit.is_none() {
return Err(custom_err!("ORDER BY without LIMIT on DELETE"));
}
if order_by.is_some() && limit.is_none() {
return Err(custom_err!("ORDER BY without LIMIT on DELETE"));
}
Ok(())
}
@@ -177,7 +172,7 @@ impl Stmt {
return Ok(());
}
let columns = columns.as_ref().unwrap();
match &*body {
match body {
InsertBody::Select(select, ..) => match select.body.select.column_count() {
ColumnCount::Fixed(n) if n != columns.len() => {
Err(custom_err!("{} values for {} columns", n, columns.len()))
@@ -193,10 +188,8 @@ impl Stmt {
let Update {
order_by, limit, ..
} = &**update;
if let Some(_) = order_by {
if limit.is_none() {
return Err(custom_err!("ORDER BY without LIMIT on UPDATE"));
}
if order_by.is_some() && limit.is_none() {
return Err(custom_err!("ORDER BY without LIMIT on UPDATE"));
}
Ok(())

View File

@@ -71,7 +71,7 @@ impl ToSqlString for Expr {
Expr::Collate(expr, name) => {
ret.push_str(&expr.to_sql_string(context));
ret.push_str(" COLLATE ");
ret.push_str(&name);
ret.push_str(name);
}
Expr::DoublyQualified(name, name1, name2) => {
ret.push_str(&name.0);

View File

@@ -23,7 +23,7 @@ pub trait ToSqlString {
impl<T: ToSqlString> ToSqlString for Box<T> {
fn to_sql_string<C: ToSqlContext>(&self, context: &C) -> String {
T::to_sql_string(&self, context)
T::to_sql_string(self, context)
}
}

View File

@@ -44,7 +44,7 @@ impl ToSqlString for ast::NamedTableConstraint {
self.constraint.to_sql_string(context)
)
} else {
format!("{}", self.constraint.to_sql_string(context))
self.constraint.to_sql_string(context).to_string()
}
}
}

View File

@@ -9,14 +9,22 @@ impl ToSqlString for ast::CreateTrigger {
fn to_sql_string<C: crate::to_sql_string::ToSqlContext>(&self, context: &C) -> String {
format!(
"CREATE{} TRIGGER {}{}{} {} ON {}{}{} BEGIN {} END;",
self.temporary.then_some(" TEMP").unwrap_or(""),
self.if_not_exists.then_some("IF NOT EXISTS ").unwrap_or(""),
if self.temporary { " TEMP" } else { "" },
if self.if_not_exists {
"IF NOT EXISTS "
} else {
""
},
self.trigger_name.to_sql_string(context),
self.time
.map_or("".to_string(), |time| format!(" {}", time)),
self.event,
self.tbl_name.to_sql_string(context),
self.for_each_row.then_some(" FOR EACH ROW").unwrap_or(""),
if self.for_each_row {
" FOR EACH ROW"
} else {
""
},
self.when_clause
.as_ref()
.map_or("".to_string(), |expr| format!(

View File

@@ -4,7 +4,11 @@ impl ToSqlString for ast::CreateVirtualTable {
fn to_sql_string<C: crate::to_sql_string::ToSqlContext>(&self, context: &C) -> String {
format!(
"CREATE VIRTUAL TABLE {}{} USING {}{};",
self.if_not_exists.then_some("IF NOT EXISTS ").unwrap_or(""),
if self.if_not_exists {
"IF NOT EXISTS "
} else {
""
},
self.tbl_name.to_sql_string(context),
self.module_name.0,
self.args

View File

@@ -26,7 +26,7 @@ impl ToSqlString for ast::Stmt {
if let Some(name) = name {
format!("ANALYZE {};", name.to_sql_string(context))
} else {
format!("ANALYZE;")
"ANALYZE;".to_string()
}
}
Self::Attach {
@@ -211,15 +211,15 @@ mod tests {
($test_name:ident, $input:expr) => {
#[test]
fn $test_name() {
let context = crate::to_sql_string::stmt::tests::TestContext;
let context = $crate::to_sql_string::stmt::tests::TestContext;
let input = $input.split_whitespace().collect::<Vec<&str>>().join(" ");
let mut parser = crate::lexer::sql::Parser::new(input.as_bytes());
let mut parser = $crate::lexer::sql::Parser::new(input.as_bytes());
let cmd = fallible_iterator::FallibleIterator::next(&mut parser)
.unwrap()
.unwrap();
assert_eq!(
input,
crate::to_sql_string::ToSqlString::to_sql_string(cmd.stmt(), &context)
$crate::to_sql_string::ToSqlString::to_sql_string(cmd.stmt(), &context)
);
}
};
@@ -227,15 +227,15 @@ mod tests {
#[test]
$(#[$attribute])*
fn $test_name() {
let context = crate::to_sql_string::stmt::tests::TestContext;
let context = $crate::to_sql_string::stmt::tests::TestContext;
let input = $input.split_whitespace().collect::<Vec<&str>>().join(" ");
let mut parser = crate::lexer::sql::Parser::new(input.as_bytes());
let mut parser = $crate::lexer::sql::Parser::new(input.as_bytes());
let cmd = fallible_iterator::FallibleIterator::next(&mut parser)
.unwrap()
.unwrap();
assert_eq!(
input,
crate::to_sql_string::ToSqlString::to_sql_string(cmd.stmt(), &context)
$crate::to_sql_string::ToSqlString::to_sql_string(cmd.stmt(), &context)
);
}
}