diff --git a/sqlness/examples/interceptor-case/simple/input.result b/sqlness/examples/interceptor-case/simple/input.result index deca3f9..3777268 100644 --- a/sqlness/examples/interceptor-case/simple/input.result +++ b/sqlness/examples/interceptor-case/simple/input.result @@ -109,3 +109,8 @@ INSERT INTO t (c) VALUES(1) , (2) , (3) , (4) ; 4 2; +-- Test case for https://github.com/CeresDB/sqlness/issues/68 +INSERT INTO timestamp VALUES ('1900-1-1 00;00;00'); + +INSERT INTO timestamp VALUES ('1900-1-1 00;00;00'); + diff --git a/sqlness/examples/interceptor-case/simple/input.sql b/sqlness/examples/interceptor-case/simple/input.sql index 113409a..4c7d9c9 100644 --- a/sqlness/examples/interceptor-case/simple/input.sql +++ b/sqlness/examples/interceptor-case/simple/input.sql @@ -63,3 +63,6 @@ INSERT INTO t (c) VALUES 4 2 2; + +-- Test case for https://github.com/CeresDB/sqlness/issues/68 +INSERT INTO timestamp VALUES ('1900-1-1 00;00;00'); diff --git a/sqlness/src/case.rs b/sqlness/src/case.rs index 4eba35e..7c36491 100644 --- a/sqlness/src/case.rs +++ b/sqlness/src/case.rs @@ -154,12 +154,14 @@ impl Query { let sql = self.concat_query_lines(); // An intercetor may generate multiple SQLs, so we need to split them. - for sql in sql.split(QUERY_DELIMITER) { + for sql in sql.split(crate::interceptor::template::DELIMITER) { if !sql.trim().is_empty() { - let mut result = db - .query(context.clone(), format!("{sql};")) - .await - .to_string(); + let sql = if sql.ends_with(QUERY_DELIMITER) { + sql.to_string() + } else { + format!("{sql};") + }; + let mut result = db.query(context.clone(), sql).await.to_string(); self.after_execute_intercept(&mut result).await; self.write_result(writer, result)?; } diff --git a/sqlness/src/interceptor/template.rs b/sqlness/src/interceptor/template.rs index d4a0f9b..dea88c2 100644 --- a/sqlness/src/interceptor/template.rs +++ b/sqlness/src/interceptor/template.rs @@ -10,6 +10,7 @@ use crate::SqlnessError; pub struct TemplateInterceptorFactory; pub const PREFIX: &str = "TEMPLATE"; +pub const DELIMITER: &str = "__sqlness_delimiter__"; /// Templated query, powered by [minijinja](https://github.com/mitsuhiko/minijinja). /// The template syntax can be found [here](https://docs.rs/minijinja/latest/minijinja/syntax/index.html). @@ -43,7 +44,7 @@ pub struct TemplateInterceptor { } fn sql_delimiter() -> std::result::Result { - Ok(";".to_string()) + Ok(DELIMITER.to_string()) } impl Interceptor for TemplateInterceptor {