Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up[sqlite] Syntax error in generated subexpression #1308
Comments
weiznich
added
bug
sqlite
labels
Nov 21, 2017
This comment has been minimized.
bgeron
commented
Feb 9, 2018
|
It seems that at least one maintainer says that it's a mistake that your program compiles, until someone has the time to put a lot of work in making this work properly. (Although I think your program is fine.) I can see two workarounds to allow sub-selects in queries. I'm personally using the second. Workaround 1Write your SQL by hand. I believe you can still use Diesel to convert the results into Rust structs. Workaround 2Wrap your use diesel::{Expression, AppearsOnTable, QueryResult};
use diesel::backend::Backend;
use diesel::query_builder::{AstPass, QueryFragment};
pub fn parens<T: Expression>(e: T) -> Parens<T> {
Parens(e)
}
#[derive(Debug, Copy, Clone)]
pub struct Parens<T: Expression>(T);
impl<T: Expression> Expression for Parens<T> {
type SqlType = T::SqlType;
}
impl<QS, T: AppearsOnTable<QS>> AppearsOnTable<QS> for Parens<T> {}
impl<DB: Backend, T: Expression + QueryFragment<DB>> QueryFragment<DB> for Parens<T> {
fn walk_ast(&self, mut out: AstPass<DB>) -> QueryResult<()> {
out.push_sql("(");
self.0.walk_ast(out.reborrow())?;
out.push_sql(")");
Ok(())
}
} after which you can simply write |
This comment has been minimized.
bgeron
commented
Feb 9, 2018
|
If the maintainers agree that this bug should not be fixed, then they should probably close it as WONTFIX or something. |
This comment has been minimized.
|
@bgeron You are coming dangerously close to trolling. Last warning. |
This comment has been minimized.
bgeron
commented
Feb 11, 2018
|
Sean, I'm a user who had the same problem, I managed to solve it for myself, and so I thought I'd share it with @mfr-itr. And I thought this 2 month old ticket could use an update. I have to admit I didn't fully understand what you said on Gitter, even after reading it multiple times, so perhaps my summary is wrong. How about you write one and I remove mine? |
mfr-itr commentedNov 21, 2017
Setup
Versions
Problem Description
My real code has a structure similar to
which produces
SELECT CURRENT_TIMESTAMP WHERE CURRENT_TIMESTAMP = SELECT CURRENT_TIMESTAMP;(syntax error) instead of
SELECT CURRENT_TIMESTAMP WHERE CURRENT_TIMESTAMP = (SELECT CURRENT_TIMESTAMP);Checklist
How can I make it produce valid code while waiting for the fix? The sub-expression is a primary key lookup.