-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We fix a bug in our IS TRUE/FALSE inference, and rewrite it to use sql_quote. We also decide to implement both versions of CASE.
- Loading branch information
Showing
11 changed files
with
149 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use derive_visitor::{DriveMut, VisitorMut}; | ||
use joinery_macros::sql_quote; | ||
|
||
use crate::{ | ||
ast::{self, Expression, IsExpression, IsExpressionPredicate}, | ||
errors::Result, | ||
}; | ||
|
||
use super::{Transform, TransformExtra}; | ||
|
||
/// Transform `expr IS [NOT] (TRUE|FALSE)` into a portable | ||
/// `CASE` expression. | ||
#[derive(VisitorMut)] | ||
#[visitor(Expression(enter))] | ||
pub struct IsBoolToCase; | ||
|
||
impl IsBoolToCase { | ||
fn enter_expression(&mut self, expr: &mut Expression) { | ||
if let Expression::Is(IsExpression { | ||
left, | ||
not_token, | ||
predicate: IsExpressionPredicate::True(pred) | IsExpressionPredicate::False(pred), | ||
.. | ||
}) = expr | ||
{ | ||
let replacement = sql_quote! { | ||
CASE #not_token #left WHEN #pred THEN TRUE ELSE FALSE END | ||
} | ||
.try_into_expression() | ||
.expect("generated SQL should always parse"); | ||
*expr = replacement; | ||
} | ||
} | ||
} | ||
|
||
impl Transform for IsBoolToCase { | ||
fn transform(mut self: Box<Self>, sql_program: &mut ast::SqlProgram) -> Result<TransformExtra> { | ||
sql_program.drive_mut(self.as_mut()); | ||
Ok(TransformExtra::default()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.