Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DELETE command includes duplicate whitespace #4397

Closed
3 tasks done
sgoll opened this issue Dec 18, 2024 · 0 comments · Fixed by #4398
Closed
3 tasks done

DELETE command includes duplicate whitespace #4397

sgoll opened this issue Dec 18, 2024 · 0 comments · Fixed by #4398
Labels

Comments

@sgoll
Copy link
Contributor

sgoll commented Dec 18, 2024

Setup

Versions

  • Rust: 1.83.0
  • Diesel: 2.2.6
  • Database: SQLite
  • Operating System Linux

Feature Flags

  • diesel: r2d2, returning_clauses_for_sqlite_3_35, sqlite, uuid

Problem Description

SQL queries generated for DELETE commands include an unnecessary duplicate space between DELETE and FROM. This can be seen from emitting the corresponding strings in walk_ast():

fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
out.push_sql("DELETE ");
self.from_clause.walk_ast(out.reborrow())?;
self.where_clause.walk_ast(out.reborrow())?;
self.returning.walk_ast(out.reborrow())?;
Ok(())
}

The trailing space can safely be omitted here because self.from_clause.walk_ast() always contributes a leading space itself, leading to duplication, in its own walk_ast() method:

fn walk_ast<'b>(&'b self, mut pass: AstPass<'_, 'b, DB>) -> QueryResult<()> {
pass.push_sql(" FROM ");
self.from_clause.walk_ast(pass)
}

Since DELETE  is always followed by  FROM self.from_clause is not optional and must always be emitted—, the trailing space is not necessary, similar to how INSERT commands are prepared without trailing space (because they are always followed by  INTO ):

fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
out.push_sql("INSERT");
Ok(())
}

What are you trying to accomplish?

Issue clean, beautiful SQL queries.

What is the expected output?

DELETE FROM "table"

What is the actual output?

DELETE FROM "table"

Are you seeing any additional errors?

No.

Steps to reproduce

Issue a DELETE query as in the following code:

let num_deleted = diesel::delete(posts.filter(title.like(pattern)))
    .execute(connection)
    .expect("Error deleting posts");

Checklist

  • This issue can be reproduced on Rust's stable channel. (Your issue will be
    closed if this is not the case)
  • This issue can be reproduced without requiring a third party crate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant